[llvm] [BOLT][NFC] Simplify getOrCreate/analyze/populate/emitJumpTable (PR #132108)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 10 12:53:10 PDT 2025
================
@@ -809,52 +809,50 @@ void BinaryEmitter::emitJumpTable(const JumpTable &JT, MCSection *HotSection,
Streamer.switchSection(JT.Count > 0 ? HotSection : ColdSection);
Streamer.emitValueToAlignment(Align(JT.EntrySize));
}
- MCSymbol *LastLabel = nullptr;
+ MCSymbol *JTLabel = nullptr;
uint64_t Offset = 0;
for (MCSymbol *Entry : JT.Entries) {
auto LI = JT.Labels.find(Offset);
- if (LI != JT.Labels.end()) {
- LLVM_DEBUG({
- dbgs() << "BOLT-DEBUG: emitting jump table " << LI->second->getName()
- << " (originally was at address 0x"
- << Twine::utohexstr(JT.getAddress() + Offset)
- << (Offset ? ") as part of larger jump table\n" : ")\n");
- });
- if (!LabelCounts.empty()) {
- LLVM_DEBUG(dbgs() << "BOLT-DEBUG: jump table count: "
- << LabelCounts[LI->second] << '\n');
- if (LabelCounts[LI->second] > 0)
- Streamer.switchSection(HotSection);
- else
- Streamer.switchSection(ColdSection);
- Streamer.emitValueToAlignment(Align(JT.EntrySize));
- }
- // Emit all labels registered at the address of this jump table
- // to sync with our global symbol table. We may have two labels
- // registered at this address if one label was created via
- // getOrCreateGlobalSymbol() (e.g. LEA instructions referencing
- // this location) and another via getOrCreateJumpTable(). This
- // creates a race where the symbols created by these two
- // functions may or may not be the same, but they are both
- // registered in our symbol table at the same address. By
- // emitting them all here we make sure there is no ambiguity
- // that depends on the order that these symbols were created, so
- // whenever this address is referenced in the binary, it is
- // certain to point to the jump table identified at this
- // address.
- if (BinaryData *BD = BC.getBinaryDataByName(LI->second->getName())) {
- for (MCSymbol *S : BD->getSymbols())
- Streamer.emitLabel(S);
- } else {
- Streamer.emitLabel(LI->second);
- }
- LastLabel = LI->second;
+ if (LI == JT.Labels.end())
+ goto emitEntry;
+ JTLabel = LI->second;
+ LLVM_DEBUG({
+ dbgs() << "BOLT-DEBUG: emitting jump table " << JTLabel->getName()
+ << " (originally was at address 0x"
+ << Twine::utohexstr(JT.getAddress() + Offset)
+ << (Offset ? ") as part of larger jump table\n" : ")\n");
+ });
+ if (!LabelCounts.empty()) {
+ uint64_t JTCount = LabelCounts[JTLabel];
----------------
maksfb wrote:
nit:
```suggestion
const uint64_t JTCount = LabelCounts[JTLabel];
```
https://github.com/llvm/llvm-project/pull/132108
More information about the llvm-commits
mailing list