Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions llvm/include/llvm/Transforms/IPO/MemProfContextDisambiguation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#ifndef LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
#define LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H

#include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <functional>

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

// Builds the symtab and analysis used for ICP during ThinLTO backends.
bool initializeIndirectCallPromotionInfo(Module &M);

// Data structure for saving indirect call profile info for use in ICP with
// cloning.
struct ICallAnalysisData {
CallBase *CB;
std::vector<InstrProfValueData> CandidateProfileData;
uint32_t NumCandidates;
uint64_t TotalCount;
size_t CallsiteInfoStartIndex;
};

// Record information needed for ICP of an indirect call, depending on its
// profile information and the clone information recorded in the corresponding
// CallsiteInfo records. The SI iterator point to the current iteration point
// through AllCallsites in this function, and will be updated in this method
// as we iterate through profiled targets. The number of clones recorded for
// this indirect call is returned. The necessary information is recorded in
// the ICallAnalysisInfo list for later ICP.
unsigned recordICPInfo(CallBase *CB, ArrayRef<CallsiteInfo> AllCallsites,
ArrayRef<CallsiteInfo>::iterator &SI,
SmallVector<ICallAnalysisData> &ICallAnalysisInfo);

// Actually performs any needed ICP in the function, using the information
// recorded in the ICallAnalysisInfo list.
void performICP(Module &M, ArrayRef<CallsiteInfo> AllCallsites,
SmallVectorImpl<std::unique_ptr<ValueToValueMapTy>> &VMaps,
SmallVector<ICallAnalysisData> &ICallAnalysisInfo,
OptimizationRemarkEmitter &ORE);

/// Import summary containing cloning decisions for the ThinLTO backend.
const ModuleSummaryIndex *ImportSummary;

Expand All @@ -45,11 +78,16 @@ class MemProfContextDisambiguation

// Whether we are building with SamplePGO. This is needed for correctly
// updating profile metadata on speculatively promoted calls.
bool SamplePGO;
bool isSamplePGO;

// Used when performing indirect call analysis and promotion when cloning in
// the ThinLTO backend during applyImport.
std::unique_ptr<InstrProfSymtab> Symtab;
std::unique_ptr<ICallPromotionAnalysis> ICallAnalysis;

public:
MemProfContextDisambiguation(const ModuleSummaryIndex *Summary = nullptr,
bool SamplePGO = false);
bool isSamplePGO = false);

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);

Expand Down
Loading
Loading