-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[JTS][NFC] Optimize guid fetching #161612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mtrofin
merged 1 commit into
main
from
users/mtrofin/10-01-_jts_nfc_optimize_guid_fetching
Oct 2, 2025
Merged
[JTS][NFC] Optimize guid fetching #161612
mtrofin
merged 1 commit into
main
from
users/mtrofin/10-01-_jts_nfc_optimize_guid_fetching
Oct 2, 2025
+17
−16
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-transforms Author: Mircea Trofin (mtrofin) ChangesIt's unnecessary to build the whole symtable, and on top of everything, un-optimal to do so for every function. All we really need is the instrumented PGO name - considering also LTO-ness - and then we can compute the function name. Full diff: https://github.com/llvm/llvm-project/pull/161612.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpTableToSwitch.h b/llvm/include/llvm/Transforms/Scalar/JumpTableToSwitch.h
index 61786227d7a33..71bf2c643d813 100644
--- a/llvm/include/llvm/Transforms/Scalar/JumpTableToSwitch.h
+++ b/llvm/include/llvm/Transforms/Scalar/JumpTableToSwitch.h
@@ -15,7 +15,12 @@ namespace llvm {
class Function;
-struct JumpTableToSwitchPass : PassInfoMixin<JumpTableToSwitchPass> {
+class JumpTableToSwitchPass : public PassInfoMixin<JumpTableToSwitchPass> {
+ // Necessary until we switch to GUIDs as metadata, after which we can drop it.
+ const bool InLTO;
+
+public:
+ JumpTableToSwitchPass(bool InLTO = false) : InLTO(InLTO) {}
/// Run the pass over the function.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 256cf9d4cd1ce..0b93dda4087e3 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -610,7 +610,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
// Jump table to switch conversion.
if (EnableJumpTableToSwitch)
- FPM.addPass(JumpTableToSwitchPass());
+ FPM.addPass(JumpTableToSwitchPass(
+ /*InLTO=*/Phase == ThinOrFullLTOPhase::ThinLTOPostLink ||
+ Phase == ThinOrFullLTOPhase::FullLTOPostLink));
FPM.addPass(
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
diff --git a/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp b/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
index 2025fbbf05973..5afdef9e95fae 100644
--- a/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
@@ -201,14 +201,12 @@ PreservedAnalyses JumpTableToSwitchPass::run(Function &F,
PostDominatorTree *PDT = AM.getCachedResult<PostDominatorTreeAnalysis>(F);
DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy);
bool Changed = false;
- InstrProfSymtab Symtab;
- if (auto E = Symtab.create(*F.getParent()))
- F.getContext().emitError(
- "Could not create indirect call table, likely corrupted IR" +
- toString(std::move(E)));
- DenseMap<const Function *, GlobalValue::GUID> FToGuid;
- for (const auto &[G, FPtr] : Symtab.getIDToNameMap())
- FToGuid.insert({FPtr, G});
+ auto FuncToGuid = [&](const Function &Fct) {
+ if (Fct.getMetadata(AssignGUIDPass::GUIDMetadataName))
+ return AssignGUIDPass::getGUID(Fct);
+
+ return Function::getGUIDAssumingExternalLinkage(getIRPGOFuncName(F, InLTO));
+ };
for (BasicBlock &BB : make_early_inc_range(F)) {
BasicBlock *CurrentBB = &BB;
@@ -230,12 +228,8 @@ PreservedAnalyses JumpTableToSwitchPass::run(Function &F,
std::optional<JumpTableTy> JumpTable = parseJumpTable(GEP, PtrTy);
if (!JumpTable)
continue;
- SplittedOutTail = expandToSwitch(
- Call, *JumpTable, DTU, ORE, [&](const Function &Fct) {
- if (Fct.getMetadata(AssignGUIDPass::GUIDMetadataName))
- return AssignGUIDPass::getGUID(Fct);
- return FToGuid.lookup_or(&Fct, 0U);
- });
+ SplittedOutTail =
+ expandToSwitch(Call, *JumpTable, DTU, ORE, FuncToGuid);
Changed = true;
break;
}
|
alexander-shaposhnikov
approved these changes
Oct 2, 2025
079c9c0
to
fb97b39
Compare
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Oct 3, 2025
It's unnecessary to build the whole symtable, and on top of everything, un-optimal to do so for every function. All we really need is the instrumented PGO name - considering also LTO-ness - and then we can compute the function name.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's unnecessary to build the whole symtable, and on top of everything, un-optimal to do so for every function. All we really need is the instrumented PGO name - considering also LTO-ness - and then we can compute the function name.