@@ -45,26 +45,6 @@ constexpr unsigned WeightsIdx = 1;
45
45
// the minimum number of operands for MD_prof nodes with branch weights
46
46
constexpr unsigned MinBWOps = 3 ;
47
47
48
- bool extractWeights (const MDNode *ProfileData,
49
- SmallVectorImpl<uint32_t > &Weights) {
50
- // Assume preconditions are already met (i.e. this is valid metadata)
51
- assert (ProfileData && " ProfileData was nullptr in extractWeights" );
52
- unsigned NOps = ProfileData->getNumOperands ();
53
-
54
- assert (WeightsIdx < NOps && " Weights Index must be less than NOps." );
55
- Weights.resize (NOps - WeightsIdx);
56
-
57
- for (unsigned Idx = WeightsIdx, E = NOps; Idx != E; ++Idx) {
58
- ConstantInt *Weight =
59
- mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand (Idx));
60
- assert (Weight && " Malformed branch_weight in MD_prof node" );
61
- assert (Weight->getValue ().getActiveBits () <= 32 &&
62
- " Too many bits for uint32_t" );
63
- Weights[Idx - WeightsIdx] = Weight->getZExtValue ();
64
- }
65
- return true ;
66
- }
67
-
68
48
// We may want to add support for other MD_prof types, so provide an abstraction
69
49
// for checking the metadata type.
70
50
bool isTargetMD (const MDNode *ProfData, const char *Name, unsigned MinOps) {
@@ -119,11 +99,30 @@ MDNode *getValidBranchWeightMDNode(const Instruction &I) {
119
99
return nullptr ;
120
100
}
121
101
102
+ void extractFromBranchWeightMD (const MDNode *ProfileData,
103
+ SmallVectorImpl<uint32_t > &Weights) {
104
+ assert (isBranchWeightMD (ProfileData) && " wrong metadata" );
105
+
106
+ unsigned NOps = ProfileData->getNumOperands ();
107
+ assert (WeightsIdx < NOps && " Weights Index must be less than NOps." );
108
+ Weights.resize (NOps - WeightsIdx);
109
+
110
+ for (unsigned Idx = WeightsIdx, E = NOps; Idx != E; ++Idx) {
111
+ ConstantInt *Weight =
112
+ mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand (Idx));
113
+ assert (Weight && " Malformed branch_weight in MD_prof node" );
114
+ assert (Weight->getValue ().getActiveBits () <= 32 &&
115
+ " Too many bits for uint32_t" );
116
+ Weights[Idx - WeightsIdx] = Weight->getZExtValue ();
117
+ }
118
+ }
119
+
122
120
bool extractBranchWeights (const MDNode *ProfileData,
123
121
SmallVectorImpl<uint32_t > &Weights) {
124
122
if (!isBranchWeightMD (ProfileData))
125
123
return false ;
126
- return extractWeights (ProfileData, Weights);
124
+ extractFromBranchWeightMD (ProfileData, Weights);
125
+ return true ;
127
126
}
128
127
129
128
bool extractBranchWeights (const Instruction &I,
0 commit comments