LLVM: include/llvm/Transforms/IPO/SampleContextTracker.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_TRANSFORMS_IPO_SAMPLECONTEXTTRACKER_H

16#define LLVM_TRANSFORMS_IPO_SAMPLECONTEXTTRACKER_H

17

22#include

23#include

24#include

25

26namespace llvm {

31

32

33

34

36public:

41 : ParentContext(Parent), FuncName(FName), FuncSamples(FSamples),

42 CallSiteLoc(CallLoc){};

44 FunctionId ChildName);

49 bool AllowCreate = true);

51 FunctionId ChildName);

64

65private:

66

67 std::map<uint64_t, ContextTrieNode> AllChildContext;

68

69

71

72

73 FunctionId FuncName;

74

75

76 FunctionSamples *FuncSamples;

77

78

79 std::optional<uint32_t> FuncSize;

80

81

82 LineLocation CallSiteLoc;

83};

84

85

86

87

88

89

90

91

93public:

95

100

102

103

106

107 LLVM_ABI std::vector<const FunctionSamples *>

109

110

112

114

118 bool AllowCreate);

119

120

122 bool MergeContext = true);

123

125 bool MergeContext = true);

126

128

130

131

132

138

139

144 auto I = ProfileToNodeMap.find(FSamples);

145 if (I == ProfileToNodeMap.end())

146 return nullptr;

147 return I->second;

148 }

151 return FuncToCtxtProfiles;

152 }

153

155 Iterator, std::forward_iterator_tag, ContextTrieNode *,

156 std::ptrdiff_t, ContextTrieNode **, ContextTrieNode *> {

157 std::queue<ContextTrieNode *> NodeQueue;

158

159 public:

163 assert(!NodeQueue.empty() && "Iterator already at the end");

165 NodeQueue.pop();

166 for (auto &It : Node->getAllChildContext())

167 NodeQueue.push(&It.second);

168 return *this;

169 }

170

172 if (NodeQueue.empty() && Other.NodeQueue.empty())

173 return true;

174 if (NodeQueue.empty() || Other.NodeQueue.empty())

175 return false;

176 return NodeQueue.front() == Other.NodeQueue.front();

177 }

178

180 assert(!NodeQueue.empty() && "Invalid access to end iterator");

181 return NodeQueue.front();

182 }

183 };

184

187

188#ifndef NDEBUG

189

192#endif

193

195

196private:

211 ProfileToNodeMap[FSample] = Node;

212 }

213

214 HashKeyMap<std::unordered_map, FunctionId, ContextSamplesTy>

215 FuncToCtxtProfiles;

216

217

218 std::unordered_map<const FunctionSamples *, ContextTrieNode *>

219 ProfileToNodeMap;

220

221

222 const DenseMap<uint64_t, StringRef> *GUIDToFuncNameMap;

223

224

225 ContextTrieNode RootContext;

226};

227

228}

229#endif

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

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

Definition SampleContextTracker.h:35

LLVM_ABI ContextTrieNode * getOrCreateChildContext(const LineLocation &CallSite, FunctionId ChildName, bool AllowCreate=true)

LLVM_ABI std::map< uint64_t, ContextTrieNode > & getAllChildContext()

LLVM_ABI void setCallSiteLoc(const LineLocation &Loc)

LLVM_ABI LineLocation getCallSiteLoc() const

LLVM_ABI FunctionSamples * getFunctionSamples() const

LLVM_ABI std::optional< uint32_t > getFunctionSize() const

LLVM_ABI ContextTrieNode * getHottestChildContext(const LineLocation &CallSite)

LLVM_ABI void setParentContext(ContextTrieNode *Parent)

LLVM_ABI void removeChildContext(const LineLocation &CallSite, FunctionId ChildName)

LLVM_ABI void addFunctionSize(uint32_t FSize)

LLVM_ABI FunctionId getFuncName() const

LLVM_ABI ContextTrieNode * getChildContext(const LineLocation &CallSite, FunctionId ChildName)

LLVM_ABI ContextTrieNode * getParentContext() const

LLVM_ABI void setFunctionSamples(FunctionSamples *FSamples)

ContextTrieNode(ContextTrieNode *Parent=nullptr, FunctionId FName=FunctionId(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})

Definition SampleContextTracker.h:37

Definition SampleContextTracker.h:156

Iterator(ContextTrieNode *Node)

Definition SampleContextTracker.h:161

bool operator==(const Iterator &Other) const

Definition SampleContextTracker.h:171

Iterator & operator++()

Definition SampleContextTracker.h:162

ContextTrieNode * operator*() const

Definition SampleContextTracker.h:179

LLVM_ABI void promoteMergeContextSamplesTree(const Instruction &Inst, FunctionId CalleeName)

LLVM_ABI FunctionSamples * getBaseSamplesFor(const Function &Func, bool MergeContext=true)

LLVM_ABI ContextTrieNode * getOrCreateContextPath(const SampleContext &Context, bool AllowCreate)

HashKeyMap< std::unordered_map, FunctionId, ContextSamplesTy > & getFuncToCtxtProfiles()

Definition SampleContextTracker.h:150

LLVM_ABI StringRef getFuncNameFor(ContextTrieNode *Node) const

LLVM_ABI void populateFuncToCtxtMap()

LLVM_ABI ContextTrieNode & getRootContext()

LLVM_ABI std::string getContextString(const FunctionSamples &FSamples) const

ContextTrieNode * getContextNodeForProfile(const FunctionSamples *FSamples) const

Definition SampleContextTracker.h:143

LLVM_ABI FunctionSamples * getContextSamplesFor(const DILocation *DIL)

std::vector< FunctionSamples * > ContextSamplesTy

Definition SampleContextTracker.h:94

Iterator begin()

Definition SampleContextTracker.h:185

LLVM_ABI ContextSamplesTy & getAllContextSamplesFor(const Function &Func)

LLVM_ABI void markContextSamplesInlined(const FunctionSamples *InlinedSamples)

LLVM_ABI void createContextLessProfileMap(SampleProfileMap &ContextLessProfiles)

Iterator end()

Definition SampleContextTracker.h:186

LLVM_ABI std::vector< const FunctionSamples * > getIndirectCalleeContextSamplesFor(const DILocation *DIL)

SampleContextTracker()=default

LLVM_ABI FunctionSamples * getCalleeContextSamplesFor(const CallBase &Inst, StringRef CalleeName)

LLVM_ABI ContextTrieNode * getContextFor(const SampleContext &Context)

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

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...

This class represents a function that is read from a sample profile.

Representation of the samples collected for a function.

This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the origi...

This class provides operator overloads to the map container using MD5 as the key type,...

This is an optimization pass for GlobalISel generic memory operations.

Represents the relative location of an instruction.