[pkg-d-commits] [ldc] 02/06: Fix build for LLVM 4.0 (#2017)

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:35:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v0.17.4
in repository ldc.

commit 4847d8a36c3248a6e18f1244767c18ebce5eb743
Author: Johan Engelen <jbc.engelen at gmail.com>
Date:   Mon Feb 27 00:16:31 2017 +0100

    Fix build for LLVM 4.0 (#2017)
    
    * Fix LLVM 4.0 build.
    
    * Copy LDC master's circle.yml.
    
    * Copy master's FindLLVM.cmake
---
 circle.yml                   | 61 +++++++++++++++++++++++++++++++-------------
 cmake/Modules/FindLLVM.cmake | 18 ++++++++++---
 dmd2/root/port.c             | 22 ++++++++++++----
 driver/cl_options.cpp        | 50 ++++++++++++++++--------------------
 driver/toobj.cpp             |  4 +++
 gen/cl_helpers.h             | 26 +++++++++++++++++--
 gen/dibuilder.cpp            | 50 ++++++++++++++++++++++++++----------
 gen/dibuilder.h              |  4 +--
 gen/llvmhelpers.cpp          | 23 +++++++++--------
 gen/optimizer.cpp            | 17 +++++++-----
 gen/runtime.cpp              |  4 +++
 gen/tollvm.cpp               | 16 +++++++++---
 12 files changed, 202 insertions(+), 93 deletions(-)

diff --git a/circle.yml b/circle.yml
index 1ebd197..c94d47d 100644
--- a/circle.yml
+++ b/circle.yml
@@ -1,29 +1,48 @@
 # Requires the BETA setting to use Ubunty 14.04 Trusty
 
+# It appears that the current directory is reset at the start of each `-` line,
+# so for example to do an out-of-source build, you have to chain operations
+# after `cd`: `cd build && cmake .. `.
+
 machine:
   environment:
-    PATH: "~/$CIRCLE_PROJECT_REPONAME/ldc2-1.0.0-alpha1-linux-x86_64/bin:$PATH"
+    PATH: "~/$CIRCLE_PROJECT_REPONAME/ldc2-1.1.0-linux-x86_64/bin:$PATH"
 dependencies:
   cache_directories:
-    - ldc2-1.0.0-alpha1-linux-x86_64
+    - ldc2-1.1.0-linux-x86_64
+    #- clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04
   pre:
-    - sudo add-apt-repository -y 'deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty main'
-    - wget -q -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
+    # LLVM's official APT repo:
+    - sudo add-apt-repository -y 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty main'
+    - sudo add-apt-repository -y 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'
+    - wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
     - sudo apt-get update
-    - if [[ ! -e ldc2-1.0.0-alpha1-linux-x86_64/bin/ldc2 ]]; then wget https://github.com/ldc-developers/ldc/releases/download/v1.0.0-alpha1/ldc2-1.0.0-alpha1-linux-x86_64.tar.xz && xzcat ldc2-1.0.0-alpha1-linux-x86_64.tar.xz | tar -xvf - ; fi
+
+    # Download and cache a prebuilt LLVM package:
+    #- if [[ ! -e clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04 ]]; then wget http://llvm.org/releases/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz && xzcat clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz | tar -xvf - ; fi
+
+    # Download and cache a prebuilt LDC package:
+    - if [[ ! -e ldc2-1.1.0-linux-x86_64/bin/ldc2 ]]; then wget https://github.com/ldc-developers/ldc/releases/download/v1.1.0/ldc2-1.1.0-linux-x86_64.tar.xz && xzcat ldc2-1.1.0-linux-x86_64.tar.xz | tar -xvf - ; fi
+
   override:
-    - sudo apt-get remove clang
-    - sudo apt-get install gcc-4.9 g++-4.9 gcc-4.9-multilib g++-4.9-multilib libconfig++8-dev llvm-3.9 llvm-3.9-dev clang-3.9 libedit-dev
+    - sudo apt-get remove clang llvm
+    - sudo apt-get install libconfig++8-dev libedit-dev
+    - sudo apt-get install llvm-4.0 llvm-4.0-dev clang-4.0
     - pip install --user lit
   post:
-    - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 99
-    - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 99
-    - sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.9 99
-    - sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.9 99
+    - sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-4.0 99
+    - sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-4.0 99
+    #- sudo update-alternatives --install /usr/bin/clang clang ~/$CIRCLE_PROJECT_REPONAME/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang 99
+    #- sudo update-alternatives --install /usr/bin/clang++ clang++ ~/$CIRCLE_PROJECT_REPONAME/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang++ 99
     - gcc --version
     - clang --version
     - ldc2 -version
+    - cmake --version
     - python -c "import lit; lit.main();" --version | head -n 1
+    - gdb --version
+    # Use ld.gold per default, so that LTO is tested.
+    - sudo update-alternatives --install /usr/bin/ld ld /usr/bin/ld.gold 99
+    - ld --version
 
 checkout:
   post:
@@ -32,15 +51,21 @@ checkout:
 
 test:
   pre:
-    - CC=clang CXX=clang++ cmake .
-    - make -j4
+    # Build first with a released LDC
+    - mkdir build
+    - cd build && export CC=clang && export CXX=clang++ && cmake .. && make -j3 && bin/ldc2 -version || exit 1
+
+    # Now build LDC with itself and use this second build for further testing
+    - CC=clang CXX=clang++ cmake -DD_COMPILER="build/bin/ldmd2" -DLDC_INSTALL_LTOPLUGIN=ON .
+    - make -j3
     - bin/ldc2 -version || exit 1
+
   override:
-    - MAKEOPTS=-j2 ctest -j 2 --verbose -R "build-"
-    - CC="" MAKEOPTS=-j4 ctest --verbose -R "dmd-testsuite"
-    - ctest --output-on-failure -R "lit-tests"
-    - MAKEOPTS=-j3 ctest --verbose -R "-test-runner"
-    - ctest -j4 --output-on-failure -E "testsuite"
+    - make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest
+    - make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest
+    - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest --verbose -R "dmd-testsuite"
+    - ctest --output-on-failure -V -R "lit-tests"
+    - ctest -j3 --output-on-failure -E "dmd-testsuite|lit-tests"
 
 # To add more value the test results could be collected, see https://circleci.com/docs/test-metadata
 # A way how to convert the ctest output is described here:
diff --git a/cmake/Modules/FindLLVM.cmake b/cmake/Modules/FindLLVM.cmake
index 286db07..2062136 100644
--- a/cmake/Modules/FindLLVM.cmake
+++ b/cmake/Modules/FindLLVM.cmake
@@ -27,7 +27,9 @@
 # We also want an user-specified LLVM_ROOT_DIR to take precedence over the
 # system default locations such as /usr/local/bin. Executing find_program()
 # multiples times is the approach recommended in the docs.
-set(llvm_config_names llvm-config-3.9 llvm-config39
+set(llvm_config_names llvm-config-5.0 llvm-config50
+                      llvm-config-4.0 llvm-config40
+                      llvm-config-3.9 llvm-config39
                       llvm-config-3.8 llvm-config38
                       llvm-config-3.7 llvm-config37
                       llvm-config-3.6 llvm-config36
@@ -99,7 +101,11 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
             # Versions beginning with 3.8 do not support component ipa
             list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
         endif()
-        if(${LLVM_VERSION_STRING} MATCHES "^4\\.[\\.0-9A-Za-z]*")
+        if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-9][\\.0-9A-Za-z]*")
+            # Versions below 4.0 do not support component debuginfomsf
+            list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
+        endif()
+        if(${LLVM_VERSION_STRING} MATCHES "^[4-9]\\.[\\.0-9A-Za-z]*")
             # Versions beginning with 4. do not support component ipa
             list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
         endif()
@@ -167,7 +173,7 @@ else()
         )
         if(result_code)
             _LLVM_FAIL("Failed to execute llvm-config ('${LLVM_CONFIG}', result code: '${result_code})'")
-        else()
+        else()        
             file(TO_CMAKE_PATH "${tmplibs}" tmplibs)
             string(REGEX MATCHALL "${pattern}[^ ]+" LLVM_${var} ${tmplibs})
         endif()
@@ -196,7 +202,11 @@ else()
         # Versions beginning with 3.8 do not support component ipa
         list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
     endif()
-    if(${LLVM_VERSION_STRING} MATCHES "^4\\.[\\.0-9A-Za-z]*")
+    if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-9][\\.0-9A-Za-z]*")
+        # Versions below 4.0 do not support component debuginfomsf
+        list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
+    endif()
+    if(${LLVM_VERSION_STRING} MATCHES "^[4-9]\\.[\\.0-9A-Za-z]*")
         # Versions beginning with 4. do not support component ipa
         list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
     endif()
diff --git a/dmd2/root/port.c b/dmd2/root/port.c
index 8953947..ca66ac0 100644
--- a/dmd2/root/port.c
+++ b/dmd2/root/port.c
@@ -704,20 +704,32 @@ PortInitializer::PortInitializer()
 {
 #if IN_LLVM
 
+#if LDC_LLVM_VER >= 400
+  const auto &IEEEdouble = llvm::APFloat::IEEEdouble();
+  const auto &x87DoubleExtended = llvm::APFloat::x87DoubleExtended();
+  const auto &PPCDoubleDouble = llvm::APFloat::PPCDoubleDouble();
+  const auto &IEEEquad = llvm::APFloat::IEEEquad();
+#else
+  const auto &IEEEdouble = llvm::APFloat::IEEEdouble;
+  const auto &x87DoubleExtended = llvm::APFloat::x87DoubleExtended;
+  const auto &PPCDoubleDouble = llvm::APFloat::PPCDoubleDouble;
+  const auto &IEEEquad = llvm::APFloat::IEEEquad;
+#endif
+
 // Derive LLVM APFloat::fltSemantics from native format
 #if LDBL_MANT_DIG == 53
-#define FLT_SEMANTIC llvm::APFloat::IEEEdouble
+#define FLT_SEMANTIC IEEEdouble
 #elif LDBL_MANT_DIG == 64
-#define FLT_SEMANTIC llvm::APFloat::x87DoubleExtended
+#define FLT_SEMANTIC x87DoubleExtended
 #elif LDBL_MANT_DIG == 106
-#define FLT_SEMANTIC llvm::APFloat::PPCDoubleDouble
+#define FLT_SEMANTIC PPCDoubleDouble
 #elif LDBL_MANT_DIG == 113
-#define FLT_SEMANTIC llvm::APFloat::IEEEquad
+#define FLT_SEMANTIC IEEEquad
 #else
 #error "Unsupported native floating point format"
 #endif
 
-    Port::nan = *reinterpret_cast<const double*>(llvm::APFloat::getNaN(llvm::APFloat::IEEEdouble).bitcastToAPInt().getRawData());
+    Port::nan = *reinterpret_cast<const double*>(llvm::APFloat::getNaN(IEEEdouble).bitcastToAPInt().getRawData());
     Port::ldbl_nan = *reinterpret_cast<const long double*>(llvm::APFloat::getNaN(FLT_SEMANTIC).bitcastToAPInt().getRawData());
     Port::snan = *reinterpret_cast<const long double*>(llvm::APFloat::getSNaN(FLT_SEMANTIC).bitcastToAPInt().getRawData());
 
diff --git a/driver/cl_options.cpp b/driver/cl_options.cpp
index 6840dd6..68ee3a7 100644
--- a/driver/cl_options.cpp
+++ b/driver/cl_options.cpp
@@ -57,10 +57,10 @@ cl::list<std::string> runargs(
 
 static cl::opt<ubyte, true> useDeprecated(
     cl::desc("Allow deprecated code/language features:"), cl::ZeroOrMore,
-    cl::values(clEnumValN(0, "de", "Do not allow deprecated features"),
-               clEnumValN(1, "d", "Silently allow deprecated features"),
-               clEnumValN(2, "dw", "Warn about the use of deprecated features"),
-               clEnumValEnd),
+    clEnumValues(clEnumValN(0, "de", "Do not allow deprecated features"),
+                 clEnumValN(1, "d", "Silently allow deprecated features"),
+                 clEnumValN(2, "dw",
+                            "Warn about the use of deprecated features")),
     cl::location(global.params.useDeprecated), cl::init(2));
 
 cl::opt<bool, true>
@@ -99,21 +99,19 @@ static cl::opt<unsigned, true> errorLimit(
 
 static cl::opt<ubyte, true>
     warnings(cl::desc("Warnings:"), cl::ZeroOrMore,
-             cl::values(clEnumValN(1, "w", "Enable warnings"),
-                        clEnumValN(2, "wi", "Enable informational warnings"),
-                        clEnumValEnd),
+             clEnumValues(clEnumValN(1, "w", "Enable warnings"),
+                          clEnumValN(2, "wi", "Enable informational warnings")),
              cl::location(global.params.warnings), cl::init(0));
 
 static cl::opt<bool, true> ignoreUnsupportedPragmas(
     "ignore", cl::desc("Ignore unsupported pragmas"), cl::ZeroOrMore,
     cl::location(global.params.ignoreUnsupportedPragmas));
 
-static cl::opt<ubyte, true>
-    debugInfo(cl::desc("Generating debug information:"), cl::ZeroOrMore,
-              cl::values(clEnumValN(1, "g", "Generate debug information"),
-                         clEnumValN(2, "gc", "Same as -g, but pretend to be C"),
-                         clEnumValEnd),
-              cl::location(global.params.symdebug), cl::init(0));
+static cl::opt<ubyte, true> debugInfo(
+    cl::desc("Generating debug information:"), cl::ZeroOrMore,
+    clEnumValues(clEnumValN(1, "g", "Generate debug information"),
+                 clEnumValN(2, "gc", "Same as -g, but pretend to be C")),
+    cl::location(global.params.symdebug), cl::init(0));
 
 cl::opt<bool> noAsm("noasm", cl::desc("Disallow use of inline assembler"));
 
@@ -277,7 +275,7 @@ cl::opt<llvm::Reloc::Model> mRelocModel(
 #if LDC_LLVM_VER < 309
     cl::init(llvm::Reloc::Default),
 #endif
-    cl::values(
+    clEnumValues(
 #if LDC_LLVM_VER < 309
         clEnumValN(llvm::Reloc::Default, "default",
                    "Target default relocation model"),
@@ -286,24 +284,22 @@ cl::opt<llvm::Reloc::Model> mRelocModel(
         clEnumValN(llvm::Reloc::PIC_, "pic",
                    "Fully relocatable, position independent code"),
         clEnumValN(llvm::Reloc::DynamicNoPIC, "dynamic-no-pic",
-                   "Relocatable external references, non-relocatable code"),
-        clEnumValEnd));
+                   "Relocatable external references, non-relocatable code")));
 
 cl::opt<llvm::CodeModel::Model> mCodeModel(
     "code-model", cl::desc("Code model"), cl::init(llvm::CodeModel::Default),
-    cl::values(
+    clEnumValues(
         clEnumValN(llvm::CodeModel::Default, "default",
                    "Target default code model"),
         clEnumValN(llvm::CodeModel::Small, "small", "Small code model"),
         clEnumValN(llvm::CodeModel::Kernel, "kernel", "Kernel code model"),
         clEnumValN(llvm::CodeModel::Medium, "medium", "Medium code model"),
-        clEnumValN(llvm::CodeModel::Large, "large", "Large code model"),
-        clEnumValEnd));
+        clEnumValN(llvm::CodeModel::Large, "large", "Large code model")));
 
 cl::opt<FloatABI::Type> mFloatABI(
     "float-abi", cl::desc("ABI/operations to use for floating-point types:"),
     cl::init(FloatABI::Default),
-    cl::values(
+    clEnumValues(
         clEnumValN(FloatABI::Default, "default",
                    "Target default floating-point ABI"),
         clEnumValN(FloatABI::Soft, "soft",
@@ -311,8 +307,7 @@ cl::opt<FloatABI::Type> mFloatABI(
         clEnumValN(FloatABI::SoftFP, "softfp",
                    "Soft-float ABI, but hardware floating-point instructions"),
         clEnumValN(FloatABI::Hard, "hard",
-                   "Hardware floating-point ABI and instructions"),
-        clEnumValEnd));
+                   "Hardware floating-point ABI and instructions")));
 
 cl::opt<bool>
     disableFpElim("disable-fp-elim",
@@ -326,12 +321,11 @@ static cl::opt<bool, true, FlagParser<bool>>
 
 cl::opt<BOUNDSCHECK> boundsCheck(
     "boundscheck", cl::desc("Enable array bounds check"),
-    cl::values(clEnumValN(BOUNDSCHECKoff, "off", "no array bounds checks"),
-               clEnumValN(BOUNDSCHECKsafeonly, "safeonly",
-                          "array bounds checks for safe functions only"),
-               clEnumValN(BOUNDSCHECKon, "on",
-                          "array bounds checks for all functions"),
-               clEnumValEnd),
+    clEnumValues(clEnumValN(BOUNDSCHECKoff, "off", "no array bounds checks"),
+                 clEnumValN(BOUNDSCHECKsafeonly, "safeonly",
+                            "array bounds checks for safe functions only"),
+                 clEnumValN(BOUNDSCHECKon, "on",
+                            "array bounds checks for all functions")),
     cl::init(BOUNDSCHECKdefault));
 
 static cl::opt<bool, true, FlagParser<bool>>
diff --git a/driver/toobj.cpp b/driver/toobj.cpp
index 16b5b97..21670b9 100644
--- a/driver/toobj.cpp
+++ b/driver/toobj.cpp
@@ -16,7 +16,11 @@
 #include "gen/programs.h"
 #include "llvm/IR/AssemblyAnnotationWriter.h"
 #include "llvm/IR/Verifier.h"
+#if LDC_LLVM_VER >= 400
+#include "llvm/Bitcode/BitcodeWriter.h"
+#else
 #include "llvm/Bitcode/ReaderWriter.h"
+#endif
 #if LDC_LLVM_VER >= 307
 #include "llvm/IR/LegacyPassManager.h"
 #else
diff --git a/gen/cl_helpers.h b/gen/cl_helpers.h
index 64e522c..77d10e3 100644
--- a/gen/cl_helpers.h
+++ b/gen/cl_helpers.h
@@ -87,7 +87,13 @@ public:
 
   // Implement virtual functions needed by generic_parser_base
   unsigned getNumOptions() const LLVM_OVERRIDE { return 1; }
-  const char *getOption(unsigned N) const LLVM_OVERRIDE {
+
+#if LDC_LLVM_VER >= 400
+  llvm::StringRef
+#else
+  const char *
+#endif
+  getOption(unsigned N) const LLVM_OVERRIDE {
     assert(N == 0);
 #if LDC_LLVM_VER >= 308
     return owner().ArgStr.data();
@@ -96,7 +102,12 @@ public:
 #endif
   }
 
-  const char *getDescription(unsigned N) const LLVM_OVERRIDE {
+#if LDC_LLVM_VER >= 400
+  llvm::StringRef
+#else
+  const char *
+#endif
+  getDescription(unsigned N) const LLVM_OVERRIDE {
     assert(N == 0);
 #if LDC_LLVM_VER >= 308
     return owner().HelpStr.data();
@@ -196,4 +207,15 @@ public:
 };
 }
 
+#if LDC_LLVM_VER >= 400
+#define clEnumValues llvm::cl::values
+#else
+template <typename DataType, typename... OptsTy>
+llvm::cl::ValuesClass<DataType> clEnumValues(const char *Arg, DataType Val,
+                                             const char *Desc,
+                                             OptsTy... Options) {
+  return llvm::cl::values(Arg, Val, Desc, Options..., clEnumValEnd);
+}
+#endif
+
 #endif
diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp
index 62af905..2b05aae 100644
--- a/gen/dibuilder.cpp
+++ b/gen/dibuilder.cpp
@@ -32,6 +32,14 @@ typedef llvm::DINode DIFlags;
 typedef llvm::DIDescriptor DIFlags;
 #endif
 
+namespace {
+#if LDC_LLVM_VER >= 400
+const auto DIFlagZero = DIFlags::FlagZero;
+#else
+const unsigned DIFlagZero = 0;
+#endif
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 // get the module the symbol is in, or - for template instances - the current
@@ -152,7 +160,9 @@ ldc::DIType ldc::DIBuilder::CreateBasicType(Type *type) {
 
   return DBuilder.createBasicType(type->toChars(),         // name
                                   getTypeAllocSize(T) * 8, // size (bits)
+#if LDC_LLVM_VER < 400
                                   getABITypeAlign(T) * 8,  // align (bits)
+#endif
                                   Encoding);
 }
 
@@ -241,7 +251,7 @@ ldc::DIType ldc::DIBuilder::CreateMemberType(unsigned linnum, Type *type,
   // find base type
   ldc::DIType basetype(CreateTypeDescription(t, true));
 
-  unsigned Flags = 0;
+  auto Flags = DIFlagZero;
   switch (prot) {
   case PROTprivate:
     Flags = DIFlags::FlagPrivate;
@@ -435,7 +445,7 @@ ldc::DIType ldc::DIBuilder::CreateArrayType(Type *type) {
       0,                 // LineNo
       getTypeAllocSize(T) * 8, // size in bits
       getABITypeAlign(T) * 8,  // alignment in bits
-      0,                       // What here?
+      DIFlagZero,              // What here?
 #if LDC_LLVM_VER >= 307
       nullptr, // DerivedFrom
 #else
@@ -605,7 +615,12 @@ void ldc::DIBuilder::EmitCompileUnit(Module *m) {
   CUNode = DBuilder.createCompileUnit(
       global.params.symdebug == 2 ? llvm::dwarf::DW_LANG_C
                                   : llvm::dwarf::DW_LANG_D,
+#if LDC_LLVM_VER >= 400
+      DBuilder.createFile(llvm::sys::path::filename(srcpath),
+                          llvm::sys::path::parent_path(srcpath)),
+#else
       llvm::sys::path::filename(srcpath), llvm::sys::path::parent_path(srcpath),
+#endif
       "LDC (http://wiki.dlang.org/LDC)",
       isOptimizationEnabled(), // isOptimized
       llvm::StringRef(),       // Flags TODO
@@ -868,7 +883,7 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
 #endif
 
   ldc::DILocalVariable debugVariable;
-  unsigned Flags = 0;
+  auto Flags = DIFlagZero;
   if (isThisPtr) {
     Flags |= DIFlags::FlagArtificial | DIFlags::FlagObjectPointer;
   }
@@ -954,16 +969,11 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
 #endif
 }
 
-ldc::DIGlobalVariable
-ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *ll,
+void
+ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *llVar,
                                    VarDeclaration *vd) {
-  if (!global.params.symdebug) {
-#if LDC_LLVM_VER >= 307
-    return nullptr;
-#else
-    return llvm::DIGlobalVariable();
-#endif
-  }
+  if (!global.params.symdebug)
+    return;
 
   Logger::println("D to dwarf global_variable");
   LOG_SCOPE;
@@ -971,7 +981,11 @@ ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *ll,
   assert(vd->isDataseg() ||
          (vd->storage_class & (STCconst | STCimmutable) && vd->init));
 
-  return DBuilder.createGlobalVariable(
+#if LDC_LLVM_VER >= 400
+  auto DIVar = DBuilder.createGlobalVariableExpression(
+#else
+  DBuilder.createGlobalVariable(
+#endif
 #if LDC_LLVM_VER >= 306
       GetCU(), // context
 #endif
@@ -981,8 +995,16 @@ ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *ll,
       vd->loc.linnum,                         // line num
       CreateTypeDescription(vd->type, false), // type
       vd->protection == PROTprivate,          // is local to unit
-      ll                                      // value
+#if LDC_LLVM_VER >= 400
+      nullptr // relative location of field
+#else
+      llVar // value
+#endif
       );
+
+#if LDC_LLVM_VER >= 400
+  llVar->addDebugInfo(DIVar);
+#endif
 }
 
 void ldc::DIBuilder::Finalize() {
diff --git a/gen/dibuilder.h b/gen/dibuilder.h
index 14fba85..fbfa830 100644
--- a/gen/dibuilder.h
+++ b/gen/dibuilder.h
@@ -146,8 +146,8 @@ public:
   /// variable vd.
   /// \param ll       LLVM global variable
   /// \param vd       Variable declaration to emit debug info for.
-  DIGlobalVariable EmitGlobalVariable(llvm::GlobalVariable *ll,
-                                      VarDeclaration *vd); // FIXME
+  void EmitGlobalVariable(llvm::GlobalVariable *llVar,
+                          VarDeclaration *vd); // FIXME
 
   void Finalize();
 
diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp
index d381225..d474f5a 100644
--- a/gen/llvmhelpers.cpp
+++ b/gen/llvmhelpers.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "gen/llvmhelpers.h"
+#include "gen/cl_helpers.h"
 #include "expression.h"
 #include "gen/abi.h"
 #include "gen/arrays.h"
@@ -44,16 +45,15 @@
 llvm::cl::opt<llvm::GlobalVariable::ThreadLocalMode> clThreadModel(
     "fthread-model", llvm::cl::desc("Thread model"),
     llvm::cl::init(llvm::GlobalVariable::GeneralDynamicTLSModel),
-    llvm::cl::values(clEnumValN(llvm::GlobalVariable::GeneralDynamicTLSModel,
-                                "global-dynamic",
-                                "Global dynamic TLS model (default)"),
-                     clEnumValN(llvm::GlobalVariable::LocalDynamicTLSModel,
-                                "local-dynamic", "Local dynamic TLS model"),
-                     clEnumValN(llvm::GlobalVariable::InitialExecTLSModel,
-                                "initial-exec", "Initial exec TLS model"),
-                     clEnumValN(llvm::GlobalVariable::LocalExecTLSModel,
-                                "local-exec", "Local exec TLS model"),
-                     clEnumValEnd));
+    clEnumValues(clEnumValN(llvm::GlobalVariable::GeneralDynamicTLSModel,
+                            "global-dynamic",
+                            "Global dynamic TLS model (default)"),
+                 clEnumValN(llvm::GlobalVariable::LocalDynamicTLSModel,
+                            "local-dynamic", "Local dynamic TLS model"),
+                 clEnumValN(llvm::GlobalVariable::InitialExecTLSModel,
+                            "initial-exec", "Initial exec TLS model"),
+                 clEnumValN(llvm::GlobalVariable::LocalExecTLSModel,
+                            "local-exec", "Local exec TLS model")));
 
 Type *getTypeInfoType(Type *t, Scope *sc);
 
@@ -1416,6 +1416,9 @@ bool isLLVMUnsigned(Type *t) { return t->isunsigned() || t->ty == Tpointer; }
 void printLabelName(std::ostream &target, const char *func_mangle,
                     const char *label_name) {
   target << gTargetMachine->getMCAsmInfo()->getPrivateGlobalPrefix()
+#if LDC_LLVM_VER >= 400
+              .str()
+#endif
          << func_mangle << "_" << label_name;
 }
 
diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp
index 531bf54..f044059 100644
--- a/gen/optimizer.cpp
+++ b/gen/optimizer.cpp
@@ -42,7 +42,7 @@ using namespace llvm;
 
 static cl::opt<signed char> optimizeLevel(
     cl::desc("Setting the optimization level:"), cl::ZeroOrMore,
-    cl::values(
+    clEnumValues(
         clEnumValN(3, "O", "Equivalent to -O3"),
         clEnumValN(0, "O0", "No optimizations (default)"),
         clEnumValN(1, "O1", "Simple optimizations"),
@@ -51,8 +51,7 @@ static cl::opt<signed char> optimizeLevel(
         clEnumValN(4, "O4", "Link-time optimization"), // Not implemented yet.
         clEnumValN(5, "O5", "Link-time optimization"), // Not implemented yet.
         clEnumValN(-1, "Os", "Like -O2 with extra optimizations for size"),
-        clEnumValN(-2, "Oz", "Like -Os but reduces code size further"),
-        clEnumValEnd),
+        clEnumValN(-2, "Oz", "Like -Os but reduces code size further")),
     cl::init(0));
 
 static cl::opt<bool> noVerify("disable-verify",
@@ -100,10 +99,10 @@ static cl::opt<bool> stripDebug(
 cl::opt<opts::SanitizerCheck> opts::sanitize(
     "sanitize", cl::desc("Enable runtime instrumentation for bug detection"),
     cl::init(opts::None),
-    cl::values(clEnumValN(opts::AddressSanitizer, "address", "memory errors"),
-               clEnumValN(opts::MemorySanitizer, "memory", "memory errors"),
-               clEnumValN(opts::ThreadSanitizer, "thread", "race detection"),
-               clEnumValEnd));
+    clEnumValues(clEnumValN(opts::AddressSanitizer, "address", "memory errors"),
+                 clEnumValN(opts::MemorySanitizer, "memory", "memory errors"),
+                 clEnumValN(opts::ThreadSanitizer, "thread",
+                            "race detection")));
 
 static cl::opt<bool> disableLoopUnrolling(
     "disable-loop-unrolling",
@@ -235,7 +234,11 @@ static void addOptimizationPasses(PassManagerBase &mpm,
     }
     builder.Inliner = createFunctionInliningPass(threshold);
   } else {
+#if LDC_LLVM_VER >= 400
+    builder.Inliner = createAlwaysInlinerLegacyPass();
+#else
     builder.Inliner = createAlwaysInlinerPass();
+#endif
   }
   builder.DisableUnitAtATime = !unitAtATime;
   builder.DisableUnrollLoops = optLevel == 0;
diff --git a/gen/runtime.cpp b/gen/runtime.cpp
index 7d10a18..4d434ff 100644
--- a/gen/runtime.cpp
+++ b/gen/runtime.cpp
@@ -25,7 +25,11 @@
 #include "module.h"
 #include "mtype.h"
 #include "root.h"
+#if LDC_LLVM_VER >= 400
+#include "llvm/Bitcode/BitcodeWriter.h"
+#else
 #include "llvm/Bitcode/ReaderWriter.h"
+#endif
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/CommandLine.h"
diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp
index d74c855..7794a12 100644
--- a/gen/tollvm.cpp
+++ b/gen/tollvm.cpp
@@ -415,6 +415,16 @@ llvm::ConstantInt *DtoConstUbyte(unsigned char i) {
 }
 
 LLConstant *DtoConstFP(Type *t, longdouble value) {
+#if LDC_LLVM_VER >= 400
+  const auto &x87DoubleExtended = llvm::APFloat::x87DoubleExtended();
+  const auto &PPCDoubleDouble = llvm::APFloat::PPCDoubleDouble();
+  const auto &IEEEquad = llvm::APFloat::IEEEquad();
+#else
+  const auto &x87DoubleExtended = llvm::APFloat::x87DoubleExtended;
+  const auto &PPCDoubleDouble = llvm::APFloat::PPCDoubleDouble;
+  const auto &IEEEquad = llvm::APFloat::IEEEquad;
+#endif
+
   LLType *llty = DtoType(t);
   assert(llty->isFloatingPointTy());
 
@@ -427,7 +437,7 @@ LLConstant *DtoConstFP(Type *t, longdouble value) {
     bits[0] = *reinterpret_cast<uint64_t *>(&value);
     bits[1] =
         *reinterpret_cast<uint16_t *>(reinterpret_cast<uint64_t *>(&value) + 1);
-    return LLConstantFP::get(gIR->context(), APFloat(APFloat::x87DoubleExtended,
+    return LLConstantFP::get(gIR->context(), APFloat(x87DoubleExtended,
                                                      APInt(80, 2, bits)));
   }
   if (llty == LLType::getFP128Ty(gIR->context())) {
@@ -437,7 +447,7 @@ LLConstant *DtoConstFP(Type *t, longdouble value) {
     } t;
     t.ld = value;
     return LLConstantFP::get(gIR->context(),
-                             APFloat(APFloat::IEEEquad, APInt(128, 2, t.bits)));
+                             APFloat(IEEEquad, APInt(128, 2, t.bits)));
   }
   if (llty == LLType::getPPC_FP128Ty(gIR->context())) {
     uint64_t bits[] = {0, 0};
@@ -445,7 +455,7 @@ LLConstant *DtoConstFP(Type *t, longdouble value) {
     bits[1] =
         *reinterpret_cast<uint16_t *>(reinterpret_cast<uint64_t *>(&value) + 1);
     return LLConstantFP::get(
-        gIR->context(), APFloat(APFloat::PPCDoubleDouble, APInt(128, 2, bits)));
+        gIR->context(), APFloat(PPCDoubleDouble, APInt(128, 2, bits)));
   }
 
   llvm_unreachable("Unknown floating point type encountered");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list