diff --git a/mlir/docs/DataLayout.md b/mlir/docs/DataLayout.md --- a/mlir/docs/DataLayout.md +++ b/mlir/docs/DataLayout.md @@ -102,7 +102,7 @@ _entries_. Data layout specification attributes implement the `DataLayoutSpecInterface`, described below. Each entry is itself an attribute that implements the `DataLayoutEntryInterface`. Entries have a key, either a -`Type` or an `Identifier`, and a value. Keys are used to associate entries with +`Type` or a `StringAttr`, and a value. Keys are used to associate entries with specific types or dialects: when handling a data layout properties request, a type or a dialect can only see the specification entries relevant to them and must go through the supplied `DataLayout` object for any recursive query. This diff --git a/mlir/docs/Interfaces.md b/mlir/docs/Interfaces.md --- a/mlir/docs/Interfaces.md +++ b/mlir/docs/Interfaces.md @@ -327,7 +327,7 @@ ```c++ void *TestDialect::getRegisteredInterfaceForOp(TypeID typeID, - Identifier opName) { + StringAttr opName) { if (typeID == TypeID::get()) { if (isSupported(opName)) return fallbackExampleOpInterface; diff --git a/mlir/docs/Tutorials/DataFlowAnalysis.md b/mlir/docs/Tutorials/DataFlowAnalysis.md --- a/mlir/docs/Tutorials/DataFlowAnalysis.md +++ b/mlir/docs/Tutorials/DataFlowAnalysis.md @@ -137,7 +137,7 @@ /// Our value represents the combined metadata, which is originally a /// DictionaryAttr, so we use a map. - DenseMap metadata; + DenseMap metadata; }; ``` diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp @@ -93,7 +93,7 @@ /// Helper conversion for a Toy AST location to an MLIR location. mlir::Location loc(Location loc) { - return mlir::FileLineColLoc::get(builder.getIdentifier(*loc.file), loc.line, + return mlir::FileLineColLoc::get(builder.getStringAttr(*loc.file), loc.line, loc.col); } diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp @@ -93,7 +93,7 @@ /// Helper conversion for a Toy AST location to an MLIR location. mlir::Location loc(Location loc) { - return mlir::FileLineColLoc::get(builder.getIdentifier(*loc.file), loc.line, + return mlir::FileLineColLoc::get(builder.getStringAttr(*loc.file), loc.line, loc.col); } diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp @@ -93,7 +93,7 @@ /// Helper conversion for a Toy AST location to an MLIR location. mlir::Location loc(Location loc) { - return mlir::FileLineColLoc::get(builder.getIdentifier(*loc.file), loc.line, + return mlir::FileLineColLoc::get(builder.getStringAttr(*loc.file), loc.line, loc.col); } diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp @@ -93,7 +93,7 @@ /// Helper conversion for a Toy AST location to an MLIR location. mlir::Location loc(Location loc) { - return mlir::FileLineColLoc::get(builder.getIdentifier(*loc.file), loc.line, + return mlir::FileLineColLoc::get(builder.getStringAttr(*loc.file), loc.line, loc.col); } diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp @@ -93,7 +93,7 @@ /// Helper conversion for a Toy AST location to an MLIR location. mlir::Location loc(Location loc) { - return mlir::FileLineColLoc::get(builder.getIdentifier(*loc.file), loc.line, + return mlir::FileLineColLoc::get(builder.getStringAttr(*loc.file), loc.line, loc.col); } diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp @@ -113,7 +113,7 @@ /// Helper conversion for a Toy AST location to an MLIR location. mlir::Location loc(Location loc) { - return mlir::FileLineColLoc::get(builder.getIdentifier(*loc.file), loc.line, + return mlir::FileLineColLoc::get(builder.getStringAttr(*loc.file), loc.line, loc.col); } diff --git a/mlir/include/mlir/CAPI/IR.h b/mlir/include/mlir/CAPI/IR.h --- a/mlir/include/mlir/CAPI/IR.h +++ b/mlir/include/mlir/CAPI/IR.h @@ -17,7 +17,6 @@ #include "mlir/CAPI/Wrap.h" #include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/Identifier.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Operation.h" diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td b/mlir/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td --- a/mlir/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td @@ -167,7 +167,7 @@ ConcreteOp op = cast(this->getOperation()); assert(memref == op.getMemRef() && "Expected memref argument to match memref operand"); - return {Identifier::get(op.getMapAttrName(), op.getContext()), + return {StringAttr::get(op.getContext(), op.getMapAttrName()), op.getAffineMapAttr()}; }] >, diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h @@ -188,14 +188,14 @@ /// Returns the AffineMapAttr associated with 'memref'. NamedAttribute getAffineMapAttrForMemRef(Value memref) { if (memref == getSrcMemRef()) - return {Identifier::get(getSrcMapAttrName(), getContext()), + return {StringAttr::get(getContext(), getSrcMapAttrName()), getSrcMapAttr()}; if (memref == getDstMemRef()) - return {Identifier::get(getDstMapAttrName(), getContext()), + return {StringAttr::get(getContext(), getDstMapAttrName()), getDstMapAttr()}; assert(memref == getTagMemRef() && "DmaStartOp expected source, destination or tag memref"); - return {Identifier::get(getTagMapAttrName(), getContext()), + return {StringAttr::get(getContext(), getTagMapAttrName()), getTagMapAttr()}; } @@ -303,7 +303,7 @@ /// associated with 'memref'. NamedAttribute getAffineMapAttrForMemRef(Value memref) { assert(memref == getTagMemRef()); - return {Identifier::get(getTagMapAttrName(), getContext()), + return {StringAttr::get(getContext(), getTagMapAttrName()), getTagMapAttr()}; } diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td @@ -309,7 +309,7 @@ void setStep(int64_t step) { assert(step > 0 && "step has to be a positive integer constant"); auto *context = getLowerBoundMap().getContext(); - (*this)->setAttr(Identifier::get(getStepAttrName(), context), + (*this)->setAttr(StringAttr::get(context, getStepAttrName()), IntegerAttr::get(IndexType::get(context), step)); } @@ -815,7 +815,7 @@ NamedAttribute getAffineMapAttrForMemRef(Value mref) { assert(mref == memref() && "Expected mref argument to match memref operand"); - return {Identifier::get(getMapAttrName(), getContext()), + return {StringAttr::get(getContext(), getMapAttrName()), getAffineMapAttr()}; } diff --git a/mlir/include/mlir/Dialect/DLTI/DLTI.h b/mlir/include/mlir/Dialect/DLTI/DLTI.h --- a/mlir/include/mlir/Dialect/DLTI/DLTI.h +++ b/mlir/include/mlir/Dialect/DLTI/DLTI.h @@ -41,7 +41,7 @@ constexpr const static llvm::StringLiteral kAttrKeyword = "dl_entry"; /// Returns the entry with the given key and value. - static DataLayoutEntryAttr get(Identifier key, Attribute value); + static DataLayoutEntryAttr get(StringAttr key, Attribute value); static DataLayoutEntryAttr get(Type key, Attribute value); /// Returns the key of this entry. diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -17,7 +17,6 @@ #include "mlir/Dialect/Utils/StaticValueUtils.h" #include "mlir/Dialect/Vector/VectorTransforms.h" #include "mlir/Dialect/X86Vector/Transforms.h" -#include "mlir/IR/Identifier.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Transforms/Bufferize.h" #include "llvm/ADT/SmallBitVector.h" @@ -426,12 +425,12 @@ using FilterFunction = std::function; explicit LinalgTransformationFilter( - ArrayRef matchDisjunction = {}, - Optional replacement = None); + ArrayRef matchDisjunction = {}, + Optional replacement = None); explicit LinalgTransformationFilter( - FilterFunction f, ArrayRef matchDisjunction = {}, - Optional replacement = None); + FilterFunction f, ArrayRef matchDisjunction = {}, + Optional replacement = None); LinalgTransformationFilter(LinalgTransformationFilter &&) = default; LinalgTransformationFilter(const LinalgTransformationFilter &) = default; @@ -456,8 +455,8 @@ private: SmallVector filters; - SmallVector matchDisjunction; - Optional replacement; + SmallVector matchDisjunction; + Optional replacement; /// When set to true, if the attribute is not set, it will be treated as /// a match. Default is false. bool matchByDefault; diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h --- a/mlir/include/mlir/IR/Attributes.h +++ b/mlir/include/mlir/IR/Attributes.h @@ -136,10 +136,10 @@ // NamedAttribute //===----------------------------------------------------------------------===// -/// NamedAttribute is combination of a name, represented by an Identifier, and a +/// NamedAttribute is combination of a name, represented by a StringAttr, and a /// value, represented by an Attribute. The attribute pointer should always be /// non-null. -using NamedAttribute = std::pair; +using NamedAttribute = std::pair; bool operator<(const NamedAttribute &lhs, const NamedAttribute &rhs); bool operator<(const NamedAttribute &lhs, StringRef rhs); diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -53,7 +53,7 @@ MLIRContext *getContext() const { return context; } - Identifier getIdentifier(const Twine &str); + StringAttr getIdentifier(const Twine &str); // Locations. Location getUnknownLoc(); diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td --- a/mlir/include/mlir/IR/BuiltinAttributes.td +++ b/mlir/include/mlir/IR/BuiltinAttributes.td @@ -379,15 +379,15 @@ /// Return the specified attribute if present, null otherwise. Attribute get(StringRef name) const; - Attribute get(Identifier name) const; + Attribute get(StringAttr name) const; /// Return the specified named attribute if present, None otherwise. Optional getNamed(StringRef name) const; - Optional getNamed(Identifier name) const; + Optional getNamed(StringAttr name) const; /// Return whether the specified attribute is present. bool contains(StringRef name) const; - bool contains(Identifier name) const; + bool contains(StringAttr name) const; /// Support range iteration. using iterator = llvm::ArrayRef::iterator; @@ -641,11 +641,11 @@ #dialect<"opaque attribute data"> ``` }]; - let parameters = (ins "Identifier":$dialectNamespace, + let parameters = (ins "StringAttr":$dialectNamespace, StringRefParameter<"">:$attrData, AttributeSelfTypeParameter<"">:$type); let builders = [ - AttrBuilderWithInferredContext<(ins "Identifier":$dialect, + AttrBuilderWithInferredContext<(ins "StringAttr":$dialect, "StringRef":$attrData, "Type":$type), [{ return $_get(dialect.getContext(), dialect, attrData, type); @@ -688,11 +688,11 @@ // TODO: Provide a way to avoid copying content of large opaque // tensors This will likely require a new reference attribute kind. - let parameters = (ins "Identifier":$dialect, + let parameters = (ins "StringAttr":$dialect, StringRefParameter<"">:$value, AttributeSelfTypeParameter<"", "ShapedType">:$type); let builders = [ - AttrBuilderWithInferredContext<(ins "Identifier":$dialect, + AttrBuilderWithInferredContext<(ins "StringAttr":$dialect, "ShapedType":$type, "StringRef":$value), [{ return $_get(dialect.getContext(), dialect, value, type); @@ -701,7 +701,7 @@ "ShapedType":$type, "StringRef":$value), [{ MLIRContext *ctxt = dialect->getContext(); - Identifier dialectName = Identifier::get(dialect->getNamespace(), ctxt); + StringAttr dialectName = StringAttr::get(ctxt, dialect->getNamespace()); return $_get(ctxt, dialectName, value, type); }]> ]; diff --git a/mlir/include/mlir/IR/BuiltinLocationAttributes.td b/mlir/include/mlir/IR/BuiltinLocationAttributes.td --- a/mlir/include/mlir/IR/BuiltinLocationAttributes.td +++ b/mlir/include/mlir/IR/BuiltinLocationAttributes.td @@ -81,10 +81,10 @@ loc("mysource.cc":10:8) ``` }]; - let parameters = (ins "Identifier":$filename, "unsigned":$line, + let parameters = (ins "StringAttr":$filename, "unsigned":$line, "unsigned":$column); let builders = [ - AttrBuilderWithInferredContext<(ins "Identifier":$filename, + AttrBuilderWithInferredContext<(ins "StringAttr":$filename, "unsigned":$line, "unsigned":$column), [{ return $_get(filename.getContext(), filename, line, column); @@ -92,7 +92,7 @@ AttrBuilder<(ins "StringRef":$filename, "unsigned":$line, "unsigned":$column), [{ return $_get($_ctxt, - Identifier::get(filename.empty() ? "-" : filename, $_ctxt), + StringAttr::get($_ctxt, filename.empty() ? "-" : filename), line, column); }]> ]; @@ -161,13 +161,13 @@ loc("CSE"("mysource.cc":10:8)) ``` }]; - let parameters = (ins "Identifier":$name, "Location":$childLoc); + let parameters = (ins "StringAttr":$name, "Location":$childLoc); let builders = [ - AttrBuilderWithInferredContext<(ins "Identifier":$name, + AttrBuilderWithInferredContext<(ins "StringAttr":$name, "Location":$childLoc), [{ return $_get(name.getContext(), name, childLoc); }]>, - AttrBuilderWithInferredContext<(ins "Identifier":$name), [{ + AttrBuilderWithInferredContext<(ins "StringAttr":$name), [{ return $_get(name.getContext(), name, UnknownLoc::get(name.getContext())); }]> diff --git a/mlir/include/mlir/IR/BuiltinTypes.h b/mlir/include/mlir/IR/BuiltinTypes.h --- a/mlir/include/mlir/IR/BuiltinTypes.h +++ b/mlir/include/mlir/IR/BuiltinTypes.h @@ -25,9 +25,6 @@ class StringAttr; class TypeRange; -// TODO: Remove this when all usages have been replaced with StringAttr. -using Identifier = StringAttr; - //===----------------------------------------------------------------------===// // FloatType //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td --- a/mlir/include/mlir/IR/BuiltinTypes.td +++ b/mlir/include/mlir/IR/BuiltinTypes.td @@ -600,13 +600,13 @@ ``` }]; let parameters = (ins - "Identifier":$dialectNamespace, + "StringAttr":$dialectNamespace, StringRefParameter<"">:$typeData ); let builders = [ TypeBuilderWithInferredContext<(ins - "Identifier":$dialectNamespace, CArg<"StringRef", "{}">:$typeData + "StringAttr":$dialectNamespace, CArg<"StringRef", "{}">:$typeData ), [{ return $_get(dialectNamespace.getContext(), dialectNamespace, typeData); }]> diff --git a/mlir/include/mlir/IR/FunctionSupport.h b/mlir/include/mlir/IR/FunctionSupport.h --- a/mlir/include/mlir/IR/FunctionSupport.h +++ b/mlir/include/mlir/IR/FunctionSupport.h @@ -396,7 +396,7 @@ /// Return the specified attribute, if present, for the argument at 'index', /// null otherwise. - Attribute getArgAttr(unsigned index, Identifier name) { + Attribute getArgAttr(unsigned index, StringAttr name) { auto argDict = getArgAttrDict(index); return argDict ? argDict.get(name) : nullptr; } @@ -406,7 +406,7 @@ } template - AttrClass getArgAttrOfType(unsigned index, Identifier name) { + AttrClass getArgAttrOfType(unsigned index, StringAttr name) { return getArgAttr(index, name).template dyn_cast_or_null(); } template @@ -436,19 +436,19 @@ /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. - void setArgAttr(unsigned index, Identifier name, Attribute value); + void setArgAttr(unsigned index, StringAttr name, Attribute value); void setArgAttr(unsigned index, StringRef name, Attribute value) { - setArgAttr(index, Identifier::get(name, this->getOperation()->getContext()), + setArgAttr(index, StringAttr::get(this->getOperation()->getContext(), name), value); } /// Remove the attribute 'name' from the argument at 'index'. Return the /// attribute that was erased, or nullptr if there was no attribute with such /// name. - Attribute removeArgAttr(unsigned index, Identifier name); + Attribute removeArgAttr(unsigned index, StringAttr name); Attribute removeArgAttr(unsigned index, StringRef name) { return removeArgAttr( - index, Identifier::get(name, this->getOperation()->getContext())); + index, StringAttr::get(this->getOperation()->getContext(), name)); } //===--------------------------------------------------------------------===// @@ -485,7 +485,7 @@ /// Return the specified attribute, if present, for the result at 'index', /// null otherwise. - Attribute getResultAttr(unsigned index, Identifier name) { + Attribute getResultAttr(unsigned index, StringAttr name) { auto argDict = getResultAttrDict(index); return argDict ? argDict.get(name) : nullptr; } @@ -495,7 +495,7 @@ } template - AttrClass getResultAttrOfType(unsigned index, Identifier name) { + AttrClass getResultAttrOfType(unsigned index, StringAttr name) { return getResultAttr(index, name).template dyn_cast_or_null(); } template @@ -525,17 +525,17 @@ /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. - void setResultAttr(unsigned index, Identifier name, Attribute value); + void setResultAttr(unsigned index, StringAttr name, Attribute value); void setResultAttr(unsigned index, StringRef name, Attribute value) { setResultAttr(index, - Identifier::get(name, this->getOperation()->getContext()), + StringAttr::get(this->getOperation()->getContext(), name), value); } /// Remove the attribute 'name' from the result at 'index'. Return the /// attribute that was erased, or nullptr if there was no attribute with such /// name. - Attribute removeResultAttr(unsigned index, Identifier name); + Attribute removeResultAttr(unsigned index, StringAttr name); protected: /// Returns the dictionary attribute corresponding to the argument at 'index'. @@ -718,7 +718,7 @@ /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. template -void FunctionLike::setArgAttr(unsigned index, Identifier name, +void FunctionLike::setArgAttr(unsigned index, StringAttr name, Attribute value) { NamedAttrList attributes(getArgAttrDict(index)); Attribute oldValue = attributes.set(name, value); @@ -731,7 +731,7 @@ /// Remove the attribute 'name' from the argument at 'index'. template Attribute FunctionLike::removeArgAttr(unsigned index, - Identifier name) { + StringAttr name) { // Build an attribute list and remove the attribute at 'name'. NamedAttrList attributes(getArgAttrDict(index)); Attribute removedAttr = attributes.erase(name); @@ -770,7 +770,7 @@ /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. template -void FunctionLike::setResultAttr(unsigned index, Identifier name, +void FunctionLike::setResultAttr(unsigned index, StringAttr name, Attribute value) { NamedAttrList attributes(getResultAttrDict(index)); Attribute oldAttr = attributes.set(name, value); @@ -783,7 +783,7 @@ /// Remove the attribute 'name' from the result at 'index'. template Attribute FunctionLike::removeResultAttr(unsigned index, - Identifier name) { + StringAttr name) { // Build an attribute list and remove the attribute at 'name'. NamedAttrList attributes(getResultAttrDict(index)); Attribute removedAttr = attributes.erase(name); diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -549,7 +549,7 @@ : Type, summary, "::mlir::OpaqueType">, BuildableType<"::mlir::OpaqueType::get(" - "$_builder.getIdentifier(\"" # dialect # "\"), \"" + "$_builder.getStringAttr(\"" # dialect # "\"), \"" # name # "\")">; // Function Type diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -320,19 +320,21 @@ } /// Return the specified attribute if present, null otherwise. - Attribute getAttr(Identifier name) { return attrs.get(name); } + Attribute getAttr(StringAttr name) { return attrs.get(name); } Attribute getAttr(StringRef name) { return attrs.get(name); } - template AttrClass getAttrOfType(Identifier name) { + template + AttrClass getAttrOfType(StringAttr name) { return getAttr(name).dyn_cast_or_null(); } - template AttrClass getAttrOfType(StringRef name) { + template + AttrClass getAttrOfType(StringRef name) { return getAttr(name).dyn_cast_or_null(); } /// Return true if the operation has an attribute with the provided name, /// false otherwise. - bool hasAttr(Identifier name) { return attrs.contains(name); } + bool hasAttr(StringAttr name) { return attrs.contains(name); } bool hasAttr(StringRef name) { return attrs.contains(name); } template bool hasAttrOfType(NameT &&name) { @@ -342,19 +344,19 @@ /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. - void setAttr(Identifier name, Attribute value) { + void setAttr(StringAttr name, Attribute value) { NamedAttrList attributes(attrs); if (attributes.set(name, value) != value) attrs = attributes.getDictionary(getContext()); } void setAttr(StringRef name, Attribute value) { - setAttr(Identifier::get(name, getContext()), value); + setAttr(StringAttr::get(getContext(), name), value); } /// Remove the attribute with the specified name if it exists. Return the /// attribute that was erased, or nullptr if there was no attribute with such /// name. - Attribute removeAttr(Identifier name) { + Attribute removeAttr(StringAttr name) { NamedAttrList attributes(attrs); Attribute removedAttr = attributes.erase(name); if (removedAttr) @@ -362,7 +364,7 @@ return removedAttr; } Attribute removeAttr(StringRef name) { - return removeAttr(Identifier::get(name, getContext())); + return removeAttr(StringAttr::get(getContext(), name)); } /// A utility iterator that filters out non-dialect attributes. diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -14,9 +14,8 @@ #ifndef MLIR_IR_OPERATION_SUPPORT_H #define MLIR_IR_OPERATION_SUPPORT_H -#include "mlir/IR/Attributes.h" #include "mlir/IR/BlockSupport.h" -#include "mlir/IR/Identifier.h" +#include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Location.h" #include "mlir/IR/TypeRange.h" #include "mlir/IR/Types.h" @@ -82,7 +81,7 @@ llvm::unique_function; /// This is the name of the operation. - const Identifier name; + const StringAttr name; /// This is the dialect that this operation belongs to. Dialect &dialect; @@ -207,7 +206,7 @@ /// greatly simplifying the cost and complexity of attribute usage produced by /// the generator. /// - ArrayRef getAttributeNames() const { return attributeNames; } + ArrayRef getAttributeNames() const { return attributeNames; } private: AbstractOperation(StringRef name, Dialect &dialect, TypeID typeID, @@ -217,7 +216,7 @@ FoldHookFn &&foldHook, GetCanonicalizationPatternsFn &&getCanonicalizationPatterns, detail::InterfaceMap &&interfaceMap, HasTraitFn &&hasTrait, - ArrayRef attrNames); + ArrayRef attrNames); /// Give Op access to lookupMutable. template class... Traits> @@ -242,7 +241,7 @@ /// A list of attribute names registered to this operation in identifier form. /// This allows for operation classes to use identifiers for attribute /// lookup/creation/etc., as opposed to strings. - ArrayRef attributeNames; + ArrayRef attributeNames; }; //===----------------------------------------------------------------------===// @@ -288,12 +287,12 @@ return {first, false}; } -/// Identifier lookups on large attribute lists will switch to string binary +/// StringAttr lookups on large attribute lists will switch to string binary /// search. String binary searches become significantly faster than linear scans /// with the identifier when the attribute list becomes very large. template std::pair findAttrSorted(IteratorT first, IteratorT last, - Identifier name) { + StringAttr name) { constexpr unsigned kSmallAttributeList = 16; if (std::distance(first, last) > kSmallAttributeList) return findAttrSorted(first, last, name.strref()); @@ -332,7 +331,7 @@ void append(StringRef name, Attribute attr); /// Add an attribute with the specified name. - void append(Identifier name, Attribute attr) { + void append(StringAttr name, Attribute attr) { append(NamedAttribute(name, attr)); } @@ -384,24 +383,24 @@ ArrayRef getAttrs() const; /// Return the specified attribute if present, null otherwise. - Attribute get(Identifier name) const; + Attribute get(StringAttr name) const; Attribute get(StringRef name) const; /// Return the specified named attribute if present, None otherwise. Optional getNamed(StringRef name) const; - Optional getNamed(Identifier name) const; + Optional getNamed(StringAttr name) const; /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. /// Returns the previous attribute value of `name`, or null if no /// attribute previously existed with `name`. - Attribute set(Identifier name, Attribute value); + Attribute set(StringAttr name, Attribute value); Attribute set(StringRef name, Attribute value); /// Erase the attribute with the given name from the list. Return the /// attribute that was erased, or nullptr if there was no attribute with such /// name. - Attribute erase(Identifier name); + Attribute erase(StringAttr name); Attribute erase(StringRef name); iterator begin() { return attrs.begin(); } @@ -443,7 +442,7 @@ class OperationName { public: using RepresentationUnion = - PointerUnion; + PointerUnion; OperationName(AbstractOperation *op) : representation(op) {} OperationName(StringRef name, MLIRContext *context); @@ -456,7 +455,7 @@ Dialect *getDialect() const { if (const auto *abstractOp = getAbstractOperation()) return &abstractOp->dialect; - return representation.get().getReferencedDialect(); + return representation.get().getReferencedDialect(); } /// Return the operation name with dialect name stripped, if it has one. @@ -466,7 +465,7 @@ StringRef getStringRef() const; /// Return the name of this operation as an identifier. This always succeeds. - Identifier getIdentifier() const; + StringAttr getIdentifier() const; /// If this operation has a registered operation description, return it. /// Otherwise return null. @@ -549,11 +548,11 @@ /// Add an attribute with the specified name. void addAttribute(StringRef name, Attribute attr) { - addAttribute(Identifier::get(name, getContext()), attr); + addAttribute(StringAttr::get(getContext(), name), attr); } /// Add an attribute with the specified name. - void addAttribute(Identifier name, Attribute attr) { + void addAttribute(StringAttr name, Attribute attr) { attributes.append(name, attr); } diff --git a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.h b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.h --- a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.h +++ b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.h @@ -22,7 +22,7 @@ namespace mlir { class DataLayout; class DataLayoutEntryInterface; -using DataLayoutEntryKey = llvm::PointerUnion; +using DataLayoutEntryKey = llvm::PointerUnion; // Using explicit SmallVector size because we cannot infer the size from the // forward declaration, and we need the typedef in the actual declaration. using DataLayoutEntryList = llvm::SmallVector; @@ -65,7 +65,7 @@ /// Given a list of data layout entries, returns the entry that has the given /// identifier as key, if such an entry exists in the list. DataLayoutEntryInterface -filterEntryForIdentifier(DataLayoutEntryListRef entries, Identifier id); +filterEntryForIdentifier(DataLayoutEntryListRef entries, StringAttr id); /// Verifies that the operation implementing the data layout interface, or a /// module operation, is valid. This calls the verifier of the spec attribute diff --git a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td --- a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td +++ b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td @@ -126,7 +126,7 @@ "present.", /*retTy=*/"::mlir::DataLayoutEntryInterface", /*methodName=*/"getSpecForIdentifier", - /*args=*/(ins "::mlir::Identifier":$identifier), + /*args=*/(ins "::mlir::StringAttr":$identifier), /*methodBody=*/"", /*defaultImplementation=*/[{ return ::mlir::detail::filterEntryForIdentifier($_attr.getEntries(), @@ -159,7 +159,7 @@ /// method directly. void bucketEntriesByType( ::llvm::DenseMap<::mlir::TypeID, ::mlir::DataLayoutEntryList> &types, - ::llvm::DenseMap<::mlir::Identifier, + ::llvm::DenseMap<::mlir::StringAttr, ::mlir::DataLayoutEntryInterface> &ids); }]; } diff --git a/mlir/include/mlir/Pass/PassInstrumentation.h b/mlir/include/mlir/Pass/PassInstrumentation.h --- a/mlir/include/mlir/Pass/PassInstrumentation.h +++ b/mlir/include/mlir/Pass/PassInstrumentation.h @@ -9,7 +9,7 @@ #ifndef MLIR_PASS_PASSINSTRUMENTATION_H_ #define MLIR_PASS_PASSINSTRUMENTATION_H_ -#include "mlir/IR/Identifier.h" +#include "mlir/IR/BuiltinAttributes.h" #include "mlir/Support/LLVM.h" #include "mlir/Support/TypeID.h" @@ -43,13 +43,13 @@ /// A callback to run before a pass pipeline is executed. This function takes /// the name of the operation type being operated on, and information related /// to the parent that spawned this pipeline. - virtual void runBeforePipeline(Identifier name, + virtual void runBeforePipeline(StringAttr name, const PipelineParentInfo &parentInfo) {} /// A callback to run after a pass pipeline has executed. This function takes /// the name of the operation type being operated on, and information related /// to the parent that spawned this pipeline. - virtual void runAfterPipeline(Identifier name, + virtual void runAfterPipeline(StringAttr name, const PipelineParentInfo &parentInfo) {} /// A callback to run before a pass is executed. This function takes a pointer @@ -90,12 +90,12 @@ /// See PassInstrumentation::runBeforePipeline for details. void - runBeforePipeline(Identifier name, + runBeforePipeline(StringAttr name, const PassInstrumentation::PipelineParentInfo &parentInfo); /// See PassInstrumentation::runAfterPipeline for details. void - runAfterPipeline(Identifier name, + runAfterPipeline(StringAttr name, const PassInstrumentation::PipelineParentInfo &parentInfo); /// See PassInstrumentation::runBeforePass for details. diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h --- a/mlir/include/mlir/Pass/PassManager.h +++ b/mlir/include/mlir/Pass/PassManager.h @@ -34,9 +34,6 @@ class PassInstrumentor; class StringAttr; -// TODO: Remove this when all usages have been replaced with StringAttr. -using Identifier = StringAttr; - namespace detail { struct OpPassManagerImpl; class OpToOpPassAdaptor; @@ -54,7 +51,7 @@ class OpPassManager { public: enum class Nesting { Implicit, Explicit }; - OpPassManager(Identifier name, Nesting nesting = Nesting::Explicit); + OpPassManager(StringAttr name, Nesting nesting = Nesting::Explicit); OpPassManager(StringRef name, Nesting nesting = Nesting::Explicit); OpPassManager(OpPassManager &&rhs); OpPassManager(const OpPassManager &rhs); @@ -78,7 +75,7 @@ /// Nest a new operation pass manager for the given operation kind under this /// pass manager. - OpPassManager &nest(Identifier nestedName); + OpPassManager &nest(StringAttr nestedName); OpPassManager &nest(StringRef nestedName); template OpPassManager &nest() { return nest(OpT::getOperationName()); @@ -101,7 +98,7 @@ size_t size() const; /// Return the operation name that this pass manager operates on. - Identifier getOpName(MLIRContext &context) const; + StringAttr getOpName(MLIRContext &context) const; /// Return the operation name that this pass manager operates on. StringRef getOpName() const; diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h --- a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h +++ b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h @@ -13,9 +13,8 @@ #ifndef MLIR_TARGET_LLVMIR_LLVMTRANSLATIONINTERFACE_H #define MLIR_TARGET_LLVMIR_LLVMTRANSLATIONINTERFACE_H -#include "mlir/IR/Attributes.h" +#include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/DialectInterface.h" -#include "mlir/IR/Identifier.h" #include "mlir/Support/LogicalResult.h" namespace llvm { diff --git a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp --- a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp +++ b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp @@ -165,7 +165,7 @@ intptr_t dataLength, const char *data, MlirType type) { return wrap( - OpaqueAttr::get(Identifier::get(unwrap(dialectNamespace), unwrap(ctx)), + OpaqueAttr::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)), StringRef(data, dataLength), unwrap(type))); } diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -145,9 +145,9 @@ MlirLocation childLoc) { if (mlirLocationIsNull(childLoc)) return wrap( - Location(NameLoc::get(Identifier::get(unwrap(name), unwrap(context))))); + Location(NameLoc::get(StringAttr::get(unwrap(context), unwrap(name))))); return wrap(Location(NameLoc::get( - Identifier::get(unwrap(name), unwrap(context)), unwrap(childLoc)))); + StringAttr::get(unwrap(context), unwrap(name)), unwrap(childLoc)))); } MlirLocation mlirLocationUnknownGet(MlirContext context) { @@ -753,7 +753,7 @@ //===----------------------------------------------------------------------===// MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str) { - return wrap(Identifier::get(unwrap(str), unwrap(context))); + return wrap(StringAttr::get(unwrap(context), unwrap(str))); } MlirContext mlirIdentifierGetContext(MlirIdentifier ident) { diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h --- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h +++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h @@ -16,7 +16,7 @@ struct GPUFuncOpLowering : ConvertOpToLLVMPattern { GPUFuncOpLowering(LLVMTypeConverter &converter, unsigned allocaAddrSpace, - Identifier kernelAttributeName) + StringAttr kernelAttributeName) : ConvertOpToLLVMPattern(converter), allocaAddrSpace(allocaAddrSpace), kernelAttributeName(kernelAttributeName) {} @@ -30,7 +30,7 @@ unsigned allocaAddrSpace; /// The attribute name to use instead of `gpu.kernel`. - Identifier kernelAttributeName; + StringAttr kernelAttributeName; }; struct GPUReturnOpLowering : public ConvertOpToLLVMPattern { diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -192,8 +192,8 @@ // memory space and does not support `alloca`s with addrspace(5). patterns.add( converter, /*allocaAddrSpace=*/0, - Identifier::get(NVVM::NVVMDialect::getKernelFuncAttrName(), - &converter.getContext())); + StringAttr::get(&converter.getContext(), + NVVM::NVVMDialect::getKernelFuncAttrName())); patterns.add>(converter, "__nv_fabsf", "__nv_fabs"); diff --git a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp --- a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp +++ b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp @@ -117,8 +117,8 @@ GPUReturnOpLowering>(converter); patterns.add( converter, /*allocaAddrSpace=*/5, - Identifier::get(ROCDL::ROCDLDialect::getKernelFuncAttrName(), - &converter.getContext())); + StringAttr::get(&converter.getContext(), + ROCDL::ROCDLDialect::getKernelFuncAttrName())); patterns.add>(converter, "__ocml_fabs_f32", "__ocml_fabs_f64"); patterns.add>(converter, "__ocml_atan_f32", diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp --- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp @@ -296,8 +296,8 @@ funcOp, *getTypeConverter(), rewriter, entryPointAttr, argABI); if (!newFuncOp) return failure(); - newFuncOp->removeAttr(Identifier::get( - gpu::GPUDialect::getKernelFuncAttrName(), rewriter.getContext())); + newFuncOp->removeAttr( + rewriter.getStringAttr(gpu::GPUDialect::getKernelFuncAttrName())); return success(); } diff --git a/mlir/lib/Conversion/PDLToPDLInterp/Predicate.h b/mlir/lib/Conversion/PDLToPDLInterp/Predicate.h --- a/mlir/lib/Conversion/PDLToPDLInterp/Predicate.h +++ b/mlir/lib/Conversion/PDLToPDLInterp/Predicate.h @@ -164,12 +164,12 @@ /// A position describing an attribute of an operation. struct AttributePosition : public PredicateBase, + std::pair, Predicates::AttributePos> { explicit AttributePosition(const KeyTy &key); /// Returns the attribute name of this position. - Identifier getName() const { return key.second; } + StringAttr getName() const { return key.second; } }; //===----------------------------------------------------------------------===// @@ -487,7 +487,7 @@ /// Returns an attribute position for an attribute of the given operation. Position *getAttribute(OperationPosition *p, StringRef name) { - return AttributePosition::get(uniquer, p, Identifier::get(name, ctx)); + return AttributePosition::get(uniquer, p, StringAttr::get(ctx, name)); } /// Returns an operand position for an operand of the given operation. diff --git a/mlir/lib/Dialect/Affine/Transforms/SimplifyAffineStructures.cpp b/mlir/lib/Dialect/Affine/Transforms/SimplifyAffineStructures.cpp --- a/mlir/lib/Dialect/Affine/Transforms/SimplifyAffineStructures.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/SimplifyAffineStructures.cpp @@ -35,7 +35,7 @@ /// Utility to simplify an affine attribute and update its entry in the parent /// operation if necessary. template - void simplifyAndUpdateAttribute(Operation *op, Identifier name, + void simplifyAndUpdateAttribute(Operation *op, StringAttr name, AttributeT attr) { auto &simplified = simplifiedAttributes[attr]; if (simplified == attr) diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -88,7 +88,7 @@ Operation *hoistOverOpClone = nullptr; // We use this unique name to identify/find `ifOp`'s clone in the else // version. - Identifier idForIfOp = b.getIdentifier("__mlir_if_hoisting"); + StringAttr idForIfOp = b.getStringAttr("__mlir_if_hoisting"); operandMap.clear(); b.setInsertionPointAfter(hoistOverOp); // We'll set an attribute to identify this op in a clone of this sub-tree. diff --git a/mlir/lib/Dialect/DLTI/DLTI.cpp b/mlir/lib/Dialect/DLTI/DLTI.cpp --- a/mlir/lib/Dialect/DLTI/DLTI.cpp +++ b/mlir/lib/Dialect/DLTI/DLTI.cpp @@ -49,7 +49,7 @@ } // namespace impl } // namespace mlir -DataLayoutEntryAttr DataLayoutEntryAttr::get(Identifier key, Attribute value) { +DataLayoutEntryAttr DataLayoutEntryAttr::get(StringAttr key, Attribute value) { return Base::get(key.getContext(), key, value); } @@ -89,7 +89,7 @@ return {}; return type ? get(type, value) - : get(parser.getBuilder().getIdentifier(identifier), value); + : get(parser.getBuilder().getStringAttr(identifier), value); } void DataLayoutEntryAttr::print(AsmPrinter &os) const { @@ -97,7 +97,7 @@ if (auto type = getKey().dyn_cast()) os << type; else - os << "\"" << getKey().get().strref() << "\""; + os << "\"" << getKey().get().strref() << "\""; os << ", " << getValue() << ">"; } @@ -146,13 +146,13 @@ DataLayoutSpecAttr::verify(function_ref emitError, ArrayRef entries) { DenseSet types; - DenseSet ids; + DenseSet ids; for (DataLayoutEntryInterface entry : entries) { if (auto type = entry.getKey().dyn_cast()) { if (!types.insert(type).second) return emitError() << "repeated layout entry key: " << type; } else { - auto id = entry.getKey().get(); + auto id = entry.getKey().get(); if (!ids.insert(id).second) return emitError() << "repeated layout entry key: " << id.getValue(); } @@ -191,13 +191,13 @@ static LogicalResult combineOneSpec(DataLayoutSpecInterface spec, DenseMap &entriesForType, - DenseMap &entriesForID) { + DenseMap &entriesForID) { // A missing spec should be fine. if (!spec) return success(); DenseMap newEntriesForType; - DenseMap newEntriesForID; + DenseMap newEntriesForID; spec.bucketEntriesByType(newEntriesForType, newEntriesForID); // Try overwriting the old entries with the new ones. @@ -220,7 +220,7 @@ } for (const auto &kvp : newEntriesForID) { - Identifier id = kvp.second.getKey().get(); + StringAttr id = kvp.second.getKey().get(); Dialect *dialect = id.getReferencedDialect(); if (!entriesForID.count(id)) { entriesForID[id] = kvp.second; @@ -253,7 +253,7 @@ // Combine all specs in order, with `this` being the last one. DenseMap entriesForType; - DenseMap entriesForID; + DenseMap entriesForID; for (DataLayoutSpecInterface spec : specs) if (failed(combineOneSpec(spec, entriesForType, entriesForID))) return nullptr; @@ -320,7 +320,7 @@ LogicalResult verifyEntry(DataLayoutEntryInterface entry, Location loc) const final { - StringRef entryName = entry.getKey().get().strref(); + StringRef entryName = entry.getKey().get().strref(); if (entryName == DLTIDialect::kDataLayoutEndiannessKey) { auto value = entry.getValue().dyn_cast(); if (value && diff --git a/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp b/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/CodegenStrategy.cpp @@ -35,12 +35,12 @@ const std::unique_ptr &t = transformationSequence[stepCount]; std::string currentStr = std::to_string(stepCount); - auto currentState = Identifier::get(currentStr, context); + auto currentState = StringAttr::get(context, currentStr); std::string nextStr = std::to_string(stepCount + 1); - auto nextState = Identifier::get(nextStr, context); + auto nextState = StringAttr::get(context, nextStr); auto filter = (currentState.str() == std::to_string(0)) ? linalg::LinalgTransformationFilter( - t->filter, ArrayRef{}, nextState) + t->filter, ArrayRef{}, nextState) : linalg::LinalgTransformationFilter( t->filter, currentState, nextState); t->addToPassPipeline(pm, filter); diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -447,8 +447,8 @@ auto *ctx = patterns.getContext(); patterns.add>( ctx, options, - LinalgTransformationFilter(ArrayRef{}, - Identifier::get("tiled", ctx))); + LinalgTransformationFilter(ArrayRef{}, + StringAttr::get(ctx, "tiled"))); RewritePatternList::insert(patterns, options); } }; diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -49,13 +49,13 @@ "__internal_linalg_transform__"; mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter( - ArrayRef matchDisjunction, Optional replacement) + ArrayRef matchDisjunction, Optional replacement) : matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()), replacement(replacement), matchByDefault(false) {} mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter( - FilterFunction f, ArrayRef matchDisjunction, - Optional replacement) + FilterFunction f, ArrayRef matchDisjunction, + Optional replacement) : filters(), matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()), replacement(replacement), matchByDefault(false) { @@ -101,10 +101,10 @@ Operation *op) const { if (replacement.hasValue()) op->setAttr(LinalgTransforms::kLinalgTransformMarker, - rewriter.getStringAttr(replacement.getValue().strref())); + replacement.getValue()); else - op->removeAttr(Identifier::get(LinalgTransforms::kLinalgTransformMarker, - rewriter.getContext())); + op->removeAttr( + rewriter.getStringAttr(LinalgTransforms::kLinalgTransformMarker)); } LinalgTilingOptions & diff --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp @@ -1171,13 +1171,13 @@ constexpr static StringRef kPromotedMarker = "PROMOTED"; tilingPatterns.add>( context, LinalgTilingOptions().setTileSizes(tileSizes), - LinalgTransformationFilter(ArrayRef{}, - Identifier::get(kTiledMarker, context))); + LinalgTransformationFilter(ArrayRef{}, + StringAttr::get(kTiledMarker, context))); promotionPatterns.add>( context, LinalgPromotionOptions().setUseFullTileBuffersByDefault(true), - LinalgTransformationFilter(Identifier::get(kTiledMarker, context), - Identifier::get(kPromotedMarker, context))); + LinalgTransformationFilter(StringAttr::get(kTiledMarker, context), + StringAttr::get(kPromotedMarker, context))); SmallVector mask(N); int offset = tileSizes.size() - N; diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp @@ -14,7 +14,6 @@ #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h" #include "mlir/IR/Attributes.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/IR/Identifier.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -207,7 +207,7 @@ if (auto arr = attribute.second.dyn_cast()) { // Verify all entries are function libraries and mappings in libraries // refer to unique ops. - DenseSet key; + DenseSet key; for (auto it : arr) { if (!it.isa()) return op->emitError( diff --git a/mlir/lib/IR/AttributeDetail.h b/mlir/lib/IR/AttributeDetail.h --- a/mlir/lib/IR/AttributeDetail.h +++ b/mlir/lib/IR/AttributeDetail.h @@ -16,7 +16,6 @@ #include "mlir/IR/AffineMap.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/IR/Identifier.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/MLIRContext.h" #include "mlir/Support/StorageUniquer.h" diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -19,8 +19,8 @@ using namespace mlir; -Identifier Builder::getIdentifier(const Twine &str) { - return Identifier::get(str, context); +StringAttr Builder::getIdentifier(const Twine &str) { + return getStringAttr(str); } //===----------------------------------------------------------------------===// @@ -83,7 +83,7 @@ //===----------------------------------------------------------------------===// NamedAttribute Builder::getNamedAttr(StringRef name, Attribute val) { - return NamedAttribute(getIdentifier(name), val); + return NamedAttribute(getStringAttr(name), val); } UnitAttr Builder::getUnitAttr() { return UnitAttr::get(context); } diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp --- a/mlir/lib/IR/BuiltinAttributes.cpp +++ b/mlir/lib/IR/BuiltinAttributes.cpp @@ -188,7 +188,7 @@ auto it = impl::findAttrSorted(begin(), end(), name); return it.second ? it.first->second : Attribute(); } -Attribute DictionaryAttr::get(Identifier name) const { +Attribute DictionaryAttr::get(StringAttr name) const { auto it = impl::findAttrSorted(begin(), end(), name); return it.second ? it.first->second : Attribute(); } @@ -198,7 +198,7 @@ auto it = impl::findAttrSorted(begin(), end(), name); return it.second ? *it.first : Optional(); } -Optional DictionaryAttr::getNamed(Identifier name) const { +Optional DictionaryAttr::getNamed(StringAttr name) const { auto it = impl::findAttrSorted(begin(), end(), name); return it.second ? *it.first : Optional(); } @@ -207,7 +207,7 @@ bool DictionaryAttr::contains(StringRef name) const { return impl::findAttrSorted(begin(), end(), name).second; } -bool DictionaryAttr::contains(Identifier name) const { +bool DictionaryAttr::contains(StringAttr name) const { return impl::findAttrSorted(begin(), end(), name).second; } @@ -394,7 +394,7 @@ //===----------------------------------------------------------------------===// LogicalResult OpaqueAttr::verify(function_ref emitError, - Identifier dialect, StringRef attrData, + StringAttr dialect, StringRef attrData, Type type) { if (!Dialect::isValidNamespace(dialect.strref())) return emitError() << "invalid dialect namespace '" << dialect << "'"; @@ -1247,7 +1247,7 @@ LogicalResult OpaqueElementsAttr::verify(function_ref emitError, - Identifier dialect, StringRef value, + StringAttr dialect, StringRef value, ShapedType type) { if (!Dialect::isValidNamespace(dialect.strref())) return emitError() << "invalid dialect namespace '" << dialect << "'"; diff --git a/mlir/lib/IR/BuiltinDialect.cpp b/mlir/lib/IR/BuiltinDialect.cpp --- a/mlir/lib/IR/BuiltinDialect.cpp +++ b/mlir/lib/IR/BuiltinDialect.cpp @@ -153,7 +153,7 @@ /// from this function to dest. void FuncOp::cloneInto(FuncOp dest, BlockAndValueMapping &mapper) { // Add the attributes of this function to dest. - llvm::MapVector newAttrs; + llvm::MapVector newAttrs; for (const auto &attr : dest->getAttrs()) newAttrs.insert(attr); for (const auto &attr : (*this)->getAttrs()) diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp --- a/mlir/lib/IR/BuiltinTypes.cpp +++ b/mlir/lib/IR/BuiltinTypes.cpp @@ -251,7 +251,7 @@ /// Verify the construction of an opaque type. LogicalResult OpaqueType::verify(function_ref emitError, - Identifier dialect, StringRef typeData) { + StringAttr dialect, StringRef typeData) { if (!Dialect::isValidNamespace(dialect.strref())) return emitError() << "invalid dialect namespace '" << dialect << "'"; diff --git a/mlir/lib/IR/Dialect.cpp b/mlir/lib/IR/Dialect.cpp --- a/mlir/lib/IR/Dialect.cpp +++ b/mlir/lib/IR/Dialect.cpp @@ -156,7 +156,7 @@ Type Dialect::parseType(DialectAsmParser &parser) const { // If this dialect allows unknown types, then represent this with OpaqueType. if (allowsUnknownTypes()) { - Identifier ns = Identifier::get(getNamespace(), getContext()); + StringAttr ns = StringAttr::get(getContext(), getNamespace()); return OpaqueType::get(ns, parser.getFullSymbolSpec()); } diff --git a/mlir/lib/IR/Location.cpp b/mlir/lib/IR/Location.cpp --- a/mlir/lib/IR/Location.cpp +++ b/mlir/lib/IR/Location.cpp @@ -8,7 +8,6 @@ #include "mlir/IR/Location.h" #include "mlir/IR/BuiltinDialect.h" -#include "mlir/IR/Identifier.h" #include "mlir/IR/Visitors.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -772,14 +772,14 @@ "context"); // Register the attribute names of this operation. - MutableArrayRef cachedAttrNames; + MutableArrayRef cachedAttrNames; if (!attrNames.empty()) { - cachedAttrNames = MutableArrayRef( - impl.abstractDialectSymbolAllocator.Allocate( + cachedAttrNames = MutableArrayRef( + impl.abstractDialectSymbolAllocator.Allocate( attrNames.size()), attrNames.size()); for (unsigned i : llvm::seq(0, attrNames.size())) - new (&cachedAttrNames[i]) Identifier(Identifier::get(attrNames[i], ctx)); + new (&cachedAttrNames[i]) StringAttr(StringAttr::get(ctx, attrNames[i])); } // Register the information for this operation. @@ -801,8 +801,8 @@ VerifyInvariantsFn &&verifyInvariants, FoldHookFn &&foldHook, GetCanonicalizationPatternsFn &&getCanonicalizationPatterns, detail::InterfaceMap &&interfaceMap, HasTraitFn &&hasTrait, - ArrayRef attrNames) - : name(Identifier::get(name, dialect.getContext())), dialect(dialect), + ArrayRef attrNames) + : name(StringAttr::get(dialect.getContext(), name)), dialect(dialect), typeID(typeID), interfaceMap(std::move(interfaceMap)), foldHookFn(std::move(foldHook)), getCanonicalizationPatternsFn(std::move(getCanonicalizationPatterns)), diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -30,7 +30,7 @@ if (auto *op = AbstractOperation::lookup(name, context)) representation = op; else - representation = Identifier::get(name, context); + representation = StringAttr::get(name, context); } /// Return the name of the dialect this operation is registered to. @@ -51,10 +51,10 @@ } /// Return the name of this operation as an identifier. This always succeeds. -Identifier OperationName::getIdentifier() const { +StringAttr OperationName::getIdentifier() const { if (auto *op = representation.dyn_cast()) return op->name; - return representation.get(); + return representation.get(); } OperationName OperationName::getFromOpaquePointer(const void *pointer) { diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -62,7 +62,7 @@ /// Add an attribute with the specified name. void NamedAttrList::append(StringRef name, Attribute attr) { - append(Identifier::get(name, attr.getContext()), attr); + append(StringAttr::get(attr.getContext(), name), attr); } /// Replaces the attributes with new list of attributes. @@ -86,7 +86,7 @@ auto it = findAttr(*this, name); return it.second ? it.first->second : Attribute(); } -Attribute NamedAttrList::get(Identifier name) const { +Attribute NamedAttrList::get(StringAttr name) const { auto it = findAttr(*this, name); return it.second ? it.first->second : Attribute(); } @@ -96,14 +96,14 @@ auto it = findAttr(*this, name); return it.second ? *it.first : Optional(); } -Optional NamedAttrList::getNamed(Identifier name) const { +Optional NamedAttrList::getNamed(StringAttr name) const { auto it = findAttr(*this, name); return it.second ? *it.first : Optional(); } /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. -Attribute NamedAttrList::set(Identifier name, Attribute value) { +Attribute NamedAttrList::set(StringAttr name, Attribute value) { assert(value && "attributes may never be null"); // Look for an existing attribute with the given name, and set its value @@ -131,7 +131,7 @@ Attribute NamedAttrList::set(StringRef name, Attribute value) { assert(value && "attributes may never be null"); - return set(mlir::Identifier::get(name, value.getContext()), value); + return set(mlir::StringAttr::get(value.getContext(), name), value); } Attribute @@ -143,7 +143,7 @@ return attr; } -Attribute NamedAttrList::erase(Identifier name) { +Attribute NamedAttrList::erase(StringAttr name) { auto it = findAttr(*this, name); return it.second ? eraseImpl(it.first) : Attribute(); } diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp --- a/mlir/lib/IR/SymbolTable.cpp +++ b/mlir/lib/IR/SymbolTable.cpp @@ -27,7 +27,7 @@ static StringAttr getNameIfSymbol(Operation *op) { return op->getAttrOfType(SymbolTable::getSymbolAttrName()); } -static StringAttr getNameIfSymbol(Operation *op, Identifier symbolAttrNameId) { +static StringAttr getNameIfSymbol(Operation *op, StringAttr symbolAttrNameId) { return op->getAttrOfType(symbolAttrNameId); } @@ -52,8 +52,8 @@ // Collect references until 'symbolTableOp' reaches 'within'. SmallVector nestedRefs(1, leafRef); - Identifier symbolNameId = - Identifier::get(SymbolTable::getSymbolAttrName(), ctx); + StringAttr symbolNameId = + StringAttr::get(ctx, SymbolTable::getSymbolAttrName()); do { // Each parent of 'symbol' should define a symbol table. if (!symbolTableOp->hasTrait()) @@ -111,8 +111,8 @@ assert(llvm::hasSingleElement(symbolTableOp->getRegion(0)) && "expected operation to have a single block"); - Identifier symbolNameId = Identifier::get(SymbolTable::getSymbolAttrName(), - symbolTableOp->getContext()); + StringAttr symbolNameId = StringAttr::get(symbolTableOp->getContext(), + SymbolTable::getSymbolAttrName()); for (auto &op : symbolTableOp->getRegion(0).front()) { StringAttr name = getNameIfSymbol(&op, symbolNameId); if (!name) @@ -235,7 +235,7 @@ // If the visibility is public, just drop the attribute as this is the // default. if (vis == Visibility::Public) { - symbol->removeAttr(Identifier::get(getVisibilityAttrName(), ctx)); + symbol->removeAttr(StringAttr::get(ctx, getVisibilityAttrName())); return; } @@ -305,8 +305,8 @@ return nullptr; // Look for a symbol with the given name. - Identifier symbolNameId = Identifier::get(SymbolTable::getSymbolAttrName(), - symbolTableOp->getContext()); + StringAttr symbolNameId = StringAttr::get(symbolTableOp->getContext(), + SymbolTable::getSymbolAttrName()); for (auto &op : region.front()) if (getNameIfSymbol(&op, symbolNameId) == symbol) return &op; diff --git a/mlir/lib/IR/TypeDetail.h b/mlir/lib/IR/TypeDetail.h --- a/mlir/lib/IR/TypeDetail.h +++ b/mlir/lib/IR/TypeDetail.h @@ -14,7 +14,6 @@ #include "mlir/IR/AffineMap.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/IR/Identifier.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/OperationSupport.h" #include "mlir/IR/TypeRange.h" diff --git a/mlir/lib/Interfaces/DataLayoutInterfaces.cpp b/mlir/lib/Interfaces/DataLayoutInterfaces.cpp --- a/mlir/lib/Interfaces/DataLayoutInterfaces.cpp +++ b/mlir/lib/Interfaces/DataLayoutInterfaces.cpp @@ -147,11 +147,11 @@ DataLayoutEntryInterface mlir::detail::filterEntryForIdentifier(DataLayoutEntryListRef entries, - Identifier id) { + StringAttr id) { const auto *it = llvm::find_if(entries, [id](DataLayoutEntryInterface entry) { - if (!entry.getKey().is()) + if (!entry.getKey().is()) return false; - return entry.getKey().get() == id; + return entry.getKey().get() == id; }); return it == entries.end() ? DataLayoutEntryInterface() : *it; } @@ -384,12 +384,12 @@ void DataLayoutSpecInterface::bucketEntriesByType( DenseMap &types, - DenseMap &ids) { + DenseMap &ids) { for (DataLayoutEntryInterface entry : getEntries()) { if (auto type = entry.getKey().dyn_cast()) types[type.getTypeID()].push_back(entry); else - ids[entry.getKey().get()] = entry; + ids[entry.getKey().get()] = entry; } } @@ -403,7 +403,7 @@ // Second, dispatch verifications of entry groups to types or dialects they // are are associated with. DenseMap types; - DenseMap ids; + DenseMap ids; spec.bucketEntriesByType(types, ids); for (const auto &kvp : types) { @@ -430,7 +430,7 @@ } for (const auto &kvp : ids) { - Identifier identifier = kvp.second.getKey().get(); + StringAttr identifier = kvp.second.getKey().get(); Dialect *dialect = identifier.getReferencedDialect(); // Ignore attributes that belong to an unknown dialect, the dialect may diff --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp --- a/mlir/lib/Parser/AttributeParser.cpp +++ b/mlir/lib/Parser/AttributeParser.cpp @@ -260,15 +260,15 @@ /// attribute-entry ::= (bare-id | string-literal) `=` attribute-value /// ParseResult Parser::parseAttributeDict(NamedAttrList &attributes) { - llvm::SmallDenseSet seenKeys; + llvm::SmallDenseSet seenKeys; auto parseElt = [&]() -> ParseResult { // The name of an attribute can either be a bare identifier, or a string. - Optional nameId; + Optional nameId; if (getToken().is(Token::string)) - nameId = builder.getIdentifier(getToken().getStringValue()); + nameId = builder.getStringAttr(getToken().getStringValue()); else if (getToken().isAny(Token::bare_identifier, Token::inttype) || getToken().isKeyword()) - nameId = builder.getIdentifier(getTokenSpelling()); + nameId = builder.getStringAttr(getTokenSpelling()); else return emitError("expected attribute name"); if (!seenKeys.insert(*nameId).second) @@ -856,7 +856,7 @@ std::string data; if (parseElementAttrHexValues(*this, hexTok, data)) return nullptr; - return OpaqueElementsAttr::get(builder.getIdentifier(name), type, data); + return OpaqueElementsAttr::get(builder.getStringAttr(name), type, data); } /// Shaped type for elements attribute. diff --git a/mlir/lib/Parser/DialectSymbolParser.cpp b/mlir/lib/Parser/DialectSymbolParser.cpp --- a/mlir/lib/Parser/DialectSymbolParser.cpp +++ b/mlir/lib/Parser/DialectSymbolParser.cpp @@ -258,7 +258,7 @@ // Otherwise, form a new opaque attribute. return OpaqueAttr::getChecked( [&] { return emitError(loc); }, - Identifier::get(dialectName, state.context), symbolData, + StringAttr::get(state.context, dialectName), symbolData, attrType ? attrType : NoneType::get(state.context)); }); @@ -297,7 +297,7 @@ // Otherwise, form a new opaque type. return OpaqueType::getChecked( [&] { return emitError(loc); }, - Identifier::get(dialectName, state.context), symbolData); + StringAttr::get(state.context, dialectName), symbolData); }); } diff --git a/mlir/lib/Parser/Lexer.cpp b/mlir/lib/Parser/Lexer.cpp --- a/mlir/lib/Parser/Lexer.cpp +++ b/mlir/lib/Parser/Lexer.cpp @@ -12,7 +12,6 @@ #include "Lexer.h" #include "mlir/IR/Diagnostics.h" -#include "mlir/IR/Identifier.h" #include "mlir/IR/Location.h" #include "mlir/IR/MLIRContext.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/Parser/LocationParser.cpp b/mlir/lib/Parser/LocationParser.cpp --- a/mlir/lib/Parser/LocationParser.cpp +++ b/mlir/lib/Parser/LocationParser.cpp @@ -137,14 +137,14 @@ if (childLoc.isa()) return emitError(childSourceLoc, "child of NameLoc cannot be another NameLoc"); - loc = NameLoc::get(Identifier::get(str, ctx), childLoc); + loc = NameLoc::get(StringAttr::get(ctx, str), childLoc); // Parse the closing ')'. if (parseToken(Token::r_paren, "expected ')' after child location of NameLoc")) return failure(); } else { - loc = NameLoc::get(Identifier::get(str, ctx)); + loc = NameLoc::get(StringAttr::get(ctx, str)); } return success(); diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -80,7 +80,7 @@ namespace mlir { namespace detail { struct OpPassManagerImpl { - OpPassManagerImpl(Identifier identifier, OpPassManager::Nesting nesting) + OpPassManagerImpl(StringAttr identifier, OpPassManager::Nesting nesting) : name(identifier.str()), identifier(identifier), initializationGeneration(0), nesting(nesting) {} OpPassManagerImpl(StringRef name, OpPassManager::Nesting nesting) @@ -91,7 +91,7 @@ /// Nest a new operation pass manager for the given operation kind under this /// pass manager. - OpPassManager &nest(Identifier nestedName); + OpPassManager &nest(StringAttr nestedName); OpPassManager &nest(StringRef nestedName); /// Add the given pass to this pass manager. If this pass has a concrete @@ -107,9 +107,9 @@ void coalesceAdjacentAdaptorPasses(); /// Return the operation name of this pass manager as an identifier. - Identifier getOpName(MLIRContext &context) { + StringAttr getOpName(MLIRContext &context) { if (!identifier) - identifier = Identifier::get(name, &context); + identifier = StringAttr::get(name, &context); return *identifier; } @@ -118,7 +118,7 @@ /// The cached identifier (internalized in the context) for the name of the /// operation that passes of this pass manager operate on. - Optional identifier; + Optional identifier; /// The set of passes to run as part of this pass manager. std::vector> passes; @@ -141,7 +141,7 @@ passes.clear(); } -OpPassManager &OpPassManagerImpl::nest(Identifier nestedName) { +OpPassManager &OpPassManagerImpl::nest(StringAttr nestedName) { OpPassManager nested(nestedName, nesting); auto *adaptor = new OpToOpPassAdaptor(std::move(nested)); addPass(std::unique_ptr(adaptor)); @@ -219,7 +219,7 @@ // OpPassManager //===----------------------------------------------------------------------===// -OpPassManager::OpPassManager(Identifier name, Nesting nesting) +OpPassManager::OpPassManager(StringAttr name, Nesting nesting) : impl(new OpPassManagerImpl(name, nesting)) {} OpPassManager::OpPassManager(StringRef name, Nesting nesting) : impl(new OpPassManagerImpl(name, nesting)) {} @@ -254,7 +254,7 @@ /// Nest a new operation pass manager for the given operation kind under this /// pass manager. -OpPassManager &OpPassManager::nest(Identifier nestedName) { +OpPassManager &OpPassManager::nest(StringAttr nestedName) { return impl->nest(nestedName); } OpPassManager &OpPassManager::nest(StringRef nestedName) { @@ -279,7 +279,7 @@ StringRef OpPassManager::getOpName() const { return impl->name; } /// Return the operation name that this pass manager operates on. -Identifier OpPassManager::getOpName(MLIRContext &context) const { +StringAttr OpPassManager::getOpName(MLIRContext &context) const { return impl->getOpName(context); } @@ -468,7 +468,7 @@ /// Find an operation pass manager that can operate on an operation of the given /// type, or nullptr if one does not exist. static OpPassManager *findPassManagerFor(MutableArrayRef mgrs, - Identifier name, + StringAttr name, MLIRContext &context) { auto it = llvm::find_if( mgrs, [&](OpPassManager &mgr) { return mgr.getOpName(context) == name; }); @@ -630,7 +630,7 @@ PassManager::PassManager(MLIRContext *ctx, Nesting nesting, StringRef operationName) - : OpPassManager(Identifier::get(operationName, ctx), nesting), context(ctx), + : OpPassManager(StringAttr::get(ctx, operationName), nesting), context(ctx), initializationKey(DenseMapInfo::getTombstoneKey()), passTiming(false), verifyPasses(true) {} @@ -794,7 +794,7 @@ /// See PassInstrumentation::runBeforePipeline for details. void PassInstrumentor::runBeforePipeline( - Identifier name, + StringAttr name, const PassInstrumentation::PipelineParentInfo &parentInfo) { llvm::sys::SmartScopedLock instrumentationLock(impl->mutex); for (auto &instr : impl->instrumentations) @@ -803,7 +803,7 @@ /// See PassInstrumentation::runAfterPipeline for details. void PassInstrumentor::runAfterPipeline( - Identifier name, + StringAttr name, const PassInstrumentation::PipelineParentInfo &parentInfo) { llvm::sys::SmartScopedLock instrumentationLock(impl->mutex); for (auto &instr : llvm::reverse(impl->instrumentations)) diff --git a/mlir/lib/Pass/PassTiming.cpp b/mlir/lib/Pass/PassTiming.cpp --- a/mlir/lib/Pass/PassTiming.cpp +++ b/mlir/lib/Pass/PassTiming.cpp @@ -52,7 +52,7 @@ // Pipeline //===--------------------------------------------------------------------===// - void runBeforePipeline(Identifier name, + void runBeforePipeline(StringAttr name, const PipelineParentInfo &parentInfo) override { auto tid = llvm::get_threadid(); auto &activeTimers = activeThreadTimers[tid]; @@ -73,7 +73,7 @@ })); } - void runAfterPipeline(Identifier, const PipelineParentInfo &) override { + void runAfterPipeline(StringAttr, const PipelineParentInfo &) override { auto &activeTimers = activeThreadTimers[llvm::get_threadid()]; assert(!activeTimers.empty() && "expected active timer"); activeTimers.pop_back(); diff --git a/mlir/lib/Rewrite/ByteCode.h b/mlir/lib/Rewrite/ByteCode.h --- a/mlir/lib/Rewrite/ByteCode.h +++ b/mlir/lib/Rewrite/ByteCode.h @@ -168,7 +168,7 @@ /// A vector containing pointers to uniqued data. The storage is intentionally /// opaque such that we can store a wide range of data types. The types of /// data stored here include: - /// * Attribute, Identifier, OperationName, Type + /// * Attribute, OperationName, Type std::vector uniquedData; /// A vector containing the generated bytecode for the matcher. diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp --- a/mlir/lib/Rewrite/ByteCode.cpp +++ b/mlir/lib/Rewrite/ByteCode.cpp @@ -721,11 +721,8 @@ // Add the attributes. OperandRange attributes = op.attributes(); writer.append(static_cast(attributes.size())); - for (auto it : llvm::zip(op.attributeNames(), op.attributes())) { - writer.append( - Identifier::get(std::get<0>(it).cast().getValue(), ctx), - std::get<1>(it)); - } + for (auto it : llvm::zip(op.attributeNames(), op.attributes())) + writer.append(std::get<0>(it), std::get<1>(it)); writer.appendPDLValueList(op.types()); } void Generator::generate(pdl_interp::CreateTypeOp op, ByteCodeWriter &writer) { @@ -745,7 +742,7 @@ void Generator::generate(pdl_interp::GetAttributeOp op, ByteCodeWriter &writer) { writer.append(OpCode::GetAttribute, op.attribute(), op.operation(), - Identifier::get(op.name(), ctx)); + op.nameAttr()); } void Generator::generate(pdl_interp::GetAttributeTypeOp op, ByteCodeWriter &writer) { @@ -1307,7 +1304,7 @@ OperationState state(mainRewriteLoc, read()); readValueList(state.operands); for (unsigned i = 0, e = read(); i != e; ++i) { - Identifier name = read(); + StringAttr name = read(); if (Attribute attr = read()) state.addAttribute(name, attr); } @@ -1364,7 +1361,7 @@ LLVM_DEBUG(llvm::dbgs() << "Executing GetAttribute:\n"); unsigned memIndex = read(); Operation *op = read(); - Identifier attrName = read(); + StringAttr attrName = read(); Attribute attr = op->getAttr(attrName); LLVM_DEBUG(llvm::dbgs() << " * Operation: " << *op << "\n" diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -803,7 +803,7 @@ convertLinkageFromLLVM(f->getLinkage())); if (FlatSymbolRefAttr personality = getPersonalityAsAttr(f)) - fop->setAttr(b.getIdentifier("personality"), personality); + fop->setAttr(b.getStringAttr("personality"), personality); else if (f->hasPersonalityFn()) emitWarning(UnknownLoc::get(context), "could not deduce personality, skipping it"); diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp --- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp @@ -227,7 +227,7 @@ return emitError(unknownLoc, "invalid Decoration code : ") << words[1]; } auto attrName = llvm::convertToSnakeFromCamelCase(decorationName); - auto symbol = opBuilder.getIdentifier(attrName); + auto symbol = opBuilder.getStringAttr(attrName); switch (static_cast(words[1])) { case spirv::Decoration::DescriptorSet: case spirv::Decoration::Binding: @@ -1964,7 +1964,7 @@ auto fileName = debugInfoMap.lookup(debugLine->fileID).str(); if (fileName.empty()) fileName = ""; - return FileLineColLoc::get(opBuilder.getIdentifier(fileName), debugLine->line, + return FileLineColLoc::get(opBuilder.getStringAttr(fileName), debugLine->line, debugLine->col); } diff --git a/mlir/lib/Transforms/LocationSnapshot.cpp b/mlir/lib/Transforms/LocationSnapshot.cpp --- a/mlir/lib/Transforms/LocationSnapshot.cpp +++ b/mlir/lib/Transforms/LocationSnapshot.cpp @@ -30,12 +30,12 @@ op->print(os, state, flags); Builder builder(op->getContext()); - Optional tagIdentifier; + Optional tagIdentifier; if (!tag.empty()) - tagIdentifier = builder.getIdentifier(tag); + tagIdentifier = builder.getStringAttr(tag); // Walk and generate new locations for each of the operations. - Identifier file = builder.getIdentifier(fileName); + StringAttr file = builder.getStringAttr(fileName); op->walk([&](Operation *opIt) { // Check to see if this operation has a mapped location. Some operations may // be elided from the printed form, e.g. the body terminators of some region diff --git a/mlir/test/lib/Dialect/Linalg/TestLinalgDistribution.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgDistribution.cpp --- a/mlir/test/lib/Dialect/Linalg/TestLinalgDistribution.cpp +++ b/mlir/test/lib/Dialect/Linalg/TestLinalgDistribution.cpp @@ -58,8 +58,8 @@ populateLinalgDistributeTiledLoopPattern( distributeTiledLoopsPatterns, getDistributionOptions(), LinalgTransformationFilter( - ArrayRef{}, - {Identifier::get("distributed", funcOp.getContext())}) + ArrayRef{}, + {StringAttr::get("distributed", funcOp.getContext())}) .addFilter([](Operation *op) { return success(!op->getParentOfType()); })); diff --git a/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp --- a/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp +++ b/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp @@ -31,81 +31,81 @@ LinalgTilingOptions().setTileSizes({32, 64, 16}).setLoopType(LoopType), LinalgFusionOptions().setIndicesToFuse({2}), LinalgTransformationFilter( - Identifier::get("basic_fusion", context), - Identifier::get("after_basic_fusion", context)), + StringAttr::get(context, "basic_fusion"), + StringAttr::get(context, "after_basic_fusion")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_basic_fusion_producer", context)), + ArrayRef(), + StringAttr::get(context, "after_basic_fusion_producer")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_basic_fusion_original", context))); + ArrayRef(), + StringAttr::get(context, "after_basic_fusion_original"))); patterns.add>( context, dependenceGraph, LinalgTilingOptions().setTileSizes({32, 64, 16}).setLoopType(LoopType), LinalgFusionOptions().setIndicesToFuse({0}), - LinalgTransformationFilter(Identifier::get("lhs_fusion", context), - Identifier::get("after_lhs_fusion", context)), + LinalgTransformationFilter(StringAttr::get(context, "lhs_fusion"), + StringAttr::get(context, "after_lhs_fusion")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_lhs_fusion_producer", context)), + ArrayRef(), + StringAttr::get(context, "after_lhs_fusion_producer")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_lhs_fusion_original", context))); + ArrayRef(), + StringAttr::get(context, "after_lhs_fusion_original"))); patterns.add>( context, dependenceGraph, LinalgTilingOptions().setTileSizes({32, 64, 16}).setLoopType(LoopType), LinalgFusionOptions().setIndicesToFuse({2}), - LinalgTransformationFilter(Identifier::get("out_fusion", context), - Identifier::get("after_out_fusion", context)), + LinalgTransformationFilter(StringAttr::get(context, "out_fusion"), + StringAttr::get(context, "after_out_fusion")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_out_fusion_producer", context)), + ArrayRef(), + StringAttr::get(context, "after_out_fusion_producer")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_out_fusion_original", context))); + ArrayRef(), + StringAttr::get(context, "after_out_fusion_original"))); patterns.add>( context, dependenceGraph, LinalgTilingOptions().setTileSizes({32, 64, 16}).setLoopType(LoopType), LinalgFusionOptions().setIndicesToFuse({1}), - LinalgTransformationFilter(Identifier::get("rhs_fusion", context), - Identifier::get("after_rhs_fusion", context)), + LinalgTransformationFilter(StringAttr::get(context, "rhs_fusion"), + StringAttr::get(context, "after_rhs_fusion")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_rhs_fusion_producer", context)), + ArrayRef(), + StringAttr::get(context, "after_rhs_fusion_producer")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_rhs_fusion_original", context))); + ArrayRef(), + StringAttr::get(context, "after_rhs_fusion_original"))); patterns.add>( context, dependenceGraph, LinalgTilingOptions().setTileSizes({32, 64, 16}).setLoopType(LoopType), LinalgFusionOptions().setIndicesToFuse({0, 2}), LinalgTransformationFilter( - Identifier::get("two_operand_fusion", context), - Identifier::get("after_two_operand_fusion", context)), + StringAttr::get(context, "two_operand_fusion"), + StringAttr::get(context, "after_two_operand_fusion")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_two_operand_fusion_producer", context)), + ArrayRef(), + StringAttr::get(context, "after_two_operand_fusion_producer")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_two_operand_fusion_original", context))); + ArrayRef(), + StringAttr::get(context, "after_two_operand_fusion_original"))); patterns.add>( context, dependenceGraph, LinalgTilingOptions().setTileSizes({32, 64}).setLoopType(LoopType), LinalgFusionOptions().setIndicesToFuse({0, 1}), LinalgTransformationFilter( - Identifier::get("transpose_fusion", context), - Identifier::get("after_transpose_fusion", context)), + StringAttr::get(context, "transpose_fusion"), + StringAttr::get(context, "after_transpose_fusion")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_transpose_fusion_producer", context)), + ArrayRef(), + StringAttr::get(context, "after_transpose_fusion_producer")), LinalgTransformationFilter( - ArrayRef(), - Identifier::get("after_transpose_fusion_original", context))); + ArrayRef(), + StringAttr::get(context, "after_transpose_fusion_original"))); } namespace { diff --git a/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp --- a/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp +++ b/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp @@ -145,35 +145,35 @@ //===--------------------------------------------------------------------===// patterns.add>( ctx, LinalgTilingOptions().setTileSizes({2000, 3000, 4000}), - LinalgTransformationFilter(Identifier::get("MEM", ctx), - Identifier::get("L3", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "MEM"), + StringAttr::get(ctx, "L3"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes({200, 300, 400}), - LinalgTransformationFilter(Identifier::get("L3", ctx), - Identifier::get("L2", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "L3"), + StringAttr::get(ctx, "L2"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes({20, 30, 40}), - LinalgTransformationFilter(Identifier::get("L2", ctx), - Identifier::get("L1", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "L2"), + StringAttr::get(ctx, "L1"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes({2, 3, 4}), - LinalgTransformationFilter(Identifier::get("L1", ctx), - Identifier::get("REG", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "L1"), + StringAttr::get(ctx, "REG"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes({5, 6}).setLoopType( LinalgTilingLoopType::ParallelLoops), - LinalgTransformationFilter(ArrayRef{}, - Identifier::get("L1", ctx))); + LinalgTransformationFilter(ArrayRef{}, + StringAttr::get(ctx, "L1"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes(8000), LinalgTransformationFilter( - ArrayRef{Identifier::get("MEM", ctx), - Identifier::get("L3", ctx), - Identifier::get("L2", ctx)}, - Identifier::get("REG", ctx))); + ArrayRef{StringAttr::get(ctx, "MEM"), + StringAttr::get(ctx, "L3"), + StringAttr::get(ctx, "L2")}, + StringAttr::get(ctx, "REG"))); //===--------------------------------------------------------------------===// // Linalg tiling and permutation patterns. @@ -183,24 +183,24 @@ LinalgTilingOptions() .setTileSizes({2000, 3000, 4000}) .setInterchange({1, 2, 0}), - LinalgTransformationFilter(Identifier::get("__with_perm__", ctx), - Identifier::get("L2__with_perm__", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "__with_perm__"), + StringAttr::get(ctx, "L2__with_perm__"))); patterns.add>( ctx, LinalgTilingOptions() .setTileSizes({200, 300, 400}) .setInterchange({1, 0, 2}), - LinalgTransformationFilter(Identifier::get("L2__with_perm__", ctx), - Identifier::get("L1__with_perm__", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "L2__with_perm__"), + StringAttr::get(ctx, "L1__with_perm__"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes({20, 30, 40}), - LinalgTransformationFilter(Identifier::get("L1__with_perm__", ctx), - Identifier::get("REG__with_perm__", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "L1__with_perm__"), + StringAttr::get(ctx, "REG__with_perm__"))); patterns.add>( ctx, LinalgTilingOptions().setTileSizes({5, 6}).setInterchange({1, 0}), - LinalgTransformationFilter(Identifier::get("__with_perm__", ctx), - Identifier::get("L1__with_perm__", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "__with_perm__"), + StringAttr::get(ctx, "L1__with_perm__"))); patterns.add>( ctx, @@ -209,8 +209,8 @@ .setInterchange({1, 2, 0}) .setLoopType(LinalgTilingLoopType::ParallelLoops), LinalgTransformationFilter( - Identifier::get("par__with_perm__", ctx), - Identifier::get("after_par__with_perm__", ctx))); + StringAttr::get(ctx, "par__with_perm__"), + StringAttr::get(ctx, "after_par__with_perm__"))); //===--------------------------------------------------------------------===// // Linalg to loops patterns. @@ -218,7 +218,7 @@ patterns.add>( ctx, /*loweringType=*/LinalgLoweringType::Loops, - LinalgTransformationFilter(Identifier::get("REG", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "REG"))); //===--------------------------------------------------------------------===// // Linalg distribution patterns. @@ -229,7 +229,7 @@ // Linalg to vector contraction patterns. //===--------------------------------------------------------------------===// patterns.add( - ctx, LinalgTransformationFilter(Identifier::get("VECTORIZE", ctx)) + ctx, LinalgTransformationFilter(StringAttr::get(ctx, "VECTORIZE")) .addOpFilter()); //===--------------------------------------------------------------------===// @@ -238,24 +238,24 @@ patterns.add( ctx, /*interchangeVector=*/ArrayRef{1, 2, 0}, - LinalgTransformationFilter(ArrayRef{}, - Identifier::get("PERMUTED", ctx))); + LinalgTransformationFilter(ArrayRef{}, + StringAttr::get(ctx, "PERMUTED"))); //===--------------------------------------------------------------------===// // Linalg subview operands promotion. //===--------------------------------------------------------------------===// patterns.add>( ctx, LinalgPromotionOptions().setUseFullTileBuffersByDefault(true), - LinalgTransformationFilter(Identifier::get("_promote_views_", ctx), - Identifier::get("_views_promoted_", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "_promote_views_"), + StringAttr::get(ctx, "_views_promoted_"))); patterns.add>( ctx, LinalgPromotionOptions() .setOperandsToPromote({0}) .setUseFullTileBuffersByDefault(true), LinalgTransformationFilter( - Identifier::get("_promote_first_view_", ctx), - Identifier::get("_first_view_promoted_", ctx))); + StringAttr::get(ctx, "_promote_first_view_"), + StringAttr::get(ctx, "_first_view_promoted_"))); patterns.add>( ctx, LinalgPromotionOptions() @@ -263,8 +263,8 @@ .setUseFullTileBuffers({false, true}) .setAlignment(32), LinalgTransformationFilter( - Identifier::get("_promote_views_aligned_", ctx), - Identifier::get("_views_aligned_promoted_", ctx))); + StringAttr::get(ctx, "_promote_views_aligned_"), + StringAttr::get(ctx, "_views_aligned_promoted_"))); (void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns)); @@ -284,20 +284,20 @@ LinalgTilingOptions() .setTileSizes({8, 12, 16}) .setInterchange({1, 0, 2}), - LinalgTransformationFilter(Identifier::get(startMarker, ctx), - Identifier::get("L1", ctx)))); + LinalgTransformationFilter(StringAttr::get(ctx, startMarker), + StringAttr::get(ctx, "L1")))); patternsVector.emplace_back( ctx, std::make_unique>( ctx, LinalgPromotionOptions().setUseFullTileBuffersByDefault(true), - LinalgTransformationFilter(Identifier::get("L1", ctx), - Identifier::get("VEC", ctx)))); + LinalgTransformationFilter(StringAttr::get(ctx, "L1"), + StringAttr::get(ctx, "VEC")))); patternsVector.emplace_back( ctx, std::make_unique( MatmulOp::getOperationName(), ctx, LinalgVectorizationOptions(), - LinalgTransformationFilter(Identifier::get("VEC", ctx)))); + LinalgTransformationFilter(StringAttr::get(ctx, "VEC")))); patternsVector.back().add( ctx, LinalgTransformationFilter().addFilter( [](Operation *op) { return success(isa(op)); })); @@ -346,8 +346,8 @@ RewritePatternSet &patterns) { patterns.add>( ctx, LinalgTilingOptions().setTileSizes({16, 16, 16}), - LinalgTransformationFilter(Identifier::get("START", ctx), - Identifier::get("PROMOTE", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "START"), + StringAttr::get(ctx, "PROMOTE"))); patterns.add>( ctx, LinalgPromotionOptions() @@ -361,7 +361,7 @@ [](OpBuilder &b, Value src, Value dst) -> LogicalResult { return copyCallBackFn(b, src, dst, true); }), - LinalgTransformationFilter(Identifier::get("PROMOTE", ctx))); + LinalgTransformationFilter(StringAttr::get(ctx, "PROMOTE"))); } template @@ -394,8 +394,8 @@ .setLoopType(LinalgTilingLoopType::ParallelLoops) .setDistributionOptions(cyclicNprocsEqNiters), LinalgTransformationFilter( - Identifier::get("distribute1", context), - Identifier::get("after_distribute1", context))); + StringAttr::get(context, "distribute1"), + StringAttr::get(context, "after_distribute1"))); } { @@ -411,8 +411,8 @@ .setLoopType(LinalgTilingLoopType::ParallelLoops) .setDistributionOptions(cyclicNprocsGeNiters), LinalgTransformationFilter( - Identifier::get("distribute2", context), - Identifier::get("after_distribute2", context))); + StringAttr::get(context, "distribute2"), + StringAttr::get(context, "after_distribute2"))); } { @@ -428,8 +428,8 @@ .setLoopType(LinalgTilingLoopType::ParallelLoops) .setDistributionOptions(cyclicNprocsDefault), LinalgTransformationFilter( - Identifier::get("distribute3", context), - Identifier::get("after_distribute3", context))); + StringAttr::get(context, "distribute3"), + StringAttr::get(context, "after_distribute3"))); } { @@ -445,8 +445,8 @@ .setLoopType(LinalgTilingLoopType::ParallelLoops) .setDistributionOptions(cyclicNprocsMixed1), LinalgTransformationFilter( - Identifier::get("distribute4", context), - Identifier::get("after_distribute4", context))); + StringAttr::get(context, "distribute4"), + StringAttr::get(context, "after_distribute4"))); } { @@ -462,8 +462,8 @@ .setLoopType(LinalgTilingLoopType::ParallelLoops) .setDistributionOptions(cyclicNprocsMixed2), LinalgTransformationFilter( - Identifier::get("distribute5", context), - Identifier::get("after_distribute5", context))); + StringAttr::get(context, "distribute5"), + StringAttr::get(context, "after_distribute5"))); } { @@ -480,8 +480,8 @@ .setLoopType(LinalgTilingLoopType::ParallelLoops) .setDistributionOptions(cyclicNprocsMixed3), LinalgTransformationFilter( - Identifier::get("distribute6", context), - Identifier::get("after_distribute6", context))); + StringAttr::get(context, "distribute6"), + StringAttr::get(context, "after_distribute6"))); } { @@ -495,10 +495,10 @@ LinalgTilingOptions() .setTileSizes({8, 8, 4}) .setLoopType(LinalgTilingLoopType::Loops) - .setDistributionOptions(cyclicNprocsEqNiters), + .setDistributionOptions(cyclicNprocsEqNiters), LinalgTransformationFilter( - Identifier::get("tensors_distribute1", context), - Identifier::get("tensors_after_distribute1", context))); + StringAttr::get(context, "tensors_distribute1"), + StringAttr::get(context, "tensors_after_distribute1"))); } } @@ -517,8 +517,8 @@ LinalgTilingOptions() .setTileSizes({768, 264, 768}) .setInterchange({1, 2, 0}), - LinalgTransformationFilter(Identifier::get("START", ctx), - Identifier::get("L2", ctx)))); + LinalgTransformationFilter(StringAttr::get(ctx, "START"), + StringAttr::get(ctx, "L2")))); fillL1TilingAndMatmulToVectorPatterns(funcOp, "L2", stage1Patterns); } { @@ -598,7 +598,7 @@ tilingPattern.add, linalg::LinalgTilingPattern>( context, linalgTilingOptions, - linalg::LinalgTransformationFilter(Identifier::get("tile", context))); + linalg::LinalgTransformationFilter(StringAttr::get(context, "tile"))); (void)applyPatternsAndFoldGreedily(funcOp, std::move(tilingPattern)); } diff --git a/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp b/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp --- a/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp +++ b/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp @@ -31,7 +31,7 @@ auto module = getOperation(); // Report the shape function available to refine the op. - auto shapeFnId = Identifier::get("shape.function", &getContext()); + auto shapeFnId = StringAttr::get(&getContext(), "shape.function"); auto remarkShapeFn = [&](shape::FunctionLibraryOp shapeFnLib, Operation *op) { if (op->hasTrait()) return true; diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -963,7 +963,7 @@ } auto namesAttr = parser.getBuilder().getStrArrayAttr(names); - result.attributes.push_back({Identifier::get("names", context), namesAttr}); + result.attributes.push_back({StringAttr::get(context, "names"), namesAttr}); return success(); } diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -43,19 +43,19 @@ // DECL-SAME: {::llvm::StringRef("aAttr"), ::llvm::StringRef("bAttr"), ::llvm::StringRef("cAttr")}; // DECL-NEXT: return ::llvm::makeArrayRef(attrNames); -// DECL: ::mlir::Identifier aAttrAttrName() +// DECL: ::mlir::StringAttr aAttrAttrName() // DECL-NEXT: return getAttributeNameForIndex(0); -// DECL: ::mlir::Identifier aAttrAttrName(::mlir::OperationName name) +// DECL: ::mlir::StringAttr aAttrAttrName(::mlir::OperationName name) // DECL-NEXT: return getAttributeNameForIndex(name, 0); -// DECL: ::mlir::Identifier bAttrAttrName() +// DECL: ::mlir::StringAttr bAttrAttrName() // DECL-NEXT: return getAttributeNameForIndex(1); -// DECL: ::mlir::Identifier bAttrAttrName(::mlir::OperationName name) +// DECL: ::mlir::StringAttr bAttrAttrName(::mlir::OperationName name) // DECL-NEXT: return getAttributeNameForIndex(name, 1); -// DECL: ::mlir::Identifier cAttrAttrName() +// DECL: ::mlir::StringAttr cAttrAttrName() // DECL-NEXT: return getAttributeNameForIndex(2); -// DECL: ::mlir::Identifier cAttrAttrName(::mlir::OperationName name) +// DECL: ::mlir::StringAttr cAttrAttrName(::mlir::OperationName name) // DECL-NEXT: return getAttributeNameForIndex(name, 2); // DEF-LABEL: AOp definitions @@ -157,19 +157,19 @@ // DECL-SAME: {::llvm::StringRef("aAttr"), ::llvm::StringRef("bAttr"), ::llvm::StringRef("cAttr")}; // DECL-NEXT: return ::llvm::makeArrayRef(attrNames); -// DECL: ::mlir::Identifier getAAttrAttrName() +// DECL: ::mlir::StringAttr getAAttrAttrName() // DECL-NEXT: return getAttributeNameForIndex(0); -// DECL: ::mlir::Identifier getAAttrAttrName(::mlir::OperationName name) +// DECL: ::mlir::StringAttr getAAttrAttrName(::mlir::OperationName name) // DECL-NEXT: return getAttributeNameForIndex(name, 0); -// DECL: ::mlir::Identifier getBAttrAttrName() +// DECL: ::mlir::StringAttr getBAttrAttrName() // DECL-NEXT: return getAttributeNameForIndex(1); -// DECL: ::mlir::Identifier getBAttrAttrName(::mlir::OperationName name) +// DECL: ::mlir::StringAttr getBAttrAttrName(::mlir::OperationName name) // DECL-NEXT: return getAttributeNameForIndex(name, 1); -// DECL: ::mlir::Identifier getCAttrAttrName() +// DECL: ::mlir::StringAttr getCAttrAttrName() // DECL-NEXT: return getAttributeNameForIndex(2); -// DECL: ::mlir::Identifier getCAttrAttrName(::mlir::OperationName name) +// DECL: ::mlir::StringAttr getCAttrAttrName(::mlir::OperationName name) // DECL-NEXT: return getAttributeNameForIndex(name, 2); // DEF-LABEL: AgetOp definitions diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp --- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp +++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp @@ -1092,7 +1092,7 @@ } genContext.setLoc(NameLoc::get( - Identifier::get(opConfig.metadata->cppClassName, &mlirContext))); + StringAttr::get(&mlirContext, opConfig.metadata->cppClassName))); if (failed(generateOp(opConfig, genContext))) { return 1; } diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -655,7 +655,7 @@ // Emit the getAttributeNameForIndex methods. { auto *method = opClass.addInlineMethod( - "::mlir::Identifier", "getAttributeNameForIndex", + "::mlir::StringAttr", "getAttributeNameForIndex", MethodParameter("unsigned", "index")); ERROR_IF_PRUNED(method, "getAttributeNameForIndex", op); method->body() @@ -663,7 +663,7 @@ } { auto *method = opClass.addStaticInlineMethod( - "::mlir::Identifier", "getAttributeNameForIndex", + "::mlir::StringAttr", "getAttributeNameForIndex", MethodParameter("::mlir::OperationName", "name"), MethodParameter("unsigned", "index")); ERROR_IF_PRUNED(method, "getAttributeNameForIndex", op); @@ -683,7 +683,7 @@ // Generate the non-static variant. { auto *method = - opClass.addInlineMethod("::mlir::Identifier", methodName); + opClass.addInlineMethod("::mlir::StringAttr", methodName); ERROR_IF_PRUNED(method, methodName, op); method->body() << llvm::formatv(attrNameMethodBody, attrIt.second).str(); @@ -692,7 +692,7 @@ // Generate the static variant. { auto *method = opClass.addStaticInlineMethod( - "::mlir::Identifier", methodName, + "::mlir::StringAttr", methodName, MethodParameter("::mlir::OperationName", "name")); ERROR_IF_PRUNED(method, methodName, op); method->body() << llvm::formatv(attrNameMethodBody, diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -1145,7 +1145,7 @@ if (tree.getNumArgs() == 1) { DagLeaf leaf = tree.getArgAsLeaf(0); if (leaf.isStringAttr()) - return formatv("::mlir::NameLoc::get(rewriter.getIdentifier(\"{0}\"))", + return formatv("::mlir::NameLoc::get(rewriter.getStringAttr(\"{0}\"))", leaf.getStringAttr()) .str(); return lookUpArgLoc(0); @@ -1607,7 +1607,7 @@ const char *addAttrCmd = "if (auto tmpAttr = {1}) {\n" - " tblgen_attrs.emplace_back(rewriter.getIdentifier(\"{0}\"), " + " tblgen_attrs.emplace_back(rewriter.getStringAttr(\"{0}\"), " "tmpAttr);\n}\n"; for (int argIndex = 0, e = resultOp.getNumArgs(); argIndex < e; ++argIndex) { if (resultOp.getArg(argIndex).is()) { diff --git a/mlir/tools/mlir-tblgen/StructsGen.cpp b/mlir/tools/mlir-tblgen/StructsGen.cpp --- a/mlir/tools/mlir-tblgen/StructsGen.cpp +++ b/mlir/tools/mlir-tblgen/StructsGen.cpp @@ -131,13 +131,13 @@ const char *getFieldInfo = R"( assert({0}); - auto {0}_id = ::mlir::Identifier::get("{0}", context); + auto {0}_id = ::mlir::StringAttr::get(context, "{0}"); fields.emplace_back({0}_id, {0}); )"; const char *getFieldInfoOptional = R"( if ({0}) { - auto {0}_id = ::mlir::Identifier::get("{0}", context); + auto {0}_id = ::mlir::StringAttr::get(context, "{0}"); fields.emplace_back({0}_id, {0}); } )"; diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp --- a/mlir/unittests/IR/AttributeTest.cpp +++ b/mlir/unittests/IR/AttributeTest.cpp @@ -8,7 +8,6 @@ #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/IR/Identifier.h" #include "gtest/gtest.h" using namespace mlir; @@ -152,7 +151,7 @@ MLIRContext context; context.allowUnregisteredDialects(); Type stringType = - OpaqueType::get(Identifier::get("test", &context), "string"); + OpaqueType::get(StringAttr::get(&context, "test"), "string"); StringRef value = "test-string"; testSplat(stringType, value); } @@ -161,7 +160,7 @@ MLIRContext context; context.allowUnregisteredDialects(); Type stringType = - OpaqueType::get(Identifier::get("test", &context), "string"); + OpaqueType::get(StringAttr::get(&context, "test"), "string"); Attribute stringAttr = StringAttr::get("test-string", stringType); testSplat(stringType, stringAttr); } @@ -211,7 +210,7 @@ IntegerType intTy = IntegerType::get(&context, 32); FloatType floatTy = FloatType::getF32(&context); - Type stringTy = OpaqueType::get(Identifier::get("test", &context), "string"); + Type stringTy = OpaqueType::get(StringAttr::get(&context, "test"), "string"); ShapedType tensorI32 = RankedTensorType::get({2, 2}, intTy); ShapedType tensorF32 = RankedTensorType::get({2, 2}, floatTy); diff --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp --- a/mlir/unittests/IR/OperationSupportTest.cpp +++ b/mlir/unittests/IR/OperationSupportTest.cpp @@ -237,10 +237,10 @@ { auto it = attrs.begin(); - EXPECT_EQ(it->first, b.getIdentifier("foo")); + EXPECT_EQ(it->first, b.getStringAttr("foo")); EXPECT_EQ(it->second, b.getStringAttr("bar")); ++it; - EXPECT_EQ(it->first, b.getIdentifier("baz")); + EXPECT_EQ(it->first, b.getStringAttr("baz")); EXPECT_EQ(it->second, b.getStringAttr("boo")); } @@ -261,10 +261,10 @@ { auto it = attrs.begin(); - EXPECT_EQ(it->first, b.getIdentifier("foo")); + EXPECT_EQ(it->first, b.getStringAttr("foo")); EXPECT_EQ(it->second, b.getStringAttr("f")); ++it; - EXPECT_EQ(it->first, b.getIdentifier("zoo")); + EXPECT_EQ(it->first, b.getStringAttr("zoo")); EXPECT_EQ(it->second, b.getStringAttr("z")); } diff --git a/mlir/unittests/TableGen/OpBuildGen.cpp b/mlir/unittests/TableGen/OpBuildGen.cpp --- a/mlir/unittests/TableGen/OpBuildGen.cpp +++ b/mlir/unittests/TableGen/OpBuildGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" -#include "mlir/IR/Identifier.h" #include "gmock/gmock.h" #include diff --git a/mlir/unittests/TableGen/StructsGenTest.cpp b/mlir/unittests/TableGen/StructsGenTest.cpp --- a/mlir/unittests/TableGen/StructsGenTest.cpp +++ b/mlir/unittests/TableGen/StructsGenTest.cpp @@ -9,7 +9,6 @@ #include "mlir/IR/Attributes.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/IR/Identifier.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" @@ -62,7 +61,7 @@ expectedValues.end()); // Add an extra NamedAttribute. - auto wrongId = mlir::Identifier::get("wrong", &context); + auto wrongId = mlir::StringAttr::get(&context, "wrong"); auto wrongAttr = mlir::NamedAttribute(wrongId, expectedValues[0].second); newValues.push_back(wrongAttr); @@ -83,8 +82,8 @@ llvm::SmallVector newValues( expectedValues.begin() + 1, expectedValues.end()); - // Add a copy of the first attribute with the wrong Identifier. - auto wrongId = mlir::Identifier::get("wrong", &context); + // Add a copy of the first attribute with the wrong name. + auto wrongId = mlir::StringAttr::get(&context, "wrong"); auto wrongAttr = mlir::NamedAttribute(wrongId, expectedValues[0].second); newValues.push_back(wrongAttr); @@ -109,7 +108,7 @@ auto elementsType = mlir::RankedTensorType::get({3}, i64Type); auto elementsAttr = mlir::DenseIntElementsAttr::get(elementsType, ArrayRef{1, 2, 3}); - mlir::Identifier id = expectedValues.back().first; + mlir::StringAttr id = expectedValues.back().first; auto wrongAttr = mlir::NamedAttribute(id, elementsAttr); newValues.push_back(wrongAttr); diff --git a/mlir/utils/gdb-scripts/prettyprinters.py b/mlir/utils/gdb-scripts/prettyprinters.py --- a/mlir/utils/gdb-scripts/prettyprinters.py +++ b/mlir/utils/gdb-scripts/prettyprinters.py @@ -3,20 +3,6 @@ import gdb.printing -class IdentifierPrinter: - """Prints an mlir::Identifier instance.""" - - def __init__(self, val): - self.entry = val['entry'] - - def to_string(self): - ptr = (self.entry + 1).cast(gdb.lookup_type('char').pointer()) - return ptr.string(length=self.entry['keyLength']) - - def display_hint(self): - return 'string' - - class StoragePrinter: """Prints bases of a struct and its fields.""" @@ -159,8 +145,6 @@ pp = gdb.printing.RegexpCollectionPrettyPrinter('MLIRSupport') -pp.add_printer('mlir::Identifier', '^mlir::Identifier$', IdentifierPrinter) - # Printers for types deriving from AttributeStorage or TypeStorage. pp.add_printer('mlir::detail::FusedLocationStorage', '^mlir::detail::FusedLocationStorage',