本文整理汇总了C++中basicblock::const_iterator::getName方法的典型用法代码示例。如果您正苦于以下问题:C++ const_iterator::getName方法的具体用法?C++ const_iterator::getName怎么用?C++ const_iterator::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类basicblock::const_iterator
的用法示例。
在下文中一共展示了const_iterator::getName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/// See comments in Cloning.h.
BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
ValueToValueMapTy &VMap,
const Twine &NameSuffix, Function *F,
ClonedCodeInfo *CodeInfo) {
BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "", F);
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
// Loop over all instructions, and copy them over.
for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();
II != IE; ++II) {
Instruction *NewInst = II->clone();
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
VMap[&*II] = NewInst; // Add instruction map to value.
hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II));
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (isa<ConstantInt>(AI->getArraySize()))
hasStaticAllocas = true;
else
hasDynamicAllocas = true;
}
}
if (CodeInfo) {
CodeInfo->ContainsCalls |= hasCalls;
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas &&
BB != &BB->getParent()->getEntryBlock();
}
return NewBB;
}
示例2: copy_function
void HeterotbbTransform::copy_function (Function* NF, Function* F) {
DenseMap<const Value*, Value *> ValueMap;
// Get the names of the parameters for old function
for(Function::arg_iterator FI = F->arg_begin(), FE=F->arg_end(), DI=NF->arg_begin(); FE!=FI; ++FI,++DI) {
DI->setName(FI->getName());
ValueMap[FI]=DI;
}
for (Function::const_iterator BI=F->begin(),BE = F->end(); BI != BE; ++BI) {
const BasicBlock &FBB = *BI;
BasicBlock *NFBB = BasicBlock::Create(FBB.getContext(), "", NF);
ValueMap[&FBB] = NFBB;
if (FBB.hasName()) {
NFBB->setName(FBB.getName());
//DEBUG(dbgs()<<NFBB->getName()<<"\n");
}
for (BasicBlock::const_iterator II = FBB.begin(), IE = FBB.end(); II != IE; ++II) {
Instruction *NFInst = II->clone(/*F->getContext()*/);
if (II->hasName()) NFInst->setName(II->getName());
const Instruction *FInst = &(*II);
rewrite_instruction((Instruction *)FInst, NFInst, ValueMap);
NFBB->getInstList().push_back(NFInst);
ValueMap[II] = NFInst;
}
}
// Remap the instructions again to take care of forward jumps
for (Function::iterator BB = NF->begin(), BE=NF->end(); BB != BE; ++ BB) {
for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II) {
int opIdx = 0;
//DEBUG(dbgs()<<*II<<"\n");
for (User::op_iterator i = II->op_begin(), e = II->op_end(); i != e; ++i, opIdx++) {
Value *V = *i;
if (ValueMap[V] != NULL) {
II->setOperand(opIdx, ValueMap[V]);
}
}
}
}
//NF->dump();
}
示例3: CloneBlock
/// CloneBlock - The specified block is found to be reachable, clone it and
/// anything that it can reach.
void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
std::vector<const BasicBlock*> &ToClone){
TrackingVH<Value> &BBEntry = VMap[BB];
// Have we already cloned this block?
if (BBEntry) return;
// Nope, clone it now.
BasicBlock *NewBB;
BBEntry = NewBB = BasicBlock::Create(BB->getContext());
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
// Loop over all instructions, and copy them over, DCE'ing as we go. This
// loop doesn't include the terminator.
for (BasicBlock::const_iterator II = BB->begin(), IE = --BB->end();
II != IE; ++II) {
// If this instruction constant folds, don't bother cloning the instruction,
// instead, just add the constant to the value map.
if (Constant *C = ConstantFoldMappedInstruction(II)) {
VMap[II] = C;
continue;
}
Instruction *NewInst = II->clone();
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
VMap[II] = NewInst; // Add instruction map to value.
hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II));
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (isa<ConstantInt>(AI->getArraySize()))
hasStaticAllocas = true;
else
hasDynamicAllocas = true;
}
}
// Finally, clone over the terminator.
const TerminatorInst *OldTI = BB->getTerminator();
bool TerminatorDone = false;
if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
if (BI->isConditional()) {
// If the condition was a known constant in the callee...
ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
// Or is a known constant in the caller...
if (Cond == 0) {
Value *V = VMap[BI->getCondition()];
Cond = dyn_cast_or_null<ConstantInt>(V);
}
// Constant fold to uncond branch!
if (Cond) {
BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
VMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest);
TerminatorDone = true;
}
}
} else if (const SwitchInst *SI = dyn_cast<SwitchInst>(OldTI)) {
// If switching on a value known constant in the caller.
ConstantInt *Cond = dyn_cast<ConstantInt>(SI->getCondition());
if (Cond == 0) { // Or known constant after constant prop in the callee...
Value *V = VMap[SI->getCondition()];
Cond = dyn_cast_or_null<ConstantInt>(V);
}
if (Cond) { // Constant fold to uncond branch!
BasicBlock *Dest = SI->getSuccessor(SI->findCaseValue(Cond));
VMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest);
TerminatorDone = true;
}
}
if (!TerminatorDone) {
Instruction *NewInst = OldTI->clone();
if (OldTI->hasName())
NewInst->setName(OldTI->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
VMap[OldTI] = NewInst; // Add instruction map to value.
// Recursively clone any reachable successor blocks.
const TerminatorInst *TI = BB->getTerminator();
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
ToClone.push_back(TI->getSuccessor(i));
}
if (CodeInfo) {
CodeInfo->ContainsCalls |= hasCalls;
CodeInfo->ContainsUnwinds |= isa<UnwindInst>(OldTI);
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas &&
BB != &BB->getParent()->front();
}
if (ReturnInst *RI = dyn_cast<ReturnInst>(NewBB->getTerminator()))
//.........这里部分代码省略.........
示例4: CloneBlock
/// The specified block is found to be reachable, clone it and
/// anything that it can reach.
void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
BasicBlock::const_iterator StartingInst,
std::vector<const BasicBlock*> &ToClone){
WeakVH &BBEntry = VMap[BB];
// Have we already cloned this block?
if (BBEntry) return;
// Nope, clone it now.
BasicBlock *NewBB;
BBEntry = NewBB = BasicBlock::Create(BB->getContext());
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
// It is only legal to clone a function if a block address within that
// function is never referenced outside of the function. Given that, we
// want to map block addresses from the old function to block addresses in
// the clone. (This is different from the generic ValueMapper
// implementation, which generates an invalid blockaddress when
// cloning a function.)
//
// Note that we don't need to fix the mapping for unreachable blocks;
// the default mapping there is safe.
if (BB->hasAddressTaken()) {
Constant *OldBBAddr = BlockAddress::get(const_cast<Function*>(OldFunc),
const_cast<BasicBlock*>(BB));
VMap[OldBBAddr] = BlockAddress::get(NewFunc, NewBB);
}
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
// Loop over all instructions, and copy them over, DCE'ing as we go. This
// loop doesn't include the terminator.
for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end();
II != IE; ++II) {
Instruction *NewInst = II->clone();
// Eagerly remap operands to the newly cloned instruction, except for PHI
// nodes for which we defer processing until we update the CFG.
if (!isa<PHINode>(NewInst)) {
RemapInstruction(NewInst, VMap,
ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
// If we can simplify this instruction to some other value, simply add
// a mapping to that value rather than inserting a new instruction into
// the basic block.
if (Value *V =
SimplifyInstruction(NewInst, BB->getModule()->getDataLayout())) {
// On the off-chance that this simplifies to an instruction in the old
// function, map it back into the new function.
if (Value *MappedV = VMap.lookup(V))
V = MappedV;
VMap[&*II] = V;
delete NewInst;
continue;
}
}
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
VMap[&*II] = NewInst; // Add instruction map to value.
NewBB->getInstList().push_back(NewInst);
hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II));
if (CodeInfo)
if (auto CS = ImmutableCallSite(&*II))
if (CS.hasOperandBundles())
CodeInfo->OperandBundleCallSites.push_back(NewInst);
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (isa<ConstantInt>(AI->getArraySize()))
hasStaticAllocas = true;
else
hasDynamicAllocas = true;
}
}
// Finally, clone over the terminator.
const TerminatorInst *OldTI = BB->getTerminator();
bool TerminatorDone = false;
if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
if (BI->isConditional()) {
// If the condition was a known constant in the callee...
ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
// Or is a known constant in the caller...
if (!Cond) {
Value *V = VMap[BI->getCondition()];
Cond = dyn_cast_or_null<ConstantInt>(V);
}
// Constant fold to uncond branch!
if (Cond) {
BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
VMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest);
TerminatorDone = true;
}
//.........这里部分代码省略.........
示例5: gen_opt_code_per_f
void HeterotbbTransform::gen_opt_code_per_f (Function* NF, Function* F) {
// Get the names of the parameters for old function
Function::arg_iterator FI = F->arg_begin();
Argument *classname = &*FI;
FI++;
Argument *numiters = &*FI;
// Set the names of the parameters for new function
Function::arg_iterator DestI = NF->arg_begin();
DestI->setName(classname->getName());
Argument *class_name = &(*DestI);
//second argument
DestI++;
DestI->setName(numiters->getName());
Argument *num_iters = &(*DestI);
#ifdef EXPLICIT_REWRITE
DenseMap<const Value*, Value *> ValueMap;
#else
ValueToValueMapTy ValueMap;
#endif
#if EXPLICIT_REWRITE
//get the old basic block and create a new one
Function::const_iterator BI = F->begin();
const BasicBlock &FB = *BI;
BasicBlock *NFBB = BasicBlock::Create(FB.getContext(), "", NF);
if (FB.hasName()) {
NFBB->setName(FB.getName());
//DEBUG(dbgs()<<FB.getName()<<"\n");
}
ValueMap[&FB] = NFBB;
ValueMap[numiters] = num_iters;
//must create a new instruction which casts i32* back to the class name
CastInst *StrucRevCast = CastInst::Create(Instruction::BitCast, class_name,
classname->getType(), classname->getName(), NFBB);
ValueMap[classname] = StrucRevCast;
for (BasicBlock::const_iterator II = FB.begin(), IE = FB.end(); II != IE; ++II) {
Instruction *NFInst = II->clone(/*F->getContext()*/);
// DEBUG(dbgs()<<*II<<"\n");
if (II->hasName()) NFInst->setName(II->getName());
const Instruction *FInst = &(*II);
rewrite_instruction((Instruction *)FInst, NFInst, ValueMap);
NFBB->getInstList().push_back(NFInst);
ValueMap[II] = NFInst;
}
BI++;
for (Function::const_iterator /*BI=F->begin(),*/BE = F->end(); BI != BE; ++BI) {
const BasicBlock &FBB = *BI;
BasicBlock *NFBB = BasicBlock::Create(FBB.getContext(), "", NF);
ValueMap[&FBB] = NFBB;
if (FBB.hasName()) {
NFBB->setName(FBB.getName());
//DEBUG(dbgs()<<NFBB->getName()<<"\n");
}
for (BasicBlock::const_iterator II = FBB.begin(), IE = FBB.end(); II != IE; ++II) {
Instruction *NFInst = II->clone(/*F->getContext()*/);
if (II->hasName()) NFInst->setName(II->getName());
const Instruction *FInst = &(*II);
rewrite_instruction((Instruction *)FInst, NFInst, ValueMap);
NFBB->getInstList().push_back(NFInst);
ValueMap[II] = NFInst;
}
}
// Remap the instructions again to take care of forward jumps
for (Function::iterator BB = NF->begin(), BE=NF->end(); BB != BE; ++ BB) {
for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II) {
int opIdx = 0;
//DEBUG(dbgs()<<*II<<"\n");
for (User::op_iterator i = II->op_begin(), e = II->op_end(); i != e; ++i, opIdx++) {
Value *V = *i;
if (ValueMap[V] != NULL) {
II->setOperand(opIdx, ValueMap[V]);
}
}
}
}
#else
Function::const_iterator BI = F->begin();
const BasicBlock &FB = *BI;
BasicBlock *NFBB = BasicBlock::Create(FB.getContext(), "", NF);
if (FB.hasName()) {
NFBB->setName(FB.getName());
}
ValueMap[&FB] = NFBB;
CastInst *StrucRevCast = CastInst::Create(Instruction::BitCast, class_name,
classname->getType(), classname->getName(), NFBB);
ValueMap[classname] = StrucRevCast;
ValueMap[numiters] = num_iters;
CloneFunctionWithExistingBBInto(NF, NFBB, F, ValueMap, "");
#endif
}
示例6: gen_code_per_f
/**
* Generate code for
*/
void HeteroOMPTransform::gen_code_per_f (Function* NF, Function* F, Instruction *max_threads){
Function::arg_iterator FI = F->arg_begin();
Argument *ctxname = &*FI;
Function::arg_iterator DestI = NF->arg_begin();
DestI->setName(ctxname->getName());
Argument *ctx_name = &(*DestI);
DestI++;
DestI->setName("tid");
Argument *num_iters = &(*DestI);
#ifdef EXPLICIT_REWRITE
DenseMap<const Value*, Value *> ValueMap;
#else
ValueToValueMapTy ValueMap;
#endif
//get the old basic block and create a new one
Function::const_iterator BI = F->begin();
const BasicBlock &FB = *BI;
BasicBlock *NFBB = BasicBlock::Create(FB.getContext(), "", NF);
if (FB.hasName()){
NFBB->setName(FB.getName());
}
ValueMap[&FB] = NFBB;
//ValueMap[numiters] = num_iters;
ValueMap[ctxname] = ctx_name;
#if EXPLICIT_REWRITE
for (BasicBlock::const_iterator II = FB.begin(), IE = FB.end(); II != IE; ++II) {
Instruction *NFInst = II->clone(/*F->getContext()*/);
// DEBUG(dbgs()<<*II<<"\n");
if (II->hasName()) NFInst->setName(II->getName());
const Instruction *FInst = &(*II);
rewrite_instruction((Instruction *)FInst, NFInst, ValueMap);
NFBB->getInstList().push_back(NFInst);
ValueMap[II] = NFInst;
}
BI++;
for (Function::const_iterator /*BI=F->begin(),*/BE = F->end();BI != BE; ++BI) {
const BasicBlock &FBB = *BI;
BasicBlock *NFBB = BasicBlock::Create(FBB.getContext(), "", NF);
ValueMap[&FBB] = NFBB;
if (FBB.hasName()){
NFBB->setName(FBB.getName());
//DEBUG(dbgs()<<NFBB->getName()<<"\n");
}
for (BasicBlock::const_iterator II = FBB.begin(), IE = FBB.end(); II != IE; ++II) {
Instruction *NFInst = II->clone(/*F->getContext()*/);
if (II->hasName()) NFInst->setName(II->getName());
const Instruction *FInst = &(*II);
rewrite_instruction((Instruction *)FInst, NFInst, ValueMap);
NFBB->getInstList().push_back(NFInst);
ValueMap[II] = NFInst;
}
}
// Remap the instructions again to take care of forward jumps
for (Function::iterator BB = NF->begin(), BE=NF->end(); BB != BE; ++ BB) {
for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II){
int opIdx = 0;
//DEBUG(dbgs()<<*II<<"\n");
for (User::op_iterator i = II->op_begin(), e = II->op_end(); i != e; ++i, opIdx++) {
Value *V = *i;
if (ValueMap[V] != NULL) {
II->setOperand(opIdx, ValueMap[V]);
}
}
}
}
#else
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
CloneFunctionInto(NF, F, ValueMap, false, Returns, "");
#endif
//max_threads->dump();
/* Remap openmp omp_num_threads() and omp_thread_num() */
/*
* define internal void @_Z20initialize_variablesiPfS_.omp_fn.4(i8* nocapture %.omp_data_i) nounwind ssp {
* entry:
* %0 = bitcast i8* %.omp_data_i to i32* ; <i32*> [#uses=1]
* %1 = load i32* %0, align 8 ; <i32> [#uses=2]
* %2 = tail call i32 @omp_get_num_threads() nounwind readnone ; <i32> [#uses=2]
* %3 = tail call i32 @omp_get_thread_num() nounwind readnone ; <i32> [#uses=2]
%4 = sdiv i32 %1, %2
%5 = mul nsw i32 %4, %2
%6 = icmp ne i32 %5, %1
%7 = zext i1 %6 to i32
*/
vector<Instruction *> toDelete;
for (Function::iterator BB = NF->begin(), BE=NF->end(); BB != BE; ++ BB) {
for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II){
if (isa<CallInst>(II)) {
CallSite CI(cast<Instruction>(II));
if (CI.getCalledFunction() != NULL){
//.........这里部分代码省略.........
示例7: CloneInnerLoop
void WorklessInstrument::CloneInnerLoop(Loop * pLoop, vector<BasicBlock *> & vecAdd, ValueToValueMapTy & VMap, set<BasicBlock *> & setCloned)
{
Function * pFunction = pLoop->getHeader()->getParent();
BasicBlock * pPreHeader = vecAdd[0];
SmallVector<BasicBlock *, 4> ExitBlocks;
pLoop->getExitBlocks(ExitBlocks);
set<BasicBlock *> setExitBlocks;
for(unsigned long i = 0; i < ExitBlocks.size(); i++)
{
setExitBlocks.insert(ExitBlocks[i]);
}
for(unsigned long i = 0; i < ExitBlocks.size(); i++ )
{
VMap[ExitBlocks[i]] = ExitBlocks[i];
}
vector<BasicBlock *> ToClone;
vector<BasicBlock *> BeenCloned;
//clone loop
ToClone.push_back(pLoop->getHeader());
while(ToClone.size()>0)
{
BasicBlock * pCurrent = ToClone.back();
ToClone.pop_back();
WeakVH & BBEntry = VMap[pCurrent];
if (BBEntry)
{
continue;
}
BasicBlock * NewBB;
BBEntry = NewBB = BasicBlock::Create(pCurrent->getContext(), "", pFunction);
if(pCurrent->hasName())
{
NewBB->setName(pCurrent->getName() + ".CPI");
}
if(pCurrent->hasAddressTaken())
{
errs() << "hasAddressTaken branch\n" ;
exit(0);
}
for(BasicBlock::const_iterator II = pCurrent->begin(); II != pCurrent->end(); ++II )
{
Instruction * NewInst = II->clone();
if(II->hasName())
{
NewInst->setName(II->getName() + ".CPI");
}
VMap[II] = NewInst;
NewBB->getInstList().push_back(NewInst);
}
const TerminatorInst *TI = pCurrent->getTerminator();
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
{
ToClone.push_back(TI->getSuccessor(i));
}
setCloned.insert(NewBB);
BeenCloned.push_back(NewBB);
}
//remap value used inside loop
vector<BasicBlock *>::iterator itVecBegin = BeenCloned.begin();
vector<BasicBlock *>::iterator itVecEnd = BeenCloned.end();
for(; itVecBegin != itVecEnd; itVecBegin ++)
{
for(BasicBlock::iterator II = (*itVecBegin)->begin(); II != (*itVecBegin)->end(); II ++ )
{
//II->dump();
RemapInstruction(II, VMap);
}
}
//add to the else if body
BasicBlock * pElseBody = vecAdd[1];
BasicBlock * pClonedHeader = cast<BasicBlock>(VMap[pLoop->getHeader()]);
BranchInst::Create(pClonedHeader, pElseBody);
//errs() << pPreHeader->getName() << "\n";
for(BasicBlock::iterator II = pClonedHeader->begin(); II != pClonedHeader->end(); II ++ )
{
if(PHINode * pPHI = dyn_cast<PHINode>(II))
{
vector<int> vecToRemoved;
for (unsigned i = 0, e = pPHI->getNumIncomingValues(); i != e; ++i)
//.........这里部分代码省略.........
示例8: DebugACrash
//.........这里部分代码省略.........
unsigned OldSize = Functions.size();
ReduceCrashingFunctions(BD, TestFn).reduceList(Functions);
if (Functions.size() < OldSize)
BD.EmitProgressBytecode("reduced-function");
}
// Attempt to delete entire basic blocks at a time to speed up
// convergence... this actually works by setting the terminator of the blocks
// to a return instruction then running simplifycfg, which can potentially
// shrinks the code dramatically quickly
//
if (!DisableSimplifyCFG && !BugpointIsInterrupted) {
std::vector<const BasicBlock*> Blocks;
for (Module::const_iterator I = BD.getProgram()->begin(),
E = BD.getProgram()->end(); I != E; ++I)
for (Function::const_iterator FI = I->begin(), E = I->end(); FI !=E; ++FI)
Blocks.push_back(FI);
ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks);
}
// 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;
std::cout << "\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;
std::cout << "Checking instruction '" << I->getName() << "': ";
Module *M = BD.deleteInstructionFromProgram(I, Simplification);
// Find out if the pass still crashes on this pass...
if (TestFn(BD, M)) {
// Yup, it does, we delete the old module, and continue trying
// to reduce the testcase...
BD.setNewProgram(M);
InstructionsToSkipBeforeDeleting = CurInstructionNum;
goto TryAgain; // I wish I had a multi-level break here!
}
// This pass didn't crash without this instruction, try the next
// one.
delete M;
}
if (InstructionsToSkipBeforeDeleting) {
InstructionsToSkipBeforeDeleting = 0;
goto TryAgain;
}
} while (Simplification);
ExitLoops:
// Try to clean up the testcase by running funcresolve and globaldce...
if (!BugpointIsInterrupted) {
std::cout << "\n*** Attempting to perform final cleanups: ";
Module *M = CloneModule(BD.getProgram());
M = BD.performFinalCleanups(M, true);
// 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.EmitProgressBytecode("reduced-simplified");
return false;
}
示例9: CloneBlock
/// CloneBlock - The specified block is found to be reachable, clone it and
/// anything that it can reach.
void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
std::vector<const BasicBlock*> &ToClone) {
TrackingVH<Value> &BBEntry = VMap[BB];
// Have we already cloned this block?
if (BBEntry) return;
// Nope, clone it now.
BasicBlock *NewBB;
BBEntry = NewBB = BasicBlock::Create(BB->getContext());
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
// It is only legal to clone a function if a block address within that
// function is never referenced outside of the function. Given that, we
// want to map block addresses from the old function to block addresses in
// the clone. (This is different from the generic ValueMapper
// implementation, which generates an invalid blockaddress when
// cloning a function.)
//
// Note that we don't need to fix the mapping for unreachable blocks;
// the default mapping there is safe.
if (BB->hasAddressTaken()) {
Constant *OldBBAddr = BlockAddress::get(const_cast<Function*>(OldFunc),
const_cast<BasicBlock*>(BB));
VMap[OldBBAddr] = BlockAddress::get(NewFunc, NewBB);
}
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
// Loop over all instructions, and copy them over, DCE'ing as we go. This
// loop doesn't include the terminator.
for (BasicBlock::const_iterator II = BB->begin(), IE = --BB->end();
II != IE; ++II) {
// If this instruction constant folds, don't bother cloning the instruction,
// instead, just add the constant to the value map.
if (Constant *C = ConstantFoldMappedInstruction(II)) {
VMap[II] = C;
continue;
}
Instruction *NewInst = II->clone();
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
VMap[II] = NewInst; // Add instruction map to value.
hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II));
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (isa<ConstantInt>(AI->getArraySize()))
hasStaticAllocas = true;
else
hasDynamicAllocas = true;
}
}
// Finally, clone over the terminator.
const TerminatorInst *OldTI = BB->getTerminator();
bool TerminatorDone = false;
if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
if (BI->isConditional()) {
// If the condition was a known constant in the callee...
ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
// Or is a known constant in the caller...
if (Cond == 0) {
Value *V = VMap[BI->getCondition()];
Cond = dyn_cast_or_null<ConstantInt>(V);
}
// Constant fold to uncond branch!
if (Cond) {
BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
VMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest);
TerminatorDone = true;
}
}
} else if (const SwitchInst *SI = dyn_cast<SwitchInst>(OldTI)) {
// If switching on a value known constant in the caller.
ConstantInt *Cond = dyn_cast<ConstantInt>(SI->getCondition());
if (Cond == 0) { // Or known constant after constant prop in the callee...
Value *V = VMap[SI->getCondition()];
Cond = dyn_cast_or_null<ConstantInt>(V);
}
if (Cond) { // Constant fold to uncond branch!
SwitchInst::ConstCaseIt Case = SI->findCaseValue(Cond);
BasicBlock *Dest = const_cast<BasicBlock*>(Case.getCaseSuccessor());
VMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest);
TerminatorDone = true;
}
}
if (!TerminatorDone) {
Instruction *NewInst = OldTI->clone();
if (OldTI->hasName())
NewInst->setName(OldTI->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
//.........这里部分代码省略.........