-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
228 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
BUILD_DIR="build" | ||
PLATFORM="linux" | ||
|
||
LLVM_COMPILE_FLAGS="llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native" | ||
EXTRA_COMPILE_FLAGS="-rdynamic" | ||
COMPILE_OUTPUT="./${BUILD_DIR}/${PLATFORM}_kaleidoscope" | ||
|
||
# Clean | ||
echo "Cleaning..." | ||
mkdir ./${BUILD_DIR} | ||
rm -r ./${BUILD_DIR}/* | ||
echo "Done cleaning." | ||
echo "" | ||
|
||
# Compile | ||
echo "Compiling..." | ||
clang++ -g -O3 ./src/${PLATFORM}_kaleidoscope.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o ./${BUILD_DIR}/${PLATFORM}_kaleidoscope | ||
echo "Compiling for ${PLATFORM}..." | ||
echo "LLVM FLAGS: ${LLVM_COMPILE_FLAGS}" | ||
echo "EXTRA FLAGS: ${EXTRA_COMPILE_FLAGS}" | ||
clang++ -g -O3 ./src/${PLATFORM}_kaleidoscope.cpp `${LLVM_COMPILE_FLAGS}` ${EXTRA_COMPILE_FLAGS} -o ${COMPILE_OUTPUT} | ||
echo "Done compiling." | ||
echo "OUTPUT: ${COMPILE_OUTPUT}" | ||
echo "" | ||
|
||
# Run | ||
echo "Running..." | ||
./${BUILD_DIR}/${PLATFORM}_kaleidoscope | ||
eval ${COMPILE_OUTPUT} | ||
echo "" | ||
echo "Done running." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//===- KaleidoscopeJIT.h - A simple JIT for Kaleidoscope --------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Contains a simple JIT definition for use in the kaleidoscope tutorials. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H | ||
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/ExecutionEngine/JITSymbol.h" | ||
#include "llvm/ExecutionEngine/Orc/CompileUtils.h" | ||
#include "llvm/ExecutionEngine/Orc/Core.h" | ||
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" | ||
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h" | ||
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" | ||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" | ||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" | ||
#include "llvm/ExecutionEngine/SectionMemoryManager.h" | ||
#include "llvm/IR/DataLayout.h" | ||
#include "llvm/IR/LLVMContext.h" | ||
#include <memory> | ||
|
||
namespace llvm { | ||
namespace orc { | ||
|
||
class KaleidoscopeJIT { | ||
private: | ||
std::unique_ptr<ExecutionSession> ES; | ||
|
||
DataLayout DL; | ||
MangleAndInterner Mangle; | ||
|
||
RTDyldObjectLinkingLayer ObjectLayer; | ||
IRCompileLayer CompileLayer; | ||
|
||
JITDylib &MainJD; | ||
|
||
public: | ||
KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES, | ||
JITTargetMachineBuilder JTMB, DataLayout DL) | ||
: ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL), | ||
ObjectLayer(*this->ES, | ||
[]() { return std::make_unique<SectionMemoryManager>(); }), | ||
CompileLayer(*this->ES, ObjectLayer, | ||
std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))), | ||
MainJD(this->ES->createBareJITDylib("<main>")) { | ||
MainJD.addGenerator( | ||
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess( | ||
DL.getGlobalPrefix()))); | ||
if (JTMB.getTargetTriple().isOSBinFormatCOFF()) { | ||
ObjectLayer.setOverrideObjectFlagsWithResponsibilityFlags(true); | ||
ObjectLayer.setAutoClaimResponsibilityForObjectSymbols(true); | ||
} | ||
} | ||
|
||
~KaleidoscopeJIT() { | ||
if (auto Err = ES->endSession()) | ||
ES->reportError(std::move(Err)); | ||
} | ||
|
||
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() { | ||
auto EPC = SelfExecutorProcessControl::Create(); | ||
if (!EPC) | ||
return EPC.takeError(); | ||
|
||
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC)); | ||
|
||
JITTargetMachineBuilder JTMB( | ||
ES->getExecutorProcessControl().getTargetTriple()); | ||
|
||
auto DL = JTMB.getDefaultDataLayoutForTarget(); | ||
if (!DL) | ||
return DL.takeError(); | ||
|
||
return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(JTMB), | ||
std::move(*DL)); | ||
} | ||
|
||
const DataLayout &getDataLayout() const { return DL; } | ||
|
||
JITDylib &getMainJITDylib() { return MainJD; } | ||
|
||
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())); | ||
} | ||
}; | ||
|
||
} // end namespace orc | ||
} // end namespace llvm | ||
|
||
#endif // LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#include "linux_putchard.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
#include "../typedefs/typedefs.hpp" | ||
|
||
/// putchard - putchar that takes a double and returns 0. | ||
extern "C" real64 | ||
putchard(real64 X) | ||
{ | ||
fputc((char)X, stderr); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#include "win32_putchard.cpp" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "../typedefs/typedefs.hpp" | ||
|
||
/// putchard - putchar that takes a double and returns 0. | ||
extern "C" __declspec(dllexport) real64 | ||
putchard(real64 X) | ||
{ | ||
fputc((char)X, stderr); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters