LLVM: include/llvm/ProfileData/PGOCtxProfReader.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H

16#define LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H

17

23#include

24

25namespace llvm {

28

30

31

32

33

34

35

36

37

38

39

40

41class IndexNode {

42

43

44 friend class ::llvm::PGOCtxProfContext;

45 friend class ::llvm::PGOContextualProfile;

46

47 IndexNode *Previous = nullptr;

48 IndexNode *Next = nullptr;

49

50 ~IndexNode() {

51 if (Next)

52 Next->Previous = Previous;

53 if (Previous)

54 Previous->Next = Next;

55 }

56

58

60

62 Previous = Other.Previous;

63

64

66 Other.Next->Previous = this;

67 if (Other.Previous)

68 Other.Previous->Next = this;

69

70

71 Other.Next = nullptr;

72 Other.Previous = nullptr;

73 }

74 IndexNode() = default;

75};

76}

77

78

79

80

82 std::map<GlobalValue::GUID, SmallVector<uint64_t, 1>>;

83

84

85

86

87

88

89

90

92public:

93 using CallTargetMapTy = std::map<GlobalValue::GUID, PGOCtxProfContext>;

94 using CallsiteMapTy = std::map<uint32_t, CallTargetMapTy>;

95

96private:

99

102 const std::optional<uint64_t> RootEntryCount{};

103 std::optional Unhandled{};

105

108 std::optional<uint64_t> RootEntryCount = std::nullopt,

109 std::optional &&Unhandled = std::nullopt)

111 Unhandled(std::move(Unhandled)) {

112 assert(RootEntryCount.has_value() == Unhandled.has_value());

113 }

114

115 Expected<PGOCtxProfContext &>

117 SmallVectorImpl<uint64_t> &&Counters);

118

119

120

122

123public:

125 PGOCtxProfContext &operator=(const PGOCtxProfContext &) = delete;

127 PGOCtxProfContext &operator=(PGOCtxProfContext &&) = delete;

128

132

133 bool isRoot() const { return RootEntryCount.has_value(); }

135

137

139 assert(!Counters.empty() &&

140 "Functions are expected to have at their entry BB instrumented, so "

141 "there should always be at least 1 counter.");

142 return Counters[0];

143 }

144

147

151

153 auto [_, Inserted] = callsites().try_emplace(CSId, std::move(Other));

154 (void)Inserted;

156 "CSId was expected to be newly created as result of e.g. inlining");

157 }

158

160

162 return Callsites.find(I) != Callsites.end();

163 }

164

167 return Callsites.find(I)->second;

168 }

169

172 return Callsites.find(I)->second;

173 }

174

175

176

177

178 template

180 Guids.insert(GUID);

181 for (const auto &[_, Callsite] : Callsites)

182 for (const auto &[_, Callee] : Callsite)

183 Callee.getContainedGuids(Guids);

184 }

185};

186

188 std::map<GlobalValue::GUID, PGOCtxProfContext>;

198

203 Error readMetadata();

206

209

213

217

218public:

222

224};

225

227 const PGOCtxProfile &Profile);

228}

229#endif

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

static StringRef substr(StringRef Str, uint64_t Len)

This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.

Lightweight error class with error context and mandatory checking.

Tagged union holding either a T or a Error.

uint64_t GUID

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

The instrumented contextual profile, produced by the CtxProfAnalysis.

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

Definition PGOCtxProfReader.h:91

CallTargetMapTy & callsite(uint32_t I)

Definition PGOCtxProfReader.h:170

SmallVectorImpl< uint64_t > & counters()

Definition PGOCtxProfReader.h:131

bool isRoot() const

Definition PGOCtxProfReader.h:133

bool hasCallsite(uint32_t I) const

Definition PGOCtxProfReader.h:161

void resizeCounters(uint32_t Size)

Definition PGOCtxProfReader.h:159

GlobalValue::GUID guid() const

Definition PGOCtxProfReader.h:129

void ingestAllContexts(uint32_t CSId, CallTargetMapTy &&Other)

Definition PGOCtxProfReader.h:152

void getContainedGuids(TSetOfGUIDs &Guids) const

Insert this node's GUID as well as the GUIDs of the transitive closure of child nodes,...

Definition PGOCtxProfReader.h:179

PGOCtxProfContext & operator=(const PGOCtxProfContext &)=delete

friend class PGOContextualProfile

Definition PGOCtxProfReader.h:98

const CallTargetMapTy & callsite(uint32_t I) const

Definition PGOCtxProfReader.h:165

PGOCtxProfContext & operator=(PGOCtxProfContext &&)=delete

friend class PGOCtxProfileReader

Definition PGOCtxProfReader.h:97

uint64_t getEntrycount() const

Definition PGOCtxProfReader.h:138

const SmallVectorImpl< uint64_t > & counters() const

Definition PGOCtxProfReader.h:130

std::map< uint32_t, CallTargetMapTy > CallsiteMapTy

Definition PGOCtxProfReader.h:94

const CtxProfFlatProfile & getUnhandled() const

Definition PGOCtxProfReader.h:136

void ingestContext(uint32_t CSId, PGOCtxProfContext &&Other)

Definition PGOCtxProfReader.h:148

CallsiteMapTy & callsites()

Definition PGOCtxProfReader.h:146

PGOCtxProfContext(const PGOCtxProfContext &)=delete

uint64_t getTotalRootEntryCount() const

Definition PGOCtxProfReader.h:134

PGOCtxProfContext(PGOCtxProfContext &&)=default

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

Definition PGOCtxProfReader.h:93

const CallsiteMapTy & callsites() const

Definition PGOCtxProfReader.h:145

LLVM_ABI Expected< PGOCtxProfile > loadProfiles()

PGOCtxProfileReader(StringRef Buffer)

Definition PGOCtxProfReader.h:219

Write one or more ContextNodes to the provided raw_fd_stream.

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

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

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

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

Definition PGOCtxProfReader.h:41

friend class ::llvm::PGOCtxProfContext

Definition PGOCtxProfReader.h:44

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

Definition PGOCtxProfReader.h:29

This is an optimization pass for GlobalISel generic memory operations.

auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)

Get the size of a range.

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

Definition PGOCtxProfReader.h:81

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

Definition PGOCtxProfReader.h:187

FunctionAddr VTableAddr Next

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

LLVM_ABI void convertCtxProfToYaml(raw_ostream &OS, const PGOCtxProfile &Profile)

Implement std::hash so that hash_code can be used in STL containers.

PGOCtxProfile(PGOCtxProfile &&)=default

PGOCtxProfile & operator=(PGOCtxProfile &&)=default

CtxProfFlatProfile FlatProfiles

Definition PGOCtxProfReader.h:191

PGOCtxProfile(const PGOCtxProfile &)=delete

CtxProfContextualProfiles Contexts

Definition PGOCtxProfReader.h:190