Skip to content

Commit 6cf97d0

Browse files
committed
Make specifying the function in bbsection profile a noop, when no other directives are specified.
1 parent 540250c commit 6cf97d0

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,13 @@ class BasicBlockSectionsProfileReader {
6868

6969
BasicBlockSectionsProfileReader() = default;
7070

71-
// Returns true if basic block sections profile exist for function \p
72-
// FuncName.
71+
// Returns true if function \p FuncName is hot based on the basic block
72+
// section profile.
7373
bool isFunctionHot(StringRef FuncName) const;
7474

75-
// Returns a pair with first element representing whether basic block sections
76-
// profile exist for the function \p FuncName, and the second element
77-
// representing the basic block sections profile (cluster info) for this
78-
// function. If the first element is true and the second element is empty, it
79-
// means unique basic block sections are desired for all basic blocks of the
80-
// function.
81-
std::pair<bool, SmallVector<BBClusterInfo>>
75+
// Returns the cluster info for the function \p FuncName. Returns an empty
76+
// vector if function has no cluster info.
77+
SmallVector<BBClusterInfo>
8278
getClusterInfoForFunction(StringRef FuncName) const;
8379

8480
// Returns the path clonings for the given function.
@@ -190,7 +186,7 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
190186

191187
bool isFunctionHot(StringRef FuncName) const;
192188

193-
std::pair<bool, SmallVector<BBClusterInfo>>
189+
SmallVector<BBClusterInfo>
194190
getClusterInfoForFunction(StringRef FuncName) const;
195191

196192
SmallVector<SmallVector<unsigned>>

llvm/lib/CodeGen/BasicBlockSections.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,9 @@ bool BasicBlockSections::handleBBSections(MachineFunction &MF) {
314314

315315
DenseMap<UniqueBBID, BBClusterInfo> FuncClusterInfo;
316316
if (BBSectionsType == BasicBlockSection::List) {
317-
auto [HasProfile, ClusterInfo] =
317+
auto ClusterInfo =
318318
getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
319319
.getClusterInfoForFunction(MF.getName());
320-
if (!HasProfile)
321-
return false;
322320
for (auto &BBClusterInfo : ClusterInfo) {
323321
FuncClusterInfo.try_emplace(BBClusterInfo.BBID, BBClusterInfo);
324322
}

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,21 @@ BasicBlockSectionsProfileReader::parseUniqueBBID(StringRef S) const {
5858
}
5959

6060
bool BasicBlockSectionsProfileReader::isFunctionHot(StringRef FuncName) const {
61-
return getClusterInfoForFunction(FuncName).first;
61+
return !getClusterInfoForFunction(FuncName).empty();
6262
}
6363

64-
std::pair<bool, SmallVector<BBClusterInfo>>
64+
SmallVector<BBClusterInfo>
6565
BasicBlockSectionsProfileReader::getClusterInfoForFunction(
6666
StringRef FuncName) const {
6767
auto R = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
68-
return R != ProgramPathAndClusterInfo.end()
69-
? std::pair(true, R->second.ClusterInfo)
70-
: std::pair(false, SmallVector<BBClusterInfo>());
68+
return R != ProgramPathAndClusterInfo.end() ? R->second.ClusterInfo : SmallVector<BBClusterInfo>();
7169
}
7270

7371
SmallVector<SmallVector<unsigned>>
7472
BasicBlockSectionsProfileReader::getClonePathsForFunction(
7573
StringRef FuncName) const {
76-
return ProgramPathAndClusterInfo.lookup(getAliasName(FuncName)).ClonePaths;
74+
auto R = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
75+
return R != ProgramPathAndClusterInfo.end() ? R->second.ClonePaths : SmallVector<SmallVector<unsigned>>();
7776
}
7877

7978
uint64_t BasicBlockSectionsProfileReader::getEdgeCount(
@@ -494,7 +493,7 @@ bool BasicBlockSectionsProfileReaderWrapperPass::isFunctionHot(
494493
return BBSPR.isFunctionHot(FuncName);
495494
}
496495

497-
std::pair<bool, SmallVector<BBClusterInfo>>
496+
SmallVector<BBClusterInfo>
498497
BasicBlockSectionsProfileReaderWrapperPass::getClusterInfoForFunction(
499498
StringRef FuncName) const {
500499
return BBSPR.getClusterInfoForFunction(FuncName);

0 commit comments

Comments
 (0)