From cf2e381155a75ad499eef774a5e8c2008662395a Mon Sep 17 00:00:00 2001 From: Thomas Symalla Date: Thu, 18 Jul 2024 08:52:05 +0200 Subject: [PATCH] Copy metadata in varargs setter --- example/ExampleMain.cpp | 6 ++++++ lib/TableGen/Operations.cpp | 1 + test/example/generated/ExampleDialect.cpp.inc | 2 ++ test/example/test-builder.test | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/example/ExampleMain.cpp b/example/ExampleMain.cpp index 00d1c56..f6c8858 100644 --- a/example/ExampleMain.cpp +++ b/example/ExampleMain.cpp @@ -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" @@ -126,6 +127,11 @@ void createFunctionExample(Module &module, const Twine &name) { b.create(); auto *replaceable = b.create(p2, varArgs); + SmallVector MD; + MD.push_back(ConstantAsMetadata::get( + ConstantInt::get(Type::getInt32Ty(bb->getContext()), 1))); + replaceable->setMetadata("testMd", MDNode::get(bb->getContext(), MD)); + SmallVector varArgs2 = varArgs; varArgs2.push_back(p2); diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index 2785d33..7be7208 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -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; diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 3800b8f..90cfbff 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -1510,6 +1510,7 @@ instName newArgs.append(arg_begin(), arg_begin() + 0); newArgs.append(instName_0.begin(), instName_0.end()); InstNameConflictVarargsOp *newOp = ::llvm::cast(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator())); + newOp->copyMetadata(*this); this->replaceAllUsesWith(newOp); this->eraseFromParent(); return newOp; @@ -2251,6 +2252,7 @@ data newArgs.append(arg_begin(), arg_begin() + 1); newArgs.append(args.begin(), args.end()); WriteVarArgOp *newOp = ::llvm::cast(::llvm::CallInst::Create(getCalledFunction(), newArgs, this->getName(), this->getIterator())); + newOp->copyMetadata(*this); this->replaceAllUsesWith(newOp); this->eraseFromParent(); return newOp; diff --git a/test/example/test-builder.test b/test/example/test-builder.test index 0afbc60..96603b4 100644 --- a/test/example/test-builder.test +++ b/test/example/test-builder.test @@ -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()