@@ -215,7 +215,8 @@ static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth,
215
215
uint64_t &NumSamples, uint32_t &LineOffset,
216
216
uint32_t &Discriminator, StringRef &CalleeName,
217
217
DenseMap<StringRef, uint64_t > &TargetCountMap,
218
- uint64_t &FunctionHash, uint32_t &Attributes) {
218
+ uint64_t &FunctionHash, uint32_t &Attributes,
219
+ bool &IsFlat) {
219
220
for (Depth = 0 ; Input[Depth] == ' ' ; Depth++)
220
221
;
221
222
if (Depth == 0 )
@@ -226,8 +227,10 @@ static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth,
226
227
// This metadata is only for manual inspection only. We already created a
227
228
// FunctionSamples and put it in the profile map, so there is no point
228
229
// to skip profiles even they have no use for ThinLTO.
229
- if (Input == StringRef (" !Flat" ))
230
+ if (Input == StringRef (" !Flat" )) {
231
+ IsFlat = true ;
230
232
return true ;
233
+ }
231
234
return parseMetadata (Input.substr (Depth), FunctionHash, Attributes);
232
235
}
233
236
@@ -330,6 +333,8 @@ std::error_code SampleProfileReaderText::readImpl() {
330
333
// top-level or nested function profile.
331
334
uint32_t DepthMetadata = 0 ;
332
335
336
+ std::vector<SampleContext *> FlatSamples;
337
+
333
338
ProfileIsFS = ProfileIsFSDisciminator;
334
339
FunctionSamples::ProfileIsFS = ProfileIsFS;
335
340
for (; !LineIt.is_at_eof (); ++LineIt) {
@@ -373,9 +378,10 @@ std::error_code SampleProfileReaderText::readImpl() {
373
378
LineType LineTy;
374
379
uint64_t FunctionHash = 0 ;
375
380
uint32_t Attributes = 0 ;
381
+ bool IsFlat = false ;
376
382
if (!ParseLine (*LineIt, LineTy, Depth, NumSamples, LineOffset,
377
383
Discriminator, FName, TargetCountMap, FunctionHash,
378
- Attributes)) {
384
+ Attributes, IsFlat )) {
379
385
reportError (LineIt.line_number (),
380
386
" Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found " +
381
387
*LineIt);
@@ -431,12 +437,26 @@ std::error_code SampleProfileReaderText::readImpl() {
431
437
if (Attributes & (uint32_t )ContextShouldBeInlined)
432
438
ProfileIsPreInlined = true ;
433
439
DepthMetadata = Depth;
440
+ if (IsFlat) {
441
+ if (Depth == 1 )
442
+ FlatSamples.push_back (&FProfile.getContext ());
443
+ else
444
+ Ctx.diagnose (DiagnosticInfoSampleProfile (
445
+ Buffer->getBufferIdentifier (), LineIt.line_number (),
446
+ " !Flat may only be used at top level function." , DS_Warning));
447
+ }
434
448
break ;
435
449
}
436
450
}
437
451
}
438
452
}
439
453
454
+ // Honor the option to skip flat functions. Since they are already added to
455
+ // the profile map, remove them all here.
456
+ if (SkipFlatProf)
457
+ for (SampleContext *FlatSample : FlatSamples)
458
+ Profiles.erase (*FlatSample);
459
+
440
460
assert ((CSProfileCount == 0 || CSProfileCount == Profiles.size ()) &&
441
461
" Cannot have both context-sensitive and regular profile" );
442
462
ProfileIsCS = (CSProfileCount > 0 );
0 commit comments