@@ -88,16 +88,23 @@ static void extractFromBranchWeightMD(const MDNode *ProfileData,
88
88
89
89
namespace llvm {
90
90
91
+ const char *MDProfLabels::BranchWeights = " branch_weights" ;
92
+ const char *MDProfLabels::ExpectedBranchWeights = " expected" ;
93
+ const char *MDProfLabels::ValueProfile = " VP" ;
94
+ const char *MDProfLabels::FunctionEntryCount = " function_entry_count" ;
95
+ const char *MDProfLabels::SyntheticFunctionEntryCount =
96
+ " synthetic_function_entry_count" ;
97
+
91
98
bool hasProfMD (const Instruction &I) {
92
99
return I.hasMetadata (LLVMContext::MD_prof);
93
100
}
94
101
95
102
bool isBranchWeightMD (const MDNode *ProfileData) {
96
- return isTargetMD (ProfileData, " branch_weights " , MinBWOps);
103
+ return isTargetMD (ProfileData, MDProfLabels::BranchWeights , MinBWOps);
97
104
}
98
105
99
106
static bool isValueProfileMD (const MDNode *ProfileData) {
100
- return isTargetMD (ProfileData, " VP " , MinVPOps);
107
+ return isTargetMD (ProfileData, MDProfLabels::ValueProfile , MinVPOps);
101
108
}
102
109
103
110
bool hasBranchWeightMD (const Instruction &I) {
@@ -131,7 +138,8 @@ bool hasBranchWeightOrigin(const MDNode *ProfileData) {
131
138
// NOTE: if we ever have more types of branch weight provenance,
132
139
// we need to check the string value is "expected". For now, we
133
140
// supply a more generic API, and avoid the spurious comparisons.
134
- assert (ProfDataName == nullptr || ProfDataName->getString () == " expected" );
141
+ assert (ProfDataName == nullptr ||
142
+ ProfDataName->getString () == MDProfLabels::ExpectedBranchWeights);
135
143
return ProfDataName != nullptr ;
136
144
}
137
145
@@ -210,7 +218,7 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
210
218
if (!ProfDataName)
211
219
return false ;
212
220
213
- if (ProfDataName->getString () == " branch_weights " ) {
221
+ if (ProfDataName->getString () == MDProfLabels::BranchWeights ) {
214
222
unsigned Offset = getBranchWeightOffset (ProfileData);
215
223
for (unsigned Idx = Offset; Idx < ProfileData->getNumOperands (); ++Idx) {
216
224
auto *V = mdconst::extract<ConstantInt>(ProfileData->getOperand (Idx));
@@ -219,7 +227,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
219
227
return true ;
220
228
}
221
229
222
- if (ProfDataName->getString () == " VP" && ProfileData->getNumOperands () > 3 ) {
230
+ if (ProfDataName->getString () == MDProfLabels::ValueProfile &&
231
+ ProfileData->getNumOperands () > 3 ) {
223
232
TotalVal = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand (2 ))
224
233
->getValue ()
225
234
.getZExtValue ();
@@ -246,8 +255,9 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
246
255
return ;
247
256
248
257
auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand (0 ));
249
- if (!ProfDataName || (ProfDataName->getString () != " branch_weights" &&
250
- ProfDataName->getString () != " VP" ))
258
+ if (!ProfDataName ||
259
+ (ProfDataName->getString () != MDProfLabels::BranchWeights &&
260
+ ProfDataName->getString () != MDProfLabels::ValueProfile))
251
261
return ;
252
262
253
263
if (!hasCountTypeMD (I))
@@ -259,7 +269,7 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
259
269
SmallVector<Metadata *, 3 > Vals;
260
270
Vals.push_back (ProfileData->getOperand (0 ));
261
271
APInt APS (128 , S), APT (128 , T);
262
- if (ProfDataName->getString () == " branch_weights " &&
272
+ if (ProfDataName->getString () == MDProfLabels::BranchWeights &&
263
273
ProfileData->getNumOperands () > 0 ) {
264
274
// Using APInt::div may be expensive, but most cases should fit 64 bits.
265
275
APInt Val (128 ,
@@ -270,7 +280,7 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
270
280
Val *= APS;
271
281
Vals.push_back (MDB.createConstant (ConstantInt::get (
272
282
Type::getInt32Ty (C), Val.udiv (APT).getLimitedValue (UINT32_MAX))));
273
- } else if (ProfDataName->getString () == " VP " )
283
+ } else if (ProfDataName->getString () == MDProfLabels::ValueProfile )
274
284
for (unsigned Idx = 1 ; Idx < ProfileData->getNumOperands (); Idx += 2 ) {
275
285
// The first value is the key of the value profile, which will not change.
276
286
Vals.push_back (ProfileData->getOperand (Idx));
0 commit comments