brintos

brintos / llvm-project-archived public Read only

0
0
Text · 38.0 KiB · 0e87373 Raw
554 lines · plain
1// RUN: mlir-tblgen -gen-op-decls -I %S/../../include %s | FileCheck %s2// RUN: mlir-tblgen -gen-op-decls -op-include-regex="test.a_op" -I %S/../../include %s | FileCheck  %s --check-prefix=REDUCE_INC3// RUN: mlir-tblgen -gen-op-decls -op-exclude-regex="test.a_op" -I %S/../../include %s | FileCheck  %s --check-prefix=REDUCE_EXC4 5// RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEFS6 7include "mlir/IR/AttrTypeBase.td"8include "mlir/IR/OpBase.td"9include "mlir/Interfaces/InferTypeOpInterface.td"10include "mlir/Interfaces/SideEffectInterfaces.td"11 12def Test_Dialect : Dialect {13  let name = "test";14  let cppNamespace = "NS";15}16class NS_Op<string mnemonic, list<Trait> traits> :17    Op<Test_Dialect, mnemonic, traits>;18 19// IsolatedFromAbove trait is included twice to ensure it gets uniqued during20// emission.21def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {22  let arguments = (ins23    I32:$a,24    Variadic<F32>:$b,25 26    I32Attr:$attr1,27    OptionalAttr<F32Attr>:$some_attr228  );29 30  let results = (outs31    I32:$r,32    Variadic<F32>:$s33  );34 35  let regions = (region36    AnyRegion:$someRegion,37    VariadicRegion<AnyRegion>:$someRegions38  );39  let builders = [OpBuilder<(ins "Value":$val)>,40                  OpBuilder<(ins CArg<"int", "0">:$integer)>,41                  DeprecatedOpBuilder<"the deprecation message",42                            (ins "float":$something)>];43  let hasCustomAssemblyFormat = 1;44 45  let hasCanonicalizer = 1;46  let hasFolder = 1;47  let hasVerifier = 1;48 49  let extraClassDeclaration = [{50    // Display a graph for debugging purposes.51    void displayGraph();52  }];53}54 55// CHECK-LABEL: NS::AOp declarations56 57// CHECK: namespace detail {58// CHECK: class AOpGenericAdaptorBase {59// CHECK: public:60// CHECK:   AOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions)61// CHECK:   AOpGenericAdaptorBase(AOp op);62// CHECK:   ::mlir::IntegerAttr getAttr1Attr() {63// CHECK:   uint32_t getAttr1();64// CHECK:   ::mlir::FloatAttr getSomeAttr2Attr() {65// CHECK:   ::std::optional< ::llvm::APFloat > getSomeAttr2();66// CHECK:   ::mlir::Region &getSomeRegion() {67// CHECK:   ::mlir::RegionRange getSomeRegions() {68// CHECK-NEXT:     return odsRegions.drop_front(1);69// CHECK:   ::mlir::RegionRange getRegions() {70// CHECK-NEXT:     return odsRegions;71// CHECK: };72// CHECK: }73 74// CHECK: template <typename RangeT>75// CHECK: class AOpGenericAdaptor : public detail::AOpGenericAdaptorBase {76// CHECK: public:77// CHECK:   AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}78// CHECK:   AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {}79// CHECK:   AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : AOpGenericAdaptor(values, attrs, Properties{}, {}) {}80// CHECK:   AOpGenericAdaptor(RangeT values, const AOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}81// CHECK:   RangeT getODSOperands(unsigned index) {82// CHECK:   ValueT getA() {83// CHECK:   RangeT getB() {84// CHECK: private:85// CHECK:   RangeT odsOperands;86// CHECK: };87 88// CHECK: class AOpAdaptor : public AOpGenericAdaptor<::mlir::ValueRange> {89// CHECK: public:90// CHECK:   AOpAdaptor(AOp91// CHECK:   ::llvm::LogicalResult verify(92// CHECK: };93 94// CHECK: class AOp : public ::mlir::Op<AOp, ::mlir::OpTrait::AtLeastNRegions<1>::Impl, ::mlir::OpTrait::AtLeastNResults<1>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::AtLeastNOperands<1>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::OpTrait::IsIsolatedFromAbove95// CHECK-NOT: ::mlir::OpTrait::IsIsolatedFromAbove96// CHECK: public:97// CHECK:   using Op::Op;98// CHECK:   using Adaptor = AOpAdaptor;99// CHECK:   static constexpr ::llvm::StringLiteral getOperationName() {100// CHECK:     return ::llvm::StringLiteral("test.a_op");101// CHECK:   }102// CHECK:   ::mlir::Operation::operand_range getODSOperands(unsigned index) {103// CHECK:   ::mlir::TypedValue<::mlir::IntegerType> getA() {104// CHECK:   ::mlir::Operation::operand_range getB() {105// CHECK:   ::mlir::OpOperand &getAMutable() {106// CHECK:   ::mlir::MutableOperandRange getBMutable();107// CHECK:   ::mlir::Operation::result_range getODSResults(unsigned index) {108// CHECK:   ::mlir::TypedValue<::mlir::IntegerType> getR() {109// CHECK:   ::mlir::Region &getSomeRegion() {110// CHECK:   ::mlir::MutableArrayRef<::mlir::Region> getSomeRegions() {111// CHECK:   ::mlir::IntegerAttr getAttr1Attr() {112// CHECK:   uint32_t getAttr1();113// CHECK:   ::mlir::FloatAttr getSomeAttr2Attr() {114// CHECK:   ::std::optional< ::llvm::APFloat > getSomeAttr2();115// CHECK:   ::mlir::Attribute removeSomeAttr2Attr() {116// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value val);117// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, Value val);118// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, Value val);119// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, int integer = 0);120// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, int integer = 0);121// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, int integer = 0);122// CHECK{LITERAL}:   [[deprecated("the deprecation message")]]123// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, float something);124// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, float something);125// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, float something);126// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)127// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)128// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)129// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);130// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);131// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);132// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)133// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)134// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)135// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);136// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);137// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);138// CHECK:   static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions)139// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions)140// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions)141// CHECK:   static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions)142// CHECK:   static AOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions)143// CHECK:   static AOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions)144// CHECK:   static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);145// CHECK:   void print(::mlir::OpAsmPrinter &p);146// CHECK:   ::llvm::LogicalResult verifyInvariants();147// CHECK:   static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context);148// CHECK:   ::llvm::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results);149// CHECK:   static ::llvm::LogicalResult setPropertiesFromParsedAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError);150// CHECK:   // Display a graph for debugging purposes.151// CHECK:   void displayGraph();152// CHECK: };153 154// DEFS-LABEL: NS::AOp definitions155 156// Check that `getAttrDictionary()` is used when not using properties.157 158// Check AttrSizedOperandSegments159// ---160 161def NS_AttrSizedOperandOp : NS_Op<"attr_sized_operands",162                                 [AttrSizedOperandSegments]> {163  let arguments = (ins164    Variadic<I32>:$a,165    Variadic<I32>:$b,166    I32:$c,167    Variadic<I32>:$d168  );169}170 171// CHECK-LABEL: class AttrSizedOperandOpGenericAdaptorBase {172// CHECK: ::llvm::ArrayRef<int32_t> getOperandSegmentSizes() const173 174// CHECK-LABEL: AttrSizedOperandOpGenericAdaptor(175// CHECK-SAME:    RangeT values176// CHECK-SAME:    ::mlir::DictionaryAttr attrs177// CHECK:  RangeT getA() {178// CHECK:  RangeT getB() {179// CHECK:  ValueT getC() {180// CHECK:  RangeT getD() {181 182// Check op trait for different number of operands183// ---184 185def NS_BOp : NS_Op<"op_with_no_operand", []> {186  let arguments = (ins);187}188 189// CHECK-LABEL: NS::BOp declarations190// CHECK: OpTrait::ZeroOperands191 192def NS_COp : NS_Op<"op_with_one_operand", []> {193  let arguments = (ins I32:$operand);194}195 196// CHECK-LABEL: NS::COp declarations197// CHECK: OpTrait::OneOperand198 199def NS_DOp : NS_Op<"op_with_two_operands", []> {200  let arguments = (ins I32:$input1, I32:$input2);201}202 203// CHECK-LABEL: NS::DOp declarations204// CHECK: OpTrait::NOperands<2>::Impl205 206def NS_EOp : NS_Op<"op_with_optionals", []> {207  let arguments = (ins Optional<I32>:$a);208  let results = (outs Optional<F32>:$b);209}210 211// CHECK-LABEL: NS::EOp declarations212// CHECK:   ::mlir::TypedValue<::mlir::IntegerType> getA() {213// CHECK:   ::mlir::MutableOperandRange getAMutable();214// CHECK:   ::mlir::TypedValue<::mlir::FloatType> getB() {215// CHECK:   static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/::mlir::Type b, /*optional*/::mlir::Value a)216// CHECK:   static EOp create(::mlir::OpBuilder &builder, ::mlir::Location location, /*optional*/::mlir::Type b, /*optional*/::mlir::Value a)217// CHECK:   static EOp create(::mlir::ImplicitLocOpBuilder &builder, /*optional*/::mlir::Type b, /*optional*/::mlir::Value a)218 219// Check that all types match constraint results in generating builder.220// ---221 222def NS_FOp : NS_Op<"op_with_all_types_constraint",223    [AllTypesMatch<["a", "b"]>]> {224  let arguments = (ins AnyType:$a);225  let results = (outs Res<AnyType, "output b", []>:$b);226}227 228// CHECK-LABEL: class FOp :229// CHECK: static ::llvm::LogicalResult inferReturnTypes230 231// DEFS: void FOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a) {232// DEFS:   if (::mlir::succeeded(FOp::inferReturnTypes(odsBuilder.getContext(),233// DEFS:   else234// DEFS:     ::mlir::detail::reportFatalInferReturnTypesError(odsState);235 236// DEFS: FOp FOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a) {237// DEFS:   ::mlir::OperationState __state__(location, getOperationName());238// DEFS:   build(builder, __state__, a);239// DEFS:   auto __res__ = ::llvm::dyn_cast<FOp>(builder.create(__state__));240// DEFS:   assert(__res__ && "builder didn't return the right type");241// DEFS:   return __res__;242// DEFS: }243 244// DEFS: FOp FOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value a) {245// DEFS:   return create(builder, builder.getLoc(), a);246// DEFS: }247 248def NS_GOp : NS_Op<"op_with_fixed_return_type", []> {249  let arguments = (ins AnyType:$a);250  let results = (outs I32:$b);251}252 253// CHECK-LABEL: class GOp :254// CHECK: static ::llvm::LogicalResult inferReturnTypes255 256// Check default value for collective params builder. Check that other builders257// are generated as well.258def NS_HCollectiveParamsOp : NS_Op<"op_collective_params", []> {259  let arguments = (ins AnyType:$a);260  let results = (outs AnyType:$b);261}262 263// CHECK-LABEL: class HCollectiveParamsOp :264// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type b, ::mlir::Value a);265// CHECK: static HCollectiveParamsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type b, ::mlir::Value a);266// CHECK: static HCollectiveParamsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type b, ::mlir::Value a);267// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a);268// CHECK: static HCollectiveParamsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a);269// CHECK: static HCollectiveParamsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a);270// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {})271// CHECK: static HCollectiveParamsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {})272// CHECK: static HCollectiveParamsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {})273// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {})274// CHECK: static HCollectiveParamsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {})275// CHECK: static HCollectiveParamsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {})276 277// Check suppression of "separate arg, separate result" build method for an op278// with single variadic arg and single variadic result (since it will be279// ambiguous with the collective params build method).280def NS_HCollectiveParamsSuppress0Op : NS_Op<"op_collective_suppress0", []> {281  let arguments = (ins Variadic<I32>:$a);282  let results = (outs Variadic<I32>:$b);283}284 285// CHECK-LABEL: class HCollectiveParamsSuppress0Op :286// CHECK-NOT: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange b, ::mlir::ValueRange a);287// CHECK-NOT: static HCollectiveParamsSuppress0Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange b, ::mlir::ValueRange a);288// CHECK-NOT: static HCollectiveParamsSuppress0Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange b, ::mlir::ValueRange a);289// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});290// CHECK: static HCollectiveParamsSuppress0Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});291// CHECK: static HCollectiveParamsSuppress0Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});292 293// Check suppression of "separate arg, collective result" build method for an op294// with single variadic arg and non variadic result (since it will be295// ambiguous with the collective params build method).296def NS_HCollectiveParamsSuppress1Op : NS_Op<"op_collective_suppress1", []> {297  let arguments = (ins Variadic<I32>:$a);298  let results = (outs I32:$b);299}300 301// CHECK-LABEL: class HCollectiveParamsSuppress1Op :302// CHECK-NOT: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange b, ::mlir::ValueRange a);303// CHECK-NOT: static HCollectiveParamsSuppress1Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange b, ::mlir::ValueRange a);304// CHECK-NOT: static HCollectiveParamsSuppress1Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange b, ::mlir::ValueRange a);305// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});306// CHECK: static HCollectiveParamsSuppress1Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});307// CHECK: static HCollectiveParamsSuppress1Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});308 309// Check suppression of "separate arg, collective result" build method for an op310// with single variadic arg and > 1 variadic result (since it will be311// ambiguous with the collective params build method). Note that "separate arg,312// separate result" build method should be generated in this case as its not313// ambiguous with the collective params build method.314def NS_HCollectiveParamsSuppress2Op : NS_Op<"op_collective_suppress2", [SameVariadicResultSize]> {315  let arguments = (ins Variadic<I32>:$a);316  let results = (outs Variadic<I32>:$b, Variadic<F32>:$c);317}318// CHECK-LABEL: class HCollectiveParamsSuppress2Op :319// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange b, ::mlir::TypeRange c, ::mlir::ValueRange a);320// CHECK: static HCollectiveParamsSuppress2Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange b, ::mlir::TypeRange c, ::mlir::ValueRange a);321// CHECK: static HCollectiveParamsSuppress2Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange b, ::mlir::TypeRange c, ::mlir::ValueRange a);322// CHECK-NOT: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange b, ::mlir::ValueRange a);323// CHECK-NOT: static HCollectiveParamsSuppress2Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange b, ::mlir::ValueRange a);324// CHECK-NOT: static HCollectiveParamsSuppress2Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange b, ::mlir::ValueRange a);325// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});326// CHECK: static HCollectiveParamsSuppress2Op create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});327// CHECK: static HCollectiveParamsSuppress2Op create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});328 329// Check default value of `attributes` for the `genUseOperandAsResultTypeCollectiveParamBuilder` builder330def NS_IOp : NS_Op<"op_with_same_operands_and_result_types_trait", [SameOperandsAndResultType]> {331  let arguments = (ins AnyType:$a, AnyType:$b);332  let results = (outs AnyType:$r);333}334// CHECK-LABEL: class IOp :335// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b);336// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b);337// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b);338 339// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a, ::mlir::Value b);340// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a, ::mlir::Value b);341// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value a, ::mlir::Value b);342 343// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);344// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);345// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);346 347// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});348// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});349// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});350 351// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});352// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});353// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});354 355// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});356// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});357// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});358 359// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});360// CHECK: static IOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});361// CHECK: static IOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});362 363// Check default value of `attributes` for the `genInferredTypeCollectiveParamBuilder` builder364def NS_JOp : NS_Op<"op_with_InferTypeOpInterface_interface", [DeclareOpInterfaceMethods<InferTypeOpInterface>]> {365  let arguments = (ins AnyType:$a, AnyType:$b);366  let results = (outs AnyType:$r);367}368// CHECK-LABEL: class JOp :369// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b);370// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b);371// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b);372 373// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a, ::mlir::Value b);374// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a, ::mlir::Value b);375// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value a, ::mlir::Value b);376 377// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);378// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);379// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);380 381// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});382// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});383// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});384 385// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});386// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});387// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});388 389// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});390// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});391// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});392 393// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});394// CHECK: static JOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});395// CHECK: static JOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});396 397// Test usage of TraitList getting flattened during emission.398def NS_KOp : NS_Op<"k_op", [IsolatedFromAbove,399    TraitList<[DeclareOpInterfaceMethods<InferTypeOpInterface>]>]> {400  let arguments = (ins AnyType:$a, AnyType:$b);401}402 403// CHECK: class KOp : public ::mlir::Op<KOp,404// CHECK-SAME: ::mlir::OpTrait::IsIsolatedFromAbove, ::mlir::InferTypeOpInterface::Trait405 406// Check native OpTrait usage407// ---408 409def NS_TestTrait : NativeOpTrait<"TestTrait"> {410    let cppNamespace = "SomeNamespace";411}412 413def NS_KWithTraitOp : NS_Op<"KWithTrait", [NS_TestTrait]>;414 415// CHECK-LABEL: NS::KWithTraitOp declarations416// CHECK:       class KWithTraitOp : public ::mlir::Op<KWithTraitOp417// CHECK-SAME:      SomeNamespace::TestTrait418 419def NS_LOp : NS_Op<"op_with_same_operands_and_result_types_unwrapped_attr", [SameOperandsAndResultType]> {420  let arguments = (ins AnyType:$a, AnyType:$b, I32Attr:$attr1);421  let results = (outs AnyType:$r);422}423// CHECK-LABEL: class LOp :424// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);425// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);426// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);427 428// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);429// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);430// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);431 432// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);433// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);434// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, ::mlir::IntegerAttr attr1);435 436// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);437// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);438// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);439 440// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);441// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);442// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);443 444// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);445// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);446// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);447 448// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});449// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});450// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});451 452// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});453// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});454// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});455 456// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});457// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});458// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});459 460// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});461// CHECK: static LOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});462// CHECK: static LOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});463 464def NS_MOp : NS_Op<"op_with_single_result_and_fold_adaptor_fold", []> {465  let results = (outs AnyType:$res);466 467  let hasFolder = 1;468}469 470// CHECK-LABEL: class MOp :471// CHECK: ::mlir::OpFoldResult fold(FoldAdaptor adaptor);472 473def NS_NOp : NS_Op<"op_with_properties", []> {474  let arguments = (ins Property<"unsigned">:$value);475}476 477// DEFS: NOpGenericAdaptorBase::NOpGenericAdaptorBase(NOp op) :478// DEFS-SAME: odsAttrs(op->getRawDictionaryAttrs())479// DEFS-SAME: odsOpName(op->getName())480// DEFS-SAME: properties(op.getProperties())481// DEFS-SAME: odsRegions(op->getRegions())482 483// Test that type defs have the proper namespaces when used as a constraint.484// ---485 486def Test_Dialect2 : Dialect {487  let name = "test";488  let cppNamespace = "::mlir::dialect2";489}490def TestDialect2Type : TypeDef<Test_Dialect2, "Dialect2Type"> {491  let typeName = "test.type";492}493 494def NS_ResultWithDialectTypeOp : NS_Op<"op_with_dialect_type", []> {495  let results = (outs TestDialect2Type);496}497 498// CHECK-LABEL: NS::ResultWithDialectTypeOp declarations499// CHECK:     class ResultWithDialectTypeOp :500// CHECK-SAME: ::mlir::OpTrait::OneTypedResult<::mlir::dialect2::Dialect2TypeType>501 502// Check that default builders can be suppressed.503// ---504 505def NS_SkipDefaultBuildersOp : NS_Op<"skip_default_builders", []> {506  let skipDefaultBuilders = 1;507  let builders = [OpBuilder<(ins "Value":$val)>];508}509 510// CHECK-LABEL: NS::SkipDefaultBuildersOp declarations511// CHECK:     class SkipDefaultBuildersOp512// CHECK-NOT:   static void build(::mlir::Builder513// CHECK:       static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value514 515// Check leading underscore in op name516// ---517 518def NS_VarOfVarOperandOp : NS_Op<"var_of_var_operand", []> {519  let arguments = (ins520    VariadicOfVariadic<F32, "var_size">:$var_of_var_attr,521    DenseI32ArrayAttr:$var_size522  );523}524 525// CHECK-LABEL: class VarOfVarOperandOpGenericAdaptor526// CHECK: public:527// CHECK: ::llvm::SmallVector<RangeT> getVarOfVarAttr() {528 529 530def NS__AOp : NS_Op<"_op_with_leading_underscore", []>;531 532// CHECK-LABEL: NS::_AOp declarations533// CHECK: class _AOp : public ::mlir::Op<_AOp534 535def _BOp : NS_Op<"_op_with_leading_underscore_and_no_namespace", []>;536 537// CHECK-LABEL: _BOp declarations538// CHECK: class _BOp : public ::mlir::Op<_BOp539 540// REDUCE_INC-LABEL: NS::AOp declarations541// REDUCE_INC-NOT: NS::BOp declarations542 543// REDUCE_EXC-NOT: NS::AOp declarations544// REDUCE_EXC-LABEL: NS::BOp declarations545 546// CHECK-LABEL: _TypeInferredPropOp declarations547def _TypeInferredPropOp : NS_Op<"type_inferred_prop_op_with_properties", [548    AllTypesMatch<["value", "result"]>549  ]> {550  let arguments = (ins Property<"unsigned">:$prop, AnyType:$value);551  let results = (outs AnyType:$result);552  let hasCustomAssemblyFormat = 1;553}554