Skip to content

Commit df295fa

Browse files
Revert "Give attributes C++ namespaces."
This reverts commit 0a34492. This change turned out to be very intrusive wrt some internal projects. Reverting until this can be sorted out.
1 parent e4e23c5 commit df295fa

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

mlir/include/mlir/IR/OpBase.td

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -791,16 +791,12 @@ class Attr<Pred condition, string descr = ""> :
791791
// instantiation.
792792
// TOOD(b/132458159): deduplicate the fields in attribute wrapper classes.
793793
Attr baseAttr = ?;
794-
795-
// The fully-qualified C++ namespace where the generated class lives.
796-
string cppNamespace = "";
797794
}
798795

799796
// An attribute of a specific dialect.
800797
class DialectAttr<Dialect d, Pred condition, string descr = ""> :
801798
Attr<condition, descr> {
802799
Dialect dialect = d;
803-
let cppNamespace = d.cppNamespace;
804800
}
805801

806802
//===----------------------------------------------------------------------===//
@@ -1119,6 +1115,16 @@ class EnumAttrInfo<string name, list<EnumAttrCaseInfo> cases> {
11191115
// underlying type is not explicitly specified.
11201116
string underlyingType = "";
11211117

1118+
// The C++ namespaces that the enum class definition and utility functions
1119+
// should be placed into.
1120+
//
1121+
// Normally you want to place the full namespace path here. If it is nested,
1122+
// use "::" as the delimiter, e.g., given "A::B", generated code will be
1123+
// placed in `namespace A { namespace B { ... } }`. To avoid placing in any
1124+
// namespace, use "".
1125+
// TODO: use dialect to provide the namespace.
1126+
string cppNamespace = "";
1127+
11221128
// The name of the utility function that converts a value of the underlying
11231129
// type to the corresponding symbol. It will have the following signature:
11241130
//
@@ -1457,25 +1463,22 @@ class StructFieldAttr<string thisName, Attr thisType> {
14571463
// useful when representing data that would normally be in a structure.
14581464
class StructAttr<string name, Dialect d,
14591465
list<StructFieldAttr> attributes> :
1460-
DictionaryAttrBase<CPred<"$_self.isa<" # d.cppNamespace
1461-
# "::" # name # ">()">,
1466+
DictionaryAttrBase<CPred<"$_self.isa<" # name # ">()">,
14621467
"DictionaryAttr with field(s): " #
14631468
StrJoin<!foreach(a, attributes, "'" # a.name # "'"), ", ">.result #
14641469
" (each field having its own constraints)"> {
14651470
// Name for this StructAttr.
14661471
string className = name;
14671472

14681473
// Return type should match the name of the structure.
1469-
let returnType = d.cppNamespace # "::" # name;
1474+
let returnType = name;
14701475

14711476
// Storage type should match the name of the structure.
1472-
let storageType = d.cppNamespace # "::" # name;
1477+
let storageType = name;
14731478

14741479
// The dialect this StructAttr belongs to.
14751480
Dialect dialect = d;
14761481

1477-
let cppNamespace = d.cppNamespace;
1478-
14791482
// List of fields that the StructAttr contains.
14801483
list<StructFieldAttr> fields = attributes;
14811484
}

mlir/lib/TableGen/Pattern.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ std::string SymbolInfoMap::SymbolInfo::getVarDecl(StringRef name) const {
219219
case Kind::Operand: {
220220
// Use operand range for captured operands (to support potential variadic
221221
// operands).
222-
return std::string(formatv(
223-
"::mlir::Operation::operand_range {0}(op0->getOperands());\n", name));
222+
return std::string(
223+
formatv("Operation::operand_range {0}(op0->getOperands());\n", name));
224224
}
225225
case Kind::Value: {
226-
return std::string(formatv("::llvm::ArrayRef<::mlir::Value> {0};\n", name));
226+
return std::string(formatv("ArrayRef<Value> {0};\n", name));
227227
}
228228
case Kind::Result: {
229229
// Use the op itself for captured results.

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,16 @@ void OpEmitter::genAttrGetters() {
487487

488488
// Emit with return type specified.
489489
auto emitAttrWithReturnType = [&](StringRef name, Attribute attr) {
490-
auto *method = opClass.addMethodAndPrune(attr.getReturnType(), name);
490+
Dialect attrDialect = attr.getDialect();
491+
// Does the current operation have a different namespace than the attribute?
492+
bool differentNamespace =
493+
attrDialect && opDialect && attrDialect != opDialect;
494+
std::string returnType = differentNamespace
495+
? (llvm::Twine(attrDialect.getCppNamespace()) +
496+
"::" + attr.getReturnType())
497+
.str()
498+
: attr.getReturnType().str();
499+
auto *method = opClass.addMethodAndPrune(returnType, name);
491500
auto &body = method->body();
492501
body << " auto attr = " << name << "Attr();\n";
493502
if (attr.hasDefaultValue()) {
@@ -1991,8 +2000,8 @@ void OpEmitter::genOpAsmInterface() {
19912000
opClass.addTrait("::mlir::OpAsmOpInterface::Trait");
19922001

19932002
// Generate the right accessor for the number of results.
1994-
auto *method = opClass.addMethodAndPrune(
1995-
"void", "getAsmResultNames", "::mlir::OpAsmSetValueNameFn", "setNameFn");
2003+
auto *method = opClass.addMethodAndPrune("void", "getAsmResultNames",
2004+
"OpAsmSetValueNameFn", "setNameFn");
19962005
auto &body = method->body();
19972006
for (int i = 0; i != numResults; ++i) {
19982007
body << " auto resultGroup" << i << " = getODSResults(" << i << ");\n"

mlir/tools/mlir-tblgen/RewriterGen.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ void PatternEmitter::emitOpMatch(DagNode tree, int depth) {
221221

222222
int indent = 4 + 2 * depth;
223223
os.indent(indent) << formatv(
224-
"auto castedOp{0} = ::llvm::dyn_cast_or_null<{1}>(op{0}); "
225-
"(void)castedOp{0};\n",
224+
"auto castedOp{0} = dyn_cast_or_null<{1}>(op{0}); (void)castedOp{0};\n",
226225
depth, op.getQualCppClassName());
227226
// Skip the operand matching at depth 0 as the pattern rewriter already does.
228227
if (depth != 0) {
@@ -536,7 +535,7 @@ void PatternEmitter::emit(StringRef rewriteName) {
536535
os << "\n// Rewrite\n";
537536
emitRewriteLogic();
538537

539-
os << "return ::mlir::success();\n";
538+
os << "return success();\n";
540539
}
541540
os << "};\n";
542541
}
@@ -1146,8 +1145,8 @@ static void emitRewriters(const RecordKeeper &recordKeeper, raw_ostream &os) {
11461145
}
11471146

11481147
// Emit function to add the generated matchers to the pattern list.
1149-
os << "void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(::mlir::MLIRContext "
1150-
"*context, ::mlir::OwningRewritePatternList *patterns) {\n";
1148+
os << "void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(MLIRContext "
1149+
"*context, OwningRewritePatternList *patterns) {\n";
11511150
for (const auto &name : rewriterNames) {
11521151
os << " patterns->insert<" << name << ">(context);\n";
11531152
}

0 commit comments

Comments
 (0)