26 #define DEBUG_TYPE "partialinlining"
28 STATISTIC(NumPartialInlined,
"Number of functions partially inlined");
38 bool runOnModule(
Module& M)
override;
47 "Partial Inliner",
false,
false)
60 unsigned returnCount = 0;
62 if (isa<ReturnInst>(BB->getTerminator())) {
78 BasicBlock* newEntryBlock = cast<BasicBlock>(VMap[entryBlock]);
79 BasicBlock* newReturnBlock = cast<BasicBlock>(VMap[returnBlock]);
80 BasicBlock* newNonReturnBlock = cast<BasicBlock>(VMap[nonReturnBlock]);
92 newReturnBlock->getFirstNonPHI());
95 while (I != preReturn->
end()) {
101 Ins = newReturnBlock->getFirstNonPHI();
113 std::vector<BasicBlock*> toExtract;
114 toExtract.push_back(newNonReturnBlock);
116 FE = duplicateFunction->
end(); FI != FE; ++FI)
117 if (&*FI != newEntryBlock && &*FI != newReturnBlock &&
118 &*FI != newNonReturnBlock)
119 toExtract.push_back(FI);
134 for (std::vector<User*>::iterator UI =
Users.begin(), UE =
Users.end();
136 if (
CallInst *CI = dyn_cast<CallInst>(*UI))
138 else if (
InvokeInst *II = dyn_cast<InvokeInst>(*UI))
148 return extractedFunction;
151 bool PartialInliner::runOnModule(
Module& M) {
152 std::vector<Function*> worklist;
153 worklist.reserve(M.
size());
155 if (!FI->use_empty() && !FI->isDeclaration())
156 worklist.push_back(&*FI);
158 bool changed =
false;
159 while (!worklist.empty()) {
165 bool recursive =
false;
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)
addIncoming - Add an incoming value to the end of the PHI list
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
A Module instance is used to store all the information related to an LLVM module. ...
bool InlineFunction(CallInst *C, InlineFunctionInfo &IFI, bool InsertLifetime=true)
InlineFunction - This function inlines the called function into the basic block of the caller...
CallInst - This class represents a function call, abstracting a target machine's calling convention...
iv Induction Variable Users
InlineFunctionInfo - This class captures the data input to the InlineFunction call, and records the auxiliary results produced by it.
iterator begin()
Instruction iterator methods.
bool isUnconditional() const
void push_back(NodeTy *val)
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
removeIncomingValue - Remove an incoming value.
const BasicBlock & back() const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Control flow instructions. These all have token chains.
LLVM Basic Block Representation.
BranchInst - Conditional or Unconditional Branch instruction.
Represent the analysis usage information of a pass.
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
void initializePartialInlinerPass(PassRegistry &)
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
void setLinkage(LinkageTypes LT)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
iterator_range< user_iterator > users()
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
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...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Rename collisions when linking (static functions).
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
user_iterator user_begin()
ModulePass * createPartialInliningPass()
createPartialInliningPass - This pass inlines parts of functions.
Module * getParent()
Get the module that this global value is contained inside of...
succ_range successors(BasicBlock *BB)
Function * CloneFunction(const Function *F, ValueToValueMapTy &VMap, bool ModuleLevelChanges, ClonedCodeInfo *CodeInfo=nullptr)
CloneFunction - Return a copy of the specified function, but without embedding the function into anot...
InvokeInst - Invoke instruction.
void recalculate(FT &F)
recalculate - compute a dominator tree for the given function