Skip to content

Commit

Permalink
Revert "Address review comments."
Browse files Browse the repository at this point in the history
This reverts commit eb93328.
  • Loading branch information
tsymalla-AMD authored Jul 17, 2024
1 parent 7a148bb commit 62fb95e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void createFunctionExample(Module &module, const Twine &name) {
SmallVector<Value *> varArgs2 = varArgs;
varArgs2.push_back(p2);

replacable->replaceArgs(varArgs2);
replacable->replaceArgsAndInvalidate(b, varArgs2);
b.create<xd::SetReadOp>(FixedVectorType::get(b.getInt32Ty(), 2));
b.create<xd::SetWriteOp>(y6);

Expand Down
28 changes: 17 additions & 11 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
void emitVarArgReplacementDefinition(const size_t numNonVarArgs) const;

private:
FmtContext &m_fmt;
Expand Down Expand Up @@ -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 replaced and erased.
$_op *replace$1(::llvm::ArrayRef<Value *>);
/// The object on which this is called will be invalidated.
$_op *replace$1AndInvalidate(::llvm_dialects::Builder &, ::llvm::ArrayRef<Value *>);
)";
}
}
Expand Down Expand Up @@ -237,22 +237,25 @@ void AccessorBuilder::emitSetterDefinition() const {
&m_fmt);
}

void AccessorBuilder::emitVarArgReplacementDefinition() const {
void AccessorBuilder::emitVarArgReplacementDefinition(
const size_t numNonVarArgs) const {
std::string toLlvm = m_arg.name;

m_fmt.addSubst("numNonVarargs", std::to_string(numNonVarArgs));

m_os << tgfmt(R"(
$_op *$_op::replace$Name(::llvm::ArrayRef<Value *> $name) {
$_op *$_op::replace$0AndInvalidate(::llvm_dialects::Builder &B, ::llvm::ArrayRef<Value *> $1) {
::llvm::SmallVector<Value *> newArgs;
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()));
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()));
this->replaceAllUsesWith(newOp);
this->eraseFromParent();
return newOp;
})",
&m_fmt);
&m_fmt, convertToCamelFromSnakeCase(toLlvm, true), toLlvm);
}

void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out,
Expand All @@ -261,6 +264,7 @@ 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);

Expand All @@ -275,7 +279,9 @@ void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out,

builder.emitAccessorDefinitions();
if (!arg.type->isImmutable() && arg.type->isVarArgList())
builder.emitVarArgReplacementDefinition();
builder.emitVarArgReplacementDefinition(numArgs);
else
++numArgs;
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1503,12 +1503,12 @@ instName
value_op_iterator(arg_end()));
}

InstNameConflictVarargsOp *InstNameConflictVarargsOp::replaceInstName_0(::llvm::ArrayRef<Value *> instName_0) {
InstNameConflictVarargsOp *InstNameConflictVarargsOp::replaceInstName_0AndInvalidate(::llvm_dialects::Builder &B, ::llvm::ArrayRef<Value *> instName_0) {
::llvm::SmallVector<Value *> newArgs;
if (0 > 0)
newArgs.append(arg_begin(), arg_begin() + 0);
newArgs.append(instName_0.begin(), instName_0.end());
InstNameConflictVarargsOp *newOp = cast<InstNameConflictVarargsOp>(::llvm::CallInst::Create(getCalledFunction(), newArgs, ::std::nullopt, this->getName(), this->getIterator()));
InstNameConflictVarargsOp *newOp = cast<InstNameConflictVarargsOp>(B.CreateCall(getCalledFunction(), newArgs, this->getName()));
this->replaceAllUsesWith(newOp);
this->eraseFromParent();
return newOp;
Expand Down Expand Up @@ -2244,12 +2244,12 @@ data
value_op_iterator(arg_end()));
}

WriteVarArgOp *WriteVarArgOp::replaceArgs(::llvm::ArrayRef<Value *> args) {
WriteVarArgOp *WriteVarArgOp::replaceArgsAndInvalidate(::llvm_dialects::Builder &B, ::llvm::ArrayRef<Value *> args) {
::llvm::SmallVector<Value *> newArgs;
if (1 > 0)
newArgs.append(arg_begin(), arg_begin() + 1);
newArgs.append(args.begin(), args.end());
WriteVarArgOp *newOp = cast<WriteVarArgOp>(::llvm::CallInst::Create(getCalledFunction(), newArgs, ::std::nullopt, this->getName(), this->getIterator()));
WriteVarArgOp *newOp = cast<WriteVarArgOp>(B.CreateCall(getCalledFunction(), newArgs, this->getName()));
this->replaceAllUsesWith(newOp);
this->eraseFromParent();
return newOp;
Expand Down
8 changes: 4 additions & 4 deletions test/example/generated/ExampleDialect.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 replaced and erased.
InstNameConflictVarargsOp *replaceInstName_0(::llvm::ArrayRef<Value *>);
/// The object on which this is called will be invalidated.
InstNameConflictVarargsOp *replaceInstName_0AndInvalidate(::llvm_dialects::Builder &, ::llvm::ArrayRef<Value *>);

::llvm::Value * getResult();

Expand Down Expand Up @@ -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 replaced and erased.
WriteVarArgOp *replaceArgs(::llvm::ArrayRef<Value *>);
/// The object on which this is called will be invalidated.
WriteVarArgOp *replaceArgsAndInvalidate(::llvm_dialects::Builder &, ::llvm::ArrayRef<Value *>);



Expand Down

0 comments on commit 62fb95e

Please sign in to comment.