diff --git a/.appveyor.yml b/.appveyor.yml index 203aceea0e..db414739f6 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,8 +10,8 @@ branches: environment: matrix: - llvm: 3.9.1 - - llvm: 4.0.1 - llvm: 5.0.1 + - llvm: 6.0.0 configuration: - release diff --git a/.ci-dockerfiles/llvm-6.0.0/Dockerfile b/.ci-dockerfiles/llvm-6.0.0/Dockerfile new file mode 100644 index 0000000000..07c0b42c44 --- /dev/null +++ b/.ci-dockerfiles/llvm-6.0.0/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:14.04 + +ENV LLVM_VERSION 6.0.0 + +RUN apt-get update \ + && apt-get install -y \ + apt-transport-https \ + build-essential \ + g++ \ + git \ + libncurses5-dev \ + libssl-dev \ + make \ + wget \ + xz-utils \ + zlib1g-dev \ + && cd /tmp \ + && wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.21.tar.bz2 \ + && tar xjvf pcre2-10.21.tar.bz2 \ + && cd pcre2-10.21 \ + && ./configure --prefix=/usr \ + && make \ + && sudo make install \ + && cd / \ + && rm -rf /tmp/pcre* \ + && wget -O - http://releases.llvm.org/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04.tar.xz \ + | tar xJf - --no-same-owner --strip-components 1 -C /usr/local/ clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04 diff --git a/.ci-dockerfiles/llvm-6.0.0/README.md b/.ci-dockerfiles/llvm-6.0.0/README.md new file mode 100644 index 0000000000..7169658023 --- /dev/null +++ b/.ci-dockerfiles/llvm-6.0.0/README.md @@ -0,0 +1,21 @@ +# Build image + +```bash +docker build -t ponylang/ponyc-ci:llvm-6.0.0 . +``` + +# Run image to test + +Will get you a bash shell in the image to try cloning Pony into where you can test a build to make sure everything will work before pushing + +```bash +docker run --name ponyc-ci-llvm-600 --rm -i -t ponylang/ponyc-ci:llvm-6.0.0 bash +``` + +# Push to dockerhub + +You'll need credentials for the ponylang dockerhub account. Talk to @jemc or @seantallen for access + +```bash +docker push ponylang/ponyc-ci:llvm-6.0.0 +``` diff --git a/.circleci/config.yml b/.circleci/config.yml index 57c9a8554e..7d1535f310 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,6 +12,18 @@ jobs: steps: - checkout - run: find . -name '*.bash' -exec shellcheck {} \; + llvm-600-debug: + docker: + - image: ponylang/ponyc-ci:llvm-6.0.0 + steps: + - checkout + - run: make test-ci config=debug default_pic=true + llvm-600-release: + docker: + - image: ponylang/ponyc-ci:llvm-6.0.0 + steps: + - checkout + - run: make test-ci config=release default_pic=true llvm-501-debug: docker: - image: ponylang/ponyc-ci:llvm-5.0.1 @@ -73,6 +85,8 @@ workflows: jobs: - verify-changelog - validate-shell-scripts + - llvm-600-debug + - llvm-600-release - llvm-501-debug - llvm-501-release - llvm-401-debug diff --git a/.travis_script.bash b/.travis_script.bash index 1b35672b6c..f8d817a98c 100644 --- a/.travis_script.bash +++ b/.travis_script.bash @@ -49,24 +49,6 @@ case "${TRAVIS_OS_NAME}" in make clean brew uninstall llvm@3.9 - # 4.0.x - brew install llvm@4 - brew link --overwrite --force llvm@4 - ln -fs "$(which llvm-config)" llvmsym/llvm-config-4.0 - ln -fs "$(which clang++)" llvmsym/clang++-4.0 - - export CC1=clang-4.0 - export CXX1=clang++-4.0 - #echo "Running LLVM 4.0 config=debug build..." - #export config=debug - #ponyc-test - echo "Running LLVM 4.0 config=release build..." - export config=release - ponyc-test - - make clean - brew uninstall llvm@4 - # 5.0.x brew install llvm@5 brew link --overwrite --force llvm@5 @@ -75,15 +57,31 @@ case "${TRAVIS_OS_NAME}" in export CC1=clang-5.0 export CXX1=clang++-5.0 - #echo "Running LLVM 5.0 config=debug build..." - #export config=debug - #ponyc-test echo "Running LLVM 5.0 config=release build..." export config=release ponyc-test make clean brew uninstall llvm@5 + + # 6.0.x + # There is no llvm@6 package right now, so this will break once LLVM 7 + # is released. Hopefully when they do that there will be a llvm@6 package + # at which point both `brew install llvm` and `brew uninstall llvm` + # should be updated to replace `llvm` with `llvm@6` + brew install llvm + brew link --overwrite --force llvm + ln -fs "$(which llvm-config)" llvmsym/llvm-config-6.0 + ln -fs "$(which clang++)" llvmsym/clang++-6.0 + + export CC1=clang-6.0 + export CXX1=clang++-6.0 + echo "Running LLVM 6.0 config=release build..." + export config=release + ponyc-test + + make clean + brew uninstall llvm fi ;; diff --git a/Makefile b/Makefile index df74153e29..95adaab3c7 100644 --- a/Makefile +++ b/Makefile @@ -205,6 +205,8 @@ endif ifndef LLVM_CONFIG ifneq (,$(shell which /usr/local/opt/llvm/bin/llvm-config 2> /dev/null)) LLVM_CONFIG = /usr/local/opt/llvm/bin/llvm-config + else ifneq (,$(shell which llvm-config-6.0 2> /dev/null)) + LLVM_CONFIG = llvm-config-6.0 else ifneq (,$(shell which llvm-config-3.9 2> /dev/null)) LLVM_CONFIG = llvm-config-3.9 else ifneq (,$(shell which /usr/local/opt/llvm@3.9/bin/llvm-config 2> /dev/null)) @@ -261,6 +263,8 @@ else ifeq ($(llvm_version),5.0.0) $(warning WARNING: LLVM 5 support is experimental and may result in decreased performance or crashes) else ifeq ($(llvm_version),5.0.1) $(warning WARNING: LLVM 5 support is experimental and may result in decreased performance or crashes) +else ifeq ($(llvm_version),6.0.0) + $(warning WARNING: LLVM 6 support is experimental and may result in decreased performance or crashes) else $(warning WARNING: Unsupported LLVM version: $(llvm_version)) $(warning Please use LLVM 3.9.1) @@ -615,12 +619,12 @@ define CONFIGURE_COMPILER compiler := $(CC) flags := $(ALL_CFLAGS) $(CFLAGS) endif - + ifeq ($(suffix $(1)),.bc) compiler := $(CC) flags := $(ALL_CFLAGS) $(CFLAGS) endif - + ifeq ($(suffix $(1)),.ll) compiler := $(CC) flags := $(ALL_CFLAGS) $(CFLAGS) -Wno-override-module diff --git a/src/libponyc/codegen/codegen.c b/src/libponyc/codegen/codegen.c index d3777636bc..9858f0c189 100644 --- a/src/libponyc/codegen/codegen.c +++ b/src/libponyc/codegen/codegen.c @@ -16,6 +16,9 @@ #include "ponyassert.h" #include +#if PONY_LLVM >= 600 +#include +#endif #include #include #include @@ -672,10 +675,22 @@ static bool init_module(compile_t* c, ast_t* program, pass_opt_t* opt, bool jit) c->builder = LLVMCreateBuilderInContext(c->context); c->di = LLVMNewDIBuilder(c->module); +#if PONY_LLVM < 600 // TODO: what LANG id should be used? c->di_unit = LLVMDIBuilderCreateCompileUnit(c->di, 0x0004, package_filename(package), package_path(package), "ponyc-" PONY_VERSION, c->opt->release); +#else + const char* filename = package_filename(package); + const char* dirname = package_path(package); + const char* version = "ponyc-" PONY_VERSION; + LLVMMetadataRef fileRef = LLVMDIBuilderCreateFile(c->di, filename, + strlen(filename), dirname, strlen(dirname)); + c->di_unit = LLVMDIBuilderCreateCompileUnit(c->di, + LLVMDWARFSourceLanguageC_plus_plus, fileRef, version, strlen(version), + opt->release, "", 0, 0, "", 0, LLVMDWARFEmissionFull, + 0, false, false); +#endif // Empty frame stack. c->frame = NULL; @@ -722,6 +737,14 @@ bool codegen_merge_runtime_bitcode(compile_t* c) return true; } +#if PONY_LLVM == 600 +// TODO: remove for 6.0.1: https://reviews.llvm.org/D44140 +PONY_EXTERN_C_BEGIN +extern void LLVMInitializeInstCombine_Pony(LLVMPassRegistryRef R); +PONY_EXTERN_C_END +#define LLVMInitializeInstCombine LLVMInitializeInstCombine_Pony +#endif + bool codegen_llvm_init() { LLVMLoadLibraryPermanently(NULL); diff --git a/src/libponyc/codegen/gendebug.cc b/src/libponyc/codegen/gendebug.cc index 655004ee67..f8eb5163ca 100644 --- a/src/libponyc/codegen/gendebug.cc +++ b/src/libponyc/codegen/gendebug.cc @@ -69,6 +69,7 @@ void LLVMDIBuilderDestroy(LLVMDIBuilderRef d) delete pd; } +#if PONY_LLVM < 600 void LLVMDIBuilderFinalize(LLVMDIBuilderRef d) { unwrap(d)->finalize(); @@ -101,6 +102,7 @@ LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef d, const char* file) return wrap(pd->createFile(filename, dir)); } +#endif LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d, LLVMMetadataRef scope, const char* name, LLVMMetadataRef file, unsigned line) diff --git a/src/libponyc/codegen/gendebug.h b/src/libponyc/codegen/gendebug.h index ae03a0881c..32976d91dc 100644 --- a/src/libponyc/codegen/gendebug.h +++ b/src/libponyc/codegen/gendebug.h @@ -3,6 +3,9 @@ #include #include +#if PONY_LLVM >= 600 +#include +#endif PONY_EXTERN_C_BEGIN @@ -46,6 +49,7 @@ LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef m); void LLVMDIBuilderDestroy(LLVMDIBuilderRef d); +#if PONY_LLVM < 600 void LLVMDIBuilderFinalize(LLVMDIBuilderRef d); LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef d, @@ -53,9 +57,10 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef d, int optimized); LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef d, const char* file); +#endif -LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d, - LLVMMetadataRef scope, const char* name, LLVMMetadataRef file, +LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d, + LLVMMetadataRef scope, const char* name, LLVMMetadataRef file, unsigned line); LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef d, diff --git a/src/libponyc/codegen/genopt.cc b/src/libponyc/codegen/genopt.cc index d0e83d9d2d..6421cda33f 100644 --- a/src/libponyc/codegen/genopt.cc +++ b/src/libponyc/codegen/genopt.cc @@ -32,6 +32,10 @@ #include #include +#if PONY_LLVM >= 600 +#include +#endif + #include "../../libponyrt/mem/heap.h" #include "ponyassert.h" @@ -87,6 +91,15 @@ static void print_transform(compile_t* c, Instruction* i, const char* s) } } +// TODO: remove for 6.0.1: https://reviews.llvm.org/D44140 +#if PONY_LLVM == 600 +PONY_EXTERN_C_BEGIN +void LLVMInitializeInstCombine_Pony(LLVMPassRegistryRef R) { + initializeInstructionCombiningPassPass(*unwrap(R)); +} +PONY_EXTERN_C_END +#endif + class HeapToStack : public FunctionPass { public: @@ -302,9 +315,9 @@ class HeapToStack : public FunctionPass } case Instruction::Load: - // This is a workaround for a problem with LLVM 4 & 5 on *nix when + // This is a workaround for a problem with LLVM 4 & 5 on *nix when // hoisting loads (see #2303, #2061, #1592). - // TODO: figure out the real reason LLVM 4 and 5 produce bad code + // TODO: figure out the real reason LLVM 4 and 5 produce bad code // when hoisting stack allocated loads. #if PONY_LLVM >= 400 && !defined(_MSC_VER) // fall through diff --git a/src/libponyc/codegen/gentype.c b/src/libponyc/codegen/gentype.c index 1f32b89514..300b51c887 100644 --- a/src/libponyc/codegen/gentype.c +++ b/src/libponyc/codegen/gentype.c @@ -20,6 +20,10 @@ #include #include +#if PONY_LLVM >= 600 +#include +#endif + static size_t tbaa_metadata_hash(tbaa_metadata_t* a) { return ponyint_hash_ptr(a->name); @@ -391,7 +395,11 @@ static void make_debug_info(compile_t* c, reach_type_t* t) file = ""; compile_type_t* c_t = (compile_type_t*)t->c_type; +#if PONY_LLVM < 600 c_t->di_file = LLVMDIBuilderCreateFile(c->di, file); +#else + c_t->di_file = LLVMDIBuilderCreateFile(c->di, file, strlen(file), "", 0); +#endif switch(t->underlying) { diff --git a/src/libponyc/codegen/host.cc b/src/libponyc/codegen/host.cc index e9ee975ade..a1ea54de99 100644 --- a/src/libponyc/codegen/host.cc +++ b/src/libponyc/codegen/host.cc @@ -39,8 +39,6 @@ LLVMTargetMachineRef codegen_machine(LLVMTargetRef target, pass_opt_t* opt, if(opt->pic || opt->library) reloc = Reloc::PIC_; - CodeModel::Model model = jit ? CodeModel::JITDefault : CodeModel::Default; - CodeGenOpt::Level opt_level = opt->release ? CodeGenOpt::Aggressive : CodeGenOpt::None; @@ -49,8 +47,14 @@ LLVMTargetMachineRef codegen_machine(LLVMTargetRef target, pass_opt_t* opt, Target* t = reinterpret_cast(target); +#if PONY_LLVM < 600 + CodeModel::Model model = jit ? CodeModel::JITDefault : CodeModel::Default; TargetMachine* m = t->createTargetMachine(opt->triple, opt->cpu, opt->features, options, reloc, model, opt_level); +#else +TargetMachine* m = t->createTargetMachine(opt->triple, opt->cpu, + opt->features, options, reloc, llvm::None, opt_level, jit); +#endif return reinterpret_cast(m); } @@ -105,7 +109,11 @@ char* LLVMGetHostCPUFeatures() void LLVMSetUnsafeAlgebra(LLVMValueRef inst) { +#if PONY_LLVM < 600 unwrap(inst)->setHasUnsafeAlgebra(true); +#else // See https://reviews.llvm.org/D39304 for this change + unwrap(inst)->setHasAllowReassoc(true); +#endif } void LLVMSetNoUnsignedWrap(LLVMValueRef inst) diff --git a/wscript b/wscript index 4a74cbd816..6336ef0790 100644 --- a/wscript +++ b/wscript @@ -50,13 +50,13 @@ MSVC_VERSIONS = [ '15.6', '15.4', '15.0', '14.0' ] # keep these in sync with the list in .appveyor.yml LLVM_VERSIONS = [ '3.9.1', - '4.0.1', - '5.0.1' + '5.0.1', + '6.0.0' ] -WINDOWS_LIBS_TAG = "v1.6.0" +WINDOWS_LIBS_TAG = "v1.7.0" LIBRESSL_VERSION = "2.6.4" -PCRE2_VERSION = "10.30" +PCRE2_VERSION = "10.31" # Adds an option for specifying debug or release mode. def options(ctx): @@ -259,8 +259,8 @@ def build(ctx): # build targets: - if ctx.options.llvm.startswith('4') or ctx.options.llvm.startswith('5'): - print('WARNING: LLVM 4 and 5 support is experimental and may result in decreased performance or crashes') + if ctx.options.llvm.startswith('4') or ctx.options.llvm.startswith('5') or ctx.options.llvm.startswith('6'): + print('WARNING: LLVM 4, 5 and 6 support is experimental and may result in decreased performance or crashes') # gtest ctx(