LLVM 24.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
20#include "llvm/IR/GlobalValue.h"
22#include "llvm/IR/PassManager.h"
24#include <functional>
25
26namespace llvm {
28class LLVMContext;
29class Module;
31
33 : public OptionalPassInfoMixin<MemProfContextDisambiguation> {
34 /// Run the context disambiguator on \p M, returns true if any changes made.
35 bool processModule(
36 Module &M,
38
39 /// In the ThinLTO backend, apply the cloning decisions in ImportSummary to
40 /// the IR.
41 bool applyImport(Module &M);
42
43 // Builds the symtab and analysis used for ICP during ThinLTO backends.
44 bool initializeIndirectCallPromotionInfo(Module &M);
45
46 // Data structure for saving indirect call profile info for use in ICP with
47 // cloning.
48 struct ICallAnalysisData {
49 CallBase *CB;
50 std::vector<InstrProfValueData> CandidateProfileData;
51 uint32_t NumCandidates;
52 uint64_t TotalCount;
53 // The number of clones recorded for the call.
54 unsigned NumClones;
55 // The CallsiteInfo summary record for each profiled target in
56 // CandidateProfileData (in the same order), or null if there is none, in
57 // which case all clones of the call should call the original target.
59 };
60
61 // Record information needed for ICP of an indirect call, depending on its
62 // profile information and the clone information recorded in the
63 // CallsiteInfo records for its profiled targets. GetCallsite is invoked once
64 // for each profiled target, in order, and returns the corresponding record
65 // (or null if there is none). The number of clones recorded for this
66 // indirect call is returned (0 if there are no records). The necessary
67 // information is recorded in the ICallAnalysisInfo list for later ICP if any
68 // clone of the call should call a cloned target.
69 unsigned
70 recordICPInfo(CallBase *CB,
71 function_ref<const CallsiteInfo *(const InstrProfValueData &)>
72 GetCallsite,
73 SmallVector<ICallAnalysisData> &ICallAnalysisInfo);
74
75 // Actually performs any needed ICP in the function, using the information
76 // recorded in the ICallAnalysisInfo list.
77 void performICP(Module &M, ArrayRef<std::unique_ptr<ValueToValueMapTy>> VMaps,
78 ArrayRef<ICallAnalysisData> ICallAnalysisInfo,
80
81 /// Import summary containing cloning decisions for the ThinLTO backend.
82 const ModuleSummaryIndex *ImportSummary;
83
84 // Owns the import summary specified by internal options for testing the
85 // ThinLTO backend via opt (to simulate distributed ThinLTO).
86 std::unique_ptr<ModuleSummaryIndex> ImportSummaryForTesting;
87
88 // Whether we are building with SamplePGO. This is needed for correctly
89 // updating profile metadata on speculatively promoted calls.
90 bool isSamplePGO;
91
92 // Used when performing indirect call analysis and promotion when cloning in
93 // the ThinLTO backend during applyImport.
94 std::unique_ptr<InstrProfSymtab> Symtab;
95 std::unique_ptr<ICallPromotionAnalysis> ICallAnalysis;
96
97public:
99 MemProfContextDisambiguation(const ModuleSummaryIndex *Summary = nullptr,
100 bool isSamplePGO = false);
101
103
104 LLVM_ABI void
105 run(ModuleSummaryIndex &Index,
107 isPrevailing,
108 LLVMContext &Ctx,
109 function_ref<void(StringRef, StringRef, const Twine &)> EmitRemark =
110 nullptr);
111};
112
113/// Strips MemProf attributes and metadata. Can be invoked by the pass pipeline
114/// when we don't have an index that has recorded that we are linking with
115/// allocation libraries containing the necessary APIs for downstream
116/// transformations.
117class MemProfRemoveInfo : public OptionalPassInfoMixin<MemProfRemoveInfo> {
118public:
120};
121
122} // end namespace llvm
123
124#endif // LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
uint64_t uint64_t
#define LLVM_ABI
Definition Compiler.h:211
This header defines various interfaces for pass management in LLVM.
Interface to identify indirect call promotion candidates.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function and variable summary information to aid decisions and implementation of importing.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVM_ABI MemProfContextDisambiguation(const ModuleSummaryIndex *Summary=nullptr, bool isSamplePGO=false)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Strips MemProf attributes and metadata.
LLVM_ABI 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:68
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Summary of memprof callsite metadata.
A CRTP mix-in for passes that can be skipped.