Skip to content

Commit

Permalink
Op's create methods support passing an instruction name
Browse files Browse the repository at this point in the history
Equivalent to CallInst, for more readable code. This allows to pass in a value
name without a call to setName which is especially useful when directly
returning a create op.

For example:

  return m_builder->create<ExampleOp>(m_builder->getInt32(123), "example_123");
  • Loading branch information
JanRehders-AMD committed Jan 30, 2024
1 parent 69e114f commit fe5bfe4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void BuilderMethod::emitDeclaration(raw_ostream &out, FmtContext &fmt) const {
for (const auto &builderArg : m_arguments) {
out << ", " << builderArg.cppType << " " << builderArg.name;
}
out << ");\n";
out << ", const llvm::Twine &instName = \"\");\n";
}

void BuilderMethod::emitDefinition(raw_ostream &out, FmtContext &fmt,
Expand All @@ -572,7 +572,7 @@ void BuilderMethod::emitDefinition(raw_ostream &out, FmtContext &fmt,
for (const auto &builderArg : m_arguments)
out << tgfmt(", $0 $1", &fmt, builderArg.cppType, builderArg.name);

out << tgfmt(R"() {
out << tgfmt(R"(, const llvm::Twine &instName) {
::llvm::LLVMContext& $_context = $_builder.getContext();
(void)$_context;
::llvm::Module& $_module = *$_builder.GetInsertBlock()->getModule();
Expand Down Expand Up @@ -711,11 +711,11 @@ void BuilderMethod::emitDefinition(raw_ostream &out, FmtContext &fmt,
out << tgfmt(R"(
};
$varArgInitializer
return ::llvm::cast<$_op>($_builder.CreateCall($fn, $args));
return ::llvm::cast<$_op>($_builder.CreateCall($fn, $args, instName));
)",
&fmt);
} else {
out << tgfmt("return ::llvm::cast<$_op>($_builder.CreateCall($fn));\n",
out << tgfmt("return ::llvm::cast<$_op>($_builder.CreateCall($fn, std::nullopt, instName));\n",
&fmt);
}

Expand Down

0 comments on commit fe5bfe4

Please sign in to comment.