LLVM: include/llvm/Analysis/CtxProfAnalysis.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ANALYSIS_CTXPROFANALYSIS_H

10#define LLVM_ANALYSIS_CTXPROFANALYSIS_H

11

19#include

20

21namespace llvm {

22

24

28

29

30class PGOContextualProfile {

33 struct FunctionInfo {

34 uint32_t NextCounterIndex = 0;

35 uint32_t NextCallsiteIndex = 0;

36 const std::string Name;

38 FunctionInfo(StringRef Name) : Name(Name) {}

39 };

40 PGOCtxProfile Profiles;

41

42

43

44 bool IsInSpecializedModule = false;

45

46

47

48 std::map<GlobalValue::GUID, FunctionInfo> FuncInfo;

49

50

52

53

54

55 PGOContextualProfile() = default;

56

57 void initIndex();

58

59public:

62

64 return Profiles.Contexts;

65 }

66

68

70

72 return getDefinedFunctionGUID(F) != 0;

73 }

74

76 auto It = FuncInfo.find(GUID);

77 if (It == FuncInfo.end())

78 return "";

79 return It->second.Name;

80 }

81

84 return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;

85 }

86

89 return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;

90 }

91

94 return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;

95 }

96

99 return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;

100 }

101

104

107

110

112 ModuleAnalysisManager::Invalidator &) {

113

114

116 return !PAC.preservedWhenStateless();

117 }

118};

119

121 const std::optional Profile;

122

123public:

126 std::optional Profile = std::nullopt);

127

129

131

132

133

135

136

138

139

142

143

146 SetVector<std::pair<CallBase *, Function *>> &Candidates);

147};

148

150 : public PassInfoMixin {

151public:

154

157

158private:

161};

162

163

164

165

166

167class ProfileAnnotatorImpl;

169 std::unique_ptr PImpl;

170

171public:

174

175

176

177

180

181

182

183

184

189};

190

191

192

193

194

195

196

197

198

199

201public:

203

204

205

208

210};

211

212}

213#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This header defines various interfaces for pass management in LLVM.

Reader for contextual iFDO profile, which comes in bitstream format.

ModuleAnalysisManager MAM

static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))

This file implements a set that has insertion order iteration characteristics.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

static LLVM_ABI uint64_t getGUID(const Function &F)

LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)

Assign a GUID if one is not already assign, as a function metadata named GUIDMetadataName.

static LLVM_ABI const char * GUIDMetadataName

Definition CtxProfAnalysis.h:207

LLVM Basic Block Representation.

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

PrintMode

Definition CtxProfAnalysis.h:152

@ Everything

Definition CtxProfAnalysis.h:152

@ YAML

Definition CtxProfAnalysis.h:152

LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)

LLVM_ABI CtxProfAnalysisPrinterPass(raw_ostream &OS)

static bool isRequired()

Definition CtxProfAnalysis.h:156

Definition CtxProfAnalysis.h:120

LLVM_ABI PGOContextualProfile run(Module &M, ModuleAnalysisManager &MAM)

static LLVM_ABI InstrProfIncrementInst * getBBInstrumentation(BasicBlock &BB)

Get the instruction instrumenting a BB, or nullptr if not present.

static LLVM_ABI InstrProfIncrementInstStep * getSelectInstrumentation(SelectInst &SI)

Get the step instrumentation associated with a select

static LLVM_ABI void collectIndirectCallPromotionList(CallBase &IC, Result &Profile, SetVector< std::pair< CallBase *, Function * > > &Candidates)

static LLVM_ABI InstrProfCallsite * getCallsiteInstrumentation(CallBase &CB)

Get the instruction instrumenting a callsite, or nullptr if that cannot be found.

static LLVM_ABI AnalysisKey Key

Definition CtxProfAnalysis.h:124

PGOContextualProfile Result

Definition CtxProfAnalysis.h:128

LLVM_ABI CtxProfAnalysis(std::optional< StringRef > Profile=std::nullopt)

uint64_t GUID

Declare a type to represent a global unique identifier for a global value.

This represents the llvm.instrprof.callsite intrinsic.

This represents the llvm.instrprof.increment.step intrinsic.

This represents the llvm.instrprof.increment intrinsic.

A Module instance is used to store all the information related to an LLVM module.

The instrumented contextual profile, produced by the CtxProfAnalysis.

Definition CtxProfAnalysis.h:30

LLVM_ABI void visit(ConstVisitor, const Function *F=nullptr) const

friend class CtxProfAnalysisPrinterPass

Definition CtxProfAnalysis.h:32

PGOContextualProfile(PGOContextualProfile &&)=default

LLVM_ABI const CtxProfFlatProfile flatten() const

LLVM_ABI bool isInSpecializedModule() const

LLVM_ABI void update(Visitor, const Function &F)

StringRef getFunctionName(GlobalValue::GUID GUID) const

Definition CtxProfAnalysis.h:75

bool invalidate(Module &, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)

Definition CtxProfAnalysis.h:111

friend class CtxProfAnalysis

Definition CtxProfAnalysis.h:31

uint32_t getNumCounters(const Function &F) const

Definition CtxProfAnalysis.h:82

function_ref< void(PGOCtxProfContext &)> Visitor

Definition CtxProfAnalysis.h:103

uint32_t allocateNextCounterIndex(const Function &F)

Definition CtxProfAnalysis.h:92

const PGOCtxProfile & profiles() const

Definition CtxProfAnalysis.h:67

function_ref< void(const PGOCtxProfContext &)> ConstVisitor

Definition CtxProfAnalysis.h:102

const CtxProfContextualProfiles & contexts() const

Definition CtxProfAnalysis.h:63

PGOContextualProfile(const PGOContextualProfile &)=delete

uint32_t getNumCallsites(const Function &F) const

Definition CtxProfAnalysis.h:87

uint32_t allocateNextCallsiteIndex(const Function &F)

Definition CtxProfAnalysis.h:97

LLVM_ABI const CtxProfFlatIndirectCallProfile flattenVirtCalls() const

bool isFunctionKnown(const Function &F) const

Definition CtxProfAnalysis.h:71

A node (context) in the loaded contextual profile, suitable for mutation during IPO passes.

A set of analyses that are preserved following a run of a transformation pass.

PreservedAnalysisChecker getChecker() const

Build a checker for this PreservedAnalyses and the specified analysis type.

LLVM_ABI ~ProfileAnnotator()

LLVM_ABI bool getSelectInstrProfile(SelectInst &SI, uint64_t &TrueCount, uint64_t &FalseCount) const

LLVM_ABI bool getOutgoingBranchWeights(BasicBlock &BB, SmallVectorImpl< uint64_t > &Profile, uint64_t &MaxCount) const

LLVM_ABI uint64_t getBBCount(const BasicBlock &BB) const

LLVM_ABI ProfileAnnotator(const Function &F, ArrayRef< uint64_t > RawCounters)

This class represents the LLVM 'select' instruction.

A vector that has set insertion semantics.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

StringRef - Represent a constant reference to a string, i.e.

size_t find(char C, size_t From=0) const

Search for the first character C in the string.

An efficient, type-erasing, non-owning reference to a callable.

This class implements an extremely fast bulk output stream that can only output to a stream.

This is an optimization pass for GlobalISel generic memory operations.

std::map< GlobalValue::GUID, SmallVector< uint64_t, 1 > > CtxProfFlatProfile

DenseMap< GlobalValue::GUID, uint64_t > FlatIndirectTargets

Definition CtxProfAnalysis.h:25

std::map< GlobalValue::GUID, PGOCtxProfContext > CtxProfContextualProfiles

DenseMap< GlobalValue::GUID, DenseMap< uint32_t, FlatIndirectTargets > > CtxProfFlatIndirectCallProfile

Definition CtxProfAnalysis.h:26

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

A CRTP mix-in that provides informational APIs needed for analysis passes.

A special type used by analysis passes to provide an address that identifies that particular analysis...

A CRTP mix-in to automatically provide informational APIs needed for passes.