Skip to content

Commit 81abf9c

Browse files
committed
update irdl-to-cpp
1 parent 82bdd13 commit 81abf9c

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ static void generateOpBuilderDeclarations(irdl::detail::dictionary &dict,
226226
stream << llvm::formatv(
227227
R"(static void build(::mlir::OpBuilder &opBuilder, ::mlir::OperationState &opState, {0} {1} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
228228
resultParams, operandParams);
229+
stream << "\n";
230+
stream << llvm::formatv(
231+
R"(static {0} create(::mlir::OpBuilder &opBuilder, ::mlir::Location location, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
232+
opStrings.opCppName, resultParams, operandParams);
233+
stream << "\n";
234+
stream << llvm::formatv(
235+
R"(static {0} create(::mlir::ImplicitLocOpBuilder &opBuilder, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
236+
opStrings.opCppName, resultParams, operandParams);
237+
stream << "\n";
229238
dict["OP_BUILD_DECLS"] = buildDecls;
230239
}
231240

@@ -339,9 +348,25 @@ void {0}::build(::mlir::OpBuilder &opBuilder, ::mlir::OperationState &opState, {
339348
{3}
340349
{4}
341350
}
351+
352+
{0} {0}::create(::mlir::OpBuilder &opBuilder, ::mlir::Location location, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
353+
::mlir::OperationState __state__(location, getOperationName());
354+
build(opBuilder, __state__, {5} {6} attributes);
355+
auto __res__ = ::llvm::dyn_cast<{0}>(opBuilder.create(__state__));
356+
assert(__res__ && "builder didn't return the right type");
357+
return __res__;
358+
}
359+
360+
{0} {0}::create(::mlir::ImplicitLocOpBuilder &opBuilder, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
361+
return create(opBuilder, opBuilder.getLoc(), {5} {6} attributes);
362+
}
342363
)",
343364
opStrings.opCppName, std::move(resultTypes), std::move(operandTypes),
344-
std::move(operandAdder), std::move(resultAdder));
365+
std::move(operandAdder), std::move(resultAdder),
366+
llvm::join(opStrings.opResultNames, ",") +
367+
(!opStrings.opResultNames.empty() ? "," : ""),
368+
llvm::join(opStrings.opOperandNames, ",") +
369+
(!opStrings.opOperandNames.empty() ? "," : ""));
345370

346371
dict["OP_BUILD_DEFS"] = buildDefinition;
347372

mlir/lib/Target/IRDLToCpp/Templates/PerOperationDecl.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ public:
175175
::mlir::TypeRange resultTypes,
176176
::mlir::ValueRange operands,
177177
::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
178+
179+
static __OP_CPP_NAME__ create(::mlir::OpBuilder &odsBuilder,
180+
::mlir::Location location,
181+
::mlir::TypeRange resultTypes,
182+
::mlir::ValueRange operands,
183+
::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
184+
185+
static __OP_CPP_NAME__ create(::mlir::ImplicitLocOpBuilder &odsBuilder,
186+
::mlir::TypeRange resultTypes,
187+
::mlir::ValueRange operands,
188+
::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
178189
};
179190

180191

mlir/lib/Target/IRDLToCpp/Templates/PerOperationDef.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ void __OP_CPP_NAME__::build(::mlir::OpBuilder &odsBuilder,
2121
odsState.addTypes(resultTypes);
2222
}
2323

24+
__OP_CPP_NAME__
25+
__OP_CPP_NAME__::create(::mlir::OpBuilder &odsBuilder,
26+
::mlir::Location location,
27+
::mlir::TypeRange resultTypes,
28+
::mlir::ValueRange operands,
29+
::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
30+
{
31+
::mlir::OperationState state(location, getOperationName());
32+
build(odsBuilder, state, resultTypes, operands, attributes);
33+
auto res = ::llvm::dyn_cast<__OP_CPP_NAME__>(odsBuilder.create(state));
34+
assert(res && "builder didn't return the right type");
35+
return res;
36+
}
37+
38+
__OP_CPP_NAME__
39+
__OP_CPP_NAME__::create(::mlir::ImplicitLocOpBuilder &odsBuilder,
40+
::mlir::TypeRange resultTypes,
41+
::mlir::ValueRange operands,
42+
::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
43+
{
44+
return create(odsBuilder, odsBuilder.getLoc(), resultTypes, operands, attributes);
45+
}
46+
2447

2548
__NAMESPACE_CLOSE__
2649

0 commit comments

Comments
 (0)