17 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Support/FormatVariadic.h"
19 #include "llvm/Support/InitLLVM.h"
20 #include "llvm/Support/Signals.h"
21 #include "llvm/TableGen/Error.h"
22 #include "llvm/TableGen/Main.h"
23 #include "llvm/TableGen/Record.h"
33 static bool findUse(Init *field, Init *deprecatedInit,
35 if (field == deprecatedInit)
38 auto it = known.find(field);
39 if (it != known.end())
42 auto memoize = [&](
bool val) {
47 if (
auto *defInit = dyn_cast<DefInit>(field)) {
52 if (!defInit->getDef()->isAnonymous())
58 llvm::any_of(defInit->getDef()->getValues(), [&](
const RecordVal &val) {
59 return findUse(val.getValue(), deprecatedInit, known);
63 if (
auto *dagInit = dyn_cast<DagInit>(field)) {
64 if (
findUse(dagInit->getOperator(), deprecatedInit, known))
67 return memoize(llvm::any_of(dagInit->getArgs(), [&](Init *arg) {
68 return findUse(arg, deprecatedInit, known);
72 if (ListInit *li = dyn_cast<ListInit>(field)) {
73 return memoize(llvm::any_of(li->getValues(), [&](Init *jt) {
74 return findUse(jt, deprecatedInit, known);
86 static bool findUse(Record &record, Init *deprecatedInit,
88 return llvm::any_of(record.getValues(), [&](
const RecordVal &val) {
89 return findUse(val.getValue(), deprecatedInit, known);
97 bool deprecatedDefsFounds =
false;
98 for (
auto &it : records.getDefs()) {
99 const RecordVal *r = it.second->getValue(
"odsDeprecated");
100 if (!r || !r->getValue())
104 if (
auto *si = dyn_cast<StringInit>(r->getValue())) {
105 for (
auto &jt : records.getDefs()) {
107 if (jt.second->isAnonymous())
110 if (
findUse(*jt.second, it.second->getDefInit(), hasUse)) {
111 PrintWarning(jt.second->getLoc(),
112 "Using deprecated def `" + it.first +
"`");
113 PrintNote(si->getAsUnquotedString());
114 deprecatedDefsFounds =
true;
119 if (deprecatedDefsFounds &&
121 PrintFatalNote(
"Error'ing out due to deprecated defs");
142 llvm::InitLLVM y(argc, argv);
144 llvm::cl::opt<DeprecatedAction, true> actionOnDeprecated(
145 "on-deprecated", llvm::cl::desc(
"Action to perform on deprecated def"),
152 llvm::cl::opt<const mlir::GenInfo *, true, mlir::GenNameParser>
generator(
153 "", llvm::cl::desc(
"Generator to run"), cl::location(::
generator));
155 cl::ParseCommandLineOptions(argc, argv);
static DeprecatedAction actionOnDeprecatedValue
static const mlir::GenInfo * generator
static bool findUse(Init *field, Init *deprecatedInit, llvm::DenseMap< Init *, bool > &known)
static void warnOfDeprecatedUses(const RecordKeeper &records)
static bool mlirTableGenMain(raw_ostream &os, const RecordKeeper &records)
Structure to group information about a generator (argument to invoke via mlir-tblgen,...
bool invoke(const llvm::RecordKeeper &records, raw_ostream &os) const
Invokes the generator and returns whether the generator failed.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
int MlirTblgenMain(int argc, char **argv)
Main Program for tools like 'mlir-tblgen' with custom backends.