Skip to content

Commit fb97b39

Browse files
committed
[JTS][NFC] Optimize guid fetching
1 parent 03cb514 commit fb97b39

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

llvm/include/llvm/Transforms/Scalar/JumpTableToSwitch.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ namespace llvm {
1515

1616
class Function;
1717

18-
struct JumpTableToSwitchPass : PassInfoMixin<JumpTableToSwitchPass> {
18+
class JumpTableToSwitchPass : public PassInfoMixin<JumpTableToSwitchPass> {
19+
// Necessary until we switch to GUIDs as metadata, after which we can drop it.
20+
const bool InLTO;
21+
22+
public:
23+
explicit JumpTableToSwitchPass(bool InLTO = false) : InLTO(InLTO) {}
1924
/// Run the pass over the function.
2025
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
2126
};

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
610610

611611
// Jump table to switch conversion.
612612
if (EnableJumpTableToSwitch)
613-
FPM.addPass(JumpTableToSwitchPass());
613+
FPM.addPass(JumpTableToSwitchPass(
614+
/*InLTO=*/Phase == ThinOrFullLTOPhase::ThinLTOPostLink ||
615+
Phase == ThinOrFullLTOPhase::FullLTOPostLink));
614616

615617
FPM.addPass(
616618
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));

llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,12 @@ PreservedAnalyses JumpTableToSwitchPass::run(Function &F,
201201
PostDominatorTree *PDT = AM.getCachedResult<PostDominatorTreeAnalysis>(F);
202202
DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy);
203203
bool Changed = false;
204-
InstrProfSymtab Symtab;
205-
if (auto E = Symtab.create(*F.getParent()))
206-
F.getContext().emitError(
207-
"Could not create indirect call table, likely corrupted IR" +
208-
toString(std::move(E)));
209-
DenseMap<const Function *, GlobalValue::GUID> FToGuid;
210-
for (const auto &[G, FPtr] : Symtab.getIDToNameMap())
211-
FToGuid.insert({FPtr, G});
204+
auto FuncToGuid = [&](const Function &Fct) {
205+
if (Fct.getMetadata(AssignGUIDPass::GUIDMetadataName))
206+
return AssignGUIDPass::getGUID(Fct);
207+
208+
return Function::getGUIDAssumingExternalLinkage(getIRPGOFuncName(F, InLTO));
209+
};
212210

213211
for (BasicBlock &BB : make_early_inc_range(F)) {
214212
BasicBlock *CurrentBB = &BB;
@@ -230,12 +228,8 @@ PreservedAnalyses JumpTableToSwitchPass::run(Function &F,
230228
std::optional<JumpTableTy> JumpTable = parseJumpTable(GEP, PtrTy);
231229
if (!JumpTable)
232230
continue;
233-
SplittedOutTail = expandToSwitch(
234-
Call, *JumpTable, DTU, ORE, [&](const Function &Fct) {
235-
if (Fct.getMetadata(AssignGUIDPass::GUIDMetadataName))
236-
return AssignGUIDPass::getGUID(Fct);
237-
return FToGuid.lookup_or(&Fct, 0U);
238-
});
231+
SplittedOutTail =
232+
expandToSwitch(Call, *JumpTable, DTU, ORE, FuncToGuid);
239233
Changed = true;
240234
break;
241235
}

0 commit comments

Comments
 (0)