@@ -537,8 +537,7 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
537
537
538
538
heatmap:
539
539
// Sort parsed traces for faster processing.
540
- if (!opts::BasicAggregation)
541
- llvm::sort (Traces, llvm::less_first ());
540
+ llvm::sort (Traces, llvm::less_first ());
542
541
543
542
if (!opts::HeatmapMode)
544
543
return Error::success ();
@@ -883,13 +882,9 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace,
883
882
884
883
// Adjust FromBB if the first LBR is a return from the last instruction in
885
884
// the previous block (that instruction should be a call).
886
- if (IsReturn) {
887
- if (From)
888
- FromBB = BF.getBasicBlockContainingOffset (From - 1 );
889
- else
890
- LLVM_DEBUG (dbgs () << " return to the function start: " << Trace << ' \n ' );
891
- } else if (Trace.Branch == Trace::EXTERNAL && From == FromBB->getOffset () &&
892
- !FromBB->isEntryPoint () && !FromBB->isLandingPad ()) {
885
+ if (Trace.Branch != Trace::FT_ONLY && !BF.containsAddress (Trace.Branch ) &&
886
+ From == FromBB->getOffset () &&
887
+ (IsReturn ? From : !(FromBB->isEntryPoint () || FromBB->isLandingPad ()))) {
893
888
const BinaryBasicBlock *PrevBB =
894
889
BF.getLayout ().getBlock (FromBB->getIndex () - 1 );
895
890
if (PrevBB->getSuccessor (FromBB->getLabel ())) {
@@ -1228,12 +1223,14 @@ ErrorOr<Location> DataAggregator::parseLocationOrOffset() {
1228
1223
std::error_code DataAggregator::parseAggregatedLBREntry () {
1229
1224
enum AggregatedLBREntry : char {
1230
1225
INVALID = 0 ,
1231
- EVENT_NAME, // E
1232
- TRACE, // T
1233
- SAMPLE, // S
1234
- BRANCH, // B
1235
- FT, // F
1236
- FT_EXTERNAL_ORIGIN // f
1226
+ EVENT_NAME, // E
1227
+ TRACE, // T
1228
+ RETURN, // R
1229
+ SAMPLE, // S
1230
+ BRANCH, // B
1231
+ FT, // F
1232
+ FT_EXTERNAL_ORIGIN, // f
1233
+ FT_EXTERNAL_RETURN // r
1237
1234
} Type = INVALID;
1238
1235
1239
1236
// / The number of fields to parse, set based on \p Type.
@@ -1261,20 +1258,22 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
1261
1258
1262
1259
Type = StringSwitch<AggregatedLBREntry>(Str)
1263
1260
.Case (" T" , TRACE)
1261
+ .Case (" R" , RETURN)
1264
1262
.Case (" S" , SAMPLE)
1265
1263
.Case (" E" , EVENT_NAME)
1266
1264
.Case (" B" , BRANCH)
1267
1265
.Case (" F" , FT)
1268
1266
.Case (" f" , FT_EXTERNAL_ORIGIN)
1267
+ .Case (" r" , FT_EXTERNAL_RETURN)
1269
1268
.Default (INVALID);
1270
1269
1271
1270
if (Type == INVALID) {
1272
- reportError (" expected T, S, E, B, F or f " );
1271
+ reportError (" expected T, R, S, E, B, F, f or r " );
1273
1272
return make_error_code (llvm::errc::io_error);
1274
1273
}
1275
1274
1276
1275
using SSI = StringSwitch<int >;
1277
- AddrNum = SSI (Str).Case (" T" , 3 ).Case (" S" , 1 ).Case (" E" , 0 ).Default (2 );
1276
+ AddrNum = SSI (Str).Cases (" T" , " R " , 3 ).Case (" S" , 1 ).Case (" E" , 0 ).Default (2 );
1278
1277
CounterNum = SSI (Str).Case (" B" , 2 ).Case (" E" , 0 ).Default (1 );
1279
1278
}
1280
1279
@@ -1331,17 +1330,30 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
1331
1330
if (ToFunc)
1332
1331
ToFunc->setHasProfileAvailable ();
1333
1332
1334
- // / For legacy fall-through types, adjust locations to match Trace container.
1335
- if (Type == FT || Type == FT_EXTERNAL_ORIGIN) {
1333
+ // / For fall-through types, adjust locations to match Trace container.
1334
+ if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN ) {
1336
1335
Addr[2 ] = Location (Addr[1 ]->Offset ); // Trace To
1337
1336
Addr[1 ] = Location (Addr[0 ]->Offset ); // Trace From
1338
- // Put a magic value into Trace Branch to differentiate from a full trace.
1339
- Addr[0 ] = Location (Type == FT ? Trace::FT_ONLY : Trace::FT_EXTERNAL_ORIGIN);
1337
+ // Put a magic value into Trace Branch to differentiate from a full trace:
1338
+ if (Type == FT)
1339
+ Addr[0 ] = Location (Trace::FT_ONLY);
1340
+ else if (Type == FT_EXTERNAL_ORIGIN)
1341
+ Addr[0 ] = Location (Trace::FT_EXTERNAL_ORIGIN);
1342
+ else if (Type == FT_EXTERNAL_RETURN)
1343
+ Addr[0 ] = Location (Trace::FT_EXTERNAL_RETURN);
1344
+ else
1345
+ llvm_unreachable (" Unexpected fall-through type" );
1340
1346
}
1341
1347
1342
- // / For legacy branch type, mark Trace To to differentite from a full trace.
1343
- if (Type == BRANCH) {
1348
+ // / For branch type, mark Trace To to differentiate from a full trace.
1349
+ if (Type == BRANCH)
1344
1350
Addr[2 ] = Location (Trace::BR_ONLY);
1351
+
1352
+ if (Type == RETURN) {
1353
+ if (!Addr[0 ]->Offset )
1354
+ Addr[0 ]->Offset = Trace::FT_EXTERNAL_RETURN;
1355
+ else
1356
+ Returns.emplace (Addr[0 ]->Offset );
1345
1357
}
1346
1358
1347
1359
// / Record a trace.
@@ -1602,6 +1614,7 @@ void DataAggregator::processBranchEvents() {
1602
1614
NamedRegionTimer T (" processBranch" , " Processing branch events" ,
1603
1615
TimerGroupName, TimerGroupDesc, opts::TimeAggregator);
1604
1616
1617
+ Returns.emplace (Trace::FT_EXTERNAL_RETURN);
1605
1618
for (const auto &[Trace, Info] : Traces) {
1606
1619
bool IsReturn = checkReturn (Trace.Branch );
1607
1620
// Ignore returns.
0 commit comments