22
22
23
23
using namespace mlir ;
24
24
using namespace mlir ::tblgen;
25
+ using llvm::Record;
26
+ using llvm::RecordKeeper;
25
27
26
28
// ===----------------------------------------------------------------------===//
27
29
// Utility Functions
@@ -30,14 +32,14 @@ using namespace mlir::tblgen;
30
32
// / Find all the AttrOrTypeDef for the specified dialect. If no dialect
31
33
// / specified and can only find one dialect's defs, use that.
32
34
static void collectAllDefs (StringRef selectedDialect,
33
- ArrayRef<const llvm:: Record *> records,
35
+ ArrayRef<const Record *> records,
34
36
SmallVectorImpl<AttrOrTypeDef> &resultDefs) {
35
37
// Nothing to do if no defs were found.
36
38
if (records.empty ())
37
39
return ;
38
40
39
41
auto defs = llvm::map_range (
40
- records, [&](const llvm:: Record *rec) { return AttrOrTypeDef (rec); });
42
+ records, [&](const Record *rec) { return AttrOrTypeDef (rec); });
41
43
if (selectedDialect.empty ()) {
42
44
// If a dialect was not specified, ensure that all found defs belong to the
43
45
// same dialect.
@@ -690,15 +692,14 @@ class DefGenerator {
690
692
bool emitDefs (StringRef selectedDialect);
691
693
692
694
protected:
693
- DefGenerator (ArrayRef<const llvm:: Record *> defs, raw_ostream &os,
695
+ DefGenerator (ArrayRef<const Record *> defs, raw_ostream &os,
694
696
StringRef defType, StringRef valueType, bool isAttrGenerator)
695
697
: defRecords(defs), os(os), defType(defType), valueType(valueType),
696
698
isAttrGenerator (isAttrGenerator) {
697
699
// 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
- });
700
+ llvm::sort (defRecords, [](const Record *lhs, const Record *rhs) {
701
+ return lhs->getID () < rhs->getID ();
702
+ });
702
703
}
703
704
704
705
// / Emit the list of def type names.
@@ -707,7 +708,7 @@ class DefGenerator {
707
708
void emitParsePrintDispatch (ArrayRef<AttrOrTypeDef> defs);
708
709
709
710
// / The set of def records to emit.
710
- std::vector<const llvm:: Record *> defRecords;
711
+ std::vector<const Record *> defRecords;
711
712
// / The attribute or type class to emit.
712
713
// / The stream to emit to.
713
714
raw_ostream &os;
@@ -722,13 +723,13 @@ class DefGenerator {
722
723
723
724
// / A specialized generator for AttrDefs.
724
725
struct AttrDefGenerator : public DefGenerator {
725
- AttrDefGenerator (const llvm:: RecordKeeper &records, raw_ostream &os)
726
+ AttrDefGenerator (const RecordKeeper &records, raw_ostream &os)
726
727
: DefGenerator(records.getAllDerivedDefinitionsIfDefined(" AttrDef" ), os,
727
728
" Attr" , " Attribute" , /* isAttrGenerator=*/ true ) {}
728
729
};
729
730
// / A specialized generator for TypeDefs.
730
731
struct TypeDefGenerator : public DefGenerator {
731
- TypeDefGenerator (const llvm:: RecordKeeper &records, raw_ostream &os)
732
+ TypeDefGenerator (const RecordKeeper &records, raw_ostream &os)
732
733
: DefGenerator(records.getAllDerivedDefinitionsIfDefined(" TypeDef" ), os,
733
734
" Type" , " Type" , /* isAttrGenerator=*/ false ) {}
734
735
};
@@ -1030,9 +1031,9 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
1030
1031
1031
1032
// / Find all type constraints for which a C++ function should be generated.
1032
1033
static std::vector<Constraint>
1033
- getAllTypeConstraints (const llvm:: RecordKeeper &records) {
1034
+ getAllTypeConstraints (const RecordKeeper &records) {
1034
1035
std::vector<Constraint> result;
1035
- for (const llvm:: Record *def :
1036
+ for (const Record *def :
1036
1037
records.getAllDerivedDefinitionsIfDefined (" TypeConstraint" )) {
1037
1038
// Ignore constraints defined outside of the top-level file.
1038
1039
if (llvm::SrcMgr.FindBufferContainingLoc (def->getLoc ()[0 ]) !=
@@ -1047,7 +1048,7 @@ getAllTypeConstraints(const llvm::RecordKeeper &records) {
1047
1048
return result;
1048
1049
}
1049
1050
1050
- static void emitTypeConstraintDecls (const llvm:: RecordKeeper &records,
1051
+ static void emitTypeConstraintDecls (const RecordKeeper &records,
1051
1052
raw_ostream &os) {
1052
1053
static const char *const typeConstraintDecl = R"(
1053
1054
bool {0}(::mlir::Type type);
@@ -1057,7 +1058,7 @@ bool {0}(::mlir::Type type);
1057
1058
os << strfmt (typeConstraintDecl, *constr.getCppFunctionName ());
1058
1059
}
1059
1060
1060
- static void emitTypeConstraintDefs (const llvm:: RecordKeeper &records,
1061
+ static void emitTypeConstraintDefs (const RecordKeeper &records,
1061
1062
raw_ostream &os) {
1062
1063
static const char *const typeConstraintDef = R"(
1063
1064
bool {0}(::mlir::Type type) {
@@ -1088,13 +1089,13 @@ static llvm::cl::opt<std::string>
1088
1089
1089
1090
static mlir::GenRegistration
1090
1091
genAttrDefs (" gen-attrdef-defs" , " Generate AttrDef definitions" ,
1091
- [](const llvm:: RecordKeeper &records, raw_ostream &os) {
1092
+ [](const RecordKeeper &records, raw_ostream &os) {
1092
1093
AttrDefGenerator generator (records, os);
1093
1094
return generator.emitDefs (attrDialect);
1094
1095
});
1095
1096
static mlir::GenRegistration
1096
1097
genAttrDecls (" gen-attrdef-decls" , " Generate AttrDef declarations" ,
1097
- [](const llvm:: RecordKeeper &records, raw_ostream &os) {
1098
+ [](const RecordKeeper &records, raw_ostream &os) {
1098
1099
AttrDefGenerator generator (records, os);
1099
1100
return generator.emitDecls (attrDialect);
1100
1101
});
@@ -1110,28 +1111,28 @@ static llvm::cl::opt<std::string>
1110
1111
1111
1112
static mlir::GenRegistration
1112
1113
genTypeDefs (" gen-typedef-defs" , " Generate TypeDef definitions" ,
1113
- [](const llvm:: RecordKeeper &records, raw_ostream &os) {
1114
+ [](const RecordKeeper &records, raw_ostream &os) {
1114
1115
TypeDefGenerator generator (records, os);
1115
1116
return generator.emitDefs (typeDialect);
1116
1117
});
1117
1118
static mlir::GenRegistration
1118
1119
genTypeDecls (" gen-typedef-decls" , " Generate TypeDef declarations" ,
1119
- [](const llvm:: RecordKeeper &records, raw_ostream &os) {
1120
+ [](const RecordKeeper &records, raw_ostream &os) {
1120
1121
TypeDefGenerator generator (records, os);
1121
1122
return generator.emitDecls (typeDialect);
1122
1123
});
1123
1124
1124
1125
static mlir::GenRegistration
1125
1126
genTypeConstrDefs (" gen-type-constraint-defs" ,
1126
1127
" Generate type constraint definitions" ,
1127
- [](const llvm:: RecordKeeper &records, raw_ostream &os) {
1128
+ [](const RecordKeeper &records, raw_ostream &os) {
1128
1129
emitTypeConstraintDefs (records, os);
1129
1130
return false ;
1130
1131
});
1131
1132
static mlir::GenRegistration
1132
1133
genTypeConstrDecls (" gen-type-constraint-decls" ,
1133
1134
" Generate type constraint declarations" ,
1134
- [](const llvm:: RecordKeeper &records, raw_ostream &os) {
1135
+ [](const RecordKeeper &records, raw_ostream &os) {
1135
1136
emitTypeConstraintDecls (records, os);
1136
1137
return false ;
1137
1138
});
0 commit comments