本文整理汇总了C++中module::iterator::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::begin方法的具体用法?C++ iterator::begin怎么用?C++ iterator::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类module::iterator
的用法示例。
在下文中一共展示了iterator::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCallsToFunction
StructuredModuleEditor::InstList StructuredModuleEditor::getCallsToFunction(
Function * F) {
InstList Calls;
// Iterates over every basic block in the module and gathers a list of instructions
// that call to the specified function
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) {
for (Function::iterator BBI = FI->begin(), BBE = FI->end(); BBI != BBE;
++BBI) {
for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end();
II != IE; ++II) {
CallSite CS(cast<Value>(II));
// If this isn't a call, or it is a call to an intrinsic...
if (!CS || isa<IntrinsicInst>(II))
continue;
Function *Callee = CS.getCalledFunction();
if (Callee == F)
Calls.push_back(CS.getInstruction());
}
}
}
return Calls;
}
示例2: runOnModule
bool ExpandByVal::runOnModule(Module &M) {
bool Modified = false;
DataLayout DL(&M);
for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) {
AttributeSet NewAttrs = RemoveAttrs(Func->getContext(),
Func->getAttributes());
Modified |= (NewAttrs != Func->getAttributes());
Func->setAttributes(NewAttrs);
for (Function::iterator BB = Func->begin(), E = Func->end();
BB != E; ++BB) {
for (BasicBlock::iterator Inst = BB->begin(), E = BB->end();
Inst != E; ++Inst) {
if (CallInst *Call = dyn_cast<CallInst>(Inst)) {
Modified |= ExpandCall(&DL, Call);
} else if (InvokeInst *Call = dyn_cast<InvokeInst>(Inst)) {
Modified |= ExpandCall(&DL, Call);
}
}
}
}
return Modified;
}
示例3: setMustKeepGlobalVariables
void GlobalMerge::setMustKeepGlobalVariables(Module &M) {
// If we already processed a Module, UsedGlobalVariables may have been
// populated. Reset the information for this module.
MustKeepGlobalVariables.clear();
collectUsedGlobalVariables(M);
for (Module::iterator IFn = M.begin(), IEndFn = M.end(); IFn != IEndFn;
++IFn) {
for (Function::iterator IBB = IFn->begin(), IEndBB = IFn->end();
IBB != IEndBB; ++IBB) {
// Follow the inwoke link to find the landing pad instruction
const InvokeInst *II = dyn_cast<InvokeInst>(IBB->getTerminator());
if (!II) continue;
const LandingPadInst *LPInst = II->getUnwindDest()->getLandingPadInst();
// Look for globals in the clauses of the landing pad instruction
for (unsigned Idx = 0, NumClauses = LPInst->getNumClauses();
Idx != NumClauses; ++Idx)
if (const GlobalVariable *GV =
dyn_cast<GlobalVariable>(LPInst->getClause(Idx)
->stripPointerCasts()))
MustKeepGlobalVariables.insert(GV);
}
}
}
示例4: runOnModule
//
// Method: runOnModule()
//
// Description:
// Entry point for this LLVM pass. Search for insert/extractvalue instructions
// that can be simplified.
//
// Inputs:
// M - A reference to the LLVM module to transform.
//
// Outputs:
// M - The transformed LLVM module.
//
// Return value:
// true - The module was modified.
// false - The module was not modified.
//
bool SimplifyLoad::runOnModule(Module& M) {
// Repeat till no change
bool changed;
do {
changed = false;
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {
for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
LoadInst *LI = dyn_cast<LoadInst>(I++);
if(!LI)
continue;
if(LI->hasOneUse()) {
if(CastInst *CI = dyn_cast<CastInst>(*(LI->use_begin()))) {
if(LI->getType()->isPointerTy()) {
if(ConstantExpr *CE = dyn_cast<ConstantExpr>(LI->getOperand(0))) {
if(const PointerType *PTy = dyn_cast<PointerType>(CE->getOperand(0)->getType()))
if(PTy->getElementType() == CI->getType()) {
LoadInst *LINew = new LoadInst(CE->getOperand(0), "", LI);
CI->replaceAllUsesWith(LINew);
}
}
}
}
}
}
}
}
} while(changed);
return (numErased > 0);
}
示例5: init
void BlockFrequencyPruner::init() {
freqSum = 0;
std::vector<BasicBlock*> blocks;
for (Module::iterator f = m->begin(); f != m->end(); f++) {
if (!(*f).isDeclaration()) {
BlockFrequencyInfo &bfi = mp->getAnalysis<BlockFrequencyInfo>(*f);
for (Function::iterator b = f->begin(); b != f->end(); b++) {
BasicBlock *block = b;
unsigned freq = bfi.getBlockFreq(block).getFrequency();
freqSum += freq;
blocks.push_back(block);
_freqPredicate.freqs[block] = freq;
}
}
}
std::sort(blocks.begin(), blocks.end(), _freqPredicate);
std::vector<double> dist = getBlockDistribution(blocks, (double)freqSum);
double distSum = 0;
for (unsigned i = 0; (i < blocks.size()) && (distSum < massThreshold); ++i, distSum += dist.at(i)) {
prunedBlocks.push_back(blocks.at(i));
}
}
示例6: updateMetadata
void Variables::updateMetadata(Module& module, Value* oldTarget, Value* newTarget, Type* newType) {
vector<Instruction*> to_remove;
if (newTarget) {
errs() << "\tChanging metadata for: " << newTarget->getName() << "\n";
bool changed = false;
for(Module::iterator f = module.begin(), fe = module.end(); f != fe; f++) {
for(Function::iterator b = f->begin(), be = f->end(); b != be; b++) {
for(BasicBlock::iterator i = b->begin(), ie = b->end(); i != ie; i++) {
if (DbgDeclareInst *oldDeclare = dyn_cast<DbgDeclareInst>(i)) {
if (Value *address = oldDeclare->getAddress()) {
if (AllocaInst *allocaInst = dyn_cast<AllocaInst>(address)) {
if (allocaInst == oldTarget) { // the alloca we are looking for
DIVariable oldDIVar(oldDeclare->getVariable());
MDNode* newDIType = getTypeMetadata(module, oldDIVar, newType);
// construct new DIVariable with new type descriptor
vector<Value*> doperands;
for(unsigned i = 0; i < oldDIVar->getNumOperands(); i++) {
if (i == 5) { // the argument that corresponds to the type descriptor
doperands.push_back(newDIType);
}
else {
doperands.push_back(oldDIVar->getOperand(i)); // preserve other descriptors
}
}
ArrayRef<Value*> *arrayRefDOperands = new ArrayRef<Value*>(doperands);
MDNode* newMDNode = MDNode::get(module.getContext(), *arrayRefDOperands);
DIVariable newDIVar(newMDNode);
// insert new declare instruction
DIBuilder* builder = new DIBuilder(module);
Instruction *newDeclare = builder->insertDeclare(newTarget, newDIVar, oldDeclare);
// make sure the declare instruction preserves its own metadata
unsigned id = 0;
if (oldDeclare->getMetadata(id)) {
newDeclare->setMetadata(id, oldDeclare->getMetadata(id));
}
to_remove.push_back(oldDeclare); // can't erase while iterating through instructions
changed = true;
}
}
}
}
}
}
}
for(unsigned i = 0; i < to_remove.size(); i++) {
to_remove[i]->eraseFromParent();
}
if (!changed) {
errs() << "\tNo metadata to change\n";
}
}
return;
}
示例7: runOnModule
bool RaiseAsmPass::runOnModule(Module &M) {
bool changed = false;
#if LLVM_VERSION_CODE >= LLVM_VERSION(2, 9)
std::string Err;
std::string HostTriple = llvm::sys::getHostTriple();
const Target *NativeTarget = TargetRegistry::lookupTarget(HostTriple, Err);
if (NativeTarget == 0) {
llvm::errs() << "Warning: unable to select native target: " << Err << "\n";
TLI = 0;
} else {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 0)
TargetMachine *TM = NativeTarget->createTargetMachine(HostTriple, "", "");
#else
TargetMachine *TM = NativeTarget->createTargetMachine(HostTriple, "");
#endif
TLI = TM->getTargetLowering();
}
#endif
for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) {
for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) {
for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) {
Instruction *i = ii;
++ii;
changed |= runOnInstruction(M, i);
}
}
}
return changed;
}
示例8: runOnModule
bool MemoryInstrumenter::runOnModule(Module &M) {
// Check whether there are unsupported language features.
checkFeatures(M);
// Setup scalar types.
setupScalarTypes(M);
// Find the main function.
Main = M.getFunction("main");
assert(Main && !Main->isDeclaration() && !Main->hasLocalLinkage());
// Setup hook function declarations.
setupHooks(M);
// Hook global variable allocations.
instrumentGlobals(M);
// Hook memory allocations and memory accesses.
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
if (F->isDeclaration())
continue;
if (!IsWhiteListed(*F))
continue;
// The second argument of main(int argc, char *argv[]) needs special
// handling, which is done in instrumentMainArgs.
// We should treat argv as a memory allocation instead of a regular
// pointer.
if (Main != F)
instrumentPointerParameters(F);
if (F->isVarArg())
instrumentVarArgFunction(F);
for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) {
if (Diagnose)
instrumentBasicBlock(BB);
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
instrumentInstructionIfNecessary(I);
}
instrumentEntry(*F);
}
// main(argc, argv)
// argv is allocated by outside.
instrumentMainArgs(M);
// Lower global constructors.
lowerGlobalCtors(M);
#if 0
// Add HookGlobalsAlloc to the global_ctors list.
addNewGlobalCtor(M);
#endif
// Call the memory hook initializer and the global variable allocation hook
// at the very beginning.
Instruction *OldEntry = Main->begin()->getFirstNonPHI();
CallInst::Create(MemHooksIniter, "", OldEntry);
CallInst::Create(GlobalsAllocHook, "", OldEntry);
return true;
}
示例9: runOnModule
bool LdStCallCounter::runOnModule(Module &M) {
if (flag == true) // if we have counted already -- structure of llvm means this could be called many times
return false;
// for all functions in module
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration())
{ // for all blocks in the function
for (Function::iterator BBB = I->begin(), BBE = I->end(); BBB != BBE; ++BBB)
{ // for all instructions in a block
for (BasicBlock::iterator IB = BBB->begin(), IE = BBB->end(); IB != IE; IB++)
{
if (isa<LoadInst>(IB)) // count loads, stores, calls
num_loads++;
else if (isa<StoreInst>(IB))
num_stores++; // count only external calls, ignore declarations, etc
else if (isa<CallInst>(IB) && ( (dyn_cast<CallInst>(IB)->getCalledFunction() == NULL) ||
(dyn_cast<CallInst>(IB)->getCalledFunction()->isDeclaration())))
num_calls++;
}
}
}
llvm::errs() << "Loads/Store/Calls:" << num_loads << " " << num_stores << " " << num_calls << "\n";
flag = true;
return false;
}
示例10:
bool llvm::ValueCounter::runOnModule(Module& M) {
std::set<Value*> values;
for(Module::iterator Fit = M.begin(), Fend = M.end(); Fit != Fend; Fit++){
if (!values.count(Fit)) values.insert(Fit);
for(Function::arg_iterator Arg = Fit->arg_begin(), aEnd = Fit->arg_end(); Arg != aEnd; Arg++) {
if (!values.count(Arg)) values.insert(Arg);
}
for (Function::iterator BBit = Fit->begin(), BBend = Fit->end(); BBit != BBend; BBit++) {
for (BasicBlock::iterator Iit = BBit->begin(), Iend = BBit->end(); Iit != Iend; Iit++) {
if (!values.count(Iit)) values.insert(Iit);
for(unsigned int i = 0; i < Iit->getNumOperands(); i++){
if (!values.count(Iit->getOperand(i))) values.insert(Iit->getOperand(i));
}
}
}
}
TotalValues = values.size();
//We don't modify anything, so we must return false;
return false;
}
示例11: runOnModule
bool BlockExtractorPass::runOnModule(Module &M) {
std::set<BasicBlock*> TranslatedBlocksToNotExtract;
for (unsigned i = 0, e = BlocksToNotExtract.size(); i != e; ++i) {
BasicBlock *BB = BlocksToNotExtract[i];
Function *F = BB->getParent();
// Map the corresponding function in this module.
Function *MF = M.getFunction(F->getName());
assert(MF->getFunctionType() == F->getFunctionType() && "Wrong function?");
// Figure out which index the basic block is in its function.
Function::iterator BBI = MF->begin();
std::advance(BBI, std::distance(F->begin(), Function::iterator(BB)));
TranslatedBlocksToNotExtract.insert(&*BBI);
}
while (!BlocksToNotExtractByName.empty()) {
// There's no way to find BBs by name without looking at every BB inside
// every Function. Fortunately, this is always empty except when used by
// bugpoint in which case correctness is more important than performance.
std::string &FuncName = BlocksToNotExtractByName.back().first;
std::string &BlockName = BlocksToNotExtractByName.back().second;
for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) {
Function &F = *FI;
if (F.getName() != FuncName) continue;
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
BasicBlock &BB = *BI;
if (BB.getName() != BlockName) continue;
TranslatedBlocksToNotExtract.insert(&*BI);
}
}
BlocksToNotExtractByName.pop_back();
}
// Now that we know which blocks to not extract, figure out which ones we WANT
// to extract.
std::vector<BasicBlock*> BlocksToExtract;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
SplitLandingPadPreds(&*F);
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
if (!TranslatedBlocksToNotExtract.count(&*BB))
BlocksToExtract.push_back(&*BB);
}
for (unsigned i = 0, e = BlocksToExtract.size(); i != e; ++i) {
SmallVector<BasicBlock*, 2> BlocksToExtractVec;
BlocksToExtractVec.push_back(BlocksToExtract[i]);
if (const InvokeInst *II =
dyn_cast<InvokeInst>(BlocksToExtract[i]->getTerminator()))
BlocksToExtractVec.push_back(II->getUnwindDest());
CodeExtractor(BlocksToExtractVec).extractCodeRegion();
}
return !BlocksToExtract.empty();
}
示例12: getFnThatStoreOnArgs
/*
* Build information about functions that store on pointer arguments
* For simplification, we only consider a function to store on an argument
* if it has exactly one StoreInst to that argument and the arg has no other use.
*/
int DeadStoreEliminationPass::getFnThatStoreOnArgs(Module &M) {
int numStores = 0;
DEBUG(errs() << "Getting functions that store on arguments...\n");
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
if (F->arg_empty() || F->isDeclaration()) continue;
// Get args
std::set<Value*> args;
for (Function::arg_iterator formalArgIter = F->arg_begin();
formalArgIter != F->arg_end(); ++formalArgIter) {
Value *formalArg = formalArgIter;
if (formalArg->getType()->isPointerTy()) {
args.insert(formalArg);
}
}
// Find stores on arguments
for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
Instruction *inst = I;
if (!isa<StoreInst>(inst)) continue;
StoreInst *SI = dyn_cast<StoreInst>(inst);
Value *ptrOp = SI->getPointerOperand();
if (args.count(ptrOp) && ptrOp->hasNUses(1)) {
fnThatStoreOnArgs[F].insert(ptrOp);
numStores++;
DEBUG(errs() << " " << F->getName() << " stores on argument "
<< ptrOp->getName() << "\n"); }
}
}
}
DEBUG(errs() << "\n");
return numStores;
}
示例13: runOnModule
bool OvershiftCheckPass::runOnModule(Module &M) {
Function *overshiftCheckFunction = 0;
LLVMContext &ctx = M.getContext();
bool moduleChanged = false;
for (Module::iterator f = M.begin(), fe = M.end(); f != fe; ++f) {
for (Function::iterator b = f->begin(), be = f->end(); b != be; ++b) {
for (BasicBlock::iterator i = b->begin(), ie = b->end(); i != ie; ++i) {
if (BinaryOperator* binOp = dyn_cast<BinaryOperator>(i)) {
// find all shift instructions
Instruction::BinaryOps opcode = binOp->getOpcode();
if (opcode == Instruction::Shl ||
opcode == Instruction::LShr ||
opcode == Instruction::AShr ) {
std::vector<llvm::Value*> args;
// Determine bit width of first operand
uint64_t bitWidth=i->getOperand(0)->getType()->getScalarSizeInBits();
ConstantInt *bitWidthC = ConstantInt::get(Type::getInt64Ty(ctx),
bitWidth, false);
args.push_back(bitWidthC);
CastInst *shift =
CastInst::CreateIntegerCast(i->getOperand(1),
Type::getInt64Ty(ctx),
false, /* sign doesn't matter */
"int_cast_to_i64",
&*i);
args.push_back(shift);
// Lazily bind the function to avoid always importing it.
if (!overshiftCheckFunction) {
Constant *fc = M.getOrInsertFunction("klee_overshift_check",
Type::getVoidTy(ctx),
Type::getInt64Ty(ctx),
Type::getInt64Ty(ctx),
NULL);
overshiftCheckFunction = cast<Function>(fc);
}
// Inject CallInstr to check if overshifting possible
CallInst *ci =
CallInst::Create(overshiftCheckFunction, args, "", &*i);
// set debug information from binary operand to preserve it
ci->setDebugLoc(binOp->getDebugLoc());
moduleChanged = true;
}
}
}
}
}
return moduleChanged;
}
示例14: SetupInstructionLabelMap
void Constraints::SetupInstructionLabelMap(Module* M) {
for (Module::iterator F = M->begin(), FE = M->end(); F != FE; F++) {
for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; BB++) {
for (BasicBlock::iterator I = BB->begin(), IE = BB->end(); I != IE; I++) {
instrLabelMap.insert(InstrLabel_pair(I->label_instr, I));
}
}
}
}
示例15: checkFeatures
void MemoryInstrumenter::checkFeatures(Module &M) {
// Check whether any memory allocation function can
// potentially be pointed by function pointers.
// Also, all intrinsic functions will be called directly,
// i.e. not via function pointers.
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
if (DynAAUtils::IsMalloc(F) || F->isIntrinsic()) {
for (Value::use_iterator UI = F->use_begin(); UI != F->use_end(); ++UI) {
User *Usr = *UI;
assert(isa<CallInst>(Usr) || isa<InvokeInst>(Usr));
CallSite CS(cast<Instruction>(Usr));
for (unsigned i = 0; i < CS.arg_size(); ++i)
assert(CS.getArgument(i) != F);
}
}
}
// Check whether memory allocation functions are captured.
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
// 0 is the return, 1 is the first parameter.
if (F->isDeclaration() && F->doesNotAlias(0) && !DynAAUtils::IsMalloc(F)) {
errs().changeColor(raw_ostream::RED);
errs() << F->getName() << "'s return value is marked noalias, ";
errs() << "but the function is not treated as malloc.\n";
errs().resetColor();
}
}
// Global variables shouldn't be of the array type.
for (Module::global_iterator GI = M.global_begin(), E = M.global_end();
GI != E; ++GI) {
assert(!GI->getType()->isArrayTy());
}
// A function parameter or an instruction can be an array, but we don't
// instrument such constructs for now. Issue a warning on such cases.
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
for (Function::arg_iterator AI = F->arg_begin(); AI != F->arg_end(); ++AI) {
if (AI->getType()->isArrayTy()) {
errs().changeColor(raw_ostream::RED);
errs() << F->getName() << ":" << *AI << " is an array\n";
errs().resetColor();
}
}
}
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) {
for (BasicBlock::iterator Ins = BB->begin(); Ins != BB->end(); ++Ins) {
if (Ins->getType()->isArrayTy()) {
errs().changeColor(raw_ostream::RED);
errs() << F->getName() << ":" << *Ins << " is an array\n";
errs().resetColor();
}
}
}
}
}