Skip to content

Commit fe04fd2

Browse files
committed
Address remaining comments
1 parent f5b8df3 commit fe04fd2

File tree

2 files changed

+225
-166
lines changed

2 files changed

+225
-166
lines changed

llvm/include/llvm/Transforms/IPO/MemProfContextDisambiguation.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#ifndef LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
1616
#define LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
1717

18+
#include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
1819
#include "llvm/IR/GlobalValue.h"
1920
#include "llvm/IR/ModuleSummaryIndex.h"
2021
#include "llvm/IR/PassManager.h"
22+
#include "llvm/Transforms/Utils/ValueMapper.h"
2123
#include <functional>
2224

2325
namespace llvm {
@@ -36,6 +38,37 @@ class MemProfContextDisambiguation
3638
/// the IR.
3739
bool applyImport(Module &M);
3840

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,
62+
ArrayRef<CallsiteInfo>::iterator &SI,
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+
SmallVectorImpl<std::unique_ptr<ValueToValueMapTy>> &VMaps,
69+
SmallVector<ICallAnalysisData> &ICallAnalysisInfo,
70+
OptimizationRemarkEmitter &ORE);
71+
3972
/// Import summary containing cloning decisions for the ThinLTO backend.
4073
const ModuleSummaryIndex *ImportSummary;
4174

@@ -47,6 +80,11 @@ class MemProfContextDisambiguation
4780
// updating profile metadata on speculatively promoted calls.
4881
bool isSamplePGO;
4982

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+
5088
public:
5189
MemProfContextDisambiguation(const ModuleSummaryIndex *Summary = nullptr,
5290
bool isSamplePGO = false);

0 commit comments

Comments
 (0)