From 6e92cb269ede92de23915e61166127d226f9f168 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Sat, 10 Jul 2021 16:49:01 -0400 Subject: [PATCH 01/15] Fix for LLVM12, linked dynamically --- src/CMakeLists.txt | 7 +++---- src/llvmheaders.h | 2 +- src/tcompiler.cpp | 8 ++------ src/tcwrapper.cpp | 12 ++++++++++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5de3e534..2cf43fff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -197,13 +197,11 @@ add_dependencies(TerraObjectFiles TerraGeneratedFiles) add_library(TerraLibrary STATIC $ - ${ALL_LLVM_OBJECTS} ${LUAJIT_OBJECTS} ) add_library(TerraLibraryShared SHARED $ - ${ALL_LLVM_OBJECTS} ${LUAJIT_OBJECTS} ) @@ -231,8 +229,7 @@ set_target_properties(TerraLibraryShared PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${ target_link_libraries(TerraLibraryShared PRIVATE ${LUAJIT_LIBRARIES} - ${ALL_LLVM_LIBRARIES} - ${LLVM_SYSTEM_LIBRARIES} + -lclang-cpp ) if(APPLE) @@ -333,6 +330,8 @@ elseif(UNIX) -Wl,--whole-archive TerraLibrary -Wl,--no-whole-archive + LLVM + -lclang-cpp ${LUAJIT_LIBRARIES} ${ALL_LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBRARIES} diff --git a/src/llvmheaders.h b/src/llvmheaders.h index 3504b66a..19a6fb21 100644 --- a/src/llvmheaders.h +++ b/src/llvmheaders.h @@ -60,7 +60,7 @@ #include "llvmheaders_90.h" #elif LLVM_VERSION == 100 #include "llvmheaders_100.h" -#elif LLVM_VERSION >= 110 && LLVM_VERSION < 120 +#elif LLVM_VERSION >= 110 && LLVM_VERSION < 130 #include "llvmheaders_110.h" #else #error "unsupported LLVM version" diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index 409ece22..362905f1 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -22,8 +22,6 @@ extern "C" { #if LLVM_VERSION < 50 #include "llvm/ExecutionEngine/MCJIT.h" -#else -#include "llvm/ExecutionEngine/OrcMCJITReplacement.h" #endif #include "llvm/Support/Atomic.h" @@ -390,7 +388,7 @@ static void InitializeJIT(TerraCompilationUnit *CU) { #else .setMCJITMemoryManager(std::make_unique(CU)) #endif - .setUseOrcMCJITReplacement(true); + ; #endif CU->ee = eb.create(); @@ -2488,9 +2486,7 @@ struct FunctionEmitter { DEBUG_ONLY(T) { MDNode *scope = debugScopeForFile(customfilename ? customfilename : obj->string("filename")); - B->SetCurrentDebugLocation(DebugLoc::get( - customfilename ? customlinenumber : obj->number("linenumber"), 0, - scope)); + B->SetCurrentDebugLocation(DILocation::get(scope->getContext(), customfilename ? customlinenumber : obj->number("linenumber"), 0, scope)); } } diff --git a/src/tcwrapper.cpp b/src/tcwrapper.cpp index 16e0ab7b..d4472c61 100644 --- a/src/tcwrapper.cpp +++ b/src/tcwrapper.cpp @@ -328,8 +328,16 @@ class IncludeCVisitor : public RecursiveASTVisitor { } CStyleCastExpr *CreateCast(QualType Ty, CastKind Kind, Expr *E) { TypeSourceInfo *TInfo = Context->getTrivialTypeSourceInfo(Ty, SourceLocation()); - return CStyleCastExpr::Create(*Context, Ty, VK_RValue, Kind, E, 0, TInfo, - SourceLocation(), SourceLocation()); + return CStyleCastExpr::Create(*Context, + Ty, + VK_RValue, + Kind, + E, + 0, // CXXCastPath BasePath (?) + FPOptionsOverride::getFromOpaqueInt(0), + TInfo, + SourceLocation(), + SourceLocation()); } IntegerLiteral *LiteralZero() { unsigned IntSize = static_cast(Context->getTypeSize(Context->IntTy)); From a5d3f071648b26118e47c5c35d3406aa04a44523 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Sat, 10 Jul 2021 20:07:51 -0400 Subject: [PATCH 02/15] Simplify the CMake hack for LLVM12 --- src/CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2cf43fff..16ff117e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,10 @@ ### Terra Generated Source Files ### +if(LLVM_VERSION_MAJOR GREATER 11) + set(ALL_LLVM_LIBRARIES clang-cpp LLVM) +endif() + if(TERRA_ENABLE_CUDA) list(APPEND TERRA_CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS} @@ -197,11 +201,13 @@ add_dependencies(TerraObjectFiles TerraGeneratedFiles) add_library(TerraLibrary STATIC $ + ${ALL_LLVM_OBJECTS} ${LUAJIT_OBJECTS} ) add_library(TerraLibraryShared SHARED $ + ${ALL_LLVM_OBJECTS} ${LUAJIT_OBJECTS} ) @@ -229,7 +235,8 @@ set_target_properties(TerraLibraryShared PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${ target_link_libraries(TerraLibraryShared PRIVATE ${LUAJIT_LIBRARIES} - -lclang-cpp + ${ALL_LLVM_LIBRARIES} + ${LLVM_SYSTEM_LIBRARIES} ) if(APPLE) @@ -330,8 +337,6 @@ elseif(UNIX) -Wl,--whole-archive TerraLibrary -Wl,--no-whole-archive - LLVM - -lclang-cpp ${LUAJIT_LIBRARIES} ${ALL_LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBRARIES} From 9c5bebe26a72c9660ab547e0f52fc9d963766a7a Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Sat, 10 Jul 2021 20:08:18 -0400 Subject: [PATCH 03/15] Add #if checks for LLVM12-specific fixes --- src/tcompiler.cpp | 17 ++++++++++++++++- src/tcwrapper.cpp | 16 +++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index 362905f1..f4e182d3 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -22,6 +22,10 @@ extern "C" { #if LLVM_VERSION < 50 #include "llvm/ExecutionEngine/MCJIT.h" +#else +#if LLVM_VERSION < 120 +#include "llvm/ExecutionEngine/OrcMCJITReplacement.h" +#endif #endif #include "llvm/Support/Atomic.h" @@ -387,6 +391,9 @@ static void InitializeJIT(TerraCompilationUnit *CU) { .setMCJITMemoryManager(make_unique(CU)) #else .setMCJITMemoryManager(std::make_unique(CU)) +#endif +#if LLVM_VERSION < 120 + .setUseOrcMCJITReplacement(true) #endif ; #endif @@ -2486,7 +2493,15 @@ struct FunctionEmitter { DEBUG_ONLY(T) { MDNode *scope = debugScopeForFile(customfilename ? customfilename : obj->string("filename")); - B->SetCurrentDebugLocation(DILocation::get(scope->getContext(), customfilename ? customlinenumber : obj->number("linenumber"), 0, scope)); +#if LLVM_VERSION < 120 + B->SetCurrentDebugLocation(DebugLoc::get( + customfilename ? customlinenumber : obj->number("linenumber"), 0, + scope)); +#else + B->SetCurrentDebugLocation(DILocation::get(scope->getContext(), + customfilename ? customlinenumber : obj->number("linenumber"), 0, + scope)); +#endif } } diff --git a/src/tcwrapper.cpp b/src/tcwrapper.cpp index d4472c61..704db47f 100644 --- a/src/tcwrapper.cpp +++ b/src/tcwrapper.cpp @@ -328,16 +328,14 @@ class IncludeCVisitor : public RecursiveASTVisitor { } CStyleCastExpr *CreateCast(QualType Ty, CastKind Kind, Expr *E) { TypeSourceInfo *TInfo = Context->getTrivialTypeSourceInfo(Ty, SourceLocation()); - return CStyleCastExpr::Create(*Context, - Ty, - VK_RValue, - Kind, - E, - 0, // CXXCastPath BasePath (?) +#if LLVM_VERSION < 120 + return CStyleCastExpr::Create(*Context, Ty, VK_RValue, Kind, E, 0, TInfo, + SourceLocation(), SourceLocation()); +#else + return CStyleCastExpr::Create(*Context, Ty, VK_RValue, Kind, E, 0, FPOptionsOverride::getFromOpaqueInt(0), - TInfo, - SourceLocation(), - SourceLocation()); + TInfo, SourceLocation(), SourceLocation()); +#endif } IntegerLiteral *LiteralZero() { unsigned IntSize = static_cast(Context->getTypeSize(Context->IntTy)); From 7bc34b19a0827cb467b20cd92a236673b0c522aa Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Mon, 12 Jul 2021 13:07:40 -0700 Subject: [PATCH 04/15] Fix formatting. --- src/tcompiler.cpp | 3 ++- src/tcwrapper.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index f4e182d3..df8411ca 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -2498,7 +2498,8 @@ struct FunctionEmitter { customfilename ? customlinenumber : obj->number("linenumber"), 0, scope)); #else - B->SetCurrentDebugLocation(DILocation::get(scope->getContext(), + B->SetCurrentDebugLocation(DILocation::get( + scope->getContext(), customfilename ? customlinenumber : obj->number("linenumber"), 0, scope)); #endif diff --git a/src/tcwrapper.cpp b/src/tcwrapper.cpp index 704db47f..5f3271fc 100644 --- a/src/tcwrapper.cpp +++ b/src/tcwrapper.cpp @@ -333,8 +333,8 @@ class IncludeCVisitor : public RecursiveASTVisitor { SourceLocation(), SourceLocation()); #else return CStyleCastExpr::Create(*Context, Ty, VK_RValue, Kind, E, 0, - FPOptionsOverride::getFromOpaqueInt(0), - TInfo, SourceLocation(), SourceLocation()); + FPOptionsOverride::getFromOpaqueInt(0), TInfo, + SourceLocation(), SourceLocation()); #endif } IntegerLiteral *LiteralZero() { From 61a4658350ebb25d405ee18e4a6f288357e4418e Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Mon, 12 Jul 2021 14:30:40 -0700 Subject: [PATCH 05/15] Enable CI tests for LLVM 12. --- .github/workflows/main.yml | 17 +++++++++++++++-- travis.sh | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aee9ed4a..afa91144 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: ['ubuntu-16.04', 'ubuntu-18.04', 'macos-10.15'] - llvm: ['3.8', '5.0', '6.0', '7', '8', '9', '10', '11'] + llvm: ['3.8', '5.0', '6.0', '7', '8', '9', '10', '11', '12'] cmake: ['0', '1'] cuda: ['0', '1'] static: ['0', '1'] @@ -38,10 +38,12 @@ jobs: llvm: '10' - os: 'ubuntu-16.04' llvm: '11' + - os: 'ubuntu-16.04' + llvm: '12' - os: 'ubuntu-18.04' llvm: '3.8' - # macOS: exclude LLVM 5.0, 8-11 make, cuda/no-static/no-slib + # macOS: exclude LLVM 5.0, 8-12 make, cuda/no-static/no-slib - os: 'macos-10.15' llvm: '5.0' - os: 'macos-10.15' @@ -56,6 +58,9 @@ jobs: - os: 'macos-10.15' llvm: '11' cmake: '0' + - os: 'macos-10.15' + llvm: '12' + cmake: '0' - os: 'macos-10.15' cuda: '1' - os: 'macos-10.15' @@ -103,6 +108,8 @@ jobs: cuda: '1' - llvm: '11' cuda: '1' + - llvm: '12' + cuda: '1' # no-static: only LLVM 8 - llvm: '3.8' @@ -119,6 +126,8 @@ jobs: static: '0' - llvm: '11' static: '0' + - llvm: '12' + static: '0' # no-slib: only LLVM 9 - llvm: '3.8' @@ -135,6 +144,8 @@ jobs: slib: '0' - llvm: '11' slib: '0' + - llvm: '12' + slib: '0' # Moonjit: only LLVM 9 - llvm: '3.8' @@ -151,6 +162,8 @@ jobs: lua: 'moonjit' - llvm: '11' lua: 'moonjit' + - llvm: '12' + lua: 'moonjit' steps: - uses: actions/checkout@v1 - run: ./travis.sh diff --git a/travis.sh b/travis.sh index fdc0f1f7..b3c92bfd 100755 --- a/travis.sh +++ b/travis.sh @@ -26,7 +26,16 @@ fi if [[ $(uname) = Linux ]]; then sudo apt-get update -qq - if [[ $LLVM_CONFIG = llvm-config-11 ]]; then + if [[ $LLVM_CONFIG = llvm-config-12 ]]; then + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main" + for i in {1..5}; do sudo apt-get update -qq && break || sleep 15; done + sudo apt-get install -y llvm-12-dev clang-12 libclang-12-dev libedit-dev + export CMAKE_PREFIX_PATH=/usr/lib/llvm-12:/usr/share/llvm-12 + if [[ -n $STATIC_LLVM && $STATIC_LLVM -eq 0 ]]; then + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/llvm-12/lib" + fi + elif [[ $LLVM_CONFIG = llvm-config-11 ]]; then wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" for i in {1..5}; do sudo apt-get update -qq && break || sleep 15; done @@ -81,7 +90,13 @@ if [[ $(uname) = Linux ]]; then fi if [[ $(uname) = Darwin ]]; then - if [[ $LLVM_CONFIG = llvm-config-11 ]]; then + if [[ $LLVM_CONFIG = llvm-config-12 ]]; then + curl -L -O https://github.com/elliottslaughter/llvm-build/releases/download/llvm-12.0.1/clang+llvm-12.0.1-x86_64-apple-darwin.tar.xz + tar xf clang+llvm-12.0.1-x86_64-apple-darwin.tar.xz + ln -s clang+llvm-12.0.1-x86_64-apple-darwin/bin/llvm-config llvm-config-12 + ln -s clang+llvm-12.0.1-x86_64-apple-darwin/bin/clang clang-12 + export CMAKE_PREFIX_PATH=$PWD/clang+llvm-12.0.1-x86_64-apple-darwin + elif [[ $LLVM_CONFIG = llvm-config-11 ]]; then curl -L -O https://github.com/elliottslaughter/llvm-build/releases/download/llvm-11.0.1/clang+llvm-11.0.1-x86_64-apple-darwin.tar.xz tar xf clang+llvm-11.0.1-x86_64-apple-darwin.tar.xz ln -s clang+llvm-11.0.1-x86_64-apple-darwin/bin/llvm-config llvm-config-11 From dfcf56feb2b64fd828442e1ec96b23f08d0b99c1 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Mon, 12 Jul 2021 17:07:14 -0700 Subject: [PATCH 06/15] Fix Makefile for LLVM 12. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9d84ea62..bfbfc09d 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ LLVMVERGT4 := $(shell expr $(LLVM_VERSION) \>= 40) FLAGS += -DLLVM_VERSION=$(LLVM_VERSION) -LLVM_NEEDS_CXX14="100 110 111" +LLVM_NEEDS_CXX14="100 110 111 120" ifneq (,$(findstring $(LLVM_VERSION),$(LLVM_NEEDS_CXX14))) CPPFLAGS += -std=c++1y # GCC 5 does not support -std=c++14 flag else From 85034d5a837caa5f8fc8797c290e8f3883d450bc Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Tue, 13 Jul 2021 09:08:44 -0700 Subject: [PATCH 07/15] Revert CMake change for now since it breaks static linking. --- src/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16ff117e..5de3e534 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,10 +2,6 @@ ### Terra Generated Source Files ### -if(LLVM_VERSION_MAJOR GREATER 11) - set(ALL_LLVM_LIBRARIES clang-cpp LLVM) -endif() - if(TERRA_ENABLE_CUDA) list(APPEND TERRA_CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS} From 0de11ce8188b7c569aa4d552949adc36e897de61 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Sun, 18 Jul 2021 00:33:54 -0400 Subject: [PATCH 08/15] Use Attribute::get* methods for ByVal and SRet Fixes "Attribute 'byval' type does not match parameter!" errors --- src/tcompiler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index df8411ca..db50fce1 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -957,13 +957,13 @@ struct CCallingConv { } template - void addSRetAttr(FnOrCall *r, int idx) { - r->addAttribute(idx, Attribute::StructRet); + void addSRetAttr(FnOrCall *r, int idx, Type* ty) { + r->addAttribute(idx, Attribute::getWithStructRetType(*CU->TT->ctx, ty)); r->addAttribute(idx, Attribute::NoAlias); } template - void addByValAttr(FnOrCall *r, int idx) { - r->addAttribute(idx, Attribute::ByVal); + void addByValAttr(FnOrCall *r, int idx, Type* ty) { + r->addAttribute(idx, llvm::Attribute::getWithByValType(*CU->TT->ctx, ty)); } template void addExtAttrIfNeeded(TType *t, FnOrCall *r, int idx) { @@ -976,14 +976,14 @@ struct CCallingConv { addExtAttrIfNeeded(info->returntype.type, r, 0); int argidx = 1; if (info->returntype.kind == C_AGGREGATE_MEM) { - addSRetAttr(r, argidx); + addSRetAttr(r, argidx, info->returntype.cctype); argidx++; } for (size_t i = 0; i < info->paramtypes.size(); i++) { Argument *v = &info->paramtypes[i]; if (v->kind == C_AGGREGATE_MEM) { #ifndef _WIN32 - addByValAttr(r, argidx); + addByValAttr(r, argidx, v->cctype); #endif } addExtAttrIfNeeded(v->type, r, argidx); From d345261377f1e0acebd98a3a8bba7b04541ed910 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Sun, 18 Jul 2021 20:20:04 -0400 Subject: [PATCH 09/15] Add LLVM 12 checks around typed ByVal/SRet attrs --- src/tcompiler.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index db50fce1..c218d711 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -958,12 +958,20 @@ struct CCallingConv { template void addSRetAttr(FnOrCall *r, int idx, Type* ty) { +#if LLVM_VERSION < 120 + r->addAttribute(idx, Attribute::StructRet); +#else r->addAttribute(idx, Attribute::getWithStructRetType(*CU->TT->ctx, ty)); +#endif r->addAttribute(idx, Attribute::NoAlias); } template void addByValAttr(FnOrCall *r, int idx, Type* ty) { - r->addAttribute(idx, llvm::Attribute::getWithByValType(*CU->TT->ctx, ty)); +#if LLVM_VERSION < 120 + r->addAttribute(idx, Attribute::ByVal); +#else + r->addAttribute(idx, Attribute::getWithByValType(*CU->TT->ctx, ty)); +#endif } template void addExtAttrIfNeeded(TType *t, FnOrCall *r, int idx) { From c056eb50fa8cf9670a5ea4c4ce95058aba404376 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Mon, 19 Jul 2021 00:08:29 -0400 Subject: [PATCH 10/15] Formatting --- src/tcompiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index c218d711..2c6ba99b 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -957,7 +957,7 @@ struct CCallingConv { } template - void addSRetAttr(FnOrCall *r, int idx, Type* ty) { + void addSRetAttr(FnOrCall *r, int idx, Type *ty) { #if LLVM_VERSION < 120 r->addAttribute(idx, Attribute::StructRet); #else @@ -966,7 +966,7 @@ struct CCallingConv { r->addAttribute(idx, Attribute::NoAlias); } template - void addByValAttr(FnOrCall *r, int idx, Type* ty) { + void addByValAttr(FnOrCall *r, int idx, Type *ty) { #if LLVM_VERSION < 120 r->addAttribute(idx, Attribute::ByVal); #else From ca92b101f1f4a8e54df4defad2aff7fab363c6ab Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Wed, 21 Jul 2021 17:56:32 -0400 Subject: [PATCH 11/15] Add llvm_headers_120.h --- src/llvmheaders.h | 4 +++- src/llvmheaders_120.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/llvmheaders_120.h diff --git a/src/llvmheaders.h b/src/llvmheaders.h index 19a6fb21..26aaf186 100644 --- a/src/llvmheaders.h +++ b/src/llvmheaders.h @@ -60,8 +60,10 @@ #include "llvmheaders_90.h" #elif LLVM_VERSION == 100 #include "llvmheaders_100.h" -#elif LLVM_VERSION >= 110 && LLVM_VERSION < 130 +#elif LLVM_VERSION >= 110 && LLVM_VERSION < 120 #include "llvmheaders_110.h" +#elif LLVM_VERSION == 120 +#include "llvmheaders_120.h" #else #error "unsupported LLVM version" // for OSX code completion diff --git a/src/llvmheaders_120.h b/src/llvmheaders_120.h new file mode 100644 index 00000000..93949901 --- /dev/null +++ b/src/llvmheaders_120.h @@ -0,0 +1,37 @@ +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/InlineAsm.h" +#include "llvm/Analysis/CallGraphSCCPass.h" +#include "llvm/Analysis/CallGraph.h" +#include "llvm/IR/DIBuilder.h" +#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/Mangler.h" +//#include "llvm/ExecutionEngine/ObjectImage.h" +#include "llvm/IR/Verifier.h" +#include "llvm/Linker/Linker.h" +#include "llvm/IR/CFG.h" +#include "llvm/IR/InstVisitor.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" + +#include "llvm/Support/VirtualFileSystem.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Rewrite/Frontend/Rewriters.h" +#include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/Object/SymbolSize.h" + +#include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/Support/Error.h" + +#define LLVM_PATH_TYPE std::string +#define RAW_FD_OSTREAM_NONE sys::fs::F_None +#define RAW_FD_OSTREAM_BINARY sys::fs::F_None +#define HASFNATTR(attr) \ + getAttributes().hasAttribute(AttributeSet::FunctionIndex, Attribute ::attr) +#define ADDFNATTR(attr) addFnAttr(Attribute ::attr) +#define ATTRIBUTE Attributes From 14874ecd0c115e6e0bd0ab3ada6f8e2b42f523db Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Wed, 21 Jul 2021 18:00:03 -0400 Subject: [PATCH 12/15] Support more linker versions in Makefile Changes the way LLVM & Clang object files are detected & extracted in the default Makefile to handle a wider variety of linker `-t` output formats. --- Makefile | 21 +++++++++++++++++---- src/unpacklibraries.lua | 25 ------------------------- 2 files changed, 17 insertions(+), 29 deletions(-) delete mode 100644 src/unpacklibraries.lua diff --git a/Makefile b/Makefile index bfbfc09d..93a891e1 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ LLVM_LIBRARY_FLAGS += -lclangFrontend -lclangDriver \ -lclangAnalysis \ -lclangEdit -lclangAST -lclangLex -lclangBasic -CLANG_AST_MATCHERS = "80 90 100 110 111" +CLANG_AST_MATCHERS = "80 90 100 110 111 120" ifneq (,$(findstring $(LLVM_VERSION),$(CLANG_AST_MATCHERS))) LLVM_LIBRARY_FLAGS += -lclangASTMatchers endif @@ -229,9 +229,22 @@ release/include/terra/%.h: $(LUAJIT_INCLUDE)/%.h $(LUAJIT_LIB) build/llvm_objects/llvm_list: $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) mkdir -p build/llvm_objects/luajit - $(CXX) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t 2>&1 | egrep "lib(LLVM|clang)" > build/llvm_objects/llvm_list - # extract needed LLVM objects based on a dummy linker invocation - < build/llvm_objects/llvm_list $(LUAJIT) src/unpacklibraries.lua build/llvm_objects + # Extract needed LLVM objects based on a dummy linker invocation: + # - Older linkers output '(libName.a)object.o' per line, + # - Newer versions output just 'libName.a', unless -t is passed twice. + # grep & uniq are used to get just the paths to the static libraries needed. + $(CXX) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t 2>&1 \ + | egrep -o "[^()]*lib(LLVM|clang|Polly).*\.a" \ + | uniq \ + > build/llvm_objects/llvm_list + # Extract all the static libraries to build/llvm_objects/* + cd build/llvm_objects; for lib in $$(cat llvm_list); do \ + DIR=$$(basename $$lib .a); \ + mkdir -p $$DIR; \ + cd $$DIR; \ + ar x $$lib; \ + cd ..; \ + done # include all luajit objects, since the entire lua interface is used in terra diff --git a/src/unpacklibraries.lua b/src/unpacklibraries.lua deleted file mode 100644 index ff884d22..00000000 --- a/src/unpacklibraries.lua +++ /dev/null @@ -1,25 +0,0 @@ -local destination = ... - -local function exe(cmd,...) - cmd = string.format(cmd,...) - local res = { os.execute(cmd) } - if type(res[1]) == 'number' and res[1] ~= 0 or not res[1] then - print('Error during '..cmd..':', table.unpack(res)) - error("command failed: "..cmd) - end -end -local function exists(path) - local f = io.open(path) - if not f then return false end - f:close() - return true -end -for line in io.lines() do - line = line:gsub("[()]"," ") - local archivepath,objectfile = line:match("(%S+)%s+(%S+)") - local archivename = archivepath:match("/([^/]*)%.a$") - if not exists( ("%s/%s/%s"):format(destination,archivename,objectfile) ) then - exe("mkdir -p %s/%s",destination,archivename) - exe("cd %s/%s; ar x %s %s",destination,archivename,archivepath,objectfile) - end -end \ No newline at end of file From 4c450ad5ea550134e0e52479fba143d6277e6568 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Thu, 22 Jul 2021 17:19:16 -0400 Subject: [PATCH 13/15] Greatly simplify Clang/LLVM bundling in Makefile --- Makefile | 57 +++++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 93a891e1..88bc5017 100644 --- a/Makefile +++ b/Makefile @@ -101,37 +101,32 @@ DYNFLAGS = -dynamiclib -single_module -fPIC -install_name "@rpath/terra.dylib" TERRA_STATIC_LIBRARY = -Wl,-force_load,$(LIBRARY) endif -LLVM_LIBRARY_FLAGS += $(LUAJIT_LIB) -LLVM_LIBRARY_FLAGS += $(shell $(LLVM_CONFIG) --ldflags) -L$(CLANG_PREFIX)/lib -LLVM_LIBRARY_FLAGS += -lclangFrontend -lclangDriver \ - -lclangSerialization -lclangCodeGen -lclangParse -lclangSema \ - -lclangAnalysis \ - -lclangEdit -lclangAST -lclangLex -lclangBasic +CLANG_LIBS += libclangFrontend.a \ + libclangDriver.a \ + libclangSerialization.a \ + libclangCodeGen.a \ + libclangParse.a \ + libclangSema.a \ + libclangAnalysis.a \ + libclangEdit.a \ + libclangAST.a \ + libclangLex.a \ + libclangBasic.a CLANG_AST_MATCHERS = "80 90 100 110 111 120" ifneq (,$(findstring $(LLVM_VERSION),$(CLANG_AST_MATCHERS))) -LLVM_LIBRARY_FLAGS += -lclangASTMatchers +CLANG_LIBS += libclangASTMatchers.a endif -# by default, Terra includes only the pieces of the LLVM libraries it needs, -# but this can be a problem if third-party-libraries that also need LLVM are -# used - allow the user to request that some/all of the LLVM components be -# included and re-exported in their entirety +# Get full path to clang libaries +CLANG_LIBFILES := $(patsubst %, $(CLANG_PREFIX)/lib/%, $(CLANG_LIBS)) + ifeq "$(LLVMVERGT4)" "1" LLVM_LIBS += $(shell $(LLVM_CONFIG) --libs --link-static) + LLVM_LIBFILES = $(shell $(LLVM_CONFIG) --libfiles --link-static) else LLVM_LIBS += $(shell $(LLVM_CONFIG) --libs) -endif -ifneq ($(REEXPORT_LLVM_COMPONENTS),) - REEXPORT_LIBS := $(shell $(LLVM_CONFIG) --libs $(REEXPORT_LLVM_COMPONENTS)) - ifneq ($(findstring $(UNAME), Linux FreeBSD),) - LLVM_LIBRARY_FLAGS += -Wl,--whole-archive $(REEXPORT_LIBS) -Wl,--no-whole-archive - else - LLVM_LIBRARY_FLAGS += $(REEXPORT_LIBS:%=-Wl,-force_load,%) - endif - LLVM_LIBRARY_FLAGS += $(filter-out $(REEXPORT_LIBS),$(LLVM_LIBS)) -else - LLVM_LIBRARY_FLAGS += $(LLVM_LIBS) + LLVM_LIBFILES = $(shell $(LLVM_CONFIG) --libfiles) endif # llvm sometimes requires ncurses and libz, check if they have the symbols, and add them if they do @@ -149,6 +144,8 @@ ifeq ($(UNAME), FreeBSD) SUPPORT_LIBRARY_FLAGS += -lexecinfo -pthread endif +SUPPORT_LIBRARY_FLAGS += -lffi -ledit + PACKAGE_DEPS += $(LUAJIT_LIB) #makes luajit happy on osx 10.6 (otherwise luaL_newstate returns NULL) @@ -229,24 +226,16 @@ release/include/terra/%.h: $(LUAJIT_INCLUDE)/%.h $(LUAJIT_LIB) build/llvm_objects/llvm_list: $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) mkdir -p build/llvm_objects/luajit - # Extract needed LLVM objects based on a dummy linker invocation: - # - Older linkers output '(libName.a)object.o' per line, - # - Newer versions output just 'libName.a', unless -t is passed twice. - # grep & uniq are used to get just the paths to the static libraries needed. - $(CXX) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t 2>&1 \ - | egrep -o "[^()]*lib(LLVM|clang|Polly).*\.a" \ - | uniq \ - > build/llvm_objects/llvm_list - # Extract all the static libraries to build/llvm_objects/* - cd build/llvm_objects; for lib in $$(cat llvm_list); do \ + # Extract Luajit + all LLVM & Clang libraries + cd build/llvm_objects; for lib in $(LUAJIT_LIB) $(LLVM_LIBFILES) $(CLANG_LIBFILES); do \ + echo ---$$lib---; \ DIR=$$(basename $$lib .a); \ mkdir -p $$DIR; \ cd $$DIR; \ ar x $$lib; \ + ls; \ cd ..; \ done - # include all luajit objects, since the entire lua interface is used in terra - build/lua_objects/lj_obj.o: $(LUAJIT_LIB) mkdir -p build/lua_objects From c9c9898b59aef10e16bb6f4207144f82ec0980b3 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Sun, 25 Jul 2021 22:44:07 -0400 Subject: [PATCH 14/15] Fix LLVM 11 builds by including libxml2 --- Makefile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 88bc5017..13dcb8d1 100644 --- a/Makefile +++ b/Makefile @@ -123,10 +123,15 @@ CLANG_LIBFILES := $(patsubst %, $(CLANG_PREFIX)/lib/%, $(CLANG_LIBS)) ifeq "$(LLVMVERGT4)" "1" LLVM_LIBS += $(shell $(LLVM_CONFIG) --libs --link-static) - LLVM_LIBFILES = $(shell $(LLVM_CONFIG) --libfiles --link-static) + LLVM_LIBFILES := $(shell $(LLVM_CONFIG) --libfiles --link-static) else LLVM_LIBS += $(shell $(LLVM_CONFIG) --libs) - LLVM_LIBFILES = $(shell $(LLVM_CONFIG) --libfiles) + LLVM_LIBFILES := $(shell $(LLVM_CONFIG) --libfiles) +endif + +LLVM_POLLY = "100 110 111 120" +ifneq (,$(findstring $(LLVM_VERSION),$(LLVM_POLLY))) + LLVM_LIBFILES += $(shell $(LLVM_CONFIG) --libdir)/libPolly*.a endif # llvm sometimes requires ncurses and libz, check if they have the symbols, and add them if they do @@ -146,6 +151,11 @@ endif SUPPORT_LIBRARY_FLAGS += -lffi -ledit +LLVM_LIBXML2 := "110 111" +ifneq (,$(findstring $(LLVM_VERSION),$(LLVM_LIBXML2))) + SUPPORT_LIBRARY_FLAGS += -lxml2 +endif + PACKAGE_DEPS += $(LUAJIT_LIB) #makes luajit happy on osx 10.6 (otherwise luaL_newstate returns NULL) @@ -228,12 +238,11 @@ build/llvm_objects/llvm_list: $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) mkdir -p build/llvm_objects/luajit # Extract Luajit + all LLVM & Clang libraries cd build/llvm_objects; for lib in $(LUAJIT_LIB) $(LLVM_LIBFILES) $(CLANG_LIBFILES); do \ - echo ---$$lib---; \ + echo Extracing objects from $$lib; \ DIR=$$(basename $$lib .a); \ mkdir -p $$DIR; \ cd $$DIR; \ ar x $$lib; \ - ls; \ cd ..; \ done From 8f72f733cdab6ffcf4acbd80fed561ae5284c2d8 Mon Sep 17 00:00:00 2001 From: Jason Dogariu Date: Mon, 26 Jul 2021 13:29:47 -0400 Subject: [PATCH 15/15] Always link libxml2 in the Makefile --- Makefile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 13dcb8d1..06090c4d 100644 --- a/Makefile +++ b/Makefile @@ -149,12 +149,7 @@ ifeq ($(UNAME), FreeBSD) SUPPORT_LIBRARY_FLAGS += -lexecinfo -pthread endif -SUPPORT_LIBRARY_FLAGS += -lffi -ledit - -LLVM_LIBXML2 := "110 111" -ifneq (,$(findstring $(LLVM_VERSION),$(LLVM_LIBXML2))) - SUPPORT_LIBRARY_FLAGS += -lxml2 -endif +SUPPORT_LIBRARY_FLAGS += -lffi -ledit -lxml2 PACKAGE_DEPS += $(LUAJIT_LIB)