[LLVMdev] creating new Metadata
John Criswell
criswell at illinois.edu
Wed Dec 21 07:20:03 PST 2011
On 12/20/11 9:25 PM, 陳韋任 wrote:
>> Dear llvm-ers,
>> I am trying to attach a customized metadata to llvm instructions.
>> Let's say, I want to attach some number to each instruction.
>> I am trying to use
>>
>> void Instruction::setMetadata(unsigned KindID, MDNode* Node)
>>
>> but I am not sure how to create a brand new instance of an MDNode.
>> Do you have any code samples demonstrating how to do that?
>>
>> Due to some tool dependencies, I am using LLVM 2.7
> `grep -r MDNode` in $LLVM_SOURCE may give you some examples. I don't know if
> there is a doxygen for LLVM 2.7, but you can see include/llvm/Metadata.h and
> unittests/VMCore/MetadataTest.cpp to know how to create a MDNode. Below is code
> snipt taken form MetadataTest.cpp.
There's example code in SAFECode for LLVM 2.7 for attaching metadata:
http://llvm.org/viewvc/llvm-project/safecode/branches/release_27/lib/Utility/PoolHandles.cpp?revision=135925&view=markup
Look at PoolMDPass::createPoolMetaData().
-- John T.
>
> ---
> MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
> MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
> ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, 0));
>
> std::vector<Value *> V;
> V.push_back(s1);
> V.push_back(CI);
> V.push_back(s2);
>
> MDNode *n1 = MDNode::get(Context,&V[0], 3);
> ---
>
> HTH,
> chenwj
>
More information about the llvm-dev
mailing list