@@ -861,14 +861,17 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
861
861
return true ;
862
862
}
863
863
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
+
868
871
BinaryContext &BC = BF.getBinaryContext ();
869
872
870
873
if (!BF.isSimple ())
871
- return false ;
874
+ return std::nullopt ;
872
875
873
876
assert (BF.hasCFG () && " can only record traces in CFG state" );
874
877
@@ -877,13 +880,13 @@ bool DataAggregator::recordTrace(
877
880
const uint64_t To = SecondLBR.From - BF.getAddress ();
878
881
879
882
if (From > To)
880
- return false ;
883
+ return std::nullopt ;
881
884
882
885
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset (From);
883
886
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset (To);
884
887
885
888
if (!FromBB || !ToBB)
886
- return false ;
889
+ return std::nullopt ;
887
890
888
891
// Adjust FromBB if the first LBR is a return from the last instruction in
889
892
// the previous block (that instruction should be a call).
@@ -907,7 +910,7 @@ bool DataAggregator::recordTrace(
907
910
// within the same basic block, e.g. when two call instructions are in the
908
911
// same block. In this case we skip the processing.
909
912
if (FromBB == ToBB)
910
- return true ;
913
+ return Branches ;
911
914
912
915
// Process blocks in the original layout order.
913
916
BinaryBasicBlock *BB = BF.getLayout ().getBlock (FromBB->getIndex ());
@@ -921,7 +924,7 @@ bool DataAggregator::recordTrace(
921
924
LLVM_DEBUG (dbgs () << " no fall-through for the trace:\n "
922
925
<< " " << FirstLBR << ' \n '
923
926
<< " " << SecondLBR << ' \n ' );
924
- return false ;
927
+ return std::nullopt ;
925
928
}
926
929
927
930
const MCInst *Instr = BB->getLastNonPseudoInstr ();
@@ -945,20 +948,7 @@ bool DataAggregator::recordTrace(
945
948
BI.Count += Count;
946
949
}
947
950
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;
962
952
}
963
953
964
954
bool DataAggregator::recordEntry (BinaryFunction &BF, uint64_t To, bool Mispred,
0 commit comments