blob: b08f3fb7768c9cf6ea0c34a171435b7f06cf0c18 [file] [log] [blame]
//===- OpGenHelpers.cpp - MLIR operation generator helpers ----------------===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// This file defines helpers used in the op generators.
#include "OpGenHelpers.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Regex.h"
#include "llvm/TableGen/Error.h"
using namespace llvm;
using namespace mlir;
using namespace mlir::tblgen;
cl::OptionCategory opDefGenCat("Options for op definition generators");
static cl::opt<std::string> opIncFilter(
cl::desc("Regex of name of op's to include (no filter if empty)"),
static cl::opt<std::string> opExcFilter(
cl::desc("Regex of name of op's to exclude (no filter if empty)"),
static std::string getOperationName(const Record &def) {
auto prefix = def.getValueAsDef("opDialect")->getValueAsString("name");
auto opName = def.getValueAsString("opName");
if (prefix.empty())
return std::string(opName);
return std::string(llvm::formatv("{0}.{1}", prefix, opName));
std::vector<Record *>
mlir::tblgen::getRequestedOpDefinitions(const RecordKeeper &recordKeeper) {
Record *classDef = recordKeeper.getClass("Op");
if (!classDef)
PrintFatalError("ERROR: Couldn't find the 'Op' class!\n");
llvm::Regex includeRegex(opIncFilter), excludeRegex(opExcFilter);
std::vector<Record *> defs;
for (const auto &def : recordKeeper.getDefs()) {
if (!def.second->isSubClassOf(classDef))
// Include if no include filter or include filter matches.
if (!opIncFilter.empty() &&
// Unless there is an exclude filter and it matches.
if (!opExcFilter.empty() &&
return defs;