aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/BrainF/BrainF.cpp4
-rw-r--r--examples/BrainF/BrainFDriver.cpp8
-rw-r--r--examples/BrainF/CMakeLists.txt1
-rw-r--r--examples/ExceptionDemo/ExceptionDemo.cpp105
-rw-r--r--examples/HowToUseJIT/CMakeLists.txt1
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h13
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp22
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h19
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp22
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h18
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp22
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h25
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp19
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h34
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h12
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/CMakeLists.txt2
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/server.cpp16
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp35
-rw-r--r--examples/Kaleidoscope/Chapter2/CMakeLists.txt4
-rw-r--r--examples/Kaleidoscope/Chapter2/toy.cpp39
-rw-r--r--examples/Kaleidoscope/Chapter3/toy.cpp13
-rw-r--r--examples/Kaleidoscope/Chapter4/toy.cpp13
-rw-r--r--examples/Kaleidoscope/Chapter5/toy.cpp15
-rw-r--r--examples/Kaleidoscope/Chapter6/toy.cpp16
-rw-r--r--examples/Kaleidoscope/Chapter7/toy.cpp19
-rw-r--r--examples/Kaleidoscope/Chapter8/toy.cpp33
-rw-r--r--examples/Kaleidoscope/include/KaleidoscopeJIT.h10
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp2
28 files changed, 320 insertions, 222 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index 97ecdab0fe950..91d813a6c3bb4 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -339,7 +339,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
switch(c) {
case '-':
direction = -1;
- // Fall through
+ LLVM_FALLTHROUGH;
case '+':
if (cursym == SYM_CHANGE) {
@@ -360,7 +360,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
case '<':
direction = -1;
- // Fall through
+ LLVM_FALLTHROUGH;
case '>':
if (cursym == SYM_MOVE) {
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index d19427add876a..57a86fbf52122 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -26,9 +26,10 @@
#include "BrainF.h"
#include "llvm/ADT/APInt.h"
-#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
@@ -153,10 +154,15 @@ int main(int argc, char **argv) {
//Write it out
if (JIT) {
InitializeNativeTarget();
+ InitializeNativeTargetAsmPrinter();
outs() << "------- Running JIT -------\n";
Module &M = *Mod;
ExecutionEngine *ee = EngineBuilder(std::move(Mod)).create();
+ if (!ee) {
+ errs() << "Error: execution engine creation failed.\n";
+ abort();
+ }
std::vector<GenericValue> args;
Function *brainf_func = M.getFunction("brainf");
GenericValue gv = ee->runFunction(brainf_func, args);
diff --git a/examples/BrainF/CMakeLists.txt b/examples/BrainF/CMakeLists.txt
index cf1cf1b61596e..7b44b3a62756a 100644
--- a/examples/BrainF/CMakeLists.txt
+++ b/examples/BrainF/CMakeLists.txt
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
MC
+ MCJIT
Support
nativecodegen
)
diff --git a/examples/ExceptionDemo/ExceptionDemo.cpp b/examples/ExceptionDemo/ExceptionDemo.cpp
index 0afc3fdf59aa4..a8b82e1da778a 100644
--- a/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -79,64 +79,12 @@
#include <inttypes.h>
+#include <unwind.h>
+
#ifndef USE_GLOBAL_STR_CONSTS
#define USE_GLOBAL_STR_CONSTS true
#endif
-// System C++ ABI unwind types from:
-// http://mentorembedded.github.com/cxx-abi/abi-eh.html (v1.22)
-
-extern "C" {
-
- typedef enum {
- _URC_NO_REASON = 0,
- _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
- _URC_FATAL_PHASE2_ERROR = 2,
- _URC_FATAL_PHASE1_ERROR = 3,
- _URC_NORMAL_STOP = 4,
- _URC_END_OF_STACK = 5,
- _URC_HANDLER_FOUND = 6,
- _URC_INSTALL_CONTEXT = 7,
- _URC_CONTINUE_UNWIND = 8
- } _Unwind_Reason_Code;
-
- typedef enum {
- _UA_SEARCH_PHASE = 1,
- _UA_CLEANUP_PHASE = 2,
- _UA_HANDLER_FRAME = 4,
- _UA_FORCE_UNWIND = 8,
- _UA_END_OF_STACK = 16
- } _Unwind_Action;
-
- struct _Unwind_Exception;
-
- typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
- struct _Unwind_Exception *);
-
- struct _Unwind_Exception {
- uint64_t exception_class;
- _Unwind_Exception_Cleanup_Fn exception_cleanup;
-
- uintptr_t private_1;
- uintptr_t private_2;
-
- // @@@ The IA-64 ABI says that this structure must be double-word aligned.
- // Taking that literally does not make much sense generically. Instead
- // we provide the maximum alignment required by any type for the machine.
- } __attribute__((__aligned__));
-
- struct _Unwind_Context;
- typedef struct _Unwind_Context *_Unwind_Context_t;
-
- extern const uint8_t *_Unwind_GetLanguageSpecificData (_Unwind_Context_t c);
- extern uintptr_t _Unwind_GetGR (_Unwind_Context_t c, int i);
- extern void _Unwind_SetGR (_Unwind_Context_t c, int i, uintptr_t n);
- extern void _Unwind_SetIP (_Unwind_Context_t, uintptr_t new_value);
- extern uintptr_t _Unwind_GetIP (_Unwind_Context_t context);
- extern uintptr_t _Unwind_GetRegionStart (_Unwind_Context_t context);
-
-} // extern "C"
-
//
// Example types
//
@@ -254,7 +202,7 @@ static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function &function,
llvm::Constant *initWith = 0) {
llvm::BasicBlock &block = function.getEntryBlock();
llvm::IRBuilder<> tmp(&block, block.begin());
- llvm::AllocaInst *ret = tmp.CreateAlloca(type, 0, varName.c_str());
+ llvm::AllocaInst *ret = tmp.CreateAlloca(type, 0, varName);
if (initWith)
tmp.CreateStore(initWith, ret);
@@ -271,6 +219,16 @@ static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function &function,
// Runtime C Library functions
//
+namespace {
+template <typename Type_>
+uintptr_t ReadType(const uint8_t *&p) {
+ Type_ value;
+ memcpy(&value, p, sizeof(Type_));
+ p += sizeof(Type_);
+ return static_cast<uintptr_t>(value);
+}
+}
+
// Note: using an extern "C" block so that static functions can be used
extern "C" {
@@ -461,8 +419,7 @@ static uintptr_t readEncodedPointer(const uint8_t **data, uint8_t encoding) {
// first get value
switch (encoding & 0x0F) {
case llvm::dwarf::DW_EH_PE_absptr:
- result = *((uintptr_t*)p);
- p += sizeof(uintptr_t);
+ result = ReadType<uintptr_t>(p);
break;
case llvm::dwarf::DW_EH_PE_uleb128:
result = readULEB128(&p);
@@ -472,28 +429,22 @@ static uintptr_t readEncodedPointer(const uint8_t **data, uint8_t encoding) {
result = readSLEB128(&p);
break;
case llvm::dwarf::DW_EH_PE_udata2:
- result = *((uint16_t*)p);
- p += sizeof(uint16_t);
+ result = ReadType<uint16_t>(p);
break;
case llvm::dwarf::DW_EH_PE_udata4:
- result = *((uint32_t*)p);
- p += sizeof(uint32_t);
+ result = ReadType<uint32_t>(p);
break;
case llvm::dwarf::DW_EH_PE_udata8:
- result = *((uint64_t*)p);
- p += sizeof(uint64_t);
+ result = ReadType<uint64_t>(p);
break;
case llvm::dwarf::DW_EH_PE_sdata2:
- result = *((int16_t*)p);
- p += sizeof(int16_t);
+ result = ReadType<int16_t>(p);
break;
case llvm::dwarf::DW_EH_PE_sdata4:
- result = *((int32_t*)p);
- p += sizeof(int32_t);
+ result = ReadType<int32_t>(p);
break;
case llvm::dwarf::DW_EH_PE_sdata8:
- result = *((int64_t*)p);
- p += sizeof(int64_t);
+ result = ReadType<int64_t>(p);
break;
default:
// not supported
@@ -642,12 +593,11 @@ static bool handleActionValue(int64_t *resultAction,
/// @param exceptionObject thrown _Unwind_Exception instance.
/// @param context unwind system context
/// @returns minimally supported unwinding control indicator
-static _Unwind_Reason_Code handleLsda(int version,
- const uint8_t *lsda,
+static _Unwind_Reason_Code handleLsda(int version, const uint8_t *lsda,
_Unwind_Action actions,
- uint64_t exceptionClass,
- struct _Unwind_Exception *exceptionObject,
- _Unwind_Context_t context) {
+ _Unwind_Exception_Class exceptionClass,
+ struct _Unwind_Exception *exceptionObject,
+ struct _Unwind_Context *context) {
_Unwind_Reason_Code ret = _URC_CONTINUE_UNWIND;
if (!lsda)
@@ -826,11 +776,10 @@ static _Unwind_Reason_Code handleLsda(int version,
/// @param exceptionObject thrown _Unwind_Exception instance.
/// @param context unwind system context
/// @returns minimally supported unwinding control indicator
-_Unwind_Reason_Code ourPersonality(int version,
- _Unwind_Action actions,
- uint64_t exceptionClass,
+_Unwind_Reason_Code ourPersonality(int version, _Unwind_Action actions,
+ _Unwind_Exception_Class exceptionClass,
struct _Unwind_Exception *exceptionObject,
- _Unwind_Context_t context) {
+ struct _Unwind_Context *context) {
#ifdef DEBUG
fprintf(stderr,
"We are in ourPersonality(...):actions is <%d>.\n",
diff --git a/examples/HowToUseJIT/CMakeLists.txt b/examples/HowToUseJIT/CMakeLists.txt
index a344ad07ca63c..e86626d5cec64 100644
--- a/examples/HowToUseJIT/CMakeLists.txt
+++ b/examples/HowToUseJIT/CMakeLists.txt
@@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
Interpreter
- MC
Support
nativecodegen
)
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index 35c871affec8b..22716b2b52155 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -16,10 +16,10 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
@@ -62,17 +62,17 @@ public:
auto Resolver = createLambdaResolver(
[&](const std::string &Name) {
if (auto Sym = CompileLayer.findSymbol(Name, false))
- return Sym.toRuntimeDyldSymbol();
- return RuntimeDyld::SymbolInfo(nullptr);
+ return Sym;
+ return JITSymbol(nullptr);
},
[](const std::string &Name) {
if (auto SymAddr =
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported);
- return RuntimeDyld::SymbolInfo(nullptr);
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return JITSymbol(nullptr);
});
- // Build a singlton module set to hold our module.
+ // Build a singleton module set to hold our module.
std::vector<std::unique_ptr<Module>> Ms;
Ms.push_back(std::move(M));
@@ -93,7 +93,6 @@ public:
void removeModule(ModuleHandle H) {
CompileLayer.removeModuleSet(H);
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
index 22b0819cd71a9..50912109e811c 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index 30cfed6af95ec..91d903029a00a 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
@@ -16,19 +16,22 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
#include <memory>
#include <string>
@@ -72,17 +75,17 @@ public:
auto Resolver = createLambdaResolver(
[&](const std::string &Name) {
if (auto Sym = OptimizeLayer.findSymbol(Name, false))
- return Sym.toRuntimeDyldSymbol();
- return RuntimeDyld::SymbolInfo(nullptr);
+ return Sym;
+ return JITSymbol(nullptr);
},
[](const std::string &Name) {
if (auto SymAddr =
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported);
- return RuntimeDyld::SymbolInfo(nullptr);
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return JITSymbol(nullptr);
});
- // Build a singlton module set to hold our module.
+ // Build a singleton module set to hold our module.
std::vector<std::unique_ptr<Module>> Ms;
Ms.push_back(std::move(M));
@@ -105,7 +108,6 @@ public:
}
private:
-
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
@@ -124,7 +126,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
index 22b0819cd71a9..50912109e811c 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index 68bdafe9897c5..5ecc869f80f57 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -16,22 +16,26 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
#include <memory>
+#include <set>
#include <string>
#include <vector>
@@ -83,17 +87,17 @@ public:
auto Resolver = createLambdaResolver(
[&](const std::string &Name) {
if (auto Sym = CODLayer.findSymbol(Name, false))
- return Sym.toRuntimeDyldSymbol();
- return RuntimeDyld::SymbolInfo(nullptr);
+ return Sym;
+ return JITSymbol(nullptr);
},
[](const std::string &Name) {
if (auto SymAddr =
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported);
- return RuntimeDyld::SymbolInfo(nullptr);
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return JITSymbol(nullptr);
});
- // Build a singlton module set to hold our module.
+ // Build a singleton module set to hold our module.
std::vector<std::unique_ptr<Module>> Ms;
Ms.push_back(std::move(M));
@@ -116,7 +120,6 @@ public:
}
private:
-
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
@@ -135,7 +138,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
index 22b0819cd71a9..50912109e811c 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index d14c2b1805f61..527d4be09f0f9 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -16,21 +16,27 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
+#include <cassert>
+#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
@@ -47,6 +53,7 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
const PrototypeAST& getProto() const;
const std::string& getName() const;
llvm::Function *codegen();
@@ -107,19 +114,19 @@ public:
auto Resolver = createLambdaResolver(
[&](const std::string &Name) {
if (auto Sym = IndirectStubsMgr->findStub(Name, false))
- return Sym.toRuntimeDyldSymbol();
+ return Sym;
if (auto Sym = OptimizeLayer.findSymbol(Name, false))
- return Sym.toRuntimeDyldSymbol();
- return RuntimeDyld::SymbolInfo(nullptr);
+ return Sym;
+ return JITSymbol(nullptr);
},
[](const std::string &Name) {
if (auto SymAddr =
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
- return RuntimeDyld::SymbolInfo(SymAddr, JITSymbolFlags::Exported);
- return RuntimeDyld::SymbolInfo(nullptr);
+ return JITSymbol(SymAddr, JITSymbolFlags::Exported);
+ return JITSymbol(nullptr);
});
- // Build a singlton module set to hold our module.
+ // Build a singleton module set to hold our module.
std::vector<std::unique_ptr<Module>> Ms;
Ms.push_back(std::move(M));
@@ -173,7 +180,7 @@ public:
addModule(std::move(M));
auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
assert(Sym && "Couldn't find compiled function?");
- TargetAddress SymAddr = Sym.getAddress();
+ JITTargetAddress SymAddr = Sym.getAddress();
if (auto Err =
IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()),
SymAddr)) {
@@ -197,7 +204,6 @@ public:
}
private:
-
std::string mangle(const std::string &Name) {
std::string MangledName;
raw_string_ostream MangledNameStream(MangledName);
@@ -223,7 +229,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
index ddce0dc35b25c..07981a8f79b79 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
@@ -7,16 +7,15 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -140,7 +139,8 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -150,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -159,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -171,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -183,6 +186,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -195,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -206,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -220,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -233,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -250,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
index 24d6dc9b7b8f0..d1ef3c9549ffa 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
@@ -15,24 +15,31 @@
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
#include "RemoteJITUtils.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
+#include <cassert>
+#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
@@ -49,6 +56,7 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
const PrototypeAST& getProto() const;
const std::string& getName() const;
llvm::Function *codegen();
@@ -87,7 +95,8 @@ public:
typedef decltype(OptimizeLayer)::ModuleSetHandleT ModuleHandle;
KaleidoscopeJIT(MyRemote &Remote)
- : TM(EngineBuilder().selectTarget()),
+ : TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
+ "", SmallVector<std::string, 0>())),
DL(TM->createDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
@@ -123,21 +132,20 @@ public:
auto Resolver = createLambdaResolver(
[&](const std::string &Name) {
if (auto Sym = IndirectStubsMgr->findStub(Name, false))
- return Sym.toRuntimeDyldSymbol();
+ return Sym;
if (auto Sym = OptimizeLayer.findSymbol(Name, false))
- return Sym.toRuntimeDyldSymbol();
- return RuntimeDyld::SymbolInfo(nullptr);
+ return Sym;
+ return JITSymbol(nullptr);
},
[&](const std::string &Name) {
if (auto AddrOrErr = Remote.getSymbolAddress(Name))
- return RuntimeDyld::SymbolInfo(*AddrOrErr,
- JITSymbolFlags::Exported);
+ return JITSymbol(*AddrOrErr, JITSymbolFlags::Exported);
else {
logAllUnhandledErrors(AddrOrErr.takeError(), errs(),
"Error resolving remote symbol:");
exit(1);
}
- return RuntimeDyld::SymbolInfo(nullptr);
+ return JITSymbol(nullptr);
});
std::unique_ptr<MyRemote::RCMemoryManager> MemMgr;
@@ -147,7 +155,7 @@ public:
exit(1);
}
- // Build a singlton module set to hold our module.
+ // Build a singleton module set to hold our module.
std::vector<std::unique_ptr<Module>> Ms;
Ms.push_back(std::move(M));
@@ -201,7 +209,7 @@ public:
addModule(std::move(M));
auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
assert(Sym && "Couldn't find compiled function?");
- TargetAddress SymAddr = Sym.getAddress();
+ JITTargetAddress SymAddr = Sym.getAddress();
if (auto Err =
IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()),
SymAddr)) {
@@ -216,7 +224,7 @@ public:
return Error::success();
}
- Error executeRemoteExpr(TargetAddress ExprAddr) {
+ Error executeRemoteExpr(JITTargetAddress ExprAddr) {
return Remote.callVoidVoid(ExprAddr);
}
@@ -229,7 +237,6 @@ public:
}
private:
-
std::string mangle(const std::string &Name) {
std::string MangledName;
raw_string_ostream MangledNameStream(MangledName);
@@ -255,7 +262,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
index 869d0a7ef39da..48a19385596f2 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
@@ -14,9 +14,11 @@
#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
-#include "llvm/ExecutionEngine/Orc/RPCChannel.h"
-#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
-#include <mutex>
+#include "llvm/ExecutionEngine/Orc/RawByteChannel.h"
+#include "llvm/Support/Error.h"
+#include <cassert>
+#include <cerrno>
+#include <system_error>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
@@ -25,7 +27,7 @@
#endif
/// RPC channel that reads from and writes from file descriptors.
-class FDRPCChannel final : public llvm::orc::remote::RPCChannel {
+class FDRPCChannel final : public llvm::orc::rpc::RawByteChannel {
public:
FDRPCChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
@@ -71,4 +73,4 @@ private:
int InFD, OutFD;
};
-#endif
+#endif // LLVM_TOOLS_LLI_REMOTEJITUTILS_H
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/CMakeLists.txt b/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/CMakeLists.txt
index 15dd53516ceb0..ef0240c0ca771 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/CMakeLists.txt
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/CMakeLists.txt
@@ -15,3 +15,5 @@ set(LLVM_LINK_COMPONENTS
add_kaleidoscope_chapter(BuildingAJIT-Ch5-Server
server.cpp
)
+
+export_executable_symbols(BuildingAJIT-Ch5-Server)
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/server.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/server.cpp
index c53e22fe83ae2..da6e8ac652348 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/server.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/server.cpp
@@ -102,18 +102,8 @@ int main(int argc, char* argv[]) {
MyServerT Server(TCPChannel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
- while (1) {
- MyServerT::JITFuncId Id = MyServerT::InvalidId;
- ExitOnErr(Server.startReceivingFunction(TCPChannel, (uint32_t&)Id));
- switch (Id) {
- case MyServerT::TerminateSessionId:
- ExitOnErr(Server.handleTerminateSession());
- return 0;
- default:
- ExitOnErr(Server.handleKnownFunction(Id));
- break;
- }
- }
+ while (!Server.receivedTerminate())
+ ExitOnErr(Server.handleOne());
- llvm_unreachable("Fell through server command loop.");
+ return 0;
}
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
index 9c21098971a68..aa08df9ceb538 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
@@ -7,29 +7,30 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include "RemoteJITUtils.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
-
#include <netdb.h>
-#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
@@ -155,7 +156,8 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -165,6 +167,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -174,8 +177,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -186,6 +190,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -198,6 +203,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -210,6 +216,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -221,6 +228,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -235,6 +243,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -248,6 +257,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -265,6 +275,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -1229,9 +1240,9 @@ std::unique_ptr<FDRPCChannel> connect() {
}
sockaddr_in servAddr;
- bzero(&servAddr, sizeof(servAddr));
+ memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = PF_INET;
- bcopy(server->h_addr, &servAddr.sin_addr.s_addr, server->h_length);
+ memcpy(&servAddr.sin_addr.s_addr, server->h_addr, server->h_length);
servAddr.sin_port = htons(Port);
if (connect(sockfd, reinterpret_cast<sockaddr*>(&servAddr),
sizeof(servAddr)) < 0) {
@@ -1265,8 +1276,8 @@ int main(int argc, char *argv[]) {
BinopPrecedence['*'] = 40; // highest.
auto TCPChannel = connect();
- MyRemote Remote = ExitOnErr(MyRemote::Create(*TCPChannel));
- TheJIT = llvm::make_unique<KaleidoscopeJIT>(Remote);
+ auto Remote = ExitOnErr(MyRemote::Create(*TCPChannel));
+ TheJIT = llvm::make_unique<KaleidoscopeJIT>(*Remote);
// Automatically inject a definition for 'printExprResult'.
FunctionProtos["printExprResult"] =
@@ -1288,7 +1299,7 @@ int main(int argc, char *argv[]) {
TheJIT = nullptr;
// Send a terminate message to the remote to tell it to exit cleanly.
- ExitOnErr(Remote.terminateSession());
+ ExitOnErr(Remote->terminateSession());
return 0;
}
diff --git a/examples/Kaleidoscope/Chapter2/CMakeLists.txt b/examples/Kaleidoscope/Chapter2/CMakeLists.txt
index 6224d9ac86406..e4f275d01d405 100644
--- a/examples/Kaleidoscope/Chapter2/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter2/CMakeLists.txt
@@ -1,3 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+ Support
+ )
+
add_kaleidoscope_chapter(Kaleidoscope-Ch2
toy.cpp
)
diff --git a/examples/Kaleidoscope/Chapter2/toy.cpp b/examples/Kaleidoscope/Chapter2/toy.cpp
index 31a998faadc74..8357c5b63fb70 100644
--- a/examples/Kaleidoscope/Chapter2/toy.cpp
+++ b/examples/Kaleidoscope/Chapter2/toy.cpp
@@ -1,3 +1,5 @@
+#include "llvm/ADT/STLExtras.h"
+#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
@@ -6,18 +8,6 @@
#include <string>
#include <vector>
-namespace helper {
-// Cloning make_unique here until it's standard in C++14.
-// Using a namespace to avoid conflicting with MSVC's std::make_unique (which
-// ADL can sometimes find in unqualified calls).
-template <class T, class... Args>
-static
- typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
- make_unique(Args &&... args) {
- return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-} // end namespace helper
-
//===----------------------------------------------------------------------===//
// Lexer
//===----------------------------------------------------------------------===//
@@ -93,11 +83,13 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
};
/// NumberExprAST - Expression class for numeric literals like "1.0".
@@ -160,6 +152,7 @@ public:
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
@@ -202,7 +195,7 @@ static std::unique_ptr<ExprAST> ParseExpression();
/// numberexpr ::= number
static std::unique_ptr<ExprAST> ParseNumberExpr() {
- auto Result = helper::make_unique<NumberExprAST>(NumVal);
+ auto Result = llvm::make_unique<NumberExprAST>(NumVal);
getNextToken(); // consume the number
return std::move(Result);
}
@@ -229,7 +222,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat identifier.
if (CurTok != '(') // Simple variable ref.
- return helper::make_unique<VariableExprAST>(IdName);
+ return llvm::make_unique<VariableExprAST>(IdName);
// Call.
getNextToken(); // eat (
@@ -253,7 +246,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
// Eat the ')'.
getNextToken();
- return helper::make_unique<CallExprAST>(IdName, std::move(Args));
+ return llvm::make_unique<CallExprAST>(IdName, std::move(Args));
}
/// primary
@@ -305,8 +298,8 @@ static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
}
// Merge LHS/RHS.
- LHS = helper::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
- std::move(RHS));
+ LHS = llvm::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
+ std::move(RHS));
}
}
@@ -342,7 +335,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() {
// success.
getNextToken(); // eat ')'.
- return helper::make_unique<PrototypeAST>(FnName, std::move(ArgNames));
+ return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames));
}
/// definition ::= 'def' prototype expression
@@ -353,7 +346,7 @@ static std::unique_ptr<FunctionAST> ParseDefinition() {
return nullptr;
if (auto E = ParseExpression())
- return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E));
+ return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
return nullptr;
}
@@ -361,9 +354,9 @@ static std::unique_ptr<FunctionAST> ParseDefinition() {
static std::unique_ptr<FunctionAST> ParseTopLevelExpr() {
if (auto E = ParseExpression()) {
// Make an anonymous proto.
- auto Proto = helper::make_unique<PrototypeAST>("__anon_expr",
- std::vector<std::string>());
- return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E));
+ auto Proto = llvm::make_unique<PrototypeAST>("__anon_expr",
+ std::vector<std::string>());
+ return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
}
return nullptr;
}
diff --git a/examples/Kaleidoscope/Chapter3/toy.cpp b/examples/Kaleidoscope/Chapter3/toy.cpp
index cdf0d6c8cdb2b..fdefb50cc209f 100644
--- a/examples/Kaleidoscope/Chapter3/toy.cpp
+++ b/examples/Kaleidoscope/Chapter3/toy.cpp
@@ -9,6 +9,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
+#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
@@ -94,11 +95,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -108,6 +112,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -117,6 +122,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -129,6 +135,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -141,6 +148,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -154,6 +162,7 @@ class PrototypeAST {
public:
PrototypeAST(const std::string &Name, std::vector<std::string> Args)
: Name(Name), Args(std::move(Args)) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
};
@@ -167,8 +176,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter4/toy.cpp b/examples/Kaleidoscope/Chapter4/toy.cpp
index 836a2053cbe9f..39b9563bc287a 100644
--- a/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -15,6 +15,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -103,11 +104,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -117,6 +121,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -126,6 +131,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -138,6 +144,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -150,6 +157,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -163,6 +171,7 @@ class PrototypeAST {
public:
PrototypeAST(const std::string &Name, std::vector<std::string> Args)
: Name(Name), Args(std::move(Args)) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
};
@@ -176,8 +185,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter5/toy.cpp b/examples/Kaleidoscope/Chapter5/toy.cpp
index a080bd00cb580..568ec8de5c30d 100644
--- a/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -121,11 +122,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -135,6 +139,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -144,6 +149,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -156,6 +162,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -168,6 +175,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -179,6 +187,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -193,6 +202,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -206,6 +216,7 @@ class PrototypeAST {
public:
PrototypeAST(const std::string &Name, std::vector<std::string> Args)
: Name(Name), Args(std::move(Args)) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
};
@@ -219,8 +230,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter6/toy.cpp b/examples/Kaleidoscope/Chapter6/toy.cpp
index 85d953b0c7564..0fa128d2e5572 100644
--- a/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -129,11 +130,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -143,6 +147,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -152,6 +157,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -163,6 +169,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -175,6 +182,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -187,6 +195,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -198,6 +207,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -212,6 +222,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -229,6 +240,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -252,8 +264,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter7/toy.cpp b/examples/Kaleidoscope/Chapter7/toy.cpp
index 3206ca8c5d7be..58b7ce1ceda21 100644
--- a/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +136,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +153,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +163,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +176,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +189,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -194,6 +202,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +214,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +229,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +243,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +261,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +285,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter8/toy.cpp b/examples/Kaleidoscope/Chapter8/toy.cpp
index f880bb8ea0f0e..f7bb814da775d 100644
--- a/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -1,26 +1,33 @@
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Analysis/Passes.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/Scalar.h"
+#include <algorithm>
+#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
+#include <system_error>
#include <utility>
#include <vector>
@@ -132,11 +139,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -146,6 +156,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -155,8 +166,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -167,6 +179,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -179,6 +192,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -191,6 +205,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -202,6 +217,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -216,6 +232,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -229,6 +246,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -246,6 +264,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -269,8 +288,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/examples/Kaleidoscope/include/KaleidoscopeJIT.h
index 2f492b0e17ffd..6130107bdd942 100644
--- a/examples/Kaleidoscope/include/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/include/KaleidoscopeJIT.h
@@ -17,12 +17,11 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/JITSymbolFlags.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
@@ -60,8 +59,8 @@ public:
auto Resolver = createLambdaResolver(
[&](const std::string &Name) {
if (auto Sym = findMangledSymbol(Name))
- return Sym.toRuntimeDyldSymbol();
- return RuntimeDyld::SymbolInfo(nullptr);
+ return Sym;
+ return JITSymbol(nullptr);
},
[](const std::string &S) { return nullptr; });
auto H = CompileLayer.addModuleSet(singletonSet(std::move(M)),
@@ -73,8 +72,7 @@ public:
}
void removeModule(ModuleHandleT H) {
- ModuleHandles.erase(
- std::find(ModuleHandles.begin(), ModuleHandles.end(), H));
+ ModuleHandles.erase(find(ModuleHandles, H));
CompileLayer.removeModuleSet(H);
}
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index d6f998b39225c..54f014e6fc82a 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -13,7 +13,7 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"