@@ -88,16 +88,23 @@ static void extractFromBranchWeightMD(const MDNode *ProfileData,
8888
8989namespace  llvm  {
9090
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+ 
9198bool  hasProfMD (const  Instruction &I) {
9299  return  I.hasMetadata (LLVMContext::MD_prof);
93100}
94101
95102bool  isBranchWeightMD (const  MDNode *ProfileData) {
96-   return  isTargetMD (ProfileData, " branch_weights "  , MinBWOps);
103+   return  isTargetMD (ProfileData, MDProfLabels::BranchWeights , MinBWOps);
97104}
98105
99106static  bool  isValueProfileMD (const  MDNode *ProfileData) {
100-   return  isTargetMD (ProfileData, " VP "  , MinVPOps);
107+   return  isTargetMD (ProfileData, MDProfLabels::ValueProfile , MinVPOps);
101108}
102109
103110bool  hasBranchWeightMD (const  Instruction &I) {
@@ -131,7 +138,8 @@ bool hasBranchWeightOrigin(const MDNode *ProfileData) {
131138  //  NOTE: if we ever have more types of branch weight provenance,
132139  //  we need to check the string value is "expected". For now, we
133140  //  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);
135143  return  ProfDataName != nullptr ;
136144}
137145
@@ -210,7 +218,7 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
210218  if  (!ProfDataName)
211219    return  false ;
212220
213-   if  (ProfDataName->getString () == " branch_weights "  ) {
221+   if  (ProfDataName->getString () == MDProfLabels::BranchWeights ) {
214222    unsigned  Offset = getBranchWeightOffset (ProfileData);
215223    for  (unsigned  Idx = Offset; Idx < ProfileData->getNumOperands (); ++Idx) {
216224      auto  *V = mdconst::extract<ConstantInt>(ProfileData->getOperand (Idx));
@@ -219,7 +227,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
219227    return  true ;
220228  }
221229
222-   if  (ProfDataName->getString () == " VP"   && ProfileData->getNumOperands () > 3 ) {
230+   if  (ProfDataName->getString () == MDProfLabels::ValueProfile &&
231+       ProfileData->getNumOperands () > 3 ) {
223232    TotalVal = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand (2 ))
224233                   ->getValue ()
225234                   .getZExtValue ();
@@ -246,8 +255,9 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
246255    return ;
247256
248257  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))
251261    return ;
252262
253263  if  (!hasCountTypeMD (I))
@@ -259,7 +269,7 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
259269  SmallVector<Metadata *, 3 > Vals;
260270  Vals.push_back (ProfileData->getOperand (0 ));
261271  APInt APS (128 , S), APT (128 , T);
262-   if  (ProfDataName->getString () == " branch_weights "   &&
272+   if  (ProfDataName->getString () == MDProfLabels::BranchWeights  &&
263273      ProfileData->getNumOperands () > 0 ) {
264274    //  Using APInt::div may be expensive, but most cases should fit 64 bits.
265275    APInt Val (128 ,
@@ -270,7 +280,7 @@ void scaleProfData(Instruction &I, uint64_t S, uint64_t T) {
270280    Val *= APS;
271281    Vals.push_back (MDB.createConstant (ConstantInt::get (
272282        Type::getInt32Ty (C), Val.udiv (APT).getLimitedValue (UINT32_MAX))));
273-   } else  if  (ProfDataName->getString () == " VP "  )
283+   } else  if  (ProfDataName->getString () == MDProfLabels::ValueProfile )
274284    for  (unsigned  Idx = 1 ; Idx < ProfileData->getNumOperands (); Idx += 2 ) {
275285      //  The first value is the key of the value profile, which will not change.
276286      Vals.push_back (ProfileData->getOperand (Idx));
0 commit comments