Skip to content

Swift stable jit updates #2017

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
33f81b5
[ORC] Add a LLJITWithThinLTOSummaries example in OrcV2Examples
weliveindetail Aug 14, 2020
3a62560
[ORC] Fix an endif comment.
lhames Aug 24, 2020
d07ed0c
[examples] Fix dependencies for OrcV2Examples/LLJITWithThinLTOSummaries.
lhames Aug 25, 2020
35de35d
[ORC][JITLink] Switch to unique ownership for EHFrameRegistrars.
lhames Aug 26, 2020
1171d1e
[ORC] Add getDFSLinkOrder / getReverseDFSLinkOrder methods to JITDylib.
lhames Aug 29, 2020
8ddd01a
[NFCI] Silent a build warning due to an extra semi-colon
SouraVX Aug 31, 2020
4f7c68d
[ORC] Remove a stray semicolon, silencing warnings. NFC.
mstorsjo Aug 31, 2020
100d3f9
[ORC] Remove an unused variable.
lhames Aug 31, 2020
c6fc120
[ORC] Add unit test for HasMaterializationSideEffectsOnly failure beh…
lhames Sep 1, 2020
b59c73a
[ORC] Fix MachOPlatform's synthetic symbol dependence registration.
lhames Sep 2, 2020
86642a4
[ORC] Add an early out for MachOPlatform's init-scraper plugin setup.
lhames Sep 2, 2020
ffed708
[ORC] Remove stray debugging output.
lhames Sep 2, 2020
8e6136f
[ORC] Fix some bugs in TPCDynamicLibrarySearchGenerator, use in llvm-…
lhames Sep 4, 2020
96219e1
[ORC] Make MaterializationResponsibility immovable, pass by unique_ptr.
lhames Sep 10, 2020
4999363
Revert "[ORC] Make MaterializationResponsibility immovable, pass by u…
fhahn Sep 11, 2020
b7ca38a
Re-apply "[ORC] Make MaterializationResponsibility immovable..." with…
lhames Sep 11, 2020
a426c69
[JITLink] Improve formatting for Edge, Block and Symbol debugging out…
lhames Sep 13, 2020
d578186
[ORC] Add operations to create and lookup JITDylibs to OrcV2 C bindings.
lhames Sep 16, 2020
e1e7f1d
Remove unnecessary forward declarations. NFCI.
RKSimon Sep 17, 2020
b2331f0
[ORC][examples] Add an OrcV2 example for IR optimization via IRTransf…
lhames Sep 20, 2020
9489860
[ORC][examples] Add missing library dependencies.
lhames Sep 22, 2020
dfeb5c7
[ORC][examples] Temporarily remove LLJITWithChildProcess until ORC TP…
weliveindetail Oct 1, 2020
1ff9f71
[JITLink][ELF] Handle BSS sections, improve some error messages.
lhames Oct 6, 2020
c963a10
[RuntimeDyld][COFF] Report fatal error on error, rather than emiting …
lhames Oct 6, 2020
5458c7c
[ORC] Remove OrcV1 APIs.
lhames Sep 8, 2020
973562e
[ORC] Add support for resource tracking/removal (removable code).
lhames Sep 11, 2020
c032b7e
[ORC][examples] Update Kaleidoscope and BuildingAJIT tutorial series …
lhames Sep 23, 2020
1bcd561
[ORC] Add a missing '&'.
lhames Oct 19, 2020
7ea775d
[ORC] Move SimpleResourceManager function object inits out of constru…
lhames Oct 19, 2020
4436be1
[ORC] Move MaterializationResponsibility methods to ExecutionSession.
lhames Oct 2, 2020
4cd25b5
[ORC] Move DefinitionGenerator out of JITDylib.
lhames Oct 1, 2020
b356e9a
[ORC] Update Symbol Lookup / DefinitionGenerator system.
lhames Oct 14, 2020
1f4a1fd
[ORC] Fix a memory leak in the OrcV2 C API (and some comment typos).
lhames Oct 1, 2020
703f9e9
[ORC] Add a C API function to set the ExecutionSession error reporter.
lhames Oct 1, 2020
e69bd68
[ORC] Add C API functions to obtain and clear the symbol string pool.
lhames Oct 2, 2020
46febcd
[ORC] Fix C API function name.
lhames Oct 14, 2020
bdd2866
[ORC] Rename LLVMOrcJITDylibDefinitionGeneratorRef.
lhames Oct 14, 2020
338abf1
[ORC] Add basic ResourceTracker support to the OrcV2 C Bindings.
lhames Oct 15, 2020
d81624b
[ORC] Add an OrcV2 ResourceTracker / Removable-code example.
lhames Oct 15, 2020
e2b7d59
[ORC] Add support for custom generators to the C bindings.
lhames Oct 16, 2020
5072a52
[ORC] Add C API support for defining absolute symbols.
lhames Oct 16, 2020
727fc8f
[ORC] Add function to get pool entry string.
lhames Oct 19, 2020
535d19b
[ORC] Break up C-API header Orc.h, and add JITEventListener support.
lhames Oct 16, 2020
c76854e
[ORC] Fix unused variable warning.
lhames Oct 19, 2020
fc29985
[ORC] Fix a missing include.
lhames Oct 19, 2020
68400f3
[ORC] Remove commented out methods accidentally left in in 069919c9ba3.
lhames Oct 20, 2020
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
12 changes: 6 additions & 6 deletions llvm/docs/tutorial/BuildingAJIT4.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
===========================================================================
Building a JIT: Extreme Laziness - Using Compile Callbacks to JIT from ASTs
===========================================================================
=======================================================================
Building a JIT: Extreme Laziness - Using LazyReexports to JIT from ASTs
=======================================================================

.. contents::
:local:
Expand All @@ -13,9 +13,9 @@ Chapter 4 Introduction
======================

Welcome to Chapter 4 of the "Building an ORC-based JIT in LLVM" tutorial. This
chapter introduces the Compile Callbacks and Indirect Stubs APIs and shows how
they can be used to replace the CompileOnDemand layer from
`Chapter 3 <BuildingAJIT3.html>`_ with a custom lazy-JITing scheme that JITs
chapter introduces custom MaterializationUnits and Layers, and the lazy
reexports API. Together these will be used to replace the CompileOnDemandLayer
from `Chapter 3 <BuildingAJIT3.html>`_ with a custom lazy-JITing scheme that JITs
directly from Kaleidoscope ASTs.

**To be done:**
Expand Down
57 changes: 0 additions & 57 deletions llvm/docs/tutorial/BuildingAJIT5.rst

This file was deleted.

6 changes: 3 additions & 3 deletions llvm/examples/Kaleidoscope/BuildingAJIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ add_subdirectory(Chapter2)
add_subdirectory(Chapter3)
add_subdirectory(Chapter4)

if (NOT WIN32)
add_subdirectory(Chapter5)
endif()
# if (NOT WIN32)
# add_subdirectory(Chapter5)
# endif()
53 changes: 34 additions & 19 deletions llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
Expand All @@ -31,53 +32,67 @@ namespace orc {

class KaleidoscopeJIT {
private:
ExecutionSession ES;
RTDyldObjectLinkingLayer ObjectLayer;
IRCompileLayer CompileLayer;
std::unique_ptr<TargetProcessControl> TPC;
std::unique_ptr<ExecutionSession> ES;

DataLayout DL;
MangleAndInterner Mangle;
ThreadSafeContext Ctx;

RTDyldObjectLinkingLayer ObjectLayer;
IRCompileLayer CompileLayer;

JITDylib &MainJD;

public:
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
: ObjectLayer(ES,
KaleidoscopeJIT(std::unique_ptr<TargetProcessControl> TPC,
std::unique_ptr<ExecutionSession> ES,
JITTargetMachineBuilder JTMB, DataLayout DL)
: TPC(std::move(TPC)), ES(std::move(ES)), DL(std::move(DL)),
Mangle(*this->ES, this->DL),
ObjectLayer(*this->ES,
[]() { return std::make_unique<SectionMemoryManager>(); }),
CompileLayer(ES, ObjectLayer,
CompileLayer(*this->ES, ObjectLayer,
std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
DL(std::move(DL)), Mangle(ES, this->DL),
Ctx(std::make_unique<LLVMContext>()),
MainJD(ES.createBareJITDylib("<main>")) {
MainJD(this->ES->createBareJITDylib("<main>")) {
MainJD.addGenerator(
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
DL.getGlobalPrefix())));
}

~KaleidoscopeJIT() {
if (auto Err = ES->endSession())
ES->reportError(std::move(Err));
}

static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
auto JTMB = JITTargetMachineBuilder::detectHost();
auto TPC = SelfTargetProcessControl::Create();
if (!TPC)
return TPC.takeError();

auto ES = std::make_unique<ExecutionSession>();

if (!JTMB)
return JTMB.takeError();
JITTargetMachineBuilder JTMB((*TPC)->getTargetTriple());

auto DL = JTMB->getDefaultDataLayoutForTarget();
auto DL = JTMB.getDefaultDataLayoutForTarget();
if (!DL)
return DL.takeError();

return std::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
return std::make_unique<KaleidoscopeJIT>(std::move(*TPC), std::move(ES),
std::move(JTMB), std::move(*DL));
}

const DataLayout &getDataLayout() const { return DL; }

LLVMContext &getContext() { return *Ctx.getContext(); }
JITDylib &getMainJITDylib() { return MainJD; }

Error addModule(std::unique_ptr<Module> M) {
return CompileLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx));
Error addModule(ThreadSafeModule TSM, ResourceTrackerSP RT = nullptr) {
if (!RT)
RT = MainJD.getDefaultResourceTracker();
return CompileLayer.add(RT, std::move(TSM));
}

Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
return ES.lookup({&MainJD}, Mangle(Name.str()));
return ES->lookup({&MainJD}, Mangle(Name.str()));
}
};

Expand Down
42 changes: 21 additions & 21 deletions llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,11 @@ static std::unique_ptr<FunctionAST> ParseDefinition() {
}

/// toplevelexpr ::= expression
static std::unique_ptr<FunctionAST> ParseTopLevelExpr(unsigned ExprCount) {
static std::unique_ptr<FunctionAST> ParseTopLevelExpr() {
if (auto E = ParseExpression()) {
// Make an anonymous proto.
auto Proto = std::make_unique<PrototypeAST>
(("__anon_expr" + Twine(ExprCount)).str(), std::vector<std::string>());
auto Proto = std::make_unique<PrototypeAST>("__anon_expr",
std::vector<std::string>());
return std::make_unique<FunctionAST>(std::move(Proto), std::move(E));
}
return nullptr;
Expand All @@ -697,7 +697,7 @@ static std::unique_ptr<PrototypeAST> ParseExtern() {
//===----------------------------------------------------------------------===//

static std::unique_ptr<KaleidoscopeJIT> TheJIT;
static LLVMContext *TheContext;
static std::unique_ptr<LLVMContext> TheContext;
static std::unique_ptr<IRBuilder<>> Builder;
static std::unique_ptr<Module> TheModule;
static std::map<std::string, AllocaInst *> NamedValues;
Expand Down Expand Up @@ -1102,7 +1102,8 @@ Function *FunctionAST::codegen() {
//===----------------------------------------------------------------------===//

static void InitializeModule() {
// Open a new module.
// Open a new context and module.
TheContext = std::make_unique<LLVMContext>();
TheModule = std::make_unique<Module>("my cool jit", *TheContext);
TheModule->setDataLayout(TheJIT->getDataLayout());

Expand All @@ -1116,7 +1117,8 @@ static void HandleDefinition() {
fprintf(stderr, "Read function definition:");
FnIR->print(errs());
fprintf(stderr, "\n");
ExitOnErr(TheJIT->addModule(std::move(TheModule)));
auto TSM = ThreadSafeModule(std::move(TheModule), std::move(TheContext));
ExitOnErr(TheJIT->addModule(std::move(TSM)));
InitializeModule();
}
} else {
Expand All @@ -1140,27 +1142,27 @@ static void HandleExtern() {
}

static void HandleTopLevelExpression() {
static unsigned ExprCount = 0;

// Update ExprCount. This number will be added to anonymous expressions to
// prevent them from clashing.
++ExprCount;

// Evaluate a top-level expression into an anonymous function.
if (auto FnAST = ParseTopLevelExpr(ExprCount)) {
if (auto FnAST = ParseTopLevelExpr()) {
if (FnAST->codegen()) {
// JIT the module containing the anonymous expression, keeping a handle so
// we can free it later.
ExitOnErr(TheJIT->addModule(std::move(TheModule)));
// Create a ResourceTracker to track JIT'd memory allocated to our
// anonymous expression -- that way we can free it after executing.
auto RT = TheJIT->getMainJITDylib().createResourceTracker();

auto TSM = ThreadSafeModule(std::move(TheModule), std::move(TheContext));
ExitOnErr(TheJIT->addModule(std::move(TSM), RT));
InitializeModule();

// Get the anonymous expression's JITSymbol.
auto Sym =
ExitOnErr(TheJIT->lookup(("__anon_expr" + Twine(ExprCount)).str()));
auto Sym = ExitOnErr(TheJIT->lookup("__anon_expr"));

// Get the symbol's address and cast it to the right type (takes no
// arguments, returns a double) so we can call it as a native function.
auto *FP = (double (*)())(intptr_t)Sym.getAddress();
assert(FP && "Failed to codegen function");
fprintf(stderr, "Evaluated to %f\n", FP());

// Delete the anonymous expression module from the JIT.
ExitOnErr(RT->remove());
}
} else {
// Skip token for error recovery.
Expand Down Expand Up @@ -1229,8 +1231,6 @@ int main() {
getNextToken();

TheJIT = ExitOnErr(KaleidoscopeJIT::Create());
TheContext = &TheJIT->getContext();

InitializeModule();

// Run the main "interpreter loop" now.
Expand Down
61 changes: 39 additions & 22 deletions llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
Expand All @@ -36,54 +37,70 @@ namespace orc {

class KaleidoscopeJIT {
private:
ExecutionSession ES;
RTDyldObjectLinkingLayer ObjectLayer;
IRCompileLayer CompileLayer;
IRTransformLayer OptimizeLayer;
std::unique_ptr<TargetProcessControl> TPC;
std::unique_ptr<ExecutionSession> ES;

DataLayout DL;
MangleAndInterner Mangle;
ThreadSafeContext Ctx;

RTDyldObjectLinkingLayer ObjectLayer;
IRCompileLayer CompileLayer;
IRTransformLayer OptimizeLayer;

JITDylib &MainJD;

public:
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
: ObjectLayer(ES,
KaleidoscopeJIT(std::unique_ptr<TargetProcessControl> TPC,
std::unique_ptr<ExecutionSession> ES,
JITTargetMachineBuilder JTMB, DataLayout DL)
: TPC(std::move(TPC)), ES(std::move(ES)), DL(std::move(DL)),
Mangle(*this->ES, this->DL),
ObjectLayer(*this->ES,
[]() { return std::make_unique<SectionMemoryManager>(); }),
CompileLayer(ES, ObjectLayer,
CompileLayer(*this->ES, ObjectLayer,
std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
OptimizeLayer(ES, CompileLayer, optimizeModule), DL(std::move(DL)),
Mangle(ES, this->DL), Ctx(std::make_unique<LLVMContext>()),
MainJD(ES.createBareJITDylib("<main>")) {
OptimizeLayer(*this->ES, CompileLayer, optimizeModule),
MainJD(this->ES->createBareJITDylib("<main>")) {
MainJD.addGenerator(
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
DL.getGlobalPrefix())));
}

const DataLayout &getDataLayout() const { return DL; }

LLVMContext &getContext() { return *Ctx.getContext(); }
~KaleidoscopeJIT() {
if (auto Err = ES->endSession())
ES->reportError(std::move(Err));
}

static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
auto JTMB = JITTargetMachineBuilder::detectHost();
auto TPC = SelfTargetProcessControl::Create();
if (!TPC)
return TPC.takeError();

if (!JTMB)
return JTMB.takeError();
auto ES = std::make_unique<ExecutionSession>();

auto DL = JTMB->getDefaultDataLayoutForTarget();
JITTargetMachineBuilder JTMB((*TPC)->getTargetTriple());

auto DL = JTMB.getDefaultDataLayoutForTarget();
if (!DL)
return DL.takeError();

return std::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
return std::make_unique<KaleidoscopeJIT>(std::move(*TPC), std::move(ES),
std::move(JTMB), std::move(*DL));
}

Error addModule(std::unique_ptr<Module> M) {
return OptimizeLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx));
const DataLayout &getDataLayout() const { return DL; }

JITDylib &getMainJITDylib() { return MainJD; }

Error addModule(ThreadSafeModule TSM, ResourceTrackerSP RT = nullptr) {
if (!RT)
RT = MainJD.getDefaultResourceTracker();

return OptimizeLayer.add(RT, std::move(TSM));
}

Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
return ES.lookup({&MainJD}, Mangle(Name.str()));
return ES->lookup({&MainJD}, Mangle(Name.str()));
}

private:
Expand Down
Loading