LLVM: include/llvm/IR/ProfDataUtils.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_IR_PROFDATAUTILS_H

16#define LLVM_IR_PROFDATAUTILS_H

17

21#include

22#include <type_traits>

23

24namespace llvm {

33

34

35

37

38

40

41

43

44

46

47

48

49

50

51

53

54

55

56

57

58

60

61

62

63

64

65

67

68

69

70

71

72

74

75

76

78

79

80

82

83

85

87

88

89

90

91

92

93

96

97

98

101

102

103

106

107

108

109

110

111

112

115

116

117

118

119

120

121

122

125

126

127

128

129

130

131

134

135

136

137

138

139

140

143

144

145

146

147

148

150 bool IsExpected, bool ElideAllZero = false);

151

152

154

155

156

158 bool IsExpected,

159 bool ElideAllZero = false);

160

161

162

163

166 std::optional<uint64_t> KnownMaxCount = std::nullopt);

167

168

169

170

171

173 return MaxCount < std::numeric_limits<uint32_t>::max()

174 ? 1

175 : MaxCount / std::numeric_limits<uint32_t>::max() + 1;

176}

177

178

179

180

181

184 assert(Scaled <= std::numeric_limits<uint32_t>::max() && "overflow 32-bits");

186}

187

188

189

190

191

192

193

194

195

198

199

200

201

202

203

206 const Function *F = nullptr);

207

208

209

212

215

216

218

219

220

221

222

223

224template <typename T1, typename T2,

225 typename = typename std::enable_if<

226 std::is_arithmetic_v && std::is_arithmetic_v &&

231

232

233

234

235

236

237

238

239

240

241

242

243

244

247 uint64_t FalseWeight = B1[1] * B2[1];

248 uint64_t TrueWeight = B1[0] * (B2[0] + B2[1]) + B1[1] * B2[0];

249 return {TrueWeight, FalseWeight};

250}

251}

252#endif

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

This file defines the SmallVector class.

static const char PassName[]

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

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.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights)

Retrieve the total of all weights from MD_prof data.

LLVM_ABI unsigned getBranchWeightOffset(const MDNode *ProfileData)

Return the offset to the first branch weight data.

LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName, const Function *F=nullptr)

Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...

LLVM_ABI bool isBranchWeightMD(const MDNode *ProfileData)

Checks if an MDNode contains Branch Weight Metadata.

LLVM_ABI bool isExplicitlyUnknownProfileMetadata(const MDNode &MD)

LLVM_ABI MDNode * getBranchWeightMDNode(const Instruction &I)

Get the branch weights metadata node.

LLVM_ABI void setExplicitlyUnknownBranchWeights(Instruction &I, StringRef PassName)

Specify that the branch weights for this terminator cannot be known at compile time.

LLVM_ABI bool hasBranchWeightOrigin(const Instruction &I)

Check if Branch Weight Metadata has an "expected" field from an llvm.expect* intrinsic.

LLVM_ABI void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights, bool IsExpected, bool ElideAllZero=false)

Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...

LLVM_ABI SmallVector< uint32_t > fitWeights(ArrayRef< uint64_t > Weights)

Push the weights right to fit in uint32_t.

LLVM_ABI MDNode * getValidBranchWeightMDNode(const Instruction &I)

Get the valid branch weights metadata node.

LLVM_ABI bool hasValidBranchWeightMD(const Instruction &I)

Checks if an instructions has valid Branch Weight Metadata.

FunctionAddr VTableAddr Count

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

LLVM_ABI void setExplicitlyUnknownFunctionEntryCount(Function &F, StringRef PassName)

Analogous to setExplicitlyUnknownBranchWeights, but for functions and their entry counts.

LLVM_ABI bool isValueProfileMD(const MDNode *ProfileData)

Checks if an MDNode contains value profiling Metadata.

LLVM_ABI unsigned getNumBranchWeights(const MDNode &ProfileData)

LLVM_ABI void extractFromBranchWeightMD32(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)

Faster version of extractBranchWeights() that skips checks and must only be called with "branch_weigh...

LLVM_ABI bool hasExplicitlyUnknownBranchWeights(const Instruction &I)

LLVM_ABI bool hasProfMD(const Instruction &I)

Checks if an Instruction has MD_prof Metadata.

LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)

Extract branch weights from MD_prof metadata.

LLVM_ABI const char * LLVMLoopEstimatedTripCount

Profile-based loop metadata that should be accessed only by using llvm::getLoopEstimatedTripCount and...

uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale)

Scale an individual branch count.

Definition ProfDataUtils.h:182

SmallVector< uint64_t, 2 > getDisjunctionWeights(const SmallVector< T1, 2 > &B1, const SmallVector< T2, 2 > &B2)

Get the branch weights of a branch conditioned on b1 || b2, where b1 and b2 are 2 booleans that are t...

Definition ProfDataUtils.h:229

LLVM_ABI bool hasBranchWeightMD(const Instruction &I)

Checks if an instructions has Branch Weight Metadata.

LLVM_ABI void setFittedBranchWeights(Instruction &I, ArrayRef< uint64_t > Weights, bool IsExpected, bool ElideAllZero=false)

Variant of setBranchWeights where the Weights will be fit first to uint32_t by shifting right.

uint64_t calculateCountScale(uint64_t MaxCount)

Calculate what to divide by to scale counts.

Definition ProfDataUtils.h:172

LLVM_ABI SmallVector< uint32_t > downscaleWeights(ArrayRef< uint64_t > Weights, std::optional< uint64_t > KnownMaxCount=std::nullopt)

downscale the given weights preserving the ratio.

LLVM_ABI void scaleProfData(Instruction &I, uint64_t S, uint64_t T)

Scaling the profile data attached to 'I' using the ratio of S/T.

LLVM_ABI void extractFromBranchWeightMD64(const MDNode *ProfileData, SmallVectorImpl< uint64_t > &Weights)

Faster version of extractBranchWeights() that skips checks and must only be called with "branch_weigh...

Definition ProfDataUtils.h:25

static LLVM_ABI const char * ExpectedBranchWeights

Definition ProfDataUtils.h:30

static LLVM_ABI const char * SyntheticFunctionEntryCount

Definition ProfDataUtils.h:29

static LLVM_ABI const char * UnknownBranchWeightsMarker

Definition ProfDataUtils.h:31

static LLVM_ABI const char * ValueProfile

Definition ProfDataUtils.h:27

static LLVM_ABI const char * FunctionEntryCount

Definition ProfDataUtils.h:28

static LLVM_ABI const char * BranchWeights

Definition ProfDataUtils.h:26