本文整理汇总了C++中module::const_iterator类的典型用法代码示例。如果您正苦于以下问题:C++ const_iterator类的具体用法?C++ const_iterator怎么用?C++ const_iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了const_iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteModule
/// WriteModule - Emit the specified module to the bitstream.
static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) {
DEBUG(dbgs() << "-> WriteModule\n");
Stream.EnterSubblock(naclbitc::MODULE_BLOCK_ID);
SmallVector<unsigned, 1> Vals;
unsigned CurVersion = 1;
Vals.push_back(CurVersion);
Stream.EmitRecord(naclbitc::MODULE_CODE_VERSION, Vals);
// Analyze the module, enumerating globals, functions, etc.
NaClValueEnumerator VE(M);
OptimizeTypeIdEncoding(VE);
// Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream);
// Emit information describing all of the types in the module.
WriteTypeTable(VE, Stream);
// Emit top-level description of module, including inline asm,
// descriptors for global variables, and function prototype info.
WriteModuleInfo(M, VE, Stream);
// Emit names for globals/functions etc.
WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream);
// Emit function bodies.
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F)
if (!F->isDeclaration())
WriteFunction(*F, VE, Stream);
Stream.ExitBlock();
DEBUG(dbgs() << "<- WriteModule\n");
}
示例2: WriteModuleInfo
// Emit top-level description of module, including inline asm,
// descriptors for global variables, and function prototype info.
static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE,
NaClBitstreamWriter &Stream) {
DEBUG(dbgs() << "-> WriteModuleInfo\n");
// Emit the function proto information. Note: We do this before
// global variables, so that global variable initializations can
// refer to the functions without a forward reference.
SmallVector<unsigned, 64> Vals;
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
// FUNCTION: [type, callingconv, isproto, linkage]
Type *Ty = F->getType()->getPointerElementType();
Vals.push_back(VE.getTypeID(Ty));
Vals.push_back(GetEncodedCallingConv(F->getCallingConv()));
Vals.push_back(F->isDeclaration());
Vals.push_back(getEncodedLinkage(F));
unsigned AbbrevToUse = 0;
Stream.EmitRecord(naclbitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
Vals.clear();
}
// Emit the global variable information.
WriteGlobalVars(M, VE, Stream);
DEBUG(dbgs() << "<- WriteModuleInfo\n");
}
示例3: printExternalMethods
/**
* Print the list of external methods.
*/
void JVMWriter::printExternalMethods() {
out << "; External methods\n";
for(Module::const_iterator i = module->begin(),
e = module->end(); i != e; i++) {
if(i->isDeclaration() && !i->isIntrinsic()) {
const Function *f = i;
const FunctionType *ty = f->getFunctionType();
out << ".extern method "
<< getValueName(f) << getCallSignature(ty);
if(debug >= 3)
out << " ; " << *ty;
out << '\n';
externRefs.insert(f);
}
}
out << '\n';
}
示例4: main
int main(int argc, char** argv) {
cl::ParseCommandLineOptions(argc, argv, "LLVM hello world\n");
LLVMContext context;
//std::unique_ptr<MemoryBuffer> mb;
DiagnosticHandlerFunction dhf;
ErrorOr<std::unique_ptr<MemoryBuffer>> mb = MemoryBuffer::getFile(FileName); // here we got segmentation fault
if (std::error_code EC = mb.getError()) {
std::cout<< "Could not open input file: " + EC.message();
}
ErrorOr<Module *> moduleOrError = parseBitcodeFile(mb.get()->getMemBufferRef() , context, dhf);
if(std::error_code() ){
std::cerr << "Error reading bitcode: " << std::error_code() << std::endl;
return -1;
}
raw_os_ostream O(std::cout);
Module * m = moduleOrError.get();
for (Module::const_iterator i = m -> getFunctionList().begin(), e = m -> getFunctionList().end(); i != e; ++i ) {
if(!i->isDeclaration()){
O << i->getName() << " has "<< i -> size() << "basic block(s).\n";
}
}
//O<<"ok";
return 0;
}
示例5: Run
void TypeFinder::Run(const Module &M) {
AddModuleTypesToPrinter(TP,&M);
// Get types from the type symbol table. This gets opaque types referened
// only through derived named types.
const TypeSymbolTable &ST = M.getTypeSymbolTable();
for (TypeSymbolTable::const_iterator TI = ST.begin(), E = ST.end();
TI != E; ++TI)
IncorporateType(TI->second);
// Get types from global variables.
for (Module::const_global_iterator I = M.global_begin(),
E = M.global_end(); I != E; ++I) {
IncorporateType(I->getType());
if (I->hasInitializer())
IncorporateValue(I->getInitializer());
}
// Get types from aliases.
for (Module::const_alias_iterator I = M.alias_begin(),
E = M.alias_end(); I != E; ++I) {
IncorporateType(I->getType());
IncorporateValue(I->getAliasee());
}
// Get types from functions.
for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
IncorporateType(FI->getType());
for (Function::const_iterator BB = FI->begin(), E = FI->end();
BB != E;++BB)
for (BasicBlock::const_iterator II = BB->begin(),
E = BB->end(); II != E; ++II) {
const Instruction &I = *II;
// Incorporate the type of the instruction and all its operands.
IncorporateType(I.getType());
for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
OI != OE; ++OI)
IncorporateValue(*OI);
}
}
}
示例6: buildCallMaps
void buildCallMaps(Module const& M, FunctionsMap& F,
CallsMap& C) {
for (Module::const_iterator f = M.begin(); f != M.end(); ++f) {
if (!f->isDeclaration())
F.insert(std::make_pair(f->getFunctionType(), &*f));
for (Function::const_iterator b = f->begin(); b != f->end(); ++b) {
for (BasicBlock::const_iterator i = b->begin(); i != b->end(); ++i)
if (const CallInst *CI = dyn_cast<CallInst>(&*i)) {
if (!isInlineAssembly(CI) && !callToMemoryManStuff(CI))
C.insert(std::make_pair(getCalleePrototype(CI), CI));
} else if (const StoreInst *SI = dyn_cast<StoreInst>(&*i)) {
const Value *r = SI->getValueOperand();
if (hasExtraReference(r) && memoryManStuff(r)) {
const Function *fn = dyn_cast<Function>(r);
F.insert(std::make_pair(fn->getFunctionType(), fn));
}
}
}
}
}
示例7: run
void TypeFinder::run(const Module &M, bool onlyNamed) {
OnlyNamed = onlyNamed;
// Get types from global variables.
for (Module::const_global_iterator I = M.global_begin(),
E = M.global_end(); I != E; ++I) {
incorporateType(I->getType());
if (I->hasInitializer())
incorporateValue(I->getInitializer());
}
// Get types from aliases.
for (Module::const_alias_iterator I = M.alias_begin(),
E = M.alias_end(); I != E; ++I) {
incorporateType(I->getType());
if (const Value *Aliasee = I->getAliasee())
incorporateValue(Aliasee);
}
// Get types from functions.
SmallVector<std::pair<unsigned, MDNode *>, 4> MDForInst;
for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
incorporateType(FI->getType());
if (FI->hasPrefixData())
incorporateValue(FI->getPrefixData());
if (FI->hasPrologueData())
incorporateValue(FI->getPrologueData());
if (FI->hasPersonalityFn())
incorporateValue(FI->getPersonalityFn());
// First incorporate the arguments.
for (Function::const_arg_iterator AI = FI->arg_begin(),
AE = FI->arg_end(); AI != AE; ++AI)
incorporateValue(AI);
for (Function::const_iterator BB = FI->begin(), E = FI->end();
BB != E; ++BB)
for (BasicBlock::const_iterator II = BB->begin(),
E = BB->end(); II != E; ++II) {
const Instruction &I = *II;
// Incorporate the type of the instruction.
incorporateType(I.getType());
// Incorporate non-instruction operand types. (We are incorporating all
// instructions with this loop.)
for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
OI != OE; ++OI)
if (*OI && !isa<Instruction>(OI))
incorporateValue(*OI);
// Incorporate types hiding in metadata.
I.getAllMetadataOtherThanDebugLoc(MDForInst);
for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
incorporateMDNode(MDForInst[i].second);
MDForInst.clear();
}
}
for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
E = M.named_metadata_end(); I != E; ++I) {
const NamedMDNode *NMD = I;
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
incorporateMDNode(NMD->getOperand(i));
}
}
示例8: Module
Module *llvm::CloneModule(const Module *M, ValueToValueMapTy &VMap) {
// First off, we need to create the new module.
Module *New = new Module(M->getModuleIdentifier(), M->getContext());
New->setDataLayout(M->getDataLayout());
New->setTargetTriple(M->getTargetTriple());
New->setModuleInlineAsm(M->getModuleInlineAsm());
// Loop over all of the global variables, making corresponding globals in the
// 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(),
I->isConstant(), I->getLinkage(),
(Constant*) nullptr, I->getName(),
(GlobalVariable*) nullptr,
I->getThreadLocalMode(),
I->getType()->getAddressSpace());
GV->copyAttributesFrom(I);
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()),
I->getLinkage(), 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) {
auto *PTy = cast<PointerType>(I->getType());
auto *GA =
GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
I->getLinkage(), I->getName(), New);
GA->copyAttributesFrom(I);
VMap[I] = GA;
}
// 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(MapValue(I->getInitializer(), VMap));
}
// 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, /*ModuleLevelChanges=*/true, Returns);
}
}
// And aliases
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I) {
GlobalAlias *GA = cast<GlobalAlias>(VMap[I]);
if (const Constant *C = I->getAliasee())
GA->setAliasee(cast<GlobalObject>(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;
NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
NewNMD->addOperand(MapValue(NMD.getOperand(i), VMap));
}
return New;
}
示例9: if
/// ValueEnumerator - Enumerate module-level information.
ValueEnumerator::ValueEnumerator(const Module *M) {
// Enumerate the global variables.
for (Module::const_global_iterator I = M->global_begin(),
E = M->global_end(); I != E; ++I)
EnumerateValue(I);
// Enumerate the functions.
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
EnumerateValue(I);
EnumerateAttributes(cast<Function>(I)->getAttributes());
}
// Enumerate the aliases.
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I)
EnumerateValue(I);
// Remember what is the cutoff between globalvalue's and other constants.
unsigned FirstConstant = Values.size();
// Enumerate the global variable initializers.
for (Module::const_global_iterator I = M->global_begin(),
E = M->global_end(); I != E; ++I)
if (I->hasInitializer())
EnumerateValue(I->getInitializer());
// Enumerate the aliasees.
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I)
EnumerateValue(I->getAliasee());
// Insert constants and metadata that are named at module level into the slot
// pool so that the module symbol table can refer to them...
EnumerateValueSymbolTable(M->getValueSymbolTable());
EnumerateNamedMetadata(M);
SmallVector<std::pair<unsigned, MDNode*>, 8> MDs;
// Enumerate types used by function bodies and argument lists.
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) {
for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
I != E; ++I)
EnumerateType(I->getType());
for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
OI != E; ++OI) {
if (MDNode *MD = dyn_cast<MDNode>(*OI))
if (MD->isFunctionLocal() && MD->getFunction())
// These will get enumerated during function-incorporation.
continue;
EnumerateOperandType(*OI);
}
EnumerateType(I->getType());
if (const CallInst *CI = dyn_cast<CallInst>(I))
EnumerateAttributes(CI->getAttributes());
else if (const InvokeInst *II = dyn_cast<InvokeInst>(I))
EnumerateAttributes(II->getAttributes());
// Enumerate metadata attached with this instruction.
MDs.clear();
I->getAllMetadataOtherThanDebugLoc(MDs);
for (unsigned i = 0, e = MDs.size(); i != e; ++i)
EnumerateMetadata(MDs[i].second);
if (!I->getDebugLoc().isUnknown()) {
MDNode *Scope, *IA;
I->getDebugLoc().getScopeAndInlinedAt(Scope, IA, I->getContext());
if (Scope) EnumerateMetadata(Scope);
if (IA) EnumerateMetadata(IA);
}
}
}
// Optimize constant ordering.
OptimizeConstants(FirstConstant, Values.size());
}
示例10: ReduceInsts
static Error ReduceInsts(BugDriver &BD,
bool (*TestFn)(const BugDriver &, Module *)) {
// Attempt to delete instructions using bisection. This should help out nasty
// cases with large basic blocks where the problem is at one end.
if (!BugpointIsInterrupted) {
std::vector<const Instruction *> Insts;
for (const Function &F : *BD.getProgram())
for (const BasicBlock &BB : F)
for (const Instruction &I : BB)
if (!isa<TerminatorInst>(&I))
Insts.push_back(&I);
Expected<bool> Result =
ReduceCrashingInstructions(BD, TestFn).reduceList(Insts);
if (Error E = Result.takeError())
return E;
}
unsigned Simplification = 2;
do {
if (BugpointIsInterrupted)
// TODO: Should we distinguish this with an "interrupted error"?
return Error::success();
--Simplification;
outs() << "\n*** Attempting to reduce testcase by deleting instruc"
<< "tions: Simplification Level #" << Simplification << '\n';
// Now that we have deleted the functions that are unnecessary for the
// program, try to remove instructions that are not necessary to cause the
// crash. To do this, we loop through all of the instructions in the
// remaining functions, deleting them (replacing any values produced with
// nulls), and then running ADCE and SimplifyCFG. If the transformed input
// still triggers failure, keep deleting until we cannot trigger failure
// anymore.
//
unsigned InstructionsToSkipBeforeDeleting = 0;
TryAgain:
// Loop over all of the (non-terminator) instructions remaining in the
// function, attempting to delete them.
unsigned CurInstructionNum = 0;
for (Module::const_iterator FI = BD.getProgram()->begin(),
E = BD.getProgram()->end();
FI != E; ++FI)
if (!FI->isDeclaration())
for (Function::const_iterator BI = FI->begin(), E = FI->end(); BI != E;
++BI)
for (BasicBlock::const_iterator I = BI->begin(), E = --BI->end();
I != E; ++I, ++CurInstructionNum) {
if (InstructionsToSkipBeforeDeleting) {
--InstructionsToSkipBeforeDeleting;
} else {
if (BugpointIsInterrupted)
// TODO: Should this be some kind of interrupted error?
return Error::success();
if (I->isEHPad() || I->getType()->isTokenTy())
continue;
outs() << "Checking instruction: " << *I;
std::unique_ptr<Module> M =
BD.deleteInstructionFromProgram(&*I, Simplification);
// Find out if the pass still crashes on this pass...
if (TestFn(BD, M.get())) {
// Yup, it does, we delete the old module, and continue trying
// to reduce the testcase...
BD.setNewProgram(M.release());
InstructionsToSkipBeforeDeleting = CurInstructionNum;
goto TryAgain; // I wish I had a multi-level break here!
}
}
}
if (InstructionsToSkipBeforeDeleting) {
InstructionsToSkipBeforeDeleting = 0;
goto TryAgain;
}
} while (Simplification);
BD.EmitProgressBitcode(BD.getProgram(), "reduced-instructions");
return Error::success();
}
示例11: externalsAndGlobalsCheck
void externalsAndGlobalsCheck(const Module *m) {
std::map<std::string, bool> externals;
std::set<std::string> modelled(modelledExternals,
modelledExternals+NELEMS(modelledExternals));
std::set<std::string> dontCare(dontCareExternals,
dontCareExternals+NELEMS(dontCareExternals));
std::set<std::string> unsafe(unsafeExternals,
unsafeExternals+NELEMS(unsafeExternals));
switch (Libc) {
case KleeLibc:
dontCare.insert(dontCareKlee, dontCareKlee+NELEMS(dontCareKlee));
break;
case UcLibc:
dontCare.insert(dontCareUclibc,
dontCareUclibc+NELEMS(dontCareUclibc));
break;
case NoLibc: /* silence compiler warning */
break;
}
if (WithPOSIXRuntime)
dontCare.insert("syscall");
for (Module::const_iterator fnIt = m->begin(), fn_ie = m->end();
fnIt != fn_ie; ++fnIt) {
if (fnIt->isDeclaration() && !fnIt->use_empty())
externals.insert(std::make_pair(fnIt->getName(), false));
for (Function::const_iterator bbIt = fnIt->begin(), bb_ie = fnIt->end();
bbIt != bb_ie; ++bbIt) {
for (BasicBlock::const_iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
if (const CallInst *ci = dyn_cast<CallInst>(it)) {
if (isa<InlineAsm>(ci->getCalledValue())) {
klee_warning_once(&*fnIt,
"function \"%s\" has inline asm",
fnIt->getName().data());
}
}
}
}
}
for (Module::const_global_iterator
it = m->global_begin(), ie = m->global_end();
it != ie; ++it)
if (it->isDeclaration() && !it->use_empty())
externals.insert(std::make_pair(it->getName(), true));
// and remove aliases (they define the symbol after global
// initialization)
for (Module::const_alias_iterator
it = m->alias_begin(), ie = m->alias_end();
it != ie; ++it) {
std::map<std::string, bool>::iterator it2 =
externals.find(it->getName());
if (it2!=externals.end())
externals.erase(it2);
}
std::map<std::string, bool> foundUnsafe;
for (std::map<std::string, bool>::iterator
it = externals.begin(), ie = externals.end();
it != ie; ++it) {
const std::string &ext = it->first;
if (!modelled.count(ext) && (WarnAllExternals ||
!dontCare.count(ext))) {
if (unsafe.count(ext)) {
foundUnsafe.insert(*it);
} else {
klee_warning("undefined reference to %s: %s",
it->second ? "variable" : "function",
ext.c_str());
}
}
}
for (std::map<std::string, bool>::iterator
it = foundUnsafe.begin(), ie = foundUnsafe.end();
it != ie; ++it) {
const std::string &ext = it->first;
klee_warning("undefined reference to %s: %s (UNSAFE)!",
it->second ? "variable" : "function",
ext.c_str());
}
}
示例12: if
ValueEnumerator::ValueEnumerator(const Module &M,
bool ShouldPreserveUseListOrder)
: HasMDString(false), HasDILocation(false), HasGenericDINode(false),
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
if (ShouldPreserveUseListOrder)
UseListOrders = predictUseListOrder(M);
// Enumerate the global variables.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
EnumerateValue(I);
// Enumerate the functions.
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
EnumerateValue(I);
EnumerateAttributes(cast<Function>(I)->getAttributes());
}
// Enumerate the aliases.
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I)
EnumerateValue(I);
// Remember what is the cutoff between globalvalue's and other constants.
unsigned FirstConstant = Values.size();
// Enumerate the global variable initializers.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
if (I->hasInitializer())
EnumerateValue(I->getInitializer());
// Enumerate the aliasees.
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I)
EnumerateValue(I->getAliasee());
// Enumerate the prefix data constants.
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
if (I->hasPrefixData())
EnumerateValue(I->getPrefixData());
// Enumerate the prologue data constants.
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
if (I->hasPrologueData())
EnumerateValue(I->getPrologueData());
// Enumerate the metadata type.
//
// TODO: Move this to ValueEnumerator::EnumerateOperandType() once bitcode
// only encodes the metadata type when it's used as a value.
EnumerateType(Type::getMetadataTy(M.getContext()));
// Insert constants and metadata that are named at module level into the slot
// pool so that the module symbol table can refer to them...
EnumerateValueSymbolTable(M.getValueSymbolTable());
EnumerateNamedMetadata(M);
SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
// Enumerate types used by function bodies and argument lists.
for (const Function &F : M) {
for (const Argument &A : F.args())
EnumerateType(A.getType());
// Enumerate metadata attached to this function.
F.getAllMetadata(MDs);
for (const auto &I : MDs)
EnumerateMetadata(I.second);
for (const BasicBlock &BB : F)
for (const Instruction &I : BB) {
for (const Use &Op : I.operands()) {
auto *MD = dyn_cast<MetadataAsValue>(&Op);
if (!MD) {
EnumerateOperandType(Op);
continue;
}
// Local metadata is enumerated during function-incorporation.
if (isa<LocalAsMetadata>(MD->getMetadata()))
continue;
EnumerateMetadata(MD->getMetadata());
}
EnumerateType(I.getType());
if (const CallInst *CI = dyn_cast<CallInst>(&I))
EnumerateAttributes(CI->getAttributes());
else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I))
EnumerateAttributes(II->getAttributes());
// Enumerate metadata attached with this instruction.
MDs.clear();
I.getAllMetadataOtherThanDebugLoc(MDs);
for (unsigned i = 0, e = MDs.size(); i != e; ++i)
EnumerateMetadata(MDs[i].second);
// Don't enumerate the location directly -- it has a special record
// type -- but enumerate its operands.
if (DILocation *L = I.getDebugLoc())
//.........这里部分代码省略.........
示例13: printCollection
static void printCollection(const Collection &C, llvm::raw_ostream &O,
const Module *M, const std::string &Prefix) {
if (M == 0) {
O << "Null Module pointer, cannot continue!\n";
return;
}
unsigned TotalNumNodes = 0, TotalCallNodes = 0;
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
if (C.hasDSGraph(*I)) {
DSGraph* Gr = C.getDSGraph((const Function&)*I);
unsigned NumCalls = Gr->shouldUseAuxCalls() ?
Gr->getAuxFunctionCalls().size() : Gr->getFunctionCalls().size();
bool IsDuplicateGraph = false;
//if no only print options, print everything
bool doPrint = OnlyPrint.begin() == OnlyPrint.end();
//otherwise check the name
if (!doPrint)
doPrint = OnlyPrint.end() !=
std::find(OnlyPrint.begin(), OnlyPrint.end(), I->getName().str());
if (doPrint) {
const Function *SCCFn = Gr->retnodes_begin()->first;
if (&*I == SCCFn) {
Gr->writeGraphToFile(O, Prefix+I->getName().str());
} else {
IsDuplicateGraph = true; // Don't double count node/call nodes.
O << "Didn't write '" << Prefix+I->getName().str()
<< ".dot' - Graph already emitted to '" << Prefix+SCCFn->getName().str()
<< "\n";
}
} else {
const Function *SCCFn = Gr->retnodes_begin()->first;
if (&*I == SCCFn) {
//O << "Skipped Writing '" << Prefix+I->getName().str() << ".dot'... ["
// << Gr->getGraphSize() << "+" << NumCalls << "]\n";
} else {
IsDuplicateGraph = true; // Don't double count node/call nodes.
}
}
if (!IsDuplicateGraph) {
unsigned GraphSize = Gr->getGraphSize();
if (MaxGraphSize < GraphSize) MaxGraphSize = GraphSize;
TotalNumNodes += Gr->getGraphSize();
TotalCallNodes += NumCalls;
for (DSGraph::node_iterator NI = Gr->node_begin(), E = Gr->node_end();
NI != E; ++NI)
if (NI->isNodeCompletelyFolded())
++NumFoldedNodes;
}
}
DSGraph* GG = C.getGlobalsGraph();
TotalNumNodes += GG->getGraphSize();
TotalCallNodes += GG->getFunctionCalls().size();
GG->writeGraphToFile(O, Prefix + "GlobalsGraph");
O << "\nGraphs contain [" << TotalNumNodes << "+" << TotalCallNodes
<< "] nodes total\n";
}
示例14: DebugACrash
//.........这里部分代码省略.........
for (BasicBlock &BB : F)
Blocks.push_back(&BB);
unsigned OldSize = Blocks.size();
ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
if (Blocks.size() < OldSize)
BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks");
}
// Attempt to delete instructions using bisection. This should help out nasty
// cases with large basic blocks where the problem is at one end.
if (!BugpointIsInterrupted) {
std::vector<const Instruction*> Insts;
for (const Function &F : *BD.getProgram())
for (const BasicBlock &BB : F)
for (const Instruction &I : BB)
if (!isa<TerminatorInst>(&I))
Insts.push_back(&I);
ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error);
}
// FIXME: This should use the list reducer to converge faster by deleting
// larger chunks of instructions at a time!
unsigned Simplification = 2;
do {
if (BugpointIsInterrupted) break;
--Simplification;
outs() << "\n*** Attempting to reduce testcase by deleting instruc"
<< "tions: Simplification Level #" << Simplification << '\n';
// Now that we have deleted the functions that are unnecessary for the
// program, try to remove instructions that are not necessary to cause the
// crash. To do this, we loop through all of the instructions in the
// remaining functions, deleting them (replacing any values produced with
// nulls), and then running ADCE and SimplifyCFG. If the transformed input
// still triggers failure, keep deleting until we cannot trigger failure
// anymore.
//
unsigned InstructionsToSkipBeforeDeleting = 0;
TryAgain:
// Loop over all of the (non-terminator) instructions remaining in the
// function, attempting to delete them.
unsigned CurInstructionNum = 0;
for (Module::const_iterator FI = BD.getProgram()->begin(),
E = BD.getProgram()->end(); FI != E; ++FI)
if (!FI->isDeclaration())
for (Function::const_iterator BI = FI->begin(), E = FI->end(); BI != E;
++BI)
for (BasicBlock::const_iterator I = BI->begin(), E = --BI->end();
I != E; ++I, ++CurInstructionNum) {
if (InstructionsToSkipBeforeDeleting) {
--InstructionsToSkipBeforeDeleting;
} else {
if (BugpointIsInterrupted) goto ExitLoops;
if (isa<LandingPadInst>(I))
continue;
outs() << "Checking instruction: " << *I;
std::unique_ptr<Module> M =
BD.deleteInstructionFromProgram(&*I, Simplification);
// Find out if the pass still crashes on this pass...
if (TestFn(BD, M.get())) {
// Yup, it does, we delete the old module, and continue trying
// to reduce the testcase...
BD.setNewProgram(M.release());
InstructionsToSkipBeforeDeleting = CurInstructionNum;
goto TryAgain; // I wish I had a multi-level break here!
}
}
}
if (InstructionsToSkipBeforeDeleting) {
InstructionsToSkipBeforeDeleting = 0;
goto TryAgain;
}
} while (Simplification);
ExitLoops:
// Try to clean up the testcase by running funcresolve and globaldce...
if (!BugpointIsInterrupted) {
outs() << "\n*** Attempting to perform final cleanups: ";
Module *M = CloneModule(BD.getProgram());
M = BD.performFinalCleanups(M, true).release();
// Find out if the pass still crashes on the cleaned up program...
if (TestFn(BD, M)) {
BD.setNewProgram(M); // Yup, it does, keep the reduced version...
} else {
delete M;
}
}
BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplified");
return false;
}
示例15: GlobalVariable
std::unique_ptr<Module> llvm::CloneModule(
const Module *M, ValueToValueMapTy &VMap,
std::function<bool(const GlobalValue *)> ShouldCloneDefinition) {
// First off, we need to create the new module.
std::unique_ptr<Module> New =
llvm::make_unique<Module>(M->getModuleIdentifier(), M->getContext());
New->setDataLayout(M->getDataLayout());
New->setTargetTriple(M->getTargetTriple());
New->setModuleInlineAsm(M->getModuleInlineAsm());
// Loop over all of the global variables, making corresponding globals in the
// 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->getValueType(),
I->isConstant(), I->getLinkage(),
(Constant*) nullptr, I->getName(),
(GlobalVariable*) nullptr,
I->getThreadLocalMode(),
I->getType()->getAddressSpace());
GV->copyAttributesFrom(&*I);
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->getValueType()),
I->getLinkage(), I->getName(), New.get());
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) {
if (!ShouldCloneDefinition(&*I)) {
// An alias cannot act as an external reference, so we need to create
// either a function or a global variable depending on the value type.
// FIXME: Once pointee types are gone we can probably pick one or the
// other.
GlobalValue *GV;
if (I->getValueType()->isFunctionTy())
GV = Function::Create(cast<FunctionType>(I->getValueType()),
GlobalValue::ExternalLinkage, I->getName(),
New.get());
else
GV = new GlobalVariable(
*New, I->getValueType(), false, GlobalValue::ExternalLinkage,
(Constant *)nullptr, I->getName(), (GlobalVariable *)nullptr,
I->getThreadLocalMode(), I->getType()->getAddressSpace());
VMap[&*I] = GV;
// We do not copy attributes (mainly because copying between different
// kinds of globals is forbidden), but this is generally not required for
// correctness.
continue;
}
auto *GA = GlobalAlias::create(I->getValueType(),
I->getType()->getPointerAddressSpace(),
I->getLinkage(), I->getName(), New.get());
GA->copyAttributesFrom(&*I);
VMap[&*I] = GA;
}
// 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 (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
GV->setLinkage(GlobalValue::ExternalLinkage);
continue;
}
if (I->hasInitializer())
GV->setInitializer(MapValue(I->getInitializer(), VMap));
}
// 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 (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
F->setLinkage(GlobalValue::ExternalLinkage);
// Personality function is not valid on a declaration.
F->setPersonalityFn(nullptr);
continue;
}
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++;
//.........这里部分代码省略.........