jeudi 2 octobre 2014

llvm Invalid operand for global metadata


Vote count:

0




I want to assign unique IDs for basic blocks in a module using global metadata. But I got an error: "Invalid operand for global metadata!". Any problems in the follow code snippet?


Here is part of the code I add operand of a named metadata node:



bool runOnModule(Module &M) {
...
NamedMDNode *NMD = M.getOrInsertNamedMetadata(mdKindName);
for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) {
for (Function::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) {
errs() << "Basic Block number: " << counter << "\n";
NMD->addOperand(assignID(BI, ++counter));
errs() << "Basic Block name: " << BI->getName() << "\n";
}
}
...
}

// Assign unique IDs to Basic Blocks as Metadata Nodes
MDNode* assignID (BasicBlock* BB, unsigned id) {
// Fetch the context in which the enclosing module was defined
LLVMContext &Context = BB->getParent()->getParent()->getContext();

// Create a metadata node that contains ID as a constant:
Value* ID[2];
ID[0] = BB;
ID[1] = ConstantInt::get(Type::getInt32Ty(Context), id);
return MDNode::getWhenValsUnresolved(Context, ArrayRef<Value*>(ID, 2), false);
}


The version of llvm is 3.6.0. I am using visual studio 2013 for my project.


Thanks, henry



asked 1 min ago







llvm Invalid operand for global metadata

Aucun commentaire:

Enregistrer un commentaire