15 #define DEBUG_TYPE "partialinlining"
27 STATISTIC(NumPartialInlined,
"Number of functions partially inlined");
37 bool runOnModule(
Module& M);
46 "Partial Inliner",
false,
false)
59 unsigned returnCount = 0;
62 if (isa<ReturnInst>((*SI)->getTerminator())) {
77 BasicBlock* newEntryBlock = cast<BasicBlock>(VMap[entryBlock]);
78 BasicBlock* newReturnBlock = cast<BasicBlock>(VMap[returnBlock]);
79 BasicBlock* newNonReturnBlock = cast<BasicBlock>(VMap[nonReturnBlock]);
91 newReturnBlock->getFirstNonPHI());
94 while (I != preReturn->
end()) {
100 Ins = newReturnBlock->getFirstNonPHI();
112 std::vector<BasicBlock*> toExtract;
113 toExtract.push_back(newNonReturnBlock);
115 FE = duplicateFunction->
end(); FI != FE; ++FI)
116 if (&*FI != newEntryBlock && &*FI != newReturnBlock &&
117 &*FI != newNonReturnBlock)
118 toExtract.push_back(FI);
133 for (std::vector<User*>::iterator UI =
Users.begin(), UE =
Users.end();
135 if (
CallInst *CI = dyn_cast<CallInst>(*UI))
137 else if (
InvokeInst *II = dyn_cast<InvokeInst>(*UI))
147 return extractedFunction;
150 bool PartialInliner::runOnModule(
Module& M) {
151 std::vector<Function*> worklist;
152 worklist.reserve(M.
size());
154 if (!FI->use_empty() && !FI->isDeclaration())
155 worklist.push_back(&*FI);
157 bool changed =
false;
158 while (!worklist.empty()) {
164 bool recursive =
false;
166 UE = currFunc->
use_end(); UI != UE; ++UI)
168 if (I->getParent()->getParent() == currFunc) {
172 if (recursive)
continue;
175 if (
Function* newFunc = unswitchFunction(currFunc)) {
176 worklist.push_back(newFunc);
void addIncoming(Value *V, BasicBlock *BB)
static PassRegistry * getPassRegistry()
The main container class for the LLVM Intermediate Representation.
bool InlineFunction(CallInst *C, InlineFunctionInfo &IFI, bool InsertLifetime=true)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
iv Induction Variable Users
bool isUnconditional() const
void push_back(NodeTy *val)
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
ID
LLVM Calling Convention Representation.
Interval::succ_iterator succ_begin(Interval *I)
STATISTIC(NumPartialInlined,"Number of functions partially inlined")
const BasicBlock & back() const
void replaceAllUsesWith(Value *V)
Interval::succ_iterator succ_end(Interval *I)
void replaceUsesOfWith(Value *From, Value *To)
Control flow instructions. These all have token chains.
value_use_iterator< User > use_iterator
LLVM Basic Block Representation.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
virtual bool runOnFunction(Function &F)
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
void initializePartialInlinerPass(PassRegistry &)
void setLinkage(LinkageTypes LT)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
INITIALIZE_PASS(PartialInliner,"partial-inliner","Partial Inliner", false, false) ModulePass *llvm
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Function * CloneFunction(const Function *F, ValueToValueMapTy &VMap, bool ModuleLevelChanges, ClonedCodeInfo *CodeInfo=0)
Rename collisions when linking (static functions).
virtual void eraseFromParent()
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
ModulePass * createPartialInliningPass()