From b8b52e07113812f3995dca585006821685c21d9e Mon Sep 17 00:00:00 2001 From: "Prof. Ronald Moore" <ronald.moore@h-da.de> Date: Mon, 11 Apr 2022 13:56:27 +0200 Subject: [PATCH] updated project for LLVM13 -- all tests pass --- LLVM/cplusplus/KaleidoscopeJIT.h | 25 +++++++++++-------------- LLVM/cplusplus/Makefile | 11 +++++++++-- LLVM/cplusplus/toy7.cpp | 9 +++++---- LLVM/cplusplus/toy8.cpp | 5 +++-- LLVM/cplusplus/toy9.cpp | 5 +++-- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/LLVM/cplusplus/KaleidoscopeJIT.h b/LLVM/cplusplus/KaleidoscopeJIT.h index eb2d21c..18a4c11 100644 --- a/LLVM/cplusplus/KaleidoscopeJIT.h +++ b/LLVM/cplusplus/KaleidoscopeJIT.h @@ -18,10 +18,10 @@ #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/Orc/TargetProcessControl.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/LLVMContext.h" @@ -32,7 +32,6 @@ namespace orc { class KaleidoscopeJIT { private: - std::unique_ptr<TargetProcessControl> TPC; std::unique_ptr<ExecutionSession> ES; DataLayout DL; @@ -44,11 +43,9 @@ private: JITDylib &MainJD; public: - KaleidoscopeJIT(std::unique_ptr<TargetProcessControl> TPC, - std::unique_ptr<ExecutionSession> ES, + KaleidoscopeJIT(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), + : 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, @@ -65,21 +62,21 @@ public: } static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() { - auto SSP = std::make_shared<SymbolStringPool>(); - auto TPC = SelfTargetProcessControl::Create(SSP); - if (!TPC) - return TPC.takeError(); + auto EPC = SelfExecutorProcessControl::Create(); + if (!EPC) + return EPC.takeError(); - auto ES = std::make_unique<ExecutionSession>(std::move(SSP)); + auto ES = std::make_unique<ExecutionSession>(std::move(*EPC)); - JITTargetMachineBuilder JTMB((*TPC)->getTargetTriple()); + JITTargetMachineBuilder JTMB( + ES->getExecutorProcessControl().getTargetTriple()); auto DL = JTMB.getDefaultDataLayoutForTarget(); if (!DL) return DL.takeError(); - return std::make_unique<KaleidoscopeJIT>(std::move(*TPC), std::move(ES), - std::move(JTMB), std::move(*DL)); + return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(JTMB), + std::move(*DL)); } const DataLayout &getDataLayout() const { return DL; } diff --git a/LLVM/cplusplus/Makefile b/LLVM/cplusplus/Makefile index 106485a..9a1f816 100644 --- a/LLVM/cplusplus/Makefile +++ b/LLVM/cplusplus/Makefile @@ -55,7 +55,8 @@ $(PROGS): %: %.cpp $(CC) -g $< $(CFLAGS) -o $@ clean: testclean - $(RM) -fv *~ $(PROGS) ModuleMaker.bc fib test8 test9 + -$(RM) -fv *~ $(PROGS) ModuleMaker.bc fib test8 test9 + -$(RM) -rfv *.dSYM testclean: rm -fv *~ *.output test8.o test9.o @@ -102,9 +103,15 @@ test8: toy8 tests/test8.kal tests/test8.cpp -clang++ tests/test8.cpp test8.o -o test8 -./test8 +## This next test calls "toy9" and then pipes STDERR to clang. +# With bash, this can be done with |& ("pipe ampersand"). +# Make uses "sh". Under Linux, sh and bash are the same thing, +# but under (e.g.) MacOS, they aren't, and with sh, "|&" doesn't work. +# The current version uses "2>&1" to redirect STDERR to STDOUT, +# and then pipe STDOUT to clang. test9: toy9 tests/test9.kal tests/test9.cpp echo && echo "\n===================> Testing toy9...(expect fib(12) == 144)\n" - -./toy9 <tests/test9.kal |& clang -x ir -c - -o test9.o + -./toy9 <tests/test9.kal 2>&1 | clang -x ir -c - -o test9.o -clang++ tests/test9.cpp test9.o -o test9 -./test9 diff --git a/LLVM/cplusplus/toy7.cpp b/LLVM/cplusplus/toy7.cpp index 2c2519e..32eba0c 100644 --- a/LLVM/cplusplus/toy7.cpp +++ b/LLVM/cplusplus/toy7.cpp @@ -746,12 +746,12 @@ Value *NumberExprAST::codegen() { Value *VariableExprAST::codegen() { // Look this variable up in the function. - Value *V = NamedValues[Name]; - if (!V) + AllocaInst *A = NamedValues[Name]; + if (!A) return LogErrorV("Unknown variable name"); // Load the value. - return Builder->CreateLoad(V, Name.c_str()); + return Builder->CreateLoad(A->getAllocatedType(), A, Name.c_str()); } Value *UnaryExprAST::codegen() { @@ -963,7 +963,8 @@ Value *ForExprAST::codegen() { // Reload, increment, and restore the alloca. This handles the case where // the body of the loop mutates the variable. - Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); + Value *CurVar = + Builder->CreateLoad(Alloca->getAllocatedType(), Alloca, VarName.c_str()); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Builder->CreateStore(NextVar, Alloca); diff --git a/LLVM/cplusplus/toy8.cpp b/LLVM/cplusplus/toy8.cpp index a1fe89a..fca54f2 100644 --- a/LLVM/cplusplus/toy8.cpp +++ b/LLVM/cplusplus/toy8.cpp @@ -749,7 +749,7 @@ Value *VariableExprAST::codegen() { return LogErrorV("Unknown variable name"); // Load the value. - return Builder->CreateLoad(V, Name.c_str()); + return Builder->CreateLoad(Type::getDoubleTy(*TheContext), V, Name.c_str()); } Value *UnaryExprAST::codegen() { @@ -961,7 +961,8 @@ Value *ForExprAST::codegen() { // Reload, increment, and restore the alloca. This handles the case where // the body of the loop mutates the variable. - Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); + Value *CurVar = Builder->CreateLoad(Type::getDoubleTy(*TheContext), Alloca, + VarName.c_str()); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Builder->CreateStore(NextVar, Alloca); diff --git a/LLVM/cplusplus/toy9.cpp b/LLVM/cplusplus/toy9.cpp index fa1fe39..a34d70c 100644 --- a/LLVM/cplusplus/toy9.cpp +++ b/LLVM/cplusplus/toy9.cpp @@ -912,7 +912,7 @@ Value *VariableExprAST::codegen() { KSDbgInfo.emitLocation(this); // Load the value. - return Builder->CreateLoad(V, Name.c_str()); + return Builder->CreateLoad(Type::getDoubleTy(*TheContext), V, Name.c_str()); } Value *UnaryExprAST::codegen() { @@ -1133,7 +1133,8 @@ Value *ForExprAST::codegen() { // Reload, increment, and restore the alloca. This handles the case where // the body of the loop mutates the variable. - Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); + Value *CurVar = Builder->CreateLoad(Type::getDoubleTy(*TheContext), Alloca, + VarName.c_str()); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Builder->CreateStore(NextVar, Alloca); -- GitLab