本文整理汇总了C++中module::iterator::isDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::isDeclaration方法的具体用法?C++ iterator::isDeclaration怎么用?C++ iterator::isDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类module::iterator
的用法示例。
在下文中一共展示了iterator::isDeclaration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EmitAssembly
void EmitAssemblyHelper::EmitAssembly(BackendAction Action, raw_ostream *OS) {
TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : 0);
llvm::formatted_raw_ostream FormattedOS;
bool UsesCodeGen = (Action != Backend_EmitNothing &&
Action != Backend_EmitBC &&
Action != Backend_EmitLL);
if (!TM)
TM.reset(CreateTargetMachine(UsesCodeGen));
if (UsesCodeGen && !TM) return;
CreatePasses();
switch (Action) {
case Backend_EmitNothing:
break;
case Backend_EmitBC:
getPerModulePasses()->add(createBitcodeWriterPass(*OS));
break;
case Backend_EmitLL:
FormattedOS.setStream(*OS, formatted_raw_ostream::PRESERVE_STREAM);
getPerModulePasses()->add(createPrintModulePass(&FormattedOS));
break;
default:
FormattedOS.setStream(*OS, formatted_raw_ostream::PRESERVE_STREAM);
if (!AddEmitPasses(Action, FormattedOS))
return;
}
// Before executing passes, print the final values of the LLVM options.
cl::PrintOptionValues();
// Run passes. For now we do all passes at once, but eventually we
// would like to have the option of streaming code generation.
if (PerFunctionPasses) {
PrettyStackTraceString CrashInfo("Per-function optimization");
PerFunctionPasses->doInitialization();
for (Module::iterator I = TheModule->begin(),
E = TheModule->end(); I != E; ++I)
if (!I->isDeclaration())
PerFunctionPasses->run(*I);
PerFunctionPasses->doFinalization();
}
if (PerModulePasses) {
PrettyStackTraceString CrashInfo("Per-module optimization passes");
PerModulePasses->run(*TheModule);
}
if (CodeGenPasses) {
PrettyStackTraceString CrashInfo("Code generation");
CodeGenPasses->run(*TheModule);
}
}
示例2: runOnModule
// run - On a module, we run this pass by initializing, runOnFunction'ing once
// for every function in the module, then by finalizing.
//
bool FunctionPass::runOnModule(Module &M) {
bool Changed = doInitialization(M);
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration()) // Passes are not run on external functions!
Changed |= runOnFunction(*I);
return Changed | doFinalization(M);
}
示例3: buildFunctionRefs
// create a reference table for functions defined in the path profile file
void PathProfileLoaderPass::buildFunctionRefs (Module &M) {
_functions.push_back(0); // make the 0 index a null pointer
for (Module::iterator F = M.begin(), E = M.end(); F != E; F++) {
if (F->isDeclaration())
continue;
_functions.push_back(F);
}
}
示例4: runOnModule
bool CreateIDBitcode::runOnModule(Module &M) {
for(Module::iterator f = M.begin(), fe = M.end(); f != fe; f++) {
if (!f->isDeclaration()) {
runOnFunction(*f);
}
}
return true;
}
示例5: 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) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
instrumentInstructionIfNecessary(I);
}
}
// 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;
}
示例6: doInitialization
/// doInitialization - If this module uses the GC intrinsics, find them now.
bool LowerIntrinsics::doInitialization(Module &M) {
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?");
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration() && I->hasGC())
MI->getFunctionInfo(*I); // Instantiate the GC strategy.
return false;
}
示例7: 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();
}
}
}
}
}
示例8: doInitialization
// doInitialization - Initializes the vector of functions that have not
// been annotated with the "always inline" attribute.
bool AlwaysInliner::doInitialization(CallGraph &CG) {
Module &M = CG.getModule();
for (Module::iterator I = M.begin(), E = M.end();
I != E; ++I)
if (!I->isDeclaration() && !I->hasFnAttr(Attribute::AlwaysInline))
NeverInline.insert(I);
return false;
}
示例9: elimConstExpr
ProgramStructure::ProgramStructure(Module &M) {
for (Module::iterator f = M.begin(); f != M.end(); ++f)
if (!f->isDeclaration() && !memoryManStuff(&*f))
for (inst_iterator i = inst_begin(*f); i != inst_end(*f); ++i)
if (const StoreInst *s = dyn_cast<StoreInst>(&*i)) {
const Value *l = elimConstExpr(s->getPointerOperand());
this->getContainer()[&*f].push_back(ProgramStructure::Command(
hasExtraReference(l) ? CMD_VAR : CMD_DREF_VAR, l));
}
}
示例10: DEBUG
//
// This pass only makes sense when the underlying chip has floating point but
// we are compiling as mips16.
// For all mips16 functions (that are not stubs we have already generated), or
// declared via attributes as nomips16, we must:
// 1) fixup all returns of float, double, single and double complex
// by calling a helper function before the actual return.
// 2) generate helper functions (stubs) that can be called by mips32 functions
// that will move parameters passed normally passed in floating point
// registers the soft float equivalents. (Coming in a later patch).
// 3) in the case of static relocation, generate helper functions so that
// mips16 functions can call extern functions of unknown type (mips16 or
// mips32). (Coming in a later patch).
// 4) TBD. For pic, calls to extern functions of unknown type are handled by
// predefined helper functions in libc but this work is currently done
// during call lowering but it should be moved here in the future.
//
bool Mips16HardFloat::runOnModule(Module &M) {
DEBUG(errs() << "Run on Module Mips16HardFloat\n");
bool Modified = false;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->isDeclaration() || F->hasFnAttribute("mips16_fp_stub") ||
F->hasFnAttribute("nomips16")) continue;
Modified |= fixupFPReturnAndCall(*F, &M, Subtarget);
}
return Modified;
}
示例11: 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) {
FunctionPassManager *P = unwrap<FunctionPassManager>(PM);
P->doInitialization();
for (Module::iterator I = unwrap(M)->begin(),
E = unwrap(M)->end(); I != E; ++I)
if (!I->isDeclaration())
P->run(*I);
P->doFinalization();
}
示例12: sliceModule
bool StaticSlicer::sliceModule() {
bool modified = false;
for (Slicers::iterator s = slicers.begin(); s != slicers.end(); ++s)
modified |= s->second->slice();
if (modified)
for (Module::iterator I = module.begin(), E = module.end(); I != E; ++I)
if (!I->isDeclaration())
FunctionStaticSlicer::removeUndefBranches(MP, *I);
return modified;
}
示例13: runOnModule
bool MergeFunctions::runOnModule(Module &M) {
bool Changed = false;
std::map<unsigned long, std::vector<Function *> > FnMap;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->isDeclaration() || F->isIntrinsic())
continue;
if (!F->hasLocalLinkage() && !F->hasExternalLinkage() &&
!F->hasWeakLinkage())
continue;
if (hasAddressTaken(F))
continue;
FnMap[hash(F)].push_back(F);
}
// TODO: instead of running in a loop, we could also fold functions in callgraph
// order. Constructing the CFG probably isn't cheaper than just running in a loop.
bool LocalChanged;
do {
LocalChanged = false;
for (std::map<unsigned long, std::vector<Function *> >::iterator
I = FnMap.begin(), E = FnMap.end(); I != E; ++I) {
DOUT << "size: " << FnMap.size() << "\n";
std::vector<Function *> &FnVec = I->second;
DOUT << "hash (" << I->first << "): " << FnVec.size() << "\n";
for (int i = 0, e = FnVec.size(); i != e; ++i) {
for (int j = i + 1; j != e; ++j) {
bool isEqual = equals(FnVec[i], FnVec[j]);
DOUT << " " << FnVec[i]->getName()
<< (isEqual ? " == " : " != ")
<< FnVec[j]->getName() << "\n";
if (isEqual) {
if (fold(FnVec, i, j)) {
LocalChanged = true;
FnVec.erase(FnVec.begin() + j);
--j, --e;
}
}
}
}
}
Changed |= LocalChanged;
} while (LocalChanged);
return Changed;
}
示例14: runOverwrittenDeadStoreAnalysis
/*
* Find stores to arguments that are overwritten before being read.
*/
void DeadStoreEliminationPass::runOverwrittenDeadStoreAnalysis(Module &M) {
DEBUG(errs() << "Running overwritten dead store analysis...\n");
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (!F->isDeclaration()) {
FunctionsCount++;
CallsCount += F->getNumUses();
runOverwrittenDeadStoreAnalysisOnFn(*F);
}
}
DEBUG(errs() << "\n");
}
示例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();
}
}
// Sequential types except pointer types shouldn't be used as the type of
// an instruction, a function parameter, or a global variable.
for (Module::global_iterator GI = M.global_begin(), E = M.global_end();
GI != E; ++GI) {
if (isa<SequentialType>(GI->getType()))
assert(GI->getType()->isPointerTy());
}
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 (isa<SequentialType>(AI->getType()))
assert(AI->getType()->isPointerTy());
}
}
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 (isa<SequentialType>(Ins->getType()))
assert(Ins->getType()->isPointerTy());
}
}
}
// We don't support multi-process programs for now.
if (!HookFork)
assert(M.getFunction("fork") == NULL);
}