From: Jean-Michel Gorius Date: Fri, 26 Jun 2020 11:20:44 +0000 (+0200) Subject: [mlir-tblgen] Use fully qualified names in generated code files X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05b4ff0a4b1a822449e9bf98782b9d337e6f81cf;p=platform%2Fupstream%2Fllvm.git [mlir-tblgen] Use fully qualified names in generated code files Using fully qualified names wherever possible avoids ambiguous class and function names. This is a follow-up to D82371. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D82471 --- diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index ae0fde0..dbd8125 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -208,25 +208,27 @@ class SuccessorConstraint : //===----------------------------------------------------------------------===// // Whether a type is a VectorType. -def IsVectorTypePred : CPred<"$_self.isa()">; +def IsVectorTypePred : CPred<"$_self.isa<::mlir::VectorType>()">; // Whether a type is a TensorType. -def IsTensorTypePred : CPred<"$_self.isa()">; +def IsTensorTypePred : CPred<"$_self.isa<::mlir::TensorType>()">; // Whether a type is a MemRefType. -def IsMemRefTypePred : CPred<"$_self.isa()">; +def IsMemRefTypePred : CPred<"$_self.isa<::mlir::MemRefType>()">; // Whether a type is an IsUnrankedMemRefType -def IsUnrankedMemRefTypePred : CPred<"$_self.isa()">; +def IsUnrankedMemRefTypePred + : CPred<"$_self.isa<::mlir::UnrankedMemRefType>()">; // Whether a type is a ShapedType. -def IsShapedTypePred : CPred<"$_self.isa()">; +def IsShapedTypePred : CPred<"$_self.isa<::mlir::ShapedType>()">; // For a ShapedType, verify that it has a static shape. -def HasStaticShapePred : CPred<"$_self.cast().hasStaticShape()">; +def HasStaticShapePred : + CPred<"$_self.cast<::mlir::ShapedType>().hasStaticShape()">; // Whether a type is a TupleType. -def IsTupleTypePred : CPred<"$_self.isa()">; +def IsTupleTypePred : CPred<"$_self.isa<::mlir::TupleType>()">; //===----------------------------------------------------------------------===// // Dialect definitions @@ -323,8 +325,8 @@ class BuildableType { def AnyType : Type, "any type">; // None type -def NoneType : Type()">, "none type">, - BuildableType<"$_builder.getType()">; +def NoneType : Type()">, "none type">, + BuildableType<"$_builder.getType<::mlir::NoneType>()">; // Any type from the given list class AnyTypeOf allowedTypes, string description = ""> : Type< @@ -337,7 +339,7 @@ class AnyTypeOf allowedTypes, string description = ""> : Type< // Integer types. // Any integer type irrespective of its width and signedness semantics. -def AnyInteger : Type()">, "integer">; +def AnyInteger : Type()">, "integer">; // Any integer type (regardless of signedness semantics) of a specific width. class AnyI @@ -424,13 +426,13 @@ def UI32 : UI<32>; def UI64 : UI<64>; // Index type. -def Index : Type()">, "index">, +def Index : Type()">, "index">, BuildableType<"$_builder.getIndexType()">; // Floating point types. // Any float type irrespective of its width. -def AnyFloat : Type()">, "floating-point">; +def AnyFloat : Type()">, "floating-point">; // Float type of a specific width. class F @@ -453,25 +455,28 @@ def BF16 : Type, "bfloat16 type">, class Complex : Type()">, - SubstLeaves<"$_self", "$_self.cast().getElementType()", + CPred<"$_self.isa<::mlir::ComplexType>()">, + SubstLeaves<"$_self", + "$_self.cast<::mlir::ComplexType>().getElementType()", type.predicate>]>, "complex type with " # type.description # " elements"> { Type elementType = type; } -def AnyComplex : Type()">, "complex-type">; +def AnyComplex : Type()">, + "complex-type">; class OpaqueType : Type, description>, - BuildableType<"OpaqueType::get($_builder.getIdentifier(\"" # dialect # - "\"), \"" # name # "\", $_builder.getContext())">; + BuildableType<"::mlir::OpaqueType::get($_builder.getIdentifier(\"" + # dialect # "\"), \"" # name # "\", $_builder.getContext())">; // Function Type // Any function type. -def FunctionType : Type()">, "function type">; +def FunctionType : Type()">, + "function type">; // A container type is a type that has another type embedded within it. class ContainerType allowedTypes, Pred containerPred, string descr> : +class ShapedContainerType allowedTypes, + Pred containerPred, string descr> : ContainerType, containerPred, - "$_self.cast().getElementType()", descr>; + "$_self.cast<::mlir::ShapedType>().getElementType()", descr>; // Whether a shaped type is ranked. -def HasRankPred : CPred<"$_self.cast().hasRank()">; +def HasRankPred : CPred<"$_self.cast<::mlir::ShapedType>().hasRank()">; // Whether a shaped type has one of the specified ranks. class HasAnyRankOfPred ranks> : And<[ HasRankPred, Or().getRank() == " # rank>)>]>; + CPred<[{$_self.cast<::mlir::ShapedType>().getRank() + == }] + # rank>)>]>; // Vector types. @@ -512,7 +520,7 @@ class VectorOf allowedTypes> : class IsVectorOfRankPred allowedRanks> : And<[IsVectorTypePred, Or().getRank() + CPred<[{$_self.cast<::mlir::VectorType>().getRank() == }] # allowedlength>)>]>; @@ -535,7 +543,7 @@ class VectorOfRankAndType allowedRanks, class IsVectorOfLengthPred allowedLengths> : And<[IsVectorTypePred, Or().getNumElements() + CPred<[{$_self.cast<::mlir::VectorType>().getNumElements() == }] # allowedlength>)>]>; @@ -641,7 +649,7 @@ class StaticShapeMemRefOf allowedTypes> def AnyStaticShapeMemRef : StaticShapeMemRefOf<[AnyType]>; // For a MemRefType, verify that it has strides. -def HasStridesPred : CPred<[{ isStrided($_self.cast()) }]>; +def HasStridesPred : CPred<[{ isStrided($_self.cast<::mlir::MemRefType>()) }]>; class StridedMemRefOf allowedTypes> : Type.predicate, HasStridesPred]>, @@ -666,7 +674,7 @@ class MixedContainerType, "; })" > @@ -682,13 +690,14 @@ class MixedContainerType allowedTypes> : MixedContainerType, IsTupleTypePred, - "$_self.cast().getTypes()", "tuple">; + "$_self.cast<::mlir::TupleType>().getTypes()", + "tuple">; // A Tuple with arbitrary nesting, where all elements are a mix of the allowed // types. class NestedTupleOf allowedTypes> : MixedContainerType, IsTupleTypePred, - "getFlattenedTypes($_self.cast())", + "getFlattenedTypes($_self.cast<::mlir::TupleType>())", "nested tuple">; //===----------------------------------------------------------------------===// @@ -806,9 +815,9 @@ class OptionalAttr : Attr { // Rewrite the attribute to be optional. // Note: this has to be kept up to date with Attr above. let storageType = attr.storageType; - let returnType = "Optional<" # attr.returnType #">"; + let returnType = "::llvm::Optional<" # attr.returnType #">"; let convertFromStorage = "$_self ? " # returnType # "(" # - attr.convertFromStorage # ") : (llvm::None)"; + attr.convertFromStorage # ") : (::llvm::None)"; let valueType = attr.valueType; let isOptional = 1; @@ -825,20 +834,20 @@ class TypedAttrBase { let constBuilderCall = "$_builder.get" # attrKind # "(" # attrValType.builderCall # ", $0)"; - let storageType = attrKind; + let storageType = "::mlir::" # attrKind; let valueType = attrValType; } // Any attribute. def AnyAttr : Attr, "any attribute"> { - let storageType = "Attribute"; - let returnType = "Attribute"; + let storageType = "::mlir::Attribute"; + let returnType = "::mlir::Attribute"; let convertFromStorage = "$_self"; let constBuilderCall = "$0"; } -def BoolAttr : Attr()">, "bool attribute"> { - let storageType = [{ BoolAttr }]; +def BoolAttr : Attr()">, "bool attribute"> { + let storageType = [{ ::mlir::BoolAttr }]; let returnType = [{ bool }]; let valueType = I1; let constBuilderCall = "$_builder.getBoolAttr($0)"; @@ -848,10 +857,11 @@ def BoolAttr : Attr()">, "bool attribute"> { def IndexAttr : TypedAttrBase< Index, "IntegerAttr", - And<[CPred<"$_self.isa()">, - CPred<"$_self.cast().getType().isa()">]>, + And<[CPred<"$_self.isa<::mlir::IntegerAttr>()">, + CPred<"$_self.cast<::mlir::IntegerAttr>().getType()" + ".isa<::mlir::IndexType>()">]>, "index attribute"> { - let returnType = [{ APInt }]; + let returnType = [{ ::llvm::APInt }]; } // Base class for any integer (regardless of signedness semantics) attributes @@ -859,11 +869,11 @@ def IndexAttr : class AnyIntegerAttrBase : TypedAttrBase< attrValType, "IntegerAttr", - And<[CPred<"$_self.isa()">, - CPred<"$_self.cast().getType()." + And<[CPred<"$_self.isa<::mlir::IntegerAttr>()">, + CPred<"$_self.cast<::mlir::IntegerAttr>().getType()." "isInteger(" # attrValType.bitwidth # ")">]>, descr> { - let returnType = [{ APInt }]; + let returnType = [{ ::llvm::APInt }]; let constBuilderCall = ?; } @@ -873,21 +883,21 @@ def AnyI16Attr : AnyIntegerAttrBase; def AnyI32Attr : AnyIntegerAttrBase; def AnyI64Attr : AnyIntegerAttrBase; -def APIntAttr : Attr()">, +def APIntAttr : Attr()">, "arbitrary integer attribute"> { - let storageType = [{ IntegerAttr }]; - let returnType = [{ APInt }]; + let storageType = [{ ::mlir::IntegerAttr }]; + let returnType = [{ ::mlir::APInt }]; } // Base class for signless integer attributes of fixed width. class SignlessIntegerAttrBase : TypedAttrBase< attrValType, "IntegerAttr", - And<[CPred<"$_self.isa()">, - CPred<"$_self.cast().getType()." + And<[CPred<"$_self.isa<::mlir::IntegerAttr>()">, + CPred<"$_self.cast<::mlir::IntegerAttr>().getType()." "isSignlessInteger(" # attrValType.bitwidth # ")">]>, descr> { - let returnType = [{ APInt }]; + let returnType = [{ ::llvm::APInt }]; } def I1Attr : SignlessIntegerAttrBase; @@ -900,11 +910,11 @@ def I64Attr : SignlessIntegerAttrBase; class SignedIntegerAttrBase : TypedAttrBase< attrValType, "IntegerAttr", - And<[CPred<"$_self.isa()">, - CPred<"$_self.cast().getType()." + And<[CPred<"$_self.isa<::mlir::IntegerAttr>()">, + CPred<"$_self.cast<::mlir::IntegerAttr>().getType()." "isSignedInteger(" # attrValType.bitwidth # ")">]>, descr> { - let returnType = [{ APInt }]; + let returnType = [{ ::llvm::APInt }]; } def SI1Attr : SignedIntegerAttrBase< @@ -922,11 +932,11 @@ def SI64Attr : SignedIntegerAttrBase< class UnsignedIntegerAttrBase : TypedAttrBase< attrValType, "IntegerAttr", - And<[CPred<"$_self.isa()">, - CPred<"$_self.cast().getType()." + And<[CPred<"$_self.isa<::mlir::IntegerAttr>()">, + CPred<"$_self.cast<::mlir::IntegerAttr>().getType()." "isUnsignedInteger(" # attrValType.bitwidth # ")">]>, descr> { - let returnType = [{ APInt }]; + let returnType = [{ ::llvm::APInt }]; } def UI1Attr : UnsignedIntegerAttrBase< @@ -943,11 +953,11 @@ def UI64Attr : UnsignedIntegerAttrBase< // Base class for float attributes of fixed width. class FloatAttrBase : TypedAttrBase()">, - CPred<"$_self.cast().getType().isF" # + And<[CPred<"$_self.isa<::mlir::FloatAttr>()">, + CPred<"$_self.cast<::mlir::FloatAttr>().getType().isF" # attrValType.bitwidth # "()">]>, descr> { - let returnType = [{ APFloat }]; + let returnType = [{ ::llvm::APFloat }]; } def F32Attr : FloatAttrBase; @@ -956,17 +966,18 @@ def F64Attr : FloatAttrBase; // An attribute backed by a string type. class StringBasedAttr : Attr { let constBuilderCall = "$_builder.getStringAttr(\"$0\")"; - let storageType = [{ StringAttr }]; - let returnType = [{ StringRef }]; + let storageType = [{ ::mlir::StringAttr }]; + let returnType = [{ ::llvm::StringRef }]; let valueType = NoneType; } -def StrAttr : StringBasedAttr()">, +def StrAttr : StringBasedAttr()">, "string attribute">; // String attribute that has a specific value type. -class TypedStrAttr : StringBasedAttr()">, - "string attribute"> { +class TypedStrAttr + : StringBasedAttr()">, + "string attribute"> { let valueType = ty; } @@ -975,22 +986,23 @@ class TypedStrAttr : StringBasedAttr()">, // defines a type attribute containing an integer type. class TypeAttrBase : Attr()">, - CPred<"$_self.cast().getValue().isa<" # retType # ">()">]>, + CPred<"$_self.isa<::mlir::TypeAttr>()">, + CPred<"$_self.cast<::mlir::TypeAttr>().getValue().isa<" + # retType # ">()">]>, description> { - let storageType = [{ TypeAttr }]; + let storageType = [{ ::mlir::TypeAttr }]; let returnType = retType; let valueType = NoneType; let convertFromStorage = "$_self.getValue().cast<" # retType # ">()"; } -def TypeAttr : TypeAttrBase<"Type", "any type attribute">; +def TypeAttr : TypeAttrBase<"::mlir::Type", "any type attribute">; // The mere presence of unit attributes has a meaning. Therefore, unit // attributes are always treated as optional and accessors to them return // "true" if the attribute is present and "false" otherwise. -def UnitAttr : Attr()">, "unit attribute"> { - let storageType = [{ UnitAttr }]; +def UnitAttr : Attr()">, "unit attribute"> { + let storageType = [{ ::mlir::UnitAttr }]; let constBuilderCall = "$_builder.getUnitAttr()"; let convertFromStorage = "$_self != nullptr"; let returnType = "bool"; @@ -1019,7 +1031,7 @@ class EnumAttrCaseInfo { class StrEnumAttrCase : EnumAttrCaseInfo, StringBasedAttr< - CPred<"$_self.cast().getValue() == \"" # sym # "\"">, + CPred<"$_self.cast<::mlir::StringAttr>().getValue() == \"" # sym # "\"">, "case " # sym>; // An enum attribute case stored with IntegerAttr, which has an integer value, @@ -1028,7 +1040,7 @@ class IntEnumAttrCaseBase : EnumAttrCaseInfo, SignlessIntegerAttrBase { let predicate = - CPred<"$_self.cast().getInt() == " # intVal>; + CPred<"$_self.cast<::mlir::IntegerAttr>().getInt() == " # intVal>; } // Cases of integer enum attributes with a specific type. By default, the string @@ -1045,7 +1057,8 @@ class BitEnumAttrCase : EnumAttrCaseInfo, SignlessIntegerAttrBase { let predicate = CPred< - "$_self.cast().getValue().getZExtValue() & " # val # "u">; + "$_self.cast<::mlir::IntegerAttr>().getValue().getZExtValue() & " + # val # "u">; } // Additional information for an enum attribute. @@ -1096,7 +1109,7 @@ class EnumAttrInfo cases> { // (); // ``` string symbolToStringFnName = "stringify" # name; - string symbolToStringFnRetType = "llvm::StringRef"; + string symbolToStringFnRetType = "::llvm::StringRef"; // The name of the utility function that returns the max enum value used // within the enum class. It will have the following signature: @@ -1143,7 +1156,8 @@ class I32EnumAttr($_self.getInt())"; - let constBuilderCall = "$_builder.getI32IntegerAttr(static_cast($0))"; + let constBuilderCall = + "$_builder.getI32IntegerAttr(static_cast($0))"; } class I64EnumAttr cases> : @@ -1151,7 +1165,8 @@ class I64EnumAttr($_self.getInt())"; - let constBuilderCall = "$_builder.getI64IntegerAttr(static_cast($0))"; + let constBuilderCall = + "$_builder.getI64IntegerAttr(static_cast($0))"; } // A bit enum stored with 32-bit IntegerAttr. @@ -1166,15 +1181,16 @@ class BitEnumAttr().getValue().getZExtValue() & (~(" # - StrJoin.result # + CPred<"!($_self.cast<::mlir::IntegerAttr>().getValue().getZExtValue() & (~(" + # StrJoin.result # ")))"> ]>; let returnType = cppNamespace # "::" # name; let underlyingType = "uint32_t"; let convertFromStorage = "static_cast<" # returnType # ">($_self.getInt())"; - let constBuilderCall = "$_builder.getI32IntegerAttr(static_cast($0))"; + let constBuilderCall = + "$_builder.getI32IntegerAttr(static_cast($0))"; // We need to return a string because we may concatenate symbols for multiple // bits together. @@ -1189,44 +1205,45 @@ class BitEnumAttr : Attr { - let storageType = [{ DictionaryAttr }]; - let returnType = [{ DictionaryAttr }]; + let storageType = [{ ::mlir::DictionaryAttr }]; + let returnType = [{ ::mlir::DictionaryAttr }]; let valueType = NoneType; let convertFromStorage = "$_self"; } -def DictionaryAttr : DictionaryAttrBase()">, - "dictionary of named attribute values">; +def DictionaryAttr + : DictionaryAttrBase()">, + "dictionary of named attribute values">; class ElementsAttrBase : Attr { - let storageType = [{ ElementsAttr }]; - let returnType = [{ ElementsAttr }]; + let storageType = [{ ::mlir::ElementsAttr }]; + let returnType = [{ ::mlir::ElementsAttr }]; let convertFromStorage = "$_self"; } -def ElementsAttr : ElementsAttrBase()">, +def ElementsAttr : ElementsAttrBase()">, "constant vector/tensor attribute">; class IntElementsAttrBase : - ElementsAttrBase()">, + ElementsAttrBase()">, condition]>, description> { - let storageType = [{ DenseIntElementsAttr }]; - let returnType = [{ DenseIntElementsAttr }]; + let storageType = [{ ::mlir::DenseIntElementsAttr }]; + let returnType = [{ ::mlir::DenseIntElementsAttr }]; let convertFromStorage = "$_self"; } def IndexElementsAttr - : IntElementsAttrBase() + : IntElementsAttrBase() .getType() .getElementType() .isIndex()}]>, "index elements attribute">; class AnyIntElementsAttr : IntElementsAttrBase< - CPred<"$_self.cast().getType()." + CPred<"$_self.cast<::mlir::DenseIntElementsAttr>().getType()." "getElementType().isInteger(" # width # ")">, width # "-bit integer elements attribute">; @@ -1234,14 +1251,15 @@ def AnyI32ElementsAttr : AnyIntElementsAttr<32>; def AnyI64ElementsAttr : AnyIntElementsAttr<64>; class SignlessIntElementsAttr : IntElementsAttrBase< - CPred<"$_self.cast().getType()." + CPred<"$_self.cast<::mlir::DenseIntElementsAttr>().getType()." "getElementType().isSignlessInteger(" # width # ")">, width # "-bit signless integer elements attribute"> { // Note that this is only constructing scalar elements attribute. - let constBuilderCall = "DenseElementsAttr::get(" - "RankedTensorType::get({}, $_builder.getIntegerType(" # width # ")), " - "llvm::makeArrayRef($0)).cast()"; + let constBuilderCall = "::mlir::DenseElementsAttr::get(" + "::mlir::RankedTensorType::get({}, " + "$_builder.getIntegerType(" # width # ")), " + "::llvm::makeArrayRef($0)).cast<::mlir::DenseIntElementsAttr>()"; } def I32ElementsAttr : SignlessIntElementsAttr<32>; @@ -1254,15 +1272,15 @@ class RankedSignlessIntElementsAttr dims> : // Check that this has the specified shape. let predicate = And<[ SignlessIntElementsAttr.predicate, - CPred<"$_self.cast().getType().getShape() == " - "ArrayRef({" # StrJoinInt.result # "})">]>; + CPred<"$_self.cast<::mlir::DenseIntElementsAttr>().getType().getShape() == " + "::mlir::ArrayRef({" # StrJoinInt.result # "})">]>; let description = width # "-bit signless int elements attribute of shape [" # StrJoinInt.result # "]"; - let constBuilderCall = "DenseIntElementsAttr::get(" - "RankedTensorType::get({" # StrJoinInt.result # - "}, $_builder.getIntegerType(" # width # ")), makeArrayRef($0))"; + let constBuilderCall = "::mlir::DenseIntElementsAttr::get(" + "::mlir::RankedTensorType::get({" # StrJoinInt.result # + "}, $_builder.getIntegerType(" # width # ")), ::llvm::makeArrayRef($0))"; } class RankedI32ElementsAttr dims> : @@ -1271,18 +1289,18 @@ class RankedI64ElementsAttr dims> : RankedSignlessIntElementsAttr<64, dims>; class FloatElementsAttr : ElementsAttrBase< - CPred<"$_self.isa() &&" - "$_self.cast().getType()." + CPred<"$_self.isa<::mlir::DenseFPElementsAttr>() &&" + "$_self.cast<::mlir::DenseElementsAttr>().getType()." "getElementType().isF" # width # "()">, width # "-bit float elements attribute"> { - let storageType = [{ DenseElementsAttr }]; - let returnType = [{ DenseElementsAttr }]; + let storageType = [{ ::mlir::DenseElementsAttr }]; + let returnType = [{ ::mlir::DenseElementsAttr }]; // Note that this is only constructing scalar elements attribute. - let constBuilderCall = "DenseElementsAttr::get(" - "RankedTensorType::get({}, $_builder.getF" # width # "Type())," - "llvm::makeArrayRef($0))"; + let constBuilderCall = "::mlir::DenseElementsAttr::get(" + "::mlir::RankedTensorType::get({}, $_builder.getF" # width # "Type())," + "::llvm::makeArrayRef($0))"; let convertFromStorage = "$_self"; } @@ -1291,23 +1309,23 @@ def F64ElementsAttr : FloatElementsAttr<64>; // A `width`-bit floating point elements attribute. The attribute should be // ranked and has a shape as specified in `dims`. class RankedFloatElementsAttr dims> : ElementsAttrBase< - CPred<"$_self.isa() &&" - "$_self.cast().getType()." + CPred<"$_self.isa<::mlir::DenseFPElementsAttr>() &&" + "$_self.cast<::mlir::DenseFPElementsAttr>().getType()." "getElementType().isF" # width # "() && " // Check that this is ranked and has the specified shape. - "$_self.cast().getType().hasRank() && " - "$_self.cast().getType().getShape() == " - "llvm::ArrayRef({" # StrJoinInt.result # "})">, + "$_self.cast<::mlir::DenseFPElementsAttr>().getType().hasRank() && " + "$_self.cast<::mlir::DenseFPElementsAttr>().getType().getShape() == " + "::mlir::ArrayRef({" # StrJoinInt.result # "})">, width # "-bit float elements attribute of shape [" # StrJoinInt.result # "]"> { - let storageType = [{ DenseFPElementsAttr }]; - let returnType = [{ DenseFPElementsAttr }]; + let storageType = [{ ::mlir::DenseFPElementsAttr }]; + let returnType = [{ ::mlir::DenseFPElementsAttr }]; - let constBuilderCall = "DenseElementsAttr::get(" - "RankedTensorType::get({" # StrJoinInt.result # + let constBuilderCall = "::mlir::DenseElementsAttr::get(" + "::mlir::RankedTensorType::get({" # StrJoinInt.result # "}, $_builder.getF" # width # "Type()), " - "llvm::makeArrayRef($0)).cast()"; + "::llvm::makeArrayRef($0)).cast<::mlir::DenseFPElementsAttr>()"; let convertFromStorage = "$_self"; } @@ -1315,11 +1333,11 @@ class RankedF32ElementsAttr dims> : RankedFloatElementsAttr<32, dims>; class RankedF64ElementsAttr dims> : RankedFloatElementsAttr<64, dims>; def StringElementsAttr : ElementsAttrBase< - CPred<"$_self.isa()" >, + CPred<"$_self.isa<::mlir::DenseStringElementsAttr>()" >, "string elements attribute"> { - let storageType = [{ DenseElementsAttr }]; - let returnType = [{ DenseElementsAttr }]; + let storageType = [{ ::mlir::DenseElementsAttr }]; + let returnType = [{ ::mlir::DenseElementsAttr }]; let convertFromStorage = "$_self"; } @@ -1327,13 +1345,13 @@ def StringElementsAttr : ElementsAttrBase< // Base class for array attributes. class ArrayAttrBase : Attr { - let storageType = [{ ArrayAttr }]; - let returnType = [{ ArrayAttr }]; + let storageType = [{ ::mlir::ArrayAttr }]; + let returnType = [{ ::mlir::ArrayAttr }]; let valueType = NoneType; let convertFromStorage = "$_self"; } -def ArrayAttr : ArrayAttrBase()">, +def ArrayAttr : ArrayAttrBase()">, "array attribute">; // Base class for array attributes whose elements are of the same kind. @@ -1341,12 +1359,12 @@ def ArrayAttr : ArrayAttrBase()">, class TypedArrayAttrBase: ArrayAttrBase< And<[ // Guarantee this is an ArrayAttr first - CPred<"$_self.isa()">, + CPred<"$_self.isa<::mlir::ArrayAttr>()">, // Guarantee all elements satisfy the constraints from `element` - Concat<"llvm::all_of($_self.cast(), " - "[](Attribute attr) { return ", - SubstLeaves<"$_self", "attr", element.predicate>, - "; })">]>, + Concat<"::llvm::all_of($_self.cast<::mlir::ArrayAttr>(), " + "[](::mlir::Attribute attr) { return ", + SubstLeaves<"$_self", "attr", element.predicate>, + "; })">]>, description> { let constBuilderCall = "$_builder.getArrayAttr($0)"; @@ -1413,18 +1431,18 @@ class StructAttr()">, +def SymbolRefAttr : Attr()">, "symbol reference attribute"> { - let storageType = [{ SymbolRefAttr }]; - let returnType = [{ SymbolRefAttr }]; + let storageType = [{ ::mlir::SymbolRefAttr }]; + let returnType = [{ ::mlir::SymbolRefAttr }]; let valueType = NoneType; let constBuilderCall = "$_builder.getSymbolRefAttr($0)"; let convertFromStorage = "$_self"; } -def FlatSymbolRefAttr : Attr()">, +def FlatSymbolRefAttr : Attr()">, "flat symbol reference attribute"> { - let storageType = [{ FlatSymbolRefAttr }]; - let returnType = [{ StringRef }]; + let storageType = [{ ::mlir::FlatSymbolRefAttr }]; + let returnType = [{ ::llvm::StringRef }]; let valueType = NoneType; let constBuilderCall = "$_builder.getSymbolRefAttr($0)"; let convertFromStorage = "$_self.getValue()"; @@ -1465,7 +1483,7 @@ class DerivedAttr : // Derived attribute that returns a mlir::Type. class DerivedTypeAttr : DerivedAttr<"Type", body> { - let convertFromStorage = "TypeAttr::get($_self)"; + let convertFromStorage = "::mlir::TypeAttr::get($_self)"; } //===----------------------------------------------------------------------===// @@ -1522,15 +1540,15 @@ class AllAttrConstraintsOf constraints> : AttrConstraint< } class IntMinValue : AttrConstraint< - CPred<"$_self.cast().getInt() >= " # n>, + CPred<"$_self.cast<::mlir::IntegerAttr>().getInt() >= " # n>, "whose minimum value is " # n>; class IntMaxValue : AttrConstraint< - CPred<"$_self.cast().getInt() <= " # n>, + CPred<"$_self.cast<::mlir::IntegerAttr>().getInt() <= " # n>, "whose maximum value is " # n>; def IntNonNegative : AttrConstraint< - CPred<"!$_self.cast().getValue().isNegative()">, + CPred<"!$_self.cast<::mlir::IntegerAttr>().getValue().isNegative()">, "whose value is non-negative">; def IntPositive : AttrConstraint< @@ -1538,26 +1556,26 @@ def IntPositive : AttrConstraint< "whose value is positive">; class ArrayMinCount : AttrConstraint< - CPred<"$_self.cast().size() >= " # n>, + CPred<"$_self.cast<::mlir::ArrayAttr>().size() >= " # n>, "with at least " # n # " elements">; class ArrayCount : AttrConstraint< - CPred<"$_self.cast().size() == " #n>, + CPred<"$_self.cast<::mlir::ArrayAttr>().size() == " #n>, "with exactly " # n # " elements">; class IntArrayNthElemEq : AttrConstraint< And<[ - CPred<"$_self.cast().size() > " # index>, - CPred<"$_self.cast()[" # index # "]" - ".cast().getInt() == " # value> + CPred<"$_self.cast<::mlir::ArrayAttr>().size() > " # index>, + CPred<"$_self.cast<::mlir::ArrayAttr>()[" # index # "]" + ".cast<::mlir::IntegerAttr>().getInt() == " # value> ]>, "whose " # index # "-th element must be " # value>; class IntArrayNthElemMinValue : AttrConstraint< And<[ - CPred<"$_self.cast().size() > " # index>, - CPred<"$_self.cast()[" # index # "]" - ".cast().getInt() >= " # min> + CPred<"$_self.cast<::mlir::ArrayAttr>().size() > " # index>, + CPred<"$_self.cast<::mlir::ArrayAttr>()[" # index # "]" + ".cast<::mlir::IntegerAttr>().getInt() >= " # min> ]>, "whose " # index # "-th element must be at least " # min>; @@ -1571,7 +1589,7 @@ def IsNullAttr : AttrConstraint< class ReferToOp : AttrConstraint< CPred<"isa_and_nonnull<" # opClass # ">(" "::mlir::SymbolTable::lookupNearestSymbolFrom(" - "&$_op, $_self.cast().getValue()))">, + "&$_op, $_self.cast<::mlir::FlatSymbolRefAttr>().getValue()))">, "referencing to a '" # opClass # "' symbol">; //===----------------------------------------------------------------------===// @@ -1586,7 +1604,7 @@ def AnyRegion : Region, "any region">; // A region with the given number of blocks. class SizedRegion : Region< - CPred<"llvm::hasNItems($_self, " # numBlocks # ")">, + CPred<"::llvm::hasNItems($_self, " # numBlocks # ")">, "region with " # numBlocks # " blocks">; // A variadic region constraint. It expands to zero or more of the base region. @@ -1729,7 +1747,8 @@ def ins; // OpInterfaceTrait corresponds to a specific 'OpInterface' class defined in // C++. The purpose to wrap around C++ symbol string with this class is to make // interfaces specified for ops in TableGen less alien and more integrated. -class OpInterfaceTrait : NativeOpTrait<""> { +class OpInterfaceTrait + : NativeOpTrait<""> { let trait = name # "::Trait"; // Specify the body of the verification function. `$_op` will be replaced with @@ -1988,18 +2007,20 @@ def HasNoUseOf: Constraint< // TODO(b/135033717): Improve the autogenerated error messages. class Rank : - StrFunc<"$" # name # ".getType().cast().getRank()">; + StrFunc<"$" # name # ".getType().cast<::mlir::ShapedType>().getRank()">; class Shape : - StrFunc<"$" # name # ".getType().cast().getShape()">; + StrFunc<"$" # name # ".getType().cast<::mlir::ShapedType>().getShape()">; class ElementCount : - StrFunc<"$" # name # ".getType().cast().getNumElements()">; + StrFunc<"$" # name # ".getType().cast<::mlir::ShapedType>()" + ".getNumElements()">; class ElementType : StrFunc<"getElementTypeOrSelf($" # name # ")">; class AllMatchPred values> : - CPred<"llvm::is_splat(llvm::makeArrayRef({"# StrJoin.result #"}))">; + CPred<"::llvm::is_splat(::llvm::makeArrayRef({" + # StrJoin.result #"}))">; class AllMatch values, string description> : PredOpTrait>; @@ -2078,8 +2099,8 @@ class TCopVTEtIsSameAs : And<[ IsShapedTypePred>, SubstLeaves<"$_self", "$_op.getOperand(" # j # ").getType()", IsShapedTypePred>, - CPred<"mlir::getElementTypeOrSelf($_op.getOperand(" # i # ")) == " - "mlir::getElementTypeOrSelf($_op.getOperand(" # j # "))">]>; + CPred<"::mlir::getElementTypeOrSelf($_op.getOperand(" # i # ")) == " + "::mlir::getElementTypeOrSelf($_op.getOperand(" # j # "))">]>; // Predicate to verify that the i'th result and the j'th operand exist and has // shaped types. @@ -2115,9 +2136,9 @@ class TCresVTEtIsSameAsOp : And<[ // of the resId'th result. class TCOpIsBroadcastableToRes : And<[ TCOpResIsShapedTypePred, - CPred<"OpTrait::util::getBroadcastedType(" - "$_op.getOperand(" # opId # ").getType(), " - "$_op.getResult(" # resId # ").getType())">]>; + CPred<"::mlir::OpTrait::util::getBroadcastedType(" + "$_op.getOperand(" # opId # ").getType(), " + "$_op.getResult(" # resId # ").getType())">]>; // Predicate to verify that all the operands at the given `indices` // have the same element type. @@ -2127,10 +2148,10 @@ class TCOpIsBroadcastableToRes : And<[ // 1) all operands involved are of shaped type and // 2) the indices are not out of range. class TCopVTEtAreSameAt indices> : CPred< - "llvm::is_splat(llvm::map_range(" - "llvm::ArrayRef({" # StrJoinInt.result # "}), " - "[this](unsigned i) { return getElementTypeOrSelf(this->getOperand(i)); " - "}))">; + "::llvm::is_splat(::llvm::map_range(" + "::mlir::ArrayRef({" # StrJoinInt.result # "}), " + "[this](unsigned i) { return getElementTypeOrSelf(this->getOperand(i)); " + "}))">; //===----------------------------------------------------------------------===// // Pattern definitions diff --git a/mlir/lib/TableGen/OpClass.cpp b/mlir/lib/TableGen/OpClass.cpp index 9e6c913..2b9da73 100644 --- a/mlir/lib/TableGen/OpClass.cpp +++ b/mlir/lib/TableGen/OpClass.cpp @@ -222,7 +222,7 @@ void tblgen::OpClass::addTrait(Twine trait) { } void tblgen::OpClass::writeDeclTo(raw_ostream &os) const { - os << "class " << className << " : public Op<" << className; + os << "class " << className << " : public ::mlir::Op<" << className; for (const auto &trait : traitsVec) os << ", " << trait; os << "> {\npublic:\n"; diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td index 766c11e..0868e83 100644 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -33,7 +33,7 @@ def AOp : NS_Op<"a_op", []> { // Test verify method // --- -// DEF: LogicalResult AOpAdaptor::verify +// DEF: ::mlir::LogicalResult AOpAdaptor::verify // DEF: auto tblgen_aAttr = odsAttrs.get("aAttr"); // DEF-NEXT: if (!tblgen_aAttr) return emitError(loc, "'test.a_op' op ""requires attribute 'aAttr'"); // DEF: if (!((some-condition))) return emitError(loc, "'test.a_op' op ""attribute 'aAttr' failed to satisfy constraint: some attribute kind"); @@ -58,14 +58,14 @@ def AOp : NS_Op<"a_op", []> { // DEF: some-return-type AOp::bAttr() { // DEF-NEXT: auto attr = bAttrAttr(); // DEF-NEXT: if (!attr) -// DEF-NEXT: return some-const-builder-call(mlir::Builder(this->getContext()), 4.2).some-convert-from-storage(); +// DEF-NEXT: return some-const-builder-call(::mlir::Builder(this->getContext()), 4.2).some-convert-from-storage(); // DEF-NEXT: return attr.some-convert-from-storage(); // DEF: some-attr-kind AOp::cAttrAttr() // DEF-NEXT: return this->getAttr("cAttr").dyn_cast_or_null() -// DEF: Optional AOp::cAttr() { +// DEF: ::llvm::Optional AOp::cAttr() { // DEF-NEXT: auto attr = cAttrAttr() -// DEF-NEXT: return attr ? Optional(attr.some-convert-from-storage()) : (llvm::None); +// DEF-NEXT: return attr ? ::llvm::Optional(attr.some-convert-from-storage()) : (::llvm::None); // Test setter methods // --- @@ -91,7 +91,7 @@ def AOp : NS_Op<"a_op", []> { // DEF: odsState.addAttribute("aAttr", some-const-builder-call(odsBuilder, aAttr)); // DEF: void AOp::build( -// DEF: ArrayRef attributes +// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes // DEF: odsState.addAttributes(attributes); def SomeTypeAttr : TypeAttrBase<"SomeType", "some type attribute">; @@ -120,35 +120,35 @@ def BOp : NS_Op<"b_op", []> { // DEF-LABEL: BOpAdaptor::verify // DEF: if (!((true))) -// DEF: if (!((tblgen_bool_attr.isa()))) -// DEF: if (!(((tblgen_i32_attr.isa())) && ((tblgen_i32_attr.cast().getType().isSignlessInteger(32))))) -// DEF: if (!(((tblgen_i64_attr.isa())) && ((tblgen_i64_attr.cast().getType().isSignlessInteger(64))))) -// DEF: if (!(((tblgen_f32_attr.isa())) && ((tblgen_f32_attr.cast().getType().isF32())))) -// DEF: if (!(((tblgen_f64_attr.isa())) && ((tblgen_f64_attr.cast().getType().isF64())))) -// DEF: if (!((tblgen_str_attr.isa()))) -// DEF: if (!((tblgen_elements_attr.isa()))) -// DEF: if (!((tblgen_function_attr.isa()))) -// DEF: if (!(((tblgen_type_attr.isa())) && ((tblgen_type_attr.cast().getValue().isa())))) -// DEF: if (!((tblgen_array_attr.isa()))) -// DEF: if (!(((tblgen_some_attr_array.isa())) && (llvm::all_of(tblgen_some_attr_array.cast(), [](Attribute attr) { return (some-condition); })))) -// DEF: if (!(((tblgen_type_attr.isa())) && ((tblgen_type_attr.cast().getValue().isa())))) +// DEF: if (!((tblgen_bool_attr.isa<::mlir::BoolAttr>()))) +// DEF: if (!(((tblgen_i32_attr.isa<::mlir::IntegerAttr>())) && ((tblgen_i32_attr.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(32))))) +// DEF: if (!(((tblgen_i64_attr.isa<::mlir::IntegerAttr>())) && ((tblgen_i64_attr.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) +// DEF: if (!(((tblgen_f32_attr.isa<::mlir::FloatAttr>())) && ((tblgen_f32_attr.cast<::mlir::FloatAttr>().getType().isF32())))) +// DEF: if (!(((tblgen_f64_attr.isa<::mlir::FloatAttr>())) && ((tblgen_f64_attr.cast<::mlir::FloatAttr>().getType().isF64())))) +// DEF: if (!((tblgen_str_attr.isa<::mlir::StringAttr>()))) +// DEF: if (!((tblgen_elements_attr.isa<::mlir::ElementsAttr>()))) +// DEF: if (!((tblgen_function_attr.isa<::mlir::FlatSymbolRefAttr>()))) +// DEF: if (!(((tblgen_type_attr.isa<::mlir::TypeAttr>())) && ((tblgen_type_attr.cast<::mlir::TypeAttr>().getValue().isa())))) +// DEF: if (!((tblgen_array_attr.isa<::mlir::ArrayAttr>()))) +// DEF: if (!(((tblgen_some_attr_array.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_some_attr_array.cast<::mlir::ArrayAttr>(), [](::mlir::Attribute attr) { return (some-condition); })))) +// DEF: if (!(((tblgen_type_attr.isa<::mlir::TypeAttr>())) && ((tblgen_type_attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>())))) // Test common attribute kind getters' return types // --- -// DEF: Attribute BOp::any_attr() +// DEF: ::mlir::Attribute BOp::any_attr() // DEF: bool BOp::bool_attr() -// DEF: APInt BOp::i32_attr() -// DEF: APInt BOp::i64_attr() -// DEF: APFloat BOp::f32_attr() -// DEF: APFloat BOp::f64_attr() -// DEF: StringRef BOp::str_attr() -// DEF: ElementsAttr BOp::elements_attr() -// DEF: StringRef BOp::function_attr() +// DEF: ::llvm::APInt BOp::i32_attr() +// DEF: ::llvm::APInt BOp::i64_attr() +// DEF: ::llvm::APFloat BOp::f32_attr() +// DEF: ::llvm::APFloat BOp::f64_attr() +// DEF: ::llvm::StringRef BOp::str_attr() +// DEF: ::mlir::ElementsAttr BOp::elements_attr() +// DEF: ::llvm::StringRef BOp::function_attr() // DEF: SomeType BOp::type_attr() -// DEF: ArrayAttr BOp::array_attr() -// DEF: ArrayAttr BOp::some_attr_array() -// DEF: Type BOp::type_attr() +// DEF: ::mlir::ArrayAttr BOp::array_attr() +// DEF: ::mlir::ArrayAttr BOp::some_attr_array() +// DEF: ::mlir::Type BOp::type_attr() // Test building constant values for array attribute kinds // --- @@ -164,11 +164,11 @@ def COp : NS_Op<"c_op", []> { } // DEF-LABEL: COp definitions -// DEF: mlir::Builder(this->getContext()).getI32ArrayAttr({1, 2}) -// DEF: mlir::Builder(this->getContext()).getI64ArrayAttr({3, 4}) -// DEF: mlir::Builder(this->getContext()).getF32ArrayAttr({5.f, 6.f}) -// DEF: mlir::Builder(this->getContext()).getF64ArrayAttr({7., 8.}) -// DEF: mlir::Builder(this->getContext()).getStrArrayAttr({"a", "b"}) +// DEF: ::mlir::Builder(this->getContext()).getI32ArrayAttr({1, 2}) +// DEF: ::mlir::Builder(this->getContext()).getI64ArrayAttr({3, 4}) +// DEF: ::mlir::Builder(this->getContext()).getF32ArrayAttr({5.f, 6.f}) +// DEF: ::mlir::Builder(this->getContext()).getF64ArrayAttr({7., 8.}) +// DEF: ::mlir::Builder(this->getContext()).getStrArrayAttr({"a", "b"}) // Test builder method which takes unwrapped values for attributes @@ -196,7 +196,7 @@ def DOp : NS_Op<"d_op", []> { } // DECL-LABEL: DOp declarations -// DECL: static void build({{.*}}, APInt i32_attr, APFloat f64_attr, StringRef str_attr, bool bool_attr, ::SomeI32Enum enum_attr, APInt dv_i32_attr, APFloat dv_f64_attr, StringRef dv_str_attr = "abc", bool dv_bool_attr = true, ::SomeI32Enum dv_enum_attr = ::SomeI32Enum::case5) +// DECL: static void build({{.*}}, ::llvm::APInt i32_attr, ::llvm::APFloat f64_attr, ::llvm::StringRef str_attr, bool bool_attr, ::SomeI32Enum enum_attr, ::llvm::APInt dv_i32_attr, ::llvm::APFloat dv_f64_attr, ::llvm::StringRef dv_str_attr = "abc", bool dv_bool_attr = true, ::SomeI32Enum dv_enum_attr = ::SomeI32Enum::case5) // DEF-LABEL: DOp definitions // DEF: odsState.addAttribute("str_attr", odsBuilder.getStringAttr(str_attr)); @@ -209,10 +209,10 @@ def DerivedTypeAttrOp : NS_Op<"derived_type_attr_op", []> { DerivedTypeAttr element_dtype = DerivedTypeAttr<"return output().getType();">; } -// DECL: class DerivedTypeAttrOp : public Op +// DECL: class DerivedTypeAttrOp : public ::mlir::Op // DECL-SAME: DerivedAttributeOpInterface::Trait // DECL: static bool isDerivedAttribute -// DEF: bool DerivedTypeAttrOp::isDerivedAttribute(StringRef name) { +// DEF: bool DerivedTypeAttrOp::isDerivedAttribute(::llvm::StringRef name) { // DEF: if (name == "element_dtype") return true; // DEF: return false; // DEF: } @@ -238,7 +238,7 @@ def EOp : NS_Op<"e_op", []> { } // DECL-LABEL: EOp declarations -// DECL: static void build({{.*}}, APInt i32_attr, APInt dv_i32_attr, APFloat f64_attr, APFloat dv_f64_attr, StringRef str_attr, StringRef dv_str_attr, bool bool_attr, bool dv_bool_attr, ::SomeI32Enum enum_attr, ::SomeI32Enum dv_enum_attr = ::SomeI32Enum::case5) +// DECL: static void build({{.*}}, ::llvm::APInt i32_attr, ::llvm::APInt dv_i32_attr, ::llvm::APFloat f64_attr, ::llvm::APFloat dv_f64_attr, ::llvm::StringRef str_attr, ::llvm::StringRef dv_str_attr, bool bool_attr, bool dv_bool_attr, ::SomeI32Enum enum_attr, ::SomeI32Enum dv_enum_attr = ::SomeI32Enum::case5) // Test mixing operands and attributes in arbitrary order // --- @@ -248,11 +248,11 @@ def MixOperandsAndAttrs : NS_Op<"mix_operands_and_attrs", []> { } // DEF-LABEL: MixOperandsAndAttrs definitions -// DEF-DAG: Value MixOperandsAndAttrs::operand() -// DEF-DAG: Value MixOperandsAndAttrs::otherArg() -// DEF-DAG: void MixOperandsAndAttrs::build(OpBuilder &odsBuilder, OperationState &odsState, FloatAttr attr, Value operand, FloatAttr otherAttr, Value otherArg) -// DEF-DAG: APFloat MixOperandsAndAttrs::attr() -// DEF-DAG: APFloat MixOperandsAndAttrs::otherAttr() +// DEF-DAG: ::mlir::Value MixOperandsAndAttrs::operand() +// DEF-DAG: ::mlir::Value MixOperandsAndAttrs::otherArg() +// DEF-DAG: void MixOperandsAndAttrs::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::FloatAttr attr, ::mlir::Value operand, ::mlir::FloatAttr otherAttr, ::mlir::Value otherArg) +// DEF-DAG: ::llvm::APFloat MixOperandsAndAttrs::attr() +// DEF-DAG: ::llvm::APFloat MixOperandsAndAttrs::otherAttr() // Test unit attributes. // --- @@ -265,7 +265,7 @@ def UnitAttrOp : NS_Op<"unit_attr_op", []> { // DEF: bool UnitAttrOp::attr() { // DEF: return {{.*}} != nullptr -// DEF: build(OpBuilder &odsBuilder, OperationState &odsState, /*optional*/UnitAttr attr) +// DEF: build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/::mlir::UnitAttr attr) // Test elementAttr field of TypedArrayAttr. diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td index 8d58d5b..728c38f 100644 --- a/mlir/test/mlir-tblgen/op-decl.td +++ b/mlir/test/mlir-tblgen/op-decl.td @@ -50,44 +50,44 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> { // CHECK: class AOpAdaptor { // CHECK: public: -// CHECK: AOpAdaptor(ValueRange values -// CHECK: ValueRange getODSOperands(unsigned index); -// CHECK: Value a(); -// CHECK: ValueRange b(); -// CHECK: IntegerAttr attr1(); -// CHECL: FloatAttr attr2(); +// CHECK: AOpAdaptor(::mlir::ValueRange values +// CHECK: ::mlir::ValueRange getODSOperands(unsigned index); +// CHECK: ::mlir::Value a(); +// CHECK: ::mlir::ValueRange b(); +// CHECK: ::mlir::IntegerAttr attr1(); +// CHECL: ::mlir::FloatAttr attr2(); // CHECK: private: -// CHECK: ValueRange odsOperands; +// CHECK: ::mlir::ValueRange odsOperands; // CHECK: }; -// CHECK: class AOp : public Op::Impl, OpTrait::AtLeastNResults<1>::Impl, OpTrait::ZeroSuccessor, OpTrait::AtLeastNOperands<1>::Impl, OpTrait::IsIsolatedFromAbove +// CHECK: class AOp : public ::mlir::Op::Impl, OpTrait::AtLeastNResults<1>::Impl, OpTrait::ZeroSuccessor, OpTrait::AtLeastNOperands<1>::Impl, OpTrait::IsIsolatedFromAbove // CHECK-NOT: OpTrait::IsIsolatedFromAbove // CHECK: public: // CHECK: using Op::Op; // CHECK: using Adaptor = AOpAdaptor; -// CHECK: static StringRef getOperationName(); -// CHECK: Operation::operand_range getODSOperands(unsigned index); -// CHECK: Value a(); -// CHECK: Operation::operand_range b(); +// CHECK: static ::llvm::StringRef getOperationName(); +// CHECK: ::mlir::Operation::operand_range getODSOperands(unsigned index); +// CHECK: ::mlir::Value a(); +// CHECK: ::mlir::Operation::operand_range b(); // CHECK: ::mlir::MutableOperandRange aMutable(); // CHECK: ::mlir::MutableOperandRange bMutable(); -// CHECK: Operation::result_range getODSResults(unsigned index); -// CHECK: Value r(); -// CHECK: Region &someRegion(); -// CHECK: MutableArrayRef someRegions(); -// CHECK: IntegerAttr attr1Attr() -// CHECK: APInt attr1(); -// CHECK: FloatAttr attr2Attr() -// CHECK: Optional< APFloat > attr2(); +// CHECK: ::mlir::Operation::result_range getODSResults(unsigned index); +// CHECK: ::mlir::Value r(); +// CHECK: ::mlir::Region &someRegion(); +// CHECK: ::mlir::MutableArrayRef someRegions(); +// CHECK: ::mlir::IntegerAttr attr1Attr() +// CHECK: ::llvm::APInt attr1(); +// CHECK: ::mlir::FloatAttr attr2Attr() +// CHECK: ::llvm::Optional< ::llvm::APFloat > attr2(); // CHECK: static void build(Value val); -// CHECK: static void build(OpBuilder &odsBuilder, OperationState &odsState, Type r, ArrayRef s, Value a, ValueRange b, IntegerAttr attr1, /*optional*/FloatAttr attr2, unsigned someRegionsCount) -// CHECK: static void build(OpBuilder &odsBuilder, OperationState &odsState, Type r, ArrayRef s, Value a, ValueRange b, APInt attr1, /*optional*/FloatAttr attr2, unsigned someRegionsCount) -// CHECK: static void build(OpBuilder &, OperationState &odsState, ArrayRef resultTypes, ValueRange operands, ArrayRef attributes, unsigned numRegions) -// CHECK: static ParseResult parse(OpAsmParser &parser, OperationState &result); -// CHECK: void print(OpAsmPrinter &p); -// CHECK: LogicalResult verify(); -// CHECK: static void getCanonicalizationPatterns(OwningRewritePatternList &results, MLIRContext *context); -// CHECK: LogicalResult fold(ArrayRef operands, SmallVectorImpl &results); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::llvm::ArrayRef<::mlir::Type> s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr attr2, unsigned someRegionsCount) +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::llvm::ArrayRef<::mlir::Type> s, ::mlir::Value a, ::mlir::ValueRange b, ::llvm::APInt attr1, /*optional*/::mlir::FloatAttr attr2, unsigned someRegionsCount) +// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) +// CHECK: static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); +// CHECK: void print(::mlir::OpAsmPrinter &p); +// CHECK: ::mlir::LogicalResult verify(); +// CHECK: static void getCanonicalizationPatterns(::mlir::OwningRewritePatternList &results, ::mlir::MLIRContext *context); +// CHECK: ::mlir::LogicalResult fold(::llvm::ArrayRef<::mlir::Attribute> operands, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results); // CHECK: // Display a graph for debugging purposes. // CHECK: void displayGraph(); // CHECK: }; @@ -107,13 +107,13 @@ def NS_AttrSizedOperandOp : NS_Op<"attr_sized_operands", } // CHECK-LABEL: AttrSizedOperandOpAdaptor( -// CHECK-SAME: ValueRange values -// CHECK-SAME: DictionaryAttr attrs -// CHECK: ValueRange a(); -// CHECK: ValueRange b(); -// CHECK: Value c(); -// CHECK: ValueRange d(); -// CHECK: DenseIntElementsAttr operand_segment_sizes(); +// CHECK-SAME: ::mlir::ValueRange values +// CHECK-SAME: ::mlir::DictionaryAttr attrs +// CHECK: ::mlir::ValueRange a(); +// CHECK: ::mlir::ValueRange b(); +// CHECK: ::mlir::Value c(); +// CHECK: ::mlir::ValueRange d(); +// CHECK: ::mlir::DenseIntElementsAttr operand_segment_sizes(); // Check op trait for different number of operands // --- @@ -145,10 +145,10 @@ def NS_EOp : NS_Op<"op_with_optionals", []> { } // CHECK-LABEL: NS::EOp declarations -// CHECK: Value a(); +// CHECK: ::mlir::Value a(); // CHECK: ::mlir::MutableOperandRange aMutable(); -// CHECK: Value b(); -// CHECK: static void build(OpBuilder &odsBuilder, OperationState &odsState, /*optional*/Type b, /*optional*/Value a) +// CHECK: ::mlir::Value b(); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/::mlir::Type b, /*optional*/::mlir::Value a) // Check that all types match constraint results in generating builder. // --- @@ -160,7 +160,7 @@ def NS_FOp : NS_Op<"op_with_all_types_constraint", } // CHECK-LABEL: class FOp : -// CHECK: static LogicalResult inferReturnTypes +// CHECK: static ::mlir::LogicalResult inferReturnTypes def NS_GOp : NS_Op<"op_with_fixed_return_type", []> { let arguments = (ins AnyType:$a); @@ -168,7 +168,7 @@ def NS_GOp : NS_Op<"op_with_fixed_return_type", []> { } // CHECK-LABEL: class GOp : -// CHECK: static LogicalResult inferReturnTypes +// CHECK: static ::mlir::LogicalResult inferReturnTypes // Check that default builders can be suppressed. // --- @@ -180,7 +180,7 @@ def NS_SkipDefaultBuildersOp : NS_Op<"skip_default_builders", []> { // CHECK-LABEL: NS::SkipDefaultBuildersOp declarations // CHECK: class SkipDefaultBuildersOp -// CHECK-NOT: static void build(Builder +// CHECK-NOT: static void build(::mlir::Builder // CHECK: static void build(Value // Check leading underscore in op name @@ -189,12 +189,12 @@ def NS_SkipDefaultBuildersOp : NS_Op<"skip_default_builders", []> { def NS__AOp : NS_Op<"_op_with_leading_underscore", []>; // CHECK-LABEL: NS::_AOp declarations -// CHECK: class _AOp : public Op<_AOp +// CHECK: class _AOp : public ::mlir::Op<_AOp def _BOp : NS_Op<"_op_with_leading_underscore_and_no_namespace", []>; // CHECK-LABEL: _BOp declarations -// CHECK: class _BOp : public Op<_BOp +// CHECK: class _BOp : public ::mlir::Op<_BOp // REDUCE-LABEL: NS::AOp declarations // REDUCE-NOT: NS::BOp declarations diff --git a/mlir/test/mlir-tblgen/op-interface.td b/mlir/test/mlir-tblgen/op-interface.td index 8e5167e..4ca2b79 100644 --- a/mlir/test/mlir-tblgen/op-interface.td +++ b/mlir/test/mlir-tblgen/op-interface.td @@ -40,7 +40,7 @@ def DeclareMethodsWithDefaultOp : Op]>; // DECL-LABEL: TestOpInterfaceInterfaceTraits -// DECL: class TestOpInterface : public OpInterface +// DECL: class TestOpInterface : public ::mlir::OpInterface // DECL: int foo(int input); // DECL-NOT: TestOpInterface diff --git a/mlir/test/mlir-tblgen/op-operand.td b/mlir/test/mlir-tblgen/op-operand.td index a0a57d8..abeb67f 100644 --- a/mlir/test/mlir-tblgen/op-operand.td +++ b/mlir/test/mlir-tblgen/op-operand.td @@ -18,11 +18,11 @@ def OpA : NS_Op<"one_normal_operand_op", []> { // CHECK-SAME: odsOperands(values), odsAttrs(attrs) // CHECK: void OpA::build -// CHECK: Value input +// CHECK: ::mlir::Value input // CHECK: odsState.addOperands(input); // CHECK: void OpA::build -// CHECK: ValueRange operands +// CHECK: ::mlir::ValueRange operands // CHECK: assert(operands.size() == 1u && "mismatched number of parameters"); // CHECK: odsState.addOperands(operands); @@ -31,7 +31,7 @@ def OpB : NS_Op<"one_variadic_operand_op", []> { } // CHECK-LABEL: OpB::build -// CHECK: ValueRange input +// CHECK: ::mlir::ValueRange input // CHECK-NOT: assert // CHECK: odsState.addOperands(input); @@ -39,19 +39,19 @@ def OpD : NS_Op<"mix_variadic_and_normal_inputs_op", [SameVariadicOperandSize]> let arguments = (ins Variadic:$input1, AnyTensor:$input2, Variadic:$input3); } -// CHECK-LABEL: ValueRange OpDAdaptor::input1 +// CHECK-LABEL: ::mlir::ValueRange OpDAdaptor::input1 // CHECK-NEXT: return getODSOperands(0); -// CHECK-LABEL: Value OpDAdaptor::input2 +// CHECK-LABEL: ::mlir::Value OpDAdaptor::input2 // CHECK-NEXT: return *getODSOperands(1).begin(); -// CHECK-LABEL: ValueRange OpDAdaptor::input3 +// CHECK-LABEL: ::mlir::ValueRange OpDAdaptor::input3 // CHECK-NEXT: return getODSOperands(2); -// CHECK-LABEL: Operation::operand_range OpD::input1 +// CHECK-LABEL: ::mlir::Operation::operand_range OpD::input1 // CHECK-NEXT: return getODSOperands(0); -// CHECK-LABEL: Value OpD::input2 +// CHECK-LABEL: ::mlir::Value OpD::input2 // CHECK-NEXT: return *getODSOperands(1).begin(); // CHECK-LABEL: OpD::build diff --git a/mlir/test/mlir-tblgen/op-result.td b/mlir/test/mlir-tblgen/op-result.td index 7886c27..c9959c5 100644 --- a/mlir/test/mlir-tblgen/op-result.td +++ b/mlir/test/mlir-tblgen/op-result.td @@ -13,7 +13,7 @@ def OpA : NS_Op<"one_normal_result_op", []> { } // CHECK-LABEL: void OpA::build -// CHECK: ArrayRef resultTypes, ValueRange operands +// CHECK: ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::ValueRange operands // CHECK: assert(resultTypes.size() == 1u && "mismatched number of return types"); // CHECK-NEXT: odsState.addTypes(resultTypes); @@ -23,9 +23,9 @@ def OpB : NS_Op<"same_input_output_type_op", [SameOperandsAndResultType]> { } // CHECK-LABEL: OpB definitions -// CHECK: void OpB::build(OpBuilder &odsBuilder, OperationState &odsState, Type y, Value x) +// CHECK: void OpB::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type y, ::mlir::Value x) // CHECK: odsState.addTypes(y); -// CHECK: void OpB::build(OpBuilder &odsBuilder, OperationState &odsState, Value x) +// CHECK: void OpB::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value x) // CHECK: odsState.addTypes({x.getType()}); def OpC : NS_Op<"three_normal_result_op", []> { @@ -33,12 +33,12 @@ def OpC : NS_Op<"three_normal_result_op", []> { } // CHECK-LABEL: OpC definitions -// CHECK: void OpC::build(OpBuilder &odsBuilder, OperationState &odsState, Type x, Type resultType1, Type z) +// CHECK: void OpC::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type x, ::mlir::Type resultType1, ::mlir::Type z) // CHECK-NEXT: odsState.addTypes(x) // CHECK-NEXT: odsState.addTypes(resultType1) // CHECK-NEXT: odsState.addTypes(z) -// CHECK: void OpC::build(OpBuilder &odsBuilder, OperationState &odsState, ArrayRef resultTypes) { +// CHECK: void OpC::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes) { // CHECK-NEXT: assert(resultTypes.size() == 3u && "mismatched number of results"); // CHECK-NEXT: odsState.addTypes(resultTypes); @@ -49,8 +49,8 @@ def OpD : NS_Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> { } // CHECK-LABEL: OpD definitions -// CHECK: void OpD::build(OpBuilder &odsBuilder, OperationState &odsState, ValueRange operands, ArrayRef attributes) -// CHECK: odsState.addTypes({attr.second.cast().getValue()}); +// CHECK: void OpD::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) +// CHECK: odsState.addTypes({attr.second.cast<::mlir::TypeAttr>().getValue()}); def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> { let arguments = (ins I32:$x, F32Attr:$attr); @@ -58,7 +58,7 @@ def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> { } // CHECK-LABEL: OpE definitions -// CHECK: void OpE::build(OpBuilder &odsBuilder, OperationState &odsState, ValueRange operands, ArrayRef attributes) +// CHECK: void OpE::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) // CHECK: odsState.addTypes({attr.second.getType()}); def OpF : NS_Op<"one_variadic_result_op", []> { @@ -66,7 +66,7 @@ def OpF : NS_Op<"one_variadic_result_op", []> { } // CHECK-LABEL: void OpF::build -// CHECK-SAME: ArrayRef x +// CHECK-SAME: ::llvm::ArrayRef<::mlir::Type> x // CHECK-NOT: assert // CHECK: odsState.addTypes(x); @@ -77,12 +77,12 @@ def OpG : NS_Op<"one_normal_and_one_variadic_result_op", []> { // CHECK-LABEL: OpG definitions -// CHECK: void OpG::build(OpBuilder &odsBuilder, OperationState &odsState, Type x, ArrayRef y) +// CHECK: void OpG::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type x, ::llvm::ArrayRef<::mlir::Type> y) // CHECK-NEXT: odsState.addTypes(x); // CHECK-NEXT: odsState.addTypes(y); // CHECK: void OpG::build -// CHECK: ArrayRef resultTypes +// CHECK: ::llvm::ArrayRef<::mlir::Type> resultTypes // CHECK: assert(resultTypes.size() >= 1u && "mismatched number of return types"); // CHECK-NEXT: odsState.addTypes(resultTypes); @@ -90,10 +90,10 @@ def OpI : NS_Op<"mix_variadic_and_normal_results_op", [SameVariadicResultSize]> let results = (outs Variadic:$output1, AnyTensor:$output2, Variadic:$output3); } -// CHECK-LABEL: Operation::result_range OpI::output1 +// CHECK-LABEL: ::mlir::Operation::result_range OpI::output1 // CHECK-NEXT: return getODSResults(0); -// CHECK-LABEL: Value OpI::output2 +// CHECK-LABEL: ::mlir::Value OpI::output2 // CHECK-NEXT: return *getODSResults(1).begin(); // CHECK-LABEL: OpI::build @@ -109,5 +109,5 @@ def OpK : NS_Op<"only_input_is_variadic_with_same_value_type_op", [SameOperandsA let results = (outs AnyTensor:$result); } -// CHECK-LABEL: OpK::build(OpBuilder &odsBuilder, OperationState &odsState, ValueRange input) +// CHECK-LABEL: OpK::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) // CHECK: odsState.addTypes({input.front().getType()}); diff --git a/mlir/test/mlir-tblgen/op-side-effects.td b/mlir/test/mlir-tblgen/op-side-effects.td index a514d46..6bae35a 100644 --- a/mlir/test/mlir-tblgen/op-side-effects.td +++ b/mlir/test/mlir-tblgen/op-side-effects.td @@ -19,9 +19,9 @@ def SideEffectOpB : TEST_Op<"side_effect_op_b", [MemoryEffects<[MemWrite]>]>; // CHECK: void SideEffectOpA::getEffects -// CHECK: for (Value value : getODSOperands(0)) +// CHECK: for (::mlir::Value value : getODSOperands(0)) // CHECK: effects.emplace_back(MemoryEffects::Read::get(), value, ::mlir::SideEffects::DefaultResource::get()); -// CHECK: for (Value value : getODSResults(0)) +// CHECK: for (::mlir::Value value : getODSResults(0)) // CHECK: effects.emplace_back(MemoryEffects::Allocate::get(), value, CustomResource::get()); // CHECK: void SideEffectOpB::getEffects diff --git a/mlir/test/mlir-tblgen/predicate.td b/mlir/test/mlir-tblgen/predicate.td index 5f19344..e5d4ac8 100644 --- a/mlir/test/mlir-tblgen/predicate.td +++ b/mlir/test/mlir-tblgen/predicate.td @@ -17,7 +17,7 @@ def OpA : NS_Op<"op_for_CPred_containing_multiple_same_placeholder", []> { // CHECK-LABEL: OpA::verify // CHECK: auto valueGroup0 = getODSOperands(0); -// CHECK: for (Value v : valueGroup0) { +// CHECK: for (::mlir::Value v : valueGroup0) { // CHECK: if (!((v.getType().isInteger(32) || v.getType().isF32()))) def OpB : NS_Op<"op_for_And_PredOpTrait", [ @@ -33,7 +33,7 @@ def OpF : NS_Op<"op_for_int_min_val", []> { } // CHECK-LABEL: OpFAdaptor::verify -// CHECK: (tblgen_attr.cast().getInt() >= 10) +// CHECK: (tblgen_attr.cast<::mlir::IntegerAttr>().getInt() >= 10) // CHECK-SAME: "attribute 'attr' failed to satisfy constraint: 32-bit signless integer attribute whose minimum value is 10" def OpFX : NS_Op<"op_for_int_max_val", []> { @@ -41,7 +41,7 @@ def OpFX : NS_Op<"op_for_int_max_val", []> { } // CHECK-LABEL: OpFXAdaptor::verify -// CHECK: (tblgen_attr.cast().getInt() <= 10) +// CHECK: (tblgen_attr.cast<::mlir::IntegerAttr>().getInt() <= 10) // CHECK-SAME: "attribute 'attr' failed to satisfy constraint: 32-bit signless integer attribute whose maximum value is 10" def OpG : NS_Op<"op_for_arr_min_count", []> { @@ -49,7 +49,7 @@ def OpG : NS_Op<"op_for_arr_min_count", []> { } // CHECK-LABEL: OpGAdaptor::verify -// CHECK: (tblgen_attr.cast().size() >= 8) +// CHECK: (tblgen_attr.cast<::mlir::ArrayAttr>().size() >= 8) // CHECK-SAME: "attribute 'attr' failed to satisfy constraint: array attribute with at least 8 elements" def OpH : NS_Op<"op_for_arr_value_at_index", []> { @@ -57,7 +57,7 @@ def OpH : NS_Op<"op_for_arr_value_at_index", []> { } // CHECK-LABEL: OpHAdaptor::verify -// CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast()[0].cast().getInt() == 8))))) +// CHECK: (((tblgen_attr.cast<::mlir::ArrayAttr>().size() > 0)) && ((tblgen_attr.cast<::mlir::ArrayAttr>()[0].cast<::mlir::IntegerAttr>().getInt() == 8))))) // CHECK-SAME: "attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be 8" def OpI: NS_Op<"op_for_arr_min_value_at_index", []> { @@ -65,7 +65,7 @@ def OpI: NS_Op<"op_for_arr_min_value_at_index", []> { } // CHECK-LABEL: OpIAdaptor::verify -// CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast()[0].cast().getInt() >= 8))))) +// CHECK: (((tblgen_attr.cast<::mlir::ArrayAttr>().size() > 0)) && ((tblgen_attr.cast<::mlir::ArrayAttr>()[0].cast<::mlir::IntegerAttr>().getInt() >= 8))))) // CHECK-SAME: "attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 8" def OpJ: NS_Op<"op_for_TCopVTEtAreSameAt", [ @@ -81,8 +81,8 @@ def OpJ: NS_Op<"op_for_TCopVTEtAreSameAt", [ } // CHECK-LABEL: OpJAdaptor::verify -// CHECK: llvm::is_splat(llvm::map_range( -// CHECK-SAME: llvm::ArrayRef({0, 2, 3}), +// CHECK: ::llvm::is_splat(::llvm::map_range( +// CHECK-SAME: ::mlir::ArrayRef({0, 2, 3}), // CHECK-SAME: [this](unsigned i) { return getElementTypeOrSelf(this->getOperand(i)); })) // CHECK: "failed to verify that operands indexed at 0, 2, 3 should all have the same type" @@ -92,5 +92,5 @@ def OpK : NS_Op<"op_for_AnyTensorOf", []> { // CHECK-LABEL: OpK::verify // CHECK: auto valueGroup0 = getODSOperands(0); -// CHECK: for (Value v : valueGroup0) { -// CHECK: if (!(((v.getType().isa())) && (((v.getType().cast().getElementType().isF32())) || ((v.getType().cast().getElementType().isSignlessInteger(32)))))) +// CHECK: for (::mlir::Value v : valueGroup0) { +// CHECK: if (!(((v.getType().isa<::mlir::TensorType>())) && (((v.getType().cast<::mlir::ShapedType>().getElementType().isF32())) || ((v.getType().cast<::mlir::ShapedType>().getElementType().isSignlessInteger(32)))))) diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp index 04d357d..b0a8915 100644 --- a/mlir/tools/mlir-tblgen/EnumsGen.cpp +++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp @@ -71,7 +71,7 @@ static void emitDenseMapInfo(StringRef enumName, std::string underlyingType, const char *const mapInfo = R"( namespace llvm { template<> struct DenseMapInfo<{0}> {{ - using StorageInfo = llvm::DenseMapInfo<{1}>; + using StorageInfo = ::llvm::DenseMapInfo<{1}>; static inline {0} getEmptyKey() {{ return static_cast<{0}>(StorageInfo::getEmptyKey()); @@ -193,7 +193,7 @@ static void emitSymToStrFnForBitEnum(const Record &enumDef, raw_ostream &os) { os << formatv(" if (val == 0) return \"{0}\";\n\n", allBitsUnsetCase->getSymbol()); } - os << " llvm::SmallVector strs;\n"; + os << " ::llvm::SmallVector<::llvm::StringRef, 2> strs;\n"; for (const auto &enumerant : enumerants) { // Skip the special enumerant for None. if (auto val = enumerant.getValue()) @@ -203,7 +203,7 @@ static void emitSymToStrFnForBitEnum(const Record &enumDef, raw_ostream &os) { } // If we have unknown bit set, return an empty string to signal errors. os << "\n if (val) return \"\";\n"; - os << formatv(" return llvm::join(strs, \"{0}\");\n", separator); + os << formatv(" return ::llvm::join(strs, \"{0}\");\n", separator); os << "}\n\n"; } @@ -214,9 +214,9 @@ static void emitStrToSymFnForIntEnum(const Record &enumDef, raw_ostream &os) { StringRef strToSymFnName = enumAttr.getStringToSymbolFnName(); auto enumerants = enumAttr.getAllCases(); - os << formatv("llvm::Optional<{0}> {1}(llvm::StringRef str) {{\n", enumName, - strToSymFnName); - os << formatv(" return llvm::StringSwitch>(str)\n", + os << formatv("::llvm::Optional<{0}> {1}(::llvm::StringRef str) {{\n", + enumName, strToSymFnName); + os << formatv(" return ::llvm::StringSwitch<::llvm::Optional<{0}>>(str)\n", enumName); for (const auto &enumerant : enumerants) { auto symbol = enumerant.getSymbol(); @@ -224,7 +224,7 @@ static void emitStrToSymFnForIntEnum(const Record &enumDef, raw_ostream &os) { os << formatv(" .Case(\"{1}\", {0}::{2})\n", enumName, str, makeIdentifier(symbol)); } - os << " .Default(llvm::None);\n"; + os << " .Default(::llvm::None);\n"; os << "}\n"; } @@ -237,8 +237,8 @@ static void emitStrToSymFnForBitEnum(const Record &enumDef, raw_ostream &os) { auto enumerants = enumAttr.getAllCases(); auto allBitsUnsetCase = getAllBitsUnsetCase(enumerants); - os << formatv("llvm::Optional<{0}> {1}(llvm::StringRef str) {{\n", enumName, - strToSymFnName); + os << formatv("::llvm::Optional<{0}> {1}(::llvm::StringRef str) {{\n", + enumName, strToSymFnName); if (allBitsUnsetCase) { os << " // Special case for all bits unset.\n"; @@ -248,7 +248,7 @@ static void emitStrToSymFnForBitEnum(const Record &enumDef, raw_ostream &os) { } // Split the string to get symbols for all the bits. - os << " llvm::SmallVector symbols;\n"; + os << " ::llvm::SmallVector<::llvm::StringRef, 2> symbols;\n"; os << formatv(" str.split(symbols, \"{0}\");\n\n", separator); os << formatv(" {0} val = 0;\n", underlyingType); @@ -256,7 +256,7 @@ static void emitStrToSymFnForBitEnum(const Record &enumDef, raw_ostream &os) { // Convert each symbol to the bit ordinal and set the corresponding bit. os << formatv( - " auto bit = llvm::StringSwitch>(symbol)\n", + " auto bit = llvm::StringSwitch<::llvm::Optional<{0}>>(symbol)\n", underlyingType); for (const auto &enumerant : enumerants) { // Skip the special enumerant for None. @@ -264,9 +264,9 @@ static void emitStrToSymFnForBitEnum(const Record &enumDef, raw_ostream &os) { os.indent(6) << formatv(".Case(\"{0}\", {1})\n", enumerant.getSymbol(), val); } - os.indent(6) << ".Default(llvm::None);\n"; + os.indent(6) << ".Default(::llvm::None);\n"; - os << " if (bit) { val |= *bit; } else { return llvm::None; }\n"; + os << " if (bit) { val |= *bit; } else { return ::llvm::None; }\n"; os << " }\n"; os << formatv(" return static_cast<{0}>(val);\n", enumName); @@ -288,7 +288,7 @@ static void emitUnderlyingToSymFnForIntEnum(const Record &enumDef, })) return; - os << formatv("llvm::Optional<{0}> {1}({2} value) {{\n", enumName, + os << formatv("::llvm::Optional<{0}> {1}({2} value) {{\n", enumName, underlyingToSymFnName, underlyingType.empty() ? std::string("unsigned") : underlyingType) @@ -299,7 +299,7 @@ static void emitUnderlyingToSymFnForIntEnum(const Record &enumDef, os << formatv(" case {0}: return {1}::{2};\n", value, enumName, makeIdentifier(symbol)); } - os << " default: return llvm::None;\n" + os << " default: return ::llvm::None;\n" << " }\n" << "}\n\n"; } @@ -313,7 +313,7 @@ static void emitUnderlyingToSymFnForBitEnum(const Record &enumDef, auto enumerants = enumAttr.getAllCases(); auto allBitsUnsetCase = getAllBitsUnsetCase(enumerants); - os << formatv("llvm::Optional<{0}> {1}({2} value) {{\n", enumName, + os << formatv("::llvm::Optional<{0}> {1}({2} value) {{\n", enumName, underlyingToSymFnName, underlyingType); if (allBitsUnsetCase) { os << " // Special case for all bits unset.\n"; @@ -357,11 +357,11 @@ static void emitEnumDecl(const Record &enumDef, raw_ostream &os) { return enumerant.getValue() >= 0; })) { os << formatv( - "llvm::Optional<{0}> {1}({2});\n", enumName, underlyingToSymFnName, + "::llvm::Optional<{0}> {1}({2});\n", enumName, underlyingToSymFnName, underlyingType.empty() ? std::string("unsigned") : underlyingType); } os << formatv("{2} {1}({0});\n", enumName, symToStrFnName, symToStrFnRetType); - os << formatv("llvm::Optional<{0}> {1}(llvm::StringRef);\n", enumName, + os << formatv("::llvm::Optional<{0}> {1}(::llvm::StringRef);\n", enumName, strToSymFnName); if (enumAttr.isBitEnum()) { @@ -383,10 +383,10 @@ inline {0} stringifyEnum({1} enumValue) {{ // specified by the user. const char *const symbolizeEnumStr = R"( template -llvm::Optional symbolizeEnum(llvm::StringRef); +::llvm::Optional symbolizeEnum(::llvm::StringRef); template <> -inline llvm::Optional<{0}> symbolizeEnum<{0}>(llvm::StringRef str) { +inline ::llvm::Optional<{0}> symbolizeEnum<{0}>(::llvm::StringRef str) { return {1}(str); } )"; diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index e477c56..5f07704 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -81,10 +81,10 @@ const char *sameVariadicSizeValueRangeCalcCode = R"( // {0}: The name of the attribute specifying the segment sizes. const char *adapterSegmentSizeAttrInitCode = R"( assert(odsAttrs && "missing segment size attribute for op"); - auto sizeAttr = odsAttrs.get("{0}").cast(); + auto sizeAttr = odsAttrs.get("{0}").cast<::mlir::DenseIntElementsAttr>(); )"; const char *opSegmentSizeAttrInitCode = R"( - auto sizeAttr = getAttrOfType("{0}"); + auto sizeAttr = getAttrOfType<::mlir::DenseIntElementsAttr>("{0}"); )"; const char *attrSizedSegmentValueRangeCalcCode = R"( unsigned start = 0; @@ -484,7 +484,7 @@ void OpEmitter::emitDef(raw_ostream &os) { opClass.writeDefTo(os); } void OpEmitter::genAttrGetters() { FmtContext fctx; - fctx.withBuilder("mlir::Builder(this->getContext())"); + fctx.withBuilder("::mlir::Builder(this->getContext())"); // Emit the derived attribute body. auto emitDerivedAttr = [&](StringRef name, Attribute attr) { @@ -545,13 +545,14 @@ void OpEmitter::genAttrGetters() { return namedAttr.attr.isDerivedAttr(); }); if (!derivedAttrs.empty()) { - opClass.addTrait("DerivedAttributeOpInterface::Trait"); + opClass.addTrait("::mlir::DerivedAttributeOpInterface::Trait"); // Generate helper method to query whether a named attribute is a derived // attribute. This enables, for example, avoiding adding an attribute that // overlaps with a derived attribute. { - auto &method = opClass.newMethod("bool", "isDerivedAttribute", - "StringRef name", OpMethod::MP_Static); + auto &method = + opClass.newMethod("bool", "isDerivedAttribute", + "::llvm::StringRef name", OpMethod::MP_Static); auto &body = method.body(); for (auto namedAttr : derivedAttrs) body << " if (name == \"" << namedAttr.name << "\") return true;\n"; @@ -559,8 +560,8 @@ void OpEmitter::genAttrGetters() { } // Generate method to materialize derived attributes as a DictionaryAttr. { - OpMethod &method = - opClass.newMethod("DictionaryAttr", "materializeDerivedAttributes"); + OpMethod &method = opClass.newMethod("::mlir::DictionaryAttr", + "materializeDerivedAttributes"); auto &body = method.body(); auto nonMaterializable = @@ -584,14 +585,15 @@ void OpEmitter::genAttrGetters() { return; } - body << " MLIRContext* ctx = getContext();\n"; - body << " Builder odsBuilder(ctx); (void)odsBuilder;\n"; - body << " return DictionaryAttr::get({\n"; + body << " ::mlir::MLIRContext* ctx = getContext();\n"; + body << " ::mlir::Builder odsBuilder(ctx); (void)odsBuilder;\n"; + body << " return ::mlir::DictionaryAttr::get({\n"; interleave( derivedAttrs, body, [&](const NamedAttribute &namedAttr) { auto tmpl = namedAttr.attr.getConvertFromStorageCall(); - body << " {Identifier::get(\"" << namedAttr.name << "\", ctx),\n" + body << " {::mlir::Identifier::get(\"" << namedAttr.name + << "\", ctx),\n" << tgfmt(tmpl, &fctx.withSelf(namedAttr.name + "()") .withBuilder("odsBuilder") .addSubst("_ctx", "ctx")) @@ -713,14 +715,14 @@ static void generateNamedOperandGetters(const Operator &op, Class &opClass, continue; if (operand.isOptional()) { - auto &m = opClass.newMethod("Value", operand.name); + auto &m = opClass.newMethod("::mlir::Value", operand.name); m.body() << " auto operands = getODSOperands(" << i << ");\n" << " return operands.empty() ? Value() : *operands.begin();"; } else if (operand.isVariadic()) { auto &m = opClass.newMethod(rangeType, operand.name); m.body() << " return getODSOperands(" << i << ");"; } else { - auto &m = opClass.newMethod("Value", operand.name); + auto &m = opClass.newMethod("::mlir::Value", operand.name); m.body() << " return *getODSOperands(" << i << ").begin();"; } } @@ -731,7 +733,7 @@ void OpEmitter::genNamedOperandGetters() { op, opClass, /*sizeAttrInit=*/ formatv(opSegmentSizeAttrInitCode, "operand_segment_sizes").str(), - /*rangeType=*/"Operation::operand_range", + /*rangeType=*/"::mlir::Operation::operand_range", /*rangeBeginCall=*/"getOperation()->operand_begin()", /*rangeSizeCall=*/"getOperation()->getNumOperands()", /*getOperandCallPattern=*/"getOperation()->getOperand({0})"); @@ -790,8 +792,8 @@ void OpEmitter::genNamedResultGetters() { numNormalResults, "getOperation()->getNumResults()", attrSizedResults, formatv(opSegmentSizeAttrInitCode, "result_segment_sizes").str(), op.getResults()); - auto &m = opClass.newMethod("Operation::result_range", "getODSResults", - "unsigned index"); + auto &m = opClass.newMethod("::mlir::Operation::result_range", + "getODSResults", "unsigned index"); m.body() << formatv(valueRangeReturnCode, "getOperation()->result_begin()", "getODSResultIndexAndLength(index)"); @@ -801,14 +803,16 @@ void OpEmitter::genNamedResultGetters() { continue; if (result.isOptional()) { - auto &m = opClass.newMethod("Value", result.name); - m.body() << " auto results = getODSResults(" << i << ");\n" - << " return results.empty() ? Value() : *results.begin();"; + auto &m = opClass.newMethod("::mlir::Value", result.name); + m.body() + << " auto results = getODSResults(" << i << ");\n" + << " return results.empty() ? ::mlir::Value() : *results.begin();"; } else if (result.isVariadic()) { - auto &m = opClass.newMethod("Operation::result_range", result.name); + auto &m = + opClass.newMethod("::mlir::Operation::result_range", result.name); m.body() << " return getODSResults(" << i << ");"; } else { - auto &m = opClass.newMethod("Value", result.name); + auto &m = opClass.newMethod("::mlir::Value", result.name); m.body() << " return *getODSResults(" << i << ").begin();"; } } @@ -823,13 +827,14 @@ void OpEmitter::genNamedRegionGetters() { // Generate the accessors for a varidiadic region. if (region.isVariadic()) { - auto &m = opClass.newMethod("MutableArrayRef", region.name); + auto &m = + opClass.newMethod("::mlir::MutableArrayRef", region.name); m.body() << formatv( " return this->getOperation()->getRegions().drop_front({0});", i); continue; } - auto &m = opClass.newMethod("Region &", region.name); + auto &m = opClass.newMethod("::mlir::Region &", region.name); m.body() << formatv(" return this->getOperation()->getRegion({0});", i); } } @@ -843,7 +848,7 @@ void OpEmitter::genNamedSuccessorGetters() { // Generate the accessors for a variadic successor list. if (successor.isVariadic()) { - auto &m = opClass.newMethod("SuccessorRange", successor.name); + auto &m = opClass.newMethod("::mlir::SuccessorRange", successor.name); m.body() << formatv( " return {std::next(this->getOperation()->successor_begin(), {0}), " "this->getOperation()->successor_end()};", @@ -851,7 +856,7 @@ void OpEmitter::genNamedSuccessorGetters() { continue; } - auto &m = opClass.newMethod("Block *", successor.name); + auto &m = opClass.newMethod("::mlir::Block *", successor.name); m.body() << formatv(" return this->getOperation()->getSuccessor({0});", i); } } @@ -910,14 +915,14 @@ void OpEmitter::genSeparateArgParamBuilder() { // inferred automatically. // TODO(jpienaar): Expand to handle regions. body << formatv(R"( - SmallVector inferredReturnTypes; + ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes; if (succeeded({0}::inferReturnTypes(odsBuilder.getContext(), {1}.location, {1}.operands, {1}.attributes.getDictionary({1}.getContext()), /*regions=*/{{}, inferredReturnTypes))) {1}.addTypes(inferredReturnTypes); else - llvm::report_fatal_error("Failed to infer result type(s).");)", + ::llvm::report_fatal_error("Failed to infer result type(s).");)", opClass.getClassName(), builderOpState); return; } @@ -967,8 +972,10 @@ void OpEmitter::genUseOperandAsResultTypeCollectiveParamBuilder() { // Signature std::string params = - std::string("OpBuilder &odsBuilder, OperationState &") + builderOpState + - ", ValueRange operands, ArrayRef attributes"; + std::string("::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &") + + builderOpState + + ", ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> " + "attributes"; if (op.getNumVariadicRegions()) params += ", unsigned numRegions"; auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static); @@ -997,8 +1004,9 @@ void OpEmitter::genUseOperandAsResultTypeCollectiveParamBuilder() { void OpEmitter::genInferredTypeCollectiveParamBuilder() { // TODO(jpienaar): Expand to support regions. const char *params = - "OpBuilder &odsBuilder, OperationState &{0}, " - "ValueRange operands, ArrayRef attributes"; + "::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &{0}, " + "::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> " + "attributes"; auto &m = opClass.newMethod("void", "build", formatv(params, builderOpState).str(), OpMethod::MP_Static); @@ -1031,7 +1039,7 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder() { // Result types body << formatv(R"( - SmallVector inferredReturnTypes; + ::mlir::SmallVector<::mlir::Type, 2> inferredReturnTypes; if (succeeded({0}::inferReturnTypes(odsBuilder.getContext(), {1}.location, operands, {1}.attributes.getDictionary({1}.getContext()), @@ -1045,7 +1053,7 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder() { body << formatv(R"( } else - llvm::report_fatal_error("Failed to infer result type(s).");)", + ::llvm::report_fatal_error("Failed to infer result type(s).");)", opClass.getClassName(), builderOpState); } @@ -1073,8 +1081,10 @@ void OpEmitter::genUseOperandAsResultTypeSeparateParamBuilder() { void OpEmitter::genUseAttrAsResultTypeBuilder() { std::string params = - std::string("OpBuilder &odsBuilder, OperationState &") + builderOpState + - ", ValueRange operands, ArrayRef attributes"; + std::string("::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &") + + builderOpState + + ", ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> " + "attributes"; auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static); auto &body = m.body(); @@ -1085,7 +1095,7 @@ void OpEmitter::genUseAttrAsResultTypeBuilder() { body << " for (auto attr : attributes) {\n"; body << " if (attr.first != \"" << namedAttr.name << "\") continue;\n"; if (namedAttr.attr.isTypeAttr()) { - resultType = "attr.second.cast().getValue()"; + resultType = "attr.second.cast<::mlir::TypeAttr>().getValue()"; } else { resultType = "attr.second.getType()"; } @@ -1163,10 +1173,12 @@ void OpEmitter::genCollectiveParamBuilder() { int numVariadicOperands = op.getNumVariableLengthOperands(); int numNonVariadicOperands = numOperands - numVariadicOperands; // Signature - std::string params = std::string("OpBuilder &, OperationState &") + - builderOpState + - ", ArrayRef resultTypes, ValueRange operands, " - "ArrayRef attributes"; + std::string params = + std::string("::mlir::OpBuilder &, ::mlir::OperationState &") + + builderOpState + + ", ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::ValueRange " + "operands, " + "::llvm::ArrayRef<::mlir::NamedAttribute> attributes"; if (op.getNumVariadicRegions()) params += ", unsigned numRegions"; auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static); @@ -1212,7 +1224,7 @@ void OpEmitter::buildParamList(std::string ¶mList, auto numResults = op.getNumResults(); resultTypeNames.reserve(numResults); - paramList = "OpBuilder &odsBuilder, OperationState &"; + paramList = "::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &"; paramList.append(builderOpState); switch (typeParamKind) { @@ -1227,18 +1239,18 @@ void OpEmitter::buildParamList(std::string ¶mList, resultName = std::string(formatv("resultType{0}", i)); if (result.isOptional()) - paramList.append(", /*optional*/Type "); + paramList.append(", /*optional*/::mlir::Type "); else if (result.isVariadic()) - paramList.append(", ArrayRef "); + paramList.append(", ::llvm::ArrayRef<::mlir::Type> "); else - paramList.append(", Type "); + paramList.append(", ::mlir::Type "); paramList.append(resultName); resultTypeNames.emplace_back(std::move(resultName)); } } break; case TypeParamKind::Collective: { - paramList.append(", ArrayRef resultTypes"); + paramList.append(", ::llvm::ArrayRef<::mlir::Type> resultTypes"); resultTypeNames.push_back("resultTypes"); } break; } @@ -1266,7 +1278,7 @@ void OpEmitter::buildParamList(std::string ¶mList, // TODO(b/144412160) Adjust the 'returnType' field of such attributes // to support them. StringRef retType = namedAttr->attr.getReturnType(); - if (retType == "APInt" || retType == "APFloat") + if (retType == "::llvm::APInt" || retType == "::llvm::APFloat") break; defaultValuedAttrStartIndex = i; @@ -1278,11 +1290,11 @@ void OpEmitter::buildParamList(std::string ¶mList, if (argument.is()) { const auto &operand = op.getOperand(numOperands); if (operand.isOptional()) - paramList.append(", /*optional*/Value "); + paramList.append(", /*optional*/::mlir::Value "); else if (operand.isVariadic()) - paramList.append(", ValueRange "); + paramList.append(", ::mlir::ValueRange "); else - paramList.append(", Value "); + paramList.append(", ::mlir::Value "); paramList.append(getArgumentName(op, numOperands)); ++numOperands; } else { @@ -1311,7 +1323,7 @@ void OpEmitter::buildParamList(std::string ¶mList, // Attach default value if requested and possible. if (attrParamKind == AttrParamKind::UnwrappedValue && i >= defaultValuedAttrStartIndex) { - bool isString = attr.getReturnType() == "StringRef"; + bool isString = attr.getReturnType() == "::llvm::StringRef"; paramList.append(" = "); if (isString) paramList.append("\""); @@ -1325,7 +1337,8 @@ void OpEmitter::buildParamList(std::string ¶mList, /// Insert parameters for each successor. for (const NamedSuccessor &succ : op.getSuccessors()) { - paramList += (succ.isVariadic() ? ", ArrayRef " : ", Block *"); + paramList += (succ.isVariadic() ? ", ::llvm::ArrayRef<::mlir::Block *> " + : ", ::mlir::Block *"); paramList += succ.name; } @@ -1421,7 +1434,7 @@ void OpEmitter::genCanonicalizerDecls() { return; const char *const params = - "OwningRewritePatternList &results, MLIRContext *context"; + "::mlir::OwningRewritePatternList &results, ::mlir::MLIRContext *context"; opClass.newMethod("void", "getCanonicalizationPatterns", params, OpMethod::MP_Static, /*declOnly=*/true); } @@ -1432,13 +1445,16 @@ void OpEmitter::genFolderDecls() { if (def.getValueAsBit("hasFolder")) { if (hasSingleResult) { - const char *const params = "ArrayRef operands"; - opClass.newMethod("OpFoldResult", "fold", params, OpMethod::MP_None, + const char *const params = "::llvm::ArrayRef<::mlir::Attribute> operands"; + opClass.newMethod("::mlir::OpFoldResult", "fold", params, + OpMethod::MP_None, /*declOnly=*/true); } else { - const char *const params = "ArrayRef operands, " - "SmallVectorImpl &results"; - opClass.newMethod("LogicalResult", "fold", params, OpMethod::MP_None, + const char *const params = + "::llvm::ArrayRef<::mlir::Attribute> operands, " + "::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results"; + opClass.newMethod("::mlir::LogicalResult", "fold", params, + OpMethod::MP_None, /*declOnly=*/true); } } @@ -1532,9 +1548,9 @@ void OpEmitter::genSideEffectInterfaceMethods() { for (auto &it : interfaceEffects) { auto effectsParam = - llvm::formatv( - "SmallVectorImpl> &effects", - it.first()) + llvm::formatv("::mlir::SmallVectorImpl<::mlir::SideEffects::" + "EffectInstance<{0}>> &effects", + it.first()) .str(); // Generate the 'getEffects' method. @@ -1544,7 +1560,7 @@ void OpEmitter::genSideEffectInterfaceMethods() { // Add effect instances for each of the locations marked on the operation. for (auto &location : it.second) { if (location.kind != EffectKind::Static) { - body << " for (Value value : getODS" + body << " for (::mlir::Value value : getODS" << (location.kind == EffectKind::Operand ? "Operands" : "Results") << "(" << location.index << "))\n "; } @@ -1565,10 +1581,12 @@ void OpEmitter::genTypeInterfaceMethods() { return; auto &method = opClass.newMethod( - "LogicalResult", "inferReturnTypes", - "MLIRContext* context, Optional location, " - "ValueRange operands, DictionaryAttr attributes, RegionRange regions, " - "SmallVectorImpl& inferredReturnTypes", + "::mlir::LogicalResult", "inferReturnTypes", + "::mlir::MLIRContext* context, " + "::llvm::Optional<::mlir::Location> location, " + "::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, " + "::mlir::RegionRange regions, " + "::llvm::SmallVectorImpl<::mlir::Type>& inferredReturnTypes", OpMethod::MP_Static, /*declOnly=*/false); auto &os = method.body(); @@ -1576,7 +1594,7 @@ void OpEmitter::genTypeInterfaceMethods() { FmtContext fctx; fctx.withBuilder("odsBuilder"); - os << " Builder odsBuilder(context);\n"; + os << " ::mlir::Builder odsBuilder(context);\n"; auto emitType = [&](const tblgen::Operator::ArgOrType &type) -> OpMethodBody & { @@ -1606,7 +1624,8 @@ void OpEmitter::genParser() { return; auto &method = opClass.newMethod( - "ParseResult", "parse", "OpAsmParser &parser, OperationState &result", + "::mlir::ParseResult", "parse", + "::mlir::OpAsmParser &parser, ::mlir::OperationState &result", OpMethod::MP_Static); FmtContext fctx; fctx.addSubst("cppClass", opClass.getClassName()); @@ -1623,7 +1642,7 @@ void OpEmitter::genPrinter() { if (!codeInit) return; - auto &method = opClass.newMethod("void", "print", "OpAsmPrinter &p"); + auto &method = opClass.newMethod("void", "print", "::mlir::OpAsmPrinter &p"); FmtContext fctx; fctx.addSubst("cppClass", opClass.getClassName()); auto printer = codeInit->getValue().ltrim().rtrim(" \t\v\f\r"); @@ -1631,7 +1650,8 @@ void OpEmitter::genPrinter() { } void OpEmitter::genVerifier() { - auto &method = opClass.newMethod("LogicalResult", "verify", /*params=*/""); + auto &method = + opClass.newMethod("::mlir::LogicalResult", "verify", /*params=*/""); auto &body = method.body(); body << " if (failed(" << op.getAdaptorName() << "(*this).verify(this->getLoc()))) " @@ -1666,7 +1686,7 @@ void OpEmitter::genVerifier() { auto printer = codeInit->getValue().ltrim().rtrim(" \t\v\f\r"); body << " " << tgfmt(printer, &fctx); } else { - body << " return mlir::success();\n"; + body << " return ::mlir::success();\n"; } } @@ -1703,7 +1723,8 @@ void OpEmitter::genOperandResultVerifier(OpMethodBody &body, continue; // Emit a loop to check all the dynamic values in the pack. - body << " for (Value v : valueGroup" << staticValue.index() << ") {\n"; + body << " for (::mlir::Value v : valueGroup" << staticValue.index() + << ") {\n"; auto constraint = staticValue.value().constraint; body << " (void)v;\n" @@ -1736,12 +1757,12 @@ void OpEmitter::genRegionVerifier(OpMethodBody &body) { if (region.constraint.getPredicate().isNull()) continue; - body << " for (Region ®ion : "; - body << formatv( - region.isVariadic() - ? "{0}()" - : "MutableArrayRef(this->getOperation()->getRegion({1}))", - region.name, i); + body << " for (::mlir::Region ®ion : "; + body << formatv(region.isVariadic() + ? "{0}()" + : "::mlir::MutableArrayRef<::mlir::Region>(this->" + "getOperation()->getRegion({1}))", + region.name, i); body << ") {\n"; auto constraint = tgfmt(region.constraint.getConditionTemplate(), &verifyCtx.withSelf("region")) @@ -1775,9 +1796,10 @@ void OpEmitter::genSuccessorVerifier(OpMethodBody &body) { if (successor.constraint.getPredicate().isNull()) continue; - body << " for (Block *successor : "; - body << formatv(successor.isVariadic() ? "{0}()" - : "ArrayRef({0}())", + body << " for (::mlir::Block *successor : "; + body << formatv(successor.isVariadic() + ? "{0}()" + : "::llvm::ArrayRef<::mlir::Block *>({0}())", successor.name); body << ") {\n"; auto constraint = tgfmt(successor.constraint.getConditionTemplate(), @@ -1873,7 +1895,7 @@ void OpEmitter::genTraits() { } void OpEmitter::genOpNameGetter() { - auto &method = opClass.newMethod("StringRef", "getOperationName", + auto &method = opClass.newMethod("::llvm::StringRef", "getOperationName", /*params=*/"", OpMethod::MP_Static); method.body() << " return \"" << op.getOperationName() << "\";\n"; } @@ -1937,15 +1959,16 @@ private: OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(const Operator &op) : op(op), adaptor(op.getAdaptorName()) { - adaptor.newField("ValueRange", "odsOperands"); - adaptor.newField("DictionaryAttr", "odsAttrs"); + adaptor.newField("::mlir::ValueRange", "odsOperands"); + adaptor.newField("::mlir::DictionaryAttr", "odsAttrs"); const auto *attrSizedOperands = op.getTrait("OpTrait::AttrSizedOperandSegments"); { auto &constructor = adaptor.newConstructor( attrSizedOperands - ? "ValueRange values, DictionaryAttr attrs" - : "ValueRange values, DictionaryAttr attrs = nullptr"); + ? "::mlir::ValueRange values, ::mlir::DictionaryAttr attrs" + : "::mlir::ValueRange values, ::mlir::DictionaryAttr attrs = " + "nullptr"); constructor.addMemberInitializer("odsOperands", "values"); constructor.addMemberInitializer("odsAttrs", "attrs"); } @@ -1962,13 +1985,13 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(const Operator &op) std::string sizeAttrInit = formatv(adapterSegmentSizeAttrInitCode, "operand_segment_sizes"); generateNamedOperandGetters(op, adaptor, sizeAttrInit, - /*rangeType=*/"ValueRange", + /*rangeType=*/"::mlir::ValueRange", /*rangeBeginCall=*/"odsOperands.begin()", /*rangeSizeCall=*/"odsOperands.size()", /*getOperandCallPattern=*/"odsOperands[{0}]"); FmtContext fctx; - fctx.withBuilder("mlir::Builder(odsAttrs.getContext())"); + fctx.withBuilder("::mlir::Builder(odsAttrs.getContext())"); auto emitAttr = [&](StringRef name, Attribute attr) { auto &body = adaptor.newMethod(attr.getStorageType(), name).body(); @@ -2004,14 +2027,14 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(const Operator &op) } void OpOperandAdaptorEmitter::addVerification() { - auto &method = adaptor.newMethod("LogicalResult", "verify", - /*params=*/"Location loc"); + auto &method = adaptor.newMethod("::mlir::LogicalResult", "verify", + /*params=*/"::mlir::Location loc"); auto &body = method.body(); const char *checkAttrSizedValueSegmentsCode = R"( { - auto sizeAttr = odsAttrs.get("{0}").cast(); - auto numElements = sizeAttr.getType().cast().getNumElements(); + auto sizeAttr = odsAttrs.get("{0}").cast<::mlir::DenseIntElementsAttr>(); + auto numElements = sizeAttr.getType().cast<::mlir::ShapedType>().getNumElements(); if (numElements != {1}) return emitError(loc, "'{0}' attribute for specifying {2} segments " "must have {1} elements"); diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index 9fa87e3..8290fc0 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -371,8 +371,8 @@ const char *const attrParserCode = R"( /// {3}: The constant builder call to create an attribute of the enum type. const char *const enumAttrParserCode = R"( { - StringAttr attrVal; - NamedAttrList attrStorage; + ::mlir::StringAttr attrVal; + ::mlir::NamedAttrList attrStorage; auto loc = parser.getCurrentLocation(); if (parser.parseAttribute(attrVal, parser.getBuilder().getNoneType(), "{0}", attrStorage)) @@ -396,8 +396,9 @@ const char *const variadicOperandParserCode = R"( )"; const char *const optionalOperandParserCode = R"( { - OpAsmParser::OperandType operand; - OptionalParseResult parseResult = parser.parseOptionalOperand(operand); + ::mlir::OpAsmParser::OperandType operand; + ::mlir::OptionalParseResult parseResult = + parser.parseOptionalOperand(operand); if (parseResult.hasValue()) { if (failed(*parseResult)) return failure(); @@ -419,8 +420,9 @@ const char *const variadicTypeParserCode = R"( )"; const char *const optionalTypeParserCode = R"( { - Type optionalType; - OptionalParseResult parseResult = parser.parseOptionalType(optionalType); + ::mlir::Type optionalType; + ::mlir::OptionalParseResult parseResult = + parser.parseOptionalType(optionalType); if (parseResult.hasValue()) { if (failed(*parseResult)) return failure(); @@ -438,7 +440,7 @@ const char *const typeParserCode = R"( /// {0}: The name for the input type list. /// {1}: The name for the result type list. const char *const functionalTypeParserCode = R"( - FunctionType {0}__{1}_functionType; + ::mlir::FunctionType {0}__{1}_functionType; if (parser.parseType({0}__{1}_functionType)) return failure(); {0}Types = {0}__{1}_functionType.getInputs(); @@ -449,9 +451,9 @@ const char *const functionalTypeParserCode = R"( /// /// {0}: The name for the successor list. const char *successorListParserCode = R"( - SmallVector {0}Successors; + ::llvm::SmallVector<::mlir::Block *, 2> {0}Successors; { - Block *succ; + ::mlir::Block *succ; auto firstSucc = parser.parseOptionalSuccessor(succ); if (firstSucc.hasValue()) { if (failed(*firstSucc)) @@ -472,7 +474,7 @@ const char *successorListParserCode = R"( /// /// {0}: The name of the successor. const char *successorParserCode = R"( - Block *{0}Successor = nullptr; + ::mlir::Block *{0}Successor = nullptr; if (parser.parseSuccessor({0}Successor)) return failure(); )"; @@ -546,31 +548,34 @@ static void genElementParserStorage(Element *element, OpMethodBody &body) { } else if (auto *operand = dyn_cast(element)) { StringRef name = operand->getVar()->name; if (operand->getVar()->isVariableLength()) { - body << " SmallVector " << name - << "Operands;\n"; + body << " ::mlir::SmallVector<::mlir::OpAsmParser::OperandType, 4> " + << name << "Operands;\n"; } else { - body << " OpAsmParser::OperandType " << name << "RawOperands[1];\n" - << " ArrayRef " << name << "Operands(" - << name << "RawOperands);"; + body << " ::mlir::OpAsmParser::OperandType " << name + << "RawOperands[1];\n" + << " ::llvm::ArrayRef<::mlir::OpAsmParser::OperandType> " << name + << "Operands(" << name << "RawOperands);"; } body << llvm::formatv( - " llvm::SMLoc {0}OperandsLoc = parser.getCurrentLocation();\n" + " ::llvm::SMLoc {0}OperandsLoc = parser.getCurrentLocation();\n" " (void){0}OperandsLoc;\n", name); } else if (auto *dir = dyn_cast(element)) { ArgumentLengthKind lengthKind; StringRef name = getTypeListName(dir->getOperand(), lengthKind); if (lengthKind != ArgumentLengthKind::Single) - body << " SmallVector " << name << "Types;\n"; + body << " ::mlir::SmallVector<::mlir::Type, 1> " << name << "Types;\n"; else - body << llvm::formatv(" Type {0}RawTypes[1];\n", name) - << llvm::formatv(" ArrayRef {0}Types({0}RawTypes);\n", name); + body << llvm::formatv(" ::mlir::Type {0}RawTypes[1];\n", name) + << llvm::formatv( + " ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n", + name); } else if (auto *dir = dyn_cast(element)) { ArgumentLengthKind ignored; - body << " ArrayRef " << getTypeListName(dir->getInputs(), ignored) - << "Types;\n"; - body << " ArrayRef " << getTypeListName(dir->getResults(), ignored) - << "Types;\n"; + body << " ::llvm::ArrayRef<::mlir::Type> " + << getTypeListName(dir->getInputs(), ignored) << "Types;\n"; + body << " ::llvm::ArrayRef<::mlir::Type> " + << getTypeListName(dir->getResults(), ignored) << "Types;\n"; } } @@ -655,8 +660,9 @@ static void genElementParser(Element *element, OpMethodBody &body, << "(result.attributes))\n" << " return failure();\n"; } else if (isa(element)) { - body << " llvm::SMLoc allOperandLoc = parser.getCurrentLocation();\n" - << " SmallVector allOperands;\n" + body << " ::llvm::SMLoc allOperandLoc = parser.getCurrentLocation();\n" + << " ::mlir::SmallVector<::mlir::OpAsmParser::OperandType, 4> " + "allOperands;\n" << " if (parser.parseOperandList(allOperands))\n" << " return failure();\n"; } else if (isa(element)) { @@ -682,7 +688,8 @@ static void genElementParser(Element *element, OpMethodBody &body, void OperationFormat::genParser(Operator &op, OpClass &opClass) { auto &method = opClass.newMethod( - "ParseResult", "parse", "OpAsmParser &parser, OperationState &result", + "::mlir::ParseResult", "parse", + "::mlir::OpAsmParser &parser, ::mlir::OperationState &result", OpMethod::MP_Static); auto &body = method.body(); @@ -726,7 +733,7 @@ void OperationFormat::genParserTypeResolution(Operator &op, continue; auto constraint = variable->constraint; - body << " for (Type type : " << variable->name << "Types) {\n" + body << " for (::mlir::Type type : " << variable->name << "Types) {\n" << " (void)type;\n" << " if (!(" << tgfmt(constraint.getConditionTemplate(), @@ -744,7 +751,7 @@ void OperationFormat::genParserTypeResolution(Operator &op, FmtContext typeBuilderCtx; typeBuilderCtx.withBuilder("parser.getBuilder()"); for (auto &it : buildableTypes) - body << " Type odsBuildableType" << it.second << " = " + body << " ::mlir::Type odsBuildableType" << it.second << " = " << tgfmt(it.first, &typeBuilderCtx) << ";\n"; } @@ -791,7 +798,7 @@ void OperationFormat::genParserTypeResolution(Operator &op, // llvm::concat does not allow the case of a single range, so guard it here. body << " if (parser.resolveOperands("; if (op.getNumOperands() > 1) { - body << "llvm::concat("; + body << "::llvm::concat("; llvm::interleaveComma(op.getOperands(), body, [&](auto &operand) { body << operand.name << "Operands"; }); @@ -811,10 +818,10 @@ void OperationFormat::genParserTypeResolution(Operator &op, // once. Use llvm::concat to perform the merge. llvm::concat does not allow // the case of a single range, so guard it here. if (op.getNumOperands() > 1) { - body << "llvm::concat("; + body << "::llvm::concat("; llvm::interleaveComma( llvm::seq(0, op.getNumOperands()), body, [&](int i) { - body << "ArrayRef("; + body << "::llvm::ArrayRef<::mlir::Type>("; emitTypeResolver(operandTypes[i], op.getOperand(i).name); body << ")"; }); @@ -946,9 +953,11 @@ static OpMethodBody &genTypeOperandPrinter(Element *arg, OpMethodBody &body) { return body << var->name << "().getTypes()"; if (var->isOptional()) return body << llvm::formatv( - "({0}() ? ArrayRef({0}().getType()) : ArrayRef())", + "({0}() ? ::llvm::ArrayRef<::mlir::Type>({0}().getType()) : " + "::llvm::ArrayRef<::mlir::Type>())", var->name); - return body << "ArrayRef(" << var->name << "().getType())"; + return body << "::llvm::ArrayRef<::mlir::Type>(" << var->name + << "().getType())"; } /// Generate the code for printing the given element. @@ -1014,7 +1023,8 @@ static void genElementPrinter(Element *element, OpMethodBody &body, body << " p.printAttribute(" << var->name << "Attr());\n"; } else if (auto *operand = dyn_cast(element)) { if (operand->getVar()->isOptional()) { - body << " if (Value value = " << operand->getVar()->name << "())\n" + body << " if (::mlir::Value value = " << operand->getVar()->name + << "())\n" << " p << value;\n"; } else { body << " p << " << operand->getVar()->name << "();\n"; @@ -1022,13 +1032,13 @@ static void genElementPrinter(Element *element, OpMethodBody &body, } else if (auto *successor = dyn_cast(element)) { const NamedSuccessor *var = successor->getVar(); if (var->isVariadic()) - body << " llvm::interleaveComma(" << var->name << "(), p);\n"; + body << " ::llvm::interleaveComma(" << var->name << "(), p);\n"; else body << " p << " << var->name << "();\n"; } else if (isa(element)) { body << " p << getOperation()->getOperands();\n"; } else if (isa(element)) { - body << " llvm::interleaveComma(getOperation()->getSuccessors(), p);\n"; + body << " ::llvm::interleaveComma(getOperation()->getSuccessors(), p);\n"; } else if (auto *dir = dyn_cast(element)) { body << " p << "; genTypeOperandPrinter(dir->getOperand(), body) << ";\n"; @@ -1301,7 +1311,8 @@ Token FormatLexer::lexIdentifier(const char *tokStart) { /// Function to find an element within the given range that has the same name as /// 'name'. -template static auto findArg(RangeT &&range, StringRef name) { +template +static auto findArg(RangeT &&range, StringRef name) { auto it = llvm::find_if(range, [=](auto &arg) { return arg.name == name; }); return it != range.end() ? &*it : nullptr; } diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp index a693b02..fc15b2d 100644 --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -119,7 +119,7 @@ static void emitModelDecl(OpInterface &interface, raw_ostream &os) { // Provide a definition of the concrete op if this is non static. if (!method.isStatic()) { - os << " auto op = llvm::cast(tablegen_opaque_op);\n" + os << " auto op = ::mlir::cast(tablegen_opaque_op);\n" << " (void)op;\n"; } @@ -146,7 +146,7 @@ static void emitTraitDecl(OpInterface &interface, raw_ostream &os, StringRef interfaceName, StringRef interfaceTraitsName) { os << " template \n " - << llvm::formatv("struct {0}Trait : public OpInterface<{0}," + << llvm::formatv("struct {0}Trait : public ::mlir::OpInterface<{0}," " detail::{1}>::Trait {{\n", interfaceName, interfaceTraitsName); @@ -171,7 +171,7 @@ static void emitTraitDecl(OpInterface &interface, raw_ostream &os, tblgen::FmtContext traitCtx; traitCtx.withOp("op"); if (auto verify = interface.getVerify()) { - os << " static LogicalResult verifyTrait(Operation* op) {\n" + os << " static ::mlir::LogicalResult verifyTrait(Operation* op) {\n" << std::string(tblgen::tgfmt(*verify, &traitCtx)) << "\n }\n"; } if (auto extraTraitDecls = interface.getExtraTraitClassDeclaration()) @@ -197,10 +197,11 @@ static void emitInterfaceDecl(OpInterface &interface, raw_ostream &os) { os << "};\n} // end namespace detail\n"; // Emit the main interface class declaration. - os << llvm::formatv("class {0} : public OpInterface<{1}, detail::{2}> {\n" - "public:\n" - " using OpInterface<{1}, detail::{2}>::OpInterface;\n", - interfaceName, interfaceName, interfaceTraitsName); + os << llvm::formatv( + "class {0} : public ::mlir::OpInterface<{1}, detail::{2}> {\n" + "public:\n" + " using ::mlir::OpInterface<{1}, detail::{2}>::OpInterface;\n", + interfaceName, interfaceName, interfaceTraitsName); // Emit the derived trait for the interface. emitTraitDecl(interface, os, interfaceName, interfaceTraitsName); diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp index b662b43..f8998f0 100644 --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -42,10 +42,10 @@ public: {0}Base(const {0}Base &) : {1}(::mlir::TypeID::get()) {{} /// Returns the command-line argument attached to this pass. - llvm::StringRef getArgument() const override { return "{2}"; } + ::llvm::StringRef getArgument() const override { return "{2}"; } /// Returns the derived pass name. - llvm::StringRef getName() const override { return "{0}"; } + ::llvm::StringRef getName() const override { return "{0}"; } /// Support isa/dyn_cast functionality for the derived pass class. static bool classof(const ::mlir::Pass *pass) {{ @@ -63,13 +63,14 @@ protected: /// Emit the declarations for each of the pass options. static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) { for (const PassOption &opt : pass.getOptions()) { - os.indent(2) << "Pass::" << (opt.isListOption() ? "ListOption" : "Option"); + os.indent(2) << "::mlir::Pass::" + << (opt.isListOption() ? "ListOption" : "Option"); - os << llvm::formatv("<{0}> {1}{{*this, \"{2}\", llvm::cl::desc(\"{3}\")", + os << llvm::formatv("<{0}> {1}{{*this, \"{2}\", ::llvm::cl::desc(\"{3}\")", opt.getType(), opt.getCppVariableName(), opt.getArgument(), opt.getDescription()); if (Optional defaultVal = opt.getDefaultValue()) - os << ", llvm::cl::init(" << defaultVal << ")"; + os << ", ::llvm::cl::init(" << defaultVal << ")"; if (Optional additionalFlags = opt.getAdditionalFlags()) os << ", " << *additionalFlags; os << "};\n"; @@ -79,9 +80,9 @@ static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) { /// Emit the declarations for each of the pass statistics. static void emitPassStatisticDecls(const Pass &pass, raw_ostream &os) { for (const PassStatistic &stat : pass.getStatistics()) { - os << llvm::formatv(" Pass::Statistic {0}{{this, \"{1}\", \"{2}\"};\n", - stat.getCppVariableName(), stat.getName(), - stat.getDescription()); + os << llvm::formatv( + " ::mlir::Pass::Statistic {0}{{this, \"{1}\", \"{2}\"};\n", + stat.getCppVariableName(), stat.getName(), stat.getDescription()); } } diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index 13498e0..37af7d2 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -39,7 +39,8 @@ using llvm::RecordKeeper; #define DEBUG_TYPE "mlir-tblgen-rewritergen" namespace llvm { -template <> struct format_provider { +template <> +struct format_provider { static void format(const mlir::tblgen::Pattern::IdentifierLine &v, raw_ostream &os, StringRef style) { os << v.first << ":" << v.second; @@ -489,9 +490,9 @@ void PatternEmitter::emit(StringRef rewriteName) { auto locs = pattern.getLocation(); os << formatv("/* Generated from:\n\t{0:$[ instantiating\n\t]}\n*/\n", make_range(locs.rbegin(), locs.rend())); - os << formatv(R"(struct {0} : public RewritePattern { - {0}(MLIRContext *context) - : RewritePattern("{1}", {{)", + os << formatv(R"(struct {0} : public ::mlir::RewritePattern { + {0}(::mlir::MLIRContext *context) + : ::mlir::RewritePattern("{1}", {{)", rewriteName, rootName); // Sort result operators by name. llvm::SmallVector sortedResultOps(resultOps.begin(), @@ -506,8 +507,9 @@ void PatternEmitter::emit(StringRef rewriteName) { // Emit matchAndRewrite() function. os << R"( - LogicalResult matchAndRewrite(Operation *op0, - PatternRewriter &rewriter) const override { + ::mlir::LogicalResult + matchAndRewrite(::mlir::Operation *op0, + ::mlir::PatternRewriter &rewriter) const override { )"; // Register all symbols bound in the source pattern. @@ -526,7 +528,7 @@ void PatternEmitter::emit(StringRef rewriteName) { } // TODO(jpienaar): capture ops with consistent numbering so that it can be // reused for fused loc. - os.indent(4) << formatv("Operation *tblgen_ops[{0}];\n\n", + os.indent(4) << formatv("::mlir::Operation *tblgen_ops[{0}];\n\n", pattern.getSourcePattern().getNumOps()); LLVM_DEBUG( llvm::dbgs() << "done creating local variables for capturing matches\n"); @@ -606,7 +608,8 @@ void PatternEmitter::emitRewriteLogic() { os.indent(4) << "rewriter.eraseOp(op0);\n"; } else { // Process replacement result patterns. - os.indent(4) << "SmallVector tblgen_repl_values;\n"; + os.indent(4) + << "::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values;\n"; for (int i = replStartIndex; i < numResultPatterns; ++i) { DagNode resultTree = pattern.getResultPattern(i); auto val = handleResultPattern(resultTree, offsets[i], 0); @@ -619,7 +622,7 @@ void PatternEmitter::emitRewriteLogic() { // TODO(b/147096809): Revisit the need for materializing a vector. os << symbolInfoMap.getAllRangeUse( val, - " for (auto v : SmallVector{ {0} }) {{ " + " for (auto v : ::llvm::SmallVector<::mlir::Value, 4>{ {0} }) {{ " "tblgen_repl_values.push_back(v); }", "\n"); } @@ -697,7 +700,7 @@ std::string PatternEmitter::handleLocationDirective(DagNode tree) { 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.getIdentifier(\"{0}\"), " "rewriter.getContext())", leaf.getStringAttr()) .str(); @@ -918,8 +921,8 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex, // Then prepare the result types. We need to specify the types for all // results. - os.indent(6) << formatv( - "SmallVector tblgen_types; (void)tblgen_types;\n"); + os.indent(6) << formatv("::mlir::SmallVector<::mlir::Type, 4> tblgen_types; " + "(void)tblgen_types;\n"); int numResults = resultOp.getNumResults(); if (numResults != 0) { for (int i = 0; i < numResults; ++i) @@ -956,7 +959,8 @@ void PatternEmitter::createSeparateLocalVarsForOpArgs( std::string varName; if (operand->isVariadic()) { varName = std::string(formatv("tblgen_values_{0}", valueIndex++)); - os.indent(6) << formatv("SmallVector {0};\n", varName); + os.indent(6) << formatv("::mlir::SmallVector<::mlir::Value, 4> {0};\n", + varName); std::string range; if (node.isNestedDagArg(argIndex)) { range = childNodeNames[argIndex]; @@ -970,7 +974,7 @@ void PatternEmitter::createSeparateLocalVarsForOpArgs( varName); } else { varName = std::string(formatv("tblgen_value_{0}", valueIndex++)); - os.indent(6) << formatv("Value {0} = ", varName); + os.indent(6) << formatv("::mlir::Value {0} = ", varName); if (node.isNestedDagArg(argIndex)) { os << symbolInfoMap.getValueAndRangeUse(childNodeNames[argIndex]); } else { @@ -1039,10 +1043,10 @@ void PatternEmitter::createAggregateLocalVarsForOpArgs( DagNode node, const ChildNodeIndexNameMap &childNodeNames) { Operator &resultOp = node.getDialectOp(opMap); - os.indent(6) << formatv( - "SmallVector tblgen_values; (void)tblgen_values;\n"); - os.indent(6) << formatv( - "SmallVector tblgen_attrs; (void)tblgen_attrs;\n"); + os.indent(6) << formatv("::mlir::SmallVector<::mlir::Value, 4> " + "tblgen_values; (void)tblgen_values;\n"); + os.indent(6) << formatv("::mlir::SmallVector<::mlir::NamedAttribute, 4> " + "tblgen_attrs; (void)tblgen_attrs;\n"); const char *addAttrCmd = "if (auto tmpAttr = {1}) " diff --git a/mlir/tools/mlir-tblgen/StructsGen.cpp b/mlir/tools/mlir-tblgen/StructsGen.cpp index 005757a..cccacc0 100644 --- a/mlir/tools/mlir-tblgen/StructsGen.cpp +++ b/mlir/tools/mlir-tblgen/StructsGen.cpp @@ -36,11 +36,11 @@ emitStructClass(const Record &structDef, StringRef structName, StringRef description, raw_ostream &os) { const char *structInfo = R"( // {0} -class {1} : public mlir::DictionaryAttr)"; +class {1} : public ::mlir::DictionaryAttr)"; const char *structInfoEnd = R"( { public: - using DictionaryAttr::DictionaryAttr; - static bool classof(mlir::Attribute attr); + using ::mlir::DictionaryAttr::DictionaryAttr; + static bool classof(::mlir::Attribute attr); )"; os << formatv(structInfo, description, structName) << structInfoEnd; @@ -48,7 +48,7 @@ public: // TblgenStruct::get(MLIRContext context, Type1 Field1, Type2 Field2, ...); const char *getInfoDecl = " static {0} get(\n"; const char *getInfoDeclArg = " {0} {1},\n"; - const char *getInfoDeclEnd = " mlir::MLIRContext* context);\n\n"; + const char *getInfoDeclEnd = " ::mlir::MLIRContext* context);\n\n"; os << llvm::formatv(getInfoDecl, structName); @@ -112,7 +112,7 @@ static void emitFactoryDef(llvm::StringRef structName, raw_ostream &os) { const char *getInfoDecl = "{0} {0}::get(\n"; const char *getInfoDeclArg = " {0} {1},\n"; - const char *getInfoDeclEnd = " mlir::MLIRContext* context) {"; + const char *getInfoDeclEnd = " ::mlir::MLIRContext* context) {"; os << llvm::formatv(getInfoDecl, structName); @@ -125,19 +125,19 @@ static void emitFactoryDef(llvm::StringRef structName, os << getInfoDeclEnd; const char *fieldStart = R"( - llvm::SmallVector fields; + ::llvm::SmallVector<::mlir::NamedAttribute, {0}> fields; )"; os << llvm::formatv(fieldStart, fields.size()); const char *getFieldInfo = R"( assert({0}); - auto {0}_id = mlir::Identifier::get("{0}", context); + auto {0}_id = ::mlir::Identifier::get("{0}", context); fields.emplace_back({0}_id, {0}); )"; const char *getFieldInfoOptional = R"( if ({0}) { - auto {0}_id = mlir::Identifier::get("{0}", context); + auto {0}_id = ::mlir::Identifier::get("{0}", context); fields.emplace_back({0}_id, {0}); } )"; @@ -150,7 +150,7 @@ static void emitFactoryDef(llvm::StringRef structName, } const char *getEndInfo = R"( - Attribute dict = mlir::DictionaryAttr::get(fields, context); + ::mlir::Attribute dict = ::mlir::DictionaryAttr::get(fields, context); return dict.dyn_cast<{0}>(); } )"; @@ -161,12 +161,12 @@ static void emitClassofDef(llvm::StringRef structName, llvm::ArrayRef fields, raw_ostream &os) { const char *classofInfo = R"( -bool {0}::classof(mlir::Attribute attr))"; +bool {0}::classof(::mlir::Attribute attr))"; const char *classofInfoHeader = R"( if (!attr) return false; - auto derived = attr.dyn_cast(); + auto derived = attr.dyn_cast<::mlir::DictionaryAttr>(); if (!derived) return false; int empty_optionals = 0; @@ -212,7 +212,7 @@ emitAccessorDef(llvm::StringRef structName, raw_ostream &os) { const char *fieldInfo = R"( {0} {2}::{1}() const { - auto derived = this->cast(); + auto derived = this->cast<::mlir::DictionaryAttr>(); auto {1} = derived.get("{1}"); assert({1} && "attribute not found."); assert({1}.isa<{0}>() && "incorrect Attribute type found."); @@ -221,7 +221,7 @@ emitAccessorDef(llvm::StringRef structName, )"; const char *fieldInfoOptional = R"( {0} {2}::{1}() const { - auto derived = this->cast(); + auto derived = this->cast<::mlir::DictionaryAttr>(); auto {1} = derived.get("{1}"); if (!{1}) return nullptr; diff --git a/mlir/unittests/TableGen/EnumsGenTest.cpp b/mlir/unittests/TableGen/EnumsGenTest.cpp index 0c3db73..47f0910 100644 --- a/mlir/unittests/TableGen/EnumsGenTest.cpp +++ b/mlir/unittests/TableGen/EnumsGenTest.cpp @@ -6,9 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "mlir/Support/LLVM.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "gmock/gmock.h"