From 6bf2b0965d821bca65e2de993a54174a94a6e83d Mon Sep 17 00:00:00 2001 From: Thomas Symalla Date: Wed, 17 Jul 2024 14:42:08 +0200 Subject: [PATCH] Address review comments. --- example/ExampleMain.cpp | 2 +- lib/TableGen/Operations.cpp | 28 ++++++++----------- test/example/generated/ExampleDialect.cpp.inc | 8 +++--- test/example/generated/ExampleDialect.h.inc | 8 +++--- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/example/ExampleMain.cpp b/example/ExampleMain.cpp index 063fff1..bcae648 100644 --- a/example/ExampleMain.cpp +++ b/example/ExampleMain.cpp @@ -129,7 +129,7 @@ void createFunctionExample(Module &module, const Twine &name) { SmallVector varArgs2 = varArgs; varArgs2.push_back(p2); - replacable->replaceArgsAndInvalidate(b, varArgs2); + replacable->replaceArgs(varArgs2); b.create(FixedVectorType::get(b.getInt32Ty(), 2)); b.create(y6); diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index f4bdef0..93428ef 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -64,7 +64,7 @@ class AccessorBuilder final { : m_fmt{fmt}, m_os{out}, m_arg{arg}, m_argTypeString{argTypeString} {} void emitAccessorDefinitions() const; - void emitVarArgReplacementDefinition(const size_t numNonVarArgs) const; + void emitVarArgReplacementDefinition() const; private: FmtContext &m_fmt; @@ -171,8 +171,8 @@ void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out, } else { defaultDeclaration += R"( /// Returns a new op with the same arguments and a new tail argument list. - /// The object on which this is called will be invalidated. - $_op *replace$1AndInvalidate(::llvm_dialects::Builder &, ::llvm::ArrayRef); + /// The object on which this is called will be replaced and erased. + $_op *replace$1(::llvm::ArrayRef); )"; } } @@ -237,25 +237,22 @@ void AccessorBuilder::emitSetterDefinition() const { &m_fmt); } -void AccessorBuilder::emitVarArgReplacementDefinition( - const size_t numNonVarArgs) const { +void AccessorBuilder::emitVarArgReplacementDefinition() const { std::string toLlvm = m_arg.name; - m_fmt.addSubst("numNonVarargs", std::to_string(numNonVarArgs)); - m_os << tgfmt(R"( - $_op *$_op::replace$0AndInvalidate(::llvm_dialects::Builder &B, ::llvm::ArrayRef $1) { + $_op *$_op::replace$Name(::llvm::ArrayRef $name) { ::llvm::SmallVector newArgs; - if ($numNonVarargs > 0) - newArgs.append(arg_begin(), arg_begin() + $numNonVarargs); - newArgs.append($1.begin(), $1.end()); - $_op *newOp = cast<$_op>(B.CreateCall(getCalledFunction(), newArgs, this->getName())); + if ($index > 0) + newArgs.append(arg_begin(), arg_begin() + $index); + newArgs.append($name.begin(), $name.end()); + $_op *newOp = cast<$_op>(::llvm::CallInst::Create(getCalledFunction(), newArgs, ::std::nullopt, this->getName(), this->getIterator())); this->replaceAllUsesWith(newOp); this->eraseFromParent(); return newOp; })", - &m_fmt, convertToCamelFromSnakeCase(toLlvm, true), toLlvm); + &m_fmt); } void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out, @@ -264,7 +261,6 @@ void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out, if (m_superclass) numSuperclassArgs = m_superclass->getNumFullArguments(); - unsigned numArgs = 0; for (const auto &indexedArg : llvm::enumerate(m_arguments)) { FmtContextScope scope(fmt); @@ -279,9 +275,7 @@ void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out, builder.emitAccessorDefinitions(); if (!arg.type->isImmutable() && arg.type->isVarArgList()) - builder.emitVarArgReplacementDefinition(numArgs); - else - ++numArgs; + builder.emitVarArgReplacementDefinition(); } } diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 7ca78d2..43c25b3 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -1503,12 +1503,12 @@ instName value_op_iterator(arg_end())); } - InstNameConflictVarargsOp *InstNameConflictVarargsOp::replaceInstName_0AndInvalidate(::llvm_dialects::Builder &B, ::llvm::ArrayRef instName_0) { + InstNameConflictVarargsOp *InstNameConflictVarargsOp::replaceInstName_0(::llvm::ArrayRef instName_0) { ::llvm::SmallVector newArgs; if (0 > 0) newArgs.append(arg_begin(), arg_begin() + 0); newArgs.append(instName_0.begin(), instName_0.end()); - InstNameConflictVarargsOp *newOp = cast(B.CreateCall(getCalledFunction(), newArgs, this->getName())); + InstNameConflictVarargsOp *newOp = cast(::llvm::CallInst::Create(getCalledFunction(), newArgs, ::std::nullopt, this->getName(), this->getIterator())); this->replaceAllUsesWith(newOp); this->eraseFromParent(); return newOp; @@ -2244,12 +2244,12 @@ data value_op_iterator(arg_end())); } - WriteVarArgOp *WriteVarArgOp::replaceArgsAndInvalidate(::llvm_dialects::Builder &B, ::llvm::ArrayRef args) { + WriteVarArgOp *WriteVarArgOp::replaceArgs(::llvm::ArrayRef args) { ::llvm::SmallVector newArgs; if (1 > 0) newArgs.append(arg_begin(), arg_begin() + 1); newArgs.append(args.begin(), args.end()); - WriteVarArgOp *newOp = cast(B.CreateCall(getCalledFunction(), newArgs, this->getName())); + WriteVarArgOp *newOp = cast(::llvm::CallInst::Create(getCalledFunction(), newArgs, ::std::nullopt, this->getName(), this->getIterator())); this->replaceAllUsesWith(newOp); this->eraseFromParent(); return newOp; diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index cf7471d..3198f89 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -386,8 +386,8 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::iterator_range<::llvm::User::value_op_iterator> getInstName_0() ; /// Returns a new op with the same arguments and a new tail argument list. - /// The object on which this is called will be invalidated. - InstNameConflictVarargsOp *replaceInstName_0AndInvalidate(::llvm_dialects::Builder &, ::llvm::ArrayRef); + /// The object on which this is called will be replaced and erased. + InstNameConflictVarargsOp *replaceInstName_0(::llvm::ArrayRef); ::llvm::Value * getResult(); @@ -605,8 +605,8 @@ bool verifier(::llvm::raw_ostream &errs); void setData(::llvm::Value * data); ::llvm::iterator_range<::llvm::User::value_op_iterator> getArgs() ; /// Returns a new op with the same arguments and a new tail argument list. - /// The object on which this is called will be invalidated. - WriteVarArgOp *replaceArgsAndInvalidate(::llvm_dialects::Builder &, ::llvm::ArrayRef); + /// The object on which this is called will be replaced and erased. + WriteVarArgOp *replaceArgs(::llvm::ArrayRef);