@@ -179,11 +179,6 @@ static cl::opt<bool> EmitJumpTableSizesSection(
179179 cl::desc (" Emit a section containing jump table addresses and sizes" ),
180180 cl::Hidden, cl::init(false ));
181181
182- static cl::opt<bool > InsertNoopsForPrefetch (
183- " insert-noops-for-prefetch" ,
184- cl::desc (" Whether to insert noops instead of prefetches." ), cl::init(false ),
185- cl::Hidden);
186-
187182// This isn't turned on by default, since several of the scheduling models are
188183// not completely accurate, and we don't want to be misleading.
189184static cl::opt<bool > PrintLatency (
@@ -485,7 +480,6 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
485480 AU.addRequired <MachineBranchProbabilityInfoWrapperPass>();
486481 if (EmitBBHash)
487482 AU.addRequired <MachineBlockHashInfo>();
488- AU.addUsedIfAvailable <BasicBlockSectionsProfileReaderWrapperPass>();
489483}
490484
491485bool AsmPrinter::doInitialization (Module &M) {
@@ -1988,44 +1982,29 @@ void AsmPrinter::emitFunctionBody() {
19881982
19891983 FunctionCallGraphInfo FuncCGInfo;
19901984 const auto &CallSitesInfoMap = MF->getCallSitesInfo ();
1991- DenseMap<UniqueBBID, SmallVector<unsigned >> FunctionPrefetchTargets;
1992- if (auto *BBSPRPass =
1993- getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>()) {
1994- FunctionPrefetchTargets = BBSPRPass->getBBSPR ().getPrefetchTargetsForFunction (MF->getName ());
1995- }
19961985
19971986 for (auto &MBB : *MF) {
1998-
1999- SmallVector<unsigned > BBPrefetchTargets;
2000- = FunctionPrefetchTargets.lookup (MBB.g );
2001- int NextPrefetchTargetIndex = MBB.getPrefetchTargets ().empty () ? -1 : 0 ;
20021987 // Print a label for the basic block.
20031988 emitBasicBlockStart (MBB);
20041989 DenseMap<StringRef, unsigned > MnemonicCounts;
2005- unsigned NumCallsInBlock = 0 ;
2006- for (auto &MI : MBB) {
2007- if (NextPrefetchTargetIndex != -1 &&
2008- NumCallsInBlock >= MBB.getPrefetchTargets ()[NextPrefetchTargetIndex]) {
20091990
2010- MCSymbol *PrefetchTargetSymbol = OutContext.getOrCreateSymbol (
1991+ SmallVector<unsigned > PrefetchTargets = MBB.getPrefetchTargetIndexes ();
1992+ auto PrefetchTargetIt = PrefetchTargets.begin ();
1993+ unsigned NumCalls = 0 ;
1994+ auto EmitPrefetchTargetSymbolIfNeeded = [&]() {
1995+ if (PrefetchTargetIt == PrefetchTargets.end () || NumCalls < *PrefetchTargetIt)
1996+ return ;
1997+ MCSymbol *PrefetchTargetSymbol = OutContext.getOrCreateSymbol (
20111998 Twine (" __llvm_prefetch_target_" ) + MF->getName () + Twine (" _" ) + utostr (MBB.getBBID ()->BaseID ) +
20121999 Twine (" _" ) +
2013- utostr (MBB.getPrefetchTargets ()[NextPrefetchTargetIndex]));
2014- if (MF->getFunction ().isWeakForLinker ()) {
2015- OutStreamer->emitSymbolAttribute (PrefetchTargetSymbol, MCSA_Weak);
2016- errs () << " Emitting weak symbol: " << PrefetchTargetSymbol->getName () << " \n " ;
2017- } else {
2018- OutStreamer->emitSymbolAttribute (PrefetchTargetSymbol, MCSA_Global);
2019- errs () << " Emitting global symbol: " << PrefetchTargetSymbol->getName () << " \n " ;
2020- }
2021- // OutStreamer->emitSymbolAttribute(PrefetchTargetSymbol, MCSA_Extern);
2022- // errs() << "Emitting symbol: " << PrefetchTargetSymbol->getName() << "\n";
2000+ utostr (*PrefetchTargetIt));
2001+ OutStreamer->emitSymbolAttribute (PrefetchTargetSymbol, MF->getFunction ().isWeakForLinker () ? MCSA_Weak : MCSA_Global);
20232002 OutStreamer->emitLabel (PrefetchTargetSymbol);
2024- ++NextPrefetchTargetIndex ;
2025- if (NextPrefetchTargetIndex >=
2026- static_cast < int >(MBB. getPrefetchTargets (). size ()))
2027- NextPrefetchTargetIndex = - 1 ;
2028- }
2003+ ++PrefetchTargetIt ;
2004+ };
2005+
2006+ for ( auto &MI : MBB) {
2007+ EmitPrefetchTargetSymbolIfNeeded ();
20292008 // Print the assembly for the instruction.
20302009 if (!MI.isPosition () && !MI.isImplicitDef () && !MI.isKill () &&
20312010 !MI.isDebugInstr ()) {
@@ -2163,8 +2142,11 @@ void AsmPrinter::emitFunctionBody() {
21632142 break ;
21642143 }
21652144
2166- if (MI.isCall () && MF->getTarget ().Options .BBAddrMap )
2145+ if (MI.isCall ()) {
2146+ if (MF->getTarget ().Options .BBAddrMap )
21672147 OutStreamer->emitLabel (createCallsiteEndSymbol (MBB));
2148+ ++NumCalls;
2149+ }
21682150
21692151 if (TM.Options .EmitCallGraphSection && MI.isCall ())
21702152 handleCallsiteForCallgraph (FuncCGInfo, CallSitesInfoMap, MI);
@@ -2176,24 +2158,7 @@ void AsmPrinter::emitFunctionBody() {
21762158 for (auto &Handler : Handlers)
21772159 Handler->endInstruction ();
21782160 }
2179- while (NextPrefetchTargetIndex != -1 ) {
2180- MCSymbol *PrefetchTargetSymbol = OutContext.getOrCreateSymbol (
2181- Twine (" __llvm_prefetch_target_" ) + MF->getName () + Twine (" _" ) + utostr (MBB.getBBID ()->BaseID ) +
2182- Twine (" _" ) +
2183- utostr (MBB.getPrefetchTargets ()[NextPrefetchTargetIndex]));
2184- if (MF->getFunction ().hasWeakLinkage ()) {
2185- OutStreamer->emitSymbolAttribute (PrefetchTargetSymbol, MCSA_WeakDefinition);
2186- } else {
2187- OutStreamer->emitSymbolAttribute (PrefetchTargetSymbol, MCSA_Global);
2188- }
2189- OutStreamer->emitSymbolAttribute (PrefetchTargetSymbol, MCSA_Extern);
2190- OutStreamer->emitLabel (PrefetchTargetSymbol);
2191- ++NextPrefetchTargetIndex;
2192- if (NextPrefetchTargetIndex >=
2193- static_cast <int >(MBB.getPrefetchTargets ().size ()))
2194- NextPrefetchTargetIndex = -1 ;
2195- }
2196-
2161+ EmitPrefetchTargetSymbolIfNeeded ();
21972162
21982163 // We must emit temporary symbol for the end of this basic block, if either
21992164 // we have BBLabels enabled or if this basic blocks marks the end of a
0 commit comments