本文整理汇总了C++中module::iterator类的典型用法代码示例。如果您正苦于以下问题:C++ iterator类的具体用法?C++ iterator怎么用?C++ iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DisambiguateGlobalSymbols
/// DisambiguateGlobalSymbols - Mangle symbols to guarantee uniqueness by
/// modifying predominantly internal symbols rather than external ones.
///
static void DisambiguateGlobalSymbols(Module *M) {
// Try not to cause collisions by minimizing chances of renaming an
// already-external symbol, so take in external globals and functions as-is.
// The code should work correctly without disambiguation (assuming the same
// mangler is used by the two code generators), but having symbols with the
// same name causes warnings to be emitted by the code generator.
Mangler Mang(*M);
// Agree with the CBE on symbol naming
Mang.markCharUnacceptable('.');
Mang.setPreserveAsmNames(true);
for (Module::global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I)
I->setName(Mang.getValueName(I));
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
I->setName(Mang.getValueName(I));
}
示例2: replaceUndefsWithNull
void Preparer::replaceUndefsWithNull(Module &M) {
ValueSet Replaced;
for (Module::global_iterator GI = M.global_begin(); GI != M.global_end();
++GI) {
if (GI->hasInitializer()) {
replaceUndefsWithNull(GI->getInitializer(), Replaced);
}
}
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) {
replaceUndefsWithNull(Ins, Replaced);
}
}
}
}
示例3: StripDebugInfo
// StripDebugInfo - Strip debug info in the module if it exists.
// To do this, we remove llvm.dbg.func.start, llvm.dbg.stoppoint, and
// llvm.dbg.region.end calls, and any globals they point to if now dead.
static bool StripDebugInfo(Module &M) {
bool Changed = false;
// Remove all of the calls to the debugger intrinsics, and remove them from
// the module.
if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
while (!Declare->use_empty()) {
CallInst *CI = cast<CallInst>(Declare->use_back());
CI->eraseFromParent();
}
Declare->eraseFromParent();
Changed = true;
}
if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
while (!DbgVal->use_empty()) {
CallInst *CI = cast<CallInst>(DbgVal->use_back());
CI->eraseFromParent();
}
DbgVal->eraseFromParent();
Changed = true;
}
for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
NME = M.named_metadata_end(); NMI != NME;) {
NamedMDNode *NMD = NMI;
++NMI;
if (NMD->getName().startswith("llvm.dbg.")) {
NMD->eraseFromParent();
Changed = true;
}
}
for (Module::iterator MI = M.begin(), ME = M.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) {
if (!BI->getDebugLoc().isUnknown()) {
Changed = true;
BI->setDebugLoc(DebugLoc());
}
}
return Changed;
}
示例4: DEBUG
bool MipsOs16::runOnModule(Module &M) {
DEBUG(errs() << "Run on Module MipsOs16\n");
bool modified = false;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->isDeclaration()) continue;
DEBUG(dbgs() << "Working on " << F->getName() << "\n");
if (needsFP(*F)) {
DEBUG(dbgs() << " need to compile as nomips16 \n");
F->addFnAttr("nomips16");
}
else {
F->addFnAttr("mips16");
DEBUG(dbgs() << " no need to compile as nomips16 \n");
}
}
return modified;
}
示例5: unwrap
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
// all the functions in a module, so we do that manually here. You'll find
// similar code in clang's BackendUtil.cpp file.
extern "C" void
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
llvm::legacy::FunctionPassManager *P = unwrap<llvm::legacy::FunctionPassManager>(PM);
P->doInitialization();
// Upgrade all calls to old intrinsics first.
for (Module::iterator I = unwrap(M)->begin(),
E = unwrap(M)->end(); I != E;)
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
for (Module::iterator I = unwrap(M)->begin(),
E = unwrap(M)->end(); I != E; ++I)
if (!I->isDeclaration())
P->run(*I);
P->doFinalization();
}
示例6: runOnModule
bool IDManager::runOnModule(Module &M) {
IDMapping.clear();
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
for (Function::iterator B = F->begin(); B != F->end(); ++B) {
for (BasicBlock::iterator I = B->begin(); I != B->end(); ++I) {
unsigned InsID = getInstructionID(I);
if (InsID != INVALID_ID)
IDMapping[InsID].push_back(I);
}
}
}
if (size() == 0)
errs() << "[Warning] No ID information in this program.\n";
return false;
}
示例7: findFunctionScopedAllocas
/// findFunctionScopedAllocas - store all allocas that are known to be valid
/// to the end of their function in a set. The current algorithm does this by
/// finding all the allocas in the entry block that are before the first
/// llvm.stacksave call (if any).
///
/// FIXME: There can also be allocas elsewhere that get deallocated at the end
/// of the function but they are pessimistically ignored for now.
///
void ExactCheckOpt::findFunctionScopedAllocas(Module &M) {
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->empty())
continue;
BasicBlock &BB = F->getEntryBlock();
for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
FunctionScopedAllocas.insert(AI);
} else if(CallInst *CI = dyn_cast<CallInst>(I)) {
Function *CalledFunction = CI->getCalledFunction();
if (CalledFunction && CalledFunction->getName() == "llvm.stacksave")
break;
}
}
}
}
示例8: if
/// deleteInstructionFromProgram - This method clones the current Program and
/// deletes the specified instruction from the cloned module. It then runs a
/// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code which
/// depends on the value. The modified module is then returned.
///
Module *BugDriver::deleteInstructionFromProgram(const Instruction *I,
unsigned Simplification) const {
Module *Result = CloneModule(Program);
const BasicBlock *PBB = I->getParent();
const Function *PF = PBB->getParent();
Module::iterator RFI = Result->begin(); // Get iterator to corresponding fn
std::advance(RFI, std::distance(PF->getParent()->begin(),
Module::const_iterator(PF)));
Function::iterator RBI = RFI->begin(); // Get iterator to corresponding BB
std::advance(RBI, std::distance(PF->begin(), Function::const_iterator(PBB)));
BasicBlock::iterator RI = RBI->begin(); // Get iterator to corresponding inst
std::advance(RI, std::distance(PBB->begin(), BasicBlock::const_iterator(I)));
Instruction *TheInst = RI; // Got the corresponding instruction!
// If this instruction produces a value, replace any users with null values
if (isa<StructType>(TheInst->getType()))
TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType()));
else if (TheInst->getType() != Type::getVoidTy(I->getContext()))
TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType()));
// Remove the instruction from the program.
TheInst->getParent()->getInstList().erase(TheInst);
//writeProgramToFile("current.bc", Result);
// Spiff up the output a little bit.
PassManager Passes;
// Make sure that the appropriate target data is always used...
Passes.add(new TargetData(Result));
/// FIXME: If this used runPasses() like the methods below, we could get rid
/// of the -disable-* options!
if (Simplification > 1 && !NoDCE)
Passes.add(createDeadCodeEliminationPass());
if (Simplification && !DisableSimplifyCFG)
Passes.add(createCFGSimplificationPass()); // Delete dead control flow
Passes.add(createVerifierPass());
Passes.run(*Result);
return Result;
}
示例9: checkFeatures
// Check the assumptions we made.
void CheckInserter::checkFeatures(Module &M) {
// Assume no function name starts with Loom.
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
assert(!F->getName().startswith("Loom") &&
"Loom update engine seems already instrumented");
}
// We do not support the situation where some important functions are called
// via a function pointer, e.g. pthread_create, pthread_join and fork.
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
if (F->getName() == "pthread_create" ||
F->getName() == "pthread_join" ||
F->getName() == "fork") {
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);
}
}
}
// pthread_cancel provides another way of terminating a thread, which we have
// not supported yet.
assert(M.getFunction("pthread_cancel") == NULL);
}
示例10:
/// Emit extern decls for functions imported from other modules, and emit
/// global declarations for function defined in this module and which are
/// available to other modules.
///
void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
// Emit declarations for external functions.
O <<"\n"<<MAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
if (I->isIntrinsic() || I->getName() == "@abort")
continue;
if (!I->isDeclaration() && !I->hasExternalLinkage())
continue;
MCSymbol *Sym = Mang->getSymbol(I);
// Do not emit memcpy, memset, and memmove here.
// Calls to these routines can be generated in two ways,
// 1. User calling the standard lib function
// 2. Codegen generating these calls for llvm intrinsics.
// In the first case a prototype is alread availale, while in
// second case the call is via and externalsym and the prototype is missing.
// So declarations for these are currently always getting printing by
// tracking both kind of references in printInstrunction.
if (I->isDeclaration() && PAN::isMemIntrinsic(Sym->getName())) continue;
const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
MAI->getGlobalDirective();
O << directive << Sym->getName() << "\n";
O << directive << PAN::getRetvalLabel(Sym->getName()) << "\n";
O << directive << PAN::getArgsLabel(Sym->getName()) << "\n";
}
O << MAI->getCommentString() << "Function Declarations - END." <<"\n";
}
示例11: runOnModule
bool DivCheckPass::runOnModule(Module &M) {
Function *divZeroCheckFunction = 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 [s|u][div|mod] instructions
Instruction::BinaryOps opcode = binOp->getOpcode();
if (opcode == Instruction::SDiv || opcode == Instruction::UDiv ||
opcode == Instruction::SRem || opcode == Instruction::URem) {
CastInst *denominator =
CastInst::CreateIntegerCast(i->getOperand(1),
Type::getInt64Ty(ctx),
false, /* sign doesn't matter */
"int_cast_to_i64",
&*i);
// Lazily bind the function to avoid always importing it.
if (!divZeroCheckFunction) {
Constant *fc = M.getOrInsertFunction("klee_div_zero_check",
Type::getVoidTy(ctx),
Type::getInt64Ty(ctx),
NULL);
divZeroCheckFunction = cast<Function>(fc);
}
CallInst * ci = CallInst::Create(divZeroCheckFunction, denominator, "", &*i);
// Set debug location of checking call to that of the div/rem
// operation so error locations are reported in the correct
// location.
ci->setDebugLoc(binOp->getDebugLoc());
moduleChanged = true;
}
}
}
}
}
return moduleChanged;
}
示例12: 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;
}
示例13: collectMainArguments
bool llvm::InputValues::runOnModule(Module& M) {
module = &M;
initializeWhiteList();
collectMainArguments();
for(Module::iterator Fit = M.begin(), Fend = M.end(); Fit != Fend; Fit++){
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 (CallInst *CI = dyn_cast<CallInst>(Iit)) {
if (isMarkedCallInst(CI)){
//Values returned by marked instructions
insertInInputDepValues(CI);
for(unsigned int i = 0; i < CI->getNumOperands(); i++){
if (CI->getOperand(i)->getType()->isPointerTy()){
//Arguments with pointer type of marked functions
insertInInputDepValues(CI->getOperand(i));
}
}
}
}
}
}
}
NumInputValues = inputValues.size();
//We don't modify anything, so we must return false;
return false;
}
示例14: CloneModule
std::unique_ptr<Module>
BugDriver::deleteInstructionFromProgram(const Instruction *I,
unsigned Simplification) {
// FIXME, use vmap?
Module *Clone = CloneModule(Program);
const BasicBlock *PBB = I->getParent();
const Function *PF = PBB->getParent();
Module::iterator RFI = Clone->begin(); // Get iterator to corresponding fn
std::advance(RFI, std::distance(PF->getParent()->begin(),
Module::const_iterator(PF)));
Function::iterator RBI = RFI->begin(); // Get iterator to corresponding BB
std::advance(RBI, std::distance(PF->begin(), Function::const_iterator(PBB)));
BasicBlock::iterator RI = RBI->begin(); // Get iterator to corresponding inst
std::advance(RI, std::distance(PBB->begin(), BasicBlock::const_iterator(I)));
Instruction *TheInst = RI; // Got the corresponding instruction!
// If this instruction produces a value, replace any users with null values
if (!TheInst->getType()->isVoidTy())
TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType()));
// Remove the instruction from the program.
TheInst->getParent()->getInstList().erase(TheInst);
// Spiff up the output a little bit.
std::vector<std::string> Passes;
/// Can we get rid of the -disable-* options?
if (Simplification > 1 && !NoDCE)
Passes.push_back("dce");
if (Simplification && !DisableSimplifyCFG)
Passes.push_back("simplifycfg"); // Delete dead control flow
Passes.push_back("verify");
std::unique_ptr<Module> New = runPassesOn(Clone, Passes);
delete Clone;
if (!New) {
errs() << "Instruction removal failed. Sorry. :( Please report a bug!\n";
exit(1);
}
return New;
}
示例15: runOnModule
bool StripAttributes::runOnModule(Module &M) {
DataLayout DL(&M);
for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) {
// Avoid stripping attributes from intrinsics because the
// constructor for Functions just adds them back again. It would
// be confusing if the attributes were sometimes present on
// intrinsics and sometimes not.
if (!Func->isIntrinsic()) {
stripGlobalValueAttrs(Func);
stripFunctionAttrs(&DL, Func);
}
}
for (Module::global_iterator GV = M.global_begin(), E = M.global_end();
GV != E; ++GV) {
stripGlobalValueAttrs(GV);
}
return true;
}