Skip to content

[ExecutionEngine] Avoid repeated map lookups (NFC) #130461

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1680,16 +1680,16 @@ RuntimeDyldELF::processRelocationRef(
SectionEntry &Section = Sections[SectionID];

// Look for an existing stub.
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
auto [It, Inserted] = Stubs.try_emplace(Value);
if (!Inserted) {
resolveRelocation(Section, Offset,
Section.getLoadAddressWithOffset(i->second), RelType,
Section.getLoadAddressWithOffset(It->second), RelType,
0);
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
Stubs[Value] = Section.getStubOffset();
It->second = Section.getStubOffset();
uint8_t *StubTargetAddr = createStubFunction(
Section.getAddressWithOffset(Section.getStubOffset()));
RelocationEntry RE(SectionID, StubTargetAddr - Section.getAddress(),
Expand Down Expand Up @@ -1745,15 +1745,15 @@ RuntimeDyldELF::processRelocationRef(
Value.Addend += Addend;

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

unsigned AbiVariant = Obj.getPlatformFlags();

Expand Down Expand Up @@ -1945,17 +1945,17 @@ RuntimeDyldELF::processRelocationRef(
RangeOverflow) {
// It is an external symbol (either Value.SymbolName is set, or
// SymType is SymbolRef::ST_Unknown) or out of range.
StubMap::const_iterator i = Stubs.find(Value);
if (i != Stubs.end()) {
auto [It, Inserted] = Stubs.try_emplace(Value);
if (!Inserted) {
// Symbol function stub already created, just relocate to it
resolveRelocation(Section, Offset,
Section.getLoadAddressWithOffset(i->second),
Section.getLoadAddressWithOffset(It->second),
RelType, 0);
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function.
LLVM_DEBUG(dbgs() << " Create a new stub function\n");
Stubs[Value] = Section.getStubOffset();
It->second = Section.getStubOffset();
uint8_t *StubTargetAddr = createStubFunction(
Section.getAddressWithOffset(Section.getStubOffset()),
AbiVariant);
Expand Down Expand Up @@ -2127,10 +2127,10 @@ RuntimeDyldELF::processRelocationRef(
// This is a call to an external function.
// Look for an existing stub.
SectionEntry *Section = &Sections[SectionID];
StubMap::const_iterator i = Stubs.find(Value);
auto [It, Inserted] = Stubs.try_emplace(Value);
uintptr_t StubAddress;
if (i != Stubs.end()) {
StubAddress = uintptr_t(Section->getAddress()) + i->second;
if (!Inserted) {
StubAddress = uintptr_t(Section->getAddress()) + It->second;
LLVM_DEBUG(dbgs() << " Stub function found\n");
} else {
// Create a new stub function (equivalent to a PLT entry).
Expand All @@ -2140,7 +2140,7 @@ RuntimeDyldELF::processRelocationRef(
StubAddress = alignTo(BaseAddress + Section->getStubOffset(),
getStubAlignment());
unsigned StubOffset = StubAddress - BaseAddress;
Stubs[Value] = StubOffset;
It->second = StubOffset;
createStubFunction((uint8_t *)StubAddress);

// Bump our stub offset counter
Expand Down