Skip to content

Commit f2d7130

Browse files
authored
[BOLT][NFC] Simplify DataAggregator::getFallthroughsInTrace (#90752)
1 parent fc382db commit f2d7130

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ class DataAggregator : public DataReader {
198198
/// A trace is region of code executed between two LBR entries supplied in
199199
/// execution order.
200200
///
201-
/// Return true if the trace is valid, false otherwise.
202-
bool
203-
recordTrace(BinaryFunction &BF, const LBREntry &First, const LBREntry &Second,
204-
uint64_t Count,
205-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const;
206-
207201
/// Return a vector of offsets corresponding to a trace in a function
208-
/// (see recordTrace() above).
202+
/// if the trace is valid, std::nullopt otherwise.
209203
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
210204
getFallthroughsInTrace(BinaryFunction &BF, const LBREntry &First,
211205
const LBREntry &Second, uint64_t Count = 1) const;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,17 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
861861
return true;
862862
}
863863

864-
bool DataAggregator::recordTrace(
865-
BinaryFunction &BF, const LBREntry &FirstLBR, const LBREntry &SecondLBR,
866-
uint64_t Count,
867-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const {
864+
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
865+
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
866+
const LBREntry &FirstLBR,
867+
const LBREntry &SecondLBR,
868+
uint64_t Count) const {
869+
SmallVector<std::pair<uint64_t, uint64_t>, 16> Branches;
870+
868871
BinaryContext &BC = BF.getBinaryContext();
869872

870873
if (!BF.isSimple())
871-
return false;
874+
return std::nullopt;
872875

873876
assert(BF.hasCFG() && "can only record traces in CFG state");
874877

@@ -877,13 +880,13 @@ bool DataAggregator::recordTrace(
877880
const uint64_t To = SecondLBR.From - BF.getAddress();
878881

879882
if (From > To)
880-
return false;
883+
return std::nullopt;
881884

882885
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
883886
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
884887

885888
if (!FromBB || !ToBB)
886-
return false;
889+
return std::nullopt;
887890

888891
// Adjust FromBB if the first LBR is a return from the last instruction in
889892
// the previous block (that instruction should be a call).
@@ -907,7 +910,7 @@ bool DataAggregator::recordTrace(
907910
// within the same basic block, e.g. when two call instructions are in the
908911
// same block. In this case we skip the processing.
909912
if (FromBB == ToBB)
910-
return true;
913+
return Branches;
911914

912915
// Process blocks in the original layout order.
913916
BinaryBasicBlock *BB = BF.getLayout().getBlock(FromBB->getIndex());
@@ -921,7 +924,7 @@ bool DataAggregator::recordTrace(
921924
LLVM_DEBUG(dbgs() << "no fall-through for the trace:\n"
922925
<< " " << FirstLBR << '\n'
923926
<< " " << SecondLBR << '\n');
924-
return false;
927+
return std::nullopt;
925928
}
926929

927930
const MCInst *Instr = BB->getLastNonPseudoInstr();
@@ -945,20 +948,7 @@ bool DataAggregator::recordTrace(
945948
BI.Count += Count;
946949
}
947950

948-
return true;
949-
}
950-
951-
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
952-
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
953-
const LBREntry &FirstLBR,
954-
const LBREntry &SecondLBR,
955-
uint64_t Count) const {
956-
SmallVector<std::pair<uint64_t, uint64_t>, 16> Res;
957-
958-
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, Res))
959-
return std::nullopt;
960-
961-
return Res;
951+
return Branches;
962952
}
963953

964954
bool DataAggregator::recordEntry(BinaryFunction &BF, uint64_t To, bool Mispred,

0 commit comments

Comments
 (0)