This is part of the replacement of Identifier with StringAttr.
Differential Revision: https://reviews.llvm.org/D113953
_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
```c++
void *TestDialect::getRegisteredInterfaceForOp(TypeID typeID,
- Identifier opName) {
+ StringAttr opName) {
if (typeID == TypeID::get<ExampleOpInterface>()) {
if (isSupported(opName))
return fallbackExampleOpInterface;
/// Our value represents the combined metadata, which is originally a
/// DictionaryAttr, so we use a map.
- DenseMap<Identifier, Attribute> metadata;
+ DenseMap<StringAttr, Attribute> metadata;
};
```
/// 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);
}
/// 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);
}
/// 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);
}
/// 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);
}
/// 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);
}
/// 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);
}
#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"
ConcreteOp op = cast<ConcreteOp>(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()};
}]
>,
/// 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()};
}
/// associated with 'memref'.
NamedAttribute getAffineMapAttrForMemRef(Value memref) {
assert(memref == getTagMemRef());
- return {Identifier::get(getTagMapAttrName(), getContext()),
+ return {StringAttr::get(getContext(), getTagMapAttrName()),
getTagMapAttr()};
}
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));
}
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()};
}
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.
#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"
using FilterFunction = std::function<LogicalResult(Operation *)>;
explicit LinalgTransformationFilter(
- ArrayRef<Identifier> matchDisjunction = {},
- Optional<Identifier> replacement = None);
+ ArrayRef<StringAttr> matchDisjunction = {},
+ Optional<StringAttr> replacement = None);
explicit LinalgTransformationFilter(
- FilterFunction f, ArrayRef<Identifier> matchDisjunction = {},
- Optional<Identifier> replacement = None);
+ FilterFunction f, ArrayRef<StringAttr> matchDisjunction = {},
+ Optional<StringAttr> replacement = None);
LinalgTransformationFilter(LinalgTransformationFilter &&) = default;
LinalgTransformationFilter(const LinalgTransformationFilter &) = default;
private:
SmallVector<FilterFunction> filters;
- SmallVector<Identifier> matchDisjunction;
- Optional<Identifier> replacement;
+ SmallVector<StringAttr> matchDisjunction;
+ Optional<StringAttr> replacement;
/// When set to true, if the attribute is not set, it will be treated as
/// a match. Default is false.
bool matchByDefault;
// 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<Identifier, Attribute>;
+using NamedAttribute = std::pair<StringAttr, Attribute>;
bool operator<(const NamedAttribute &lhs, const NamedAttribute &rhs);
bool operator<(const NamedAttribute &lhs, StringRef rhs);
MLIRContext *getContext() const { return context; }
- Identifier getIdentifier(const Twine &str);
+ StringAttr getIdentifier(const Twine &str);
// Locations.
Location getUnknownLoc();
/// 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<NamedAttribute> getNamed(StringRef name) const;
- Optional<NamedAttribute> getNamed(Identifier name) const;
+ Optional<NamedAttribute> 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<NamedAttribute>::iterator;
#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);
// 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);
"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);
}]>
];
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);
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);
}]>
];
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()));
}]>
class StringAttr;
class TypeRange;
-// TODO: Remove this when all usages have been replaced with StringAttr.
-using Identifier = StringAttr;
-
//===----------------------------------------------------------------------===//
// FloatType
//===----------------------------------------------------------------------===//
```
}];
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);
}]>
/// 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;
}
}
template <typename AttrClass>
- AttrClass getArgAttrOfType(unsigned index, Identifier name) {
+ AttrClass getArgAttrOfType(unsigned index, StringAttr name) {
return getArgAttr(index, name).template dyn_cast_or_null<AttrClass>();
}
template <typename AttrClass>
/// 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));
}
//===--------------------------------------------------------------------===//
/// 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;
}
}
template <typename AttrClass>
- AttrClass getResultAttrOfType(unsigned index, Identifier name) {
+ AttrClass getResultAttrOfType(unsigned index, StringAttr name) {
return getResultAttr(index, name).template dyn_cast_or_null<AttrClass>();
}
template <typename AttrClass>
/// 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'.
/// 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 <typename ConcreteType>
-void FunctionLike<ConcreteType>::setArgAttr(unsigned index, Identifier name,
+void FunctionLike<ConcreteType>::setArgAttr(unsigned index, StringAttr name,
Attribute value) {
NamedAttrList attributes(getArgAttrDict(index));
Attribute oldValue = attributes.set(name, value);
/// Remove the attribute 'name' from the argument at 'index'.
template <typename ConcreteType>
Attribute FunctionLike<ConcreteType>::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);
/// 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 <typename ConcreteType>
-void FunctionLike<ConcreteType>::setResultAttr(unsigned index, Identifier name,
+void FunctionLike<ConcreteType>::setResultAttr(unsigned index, StringAttr name,
Attribute value) {
NamedAttrList attributes(getResultAttrDict(index));
Attribute oldAttr = attributes.set(name, value);
/// Remove the attribute 'name' from the result at 'index'.
template <typename ConcreteType>
Attribute FunctionLike<ConcreteType>::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);
: Type<CPred<"isOpaqueTypeWithName($_self, \""#dialect#"\", \""#name#"\")">,
summary, "::mlir::OpaqueType">,
BuildableType<"::mlir::OpaqueType::get("
- "$_builder.getIdentifier(\"" # dialect # "\"), \""
+ "$_builder.getStringAttr(\"" # dialect # "\"), \""
# name # "\")">;
// Function Type
}
/// 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 <typename AttrClass> AttrClass getAttrOfType(Identifier name) {
+ template <typename AttrClass>
+ AttrClass getAttrOfType(StringAttr name) {
return getAttr(name).dyn_cast_or_null<AttrClass>();
}
- template <typename AttrClass> AttrClass getAttrOfType(StringRef name) {
+ template <typename AttrClass>
+ AttrClass getAttrOfType(StringRef name) {
return getAttr(name).dyn_cast_or_null<AttrClass>();
}
/// 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 <typename AttrClass, typename NameT>
bool hasAttrOfType(NameT &&name) {
/// 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)
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.
#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"
llvm::unique_function<LogicalResult(Operation *) const>;
/// This is the name of the operation.
- const Identifier name;
+ const StringAttr name;
/// This is the dialect that this operation belongs to.
Dialect &dialect;
/// greatly simplifying the cost and complexity of attribute usage produced by
/// the generator.
///
- ArrayRef<Identifier> getAttributeNames() const { return attributeNames; }
+ ArrayRef<StringAttr> getAttributeNames() const { return attributeNames; }
private:
AbstractOperation(StringRef name, Dialect &dialect, TypeID typeID,
FoldHookFn &&foldHook,
GetCanonicalizationPatternsFn &&getCanonicalizationPatterns,
detail::InterfaceMap &&interfaceMap, HasTraitFn &&hasTrait,
- ArrayRef<Identifier> attrNames);
+ ArrayRef<StringAttr> attrNames);
/// Give Op access to lookupMutable.
template <typename ConcreteType, template <typename T> class... Traits>
/// 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<Identifier> attributeNames;
+ ArrayRef<StringAttr> attributeNames;
};
//===----------------------------------------------------------------------===//
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 <typename IteratorT>
std::pair<IteratorT, bool> 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());
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));
}
ArrayRef<NamedAttribute> 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<NamedAttribute> getNamed(StringRef name) const;
- Optional<NamedAttribute> getNamed(Identifier name) const;
+ Optional<NamedAttribute> 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(); }
class OperationName {
public:
using RepresentationUnion =
- PointerUnion<Identifier, const AbstractOperation *>;
+ PointerUnion<StringAttr, const AbstractOperation *>;
OperationName(AbstractOperation *op) : representation(op) {}
OperationName(StringRef name, MLIRContext *context);
Dialect *getDialect() const {
if (const auto *abstractOp = getAbstractOperation())
return &abstractOp->dialect;
- return representation.get<Identifier>().getReferencedDialect();
+ return representation.get<StringAttr>().getReferencedDialect();
}
/// Return the operation name with dialect name stripped, if it has one.
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.
/// 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);
}
namespace mlir {
class DataLayout;
class DataLayoutEntryInterface;
-using DataLayoutEntryKey = llvm::PointerUnion<Type, Identifier>;
+using DataLayoutEntryKey = llvm::PointerUnion<Type, StringAttr>;
// 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<DataLayoutEntryInterface, 4>;
/// 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
"present.",
/*retTy=*/"::mlir::DataLayoutEntryInterface",
/*methodName=*/"getSpecForIdentifier",
- /*args=*/(ins "::mlir::Identifier":$identifier),
+ /*args=*/(ins "::mlir::StringAttr":$identifier),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return ::mlir::detail::filterEntryForIdentifier($_attr.getEntries(),
/// method directly.
void bucketEntriesByType(
::llvm::DenseMap<::mlir::TypeID, ::mlir::DataLayoutEntryList> &types,
- ::llvm::DenseMap<::mlir::Identifier,
+ ::llvm::DenseMap<::mlir::StringAttr,
::mlir::DataLayoutEntryInterface> &ids);
}];
}
#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"
/// 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
/// 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.
class PassInstrumentor;
class StringAttr;
-// TODO: Remove this when all usages have been replaced with StringAttr.
-using Identifier = StringAttr;
-
namespace detail {
struct OpPassManagerImpl;
class OpToOpPassAdaptor;
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);
/// 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 <typename OpT> OpPassManager &nest() {
return nest(OpT::getOperationName());
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;
#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 {
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)));
}
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) {
//===----------------------------------------------------------------------===//
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) {
struct GPUFuncOpLowering : ConvertOpToLLVMPattern<gpu::GPUFuncOp> {
GPUFuncOpLowering(LLVMTypeConverter &converter, unsigned allocaAddrSpace,
- Identifier kernelAttributeName)
+ StringAttr kernelAttributeName)
: ConvertOpToLLVMPattern<gpu::GPUFuncOp>(converter),
allocaAddrSpace(allocaAddrSpace),
kernelAttributeName(kernelAttributeName) {}
unsigned allocaAddrSpace;
/// The attribute name to use instead of `gpu.kernel`.
- Identifier kernelAttributeName;
+ StringAttr kernelAttributeName;
};
struct GPUReturnOpLowering : public ConvertOpToLLVMPattern<gpu::ReturnOp> {
// memory space and does not support `alloca`s with addrspace(5).
patterns.add<GPUFuncOpLowering>(
converter, /*allocaAddrSpace=*/0,
- Identifier::get(NVVM::NVVMDialect::getKernelFuncAttrName(),
- &converter.getContext()));
+ StringAttr::get(&converter.getContext(),
+ NVVM::NVVMDialect::getKernelFuncAttrName()));
patterns.add<OpToFuncCallLowering<math::AbsOp>>(converter, "__nv_fabsf",
"__nv_fabs");
GPUReturnOpLowering>(converter);
patterns.add<GPUFuncOpLowering>(
converter, /*allocaAddrSpace=*/5,
- Identifier::get(ROCDL::ROCDLDialect::getKernelFuncAttrName(),
- &converter.getContext()));
+ StringAttr::get(&converter.getContext(),
+ ROCDL::ROCDLDialect::getKernelFuncAttrName()));
patterns.add<OpToFuncCallLowering<math::AbsOp>>(converter, "__ocml_fabs_f32",
"__ocml_fabs_f64");
patterns.add<OpToFuncCallLowering<math::AtanOp>>(converter, "__ocml_atan_f32",
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();
}
/// A position describing an attribute of an operation.
struct AttributePosition
: public PredicateBase<AttributePosition, Position,
- std::pair<OperationPosition *, Identifier>,
+ std::pair<OperationPosition *, StringAttr>,
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; }
};
//===----------------------------------------------------------------------===//
/// 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.
/// Utility to simplify an affine attribute and update its entry in the parent
/// operation if necessary.
template <typename AttributeT>
- void simplifyAndUpdateAttribute(Operation *op, Identifier name,
+ void simplifyAndUpdateAttribute(Operation *op, StringAttr name,
AttributeT attr) {
auto &simplified = simplifiedAttributes[attr];
if (simplified == attr)
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.
} // 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);
}
return {};
return type ? get(type, value)
- : get(parser.getBuilder().getIdentifier(identifier), value);
+ : get(parser.getBuilder().getStringAttr(identifier), value);
}
void DataLayoutEntryAttr::print(AsmPrinter &os) const {
if (auto type = getKey().dyn_cast<Type>())
os << type;
else
- os << "\"" << getKey().get<Identifier>().strref() << "\"";
+ os << "\"" << getKey().get<StringAttr>().strref() << "\"";
os << ", " << getValue() << ">";
}
DataLayoutSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
ArrayRef<DataLayoutEntryInterface> entries) {
DenseSet<Type> types;
- DenseSet<Identifier> ids;
+ DenseSet<StringAttr> ids;
for (DataLayoutEntryInterface entry : entries) {
if (auto type = entry.getKey().dyn_cast<Type>()) {
if (!types.insert(type).second)
return emitError() << "repeated layout entry key: " << type;
} else {
- auto id = entry.getKey().get<Identifier>();
+ auto id = entry.getKey().get<StringAttr>();
if (!ids.insert(id).second)
return emitError() << "repeated layout entry key: " << id.getValue();
}
static LogicalResult
combineOneSpec(DataLayoutSpecInterface spec,
DenseMap<TypeID, DataLayoutEntryList> &entriesForType,
- DenseMap<Identifier, DataLayoutEntryInterface> &entriesForID) {
+ DenseMap<StringAttr, DataLayoutEntryInterface> &entriesForID) {
// A missing spec should be fine.
if (!spec)
return success();
DenseMap<TypeID, DataLayoutEntryList> newEntriesForType;
- DenseMap<Identifier, DataLayoutEntryInterface> newEntriesForID;
+ DenseMap<StringAttr, DataLayoutEntryInterface> newEntriesForID;
spec.bucketEntriesByType(newEntriesForType, newEntriesForID);
// Try overwriting the old entries with the new ones.
}
for (const auto &kvp : newEntriesForID) {
- Identifier id = kvp.second.getKey().get<Identifier>();
+ StringAttr id = kvp.second.getKey().get<StringAttr>();
Dialect *dialect = id.getReferencedDialect();
if (!entriesForID.count(id)) {
entriesForID[id] = kvp.second;
// Combine all specs in order, with `this` being the last one.
DenseMap<TypeID, DataLayoutEntryList> entriesForType;
- DenseMap<Identifier, DataLayoutEntryInterface> entriesForID;
+ DenseMap<StringAttr, DataLayoutEntryInterface> entriesForID;
for (DataLayoutSpecInterface spec : specs)
if (failed(combineOneSpec(spec, entriesForType, entriesForID)))
return nullptr;
LogicalResult verifyEntry(DataLayoutEntryInterface entry,
Location loc) const final {
- StringRef entryName = entry.getKey().get<Identifier>().strref();
+ StringRef entryName = entry.getKey().get<StringAttr>().strref();
if (entryName == DLTIDialect::kDataLayoutEndiannessKey) {
auto value = entry.getValue().dyn_cast<StringAttr>();
if (value &&
const std::unique_ptr<Transformation> &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<Identifier>{}, nextState)
+ t->filter, ArrayRef<StringAttr>{}, nextState)
: linalg::LinalgTransformationFilter(
t->filter, currentState, nextState);
t->addToPassPipeline(pm, filter);
auto *ctx = patterns.getContext();
patterns.add<LinalgTilingPattern<OpTy>>(
ctx, options,
- LinalgTransformationFilter(ArrayRef<Identifier>{},
- Identifier::get("tiled", ctx)));
+ LinalgTransformationFilter(ArrayRef<StringAttr>{},
+ StringAttr::get(ctx, "tiled")));
RewritePatternList<OpTypes...>::insert(patterns, options);
}
};
"__internal_linalg_transform__";
mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter(
- ArrayRef<Identifier> matchDisjunction, Optional<Identifier> replacement)
+ ArrayRef<StringAttr> matchDisjunction, Optional<StringAttr> replacement)
: matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()),
replacement(replacement), matchByDefault(false) {}
mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter(
- FilterFunction f, ArrayRef<Identifier> matchDisjunction,
- Optional<Identifier> replacement)
+ FilterFunction f, ArrayRef<StringAttr> matchDisjunction,
+ Optional<StringAttr> replacement)
: filters(),
matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()),
replacement(replacement), matchByDefault(false) {
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 &
constexpr static StringRef kPromotedMarker = "PROMOTED";
tilingPatterns.add<LinalgTilingPattern<ConvOp>>(
context, LinalgTilingOptions().setTileSizes(tileSizes),
- LinalgTransformationFilter(ArrayRef<Identifier>{},
- Identifier::get(kTiledMarker, context)));
+ LinalgTransformationFilter(ArrayRef<StringAttr>{},
+ StringAttr::get(kTiledMarker, context)));
promotionPatterns.add<LinalgPromotionPattern<ConvOp>>(
context, LinalgPromotionOptions().setUseFullTileBuffersByDefault(true),
- LinalgTransformationFilter(Identifier::get(kTiledMarker, context),
- Identifier::get(kPromotedMarker, context)));
+ LinalgTransformationFilter(StringAttr::get(kTiledMarker, context),
+ StringAttr::get(kPromotedMarker, context)));
SmallVector<bool, 4> mask(N);
int offset = tileSizes.size() - N;
#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"
if (auto arr = attribute.second.dyn_cast<ArrayAttr>()) {
// Verify all entries are function libraries and mappings in libraries
// refer to unique ops.
- DenseSet<Identifier> key;
+ DenseSet<StringAttr> key;
for (auto it : arr) {
if (!it.isa<SymbolRefAttr>())
return op->emitError(
#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"
using namespace mlir;
-Identifier Builder::getIdentifier(const Twine &str) {
- return Identifier::get(str, context);
+StringAttr Builder::getIdentifier(const Twine &str) {
+ return getStringAttr(str);
}
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
NamedAttribute Builder::getNamedAttr(StringRef name, Attribute val) {
- return NamedAttribute(getIdentifier(name), val);
+ return NamedAttribute(getStringAttr(name), val);
}
UnitAttr Builder::getUnitAttr() { return UnitAttr::get(context); }
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();
}
auto it = impl::findAttrSorted(begin(), end(), name);
return it.second ? *it.first : Optional<NamedAttribute>();
}
-Optional<NamedAttribute> DictionaryAttr::getNamed(Identifier name) const {
+Optional<NamedAttribute> DictionaryAttr::getNamed(StringAttr name) const {
auto it = impl::findAttrSorted(begin(), end(), name);
return it.second ? *it.first : Optional<NamedAttribute>();
}
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;
}
//===----------------------------------------------------------------------===//
LogicalResult OpaqueAttr::verify(function_ref<InFlightDiagnostic()> emitError,
- Identifier dialect, StringRef attrData,
+ StringAttr dialect, StringRef attrData,
Type type) {
if (!Dialect::isValidNamespace(dialect.strref()))
return emitError() << "invalid dialect namespace '" << dialect << "'";
LogicalResult
OpaqueElementsAttr::verify(function_ref<InFlightDiagnostic()> emitError,
- Identifier dialect, StringRef value,
+ StringAttr dialect, StringRef value,
ShapedType type) {
if (!Dialect::isValidNamespace(dialect.strref()))
return emitError() << "invalid dialect namespace '" << dialect << "'";
/// from this function to dest.
void FuncOp::cloneInto(FuncOp dest, BlockAndValueMapping &mapper) {
// Add the attributes of this function to dest.
- llvm::MapVector<Identifier, Attribute> newAttrs;
+ llvm::MapVector<StringAttr, Attribute> newAttrs;
for (const auto &attr : dest->getAttrs())
newAttrs.insert(attr);
for (const auto &attr : (*this)->getAttrs())
/// Verify the construction of an opaque type.
LogicalResult OpaqueType::verify(function_ref<InFlightDiagnostic()> emitError,
- Identifier dialect, StringRef typeData) {
+ StringAttr dialect, StringRef typeData) {
if (!Dialect::isValidNamespace(dialect.strref()))
return emitError() << "invalid dialect namespace '" << dialect << "'";
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());
}
#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"
"context");
// Register the attribute names of this operation.
- MutableArrayRef<Identifier> cachedAttrNames;
+ MutableArrayRef<StringAttr> cachedAttrNames;
if (!attrNames.empty()) {
- cachedAttrNames = MutableArrayRef<Identifier>(
- impl.abstractDialectSymbolAllocator.Allocate<Identifier>(
+ cachedAttrNames = MutableArrayRef<StringAttr>(
+ impl.abstractDialectSymbolAllocator.Allocate<StringAttr>(
attrNames.size()),
attrNames.size());
for (unsigned i : llvm::seq<unsigned>(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.
VerifyInvariantsFn &&verifyInvariants, FoldHookFn &&foldHook,
GetCanonicalizationPatternsFn &&getCanonicalizationPatterns,
detail::InterfaceMap &&interfaceMap, HasTraitFn &&hasTrait,
- ArrayRef<Identifier> attrNames)
- : name(Identifier::get(name, dialect.getContext())), dialect(dialect),
+ ArrayRef<StringAttr> attrNames)
+ : name(StringAttr::get(dialect.getContext(), name)), dialect(dialect),
typeID(typeID), interfaceMap(std::move(interfaceMap)),
foldHookFn(std::move(foldHook)),
getCanonicalizationPatternsFn(std::move(getCanonicalizationPatterns)),
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.
}
/// 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<const AbstractOperation *>())
return op->name;
- return representation.get<Identifier>();
+ return representation.get<StringAttr>();
}
OperationName OperationName::getFromOpaquePointer(const void *pointer) {
/// 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.
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();
}
auto it = findAttr(*this, name);
return it.second ? *it.first : Optional<NamedAttribute>();
}
-Optional<NamedAttribute> NamedAttrList::getNamed(Identifier name) const {
+Optional<NamedAttribute> NamedAttrList::getNamed(StringAttr name) const {
auto it = findAttr(*this, name);
return it.second ? *it.first : Optional<NamedAttribute>();
}
/// 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
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
return attr;
}
-Attribute NamedAttrList::erase(Identifier name) {
+Attribute NamedAttrList::erase(StringAttr name) {
auto it = findAttr(*this, name);
return it.second ? eraseImpl(it.first) : Attribute();
}
static StringAttr getNameIfSymbol(Operation *op) {
return op->getAttrOfType<StringAttr>(SymbolTable::getSymbolAttrName());
}
-static StringAttr getNameIfSymbol(Operation *op, Identifier symbolAttrNameId) {
+static StringAttr getNameIfSymbol(Operation *op, StringAttr symbolAttrNameId) {
return op->getAttrOfType<StringAttr>(symbolAttrNameId);
}
// Collect references until 'symbolTableOp' reaches 'within'.
SmallVector<FlatSymbolRefAttr, 1> 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<OpTrait::SymbolTable>())
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)
// 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;
}
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;
#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"
DataLayoutEntryInterface
mlir::detail::filterEntryForIdentifier(DataLayoutEntryListRef entries,
- Identifier id) {
+ StringAttr id) {
const auto *it = llvm::find_if(entries, [id](DataLayoutEntryInterface entry) {
- if (!entry.getKey().is<Identifier>())
+ if (!entry.getKey().is<StringAttr>())
return false;
- return entry.getKey().get<Identifier>() == id;
+ return entry.getKey().get<StringAttr>() == id;
});
return it == entries.end() ? DataLayoutEntryInterface() : *it;
}
void DataLayoutSpecInterface::bucketEntriesByType(
DenseMap<TypeID, DataLayoutEntryList> &types,
- DenseMap<Identifier, DataLayoutEntryInterface> &ids) {
+ DenseMap<StringAttr, DataLayoutEntryInterface> &ids) {
for (DataLayoutEntryInterface entry : getEntries()) {
if (auto type = entry.getKey().dyn_cast<Type>())
types[type.getTypeID()].push_back(entry);
else
- ids[entry.getKey().get<Identifier>()] = entry;
+ ids[entry.getKey().get<StringAttr>()] = entry;
}
}
// Second, dispatch verifications of entry groups to types or dialects they
// are are associated with.
DenseMap<TypeID, DataLayoutEntryList> types;
- DenseMap<Identifier, DataLayoutEntryInterface> ids;
+ DenseMap<StringAttr, DataLayoutEntryInterface> ids;
spec.bucketEntriesByType(types, ids);
for (const auto &kvp : types) {
}
for (const auto &kvp : ids) {
- Identifier identifier = kvp.second.getKey().get<Identifier>();
+ StringAttr identifier = kvp.second.getKey().get<StringAttr>();
Dialect *dialect = identifier.getReferencedDialect();
// Ignore attributes that belong to an unknown dialect, the dialect may
/// attribute-entry ::= (bare-id | string-literal) `=` attribute-value
///
ParseResult Parser::parseAttributeDict(NamedAttrList &attributes) {
- llvm::SmallDenseSet<Identifier> seenKeys;
+ llvm::SmallDenseSet<StringAttr> seenKeys;
auto parseElt = [&]() -> ParseResult {
// The name of an attribute can either be a bare identifier, or a string.
- Optional<Identifier> nameId;
+ Optional<StringAttr> 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)
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.
// 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));
});
// Otherwise, form a new opaque type.
return OpaqueType::getChecked(
[&] { return emitError(loc); },
- Identifier::get(dialectName, state.context), symbolData);
+ StringAttr::get(state.context, dialectName), symbolData);
});
}
#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"
if (childLoc.isa<NameLoc>())
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();
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)
/// 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
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;
}
/// The cached identifier (internalized in the context) for the name of the
/// operation that passes of this pass manager operate on.
- Optional<Identifier> identifier;
+ Optional<StringAttr> identifier;
/// The set of passes to run as part of this pass manager.
std::vector<std::unique_ptr<Pass>> passes;
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<Pass>(adaptor));
// 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)) {}
/// 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) {
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);
}
/// 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<OpPassManager> mgrs,
- Identifier name,
+ StringAttr name,
MLIRContext &context) {
auto it = llvm::find_if(
mgrs, [&](OpPassManager &mgr) { return mgr.getOpName(context) == name; });
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<llvm::hash_code>::getTombstoneKey()),
passTiming(false), verifyPasses(true) {}
/// See PassInstrumentation::runBeforePipeline for details.
void PassInstrumentor::runBeforePipeline(
- Identifier name,
+ StringAttr name,
const PassInstrumentation::PipelineParentInfo &parentInfo) {
llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex);
for (auto &instr : impl->instrumentations)
/// See PassInstrumentation::runAfterPipeline for details.
void PassInstrumentor::runAfterPipeline(
- Identifier name,
+ StringAttr name,
const PassInstrumentation::PipelineParentInfo &parentInfo) {
llvm::sys::SmartScopedLock<true> instrumentationLock(impl->mutex);
for (auto &instr : llvm::reverse(impl->instrumentations))
// Pipeline
//===--------------------------------------------------------------------===//
- void runBeforePipeline(Identifier name,
+ void runBeforePipeline(StringAttr name,
const PipelineParentInfo &parentInfo) override {
auto tid = llvm::get_threadid();
auto &activeTimers = activeThreadTimers[tid];
}));
}
- 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();
// Add the attributes.
OperandRange attributes = op.attributes();
writer.append(static_cast<ByteCodeField>(attributes.size()));
- for (auto it : llvm::zip(op.attributeNames(), op.attributes())) {
- writer.append(
- Identifier::get(std::get<0>(it).cast<StringAttr>().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) {
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) {
OperationState state(mainRewriteLoc, read<OperationName>());
readValueList(state.operands);
for (unsigned i = 0, e = read(); i != e; ++i) {
- Identifier name = read<Identifier>();
+ StringAttr name = read<StringAttr>();
if (Attribute attr = read<Attribute>())
state.addAttribute(name, attr);
}
LLVM_DEBUG(llvm::dbgs() << "Executing GetAttribute:\n");
unsigned memIndex = read();
Operation *op = read<Operation *>();
- Identifier attrName = read<Identifier>();
+ StringAttr attrName = read<StringAttr>();
Attribute attr = op->getAttr(attrName);
LLVM_DEBUG(llvm::dbgs() << " * Operation: " << *op << "\n"
/// 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<const void *> uniquedData;
/// A vector containing the generated bytecode for the matcher.
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");
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<spirv::Decoration>(words[1])) {
case spirv::Decoration::DescriptorSet:
case spirv::Decoration::Binding:
auto fileName = debugInfoMap.lookup(debugLine->fileID).str();
if (fileName.empty())
fileName = "<unknown>";
- return FileLineColLoc::get(opBuilder.getIdentifier(fileName), debugLine->line,
+ return FileLineColLoc::get(opBuilder.getStringAttr(fileName), debugLine->line,
debugLine->col);
}
op->print(os, state, flags);
Builder builder(op->getContext());
- Optional<Identifier> tagIdentifier;
+ Optional<StringAttr> 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
populateLinalgDistributeTiledLoopPattern(
distributeTiledLoopsPatterns, getDistributionOptions(),
LinalgTransformationFilter(
- ArrayRef<Identifier>{},
- {Identifier::get("distributed", funcOp.getContext())})
+ ArrayRef<StringAttr>{},
+ {StringAttr::get("distributed", funcOp.getContext())})
.addFilter([](Operation *op) {
return success(!op->getParentOfType<linalg::TiledLoopOp>());
}));
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>(),
- Identifier::get("after_basic_fusion_producer", context)),
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_basic_fusion_producer")),
LinalgTransformationFilter(
- ArrayRef<Identifier>(),
- Identifier::get("after_basic_fusion_original", context)));
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_basic_fusion_original")));
patterns.add<LinalgTileAndFusePattern<MatmulOp>>(
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>(),
- Identifier::get("after_lhs_fusion_producer", context)),
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_lhs_fusion_producer")),
LinalgTransformationFilter(
- ArrayRef<Identifier>(),
- Identifier::get("after_lhs_fusion_original", context)));
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_lhs_fusion_original")));
patterns.add<LinalgTileAndFusePattern<MatmulOp>>(
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>(),
- Identifier::get("after_out_fusion_producer", context)),
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_out_fusion_producer")),
LinalgTransformationFilter(
- ArrayRef<Identifier>(),
- Identifier::get("after_out_fusion_original", context)));
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_out_fusion_original")));
patterns.add<LinalgTileAndFusePattern<MatmulOp>>(
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>(),
- Identifier::get("after_rhs_fusion_producer", context)),
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_rhs_fusion_producer")),
LinalgTransformationFilter(
- ArrayRef<Identifier>(),
- Identifier::get("after_rhs_fusion_original", context)));
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_rhs_fusion_original")));
patterns.add<LinalgTileAndFusePattern<MatmulOp>>(
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>(),
- Identifier::get("after_two_operand_fusion_producer", context)),
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_two_operand_fusion_producer")),
LinalgTransformationFilter(
- ArrayRef<Identifier>(),
- Identifier::get("after_two_operand_fusion_original", context)));
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_two_operand_fusion_original")));
patterns.add<LinalgTileAndFusePattern<GenericOp>>(
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>(),
- Identifier::get("after_transpose_fusion_producer", context)),
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_transpose_fusion_producer")),
LinalgTransformationFilter(
- ArrayRef<Identifier>(),
- Identifier::get("after_transpose_fusion_original", context)));
+ ArrayRef<StringAttr>(),
+ StringAttr::get(context, "after_transpose_fusion_original")));
}
namespace {
//===--------------------------------------------------------------------===//
patterns.add<LinalgTilingPattern<MatmulOp>>(
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<LinalgTilingPattern<MatmulOp>>(
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<LinalgTilingPattern<MatmulOp>>(
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<LinalgTilingPattern<MatmulOp>>(
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<LinalgTilingPattern<MatvecOp>>(
ctx,
LinalgTilingOptions().setTileSizes({5, 6}).setLoopType(
LinalgTilingLoopType::ParallelLoops),
- LinalgTransformationFilter(ArrayRef<Identifier>{},
- Identifier::get("L1", ctx)));
+ LinalgTransformationFilter(ArrayRef<StringAttr>{},
+ StringAttr::get(ctx, "L1")));
patterns.add<LinalgTilingPattern<DotOp>>(
ctx, LinalgTilingOptions().setTileSizes(8000),
LinalgTransformationFilter(
- ArrayRef<Identifier>{Identifier::get("MEM", ctx),
- Identifier::get("L3", ctx),
- Identifier::get("L2", ctx)},
- Identifier::get("REG", ctx)));
+ ArrayRef<StringAttr>{StringAttr::get(ctx, "MEM"),
+ StringAttr::get(ctx, "L3"),
+ StringAttr::get(ctx, "L2")},
+ StringAttr::get(ctx, "REG")));
//===--------------------------------------------------------------------===//
// Linalg tiling and permutation patterns.
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<LinalgTilingPattern<MatmulOp>>(
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<LinalgTilingPattern<MatmulOp>>(
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<LinalgTilingPattern<MatvecOp>>(
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<LinalgTilingPattern<MatmulOp>>(
ctx,
.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.
patterns.add<LinalgLoweringPattern<DotOp>>(
ctx,
/*loweringType=*/LinalgLoweringType::Loops,
- LinalgTransformationFilter(Identifier::get("REG", ctx)));
+ LinalgTransformationFilter(StringAttr::get(ctx, "REG")));
//===--------------------------------------------------------------------===//
// Linalg distribution patterns.
// Linalg to vector contraction patterns.
//===--------------------------------------------------------------------===//
patterns.add<LinalgVectorizationPattern>(
- ctx, LinalgTransformationFilter(Identifier::get("VECTORIZE", ctx))
+ ctx, LinalgTransformationFilter(StringAttr::get(ctx, "VECTORIZE"))
.addOpFilter<MatmulOp, FillOp, CopyOp, GenericOp>());
//===--------------------------------------------------------------------===//
patterns.add<GenericOpInterchangePattern>(
ctx,
/*interchangeVector=*/ArrayRef<unsigned>{1, 2, 0},
- LinalgTransformationFilter(ArrayRef<Identifier>{},
- Identifier::get("PERMUTED", ctx)));
+ LinalgTransformationFilter(ArrayRef<StringAttr>{},
+ StringAttr::get(ctx, "PERMUTED")));
//===--------------------------------------------------------------------===//
// Linalg subview operands promotion.
//===--------------------------------------------------------------------===//
patterns.add<LinalgPromotionPattern<MatmulOp>>(
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<LinalgPromotionPattern<MatmulOp>>(
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<LinalgPromotionPattern<FillOp>>(
ctx,
LinalgPromotionOptions()
.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));
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<LinalgPromotionPattern<MatmulOp>>(
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<LinalgVectorizationPattern>(
MatmulOp::getOperationName(), ctx, LinalgVectorizationOptions(),
- LinalgTransformationFilter(Identifier::get("VEC", ctx))));
+ LinalgTransformationFilter(StringAttr::get(ctx, "VEC"))));
patternsVector.back().add<LinalgVectorizationPattern>(
ctx, LinalgTransformationFilter().addFilter(
[](Operation *op) { return success(isa<FillOp, CopyOp>(op)); }));
RewritePatternSet &patterns) {
patterns.add<LinalgTilingPattern<MatmulOp>>(
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<LinalgPromotionPattern<MatmulOp>>(
ctx,
LinalgPromotionOptions()
[](OpBuilder &b, Value src, Value dst) -> LogicalResult {
return copyCallBackFn(b, src, dst, true);
}),
- LinalgTransformationFilter(Identifier::get("PROMOTE", ctx)));
+ LinalgTransformationFilter(StringAttr::get(ctx, "PROMOTE")));
}
template <typename IdOp, typename NProcsOp>
.setLoopType(LinalgTilingLoopType::ParallelLoops)
.setDistributionOptions(cyclicNprocsEqNiters),
LinalgTransformationFilter(
- Identifier::get("distribute1", context),
- Identifier::get("after_distribute1", context)));
+ StringAttr::get(context, "distribute1"),
+ StringAttr::get(context, "after_distribute1")));
}
{
.setLoopType(LinalgTilingLoopType::ParallelLoops)
.setDistributionOptions(cyclicNprocsGeNiters),
LinalgTransformationFilter(
- Identifier::get("distribute2", context),
- Identifier::get("after_distribute2", context)));
+ StringAttr::get(context, "distribute2"),
+ StringAttr::get(context, "after_distribute2")));
}
{
.setLoopType(LinalgTilingLoopType::ParallelLoops)
.setDistributionOptions(cyclicNprocsDefault),
LinalgTransformationFilter(
- Identifier::get("distribute3", context),
- Identifier::get("after_distribute3", context)));
+ StringAttr::get(context, "distribute3"),
+ StringAttr::get(context, "after_distribute3")));
}
{
.setLoopType(LinalgTilingLoopType::ParallelLoops)
.setDistributionOptions(cyclicNprocsMixed1),
LinalgTransformationFilter(
- Identifier::get("distribute4", context),
- Identifier::get("after_distribute4", context)));
+ StringAttr::get(context, "distribute4"),
+ StringAttr::get(context, "after_distribute4")));
}
{
.setLoopType(LinalgTilingLoopType::ParallelLoops)
.setDistributionOptions(cyclicNprocsMixed2),
LinalgTransformationFilter(
- Identifier::get("distribute5", context),
- Identifier::get("after_distribute5", context)));
+ StringAttr::get(context, "distribute5"),
+ StringAttr::get(context, "after_distribute5")));
}
{
.setLoopType(LinalgTilingLoopType::ParallelLoops)
.setDistributionOptions(cyclicNprocsMixed3),
LinalgTransformationFilter(
- Identifier::get("distribute6", context),
- Identifier::get("after_distribute6", context)));
+ StringAttr::get(context, "distribute6"),
+ StringAttr::get(context, "after_distribute6")));
}
{
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")));
}
}
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);
}
{
tilingPattern.add<linalg::LinalgTilingPattern<linalg::MatmulOp>,
linalg::LinalgTilingPattern<linalg::GenericOp>>(
context, linalgTilingOptions,
- linalg::LinalgTransformationFilter(Identifier::get("tile", context)));
+ linalg::LinalgTransformationFilter(StringAttr::get(context, "tile")));
(void)applyPatternsAndFoldGreedily(funcOp, std::move(tilingPattern));
}
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<OpTrait::IsTerminator>())
return true;
}
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();
}
// 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
// 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
}
genContext.setLoc(NameLoc::get(
- Identifier::get(opConfig.metadata->cppClassName, &mlirContext)));
+ StringAttr::get(&mlirContext, opConfig.metadata->cppClassName)));
if (failed(generateOp(opConfig, genContext))) {
return 1;
}
// Emit the getAttributeNameForIndex methods.
{
auto *method = opClass.addInlineMethod<Method::MP_Private>(
- "::mlir::Identifier", "getAttributeNameForIndex",
+ "::mlir::StringAttr", "getAttributeNameForIndex",
MethodParameter("unsigned", "index"));
ERROR_IF_PRUNED(method, "getAttributeNameForIndex", op);
method->body()
}
{
auto *method = opClass.addStaticInlineMethod<Method::MP_Private>(
- "::mlir::Identifier", "getAttributeNameForIndex",
+ "::mlir::StringAttr", "getAttributeNameForIndex",
MethodParameter("::mlir::OperationName", "name"),
MethodParameter("unsigned", "index"));
ERROR_IF_PRUNED(method, "getAttributeNameForIndex", op);
// 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();
// 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,
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);
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<NamedAttribute *>()) {
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});
}
)";
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinTypes.h"
-#include "mlir/IR/Identifier.h"
#include "gtest/gtest.h"
using namespace mlir;
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);
}
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);
}
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);
{
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"));
}
{
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"));
}
#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 <vector>
#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"
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);
llvm::SmallVector<mlir::NamedAttribute, 4> 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);
auto elementsType = mlir::RankedTensorType::get({3}, i64Type);
auto elementsAttr =
mlir::DenseIntElementsAttr::get(elementsType, ArrayRef<int64_t>{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);
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."""
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',