30 #define DEBUG_TYPE "partialinlining"
32 STATISTIC(NumPartialInlined,
"Number of functions partially inlined");
35 struct PartialInlinerImpl {
43 struct PartialInlinerLegacyPass :
public ModulePass {
52 bool runOnModule(
Module &M)
override {
57 std::function<AssumptionCache &(Function &)> GetAssumptionCache =
62 return PartialInlinerImpl(IFI).run(M);
76 unsigned ReturnCount = 0;
78 if (isa<ReturnInst>(BB->getTerminator())) {
92 BasicBlock *NewEntryBlock = cast<BasicBlock>(VMap[EntryBlock]);
93 BasicBlock *NewReturnBlock = cast<BasicBlock>(VMap[ReturnBlock]);
94 BasicBlock *NewNonReturnBlock = cast<BasicBlock>(VMap[NonReturnBlock]);
106 NewReturnBlock->getFirstNonPHI()->getIterator());
109 while (I != PreReturn->
end()) {
116 Ins = NewReturnBlock->getFirstNonPHI();
128 std::vector<BasicBlock *> ToExtract;
129 ToExtract.push_back(NewNonReturnBlock);
131 if (&BB != NewEntryBlock && &BB != NewReturnBlock &&
132 &BB != NewNonReturnBlock)
133 ToExtract.push_back(&BB);
150 std::vector<User *>
Users(DuplicateFunction->user_begin(),
151 DuplicateFunction->user_end());
160 DuplicateFunction->replaceAllUsesWith(F);
161 DuplicateFunction->eraseFromParent();
165 return ExtractedFunction;
168 bool PartialInlinerImpl::run(
Module &M) {
169 std::vector<Function *> Worklist;
170 Worklist.reserve(M.
size());
173 Worklist.push_back(&F);
175 bool Changed =
false;
176 while (!Worklist.empty()) {
183 bool Recursive =
false;
186 if (I->getParent()->getParent() == CurrFunc) {
193 if (
Function *NewFunc = unswitchFunction(CurrFunc)) {
194 Worklist.push_back(NewFunc);
204 "Partial Inliner",
false,
false)
210 return new PartialInlinerLegacyPass();
216 std::function<AssumptionCache &(Function &)> GetAssumptionCache =
221 if (PartialInlinerImpl(IFI).
run(M))
void addIncoming(Value *V, BasicBlock *BB)
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")
void initializePartialInlinerLegacyPassPass(PassRegistry &)
A Module instance is used to store all the information related to an LLVM module. ...
This class represents a function call, abstracting a target machine's calling convention.
Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
CloneFunction - Return a copy of the specified function and add it to that function's module...
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
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 InlineFunction(CallInst *C, InlineFunctionInfo &IFI, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true)
InlineFunction - This function inlines the called function into the basic block of the caller...
AnalysisUsage & addRequired()
ModulePass * createPartialInliningPass()
createPartialInliningPass - This pass inlines parts of functions.
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
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...
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Control flow instructions. These all have token chains.
A set of analyses that are preserved following a run of a transformation pass.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A function analysis which provides an AssumptionCache.
Iterator for intrusive lists based on ilist_node.
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()
Analysis providing branch probability information.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
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...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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.
const BasicBlock & front() const
succ_range successors(BasicBlock *BB)
AssumptionCache & getAssumptionCache(Function &F)
Get the cached assumptions for a function.
void recalculate(FT &F)
recalculate - compute a dominator tree for the given function
A container for analyses that lazily runs them and caches their results.
INITIALIZE_PASS_BEGIN(PartialInlinerLegacyPass,"partial-inliner","Partial Inliner", false, false) INITIALIZE_PASS_END(PartialInlinerLegacyPass
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...