virtual bool runOnFunction(Function& f) { CurrentFile::set(__FILE__); bool changed = false; // Make sure this is a function that we can use if (f.isDeclaration() /*|| !f.isDFFunction()*/ ) { return changed ; } for(Function::iterator BB = f.begin(); BB != f.end(); ++BB) { begin: for(BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II) { if( !dynamic_cast<TerminatorInst*>(&*II) ) { II->replaceAllUsesWith(UndefValue::get(II->getType())); II->eraseFromParent(); goto begin; } } } changed = true; return changed; }
void MakeDispatcherPass::ConvertCmp(Function& function) { typedef std::vector< Instruction * > InstList; InstList insts; for (Function::iterator BB = function.begin(), bbE = function.end(); BB != bbE; ++BB) { for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) { if (isa< CmpInst >(I)) { insts.push_back(I); } if (isa< BranchInst >(I)) { BasicBlock::iterator save = I; BranchInst* branchInst = dynamic_cast< BranchInst *>(&*I); if (branchInst->isConditional() && !insts.empty()) { Value* valbranch = NULL; valbranch = branchInst->getCondition(); ShowType(dynamic_cast<CmpInst*>(insts[0])); CreateInt3(BB, I); I++; save->eraseFromParent(); insts.pop_back(); continue; } } I++; } } }
bool EraseUclibcFiniPass::runOnModule(Module &M) { Function *f = M.getFunction("tern_exit"); Function *fini = M.getFunction("__uClibc_fini"); if(!f || !fini) return false; 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 (i->getOpcode() == Instruction::Call) { CallInst *ci = dyn_cast<CallInst>(i); assert(ci); if (ci->getCalledFunction() == fini) { i->eraseFromParent(); return true; } } } } return false; }
bool RemoveExtendsPass::runOnFunction(Function& f) { CurrentFile::set(__FILE__); bool changed = false ; //see if there are any ROCCCNames or ROCCCSizes that caused the extend for(Function::iterator BB = f.begin(); BB != f.end(); ++BB) { begin: for(BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II) { if( dynamic_cast<FPExtInst*>(&*II) or dynamic_cast<ZExtInst*>(&*II) or dynamic_cast<SExtInst*>(&*II) or dynamic_cast<BitCastInst*>(&*II) ) { INTERNAL_MESSAGE("Attempting to remove uses of " << II->getName() << "\n"); for(Value::use_iterator UI = II->use_begin(); UI != II->use_end(); ++UI) { dynamic_cast<Instruction*>(*UI)->replaceUsesOfWith(II, II->getOperand(0)); goto begin; } if( II->use_begin() == II->use_end() ) { II->eraseFromParent(); II = BB->begin(); } else { INTERNAL_ERROR("Extend " << *II << " is still used in " << **II->use_begin() << "!"); assert(0 and "Extend operation still exists!"); } } } } return changed ; }