// are generated, with the following signatures:
//
// ```c++
- // static void build(Builder* builder, OperationState* result,
+ // static void build(Builder *, OperationState *tblgen_state,
// Type <result0-name>, Type <result1-name>, ...,
// Value <arg0-name>, Value <arg1-name>, ...,
// Attribute <attr0-name>, Attribute <attr1-name>, ...);
// * where the attributes follow the same declaration order as in the op.
//
// ```c++
- // static void build(Builder* builder, OperationState* result,
+ // static void build(Builder *, OperationState *tblgen_state,
// ArrayRef<Type> resultTypes,
// ArrayRef<Value> operands,
// ArrayRef<NamedAttribute> attributes);
// CHECK-LABEL: MixOperandsAndAttrs definitions
// CHECK-DAG: Value *MixOperandsAndAttrs::operand()
// CHECK-DAG: Value *MixOperandsAndAttrs::otherArg()
-// CHECK-DAG: void MixOperandsAndAttrs::build(Builder *builder, OperationState *result, FloatAttr attr, Value *operand, FloatAttr otherAttr, Value *otherArg)
+// CHECK-DAG: void MixOperandsAndAttrs::build(Builder *, OperationState *tblgen_state, FloatAttr attr, Value *operand, FloatAttr otherAttr, Value *otherArg)
// CHECK-DAG: APFloat MixOperandsAndAttrs::attr()
// CHECK-DAG: APFloat MixOperandsAndAttrs::otherAttr()
}
// CHECK-LABEL: OpWithArgs definitions
-// CHECK-DAG: void OpWithArgs::build(Builder *builder, OperationState *result, Value *x, FloatAttr attr, /*optional*/FloatAttr optAttr)
+// CHECK-DAG: void OpWithArgs::build(Builder *, OperationState *tblgen_state, Value *x, FloatAttr attr, /*optional*/FloatAttr optAttr)
// CHECK-DAG: APFloat OpWithArgs::attr()
// CHECK-DAG: Optional< APFloat > OpWithArgs::optAttr()
// CHECK: APInt attr1();
// CHECK: Optional< APFloat > attr2();
// CHECK: static void build(Value *val);
-// CHECK: static void build(Builder *builder, OperationState *result, Type r, ArrayRef<Type> s, Value *a, ArrayRef<Value *> b, IntegerAttr attr1, /*optional*/FloatAttr attr2);
-// CHECK: static void build(Builder *builder, OperationState *result, ArrayRef<Type> resultTypes, ArrayRef<Value *> args, ArrayRef<NamedAttribute> attributes);
+// CHECK: static void build(Builder *, OperationState *tblgen_state, Type r, ArrayRef<Type> s, Value *a, ArrayRef<Value *> b, IntegerAttr attr1, /*optional*/FloatAttr attr2);
+// CHECK: static void build(Builder *, OperationState *tblgen_state, ArrayRef<Type> resultTypes, ArrayRef<Value *> operands, ArrayRef<NamedAttribute> attributes);
// CHECK: static bool parse(OpAsmParser *parser, OperationState *result);
// CHECK: void print(OpAsmPrinter *p);
// CHECK: bool verify();
}
// CHECK-LABEL: OneOperandOp definitions
+
+// CHECK: void OneOperandOp::build
+// CHECK-SAME: Value *input
+// CHECK: tblgen_state->addOperands({input});
+
+// CHECK: void OneOperandOp::build
+// CHECK-SAME: ArrayRef<Value *> operands
+// CHECK: assert(operands.size() == 1u && "mismatched number of parameters");
+// CHECK: tblgen_state->addOperands(operands);
+
// CHECK: bool OneOperandOp::verify() {
// CHECK: if (!((this->getOperation()->getOperand(0)->getType().isInteger(32))))
// CHECK-NEXT: return emitOpError("operand #0 must be 32-bit integer");
}
// CHECK-LABEL: SameTypeOp definitions
-// CHECK: void SameTypeOp::build(Builder *builder, OperationState *result, Type y, Value *x)
-// CHECK: result->addTypes({y});
-// CHECK: void SameTypeOp::build(Builder *builder, OperationState *result, Value *x)
-// CHECK: result->addTypes({x->getType()});
+// CHECK: void SameTypeOp::build(Builder *, OperationState *tblgen_state, Type y, Value *x)
+// CHECK: tblgen_state->addTypes({y});
+// CHECK: void SameTypeOp::build(Builder *, OperationState *tblgen_state, Value *x)
+// CHECK: tblgen_state->addTypes({x->getType()});
def ThreeResultOp : Op<"three_result_op", []> {
let results = (outs I32:$x, /*unnamed*/I32, I32:$z);
}
// CHECK-LABEL: ThreeResultOp definitions
-// CHECK: void ThreeResultOp::build(Builder *builder, OperationState *result, Type x, Type resultType1, Type z)
-// CHECK: result->addTypes({x, resultType1, z});
+// CHECK: void ThreeResultOp::build(Builder *, OperationState *tblgen_state, Type x, Type resultType1, Type z)
+// CHECK: tblgen_state->addTypes({x, resultType1, z});
def IntegerTypeAttr : TypeAttrBase<"IntegerType", "Integer type attribute">;
def TypeAttrResultTypeOp : Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> {
}
// CHECK-LABEL: TypeAttrResultTypeOp definitions
-// CHECK: void TypeAttrResultTypeOp::build(Builder *builder, OperationState *result, Value *x, TypeAttr attr, FloatAttr f32)
-// CHECK: result->addTypes({attr.getValue()});
+// CHECK: void TypeAttrResultTypeOp::build(Builder *, OperationState *tblgen_state, Value *x, TypeAttr attr, FloatAttr f32)
+// CHECK: tblgen_state->addTypes({attr.getValue()});
def ValueAttrResultTypeOp : Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
let arguments = (ins I32:$x, F32Attr:$attr);
}
// CHECK-LABEL: ValueAttrResultTypeOp definitions
-// CHECK: void ValueAttrResultTypeOp::build(Builder *builder, OperationState *result, Value *x, FloatAttr attr)
-// CHECK: result->addTypes({attr.getType()});
+// CHECK: void ValueAttrResultTypeOp::build(Builder *, OperationState *tblgen_state, Value *x, FloatAttr attr)
+// CHECK: tblgen_state->addTypes({attr.getType()});
def VariadicResultOp : Op<"variadic_op", []> {
let results = (outs I32:$x, Variadic<I32>:$y);
}
// CHECK-LABEL: VariadicResultOp definitions
-// CHECK: void VariadicResultOp::build(Builder *builder, OperationState *result, Type x, ArrayRef<Type> y)
-// CHECK: result->addTypes({x});
-// CHECK: result->addTypes(y);
+// CHECK: void VariadicResultOp::build(Builder *, OperationState *tblgen_state, Type x, ArrayRef<Type> y)
+// CHECK: tblgen_state->addTypes({x});
+// CHECK: tblgen_state->addTypes(y);
using mlir::tblgen::Operator;
+static const char *const builderOpState = "tblgen_state";
static const char *const generatedArgName = "_arg";
static const char *const opCommentHeader = R"(
llvm::SmallVector<std::string, 4> resultNames;
resultNames.reserve(numResults);
- std::string paramList = "Builder *builder, OperationState *result";
+ std::string paramList = "Builder *, OperationState *";
+ paramList.append(builderOpState);
// Emit parameters for all return types
if (!useOperandType && !useAttrType) {
numResults - static_cast<int>(hasVariadicResult);
if (numNonVariadicResults > 0) {
- method.body() << " result->addTypes({" << resultNames.front();
+ method.body() << " " << builderOpState << "->addTypes({"
+ << resultNames.front();
for (int i = 1; i < numNonVariadicResults; ++i) {
method.body() << ", " << resultNames[i];
}
}
if (hasVariadicResult) {
- method.body() << " result->addTypes(" << resultNames.back() << ");\n";
+ method.body() << " " << builderOpState << "->addTypes("
+ << resultNames.back() << ");\n";
}
} else {
std::string resultType;
} else {
resultType = formatv("{0}->getType()", getArgumentName(op, 0)).str();
}
- method.body() << " result->addTypes({" << resultType;
+ method.body() << " " << builderOpState << "->addTypes({" << resultType;
for (unsigned i = 1; i != numResults; ++i)
method.body() << ", " << resultType;
method.body() << "});\n\n";
int numNonVariadicOperands =
numOperands - static_cast<int>(hasVariadicOperand);
if (numNonVariadicOperands > 0) {
- method.body() << " result->addOperands({" << getArgumentName(op, 0);
+ method.body() << " " << builderOpState << "->addOperands({"
+ << getArgumentName(op, 0);
for (int i = 1; i < numNonVariadicOperands; ++i) {
method.body() << ", " << getArgumentName(op, i);
}
method.body() << "});\n";
}
if (hasVariadicOperand) {
- method.body() << " result->addOperands("
+ method.body() << " " << builderOpState << "->addOperands("
<< getArgumentName(op, numOperands - 1) << ");\n";
}
if (emitNotNullCheck) {
method.body() << formatv(" if ({0}) ", namedAttr.name) << "{\n";
}
- method.body() << formatv(" result->addAttribute(\"{0}\", {1});\n",
- namedAttr.getName(), namedAttr.name);
+ method.body() << formatv(" {0}->addAttribute(\"{1}\", {2});\n",
+ builderOpState, namedAttr.getName(),
+ namedAttr.name);
if (emitNotNullCheck) {
method.body() << " }\n";
}
// 2. Aggregated parameters
// Signature
- const char *const params =
- "Builder *builder, OperationState *result, ArrayRef<Type> resultTypes, "
- "ArrayRef<Value *> args, ArrayRef<NamedAttribute> attributes";
+ std::string params =
+ std::string("Builder *, OperationState *") + builderOpState +
+ ", ArrayRef<Type> resultTypes, ArrayRef<Value *> operands, "
+ "ArrayRef<NamedAttribute> attributes";
auto &method =
opClass.newMethod("void", "build", params, OpMethod::MP_Static);
<< (hasVariadicResult ? " >= " : " == ")
<< numNonVariadicResults
<< "u && \"mismatched number of return types\");\n"
- << " result->addTypes(resultTypes);\n";
+ << " " << builderOpState << "->addTypes(resultTypes);\n";
// Operands
- method.body() << " assert(args.size()"
+ method.body() << " assert(operands.size()"
<< (hasVariadicOperand ? " >= " : " == ")
<< numNonVariadicOperands
<< "u && \"mismatched number of parameters\");\n"
- << " result->addOperands(args);\n\n";
+ << " " << builderOpState << "->addOperands(operands);\n\n";
// Attributes
if (op.getNumAttributes() > 0) {
} else {
method.body() << " assert(attributes.size() >= " << op.getNumAttributes()
<< "u && \"not enough attributes\");\n"
- << " for (const auto& pair : attributes)\n"
- << " result->addAttribute(pair.first, pair.second);\n";
+ << " for (const auto& pair : attributes)\n"
+ << " " << builderOpState
+ << "->addAttribute(pair.first, pair.second);\n";
}
// 3. Deduced result types