LLVM 20.0.0git
MemProfContextDisambiguation.h
Go to the documentation of this file.
1//==- MemProfContextDisambiguation.h - Context Disambiguation ----*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implements support for context disambiguation of allocation calls for profile
10// guided heap optimization using memprof metadata. See implementation file for
11// details.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
16#define LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
17
19#include "llvm/IR/GlobalValue.h"
21#include "llvm/IR/PassManager.h"
23#include <functional>
24
25namespace llvm {
26class GlobalValueSummary;
27class Module;
28class OptimizationRemarkEmitter;
29
31 : public PassInfoMixin<MemProfContextDisambiguation> {
32 /// Run the context disambiguator on \p M, returns true if any changes made.
33 bool processModule(
34 Module &M,
36
37 /// In the ThinLTO backend, apply the cloning decisions in ImportSummary to
38 /// the IR.
39 bool applyImport(Module &M);
40
41 // Builds the symtab and analysis used for ICP during ThinLTO backends.
42 bool initializeIndirectCallPromotionInfo(Module &M);
43
44 // Data structure for saving indirect call profile info for use in ICP with
45 // cloning.
46 struct ICallAnalysisData {
47 CallBase *CB;
48 std::vector<InstrProfValueData> CandidateProfileData;
49 uint32_t NumCandidates;
50 uint64_t TotalCount;
51 size_t CallsiteInfoStartIndex;
52 };
53
54 // Record information needed for ICP of an indirect call, depending on its
55 // profile information and the clone information recorded in the corresponding
56 // CallsiteInfo records. The SI iterator point to the current iteration point
57 // through AllCallsites in this function, and will be updated in this method
58 // as we iterate through profiled targets. The number of clones recorded for
59 // this indirect call is returned. The necessary information is recorded in
60 // the ICallAnalysisInfo list for later ICP.
61 unsigned recordICPInfo(CallBase *CB, ArrayRef<CallsiteInfo> AllCallsites,
63 SmallVector<ICallAnalysisData> &ICallAnalysisInfo);
64
65 // Actually performs any needed ICP in the function, using the information
66 // recorded in the ICallAnalysisInfo list.
67 void performICP(Module &M, ArrayRef<CallsiteInfo> AllCallsites,
68 ArrayRef<std::unique_ptr<ValueToValueMapTy>> VMaps,
69 ArrayRef<ICallAnalysisData> ICallAnalysisInfo,
71
72 /// Import summary containing cloning decisions for the ThinLTO backend.
73 const ModuleSummaryIndex *ImportSummary;
74
75 // Owns the import summary specified by internal options for testing the
76 // ThinLTO backend via opt (to simulate distributed ThinLTO).
77 std::unique_ptr<ModuleSummaryIndex> ImportSummaryForTesting;
78
79 // Whether we are building with SamplePGO. This is needed for correctly
80 // updating profile metadata on speculatively promoted calls.
81 bool isSamplePGO;
82
83 // Used when performing indirect call analysis and promotion when cloning in
84 // the ThinLTO backend during applyImport.
85 std::unique_ptr<InstrProfSymtab> Symtab;
86 std::unique_ptr<ICallPromotionAnalysis> ICallAnalysis;
87
88public:
89 MemProfContextDisambiguation(const ModuleSummaryIndex *Summary = nullptr,
90 bool isSamplePGO = false);
91
93
96 isPrevailing);
97};
98} // end namespace llvm
99
100#endif // LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
uint32_t Index
This header defines various interfaces for pass management in LLVM.
Interface to identify indirect call promotion candidates.
Machine Check Debug Module
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1120
Function and variable summary information to aid decisions and implementation of importing.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69