Skip to content

Commit

Permalink
[LegacyPM] Reduce number of calls to getName
Browse files Browse the repository at this point in the history
Repeatedly calling getName adds some overhead, which can be easily
avoided by querying the name just once per function. The improvements
are rather small (~0.5% back-end time in a compile-time optimized
setting), but also very easy to achieve.

Note that getting the name should be entirely avoidable in the common
case, but would require more substantial changes.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D148145
  • Loading branch information
aengelke committed Apr 13, 2023
1 parent 053bdb7 commit a2e596b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions llvm/lib/IR/LegacyPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,9 @@ bool FPPassManager::runOnFunction(Function &F) {
FunctionSize = F.getInstructionCount();
}

llvm::TimeTraceScope FunctionScope("OptFunction", F.getName());
// Store name outside of loop to avoid redundant calls.
const StringRef Name = F.getName();
llvm::TimeTraceScope FunctionScope("OptFunction", Name);

for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
FunctionPass *FP = getContainedPass(Index);
Expand All @@ -1419,7 +1421,7 @@ bool FPPassManager::runOnFunction(Function &F) {
llvm::TimeTraceScope PassScope(
"RunPass", [FP]() { return std::string(FP->getPassName()); });

dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, Name);
dumpRequiredSet(FP);

initializeAnalysisImpl(FP);
Expand Down Expand Up @@ -1458,15 +1460,15 @@ bool FPPassManager::runOnFunction(Function &F) {

Changed |= LocalChanged;
if (LocalChanged)
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, Name);
dumpPreservedSet(FP);
dumpUsedSet(FP);

verifyPreservedAnalysis(FP);
if (LocalChanged)
removeNotPreservedAnalysis(FP);
recordAvailableAnalysis(FP);
removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
removeDeadPasses(FP, Name, ON_FUNCTION_MSG);
}

return Changed;
Expand Down

0 comments on commit a2e596b

Please sign in to comment.