Skip to content

Commit 151e267

Browse files
committed
[NFC][MLIR][TableGen] Eliminate llvm:: for commonly used types
Eliminate `llvm::` namespace qualifier for commonly used types in MLIR TableGen backends to reduce code clutter.
1 parent 9bf02a8 commit 151e267

18 files changed

+541
-551
lines changed

mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
using namespace mlir;
2424
using namespace mlir::tblgen;
25+
using llvm::Record;
26+
using llvm::RecordKeeper;
27+
namespace cl = llvm::cl;
2528

2629
//===----------------------------------------------------------------------===//
2730
// Utility Functions
@@ -30,14 +33,14 @@ using namespace mlir::tblgen;
3033
/// Find all the AttrOrTypeDef for the specified dialect. If no dialect
3134
/// specified and can only find one dialect's defs, use that.
3235
static void collectAllDefs(StringRef selectedDialect,
33-
ArrayRef<const llvm::Record *> records,
36+
ArrayRef<const Record *> records,
3437
SmallVectorImpl<AttrOrTypeDef> &resultDefs) {
3538
// Nothing to do if no defs were found.
3639
if (records.empty())
3740
return;
3841

3942
auto defs = llvm::map_range(
40-
records, [&](const llvm::Record *rec) { return AttrOrTypeDef(rec); });
43+
records, [&](const Record *rec) { return AttrOrTypeDef(rec); });
4144
if (selectedDialect.empty()) {
4245
// If a dialect was not specified, ensure that all found defs belong to the
4346
// same dialect.
@@ -690,15 +693,14 @@ class DefGenerator {
690693
bool emitDefs(StringRef selectedDialect);
691694

692695
protected:
693-
DefGenerator(ArrayRef<const llvm::Record *> defs, raw_ostream &os,
696+
DefGenerator(ArrayRef<const Record *> defs, raw_ostream &os,
694697
StringRef defType, StringRef valueType, bool isAttrGenerator)
695698
: defRecords(defs), os(os), defType(defType), valueType(valueType),
696699
isAttrGenerator(isAttrGenerator) {
697700
// Sort by occurrence in file.
698-
llvm::sort(defRecords,
699-
[](const llvm::Record *lhs, const llvm::Record *rhs) {
700-
return lhs->getID() < rhs->getID();
701-
});
701+
llvm::sort(defRecords, [](const Record *lhs, const Record *rhs) {
702+
return lhs->getID() < rhs->getID();
703+
});
702704
}
703705

704706
/// Emit the list of def type names.
@@ -707,7 +709,7 @@ class DefGenerator {
707709
void emitParsePrintDispatch(ArrayRef<AttrOrTypeDef> defs);
708710

709711
/// The set of def records to emit.
710-
std::vector<const llvm::Record *> defRecords;
712+
std::vector<const Record *> defRecords;
711713
/// The attribute or type class to emit.
712714
/// The stream to emit to.
713715
raw_ostream &os;
@@ -722,13 +724,13 @@ class DefGenerator {
722724

723725
/// A specialized generator for AttrDefs.
724726
struct AttrDefGenerator : public DefGenerator {
725-
AttrDefGenerator(const llvm::RecordKeeper &records, raw_ostream &os)
727+
AttrDefGenerator(const RecordKeeper &records, raw_ostream &os)
726728
: DefGenerator(records.getAllDerivedDefinitionsIfDefined("AttrDef"), os,
727729
"Attr", "Attribute", /*isAttrGenerator=*/true) {}
728730
};
729731
/// A specialized generator for TypeDefs.
730732
struct TypeDefGenerator : public DefGenerator {
731-
TypeDefGenerator(const llvm::RecordKeeper &records, raw_ostream &os)
733+
TypeDefGenerator(const RecordKeeper &records, raw_ostream &os)
732734
: DefGenerator(records.getAllDerivedDefinitionsIfDefined("TypeDef"), os,
733735
"Type", "Type", /*isAttrGenerator=*/false) {}
734736
};
@@ -1030,9 +1032,9 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
10301032

10311033
/// Find all type constraints for which a C++ function should be generated.
10321034
static std::vector<Constraint>
1033-
getAllTypeConstraints(const llvm::RecordKeeper &records) {
1035+
getAllTypeConstraints(const RecordKeeper &records) {
10341036
std::vector<Constraint> result;
1035-
for (const llvm::Record *def :
1037+
for (const Record *def :
10361038
records.getAllDerivedDefinitionsIfDefined("TypeConstraint")) {
10371039
// Ignore constraints defined outside of the top-level file.
10381040
if (llvm::SrcMgr.FindBufferContainingLoc(def->getLoc()[0]) !=
@@ -1047,7 +1049,7 @@ getAllTypeConstraints(const llvm::RecordKeeper &records) {
10471049
return result;
10481050
}
10491051

1050-
static void emitTypeConstraintDecls(const llvm::RecordKeeper &records,
1052+
static void emitTypeConstraintDecls(const RecordKeeper &records,
10511053
raw_ostream &os) {
10521054
static const char *const typeConstraintDecl = R"(
10531055
bool {0}(::mlir::Type type);
@@ -1057,7 +1059,7 @@ bool {0}(::mlir::Type type);
10571059
os << strfmt(typeConstraintDecl, *constr.getCppFunctionName());
10581060
}
10591061

1060-
static void emitTypeConstraintDefs(const llvm::RecordKeeper &records,
1062+
static void emitTypeConstraintDefs(const RecordKeeper &records,
10611063
raw_ostream &os) {
10621064
static const char *const typeConstraintDef = R"(
10631065
bool {0}(::mlir::Type type) {
@@ -1080,58 +1082,57 @@ bool {0}(::mlir::Type type) {
10801082
//===----------------------------------------------------------------------===//
10811083
// AttrDef
10821084

1083-
static llvm::cl::OptionCategory attrdefGenCat("Options for -gen-attrdef-*");
1084-
static llvm::cl::opt<std::string>
1085+
static cl::OptionCategory attrdefGenCat("Options for -gen-attrdef-*");
1086+
static cl::opt<std::string>
10851087
attrDialect("attrdefs-dialect",
1086-
llvm::cl::desc("Generate attributes for this dialect"),
1087-
llvm::cl::cat(attrdefGenCat), llvm::cl::CommaSeparated);
1088+
cl::desc("Generate attributes for this dialect"),
1089+
cl::cat(attrdefGenCat), cl::CommaSeparated);
10881090

10891091
static mlir::GenRegistration
10901092
genAttrDefs("gen-attrdef-defs", "Generate AttrDef definitions",
1091-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
1093+
[](const RecordKeeper &records, raw_ostream &os) {
10921094
AttrDefGenerator generator(records, os);
10931095
return generator.emitDefs(attrDialect);
10941096
});
10951097
static mlir::GenRegistration
10961098
genAttrDecls("gen-attrdef-decls", "Generate AttrDef declarations",
1097-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
1099+
[](const RecordKeeper &records, raw_ostream &os) {
10981100
AttrDefGenerator generator(records, os);
10991101
return generator.emitDecls(attrDialect);
11001102
});
11011103

11021104
//===----------------------------------------------------------------------===//
11031105
// TypeDef
11041106

1105-
static llvm::cl::OptionCategory typedefGenCat("Options for -gen-typedef-*");
1106-
static llvm::cl::opt<std::string>
1107-
typeDialect("typedefs-dialect",
1108-
llvm::cl::desc("Generate types for this dialect"),
1109-
llvm::cl::cat(typedefGenCat), llvm::cl::CommaSeparated);
1107+
static cl::OptionCategory typedefGenCat("Options for -gen-typedef-*");
1108+
static cl::opt<std::string>
1109+
typeDialect("typedefs-dialect", cl::desc("Generate types for this dialect"),
1110+
cl::cat(typedefGenCat), cl::CommaSeparated);
11101111

11111112
static mlir::GenRegistration
11121113
genTypeDefs("gen-typedef-defs", "Generate TypeDef definitions",
1113-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
1114+
[](const RecordKeeper &records, raw_ostream &os) {
11141115
TypeDefGenerator generator(records, os);
11151116
return generator.emitDefs(typeDialect);
11161117
});
11171118
static mlir::GenRegistration
11181119
genTypeDecls("gen-typedef-decls", "Generate TypeDef declarations",
1119-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
1120+
[](const RecordKeeper &records, raw_ostream &os) {
11201121
TypeDefGenerator generator(records, os);
11211122
return generator.emitDecls(typeDialect);
11221123
});
11231124

11241125
static mlir::GenRegistration
11251126
genTypeConstrDefs("gen-type-constraint-defs",
11261127
"Generate type constraint definitions",
1127-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
1128+
[](const RecordKeeper &records, raw_ostream &os) {
11281129
emitTypeConstraintDefs(records, os);
11291130
return false;
11301131
});
11311132
static mlir::GenRegistration
11321133
genTypeConstrDecls("gen-type-constraint-decls",
11331134
"Generate type constraint declarations",
1134-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
1135+
[](const RecordKeeper &records, raw_ostream &os) {
11351136
emitTypeConstraintDecls(records, os);
11361137
return false;
11371138
});

mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
using namespace llvm;
2020

21-
static llvm::cl::OptionCategory dialectGenCat("Options for -gen-bytecode");
22-
static llvm::cl::opt<std::string>
23-
selectedBcDialect("bytecode-dialect",
24-
llvm::cl::desc("The dialect to gen for"),
25-
llvm::cl::cat(dialectGenCat), llvm::cl::CommaSeparated);
21+
static cl::OptionCategory dialectGenCat("Options for -gen-bytecode");
22+
static cl::opt<std::string>
23+
selectedBcDialect("bytecode-dialect", cl::desc("The dialect to gen for"),
24+
cl::cat(dialectGenCat), cl::CommaSeparated);
2625

2726
namespace {
2827

@@ -306,7 +305,7 @@ void Generator::emitPrint(StringRef kind, StringRef type,
306305
auto funScope = os.scope("{\n", "}\n\n");
307306

308307
// Check that predicates specified if multiple bytecode instances.
309-
for (const llvm::Record *rec : make_second_range(vec)) {
308+
for (const Record *rec : make_second_range(vec)) {
310309
StringRef pred = rec->getValueAsString("printerPredicate");
311310
if (vec.size() > 1 && pred.empty()) {
312311
for (auto [index, rec] : vec) {

mlir/tools/mlir-tblgen/DialectGen.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@
3030

3131
using namespace mlir;
3232
using namespace mlir::tblgen;
33+
using llvm::Record;
34+
using llvm::RecordKeeper;
35+
namespace cl = llvm::cl;
3336

34-
static llvm::cl::OptionCategory dialectGenCat("Options for -gen-dialect-*");
35-
llvm::cl::opt<std::string>
36-
selectedDialect("dialect", llvm::cl::desc("The dialect to gen for"),
37-
llvm::cl::cat(dialectGenCat), llvm::cl::CommaSeparated);
37+
static cl::OptionCategory dialectGenCat("Options for -gen-dialect-*");
38+
cl::opt<std::string> selectedDialect("dialect",
39+
cl::desc("The dialect to gen for"),
40+
cl::cat(dialectGenCat),
41+
cl::CommaSeparated);
3842

3943
/// Utility iterator used for filtering records for a specific dialect.
4044
namespace {
4145
using DialectFilterIterator =
42-
llvm::filter_iterator<ArrayRef<llvm::Record *>::iterator,
43-
std::function<bool(const llvm::Record *)>>;
46+
llvm::filter_iterator<ArrayRef<Record *>::iterator,
47+
std::function<bool(const Record *)>>;
4448
} // namespace
4549

4650
static void populateDiscardableAttributes(
@@ -62,8 +66,8 @@ static void populateDiscardableAttributes(
6266
/// the given dialect.
6367
template <typename T>
6468
static iterator_range<DialectFilterIterator>
65-
filterForDialect(ArrayRef<llvm::Record *> records, Dialect &dialect) {
66-
auto filterFn = [&](const llvm::Record *record) {
69+
filterForDialect(ArrayRef<Record *> records, Dialect &dialect) {
70+
auto filterFn = [&](const Record *record) {
6771
return T(record).getDialect() == dialect;
6872
};
6973
return {DialectFilterIterator(records.begin(), records.end(), filterFn),
@@ -295,7 +299,7 @@ static void emitDialectDecl(Dialect &dialect, raw_ostream &os) {
295299
<< "::" << dialect.getCppClassName() << ")\n";
296300
}
297301

298-
static bool emitDialectDecls(const llvm::RecordKeeper &recordKeeper,
302+
static bool emitDialectDecls(const RecordKeeper &recordKeeper,
299303
raw_ostream &os) {
300304
emitSourceFileHeader("Dialect Declarations", os, recordKeeper);
301305

@@ -340,8 +344,7 @@ static const char *const dialectDestructorStr = R"(
340344
341345
)";
342346

343-
static void emitDialectDef(Dialect &dialect,
344-
const llvm::RecordKeeper &recordKeeper,
347+
static void emitDialectDef(Dialect &dialect, const RecordKeeper &recordKeeper,
345348
raw_ostream &os) {
346349
std::string cppClassName = dialect.getCppClassName();
347350

@@ -389,8 +392,7 @@ static void emitDialectDef(Dialect &dialect,
389392
os << llvm::formatv(dialectDestructorStr, cppClassName);
390393
}
391394

392-
static bool emitDialectDefs(const llvm::RecordKeeper &recordKeeper,
393-
raw_ostream &os) {
395+
static bool emitDialectDefs(const RecordKeeper &recordKeeper, raw_ostream &os) {
394396
emitSourceFileHeader("Dialect Definitions", os, recordKeeper);
395397

396398
auto dialectDefs = recordKeeper.getAllDerivedDefinitions("Dialect");
@@ -411,12 +413,12 @@ static bool emitDialectDefs(const llvm::RecordKeeper &recordKeeper,
411413

412414
static mlir::GenRegistration
413415
genDialectDecls("gen-dialect-decls", "Generate dialect declarations",
414-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
416+
[](const RecordKeeper &records, raw_ostream &os) {
415417
return emitDialectDecls(records, os);
416418
});
417419

418420
static mlir::GenRegistration
419421
genDialectDefs("gen-dialect-defs", "Generate dialect definitions",
420-
[](const llvm::RecordKeeper &records, raw_ostream &os) {
422+
[](const RecordKeeper &records, raw_ostream &os) {
421423
return emitDialectDefs(records, os);
422424
});

mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using llvm::ClauseVal;
2525
using llvm::raw_ostream;
2626
using llvm::Record;
2727
using llvm::RecordKeeper;
28+
namespace cl = llvm::cl;
2829

2930
// LLVM has multiple places (Clang, Flang, MLIR) where information about
3031
// the directives (OpenMP/OpenACC), and clauses are needed. It is good software
@@ -96,12 +97,11 @@ static bool emitDecls(const RecordKeeper &recordKeeper, llvm::StringRef dialect,
9697
return false;
9798
}
9899

99-
static llvm::cl::OptionCategory
100-
directiveGenCat("Options for gen-directive-decl");
101-
static llvm::cl::opt<std::string>
100+
static cl::OptionCategory directiveGenCat("Options for gen-directive-decl");
101+
static cl::opt<std::string>
102102
dialect("directives-dialect",
103-
llvm::cl::desc("Generate directives for this dialect"),
104-
llvm::cl::cat(directiveGenCat), llvm::cl::CommaSeparated);
103+
cl::desc("Generate directives for this dialect"),
104+
cl::cat(directiveGenCat), cl::CommaSeparated);
105105

106106
// Registers the generator to mlir-tblgen.
107107
static mlir::GenRegistration genDirectiveDecls(

0 commit comments

Comments
 (0)