<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Hi llvm-ers,<div><br></div><div>I try to assign unique IDs for each basic block in a module using globle metadata (NamedMDNode). However, I got an error: '<b>Invalide operand for global metadata!</b>' and I have no idea how to deal with it. My llvm version is 3.6.0 and I use visual studio 2013 to build the project. The way to add MDNode is learnt from LLVM Giri project (their project is based on llvm 3.4).</div><div><br></div><div>Thanks for your time. :-)</div><div>Henry</div><div><br></div><div>Here is the code snippet:</div><div>---------------------------------------------</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>bool runOnModule(Module &M) {</div></div><div><div>    ...</div></div><div><div>    NamedMDNode *NMD = M.getOrInsertNamedMetadata(mdKindName);</div></div><div><div>    for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) {</div></div><div><div>        for (Function::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) {</div></div><div><div>            errs() << "Basic Block number: " << counter << "\n";</div></div><div><div>            NMD->addOperand(assignID(BI, ++counter));</div></div><div><div>            errs() << "Basic Block name: " << BI->getName() << "\n";</div></div><div><div>        }</div></div><div><div>    }</div></div><div><div>    ...</div></div><div><div>}</div></div><div><div><br></div></div><div><div>// Assign unique IDs to Basic Blocks as Metadata Nodes</div></div><div><div>MDNode* assignID (BasicBlock* BB, unsigned id) {</div></div><div><div>    // Fetch the context in which the enclosing module was defined</div></div><div><div>    LLVMContext &Context = BB->getParent()->getParent()->getContext();</div></div><div><div><br></div></div><div><div>    // Create a metadata node that contains ID as a constant:</div></div><div><div>    Value* ID[2];</div></div><div><div>    ID[0] = BB;</div></div><div><div>    ID[1] = ConstantInt::get(Type::getInt32Ty(Context), id);</div></div><div><div>    return MDNode::getWhenValsUnresolved(Context, ArrayRef<Value*>(ID, 2), false);</div></div><div><div>}</div></div></blockquote>----------------------------------</div>
</div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>-----------------------------------------------</div>ZHONG, Guanwen (Henry)<div><i>Ph.D. Candidate</i></div><div><i>System & Networking Research Lab</i></div><div><i>National University of Singapore</i></div><div>------------------------------------------------</div></div></div>