/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Transforms/IPO/InlineSimple.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- InlineSimple.cpp - Code to perform simple function inlining --------===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements bottom-up inlining of functions into callees. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/Analysis/AssumptionCache.h" |
15 | | #include "llvm/Analysis/CallGraph.h" |
16 | | #include "llvm/Analysis/InlineCost.h" |
17 | | #include "llvm/Analysis/ProfileSummaryInfo.h" |
18 | | #include "llvm/Analysis/TargetLibraryInfo.h" |
19 | | #include "llvm/Analysis/TargetTransformInfo.h" |
20 | | #include "llvm/IR/CallSite.h" |
21 | | #include "llvm/IR/CallingConv.h" |
22 | | #include "llvm/IR/DataLayout.h" |
23 | | #include "llvm/IR/Instructions.h" |
24 | | #include "llvm/IR/IntrinsicInst.h" |
25 | | #include "llvm/IR/Module.h" |
26 | | #include "llvm/IR/Type.h" |
27 | | #include "llvm/Transforms/IPO.h" |
28 | | #include "llvm/Transforms/IPO/Inliner.h" |
29 | | |
30 | | using namespace llvm; |
31 | | |
32 | 2.05M | #define DEBUG_TYPE "inline" |
33 | | |
34 | | namespace { |
35 | | |
36 | | /// \brief Actual inliner pass implementation. |
37 | | /// |
38 | | /// The common implementation of the inlining logic is shared between this |
39 | | /// inliner pass and the always inliner pass. The two passes use different cost |
40 | | /// analyses to determine when to inline. |
41 | | class SimpleInliner : public LegacyInlinerBase { |
42 | | |
43 | | InlineParams Params; |
44 | | |
45 | | public: |
46 | 551 | SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) { |
47 | 551 | initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); |
48 | 551 | } |
49 | | |
50 | | explicit SimpleInliner(InlineParams Params) |
51 | 16.9k | : LegacyInlinerBase(ID), Params(std::move(Params)) { |
52 | 16.9k | initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); |
53 | 16.9k | } |
54 | | |
55 | | static char ID; // Pass identification, replacement for typeid |
56 | | |
57 | 2.05M | InlineCost getInlineCost(CallSite CS) override { |
58 | 2.05M | Function *Callee = CS.getCalledFunction(); |
59 | 2.05M | TargetTransformInfo &TTI = TTIWP->getTTI(*Callee); |
60 | 2.05M | |
61 | 2.05M | bool RemarksEnabled = false; |
62 | 2.05M | const auto &BBs = CS.getCaller()->getBasicBlockList(); |
63 | 2.05M | if (!BBs.empty()2.05M ) { |
64 | 2.05M | auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front()); |
65 | 2.05M | if (DI.isEnabled()) |
66 | 15 | RemarksEnabled = true; |
67 | 2.05M | } |
68 | 2.05M | OptimizationRemarkEmitter ORE(CS.getCaller()); |
69 | 2.05M | |
70 | 2.05M | std::function<AssumptionCache &(Function &)> GetAssumptionCache = |
71 | 519k | [&](Function &F) -> AssumptionCache & { |
72 | 519k | return ACT->getAssumptionCache(F); |
73 | 519k | }; |
74 | 2.05M | return llvm::getInlineCost(CS, Params, TTI, GetAssumptionCache, |
75 | 2.05M | /*GetBFI=*/None, PSI, |
76 | 2.05M | RemarksEnabled ? &ORE15 : nullptr2.05M ); |
77 | 2.05M | } |
78 | | |
79 | | bool runOnSCC(CallGraphSCC &SCC) override; |
80 | | void getAnalysisUsage(AnalysisUsage &AU) const override; |
81 | | |
82 | | private: |
83 | | TargetTransformInfoWrapperPass *TTIWP; |
84 | | |
85 | | }; |
86 | | |
87 | | } // end anonymous namespace |
88 | | |
89 | | char SimpleInliner::ID = 0; |
90 | 25.0k | INITIALIZE_PASS_BEGIN25.0k (SimpleInliner, "inline", "Function Integration/Inlining",
|
91 | 25.0k | false, false) |
92 | 25.0k | INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) |
93 | 25.0k | INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) |
94 | 25.0k | INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass) |
95 | 25.0k | INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass) |
96 | 25.0k | INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) |
97 | 25.0k | INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining", |
98 | | false, false) |
99 | | |
100 | 381 | Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); } |
101 | | |
102 | 0 | Pass *llvm::createFunctionInliningPass(int Threshold) { |
103 | 0 | return new SimpleInliner(llvm::getInlineParams(Threshold)); |
104 | 0 | } |
105 | | |
106 | | Pass *llvm::createFunctionInliningPass(unsigned OptLevel, |
107 | | unsigned SizeOptLevel, |
108 | 16.9k | bool DisableInlineHotCallSite) { |
109 | 16.9k | auto Param = llvm::getInlineParams(OptLevel, SizeOptLevel); |
110 | 16.9k | if (DisableInlineHotCallSite) |
111 | 1 | Param.HotCallSiteThreshold = 0; |
112 | 16.9k | return new SimpleInliner(Param); |
113 | 16.9k | } |
114 | | |
115 | 4 | Pass *llvm::createFunctionInliningPass(InlineParams &Params) { |
116 | 4 | return new SimpleInliner(Params); |
117 | 4 | } |
118 | | |
119 | 756k | bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { |
120 | 756k | TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>(); |
121 | 756k | return LegacyInlinerBase::runOnSCC(SCC); |
122 | 756k | } |
123 | | |
124 | 17.5k | void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const { |
125 | 17.5k | AU.addRequired<TargetTransformInfoWrapperPass>(); |
126 | 17.5k | LegacyInlinerBase::getAnalysisUsage(AU); |
127 | 17.5k | } |