本文整理汇总了C++中basicblock::iterator::setMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::setMetadata方法的具体用法?C++ iterator::setMetadata怎么用?C++ iterator::setMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类basicblock::iterator
的用法示例。
在下文中一共展示了iterator::setMetadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnModule
bool IDTagger::runOnModule(Module &M) {
IntegerType *IntType = IntegerType::get(M.getContext(), 32);
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
Constant *InsID = ConstantInt::get(IntType, NumInstructions);
I->setMetadata("ins_id", MDNode::get(M.getContext(), InsID));
++NumInstructions;
}
}
}
return true;
}
示例2: Module
//.........这里部分代码省略.........
// new module. Here we add them to the VMap and to the new Module. We
// don't worry about attributes or initializers, they will come later.
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
GlobalVariable *GV = new GlobalVariable(*New,
I->getType()->getElementType(),
false,
GlobalValue::ExternalLinkage, 0,
I->getName());
GV->setAlignment(I->getAlignment());
VMap[I] = GV;
}
// Loop over the functions in the module, making external functions as before
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *NF =
Function::Create(cast<FunctionType>(I->getType()->getElementType()),
GlobalValue::ExternalLinkage, I->getName(), New);
NF->copyAttributesFrom(I);
VMap[I] = NF;
}
// Loop over the aliases in the module
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I)
VMap[I] = new GlobalAlias(I->getType(), GlobalAlias::ExternalLinkage,
I->getName(), NULL, New);
// Now that all of the things that global variable initializer can refer to
// have been created, loop through and copy the global variable referrers
// over... We also set the attributes on the global now.
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
GlobalVariable *GV = cast<GlobalVariable>(VMap[I]);
if (I->hasInitializer())
GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
VMap)));
GV->setLinkage(I->getLinkage());
GV->setThreadLocal(I->isThreadLocal());
GV->setConstant(I->isConstant());
}
// Similarly, copy over function bodies now...
//
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *F = cast<Function>(VMap[I]);
if (!I->isDeclaration()) {
Function::arg_iterator DestI = F->arg_begin();
for (Function::const_arg_iterator J = I->arg_begin(); J != I->arg_end();
++J) {
DestI->setName(J->getName());
VMap[J] = DestI++;
}
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
CloneFunctionInto(F, I, VMap, Returns);
}
F->setLinkage(I->getLinkage());
}
// And aliases
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I) {
GlobalAlias *GA = cast<GlobalAlias>(VMap[I]);
GA->setLinkage(I->getLinkage());
if (const Constant* C = I->getAliasee())
GA->setAliasee(cast<Constant>(MapValue(C, VMap)));
}
// And named metadata....
for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
E = M->named_metadata_end(); I != E; ++I) {
const NamedMDNode &NMD = *I;
SmallVector<MDNode*, 4> MDs;
for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
MDs.push_back(cast<MDNode>(MapValue(NMD.getOperand(i), VMap)));
NamedMDNode::Create(New->getContext(), NMD.getName(),
MDs.data(), MDs.size(), New);
}
// Update metadata attach with instructions.
for (Module::iterator MI = New->begin(), ME = New->end(); MI != ME; ++MI)
for (Function::iterator FI = MI->begin(), FE = MI->end();
FI != FE; ++FI)
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
BI != BE; ++BI) {
SmallVector<std::pair<unsigned, MDNode *>, 4 > MDs;
BI->getAllMetadata(MDs);
for (SmallVector<std::pair<unsigned, MDNode *>, 4>::iterator
MDI = MDs.begin(), MDE = MDs.end(); MDI != MDE; ++MDI) {
Value *MappedValue = MapValue(MDI->second, VMap);
if (MDI->second != MappedValue && MappedValue)
BI->setMetadata(MDI->first, cast<MDNode>(MappedValue));
}
}
return New;
}
示例3: CloneAndPruneFunctionInto
/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
/// except that it does some simple constant prop and DCE on the fly. The
/// effect of this is to copy significantly less code in cases where (for
/// example) a function call with constant arguments is inlined, and those
/// constant arguments cause a significant amount of code in the callee to be
/// dead. Since this doesn't produce an exact copy of the input, it can't be
/// used for things like CloneFunction or CloneModule.
void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
ValueToValueMapTy &VMap,
SmallVectorImpl<ReturnInst*> &Returns,
const char *NameSuffix,
ClonedCodeInfo *CodeInfo,
const TargetData *TD,
Instruction *TheCall) {
assert(NameSuffix && "NameSuffix cannot be null!");
#ifndef NDEBUG
for (Function::const_arg_iterator II = OldFunc->arg_begin(),
E = OldFunc->arg_end(); II != E; ++II)
assert(VMap.count(II) && "No mapping from source argument specified!");
#endif
PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, Returns,
NameSuffix, CodeInfo, TD);
// Clone the entry block, and anything recursively reachable from it.
std::vector<const BasicBlock*> CloneWorklist;
CloneWorklist.push_back(&OldFunc->getEntryBlock());
while (!CloneWorklist.empty()) {
const BasicBlock *BB = CloneWorklist.back();
CloneWorklist.pop_back();
PFC.CloneBlock(BB, CloneWorklist);
}
// Loop over all of the basic blocks in the old function. If the block was
// reachable, we have cloned it and the old block is now in the value map:
// insert it into the new function in the right order. If not, ignore it.
//
// Defer PHI resolution until rest of function is resolved.
SmallVector<const PHINode*, 16> PHIToResolve;
for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end();
BI != BE; ++BI) {
BasicBlock *NewBB = cast_or_null<BasicBlock>(VMap[BI]);
if (NewBB == 0) continue; // Dead block.
// Add the new block to the new function.
NewFunc->getBasicBlockList().push_back(NewBB);
// Loop over all of the instructions in the block, fixing up operand
// references as we go. This uses VMap to do all the hard work.
//
BasicBlock::iterator I = NewBB->begin();
unsigned DbgKind = OldFunc->getContext().getMDKindID("dbg");
MDNode *TheCallMD = NULL;
if (TheCall && TheCall->hasMetadata())
TheCallMD = TheCall->getMetadata(DbgKind);
// Handle PHI nodes specially, as we have to remove references to dead
// blocks.
if (PHINode *PN = dyn_cast<PHINode>(I)) {
// Skip over all PHI nodes, remembering them for later.
BasicBlock::const_iterator OldI = BI->begin();
for (; (PN = dyn_cast<PHINode>(I)); ++I, ++OldI) {
if (I->hasMetadata()) {
if (TheCallMD) {
if (MDNode *IMD = I->getMetadata(DbgKind)) {
MDNode *NewMD = UpdateInlinedAtInfo(IMD, TheCallMD);
I->setMetadata(DbgKind, NewMD);
}
} else {
// The cloned instruction has dbg info but the call instruction
// does not have dbg info. Remove dbg info from cloned instruction.
I->setMetadata(DbgKind, 0);
}
}
PHIToResolve.push_back(cast<PHINode>(OldI));
}
}
// FIXME:
// FIXME:
// FIXME: Unclone all this metadata stuff.
// FIXME:
// FIXME:
// Otherwise, remap the rest of the instructions normally.
for (; I != NewBB->end(); ++I) {
if (I->hasMetadata()) {
if (TheCallMD) {
if (MDNode *IMD = I->getMetadata(DbgKind)) {
MDNode *NewMD = UpdateInlinedAtInfo(IMD, TheCallMD);
I->setMetadata(DbgKind, NewMD);
}
} else {
// The cloned instruction has dbg info but the call instruction
// does not have dbg info. Remove dbg info from cloned instruction.
I->setMetadata(DbgKind, 0);
}
}
//.........这里部分代码省略.........
示例4: runOnModule
//.........这里部分代码省略.........
SecSensitiveObjs.insert(sensitiveObject);
}
//check if any operand is global string..
if(writeStrings)
{
for (unsigned int i = 0; i < cast<User> (I)->getNumOperands(); i++)
{
Value *v1 = cast<User> (I)->getOperand(i);
if(isa<GlobalVariable> (v1))
{
if(isa<Constant> (v1))
{
//string sName = v1->getName()
v1->print(FileS);
(FileS) << "\n";
}
}
}
}
LLVMContext& C = I->getContext();
MDNode* N = MDNode::get(C, MDString::get(C, "ComputeSSO"));
// char numstr[21]; // enough to hold all numbers up to 64-bits
//sprintf(numstr, "%d", inputDepVal_count);
//appendVal = ()
std::string taintVal = "TAINT_"+appendVal;
// if(debug) errs()<<"\nFunction : "<< F->getName()<<" Tainted Val " << *I <<" val: " << appendVal;
//For the given tainted Val try priniting all the uses of it.
// errs()<<"\nUsed in :: "<<I->getNumUses();
// std::string taintVal = std::strcat("tainted",numstr);
I->setMetadata(taintVal, N);
}
/* if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(&*I)) {
// Dump the GEP instruction
// gep->dump();
Value* firstOperand = gep->getOperand(0);
Type* type = firstOperand->getType();
// Figure out whether the first operand points to an array
if (PointerType *pointerType = dyn_cast<PointerType>(type)) {
Type* elementType = pointerType->getElementType();
//errs() << "The element type is: " << *elementType << "\n";
if (elementType->isArrayTy()) {
errs() << "\n .. points to an array!\n";
errs()<< "First op ..: "<< firstOperand <<" full def :";
gep->dump();
}
else if(elementType->isStructTy ()) {
errs() << "\n *** points to a Struct !\n";
errs()<< "First op ..: "<< firstOperand <<" full def :";
gep->dump();
}
}
} */
}
}
}
//Print how many source types added