Skip to content

Commit

Permalink
Copy metadata in varargs setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Symalla authored and tsymalla-AMD committed Jul 18, 2024
1 parent ec8493d commit cf2e381
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IRPrinter/IRPrintingPasses.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -126,6 +127,11 @@ void createFunctionExample(Module &module, const Twine &name) {
b.create<xd::HandleGetOp>();

auto *replaceable = b.create<xd::WriteVarArgOp>(p2, varArgs);
SmallVector<Metadata *, 1> MD;
MD.push_back(ConstantAsMetadata::get(
ConstantInt::get(Type::getInt32Ty(bb->getContext()), 1)));
replaceable->setMetadata("testMd", MDNode::get(bb->getContext(), MD));

SmallVector<Value *> varArgs2 = varArgs;
varArgs2.push_back(p2);

Expand Down
1 change: 1 addition & 0 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ void AccessorBuilder::emitVarArgReplacementDefinition() const {
newArgs.append(arg_begin(), arg_begin() + $index);
newArgs.append($name.begin(), $name.end());
$_op *newOp = ::llvm::cast<$_op>(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator()));
newOp->copyMetadata(*this);
this->replaceAllUsesWith(newOp);
this->eraseFromParent();
return newOp;
Expand Down
2 changes: 2 additions & 0 deletions test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ instName
newArgs.append(arg_begin(), arg_begin() + 0);
newArgs.append(instName_0.begin(), instName_0.end());
InstNameConflictVarargsOp *newOp = ::llvm::cast<InstNameConflictVarargsOp>(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator()));
newOp->copyMetadata(*this);
this->replaceAllUsesWith(newOp);
this->eraseFromParent();
return newOp;
Expand Down Expand Up @@ -2251,6 +2252,7 @@ data
newArgs.append(arg_begin(), arg_begin() + 1);
newArgs.append(args.begin(), args.end());
WriteVarArgOp *newOp = ::llvm::cast<WriteVarArgOp>(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator()));
newOp->copyMetadata(*this);
this->replaceAllUsesWith(newOp);
this->eraseFromParent();
return newOp;
Expand Down
2 changes: 1 addition & 1 deletion test/example/test-builder.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
; CHECK-NEXT: call void (...) @xd.write(i8 [[P2]])
; CHECK-NEXT: call void (...) @xd.write.vararg(i8 [[P2]], ptr [[P1]], i8 [[P2]])
; CHECK-NEXT: [[TMP14:%.*]] = call target("xd.handle") @xd.handle.get()
; CHECK-NEXT: call void (...) @xd.write.vararg(i8 [[P2]], ptr [[P1]], i8 [[P2]], i8 [[P2]])
; CHECK-NEXT: call void (...) @xd.write.vararg(i8 [[P2]], ptr [[P1]], i8 [[P2]], i8 [[P2]]), !testMd !{{.*}}
; CHECK-NEXT: [[TMP15:%.*]] = call <2 x i32> @xd.set.read__v2i32()
; CHECK-NEXT: call void (...) @xd.set.write(target("xd.vector", i32, 1, 2) [[TMP13]])
; CHECK-NEXT: [[TMP16:%.*]] = call [[TMP0]] @xd.read__s_s()
Expand Down

0 comments on commit cf2e381

Please sign in to comment.