@@ -183,8 +183,7 @@ updateBranches(MachineFunction &MF,
183183// clusters are ordered in increasing order of their IDs, with the "Exception"
184184// and "Cold" succeeding all other clusters.
185185// FuncClusterInfo represents the cluster information for basic blocks. It
186- // maps from BBID of basic blocks to their cluster information. If this is
187- // empty, it means unique sections for all basic blocks in the function.
186+ // maps from BBID of basic blocks to their cluster information.
188187static void
189188assignSections (MachineFunction &MF,
190189 const DenseMap<UniqueBBID, BBClusterInfo> &FuncClusterInfo) {
@@ -197,10 +196,8 @@ assignSections(MachineFunction &MF,
197196 for (auto &MBB : MF) {
198197 // With the 'all' option, every basic block is placed in a unique section.
199198 // With the 'list' option, every basic block is placed in a section
200- // associated with its cluster, unless we want individual unique sections
201- // for every basic block in this function (if FuncClusterInfo is empty).
202- if (MF.getTarget ().getBBSectionsType () == llvm::BasicBlockSection::All ||
203- FuncClusterInfo.empty ()) {
199+ // associated with its cluster.
200+ if (MF.getTarget ().getBBSectionsType () == llvm::BasicBlockSection::All) {
204201 // If unique sections are desired for all basic blocks of the function, we
205202 // set every basic block's section ID equal to its original position in
206203 // the layout (which is equal to its number). This ensures that basic
@@ -308,19 +305,21 @@ bool BasicBlockSections::handleBBSections(MachineFunction &MF) {
308305 if (BBSectionsType == BasicBlockSection::List &&
309306 hasInstrProfHashMismatch (MF))
310307 return false ;
311- // Renumber blocks before sorting them. This is useful for accessing the
312- // original layout positions and finding the original fallthroughs.
313- MF.RenumberBlocks ();
314308
315309 DenseMap<UniqueBBID, BBClusterInfo> FuncClusterInfo;
316310 if (BBSectionsType == BasicBlockSection::List) {
317311 auto ClusterInfo = getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
318312 .getClusterInfoForFunction (MF.getName ());
313+ if (ClusterInfo.empty ()) return false ;
319314 for (auto &BBClusterInfo : ClusterInfo) {
320315 FuncClusterInfo.try_emplace (BBClusterInfo.BBID , BBClusterInfo);
321316 }
322317 }
323318
319+ // Renumber blocks before sorting them. This is useful for accessing the
320+ // original layout positions and finding the original fallthroughs.
321+ MF.RenumberBlocks ();
322+
324323 MF.setBBSectionsType (BBSectionsType);
325324 assignSections (MF, FuncClusterInfo);
326325
0 commit comments