Skip to content

Commit fec084b

Browse files
KristofferCKristofferC
authored andcommitted
Revert "Fix LLVM TaskDispatcher implementation issues (#58950)"
This reverts commit 6846af7.
1 parent ebfd625 commit fec084b

File tree

3 files changed

+16
-474
lines changed

3 files changed

+16
-474
lines changed

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ $(BUILDDIR)/gc-alloc-profiler.o $(BUILDDIR)/gc-alloc-profiler.dbg.obj: $(SRCDIR)
349349
$(BUILDDIR)/gc-page-profiler.o $(BUILDDIR)/gc-page-profiler.dbg.obj: $(SRCDIR)/gc-page-profiler.h
350350
$(BUILDDIR)/init.o $(BUILDDIR)/init.dbg.obj: $(SRCDIR)/builtin_proto.h
351351
$(BUILDDIR)/interpreter.o $(BUILDDIR)/interpreter.dbg.obj: $(SRCDIR)/builtin_proto.h
352-
$(BUILDDIR)/jitlayers.o $(BUILDDIR)/jitlayers.dbg.obj: $(SRCDIR)/jitlayers.h $(SRCDIR)/llvm-codegen-shared.h $(SRCDIR)/llvm-julia-task-dispatcher.h
352+
$(BUILDDIR)/jitlayers.o $(BUILDDIR)/jitlayers.dbg.obj: $(SRCDIR)/jitlayers.h $(SRCDIR)/llvm-codegen-shared.h
353353
$(BUILDDIR)/jltypes.o $(BUILDDIR)/jltypes.dbg.obj: $(SRCDIR)/builtin_proto.h
354354
$(build_shlibdir)/libllvmcalltest.$(SHLIB_EXT): $(SRCDIR)/llvm-codegen-shared.h $(BUILDDIR)/julia_version.h
355355
$(BUILDDIR)/llvm-alloc-helpers.o $(BUILDDIR)/llvm-alloc-helpers.dbg.obj: $(SRCDIR)/llvm-codegen-shared.h $(SRCDIR)/llvm-pass-helpers.h $(SRCDIR)/llvm-alloc-helpers.h

src/jitlayers.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <string>
77

88
#include "llvm/IR/Mangler.h"
9-
#include <llvm/ADT/BitmaskEnum.h>
109
#include <llvm/ADT/Statistic.h>
1110
#include <llvm/ADT/StringMap.h>
1211
#include <llvm/Analysis/TargetLibraryInfo.h>
@@ -47,7 +46,6 @@ using namespace llvm;
4746
#include "jitlayers.h"
4847
#include "julia_assert.h"
4948
#include "processor.h"
50-
#include "llvm-julia-task-dispatcher.h"
5149

5250
#if JL_LLVM_VERSION >= 180000
5351
# include <llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h>
@@ -668,8 +666,17 @@ static void jl_compile_codeinst_now(jl_code_instance_t *codeinst)
668666
if (!decls.specFunctionObject.empty())
669667
NewDefs.push_back(decls.specFunctionObject);
670668
}
671-
auto Addrs = jl_ExecutionEngine->findSymbols(NewDefs);
672-
669+
// Split batches to avoid stack overflow in the JIT linker.
670+
// FIXME: Patch ORCJITs InPlaceTaskDispatcher to not recurse on task dispatches but
671+
// push the tasks to a queue to be drained later. This avoids the stackoverflow caused by recursion
672+
// in the linker when compiling a large number of functions at once.
673+
SmallVector<uint64_t, 0> Addrs;
674+
for (size_t i = 0; i < NewDefs.size(); i += 1000) {
675+
auto end = std::min(i + 1000, NewDefs.size());
676+
SmallVector<StringRef> batch(NewDefs.begin() + i, NewDefs.begin() + end);
677+
auto AddrsBatch = jl_ExecutionEngine->findSymbols(batch);
678+
Addrs.append(AddrsBatch);
679+
}
673680
size_t nextaddr = 0;
674681
for (auto &this_code : linkready) {
675682
auto it = invokenames.find(this_code);
@@ -1834,7 +1841,7 @@ llvm::DataLayout jl_create_datalayout(TargetMachine &TM) {
18341841
JuliaOJIT::JuliaOJIT()
18351842
: TM(createTargetMachine()),
18361843
DL(jl_create_datalayout(*TM)),
1837-
ES(cantFail(orc::SelfExecutorProcessControl::Create(nullptr, std::make_unique<::JuliaTaskDispatcher>()))),
1844+
ES(cantFail(orc::SelfExecutorProcessControl::Create())),
18381845
GlobalJD(ES.createBareJITDylib("JuliaGlobals")),
18391846
JD(ES.createBareJITDylib("JuliaOJIT")),
18401847
ExternalJD(ES.createBareJITDylib("JuliaExternal")),
@@ -2091,7 +2098,7 @@ SmallVector<uint64_t> JuliaOJIT::findSymbols(ArrayRef<StringRef> Names)
20912098
Unmangled[NonOwningSymbolStringPtr(Mangled)] = Unmangled.size();
20922099
Exports.add(std::move(Mangled));
20932100
}
2094-
SymbolMap Syms = cantFail(::safelookup(ES, orc::makeJITDylibSearchOrder(ArrayRef(&JD)), std::move(Exports)));
2101+
SymbolMap Syms = cantFail(ES.lookup(orc::makeJITDylibSearchOrder(ArrayRef(&JD)), std::move(Exports)));
20952102
SmallVector<uint64_t> Addrs(Names.size());
20962103
for (auto it : Syms) {
20972104
Addrs[Unmangled.at(orc::NonOwningSymbolStringPtr(it.first))] = it.second.getAddress().getValue();
@@ -2103,7 +2110,7 @@ Expected<ExecutorSymbolDef> JuliaOJIT::findSymbol(StringRef Name, bool ExportedS
21032110
{
21042111
orc::JITDylib* SearchOrders[3] = {&JD, &GlobalJD, &ExternalJD};
21052112
ArrayRef<orc::JITDylib*> SearchOrder = ArrayRef<orc::JITDylib*>(&SearchOrders[0], ExportedSymbolsOnly ? 3 : 1);
2106-
auto Sym = ::safelookup(ES, SearchOrder, Name);
2113+
auto Sym = ES.lookup(SearchOrder, Name);
21072114
return Sym;
21082115
}
21092116

@@ -2116,7 +2123,7 @@ Expected<ExecutorSymbolDef> JuliaOJIT::findExternalJDSymbol(StringRef Name, bool
21162123
{
21172124
orc::JITDylib* SearchOrders[3] = {&ExternalJD, &GlobalJD, &JD};
21182125
ArrayRef<orc::JITDylib*> SearchOrder = ArrayRef<orc::JITDylib*>(&SearchOrders[0], ExternalJDOnly ? 1 : 3);
2119-
auto Sym = ::safelookup(ES, SearchOrder, getMangledName(Name));
2126+
auto Sym = ES.lookup(SearchOrder, getMangledName(Name));
21202127
return Sym;
21212128
}
21222129

0 commit comments

Comments
 (0)