File tree Expand file tree Collapse file tree 5 files changed +23
-16
lines changed Expand file tree Collapse file tree 5 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,12 @@ struct BBClusterInfo {
4242 unsigned PositionInCluster;
4343};
4444
45- // The prefetch symbol is emitted immediately after the call of the given index
46- // in block `BBID` (or at the beginning of the block if CallsiteIndex is -1).
45+ // The prefetch symbol is emitted immediately after the call of the given index,
46+ // in block `BBID` (First call has an index of 1). Zero callsite index means the
47+ // start of the block.
4748struct CallsiteID {
4849 UniqueBBID BBID;
49- int CallsiteIndex;
50+ unsigned CallsiteIndex;
5051};
5152
5253// This represents the raw input profile for one function.
Original file line number Diff line number Diff line change @@ -230,9 +230,10 @@ class MachineBasicBlock
230230 mutable MCSymbol *CachedMCSymbol = nullptr ;
231231
232232 // / Contains the callsite indices in this block that are targets of code
233- // / prefetching. The index `i` specifies the `i`th call, with `-1`
234- // / representing the beginning of the block.
235- SmallVector<int > PrefetchTargetCallsiteIndexes;
233+ // / prefetching. The index `i` specifies the `i`th call, with zero
234+ // / representing the beginning of the block and ` representing the first call.
235+ // / Must be in ascending order and without duplicates.
236+ SmallVector<unsigned > PrefetchTargetCallsiteIndexes;
236237
237238 // / Cached MCSymbol for this block (used if IsEHContTarget).
238239 mutable MCSymbol *CachedEHContMCSymbol = nullptr ;
@@ -715,11 +716,11 @@ class MachineBasicBlock
715716
716717 std::optional<UniqueBBID> getBBID () const { return BBID; }
717718
718- const SmallVector<int > &getPrefetchTargetCallsiteIndexes () const {
719+ const SmallVector<unsigned > &getPrefetchTargetCallsiteIndexes () const {
719720 return PrefetchTargetCallsiteIndexes;
720721 }
721722
722- void setPrefetchTargetCallsiteIndexes (const SmallVector<int > &V) {
723+ void setPrefetchTargetCallsiteIndexes (const SmallVector<unsigned > &V) {
723724 PrefetchTargetCallsiteIndexes = V;
724725 }
725726
Original file line number Diff line number Diff line change @@ -1986,14 +1986,14 @@ void AsmPrinter::emitFunctionBody() {
19861986 emitBasicBlockStart (MBB);
19871987 DenseMap<StringRef, unsigned > MnemonicCounts;
19881988
1989- SmallVector<int > PrefetchTargets = MBB.getPrefetchTargetCallsiteIndexes ();
1989+ SmallVector<unsigned > PrefetchTargets = MBB.getPrefetchTargetCallsiteIndexes ();
19901990 auto PrefetchTargetIt = PrefetchTargets.begin ();
1991- int CurrentCallsiteIndex = - 1 ;
1991+ unsigned LastCallsiteIndex = 0 ;
19921992 // Helper to emit a symbol for the prefetch target and proceed to the next
19931993 // one.
19941994 auto EmitPrefetchTargetSymbolIfNeeded = [&]() {
19951995 if (PrefetchTargetIt != PrefetchTargets.end () &&
1996- *PrefetchTargetIt == CurrentCallsiteIndex ) {
1996+ *PrefetchTargetIt == LastCallsiteIndex ) {
19971997 MCSymbol *PrefetchTargetSymbol = OutContext.getOrCreateSymbol (
19981998 Twine (" __llvm_prefetch_target_" ) + MF->getName () + Twine (" _" ) +
19991999 utostr (MBB.getBBID ()->BaseID ) + Twine (" _" ) +
@@ -2151,7 +2151,7 @@ void AsmPrinter::emitFunctionBody() {
21512151 if (MI.isCall ()) {
21522152 if (MF->getTarget ().Options .BBAddrMap )
21532153 OutStreamer->emitLabel (createCallsiteEndSymbol (MBB));
2154- CurrentCallsiteIndex ++;
2154+ LastCallsiteIndex ++;
21552155 }
21562156
21572157 if (TM.Options .EmitCallGraphSection && MI.isCall ())
Original file line number Diff line number Diff line change @@ -358,12 +358,12 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
358358 auto TargetBBID = parseUniqueBBID (PrefetchTargetStr[0 ]);
359359 if (!TargetBBID)
360360 return TargetBBID.takeError ();
361- long long CallsiteIndex;
362- if (getAsSignedInteger (PrefetchTargetStr[1 ], 10 , CallsiteIndex))
361+ unsigned long long CallsiteIndex;
362+ if (getAsUnsignedInteger (PrefetchTargetStr[1 ], 10 , CallsiteIndex))
363363 return createProfileParseError (Twine (" signed integer expected: '" ) +
364364 PrefetchTargetStr[1 ]);
365365 FI->second .PrefetchTargets .push_back (
366- CallsiteID{*TargetBBID, static_cast <int >(CallsiteIndex - 1 )});
366+ CallsiteID{*TargetBBID, static_cast <unsigned >(CallsiteIndex)});
367367 continue ;
368368 }
369369 default :
Original file line number Diff line number Diff line change @@ -73,9 +73,14 @@ bool InsertCodePrefetch::runOnMachineFunction(MachineFunction &MF) {
7373 SmallVector<CallsiteID> PrefetchTargets =
7474 getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
7575 .getPrefetchTargetsForFunction (MF.getName ());
76- DenseMap<UniqueBBID, SmallVector<int >> PrefetchTargetsByBBID;
76+ DenseMap<UniqueBBID, SmallVector<unsigned >> PrefetchTargetsByBBID;
7777 for (const auto &Target : PrefetchTargets)
7878 PrefetchTargetsByBBID[Target.BBID ].push_back (Target.CallsiteIndex );
79+ // Sort and uniquify the callsite indices for every block.
80+ for (auto &[K, V]: PrefetchTargetsByBBID) {
81+ llvm::sort (V);
82+ V.erase (llvm::unique (V), V.end ());
83+ }
7984 for (auto &MBB : MF) {
8085 auto R = PrefetchTargetsByBBID.find (*MBB.getBBID ());
8186 if (R == PrefetchTargetsByBBID.end ())
You can’t perform that action at this time.
0 commit comments