Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 1 | //===- ModuleSummaryAnalysis.cpp - Module summary index builder -----------===// |
| 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 pass builds a ModuleSummaryIndex object for the module, to be written |
| 11 | // to bitcode or LLVM assembly. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Analysis/ModuleSummaryAnalysis.h" |
| 16 | #include "llvm/Analysis/BlockFrequencyInfo.h" |
| 17 | #include "llvm/Analysis/BlockFrequencyInfoImpl.h" |
| 18 | #include "llvm/Analysis/BranchProbabilityInfo.h" |
Teresa Johnson | cd21a64 | 2016-07-17 14:47:01 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/IndirectCallPromotionAnalysis.h" |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 20 | #include "llvm/Analysis/LoopInfo.h" |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/ProfileSummaryInfo.h" |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 22 | #include "llvm/IR/CallSite.h" |
| 23 | #include "llvm/IR/Dominators.h" |
Teresa Johnson | df5ef87 | 2016-04-27 14:19:38 +0000 | [diff] [blame] | 24 | #include "llvm/IR/InstIterator.h" |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 25 | #include "llvm/IR/IntrinsicInst.h" |
| 26 | #include "llvm/IR/ValueSymbolTable.h" |
| 27 | #include "llvm/Pass.h" |
| 28 | using namespace llvm; |
| 29 | |
| 30 | #define DEBUG_TYPE "module-summary-analysis" |
| 31 | |
| 32 | // Walk through the operands of a given User via worklist iteration and populate |
| 33 | // the set of GlobalValue references encountered. Invoked either on an |
| 34 | // Instruction or a GlobalVariable (which walks its initializer). |
| 35 | static void findRefEdges(const User *CurUser, DenseSet<const Value *> &RefEdges, |
| 36 | SmallPtrSet<const User *, 8> &Visited) { |
| 37 | SmallVector<const User *, 32> Worklist; |
| 38 | Worklist.push_back(CurUser); |
| 39 | |
| 40 | while (!Worklist.empty()) { |
| 41 | const User *U = Worklist.pop_back_val(); |
| 42 | |
| 43 | if (!Visited.insert(U).second) |
| 44 | continue; |
| 45 | |
| 46 | ImmutableCallSite CS(U); |
| 47 | |
| 48 | for (const auto &OI : U->operands()) { |
| 49 | const User *Operand = dyn_cast<User>(OI); |
| 50 | if (!Operand) |
| 51 | continue; |
| 52 | if (isa<BlockAddress>(Operand)) |
| 53 | continue; |
| 54 | if (isa<GlobalValue>(Operand)) { |
| 55 | // We have a reference to a global value. This should be added to |
| 56 | // the reference set unless it is a callee. Callees are handled |
| 57 | // specially by WriteFunction and are added to a separate list. |
| 58 | if (!(CS && CS.isCallee(&OI))) |
| 59 | RefEdges.insert(Operand); |
| 60 | continue; |
| 61 | } |
| 62 | Worklist.push_back(Operand); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 67 | static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount, |
| 68 | ProfileSummaryInfo *PSI) { |
| 69 | if (!PSI) |
| 70 | return CalleeInfo::HotnessType::Unknown; |
| 71 | if (PSI->isHotCount(ProfileCount)) |
| 72 | return CalleeInfo::HotnessType::Hot; |
| 73 | if (PSI->isColdCount(ProfileCount)) |
| 74 | return CalleeInfo::HotnessType::Cold; |
| 75 | return CalleeInfo::HotnessType::None; |
| 76 | } |
| 77 | |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 78 | static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 79 | const Function &F, BlockFrequencyInfo *BFI, |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 80 | ProfileSummaryInfo *PSI, |
| 81 | SmallPtrSetImpl<GlobalValue *> &LocalsUsed) { |
Teresa Johnson | 02563cd | 2016-10-28 02:39:38 +0000 | [diff] [blame] | 82 | // Summary not currently supported for anonymous functions, they should |
| 83 | // have been named. |
| 84 | assert(F.hasName()); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 85 | |
| 86 | unsigned NumInsts = 0; |
| 87 | // Map from callee ValueId to profile count. Used to accumulate profile |
| 88 | // counts for all static calls to a given callee. |
| 89 | DenseMap<const Value *, CalleeInfo> CallGraphEdges; |
Teresa Johnson | cd21a64 | 2016-07-17 14:47:01 +0000 | [diff] [blame] | 90 | DenseMap<GlobalValue::GUID, CalleeInfo> IndirectCallEdges; |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 91 | DenseSet<const Value *> RefEdges; |
Teresa Johnson | cd21a64 | 2016-07-17 14:47:01 +0000 | [diff] [blame] | 92 | ICallPromotionAnalysis ICallAnalysis; |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 93 | bool HasLocalsInUsed = !LocalsUsed.empty(); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 94 | |
| 95 | SmallPtrSet<const User *, 8> Visited; |
Benjamin Kramer | aa20915 | 2016-06-26 17:27:42 +0000 | [diff] [blame] | 96 | for (const BasicBlock &BB : F) |
| 97 | for (const Instruction &I : BB) { |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 98 | if (isa<DbgInfoIntrinsic>(I)) |
| 99 | continue; |
| 100 | ++NumInsts; |
Benjamin Kramer | aa20915 | 2016-06-26 17:27:42 +0000 | [diff] [blame] | 101 | findRefEdges(&I, RefEdges, Visited); |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 102 | auto CS = ImmutableCallSite(&I); |
| 103 | if (!CS) |
| 104 | continue; |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 105 | |
| 106 | const auto *CI = dyn_cast<CallInst>(&I); |
| 107 | // Since we don't know exactly which local values are referenced in inline |
| 108 | // assembly, conservatively reference all of them from this function, to |
| 109 | // ensure we don't export a reference (which would require renaming and |
| 110 | // promotion). |
| 111 | if (HasLocalsInUsed && CI && CI->isInlineAsm()) |
| 112 | RefEdges.insert(LocalsUsed.begin(), LocalsUsed.end()); |
| 113 | |
Teresa Johnson | 897bab9 | 2016-10-08 16:11:42 +0000 | [diff] [blame] | 114 | auto *CalledValue = CS.getCalledValue(); |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 115 | auto *CalledFunction = CS.getCalledFunction(); |
Teresa Johnson | 897bab9 | 2016-10-08 16:11:42 +0000 | [diff] [blame] | 116 | // Check if this is an alias to a function. If so, get the |
| 117 | // called aliasee for the checks below. |
| 118 | if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) { |
| 119 | assert(!CalledFunction && "Expected null called function in callsite for alias"); |
| 120 | CalledFunction = dyn_cast<Function>(GA->getBaseObject()); |
| 121 | } |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 122 | // Check if this is a direct call to a known function. |
| 123 | if (CalledFunction) { |
Teresa Johnson | 02563cd | 2016-10-28 02:39:38 +0000 | [diff] [blame] | 124 | // Skip intrinsics. |
| 125 | if (CalledFunction->isIntrinsic()) |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 126 | continue; |
Teresa Johnson | 02563cd | 2016-10-28 02:39:38 +0000 | [diff] [blame] | 127 | // We should have named any anonymous globals |
| 128 | assert(CalledFunction->hasName()); |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 129 | auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None; |
Teresa Johnson | 897bab9 | 2016-10-08 16:11:42 +0000 | [diff] [blame] | 130 | // Use the original CalledValue, in case it was an alias. We want |
| 131 | // to record the call edge to the alias in that case. Eventually |
| 132 | // an alias summary will be created to associate the alias and |
| 133 | // aliasee. |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 134 | auto *CalleeId = |
Teresa Johnson | 897bab9 | 2016-10-08 16:11:42 +0000 | [diff] [blame] | 135 | M.getValueSymbolTable().lookup(CalledValue->getName()); |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 136 | |
| 137 | auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI) |
| 138 | : CalleeInfo::HotnessType::Unknown; |
| 139 | CallGraphEdges[CalleeId].updateHotness(Hotness); |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 140 | } else { |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 141 | // Skip inline assembly calls. |
| 142 | if (CI && CI->isInlineAsm()) |
| 143 | continue; |
| 144 | // Skip direct calls. |
| 145 | if (!CS.getCalledValue() || isa<Constant>(CS.getCalledValue())) |
| 146 | continue; |
| 147 | |
| 148 | uint32_t NumVals, NumCandidates; |
| 149 | uint64_t TotalCount; |
| 150 | auto CandidateProfileData = |
| 151 | ICallAnalysis.getPromotionCandidatesForInstruction( |
| 152 | &I, NumVals, TotalCount, NumCandidates); |
| 153 | for (auto &Candidate : CandidateProfileData) |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 154 | IndirectCallEdges[Candidate.Value].updateHotness( |
| 155 | getHotness(Candidate.Count, PSI)); |
Piotr Padlewski | 442d38c | 2016-08-30 00:46:26 +0000 | [diff] [blame] | 156 | } |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Mehdi Amini | c3ed48c | 2016-04-24 03:18:18 +0000 | [diff] [blame] | 159 | GlobalValueSummary::GVFlags Flags(F); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 160 | std::unique_ptr<FunctionSummary> FuncSummary = |
Mehdi Amini | c3ed48c | 2016-04-24 03:18:18 +0000 | [diff] [blame] | 161 | llvm::make_unique<FunctionSummary>(Flags, NumInsts); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 162 | FuncSummary->addCallGraphEdges(CallGraphEdges); |
Teresa Johnson | cd21a64 | 2016-07-17 14:47:01 +0000 | [diff] [blame] | 163 | FuncSummary->addCallGraphEdges(IndirectCallEdges); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 164 | FuncSummary->addRefEdges(RefEdges); |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 165 | Index.addGlobalValueSummary(F.getName(), std::move(FuncSummary)); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 168 | static void computeVariableSummary(ModuleSummaryIndex &Index, |
| 169 | const GlobalVariable &V) { |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 170 | DenseSet<const Value *> RefEdges; |
| 171 | SmallPtrSet<const User *, 8> Visited; |
| 172 | findRefEdges(&V, RefEdges, Visited); |
Mehdi Amini | c3ed48c | 2016-04-24 03:18:18 +0000 | [diff] [blame] | 173 | GlobalValueSummary::GVFlags Flags(V); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 174 | std::unique_ptr<GlobalVarSummary> GVarSummary = |
Mehdi Amini | c3ed48c | 2016-04-24 03:18:18 +0000 | [diff] [blame] | 175 | llvm::make_unique<GlobalVarSummary>(Flags); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 176 | GVarSummary->addRefEdges(RefEdges); |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 177 | Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary)); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Teresa Johnson | 02563cd | 2016-10-28 02:39:38 +0000 | [diff] [blame] | 180 | static void computeAliasSummary(ModuleSummaryIndex &Index, |
| 181 | const GlobalAlias &A) { |
| 182 | GlobalValueSummary::GVFlags Flags(A); |
| 183 | std::unique_ptr<AliasSummary> AS = llvm::make_unique<AliasSummary>(Flags); |
| 184 | auto *Aliasee = A.getBaseObject(); |
| 185 | auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee); |
| 186 | assert(AliaseeSummary && "Alias expects aliasee summary to be parsed"); |
| 187 | AS->setAliasee(AliaseeSummary); |
| 188 | Index.addGlobalValueSummary(A.getName(), std::move(AS)); |
| 189 | } |
| 190 | |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 191 | ModuleSummaryIndex llvm::buildModuleSummaryIndex( |
| 192 | const Module &M, |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 193 | std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback, |
| 194 | ProfileSummaryInfo *PSI) { |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 195 | ModuleSummaryIndex Index; |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 196 | |
Mehdi Amini | b6a11a7 | 2016-11-09 01:45:13 +0000 | [diff] [blame^] | 197 | // Identify the local values in the llvm.used set, which should not be |
| 198 | // exported as they would then require renaming and promotion, but we |
| 199 | // may have opaque uses e.g. in inline asm. |
Teresa Johnson | 6955fee | 2016-11-08 21:53:35 +0000 | [diff] [blame] | 200 | SmallPtrSet<GlobalValue *, 8> Used; |
Teresa Johnson | 6955fee | 2016-11-08 21:53:35 +0000 | [diff] [blame] | 201 | collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false); |
Mehdi Amini | b6a11a7 | 2016-11-09 01:45:13 +0000 | [diff] [blame^] | 202 | SmallPtrSet<GlobalValue *, 8> LocalsUsed; |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 203 | for (auto *V : Used) { |
| 204 | if (V->hasLocalLinkage()) |
| 205 | LocalsUsed.insert(V); |
| 206 | } |
Teresa Johnson | b35cc69 | 2016-04-20 14:39:45 +0000 | [diff] [blame] | 207 | |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 208 | // Compute summaries for all functions defined in module, and save in the |
| 209 | // index. |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 210 | for (auto &F : M) { |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 211 | if (F.isDeclaration()) |
| 212 | continue; |
| 213 | |
| 214 | BlockFrequencyInfo *BFI = nullptr; |
| 215 | std::unique_ptr<BlockFrequencyInfo> BFIPtr; |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 216 | if (GetBFICallback) |
| 217 | BFI = GetBFICallback(F); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 218 | else if (F.getEntryCount().hasValue()) { |
| 219 | LoopInfo LI{DominatorTree(const_cast<Function &>(F))}; |
| 220 | BranchProbabilityInfo BPI{F, LI}; |
| 221 | BFIPtr = llvm::make_unique<BlockFrequencyInfo>(F, BPI, LI); |
| 222 | BFI = BFIPtr.get(); |
| 223 | } |
| 224 | |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 225 | computeFunctionSummary(Index, M, F, BFI, PSI, LocalsUsed); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | // Compute summaries for all variables defined in module, and save in the |
| 229 | // index. |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 230 | for (const GlobalVariable &G : M.globals()) { |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 231 | if (G.isDeclaration()) |
| 232 | continue; |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 233 | computeVariableSummary(Index, G); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 234 | } |
Teresa Johnson | 02563cd | 2016-10-28 02:39:38 +0000 | [diff] [blame] | 235 | |
| 236 | // Compute summaries for all aliases defined in module, and save in the |
| 237 | // index. |
| 238 | for (const GlobalAlias &A : M.aliases()) |
| 239 | computeAliasSummary(Index, A); |
| 240 | |
Teresa Johnson | bf28c8f | 2016-10-30 05:40:44 +0000 | [diff] [blame] | 241 | for (auto *V : LocalsUsed) { |
| 242 | auto *Summary = Index.getGlobalValueSummary(*V); |
| 243 | assert(Summary && "Missing summary for global value"); |
| 244 | Summary->setNoRename(); |
| 245 | } |
| 246 | |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 247 | return Index; |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 250 | char ModuleSummaryIndexAnalysis::PassID; |
| 251 | |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 252 | ModuleSummaryIndex |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 253 | ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) { |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 254 | ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M); |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 255 | auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 256 | return buildModuleSummaryIndex( |
| 257 | M, |
| 258 | [&FAM](const Function &F) { |
| 259 | return &FAM.getResult<BlockFrequencyAnalysis>( |
| 260 | *const_cast<Function *>(&F)); |
| 261 | }, |
| 262 | &PSI); |
Teresa Johnson | f93b246 | 2016-08-12 13:53:02 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 265 | char ModuleSummaryIndexWrapperPass::ID = 0; |
| 266 | INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", |
| 267 | "Module Summary Analysis", false, true) |
| 268 | INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass) |
| 269 | INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass, "module-summary-analysis", |
| 270 | "Module Summary Analysis", false, true) |
| 271 | |
| 272 | ModulePass *llvm::createModuleSummaryIndexWrapperPass() { |
| 273 | return new ModuleSummaryIndexWrapperPass(); |
| 274 | } |
| 275 | |
| 276 | ModuleSummaryIndexWrapperPass::ModuleSummaryIndexWrapperPass() |
| 277 | : ModulePass(ID) { |
| 278 | initializeModuleSummaryIndexWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 279 | } |
| 280 | |
| 281 | bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) { |
Dehao Chen | 5461d8b | 2016-09-28 21:00:58 +0000 | [diff] [blame] | 282 | auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(); |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 283 | Index = buildModuleSummaryIndex( |
| 284 | M, |
| 285 | [this](const Function &F) { |
| 286 | return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>( |
| 287 | *const_cast<Function *>(&F)) |
| 288 | .getBFI()); |
| 289 | }, |
| 290 | &PSI); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 291 | return false; |
| 292 | } |
| 293 | |
| 294 | bool ModuleSummaryIndexWrapperPass::doFinalization(Module &M) { |
Chandler Carruth | b7be5b6 | 2016-08-19 07:49:19 +0000 | [diff] [blame] | 295 | Index.reset(); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 296 | return false; |
| 297 | } |
| 298 | |
| 299 | void ModuleSummaryIndexWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 300 | AU.setPreservesAll(); |
| 301 | AU.addRequired<BlockFrequencyInfoWrapperPass>(); |
Piotr Padlewski | d9830eb | 2016-09-26 20:37:32 +0000 | [diff] [blame] | 302 | AU.addRequired<ProfileSummaryInfoWrapperPass>(); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 303 | } |