Skip to content

Commit

Permalink
[LegacyPM] Call getPassName only when needed
Browse files Browse the repository at this point in the history
Even when time tracing is disabled, getPassName is currently still
called. This adds an avoidable virtual function call for each pass.
Fetching the pass name only when required slightly improves
compile-time (particularly when LLVM is built without LTO).

Reviewed By: nikic, MaskRay

Differential Revision: https://reviews.llvm.org/D148022
  • Loading branch information
aengelke committed Apr 12, 2023
1 parent 6f42b97 commit 63a8ca3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/IR/LegacyPassManager.cpp
Expand Up @@ -1414,7 +1414,10 @@ bool FPPassManager::runOnFunction(Function &F) {
FunctionPass *FP = getContainedPass(Index);
bool LocalChanged = false;

llvm::TimeTraceScope PassScope("RunPass", FP->getPassName());
// Call getPassName only when required. The call itself is fairly cheap, but
// still virtual and repeated calling adds unnecessary overhead.
llvm::TimeTraceScope PassScope(
"RunPass", [FP]() { return std::string(FP->getPassName()); });

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

0 comments on commit 63a8ca3

Please sign in to comment.