Page MenuHomePhabricator

Changes to use a string pool for symbols
AcceptedPublic

Authored by jaredwy on Aug 30 2022, 7:24 PM.

Details

Reviewers
lhames
ributzka

Diff Detail

Unit TestsFailed

TimeTest
20 msx64 debian > LLVM-Unit.ExecutionEngine/Orc/_/OrcJITTests/30::34
Script(shard): -- GTEST_OUTPUT=json:/var/lib/buildkite-agent/builds/llvm-project/build/unittests/ExecutionEngine/Orc/./OrcJITTests-LLVM-Unit-1797385-30-34.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=34 GTEST_SHARD_INDEX=30 /var/lib/buildkite-agent/builds/llvm-project/build/unittests/ExecutionEngine/Orc/./OrcJITTests
3,470 msx64 debian > LLVM.Examples/OrcV2Examples::lljit-with-remote-debugging.test
Script: -- : 'RUN: at line 4'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/LLJITWithRemoteDebugging /var/lib/buildkite-agent/builds/llvm-project/llvm/test/Examples/OrcV2Examples/Inputs/argc_sub1_elf.ll | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --check-prefix=CHECK0 /var/lib/buildkite-agent/builds/llvm-project/llvm/test/Examples/OrcV2Examples/lljit-with-remote-debugging.test
3,390 msx64 debian > LLVM.ExecutionEngine/JITLink/AArch64::ELF_aarch64_ehframe.s
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/llvm-mc -triple=aarch64-linux-gnu -filetype=obj -o /var/lib/buildkite-agent/builds/llvm-project/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_aarch64_ehframe.s.tmp /var/lib/buildkite-agent/builds/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_aarch64_ehframe.s
50 msx64 debian > LLVM.ExecutionEngine/JITLink/AArch64::ELF_aarch64_ehframe.test
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/yaml2obj -o /var/lib/buildkite-agent/builds/llvm-project/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_aarch64_ehframe.test.tmp.o /var/lib/buildkite-agent/builds/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_aarch64_ehframe.test
60 msx64 debian > LLVM.ExecutionEngine/JITLink/AArch64::ELF_aarch64_minimal.s
Script: -- : 'RUN: at line 1'; rm -rf /var/lib/buildkite-agent/builds/llvm-project/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_aarch64_minimal.s.tmp && mkdir -p /var/lib/buildkite-agent/builds/llvm-project/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_aarch64_minimal.s.tmp
View Full Test Results (102 Failed)

Event Timeline

jaredwy created this revision.Aug 30 2022, 7:24 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
jaredwy requested review of this revision.Aug 30 2022, 7:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 7:24 PM
jaredwy edited reviewers, added: lhames; removed: ributzka.Aug 30 2022, 7:25 PM
jaredwy removed a subscriber: hiraditya.
jaredwy removed a subscriber: StephenFan.

Hi Jared, thanks for working on this! Your patch looks really good. Two minor comments inline.

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
418–421

Is there a special reason for these methods to take RValue references? Otherwise, these look like classical sink arguments that should be moved in and taken by value (just remove the &&).

969

Do we have a definition for the dtor here?

jaredwy added inline comments.Sep 6 2022, 1:08 AM
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
418–421

No not really and in fact started life that way, just was looking to avoid the overhead of the add/decrement of the ownership counter when I noticed every usage was taking ownership, will remove :)

969

Sorry don't follow the question? Implementation is further down if that's what you meant? Did you want me to move it inline here?

dblaikie added inline comments.
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
418–421

If you std::move at the caller and in the callee, you shouldn't need to add/decrement ownership counters even when passing by value. (it'll add an extra move, but no copies - copies are what cause add/decrement), so this should be good

lhames accepted this revision.Sep 8 2022, 6:30 PM

Dave's suggestion about pass-by-value should be implemented, but otherwise LGTM. Thanks Jared!

There's a part 2 to this bug, which I thought was mentioned in http://llvm.org/PR55533, but I now realize is not: We want to change the interface of LinkGraph and associated classes to use SymbolStringPtr rather than StringRef. That will make it cheap to transfer/copy/compare strings between the current link and the surrounding ORC session, which is something that plugins (and the ObjectLinkingLayer) do quite a lot.

Jared -- do you want to tackle that under http://llvm.org/PR55533? Otherwise we can close that (once you land this patch) and file a follow-up issue.

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
418–421

Yep -- the various rvalue reference arguments should all be changed to pass-by-value with the caller using std::move.

950–963

What happens if you ditch this overload and require a SymbolStringPool for construction? Does it break many uses (outside the unit tests)?

I guess it's just the jitlink::link API (and various implementations of that) that we'd need to update?

This revision is now accepted and ready to land.Sep 8 2022, 6:30 PM
jaredwy updated this revision to Diff 465653.Oct 5 2022, 9:36 PM

Review comments addressed and also just went and removed the getName returning a stringref.

dblaikie added inline comments.Oct 6 2022, 2:24 PM
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
497–498

This could return by const-ref (the same way a large member like a std::vector would return from an accessor by const ref) & then isNamed could be removed & the usage code kept the same? (I assume isNamed was added to avoid the cost of copying the SymbolStringPtr - and if it returns by const ref there's no added cost? Oh, I guess callers still have to add the * in to dereference? yeah, but still maybe better than adding this isNamed function that's a bit quirky - since it only allows the one operation (equality) without the SymbolStringPtr copy, which is a bit niche/special case/inflexible)

500–502

I think this can be removed now?

jaredwy added inline comments.Oct 6 2022, 3:39 PM
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
497–498

It was mostly added to aid in readability of the code and avoiding the unnecessary copy but I am not attached to it, I am new to these lands so if it is not the LLVM way to add utility functions i can remove

500–502

It could.

jaredwy updated this revision to Diff 465919.Oct 6 2022, 4:17 PM

Removing an uncessary if statement

dblaikie added inline comments.Oct 6 2022, 5:46 PM
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
497–498

Could you show/compare the readability issues you had in mind?

Would getName returning by const-ref address the unnecessary copy concerns?

sgraenitz added inline comments.Oct 7 2022, 9:21 AM
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
969

Ah you are right, sorry missed that.

jaredwy updated this revision to Diff 466205.Oct 7 2022, 3:48 PM

Removing a isNamed in favour of just using the comparisons

lhames added a comment.Oct 7 2022, 6:15 PM

I love seeing all that BlockDependenciesMap code disappearing as a result of this change. :D

Lots of minor changes, but the broad direction of this is _great_! Once this patch lands the next big target should be LinkGraph::LookupMap -- we should be able to ditch the StringRefs and pass the SymbolStringPtrs right through to the context. That'll avoid a tonne of re-interning on the ObjectLinkingLayer side.

Very cool work!

llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
497–498

I'd be in favor of having getName() return by const-ref and dropping isNamed -- this would be consistent with the existing getters/setters.

1100

This and the other "add" methods can take SymbolStringPtrs now, rather than StringRefs.

This is a place where I wouldn't mind a convenience overload for the StringRef though. I.e.:

Symbol &addExternalSymbol(SymbolStringPtr Name, orc::ExecutorAddrDiff Size, Linkage L) {
  assert(llvm::count(ExternalSymbols, Name) == 0 && "Duplicate external symbol");
    auto &Sym = Symbol::constructExternal(
        Allocator, createAddressable(orc::ExecutorAddr(), false),
        std::move(Name), Size, L);
    ExternalSymbols.insert(&Sym);
    return Sym;
}

Symbol &addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size, Linkage L) {
  return addExternalSymbol(SSP->intern(Name), Size, L);
}
llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h
42

Are the parens needed here? I think * binds tight enough that you can omit them.

llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
238–239

I'd include intern convenience methods on both the LinkGraph and the builder, and then use them to avoid naming SymbolStringPtrs that only have one use. I.e.

Gym = &createDLLImportEntry(intern(SymbolName), *ExternalSym);

OTOH it's always worth naming a SymbolStringPtr that gets used more than once (otherwise you'd have to intern it more than once).

llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
388

I think you can drop the outer parens here.

541

I think you can drop them outer parens here too.

llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
280

Could lazily intern ELFGOTSymbolName into an ELFJITLinker_x86_64 member variable to speed up repeat comparisons?

No need to do that for this patch, but maybe add a FIXME to follow up on the idea?

llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp
203

I think you can now just assert(Sym->getName() && "Externals must be named").

209

We should key UnresolvedExternals on the SymbolStringPtr now, rather than the StringRef.

llvm/lib/ExecutionEngine/JITLink/PerGraphGOTAndPLTStubsBuilder.h
73

I think GOTEntries should be able to be keyed on the SymbolStringPtr too.

95

PLTStubs should likewise be keyed on the SymbolStringPtr.

llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
67

We need to use the ExecutionSession's SymbolStringPool here. I'd update this to take the ExecutionSession& -- COFFPlatform has an ES member handy that you can pass in.

733

Once everyone's sharing the same pool this can be a direct SymbolStringPtr value comparison.

llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
693

Can be a SSP comparison once the pool is shared.

843–850

These tls symbol strings should be interned and stored in the plugin -- that'll save re-interning them for each graph.

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
532–535

We shouldn't need to allocate a string on the LinkGraph for this any more. Instead, you should just be able to say:

Ptr.setName(G->intern(getImplPrefix() + *KV.first));
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
676

Can compare SSP values once the pool is shared.

814–817

We should intern these tlv strings and store them as members in the plugin to avoid redundant interning.

994–997

More strings to be interned and stored in the plugin.

llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
212–225

Once Symbol::getName() returns by const-ref I think you can replace InternedName with Sym->getName() everywhere here.

231

Ditto here.

414–420

I'd drop Name and just use Sym->getName() here.

465–469

Drop SymName and just use Sym->getName().

llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
75–89

Once you drop the convenience method this shouldn't be needed.

717

Missing newline. :)