Skip to content

Commit 0b181de

Browse files
[ExecutionEngine] Avoid repeated hash lookups (NFC) (llvm#132587)
1 parent 0a08d71 commit 0b181de

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,15 +1515,15 @@ void RuntimeDyldELF::resolveAArch64Branch(unsigned SectionID,
15151515
uint64_t Offset = RelI->getOffset();
15161516
unsigned RelType = RelI->getType();
15171517
// Look for an existing stub.
1518-
StubMap::const_iterator i = Stubs.find(Value);
1519-
if (i != Stubs.end()) {
1518+
auto [It, Inserted] = Stubs.try_emplace(Value);
1519+
if (!Inserted) {
15201520
resolveRelocation(Section, Offset,
1521-
Section.getLoadAddressWithOffset(i->second), RelType, 0);
1521+
Section.getLoadAddressWithOffset(It->second), RelType, 0);
15221522
LLVM_DEBUG(dbgs() << " Stub function found\n");
15231523
} else if (!resolveAArch64ShortBranch(SectionID, RelI, Value)) {
15241524
// Create a new stub function.
15251525
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
1526-
Stubs[Value] = Section.getStubOffset();
1526+
It->second = Section.getStubOffset();
15271527
uint8_t *StubTargetAddr = createStubFunction(
15281528
Section.getAddressWithOffset(Section.getStubOffset()));
15291529

@@ -1837,15 +1837,15 @@ RuntimeDyldELF::processRelocationRef(
18371837
SectionEntry &Section = Sections[SectionID];
18381838

18391839
// Look up for existing stub.
1840-
StubMap::const_iterator i = Stubs.find(Value);
1841-
if (i != Stubs.end()) {
1842-
RelocationEntry RE(SectionID, Offset, RelType, i->second);
1840+
auto [It, Inserted] = Stubs.try_emplace(Value);
1841+
if (!Inserted) {
1842+
RelocationEntry RE(SectionID, Offset, RelType, It->second);
18431843
addRelocationForSection(RE, SectionID);
18441844
LLVM_DEBUG(dbgs() << " Stub function found\n");
18451845
} else {
18461846
// Create a new stub function.
18471847
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
1848-
Stubs[Value] = Section.getStubOffset();
1848+
It->second = Section.getStubOffset();
18491849

18501850
unsigned AbiVariant = Obj.getPlatformFlags();
18511851

@@ -2075,10 +2075,10 @@ RuntimeDyldELF::processRelocationRef(
20752075
SectionEntry &Section = Sections[SectionID];
20762076

20772077
// Look for an existing stub.
2078-
StubMap::const_iterator i = Stubs.find(Value);
2078+
auto [It, Inserted] = Stubs.try_emplace(Value);
20792079
uintptr_t StubAddress;
2080-
if (i != Stubs.end()) {
2081-
StubAddress = uintptr_t(Section.getAddressWithOffset(i->second));
2080+
if (!Inserted) {
2081+
StubAddress = uintptr_t(Section.getAddressWithOffset(It->second));
20822082
LLVM_DEBUG(dbgs() << " Stub function found\n");
20832083
} else {
20842084
// Create a new stub function.
@@ -2089,7 +2089,7 @@ RuntimeDyldELF::processRelocationRef(
20892089
alignTo(BaseAddress + Section.getStubOffset(), getStubAlignment());
20902090
unsigned StubOffset = StubAddress - BaseAddress;
20912091

2092-
Stubs[Value] = StubOffset;
2092+
It->second = StubOffset;
20932093
createStubFunction((uint8_t *)StubAddress);
20942094
RelocationEntry RE(SectionID, StubOffset + 8, ELF::R_390_64,
20952095
Value.Offset);

llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ class RuntimeDyldMachOARM
307307
// This is an ARM branch relocation, need to use a stub function.
308308
// Look up for existing stub.
309309
SectionEntry &Section = Sections[RE.SectionID];
310-
RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(Value);
310+
auto [It, Inserted] = Stubs.try_emplace(Value);
311311
uint8_t *Addr;
312-
if (i != Stubs.end()) {
313-
Addr = Section.getAddressWithOffset(i->second);
312+
if (!Inserted) {
313+
Addr = Section.getAddressWithOffset(It->second);
314314
} else {
315315
// Create a new stub function.
316316
assert(Section.getStubOffset() % 4 == 0 && "Misaligned stub");
317-
Stubs[Value] = Section.getStubOffset();
317+
It->second = Section.getStubOffset();
318318
uint32_t StubOpcode = 0;
319319
if (RE.RelType == MachO::ARM_RELOC_BR24)
320320
StubOpcode = 0xe51ff004; // ldr pc, [pc, #-4]

llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ class RuntimeDyldMachOX86_64
131131
assert(RE.IsPCRel);
132132
assert(RE.Size == 2);
133133
Value.Offset -= RE.Addend;
134-
RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(Value);
134+
auto [It, Inserted] = Stubs.try_emplace(Value);
135135
uint8_t *Addr;
136-
if (i != Stubs.end()) {
137-
Addr = Section.getAddressWithOffset(i->second);
136+
if (!Inserted) {
137+
Addr = Section.getAddressWithOffset(It->second);
138138
} else {
139-
Stubs[Value] = Section.getStubOffset();
139+
It->second = Section.getStubOffset();
140140
uint8_t *GOTEntry = Section.getAddressWithOffset(Section.getStubOffset());
141141
RelocationEntry GOTRE(RE.SectionID, Section.getStubOffset(),
142142
MachO::X86_64_RELOC_UNSIGNED, Value.Offset, false,

0 commit comments

Comments
 (0)