|
LLVM
4.0.0
|
#include "llvm/Transforms/IPO/Inliner.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/AliasAnalysis.h"#include "llvm/Analysis/AssumptionCache.h"#include "llvm/Analysis/BasicAliasAnalysis.h"#include "llvm/Analysis/CallGraph.h"#include "llvm/Analysis/InlineCost.h"#include "llvm/Analysis/OptimizationDiagnosticInfo.h"#include "llvm/Analysis/ProfileSummaryInfo.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/IR/CallSite.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DiagnosticInfo.h"#include "llvm/IR/InstIterator.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Module.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Transforms/Utils/Cloning.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Transforms/Utils/ModuleUtils.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "inline" |
Typedefs | |
| typedef DenseMap< ArrayType *, std::vector< AllocaInst * > > | InlinedArrayAllocasTy |
Enumerations | |
| enum | InlinerFunctionImportStatsOpts |
Functions | |
| STATISTIC (NumInlined,"Number of functions inlined") | |
| STATISTIC (NumCallsDeleted,"Number of call sites deleted, not inlined") | |
| STATISTIC (NumDeleted,"Number of functions deleted because all callers found") | |
| STATISTIC (NumMergedAllocas,"Number of allocas merged together") | |
| STATISTIC (NumCallerCallersAnalyzed,"Number of caller-callers analyzed") | |
| static void | mergeInlinedArrayAllocas (Function *Caller, InlineFunctionInfo &IFI, InlinedArrayAllocasTy &InlinedArrayAllocas, int InlineHistory) |
| Look at all of the allocas that we inlined through this call site. More... | |
| static bool | InlineCallIfPossible (CallSite CS, InlineFunctionInfo &IFI, InlinedArrayAllocasTy &InlinedArrayAllocas, int InlineHistory, bool InsertLifetime, function_ref< AAResults &(Function &)> &AARGetter, ImportedFunctionsInliningStatistics &ImportedFunctionsStats) |
| If it is possible to inline the specified call site, do so and update the CallGraph for this operation. More... | |
| static bool | shouldBeDeferred (Function *Caller, CallSite CS, InlineCost IC, int &TotalSecondaryCost, function_ref< InlineCost(CallSite CS)> GetInlineCost) |
| Return true if inlining of CS can block the caller from being inlined which is proved to be more beneficial. More... | |
| static bool | shouldInline (CallSite CS, function_ref< InlineCost(CallSite CS)> GetInlineCost, OptimizationRemarkEmitter &ORE) |
| Return true if the inliner should attempt to inline at the given CallSite. More... | |
| static bool | InlineHistoryIncludes (Function *F, int InlineHistoryID, const SmallVectorImpl< std::pair< Function *, int >> &InlineHistory) |
| Return true if the specified inline history ID indicates an inline history that includes the specified function. More... | |
| static bool | inlineCallsImpl (CallGraphSCC &SCC, CallGraph &CG, std::function< AssumptionCache &(Function &)> GetAssumptionCache, ProfileSummaryInfo *PSI, TargetLibraryInfo &TLI, bool InsertLifetime, function_ref< InlineCost(CallSite CS)> GetInlineCost, function_ref< AAResults &(Function &)> AARGetter, ImportedFunctionsInliningStatistics &ImportedFunctionsStats) |
Variables | |
| static cl::opt< bool > | DisableInlinedAllocaMerging ("disable-inlined-alloca-merging", cl::init(false), cl::Hidden) |
| Flag to disable manual alloca merging. More... | |
| #define DEBUG_TYPE "inline" |
Definition at line 41 of file Inliner.cpp.
Referenced by inlineCallsImpl(), and shouldInline().
| typedef DenseMap<ArrayType *, std::vector<AllocaInst *> > InlinedArrayAllocasTy |
Definition at line 98 of file Inliner.cpp.
|
strong |
Definition at line 65 of file Inliner.cpp.
|
static |
If it is possible to inline the specified call site, do so and update the CallGraph for this operation.
This function also does some basic book-keeping to update the IR. The InlinedArrayAllocas map keeps track of any allocas that are already available from other functions inlined into the caller. If we are able to inline this call site we attempt to reuse already available allocas or add any new allocas to the set if not possible.
Definition at line 234 of file Inliner.cpp.
References DisableInlinedAllocaMerging, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCaller(), llvm::InlineFunction(), llvm::AttributeFuncs::mergeAttributesForInlining(), mergeInlinedArrayAllocas(), and llvm::ImportedFunctionsInliningStatistics::recordInline().
Referenced by inlineCallsImpl().
|
static |
Definition at line 428 of file Inliner.cpp.
References llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), DEBUG, DEBUG_TYPE, llvm::OptimizationRemarkEmitter::emit(), llvm::SmallVectorBase::empty(), llvm::SmallVectorImpl< T >::erase(), llvm::Instruction::eraseFromParent(), F, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCaller(), llvm::Instruction::getDebugLoc(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Value::getName(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getParent(), llvm::GlobalValue::hasLocalLinkage(), I, i, InlineCallIfPossible(), llvm::InlineFunctionInfo::InlinedCalls, InlineHistoryIncludes(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::GlobalValue::isDeclaration(), llvm::isInstructionTriviallyDead(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::pop_back(), Ptr, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::CallGraph::removeFunctionFromModule(), shouldInline(), llvm::SmallVectorTemplateCommon< T >::size(), std::swap(), and llvm::Value::use_empty().
Referenced by llvm::LegacyInlinerBase::inlineCalls().
|
static |
Return true if the specified inline history ID indicates an inline history that includes the specified function.
Definition at line 402 of file Inliner.cpp.
References assert().
Referenced by inlineCallsImpl(), and llvm::InlinerPass::run().
|
static |
Look at all of the allocas that we inlined through this call site.
If we have already inlined other allocas through other calls into this function, then we know that they have disjoint lifetimes and that we can merge them.
There are many heuristics possible for merging these allocas, and the different options have different tradeoffs. One thing that we really don't want to hurt is SRoA: once inlining happens, often allocas are no longer address taken and so they can be promoted.
Our "solution" for that is to only merge allocas whose outermost type is an array type. These are usually not promoted because someone is using a variable index into them. These are also often the most important ones to merge.
A better solution would be to have real memory lifetime markers in the IR and not have the inliner do any merging of allocas at all. This would allow the backend to do proper stack slot coloring of all allocas that actually make it to the backend, which is really what we want.
Because we don't have this information, we do this simple and useful hack.
Definition at line 120 of file Inliner.cpp.
References llvm::dbgs(), DEBUG, llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::DataLayout::getABITypeAlignment(), llvm::AllocaInst::getAlignment(), llvm::AllocaInst::getAllocatedType(), llvm::Value::getContext(), llvm::Module::getDataLayout(), llvm::MetadataAsValue::getIfExists(), llvm::LocalAsMetadata::getIfExists(), llvm::Instruction::getParent(), llvm::GlobalValue::getParent(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::AllocaInst::isArrayAllocation(), L, llvm::Value::replaceAllUsesWith(), llvm::InlineFunctionInfo::StaticAllocas, and llvm::Value::users().
Referenced by InlineCallIfPossible().
|
static |
Return true if inlining of CS can block the caller from being inlined which is proved to be more beneficial.
IC is the estimated inline cost associated with callsite CS. TotalAltCost will be set to the estimated cost of inlining the caller if CS is suppressed for inlining.
Definition at line 266 of file Inliner.cpp.
References llvm::InlineConstants::CallPenalty, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::InlineCost::getCost(), llvm::InlineCost::getCostDelta(), llvm::GlobalValue::hasLinkOnceODRLinkage(), llvm::GlobalValue::hasLocalLinkage(), llvm::InlineCost::isAlways(), llvm::InlineConstants::LastCallToStaticBonus, llvm::Value::use_empty(), and llvm::Value::users().
Referenced by shouldInline().
|
static |
Return true if the inliner should attempt to inline at the given CallSite.
Definition at line 338 of file Inliner.cpp.
References llvm::Call, llvm::dbgs(), DEBUG, DEBUG_TYPE, llvm::OptimizationRemarkEmitter::emit(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCaller(), llvm::InlineCost::getCost(), llvm::InlineCost::getCostDelta(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::InlineCost::isAlways(), llvm::InlineCost::isNever(), and shouldBeDeferred().
Referenced by inlineCallsImpl(), and llvm::InlinerPass::run().
| STATISTIC | ( | NumInlined | , |
| "Number of functions inlined" | |||
| ) |
| STATISTIC | ( | NumCallsDeleted | , |
| "Number of call sites | deleted, | ||
| not inlined" | |||
| ) |
| STATISTIC | ( | NumDeleted | , |
| "Number of functions deleted because all callers found" | |||
| ) |
| STATISTIC | ( | NumMergedAllocas | , |
| "Number of allocas merged together" | |||
| ) |
| STATISTIC | ( | NumCallerCallersAnalyzed | , |
| "Number of caller-callers analyzed" | |||
| ) |
|
static |
Flag to disable manual alloca merging.
Merging of allocas was originally done as a stack-size saving technique prior to LLVM's code generator having support for stack coloring based on lifetime markers. It is now in the process of being removed. To experiment with disabling it and relying fully on lifetime marker based stack coloring, you can pass this flag to LLVM.
Referenced by InlineCallIfPossible().
1.8.6