[PATCH] D148022: [LegacyPM] Call getPassName only when needed

Alexis Engelke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 08:22:23 PDT 2023


aengelke created this revision.
aengelke added reviewers: nikic, russell.gallop, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
aengelke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148022

Files:
  llvm/lib/IR/LegacyPassManager.cpp


Index: llvm/lib/IR/LegacyPassManager.cpp
===================================================================
--- llvm/lib/IR/LegacyPassManager.cpp
+++ llvm/lib/IR/LegacyPassManager.cpp
@@ -1414,7 +1414,11 @@
     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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148022.512465.patch
Type: text/x-patch
Size: 717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230411/32a81fc9/attachment.bin>


More information about the llvm-commits mailing list