Johns Paul Johns Paul - 2 months ago 19
C++ Question

How to add multiple operands to a MDNode or metadata in LLVM?

I want to create an MDNode pointer with multiple operands. The following code create an MDNode pointer with 1 operand:

llvm::MDNode *MDNOdeNVVM = llvm::MDNode::get(*context, llvm::MDString::get(*context, "kernel"));

But I dont see an addOperand function in LLVM Manual. So is there any function that will let me create metadata with multiple operands?


You need to create a MDTuple. First you create your operands in a vector and then you create the Tuple. Something like:

SmallVector<Metadata *, 32> Ops;
Ops.push_back(llvm::MDString::get(*context, "linux"));
Ops.push_back(llvm::MDString::get(*context, "kernel"));
auto *Node =  MDTuple::get(Context, Ops);