@@ -70,50 +70,18 @@ Metadata *ProfileSummary::getDetailedSummaryMD(LLVMContext &Context) {
70
70
// to the kind of profile summary as returned by getFormatSpecificMD.
71
71
Metadata *ProfileSummary::getMD (LLVMContext &Context) {
72
72
std::vector<Metadata *> Components;
73
- Components.push_back (getKeyValMD (Context, " ProfileFormat" , getKindStr ()));
74
- std::vector<Metadata *> Res = getFormatSpecificMD (Context);
75
- Components.insert (Components.end (), Res.begin (), Res.end ());
76
- return MDTuple::get (Context, Components);
77
- }
78
-
79
- // Returns a vector of MDTuples specific to InstrProfSummary. The first six
80
- // elements of this vector are (Key, Val) pairs of the six scalar fields of
81
- // InstrProfSummary (TotalCount, MaxBlockCount, MaxInternalBlockCount,
82
- // MaxFunctionCount, NumBlocks, NumFunctions). The last element of this vector
83
- // is an MDTuple returned by getDetailedSummaryMD.
84
- std::vector<Metadata *>
85
- InstrProfSummary::getFormatSpecificMD (LLVMContext &Context) {
86
- std::vector<Metadata *> Components;
73
+ Components.push_back (getKeyValMD (Context, " ProfileFormat" , KindStr[PSK]));
87
74
88
75
Components.push_back (getKeyValMD (Context, " TotalCount" , getTotalCount ()));
76
+ Components.push_back (getKeyValMD (Context, " MaxCount" , getMaxCount ()));
89
77
Components.push_back (
90
- getKeyValMD (Context, " MaxBlockCount" , getMaxBlockCount ()));
91
- Components.push_back (getKeyValMD (Context, " MaxInternalBlockCount" ,
92
- getMaxInternalBlockCount ()));
78
+ getKeyValMD (Context, " MaxInternalCount" , getMaxInternalCount ()));
93
79
Components.push_back (
94
80
getKeyValMD (Context, " MaxFunctionCount" , getMaxFunctionCount ()));
95
- Components.push_back (getKeyValMD (Context, " NumBlocks " , getNumBlocks ()));
81
+ Components.push_back (getKeyValMD (Context, " NumCounts " , getNumCounts ()));
96
82
Components.push_back (getKeyValMD (Context, " NumFunctions" , getNumFunctions ()));
97
-
98
- Components.push_back (getDetailedSummaryMD (Context));
99
- return Components;
100
- }
101
-
102
- std::vector<Metadata *>
103
- SampleProfileSummary::getFormatSpecificMD (LLVMContext &Context) {
104
- std::vector<Metadata *> Components;
105
-
106
- Components.push_back (getKeyValMD (Context, " TotalSamples" , getTotalSamples ()));
107
- Components.push_back (
108
- getKeyValMD (Context, " MaxSamplesPerLine" , getMaxSamplesPerLine ()));
109
- Components.push_back (
110
- getKeyValMD (Context, " MaxFunctionCount" , getMaxFunctionCount ()));
111
- Components.push_back (
112
- getKeyValMD (Context, " NumLinesWithSamples" , getNumLinesWithSamples ()));
113
- Components.push_back (getKeyValMD (Context, " NumFunctions" , NumFunctions));
114
-
115
83
Components.push_back (getDetailedSummaryMD (Context));
116
- return Components;
84
+ return MDTuple::get (Context, Components) ;
117
85
}
118
86
119
87
// Parse an MDTuple representing (Key, Val) pair.
@@ -175,83 +143,47 @@ static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary) {
175
143
return true ;
176
144
}
177
145
178
- // Parse an MDTuple representing an InstrProfSummary object.
179
- static ProfileSummary *getInstrProfSummaryFromMD (MDTuple *Tuple) {
180
- uint64_t NumBlocks, TotalCount, NumFunctions, MaxFunctionCount, MaxBlockCount,
181
- MaxInternalBlockCount;
182
- SummaryEntryVector Summary;
183
-
146
+ ProfileSummary *ProfileSummary::getFromMD (Metadata *MD) {
147
+ if (!isa<MDTuple>(MD))
148
+ return nullptr ;
149
+ MDTuple *Tuple = cast<MDTuple>(MD);
184
150
if (Tuple->getNumOperands () != 8 )
185
151
return nullptr ;
186
152
187
- // Skip operand 0 which has been already parsed in the caller
153
+ auto &FormatMD = Tuple->getOperand (0 );
154
+ ProfileSummary::Kind SummaryKind;
155
+ if (isKeyValuePair (dyn_cast_or_null<MDTuple>(FormatMD), " ProfileFormat" ,
156
+ " SampleProfile" ))
157
+ SummaryKind = PSK_Sample;
158
+ else if (isKeyValuePair (dyn_cast_or_null<MDTuple>(FormatMD), " ProfileFormat" ,
159
+ " InstrProf" ))
160
+ SummaryKind = PSK_Instr;
161
+ else
162
+ return nullptr ;
163
+
164
+ uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount,
165
+ MaxInternalCount;
188
166
if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (1 )), " TotalCount" ,
189
167
TotalCount))
190
168
return nullptr ;
191
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (2 )), " MaxBlockCount" ,
192
- MaxBlockCount))
169
+ if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (2 )), " MaxCount" , MaxCount))
193
170
return nullptr ;
194
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (3 )), " MaxInternalBlockCount " ,
195
- MaxInternalBlockCount ))
171
+ if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (3 )), " MaxInternalCount " ,
172
+ MaxInternalCount ))
196
173
return nullptr ;
197
174
if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (4 )), " MaxFunctionCount" ,
198
175
MaxFunctionCount))
199
176
return nullptr ;
200
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (5 )), " NumBlocks " , NumBlocks ))
177
+ if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (5 )), " NumCounts " , NumCounts ))
201
178
return nullptr ;
202
179
if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (6 )), " NumFunctions" ,
203
180
NumFunctions))
204
181
return nullptr ;
205
- if (!getSummaryFromMD (dyn_cast<MDTuple>(Tuple->getOperand (7 )), Summary))
206
- return nullptr ;
207
- return new InstrProfSummary (TotalCount, MaxBlockCount, MaxInternalBlockCount,
208
- MaxFunctionCount, NumBlocks, NumFunctions,
209
- Summary);
210
- }
211
182
212
- // Parse an MDTuple representing a SampleProfileSummary object.
213
- static ProfileSummary *getSampleProfileSummaryFromMD (MDTuple *Tuple) {
214
- uint64_t TotalSamples, MaxSamplesPerLine, MaxFunctionCount,
215
- NumLinesWithSamples, NumFunctions;
216
183
SummaryEntryVector Summary;
217
-
218
- if (Tuple->getNumOperands () != 7 )
219
- return nullptr ;
220
-
221
- // Skip operand 0 which has been already parsed in the caller
222
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (1 )), " TotalSamples" ,
223
- TotalSamples))
224
- return nullptr ;
225
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (2 )), " MaxSamplesPerLine" ,
226
- MaxSamplesPerLine))
227
- return nullptr ;
228
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (3 )), " MaxFunctionCount" ,
229
- MaxFunctionCount))
230
- return nullptr ;
231
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (4 )), " NumLinesWithSamples" ,
232
- NumLinesWithSamples))
233
- return nullptr ;
234
- if (!getVal (dyn_cast<MDTuple>(Tuple->getOperand (5 )), " NumFunctions" ,
235
- NumFunctions))
236
- return nullptr ;
237
- if (!getSummaryFromMD (dyn_cast<MDTuple>(Tuple->getOperand (6 )), Summary))
238
- return nullptr ;
239
- return new SampleProfileSummary (TotalSamples, MaxSamplesPerLine,
240
- MaxFunctionCount, NumLinesWithSamples,
241
- NumFunctions, Summary);
242
- }
243
-
244
- ProfileSummary *ProfileSummary::getFromMD (Metadata *MD) {
245
- if (!isa<MDTuple>(MD))
246
- return nullptr ;
247
- MDTuple *Tuple = cast<MDTuple>(MD);
248
- auto &FormatMD = Tuple->getOperand (0 );
249
- if (isKeyValuePair (dyn_cast_or_null<MDTuple>(FormatMD), " ProfileFormat" ,
250
- " SampleProfile" ))
251
- return getSampleProfileSummaryFromMD (Tuple);
252
- else if (isKeyValuePair (dyn_cast_or_null<MDTuple>(FormatMD), " ProfileFormat" ,
253
- " InstrProf" ))
254
- return getInstrProfSummaryFromMD (Tuple);
255
- else
184
+ if (!getSummaryFromMD (dyn_cast<MDTuple>(Tuple->getOperand (7 )), Summary))
256
185
return nullptr ;
186
+ return new ProfileSummary (SummaryKind, Summary, TotalCount, MaxCount,
187
+ MaxInternalCount, MaxFunctionCount, NumCounts,
188
+ NumFunctions);
257
189
}
0 commit comments