Drop support for LLVM < 3.7

This commit is contained in:
Martin 2017-07-16 02:08:06 +02:00
parent 4e174ff19c
commit 1fb269f940
72 changed files with 98 additions and 3862 deletions

View file

@ -6,22 +6,16 @@ matrix:
include: include:
- os: linux - os: linux
d: ldc d: ldc
env: LLVM_VERSION=4.0.1 env: LLVM_VERSION=4.0.1 OPTS="-DLIB_SUFFIX=64"
- os: linux - os: linux
d: ldc-beta d: ldc-beta
env: LLVM_VERSION=3.9.1 OPTS="-DLIB_SUFFIX=64" env: LLVM_VERSION=3.9.1 OPTS="-DBUILD_SHARED_LIBS=ON"
- os: linux
d: ldc
env: LLVM_VERSION=3.8.1 OPTS="-DBUILD_SHARED_LIBS=ON"
- os: linux
d: ldc
env: LLVM_VERSION=3.7.1 OPTS="-DBUILD_SHARED_LIBS=OFF -DLIB_SUFFIX=64"
- os: linux - os: linux
d: ldc-0.17.2 d: ldc-0.17.2
env: LLVM_VERSION=3.6.2 env: LLVM_VERSION=3.8.1 OPTS="-DBUILD_SHARED_LIBS=OFF -DLIB_SUFFIX=64"
- os: linux - os: linux
d: dmd d: dmd
env: LLVM_VERSION=3.5.2 OPTS="-DTEST_COVERAGE=ON" env: LLVM_VERSION=3.7.1 OPTS="-DTEST_COVERAGE=ON"
- os: osx - os: osx
d: ldc-beta d: ldc-beta
env: LLVM_VERSION=5.0.0-3 OPTS="-DBUILD_SHARED_LIBS=OFF" LLVM_SPIRV_AVAILABLE=ON env: LLVM_VERSION=5.0.0-3 OPTS="-DBUILD_SHARED_LIBS=OFF" LLVM_SPIRV_AVAILABLE=ON
@ -39,8 +33,6 @@ cache:
- llvm-3.9.1 - llvm-3.9.1
- llvm-3.8.1 - llvm-3.8.1
- llvm-3.7.1 - llvm-3.7.1
- llvm-3.6.2
- llvm-3.5.2
addons: addons:
apt: apt:
sources: sources:

View file

@ -19,7 +19,7 @@ endif()
# Locate LLVM. # Locate LLVM.
# #
find_package(LLVM 3.5 REQUIRED find_package(LLVM 3.7 REQUIRED
all-targets analysis asmparser asmprinter bitreader bitwriter codegen core debuginfocodeview debuginfodwarf debuginfomsf debuginfopdb globalisel instcombine ipa ipo instrumentation irreader libdriver linker lto mc mcdisassembler mcparser objcarcopts object option profiledata scalaropts selectiondag support tablegen target transformutils vectorize ${EXTRA_LLVM_MODULES}) all-targets analysis asmparser asmprinter bitreader bitwriter codegen core debuginfocodeview debuginfodwarf debuginfomsf debuginfopdb globalisel instcombine ipa ipo instrumentation irreader libdriver linker lto mc mcdisassembler mcparser objcarcopts object option profiledata scalaropts selectiondag support tablegen target transformutils vectorize ${EXTRA_LLVM_MODULES})
math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR}) math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR})
# Remove LLVMTableGen library from list of libraries # Remove LLVMTableGen library from list of libraries
@ -405,15 +405,11 @@ source_group("Generated Files" REGULAR_EXPRESSION "(id\\.[cdh]|impcnvtab\\.c)$")
include(HandleLTOPGOBuildOptions) include(HandleLTOPGOBuildOptions)
# #
# Enable PGO if supported for this platform and LLVM version. # Enable PGO if supported for this platform.
# LLVM >= 3.7 is required for PGO.
# #
set(LDC_WITH_PGO False) # must be a valid Python boolean constant (case sensitive) set(LDC_WITH_PGO True) # must be a valid Python boolean constant (case sensitive)
if (NOT (LDC_LLVM_VER LESS 307)) message(STATUS "Building LDC with PGO support")
message(STATUS "Building LDC with PGO support") append("-DLDC_WITH_PGO" LDC_CXXFLAGS)
append("-DLDC_WITH_PGO" LDC_CXXFLAGS)
set(LDC_WITH_PGO True)
endif()
# #
# Includes, defines. # Includes, defines.

View file

@ -64,7 +64,7 @@ libraries is available on the project wiki for
[Linux and OS X](http://wiki.dlang.org/Building_LDC_from_source) and [Linux and OS X](http://wiki.dlang.org/Building_LDC_from_source) and
[Windows](http://wiki.dlang.org/Building_and_hacking_LDC_on_Windows_using_MSVC). [Windows](http://wiki.dlang.org/Building_and_hacking_LDC_on_Windows_using_MSVC).
If you have a working C++ build environment, CMake, and a current LLVM (≥ 3.5) If you have a working C++ build environment, CMake, and a current LLVM (≥ 3.7)
available, there should be no big surprises. available, there should be no big surprises.
Building LDC also requires a working D compiler, DMD and LDC are supported. Building LDC also requires a working D compiler, DMD and LDC are supported.
(LDC 0.17 is the last version that does not need a D compiler, (LDC 0.17 is the last version that does not need a D compiler,

View file

@ -32,8 +32,6 @@ set(llvm_config_names llvm-config-5.0 llvm-config50
llvm-config-3.9 llvm-config39 llvm-config-3.9 llvm-config39
llvm-config-3.8 llvm-config38 llvm-config-3.8 llvm-config38
llvm-config-3.7 llvm-config37 llvm-config-3.7 llvm-config37
llvm-config-3.6 llvm-config36
llvm-config-3.5 llvm-config35
llvm-config) llvm-config)
find_program(LLVM_CONFIG find_program(LLVM_CONFIG
NAMES ${llvm_config_names} NAMES ${llvm_config_names}
@ -85,13 +83,6 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
if(TARGET_AMDGPU GREATER -1) if(TARGET_AMDGPU GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS AMDGPUUtils) list(APPEND LLVM_FIND_COMPONENTS AMDGPUUtils)
endif() endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support components debuginfo[dwarf|pdb]
# Only debuginfo is available
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfopdb" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*") if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*")
# Versions below 3.9 do not support components debuginfocodeview, globalisel # Versions below 3.9 do not support components debuginfocodeview, globalisel
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index) list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
@ -105,10 +96,6 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
# Versions below 4.0 do not support component debuginfomsf # Versions below 4.0 do not support component debuginfomsf
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index) list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
endif() endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support component libdriver
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "libdriver" index)
endif()
llvm_map_components_to_libnames(tmplibs ${LLVM_FIND_COMPONENTS}) llvm_map_components_to_libnames(tmplibs ${LLVM_FIND_COMPONENTS})
if(MSVC) if(MSVC)
@ -182,13 +169,6 @@ else()
llvm_set(ROOT_DIR prefix true) llvm_set(ROOT_DIR prefix true)
llvm_set(ENABLE_ASSERTIONS assertion-mode) llvm_set(ENABLE_ASSERTIONS assertion-mode)
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support components debuginfo[dwarf|pdb]
# Only debuginfo is available
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfopdb" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*") if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-8][\\.0-9A-Za-z]*")
# Versions below 3.9 do not support components debuginfocodeview, globalisel # Versions below 3.9 do not support components debuginfocodeview, globalisel
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index) list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
@ -202,18 +182,12 @@ else()
# Versions below 4.0 do not support component debuginfomsf # Versions below 4.0 do not support component debuginfomsf
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index) list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
endif() endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-6][\\.0-9A-Za-z]*")
# Versions below 3.7 do not support component libdriver
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "libdriver" index)
endif()
llvm_set(LDFLAGS ldflags) llvm_set(LDFLAGS ldflags)
if(NOT ${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*") # In LLVM 3.5+, the system library dependencies (e.g. "-lz") are accessed
# In LLVM 3.5+, the system library dependencies (e.g. "-lz") are accessed # using the separate "--system-libs" flag.
# using the separate "--system-libs" flag. llvm_set(SYSTEM_LIBS system-libs)
llvm_set(SYSTEM_LIBS system-libs) string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")
string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")
endif()
llvm_set(LIBRARY_DIRS libdir true) llvm_set(LIBRARY_DIRS libdir true)
llvm_set_libs(LIBRARIES libs) llvm_set_libs(LIBRARIES libs)
# LLVM bug: llvm-config --libs tablegen returns -lLLVM-3.8.0 # LLVM bug: llvm-config --libs tablegen returns -lLLVM-3.8.0

View file

@ -28,8 +28,6 @@ void recoverObjectFile(llvm::StringRef cacheObjectHash,
llvm::StringRef objectFile); llvm::StringRef objectFile);
/// Prune the cache to avoid filling up disk space. /// Prune the cache to avoid filling up disk space.
///
/// Note: Does nothing for LLVM < 3.7.
void pruneCache(); void pruneCache();
} }

View file

@ -27,9 +27,7 @@ llvm::SmallVector<const char *, 32> allArguments;
* -cov=101 --> error, value must be in range [0..100] * -cov=101 --> error, value must be in range [0..100]
*/ */
struct CoverageParser : public cl::parser<unsigned char> { struct CoverageParser : public cl::parser<unsigned char> {
#if LDC_LLVM_VER >= 307
explicit CoverageParser(cl::Option &O) : cl::parser<unsigned char>(O) {} explicit CoverageParser(cl::Option &O) : cl::parser<unsigned char>(O) {}
#endif
bool parse(cl::Option &O, llvm::StringRef /*ArgName*/, llvm::StringRef Arg, bool parse(cl::Option &O, llvm::StringRef /*ArgName*/, llvm::StringRef Arg,
unsigned char &Val) { unsigned char &Val) {
@ -312,11 +310,9 @@ cl::list<std::string>
cl::opt<std::string> mTargetTriple("mtriple", cl::ZeroOrMore, cl::opt<std::string> mTargetTriple("mtriple", cl::ZeroOrMore,
cl::desc("Override target triple")); cl::desc("Override target triple"));
#if LDC_LLVM_VER >= 307
cl::opt<std::string> cl::opt<std::string>
mABI("mabi", cl::ZeroOrMore, cl::Hidden, cl::init(""), mABI("mabi", cl::ZeroOrMore, cl::Hidden, cl::init(""),
cl::desc("The name of the ABI to be targeted from the backend")); cl::desc("The name of the ABI to be targeted from the backend"));
#endif
static StringsAdapter static StringsAdapter
modFileAliasStringsStore("mv", global.params.modFileAliasStrings); modFileAliasStringsStore("mv", global.params.modFileAliasStrings);
@ -532,12 +528,7 @@ static cl::extrahelp footer(
/// The clashing LLVM options are suffixed with "llvm-" and hidden from the /// The clashing LLVM options are suffixed with "llvm-" and hidden from the
/// -help output. /// -help output.
void createClashingOptions() { void createClashingOptions() {
#if LDC_LLVM_VER >= 307
llvm::StringMap<cl::Option *> &map = cl::getRegisteredOptions(); llvm::StringMap<cl::Option *> &map = cl::getRegisteredOptions();
#else
llvm::StringMap<cl::Option *> map;
cl::getRegisteredOptions(map);
#endif
auto renameAndHide = [&map](const char *from, const char *to) { auto renameAndHide = [&map](const char *from, const char *to) {
auto i = map.find(from); auto i = map.find(from);
@ -605,13 +596,7 @@ void hideLLVMOptions() {
// line has been parsed). // line has been parsed).
"fdata-sections", "ffunction-sections"}; "fdata-sections", "ffunction-sections"};
#if LDC_LLVM_VER >= 307
llvm::StringMap<cl::Option *> &map = cl::getRegisteredOptions(); llvm::StringMap<cl::Option *> &map = cl::getRegisteredOptions();
#else
llvm::StringMap<cl::Option *> map;
cl::getRegisteredOptions(map);
#endif
for (const auto name : hiddenOptions) { for (const auto name : hiddenOptions) {
// Check if option exists first for resilience against LLVM changes // Check if option exists first for resilience against LLVM changes
// between versions. // between versions.

View file

@ -75,9 +75,7 @@ extern cl::opt<bool> m64bits;
extern cl::opt<std::string> mCPU; extern cl::opt<std::string> mCPU;
extern cl::list<std::string> mAttrs; extern cl::list<std::string> mAttrs;
extern cl::opt<std::string> mTargetTriple; extern cl::opt<std::string> mTargetTriple;
#if LDC_LLVM_VER >= 307
extern cl::opt<std::string> mABI; extern cl::opt<std::string> mABI;
#endif
extern cl::opt<llvm::Reloc::Model> mRelocModel; extern cl::opt<llvm::Reloc::Model> mRelocModel;
extern cl::opt<llvm::CodeModel::Model> mCodeModel; extern cl::opt<llvm::CodeModel::Model> mCodeModel;
extern cl::opt<bool> disableFpElim; extern cl::opt<bool> disableFpElim;

View file

@ -89,11 +89,6 @@ void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
// Merge the Linker Options with the pre-existing one // Merge the Linker Options with the pre-existing one
// (this can happen when passing a .bc file on the commandline) // (this can happen when passing a .bc file on the commandline)
#if LDC_LLVM_VER < 306
// Passing a bitcode file on the commandline is not supported for LLVM 3.5.
llvm_unreachable(
"Merging of Linker Options is not implemented for LLVM 3.5");
#else
auto *moduleFlags = M.getModuleFlagsMetadata(); auto *moduleFlags = M.getModuleFlagsMetadata();
for (unsigned i = 0, e = moduleFlags->getNumOperands(); i < e; ++i) { for (unsigned i = 0, e = moduleFlags->getNumOperands(); i < e; ++i) {
auto *flag = moduleFlags->getOperand(i); auto *flag = moduleFlags->getOperand(i);
@ -122,7 +117,6 @@ void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
break; break;
} }
#endif
} }
} }
#else #else
@ -261,12 +255,7 @@ void CodeGenerator::writeAndFreeLLModule(const char *filename) {
ir_->module.getOrInsertNamedMetadata("llvm.ident"); ir_->module.getOrInsertNamedMetadata("llvm.ident");
std::string Version("ldc version "); std::string Version("ldc version ");
Version.append(global.ldc_version); Version.append(global.ldc_version);
#if LDC_LLVM_VER >= 306 llvm::Metadata *IdentNode[] = {llvm::MDString::get(ir_->context(), Version)};
llvm::Metadata *IdentNode[] =
#else
llvm::Value *IdentNode[] =
#endif
{llvm::MDString::get(ir_->context(), Version)};
IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode)); IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode));
std::unique_ptr<llvm::tool_output_file> diagnosticsOutputFile = std::unique_ptr<llvm::tool_output_file> diagnosticsOutputFile =

View file

@ -656,12 +656,8 @@ std::string locateBinary(std::string exeName) {
return path; return path;
} }
#if LDC_LLVM_VER >= 306
llvm::ErrorOr<std::string> res = ls::findProgramByName(exeName); llvm::ErrorOr<std::string> res = ls::findProgramByName(exeName);
path = res ? res.get() : std::string(); path = res ? res.get() : std::string();
#else
path = ls::FindProgramByName(exeName);
#endif
if (ls::fs::can_execute(path)) { if (ls::fs::can_execute(path)) {
return path; return path;
} }

View file

@ -429,10 +429,6 @@ void ArgsBuilder::addArch() {
case llvm::Triple::armeb: case llvm::Triple::armeb:
case llvm::Triple::aarch64: case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be: case llvm::Triple::aarch64_be:
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
case llvm::Triple::arm64_be:
#endif
break; break;
default: default:
if (global.params.is64bit) { if (global.params.is64bit) {

View file

@ -91,7 +91,6 @@ static std::string getOutputName() {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#if LDC_LLVM_VER >= 306
/// Insert an LLVM bitcode file into the module /// Insert an LLVM bitcode file into the module
static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M, static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
llvm::LLVMContext &Context) { llvm::LLVMContext &Context) {
@ -110,22 +109,13 @@ static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
llvm::Linker(&M).linkInModule(loadedModule.release()); llvm::Linker(&M).linkInModule(loadedModule.release());
#endif #endif
} }
#endif // LDC_LLVM_VER >= 306
/// Insert LLVM bitcode files into the module /// Insert LLVM bitcode files into the module
void insertBitcodeFiles(llvm::Module &M, llvm::LLVMContext &Ctx, void insertBitcodeFiles(llvm::Module &M, llvm::LLVMContext &Ctx,
Array<const char *> &bitcodeFiles) { Array<const char *> &bitcodeFiles) {
#if LDC_LLVM_VER >= 306
for (const char *fname : bitcodeFiles) { for (const char *fname : bitcodeFiles) {
insertBitcodeIntoModule(fname, M, Ctx); insertBitcodeIntoModule(fname, M, Ctx);
} }
#else
if (!bitcodeFiles.empty()) {
error(Loc(),
"Passing LLVM bitcode files to LDC is not supported for LLVM < 3.6");
fatal();
}
#endif
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View file

@ -56,9 +56,7 @@
#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h" #include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 306
#include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Target/TargetSubtargetInfo.h"
#endif
#include "llvm/LinkAllIR.h" #include "llvm/LinkAllIR.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include <assert.h> #include <assert.h>
@ -638,20 +636,15 @@ void initializePasses() {
initializeTarget(Registry); initializeTarget(Registry);
// Initialize passes not included above // Initialize passes not included above
#if LDC_LLVM_VER < 306
initializeDebugIRPass(Registry);
#endif
#if LDC_LLVM_VER < 308 #if LDC_LLVM_VER < 308
initializeIPA(Registry); initializeIPA(Registry);
#endif #endif
#if LDC_LLVM_VER >= 400 #if LDC_LLVM_VER >= 400
initializeRewriteSymbolsLegacyPassPass(Registry); initializeRewriteSymbolsLegacyPassPass(Registry);
#elif LDC_LLVM_VER >= 306 #else
initializeRewriteSymbolsPass(Registry); initializeRewriteSymbolsPass(Registry);
#endif #endif
#if LDC_LLVM_VER >= 307
initializeSjLjEHPreparePass(Registry); initializeSjLjEHPreparePass(Registry);
#endif
} }
/// Register the MIPS ABI. /// Register the MIPS ABI.
@ -678,13 +671,9 @@ static void registerMipsABI() {
/// Also defines D_HardFloat or D_SoftFloat depending if FPU should be used /// Also defines D_HardFloat or D_SoftFloat depending if FPU should be used
void registerPredefinedFloatABI(const char *soft, const char *hard, void registerPredefinedFloatABI(const char *soft, const char *hard,
const char *softfp = nullptr) { const char *softfp = nullptr) {
// Use target floating point unit instead of s/w float routines // Use target floating point unit instead of s/w float routines
#if LDC_LLVM_VER >= 307
// FIXME: This is a semantic change! // FIXME: This is a semantic change!
bool useFPU = gTargetMachine->Options.FloatABIType == llvm::FloatABI::Hard; bool useFPU = gTargetMachine->Options.FloatABIType == llvm::FloatABI::Hard;
#else
bool useFPU = !gTargetMachine->Options.UseSoftFloat;
#endif
VersionCondition::addPredefinedGlobalIdent(useFPU ? "D_HardFloat" VersionCondition::addPredefinedGlobalIdent(useFPU ? "D_HardFloat"
: "D_SoftFloat"); : "D_SoftFloat");
@ -746,10 +735,6 @@ void registerPredefinedTargetVersions() {
VersionCondition::addPredefinedGlobalIdent("ARM_Thumb"); VersionCondition::addPredefinedGlobalIdent("ARM_Thumb");
registerPredefinedFloatABI("ARM_SoftFloat", "ARM_HardFloat", "ARM_SoftFP"); registerPredefinedFloatABI("ARM_SoftFloat", "ARM_HardFloat", "ARM_SoftFP");
break; break;
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
case llvm::Triple::arm64_be:
#endif
case llvm::Triple::aarch64: case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be: case llvm::Triple::aarch64_be:
VersionCondition::addPredefinedGlobalIdent("AArch64"); VersionCondition::addPredefinedGlobalIdent("AArch64");
@ -1046,10 +1031,6 @@ int cppmain(int argc, char **argv) {
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308
static llvm::DataLayout DL = gTargetMachine->createDataLayout(); static llvm::DataLayout DL = gTargetMachine->createDataLayout();
gDataLayout = &DL; gDataLayout = &DL;
#elif LDC_LLVM_VER >= 307
gDataLayout = gTargetMachine->getDataLayout();
#elif LDC_LLVM_VER >= 306
gDataLayout = gTargetMachine->getSubtargetImpl()->getDataLayout();
#else #else
gDataLayout = gTargetMachine->getDataLayout(); gDataLayout = gTargetMachine->getDataLayout();
#endif #endif

View file

@ -13,12 +13,14 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "driver/cl_options.h"
#include "driver/targetmachine.h" #include "driver/targetmachine.h"
#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/MC/SubtargetFeature.h" #include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/Host.h" #include "llvm/Support/Host.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/TargetParser.h"
#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h" #include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
@ -27,10 +29,6 @@
#include "mars.h" #include "mars.h"
#include "gen/logger.h" #include "gen/logger.h"
#if LDC_LLVM_VER >= 307
#include "driver/cl_options.h"
#include "llvm/Support/TargetParser.h"
static const char *getABI(const llvm::Triple &triple) { static const char *getABI(const llvm::Triple &triple) {
llvm::StringRef ABIName(opts::mABI); llvm::StringRef ABIName(opts::mABI);
if (ABIName != "") { if (ABIName != "") {
@ -81,12 +79,10 @@ static const char *getABI(const llvm::Triple &triple) {
return ""; return "";
} }
} }
#endif
extern llvm::TargetMachine *gTargetMachine; extern llvm::TargetMachine *gTargetMachine;
MipsABI::Type getMipsABI() { MipsABI::Type getMipsABI() {
#if LDC_LLVM_VER >= 307
// eabi can only be set on the commandline // eabi can only be set on the commandline
if (strncmp(opts::mABI.c_str(), "eabi", 4) == 0) if (strncmp(opts::mABI.c_str(), "eabi", 4) == 0)
return MipsABI::EABI; return MipsABI::EABI;
@ -106,22 +102,6 @@ MipsABI::Type getMipsABI() {
const auto largestInt = dl.getLargestLegalIntTypeSize(); const auto largestInt = dl.getLargestLegalIntTypeSize();
#endif #endif
return (largestInt == 64) ? MipsABI::N32 : MipsABI::O32; return (largestInt == 64) ? MipsABI::N32 : MipsABI::O32;
#else // LDC_LLVM_VER < 307
llvm::StringRef features = gTargetMachine->getTargetFeatureString();
if (features.find("+o32") != std::string::npos) {
return MipsABI::O32;
}
if (features.find("+n32") != std::string::npos) {
return MipsABI::N32;
}
if (features.find("+n64") != std::string::npos) {
return MipsABI::N32;
}
if (features.find("+eabi") != std::string::npos) {
return MipsABI::EABI;
}
return MipsABI::Unknown;
#endif
} }
static std::string getX86TargetCPU(const llvm::Triple &triple) { static std::string getX86TargetCPU(const llvm::Triple &triple) {
@ -246,10 +226,6 @@ static std::string getTargetCPU(const std::string &cpu,
case llvm::Triple::armeb: case llvm::Triple::armeb:
case llvm::Triple::thumb: case llvm::Triple::thumb:
return getARMTargetCPU(triple); return getARMTargetCPU(triple);
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
case llvm::Triple::arm64_be:
#endif
case llvm::Triple::aarch64: case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be: case llvm::Triple::aarch64_be:
return getAArch64TargetCPU(triple); return getAArch64TargetCPU(triple);
@ -329,67 +305,6 @@ static FloatABI::Type getARMFloatABI(const llvm::Triple &triple,
} }
} }
#if LDC_LLVM_VER < 307
/// Sanitizes the MIPS ABI in the feature string.
static void addMipsABI(const llvm::Triple &triple,
std::vector<std::string> &attrs) {
enum ABI { O32 = 1 << 0, N32 = 1 << 1, N64 = 1 << 2, EABI = 1 << 3 };
const bool is64Bit = triple.getArch() == llvm::Triple::mips64 ||
triple.getArch() == llvm::Triple::mips64el;
const uint32_t defaultABI = is64Bit ? N64 : O32;
uint32_t bits = defaultABI;
auto I = attrs.begin();
while (I != attrs.end()) {
std::string str = *I;
bool enabled = str[0] == '+';
std::string flag = (str[0] == '+' || str[0] == '-') ? str.substr(1) : str;
uint32_t newBit = 0;
if (flag == "o32") {
newBit = O32;
}
if (flag == "n32") {
newBit = N32;
}
if (flag == "n64") {
newBit = N64;
}
if (flag == "eabi") {
newBit = EABI;
}
if (newBit) {
I = attrs.erase(I);
if (enabled) {
bits |= newBit;
} else {
bits &= ~newBit;
}
} else {
++I;
}
}
switch (bits) {
case O32:
attrs.push_back("+o32");
break;
case N32:
attrs.push_back("+n32");
break;
case N64:
attrs.push_back("+n64");
break;
case EABI:
attrs.push_back("+eabi");
break;
default:
error(Loc(), "Only one ABI argument is supported");
fatal();
}
if (bits != defaultABI) {
attrs.push_back(is64Bit ? "-n64" : "-o32");
}
}
#endif
/// Looks up a target based on an arch name and a target triple. /// Looks up a target based on an arch name and a target triple.
/// ///
/// If the arch name is non-empty, then the lookup is done by arch. Otherwise, /// If the arch name is non-empty, then the lookup is done by arch. Otherwise,
@ -405,14 +320,7 @@ const llvm::Target *lookupTarget(const std::string &arch, llvm::Triple &triple,
// name, because it might be a backend that has no mapping to a target triple. // name, because it might be a backend that has no mapping to a target triple.
const llvm::Target *target = nullptr; const llvm::Target *target = nullptr;
if (!arch.empty()) { if (!arch.empty()) {
#if LDC_LLVM_VER >= 307
for (const llvm::Target &T : llvm::TargetRegistry::targets()) { for (const llvm::Target &T : llvm::TargetRegistry::targets()) {
#else
for (auto it = llvm::TargetRegistry::begin(),
ie = llvm::TargetRegistry::end();
it != ie; ++it) {
const llvm::Target &T = *it;
#endif
if (arch == T.getName()) { if (arch == T.getName()) {
target = &T; target = &T;
break; break;
@ -502,14 +410,6 @@ createTargetMachine(std::string targetTriple, std::string arch, std::string cpu,
} }
} }
} }
#if LDC_LLVM_VER < 307
if (triple.getArch() == llvm::Triple::mips ||
triple.getArch() == llvm::Triple::mipsel ||
triple.getArch() == llvm::Triple::mips64 ||
triple.getArch() == llvm::Triple::mips64el) {
addMipsABI(triple, attrs);
}
#endif
for (auto &attr : attrs) { for (auto &attr : attrs) {
features.AddFeature(attr); features.AddFeature(attr);
} }
@ -586,34 +486,19 @@ createTargetMachine(std::string targetTriple, std::string arch, std::string cpu,
} }
llvm::TargetOptions targetOptions; llvm::TargetOptions targetOptions;
#if LDC_LLVM_VER < 307
targetOptions.NoFramePointerElim = noFramePointerElim;
#endif
#if LDC_LLVM_VER >= 307
targetOptions.MCOptions.ABIName = getABI(triple); targetOptions.MCOptions.ABIName = getABI(triple);
#endif
switch (floatABI) { switch (floatABI) {
default: default:
llvm_unreachable("Floating point ABI type unknown."); llvm_unreachable("Floating point ABI type unknown.");
case FloatABI::Soft: case FloatABI::Soft:
#if LDC_LLVM_VER < 307
targetOptions.UseSoftFloat = true;
#else
features.AddFeature("+soft-float"); features.AddFeature("+soft-float");
#endif
targetOptions.FloatABIType = llvm::FloatABI::Soft; targetOptions.FloatABIType = llvm::FloatABI::Soft;
break; break;
case FloatABI::SoftFP: case FloatABI::SoftFP:
#if LDC_LLVM_VER < 307
targetOptions.UseSoftFloat = false;
#endif
targetOptions.FloatABIType = llvm::FloatABI::Soft; targetOptions.FloatABIType = llvm::FloatABI::Soft;
break; break;
case FloatABI::Hard: case FloatABI::Hard:
#if LDC_LLVM_VER < 307
targetOptions.UseSoftFloat = false;
#endif
targetOptions.FloatABIType = llvm::FloatABI::Hard; targetOptions.FloatABIType = llvm::FloatABI::Hard;
break; break;
} }

View file

@ -27,40 +27,22 @@
#else #else
#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/ReaderWriter.h"
#endif #endif
#if LDC_LLVM_VER >= 307
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
#else
#include "llvm/PassManager.h"
#endif
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Program.h" #include "llvm/Support/Program.h"
#if LDC_LLVM_VER >= 307
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
#endif
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV #ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
#include "llvm/Support/SPIRV.h" #include "llvm/Support/SPIRV.h"
#endif #endif
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/TargetTransformInfo.h"
#endif
#if LDC_LLVM_VER >= 306
#include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Target/TargetSubtargetInfo.h"
#endif
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include <cstddef> #include <cstddef>
#include <fstream> #include <fstream>
#if LDC_LLVM_VER >= 306
using LLErrorInfo = std::error_code;
#define ERRORINFO_STRING(errinfo) errinfo.message().c_str()
#else
using LLErrorInfo = std::string;
#define ERRORINFO_STRING(errinfo) errinfo.c_str()
#endif
static llvm::cl::opt<bool> static llvm::cl::opt<bool>
NoIntegratedAssembler("no-integrated-as", llvm::cl::ZeroOrMore, NoIntegratedAssembler("no-integrated-as", llvm::cl::ZeroOrMore,
llvm::cl::Hidden, llvm::cl::Hidden,
@ -74,10 +56,7 @@ static void codegenModule(llvm::TargetMachine &Target, llvm::Module &m,
// Create a PassManager to hold and optimize the collection of passes we are // Create a PassManager to hold and optimize the collection of passes we are
// about to build. // about to build.
#if LDC_LLVM_VER >= 307 legacy::PassManager Passes;
legacy::
#endif
PassManager Passes;
ComputeBackend::Type cb = getComputeTargetType(&m); ComputeBackend::Type cb = getComputeTargetType(&m);
if (cb == ComputeBackend::SPIRV) { if (cb == ComputeBackend::SPIRV) {
@ -91,37 +70,18 @@ static void codegenModule(llvm::TargetMachine &Target, llvm::Module &m,
return; return;
} }
#if LDC_LLVM_VER >= 307
// The DataLayout is already set at the module (in module.cpp,
// method Module::genLLVMModule())
// FIXME: Introduce new command line switch default-data-layout to
// override the module data layout
#elif LDC_LLVM_VER == 306
Passes.add(new DataLayoutPass());
#else
if (const DataLayout *DL = Target.getDataLayout())
Passes.add(new DataLayoutPass(*DL));
else
Passes.add(new DataLayoutPass(&m));
#endif
#if LDC_LLVM_VER >= 307 // The DataLayout is already set at the module (in module.cpp,
// method Module::genLLVMModule())
// FIXME: Introduce new command line switch default-data-layout to
// override the module data layout
// Add internal analysis passes from the target machine. // Add internal analysis passes from the target machine.
Passes.add( Passes.add(
createTargetTransformInfoWrapperPass(Target.getTargetIRAnalysis())); createTargetTransformInfoWrapperPass(Target.getTargetIRAnalysis()));
#else
Target.addAnalysisPasses(Passes);
#endif
#if LDC_LLVM_VER < 307
llvm::formatted_raw_ostream fout(out);
#endif
if (Target.addPassesToEmitFile(Passes, if (Target.addPassesToEmitFile(Passes,
#if LDC_LLVM_VER >= 307
out, out,
#else
fout,
#endif
// Always generate assembly for ptx as it is an assembly format // Always generate assembly for ptx as it is an assembly format
// The PTX backend fails if we pass anything else. // The PTX backend fails if we pass anything else.
(cb == ComputeBackend::NVPTX) ? llvm::TargetMachine::CGFT_AssemblyFile (cb == ComputeBackend::NVPTX) ? llvm::TargetMachine::CGFT_AssemblyFile
@ -196,62 +156,32 @@ namespace {
using namespace llvm; using namespace llvm;
static void printDebugLoc(const DebugLoc &debugLoc, formatted_raw_ostream &os) { static void printDebugLoc(const DebugLoc &debugLoc, formatted_raw_ostream &os) {
os << debugLoc.getLine() << ":" << debugLoc.getCol(); os << debugLoc.getLine() << ":" << debugLoc.getCol();
#if LDC_LLVM_VER >= 307
if (DILocation *IDL = debugLoc.getInlinedAt()) { if (DILocation *IDL = debugLoc.getInlinedAt()) {
os << "@"; os << "@";
printDebugLoc(IDL, os); printDebugLoc(IDL, os);
} }
#else
if (MDNode *N = debugLoc.getInlinedAt(getGlobalContext())) {
DebugLoc IDL = DebugLoc::getFromDILocation(N);
if (!IDL.isUnknown()) {
os << "@";
printDebugLoc(IDL, os);
}
}
#endif
} }
class AssemblyAnnotator : public AssemblyAnnotationWriter { class AssemblyAnnotator : public AssemblyAnnotationWriter {
// Find the MDNode which corresponds to the DISubprogram data that described F. // Find the MDNode which corresponds to the DISubprogram data that described F.
#if LDC_LLVM_VER >= 307
static DISubprogram *FindSubprogram(const Function *F, static DISubprogram *FindSubprogram(const Function *F,
DebugInfoFinder &Finder) DebugInfoFinder &Finder)
#else
static MDNode *FindSubprogram(const Function *F, DebugInfoFinder &Finder)
#endif
{ {
#if LDC_LLVM_VER >= 307
for (DISubprogram *Subprogram : Finder.subprograms()) for (DISubprogram *Subprogram : Finder.subprograms())
if (Subprogram->describes(F)) if (Subprogram->describes(F))
return Subprogram; return Subprogram;
return nullptr; return nullptr;
#else
for (DISubprogram Subprogram : Finder.subprograms()) {
if (Subprogram.describes(F)) {
return Subprogram;
}
}
return nullptr;
#endif
} }
static llvm::StringRef GetDisplayName(const Function *F) { static llvm::StringRef GetDisplayName(const Function *F) {
llvm::DebugInfoFinder Finder; llvm::DebugInfoFinder Finder;
Finder.processModule(*F->getParent()); Finder.processModule(*F->getParent());
#if LDC_LLVM_VER >= 307
if (DISubprogram *N = FindSubprogram(F, Finder)) if (DISubprogram *N = FindSubprogram(F, Finder))
#else
if (MDNode *N = FindSubprogram(F, Finder))
#endif
{ {
#if LDC_LLVM_VER >= 500 #if LDC_LLVM_VER >= 500
return N->getName(); return N->getName();
#elif LDC_LLVM_VER >= 307
return N->getDisplayName();
#else #else
llvm::DISubprogram sub(N); return N->getDisplayName();
return sub.getDisplayName();
#endif #endif
} }
return ""; return "";
@ -294,12 +224,7 @@ public:
return; return;
} }
#if LDC_LLVM_VER >= 307
if (const DebugLoc &debugLoc = instr->getDebugLoc()) if (const DebugLoc &debugLoc = instr->getDebugLoc())
#else
const DebugLoc &debugLoc = instr->getDebugLoc();
if (!debugLoc.isUnknown())
#endif
{ {
if (!padding) { if (!padding) {
os.PadToColumn(50); os.PadToColumn(50);
@ -311,35 +236,19 @@ public:
os << ']'; os << ']';
} }
if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(instr)) { if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(instr)) {
#if LDC_LLVM_VER >= 307
DILocalVariable *Var(DDI->getVariable()); DILocalVariable *Var(DDI->getVariable());
#else
DIVariable Var(DDI->getVariable());
#endif
if (!padding) { if (!padding) {
os.PadToColumn(50); os.PadToColumn(50);
os << ";"; os << ";";
} }
#if LDC_LLVM_VER >= 307
os << " [debug variable = " << Var->getName() << ']'; os << " [debug variable = " << Var->getName() << ']';
#else
os << " [debug variable = " << Var.getName() << ']';
#endif
} else if (const DbgValueInst *DVI = dyn_cast<DbgValueInst>(instr)) { } else if (const DbgValueInst *DVI = dyn_cast<DbgValueInst>(instr)) {
#if LDC_LLVM_VER >= 307
DILocalVariable *Var(DVI->getVariable()); DILocalVariable *Var(DVI->getVariable());
#else
DIVariable Var(DVI->getVariable());
#endif
if (!padding) { if (!padding) {
os.PadToColumn(50); os.PadToColumn(50);
os << ";"; os << ";";
} }
#if LDC_LLVM_VER >= 307
os << " [debug variable = " << Var->getName() << ']'; os << " [debug variable = " << Var->getName() << ']';
#else
os << " [debug variable = " << Var.getName() << ']';
#endif
} else if (const CallInst *callinstr = dyn_cast<CallInst>(instr)) { } else if (const CallInst *callinstr = dyn_cast<CallInst>(instr)) {
const Function *F = callinstr->getCalledFunction(); const Function *F = callinstr->getCalledFunction();
if (!F) { if (!F) {
@ -374,20 +283,16 @@ public:
void writeObjectFile(llvm::Module *m, const char *filename) { void writeObjectFile(llvm::Module *m, const char *filename) {
IF_LOG Logger::println("Writing object file to: %s", filename); IF_LOG Logger::println("Writing object file to: %s", filename);
LLErrorInfo errinfo; std::error_code errinfo;
{ {
llvm::raw_fd_ostream out(filename, errinfo, llvm::sys::fs::F_None); llvm::raw_fd_ostream out(filename, errinfo, llvm::sys::fs::F_None);
#if LDC_LLVM_VER >= 306
if (!errinfo) if (!errinfo)
#else
if (errinfo.empty())
#endif
{ {
codegenModule(*gTargetMachine, *m, out, codegenModule(*gTargetMachine, *m, out,
llvm::TargetMachine::CGFT_ObjectFile); llvm::TargetMachine::CGFT_ObjectFile);
} else { } else {
error(Loc(), "cannot write object file '%s': %s", filename, error(Loc(), "cannot write object file '%s': %s", filename,
ERRORINFO_STRING(errinfo)); errinfo.message().c_str());
fatal(); fatal();
} }
} }
@ -480,11 +385,11 @@ void writeModule(llvm::Module *m, const char *filename) {
std::string bcpath = std::string bcpath =
(doLTO && outputObj) ? filename : replaceExtensionWith(global.bc_ext); (doLTO && outputObj) ? filename : replaceExtensionWith(global.bc_ext);
Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
LLErrorInfo errinfo; std::error_code errinfo;
llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::sys::fs::F_None); llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::sys::fs::F_None);
if (bos.has_error()) { if (bos.has_error()) {
error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(), error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(),
ERRORINFO_STRING(errinfo)); errinfo.message().c_str());
fatal(); fatal();
} }
if (opts::isUsingThinLTO()) { if (opts::isUsingThinLTO()) {
@ -517,11 +422,11 @@ void writeModule(llvm::Module *m, const char *filename) {
if (global.params.output_ll) { if (global.params.output_ll) {
const auto llpath = replaceExtensionWith(global.ll_ext); const auto llpath = replaceExtensionWith(global.ll_ext);
Logger::println("Writing LLVM IR to: %s\n", llpath.c_str()); Logger::println("Writing LLVM IR to: %s\n", llpath.c_str());
LLErrorInfo errinfo; std::error_code errinfo;
llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None); llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None);
if (aos.has_error()) { if (aos.has_error()) {
error(Loc(), "cannot write LLVM IR file '%s': %s", llpath.c_str(), error(Loc(), "cannot write LLVM IR file '%s': %s", llpath.c_str(),
ERRORINFO_STRING(errinfo)); errinfo.message().c_str());
fatal(); fatal();
} }
AssemblyAnnotator annotator; AssemblyAnnotator annotator;
@ -540,19 +445,15 @@ void writeModule(llvm::Module *m, const char *filename) {
} }
Logger::println("Writing asm to: %s\n", spath.c_str()); Logger::println("Writing asm to: %s\n", spath.c_str());
LLErrorInfo errinfo; std::error_code errinfo;
{ {
llvm::raw_fd_ostream out(spath.c_str(), errinfo, llvm::sys::fs::F_None); llvm::raw_fd_ostream out(spath.c_str(), errinfo, llvm::sys::fs::F_None);
#if LDC_LLVM_VER >= 306
if (!errinfo) if (!errinfo)
#else
if (errinfo.empty())
#endif
{ {
codegenModule(*gTargetMachine, *m, out, codegenModule(*gTargetMachine, *m, out,
llvm::TargetMachine::CGFT_AssemblyFile); llvm::TargetMachine::CGFT_AssemblyFile);
} else { } else {
error(Loc(), "cannot write asm: %s", ERRORINFO_STRING(errinfo)); error(Loc(), "cannot write asm: %s", errinfo.message().c_str());
fatal(); fatal();
} }
} }
@ -573,5 +474,3 @@ void writeModule(llvm::Module *m, const char *filename) {
} }
} }
} }
#undef ERRORINFO_STRING

View file

@ -28,12 +28,8 @@ static llvm::cl::opt<std::string>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
static std::string findProgramByName(llvm::StringRef name) { static std::string findProgramByName(llvm::StringRef name) {
#if LDC_LLVM_VER >= 306
llvm::ErrorOr<std::string> res = llvm::sys::findProgramByName(name); llvm::ErrorOr<std::string> res = llvm::sys::findProgramByName(name);
return res ? res.get() : std::string(); return res ? res.get() : std::string();
#else
return llvm::sys::FindProgramByName(name);
#endif
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View file

@ -323,10 +323,6 @@ TargetABI *TargetABI::getTarget() {
return getPPCTargetABI(global.params.targetTriple->isArch64Bit()); return getPPCTargetABI(global.params.targetTriple->isArch64Bit());
case llvm::Triple::ppc64le: case llvm::Triple::ppc64le:
return getPPC64LETargetABI(); return getPPC64LETargetABI();
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
case llvm::Triple::arm64_be:
#endif
case llvm::Triple::aarch64: case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be: case llvm::Triple::aarch64_be:
return getAArch64TargetABI(); return getAArch64TargetABI();

View file

@ -479,12 +479,8 @@ LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit,
LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)}; LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)};
#if LDC_LLVM_VER >= 307
LLConstant *gep = llvm::ConstantExpr::getGetElementPtr( LLConstant *gep = llvm::ConstantExpr::getGetElementPtr(
isaPointer(gvar)->getElementType(), gvar, idxs, true); isaPointer(gvar)->getElementType(), gvar, idxs, true);
#else
LLConstant *gep = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, true);
#endif
gep = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llelemty)); gep = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llelemty));
return DtoConstSlice(DtoConstSize_t(arrlen), gep, arrty); return DtoConstSlice(DtoConstSize_t(arrlen), gep, arrty);

View file

@ -21,8 +21,6 @@
#if LDC_LLVM_VER >= 500 #if LDC_LLVM_VER >= 500
#define LLVM_END_WITH_NULL #define LLVM_END_WITH_NULL
#elif LDC_LLVM_VER < 306
#define LLVM_END_WITH_NULL END_WITH_NULL
#endif #endif
template <typename TYPE> struct Array; template <typename TYPE> struct Array;
@ -47,39 +45,23 @@ template <> struct FlagParserDataType<cl::boolOrDefault> {
template <class DataType> class FlagParser : public cl::generic_parser_base { template <class DataType> class FlagParser : public cl::generic_parser_base {
protected: protected:
llvm::SmallVector<std::pair<std::string, DataType>, 2> switches; llvm::SmallVector<std::pair<std::string, DataType>, 2> switches;
#if LDC_LLVM_VER >= 307
cl::Option &owner() const { return Owner; } cl::Option &owner() const { return Owner; }
#else
cl::Option *Owner;
cl::Option &owner() const { return *Owner; }
#endif
public: public:
#if LDC_LLVM_VER >= 307
FlagParser(cl::Option &O) : generic_parser_base(O) {} FlagParser(cl::Option &O) : generic_parser_base(O) {}
#else
FlagParser() : generic_parser_base(), Owner(nullptr) {}
#endif
typedef DataType parser_data_type; typedef DataType parser_data_type;
#if LDC_LLVM_VER >= 307
void initialize() { void initialize() {
#else
void initialize(cl::Option &O) {
Owner = &O;
#endif
std::string Name(owner().ArgStr); std::string Name(owner().ArgStr);
switches.push_back( switches.push_back(
make_pair("enable-" + Name, FlagParserDataType<DataType>::true_val())); make_pair("enable-" + Name, FlagParserDataType<DataType>::true_val()));
switches.push_back(make_pair("disable-" + Name, switches.push_back(make_pair("disable-" + Name,
FlagParserDataType<DataType>::false_val())); FlagParserDataType<DataType>::false_val()));
// Replace <foo> with -enable-<foo> and register -disable-<foo> // Replace <foo> with -enable-<foo> and register -disable-<foo>.
#if LDC_LLVM_VER >= 307
// A literal option can only registered if the argstr is empty - // A literal option can only registered if the argstr is empty -
// just do this first. // just do this first.
owner().setArgStr(""); owner().setArgStr("");
AddLiteralOption(Owner, strdup(switches[1].first.data())); AddLiteralOption(Owner, strdup(switches[1].first.data()));
#endif
owner().setArgStr(switches[0].first.data()); owner().setArgStr(switches[0].first.data());
} }

View file

@ -34,9 +34,7 @@ void emitCoverageLinecountInc(Loc &loc) {
// Get GEP into _d_cover_data array // Get GEP into _d_cover_data array
LLConstant *idxs[] = {DtoConstUint(0), DtoConstUint(line)}; LLConstant *idxs[] = {DtoConstUint(0), DtoConstUint(line)};
LLValue *ptr = llvm::ConstantExpr::getGetElementPtr( LLValue *ptr = llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
LLArrayType::get(LLType::getInt32Ty(gIR->context()), m->numlines), LLArrayType::get(LLType::getInt32Ty(gIR->context()), m->numlines),
#endif
m->d_cover_data, idxs, true); m->d_cover_data, idxs, true);
// Do an atomic increment, so this works when multiple threads are executed. // Do an atomic increment, so this works when multiple threads are executed.

View file

@ -72,20 +72,7 @@ void CTFloat::toAPFloat(const real_t src, APFloat &dst) {
CTFloatUnion u; CTFloatUnion u;
u.fp = src; u.fp = src;
#if LDC_LLVM_VER >= 307
const unsigned sizeInBits = APFloat::getSizeInBits(*apSemantics); const unsigned sizeInBits = APFloat::getSizeInBits(*apSemantics);
#else
#if __i386__ || __x86_64__
const unsigned sizeInBits = 80;
#elif __aarch64__
const unsigned sizeInBits = 128;
#elif __ppc__ || __ppc64__
const unsigned sizeInBits = 128;
#else
llvm_unreachable("Unknown host real_t type for compile-time reals");
#endif
#endif
const APInt bits = APInt(sizeInBits, numUint64Parts, u.bits); const APInt bits = APInt(sizeInBits, numUint64Parts, u.bits);
dst = APFloat(*apSemantics, bits); dst = APFloat(*apSemantics, bits);

View file

@ -59,8 +59,6 @@ public:
} }
void addKernelMetadata(FuncDeclaration *df, llvm::Function *llf) override { void addKernelMetadata(FuncDeclaration *df, llvm::Function *llf) override {
// Fix 3.5.2 build failures. Remove when dropping 3.5 support.
#if LDC_LLVM_VER >= 306
// TODO: Handle Function attibutes // TODO: Handle Function attibutes
llvm::NamedMDNode *na = llvm::NamedMDNode *na =
_ir->module.getOrInsertNamedMetadata("nvvm.annotations"); _ir->module.getOrInsertNamedMetadata("nvvm.annotations");
@ -72,7 +70,6 @@ public:
llvm::Metadata *arr[] = {fn, kstr, one}; llvm::Metadata *arr[] = {fn, kstr, one};
llvm::MDNode *tup = llvm::MDTuple::get(ctx, arr); llvm::MDNode *tup = llvm::MDTuple::get(ctx, arr);
na->addOperand(tup); na->addOperand(tup);
#endif
} }
}; };
} // anonymous namespace. } // anonymous namespace.

View file

@ -54,9 +54,6 @@ public:
// Adapted from clang // Adapted from clang
void addMetadata() override { void addMetadata() override {
// Fix 3.5.2 build failures. Remove when dropping 3.5 support.
// OCL is only supported for 3.6.1 and 3.8 anyway.
#if LDC_LLVM_VER >= 306
// opencl.ident? // opencl.ident?
// spirv.Source // debug only // spirv.Source // debug only
// stuff from clang's CGSPIRMetadataAdder.cpp // stuff from clang's CGSPIRMetadataAdder.cpp
@ -83,7 +80,6 @@ public:
_ir->module.getOrInsertNamedMetadata("opencl.ocl.version"); _ir->module.getOrInsertNamedMetadata("opencl.ocl.version");
OCLVerMD->addOperand(llvm::MDNode::get(ctx, OCLVerElts)); OCLVerMD->addOperand(llvm::MDNode::get(ctx, OCLVerElts));
#endif
} }
enum KernArgMD { enum KernArgMD {
KernArgMD_addr_space, KernArgMD_addr_space,
@ -95,12 +91,10 @@ public:
count_KernArgMD count_KernArgMD
}; };
void addKernelMetadata(FuncDeclaration *fd, llvm::Function *llf) override { void addKernelMetadata(FuncDeclaration *fd, llvm::Function *llf) override {
// By the time we get here the ABI should have rewritten the function // By the time we get here the ABI should have rewritten the function
// type so that the magic types in ldc.dcompute are transformed into // type so that the magic types in ldc.dcompute are transformed into
// what the LLVM backend expects. // what the LLVM backend expects.
// Fix 3.5.2 build failures. Remove when dropping 3.5 support.
#if LDC_LLVM_VER >= 306
unsigned i = 0; unsigned i = 0;
// TODO: Handle Function attibutes // TODO: Handle Function attibutes
llvm::SmallVector<llvm::Metadata *, 8> kernelMDArgs; llvm::SmallVector<llvm::Metadata *, 8> kernelMDArgs;
@ -137,7 +131,6 @@ public:
llvm::NamedMDNode *OpenCLKernelMetadata = llvm::NamedMDNode *OpenCLKernelMetadata =
_ir->module.getOrInsertNamedMetadata("opencl.kernels"); _ir->module.getOrInsertNamedMetadata("opencl.kernels");
OpenCLKernelMetadata->addOperand(kernelMDNode); OpenCLKernelMetadata->addOperand(kernelMDNode);
#endif
} }
std::string mod2str(MOD mod) { std::string mod2str(MOD mod) {
@ -166,7 +159,7 @@ public:
ss << t->toChars(); ss << t->toChars();
return ss.str(); return ss.str();
} }
#if LDC_LLVM_VER >= 306
void decodeTypes(std::array<llvm::SmallVector<llvm::Metadata *, 8>,count_KernArgMD> attrs, void decodeTypes(std::array<llvm::SmallVector<llvm::Metadata *, 8>,count_KernArgMD> attrs,
VarDeclaration *v) VarDeclaration *v)
{ {
@ -199,7 +192,6 @@ public:
attrs[KernArgMD_type_qual].push_back(llvm::MDString::get(ctx, typeQuals)); attrs[KernArgMD_type_qual].push_back(llvm::MDString::get(ctx, typeQuals));
attrs[KernArgMD_name].push_back(llvm::MDString::get(ctx, v->ident->toChars())); attrs[KernArgMD_name].push_back(llvm::MDString::get(ctx, v->ident->toChars()));
} }
#endif
}; };
} // anonymous namespace. } // anonymous namespace.

View file

@ -28,17 +28,8 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#if LDC_LLVM_VER >= 306
using LLMetadata = llvm::Metadata; using LLMetadata = llvm::Metadata;
#else
using LLMetadata = llvm::Value;
#endif
#if LDC_LLVM_VER >= 307
using DIFlags = llvm::DINode; using DIFlags = llvm::DINode;
#else
using DIFlags = llvm::DIDescriptor;
#endif
namespace { namespace {
#if LDC_LLVM_VER >= 400 #if LDC_LLVM_VER >= 400
@ -48,22 +39,12 @@ const unsigned DIFlagZero = 0;
#endif #endif
ldc::DIType getNullDIType() { ldc::DIType getNullDIType() {
#if LDC_LLVM_VER >= 307
return nullptr; return nullptr;
#else
return llvm::DIType();
#endif
} }
#if LDC_LLVM_VER >= 307
llvm::DINodeArray getEmptyDINodeArray() { llvm::DINodeArray getEmptyDINodeArray() {
return nullptr; return nullptr;
} }
#else
llvm::DIArray getEmptyDINodeArray() {
return llvm::DIArray();
}
#endif
llvm::StringRef uniqueIdent(Type* t) { llvm::StringRef uniqueIdent(Type* t) {
#if LDC_LLVM_VER >= 309 #if LDC_LLVM_VER >= 309
@ -132,24 +113,11 @@ ldc::DIScope ldc::DIBuilder::GetCurrentScope() {
} }
void ldc::DIBuilder::Declare(const Loc &loc, llvm::Value *var, void ldc::DIBuilder::Declare(const Loc &loc, llvm::Value *var,
ldc::DILocalVariable divar ldc::DILocalVariable divar,
#if LDC_LLVM_VER >= 306 ldc::DIExpression diexpr) {
,
ldc::DIExpression diexpr
#endif
) {
unsigned charnum = (loc.linnum ? loc.charnum : 0); unsigned charnum = (loc.linnum ? loc.charnum : 0);
auto debugLoc = llvm::DebugLoc::get(loc.linnum, charnum, GetCurrentScope()); auto debugLoc = llvm::DebugLoc::get(loc.linnum, charnum, GetCurrentScope());
#if LDC_LLVM_VER < 307
llvm::Instruction *instr = DBuilder.insertDeclare(var, divar,
#if LDC_LLVM_VER >= 306
diexpr,
#endif
IR->scopebb());
instr->setDebugLoc(debugLoc);
#else // if LLVM >= 3.7
DBuilder.insertDeclare(var, divar, diexpr, debugLoc, IR->scopebb()); DBuilder.insertDeclare(var, divar, diexpr, debugLoc, IR->scopebb());
#endif
} }
ldc::DIFile ldc::DIBuilder::CreateFile(Loc &loc) { ldc::DIFile ldc::DIBuilder::CreateFile(Loc &loc) {
@ -399,11 +367,9 @@ ldc::DIType ldc::DIBuilder::CreateMemberType(unsigned linnum, Type *type,
case PROTprotected: case PROTprotected:
Flags = DIFlags::FlagProtected; Flags = DIFlags::FlagProtected;
break; break;
#if LDC_LLVM_VER >= 306
case PROTpublic: case PROTpublic:
Flags = DIFlags::FlagPublic; Flags = DIFlags::FlagPublic;
break; break;
#endif
default: default:
break; break;
} }
@ -477,11 +443,7 @@ ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type) {
// set diCompositeType to handle recursive types properly // set diCompositeType to handle recursive types properly
unsigned tag = (t->ty == Tstruct) ? llvm::dwarf::DW_TAG_structure_type unsigned tag = (t->ty == Tstruct) ? llvm::dwarf::DW_TAG_structure_type
: llvm::dwarf::DW_TAG_class_type; : llvm::dwarf::DW_TAG_class_type;
#if LDC_LLVM_VER >= 307
ir->diCompositeType = DBuilder.createReplaceableCompositeType( ir->diCompositeType = DBuilder.createReplaceableCompositeType(
#else
ir->diCompositeType = DBuilder.createReplaceableForwardDecl(
#endif
tag, name, CU, file, linnum); tag, name, CU, file, linnum);
if (!sd->isInterfaceDeclaration()) // plain interfaces don't have one if (!sd->isInterfaceDeclaration()) // plain interfaces don't have one
@ -505,12 +467,7 @@ ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type) {
nullptr, // TemplateParms nullptr, // TemplateParms
uniqueIdent(t)); // UniqueIdentifier uniqueIdent(t)); // UniqueIdentifier
auto dt = DBuilder.createInheritance(fwd, derivedFrom, 0, auto dt = DBuilder.createInheritance(fwd, derivedFrom, 0,
#if LDC_LLVM_VER >= 306 DIFlags::FlagPublic);
DIFlags::FlagPublic
#else
0
#endif
);
elems.push_back(dt); elems.push_back(dt);
} }
AddFields(sd, file, elems); AddFields(sd, file, elems);
@ -548,12 +505,8 @@ ldc::DIType ldc::DIBuilder::CreateCompositeType(Type *type) {
uniqueIdent(t)); // UniqueIdentifier uniqueIdent(t)); // UniqueIdentifier
} }
#if LDC_LLVM_VER >= 307
ir->diCompositeType = DBuilder.replaceTemporary( ir->diCompositeType = DBuilder.replaceTemporary(
llvm::TempDINode(ir->diCompositeType), static_cast<llvm::DIType *>(ret)); llvm::TempDINode(ir->diCompositeType), static_cast<llvm::DIType *>(ret));
#else
ir->diCompositeType.replaceAllUsesWith(ret);
#endif
ir->diCompositeType = ret; ir->diCompositeType = ret;
return ret; return ret;
@ -629,11 +582,7 @@ ldc::DISubroutineType ldc::DIBuilder::CreateFunctionType(Type *type) {
// Create "dummy" subroutine type for the return type // Create "dummy" subroutine type for the return type
LLMetadata *params = {CreateTypeDescription(retType)}; LLMetadata *params = {CreateTypeDescription(retType)};
#if LDC_LLVM_VER == 305
auto paramsArray = DBuilder.getOrCreateArray(params);
#else
auto paramsArray = DBuilder.getOrCreateTypeArray(params); auto paramsArray = DBuilder.getOrCreateTypeArray(params);
#endif
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308
return DBuilder.createSubroutineType(paramsArray); return DBuilder.createSubroutineType(paramsArray);
@ -643,11 +592,7 @@ ldc::DISubroutineType ldc::DIBuilder::CreateFunctionType(Type *type) {
} }
ldc::DISubroutineType ldc::DIBuilder::CreateEmptyFunctionType() { ldc::DISubroutineType ldc::DIBuilder::CreateEmptyFunctionType() {
#if LDC_LLVM_VER == 305
auto paramsArray = DBuilder.getOrCreateArray(llvm::None);
#else
auto paramsArray = DBuilder.getOrCreateTypeArray(llvm::None); auto paramsArray = DBuilder.getOrCreateTypeArray(llvm::None);
#endif
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308
return DBuilder.createSubroutineType(paramsArray); return DBuilder.createSubroutineType(paramsArray);
#else #else
@ -821,10 +766,8 @@ void ldc::DIBuilder::EmitCompileUnit(Module *m) {
llvm::StringRef(), // Flags TODO llvm::StringRef(), // Flags TODO
1, // Runtime Version TODO 1, // Runtime Version TODO
llvm::StringRef(), // SplitName llvm::StringRef(), // SplitName
getDebugEmissionKind() // DebugEmissionKind getDebugEmissionKind(), // DebugEmissionKind
#if LDC_LLVM_VER > 306 0 // DWOId
, 0 // DWOId
#endif
#if LDC_LLVM_VER < 309 #if LDC_LLVM_VER < 309
, mustEmitFullDebugInfo() // EmitDebugInfo , mustEmitFullDebugInfo() // EmitDebugInfo
#endif #endif
@ -833,11 +776,7 @@ void ldc::DIBuilder::EmitCompileUnit(Module *m) {
ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) { ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) {
if (!mustEmitLocationsDebugInfo()) { if (!mustEmitLocationsDebugInfo()) {
#if LDC_LLVM_VER >= 307
return nullptr; return nullptr;
#else
return llvm::DISubprogram();
#endif
} }
Logger::println("D to dwarf subprogram"); Logger::println("D to dwarf subprogram");
@ -882,11 +821,7 @@ ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) {
ldc::DISubprogram ldc::DIBuilder::EmitThunk(llvm::Function *Thunk, ldc::DISubprogram ldc::DIBuilder::EmitThunk(llvm::Function *Thunk,
FuncDeclaration *fd) { FuncDeclaration *fd) {
if (!mustEmitLocationsDebugInfo()) { if (!mustEmitLocationsDebugInfo()) {
#if LDC_LLVM_VER >= 307
return nullptr; return nullptr;
#else
return llvm::DISubprogram();
#endif
} }
Logger::println("Thunk to dwarf subprogram"); Logger::println("Thunk to dwarf subprogram");
@ -931,11 +866,7 @@ ldc::DISubprogram ldc::DIBuilder::EmitThunk(llvm::Function *Thunk,
ldc::DISubprogram ldc::DIBuilder::EmitModuleCTor(llvm::Function *Fn, ldc::DISubprogram ldc::DIBuilder::EmitModuleCTor(llvm::Function *Fn,
llvm::StringRef prettyname) { llvm::StringRef prettyname) {
if (!mustEmitLocationsDebugInfo()) { if (!mustEmitLocationsDebugInfo()) {
#if LDC_LLVM_VER >= 307
return nullptr; return nullptr;
#else
return llvm::DISubprogram();
#endif
} }
Logger::println("D to dwarf subprogram"); Logger::println("D to dwarf subprogram");
@ -948,11 +879,7 @@ ldc::DISubprogram ldc::DIBuilder::EmitModuleCTor(llvm::Function *Fn,
// Create "dummy" subroutine type for the return type // Create "dummy" subroutine type for the return type
LLMetadata *params = {CreateTypeDescription(Type::tvoid)}; LLMetadata *params = {CreateTypeDescription(Type::tvoid)};
#if LDC_LLVM_VER >= 306
auto paramsArray = DBuilder.getOrCreateTypeArray(params); auto paramsArray = DBuilder.getOrCreateTypeArray(params);
#else
auto paramsArray = DBuilder.getOrCreateArray(params);
#endif
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308
auto DIFnType = DBuilder.createSubroutineType(paramsArray); auto DIFnType = DBuilder.createSubroutineType(paramsArray);
#else #else
@ -1017,10 +944,6 @@ void ldc::DIBuilder::EmitBlockStart(Loc &loc) {
CreateFile(loc), // file CreateFile(loc), // file
loc.linnum, // line loc.linnum, // line
loc.linnum ? loc.charnum : 0 // column loc.linnum ? loc.charnum : 0 // column
#if LDC_LLVM_VER == 305
,
0 // DWARF path discriminator value
#endif
); );
IR->func()->diLexicalBlocks.push(block); IR->func()->diLexicalBlocks.push(block);
EmitStopPoint(loc); EmitStopPoint(loc);
@ -1045,13 +968,8 @@ void ldc::DIBuilder::EmitStopPoint(Loc &loc) {
// If we already have a location set and the current loc is invalid // If we already have a location set and the current loc is invalid
// (line 0), then we can just ignore it (see GitHub issue #998 for why we // (line 0), then we can just ignore it (see GitHub issue #998 for why we
// cannot do this in all cases). // cannot do this in all cases).
#if LDC_LLVM_VER >= 307
if (!loc.linnum && IR->ir->getCurrentDebugLocation()) if (!loc.linnum && IR->ir->getCurrentDebugLocation())
return; return;
#else
if (!loc.linnum && !IR->ir->getCurrentDebugLocation().isUnknown())
return;
#endif
unsigned linnum = loc.linnum; unsigned linnum = loc.linnum;
// without proper loc use the line of the enclosing symbol that has line // without proper loc use the line of the enclosing symbol that has line
// number debug info // number debug info
@ -1082,12 +1000,8 @@ void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd) {
llvm::Instruction *instr = llvm::Instruction *instr =
DBuilder.insertDbgValueIntrinsic(val, 0, debugVariable, DBuilder.insertDbgValueIntrinsic(val, 0, debugVariable,
#if LDC_LLVM_VER >= 306
DBuilder.createExpression(), DBuilder.createExpression(),
#endif
#if LDC_LLVM_VER >= 307
IR->ir->getCurrentDebugLocation(), IR->ir->getCurrentDebugLocation(),
#endif
IR->scopebb()); IR->scopebb());
instr->setDebugLoc(IR->ir->getCurrentDebugLocation()); instr->setDebugLoc(IR->ir->getCurrentDebugLocation());
} }
@ -1095,12 +1009,7 @@ void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd) {
void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd, void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
Type *type, bool isThisPtr, Type *type, bool isThisPtr,
bool forceAsLocal, bool forceAsLocal,
#if LDC_LLVM_VER >= 306 llvm::ArrayRef<int64_t> addr) {
llvm::ArrayRef<int64_t> addr
#else
llvm::ArrayRef<llvm::Value *> addr
#endif
) {
if (!mustEmitFullDebugInfo()) if (!mustEmitFullDebugInfo())
return; return;
@ -1155,27 +1064,7 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
? DIFlagZero ? DIFlagZero
: DIFlags::FlagArtificial | DIFlags::FlagObjectPointer; : DIFlags::FlagArtificial | DIFlags::FlagObjectPointer;
#if LDC_LLVM_VER < 306 #if LDC_LLVM_VER < 308
if (addr.empty()) {
debugVariable = DBuilder.createLocalVariable(tag, // tag
GetCurrentScope(), // scope
vd->toChars(), // name
CreateFile(vd), // file
vd->loc.linnum, // line num
TD, // type
true, // preserve
Flags // flags
);
} else {
debugVariable = DBuilder.createComplexVariable(tag, // tag
GetCurrentScope(), // scope
vd->toChars(), // name
CreateFile(vd), // file
vd->loc.linnum, // line num
TD, // type
addr);
}
#elif LDC_LLVM_VER < 308
debugVariable = DBuilder.createLocalVariable(tag, // tag debugVariable = DBuilder.createLocalVariable(tag, // tag
GetCurrentScope(), // scope GetCurrentScope(), // scope
vd->toChars(), // name vd->toChars(), // name
@ -1221,14 +1110,10 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
#endif #endif
variableMap[vd] = debugVariable; variableMap[vd] = debugVariable;
// declare // declare
#if LDC_LLVM_VER >= 306
Declare(vd->loc, ll, debugVariable, addr.empty() Declare(vd->loc, ll, debugVariable, addr.empty()
? DBuilder.createExpression() ? DBuilder.createExpression()
: DBuilder.createExpression(addr)); : DBuilder.createExpression(addr));
#else
Declare(vd->loc, ll, debugVariable);
#endif
} }
void ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *llVar, void ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *llVar,
@ -1250,9 +1135,7 @@ void ldc::DIBuilder::EmitGlobalVariable(llvm::GlobalVariable *llVar,
#else #else
DBuilder.createGlobalVariable( DBuilder.createGlobalVariable(
#endif #endif
#if LDC_LLVM_VER >= 306 GetCU(), // context
GetCU(), // context
#endif
vd->toChars(), // name vd->toChars(), // name
mangleBuf.peekString(), // linkage name mangleBuf.peekString(), // linkage name
CreateFile(vd), // file CreateFile(vd), // file

View file

@ -43,7 +43,6 @@ extern const llvm::DataLayout *gDataLayout;
namespace ldc { namespace ldc {
// Define some basic types // Define some basic types
#if LDC_LLVM_VER >= 307
typedef llvm::DIType *DIType; typedef llvm::DIType *DIType;
typedef llvm::DIFile *DIFile; typedef llvm::DIFile *DIFile;
typedef llvm::DIGlobalVariable *DIGlobalVariable; typedef llvm::DIGlobalVariable *DIGlobalVariable;
@ -54,39 +53,17 @@ typedef llvm::DIScope *DIScope;
typedef llvm::DISubroutineType *DISubroutineType; typedef llvm::DISubroutineType *DISubroutineType;
typedef llvm::DISubprogram *DISubprogram; typedef llvm::DISubprogram *DISubprogram;
typedef llvm::DICompileUnit *DICompileUnit; typedef llvm::DICompileUnit *DICompileUnit;
#else
typedef llvm::DIType DIType;
typedef llvm::DIFile DIFile;
typedef llvm::DIGlobalVariable DIGlobalVariable;
typedef llvm::DIVariable DILocalVariable;
typedef llvm::DILexicalBlock DILexicalBlock;
typedef llvm::DIDescriptor DIScope;
typedef llvm::DICompositeType DISubroutineType;
typedef llvm::DISubprogram DISubprogram;
typedef llvm::DICompileUnit DICompileUnit;
#if LDC_LLVM_VER == 306
typedef llvm::DIExpression DIExpression;
#endif
#endif
class DIBuilder { class DIBuilder {
IRState *const IR; IRState *const IR;
llvm::DIBuilder DBuilder; llvm::DIBuilder DBuilder;
#if LDC_LLVM_VER >= 307
DICompileUnit CUNode; DICompileUnit CUNode;
#else
const llvm::MDNode *CUNode;
#endif
const bool isTargetMSVCx64; const bool isTargetMSVCx64;
DICompileUnit GetCU() { DICompileUnit GetCU() {
#if LDC_LLVM_VER >= 307
return CUNode; return CUNode;
#else
return llvm::DICompileUnit(CUNode);
#endif
} }
Loc currentLoc; Loc currentLoc;
@ -147,13 +124,7 @@ public:
void void
EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd, Type *type = nullptr, EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd, Type *type = nullptr,
bool isThisPtr = false, bool forceAsLocal = false, bool isThisPtr = false, bool forceAsLocal = false,
#if LDC_LLVM_VER >= 306 llvm::ArrayRef<int64_t> addr = llvm::ArrayRef<int64_t>());
llvm::ArrayRef<int64_t> addr = llvm::ArrayRef<int64_t>()
#else
llvm::ArrayRef<llvm::Value *> addr =
llvm::ArrayRef<llvm::Value *>()
#endif
);
/// \brief Emits all things necessary for making debug info for a global /// \brief Emits all things necessary for making debug info for a global
/// variable vd. /// variable vd.
@ -168,19 +139,10 @@ private:
llvm::LLVMContext &getContext(); llvm::LLVMContext &getContext();
Module *getDefinedModule(Dsymbol *s); Module *getDefinedModule(Dsymbol *s);
DIScope GetCurrentScope(); DIScope GetCurrentScope();
void Declare(const Loc &loc, llvm::Value *var, ldc::DILocalVariable divar void Declare(const Loc &loc, llvm::Value *var, ldc::DILocalVariable divar,
#if LDC_LLVM_VER >= 306 ldc::DIExpression diexpr);
,
ldc::DIExpression diexpr
#endif
);
void AddFields(AggregateDeclaration *sd, ldc::DIFile file, void AddFields(AggregateDeclaration *sd, ldc::DIFile file,
#if LDC_LLVM_VER >= 306 llvm::SmallVector<llvm::Metadata *, 16> &elems);
llvm::SmallVector<llvm::Metadata *, 16> &elems
#else
llvm::SmallVector<llvm::Value *, 16> &elems
#endif
);
DIFile CreateFile(Loc &loc); DIFile CreateFile(Loc &loc);
DIFile CreateFile(); DIFile CreateFile();
DIFile CreateFile(Dsymbol* decl); DIFile CreateFile(Dsymbol* decl);
@ -212,14 +174,8 @@ public:
uint64_t offset = uint64_t offset =
gDataLayout->getStructLayout(type)->getElementOffset(index); gDataLayout->getStructLayout(type)->getElementOffset(index);
#if LDC_LLVM_VER >= 306
addr.push_back(llvm::dwarf::DW_OP_plus); addr.push_back(llvm::dwarf::DW_OP_plus);
addr.push_back(offset); addr.push_back(offset);
#else
llvm::Type *int64Ty = llvm::Type::getInt64Ty(getContext());
addr.push_back(llvm::ConstantInt::get(int64Ty, llvm::DIBuilder::OpPlus));
addr.push_back(llvm::ConstantInt::get(int64Ty, offset));
#endif
} }
template <typename T> void OpOffset(T &addr, llvm::Value *val, int index) { template <typename T> void OpOffset(T &addr, llvm::Value *val, int index) {
@ -237,12 +193,7 @@ public:
return; return;
} }
#if LDC_LLVM_VER >= 306
addr.push_back(llvm::dwarf::DW_OP_deref); addr.push_back(llvm::dwarf::DW_OP_deref);
#else
llvm::Type *int64Ty = llvm::Type::getInt64Ty(getContext());
addr.push_back(llvm::ConstantInt::get(int64Ty, llvm::DIBuilder::OpDeref));
#endif
} }
}; };

View file

@ -87,13 +87,6 @@ bool defineAsExternallyAvailable(FuncDeclaration &fdecl) {
IF_LOG Logger::println("Enter defineAsExternallyAvailable"); IF_LOG Logger::println("Enter defineAsExternallyAvailable");
LOG_SCOPE LOG_SCOPE
#if LDC_LLVM_VER < 307
// Pre-3.7, cross-module inlining is disabled completely.
// See the commandline flag definition for more details.
IF_LOG Logger::println("LLVM < 3.7: Cross-module inlining disabled.");
return false;
#endif
// FIXME: For now, disable all cross-module inlining (also of pragma(inline, true) // FIXME: For now, disable all cross-module inlining (also of pragma(inline, true)
// functions). This check should be removed when cross-module inlining has // functions). This check should be removed when cross-module inlining has
// become more stable. // become more stable.

View file

@ -457,9 +457,6 @@ void applyTargetMachineAttributes(llvm::Function &func,
lessPreciseFPMADOption ? "true" : "false"); lessPreciseFPMADOption ? "true" : "false");
func.addFnAttr("no-infs-fp-math", TO.NoInfsFPMath ? "true" : "false"); func.addFnAttr("no-infs-fp-math", TO.NoInfsFPMath ? "true" : "false");
func.addFnAttr("no-nans-fp-math", TO.NoNaNsFPMath ? "true" : "false"); func.addFnAttr("no-nans-fp-math", TO.NoNaNsFPMath ? "true" : "false");
#if LDC_LLVM_VER < 307
func.addFnAttr("use-soft-float", TO.UseSoftFloat ? "true" : "false");
#endif
// Frame pointer elimination // Frame pointer elimination
func.addFnAttr("no-frame-pointer-elim", func.addFnAttr("no-frame-pointer-elim",
@ -1007,11 +1004,7 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
{ {
// emit a call to llvm_eh_unwind_init // emit a call to llvm_eh_unwind_init
LLFunction *hack = GET_INTRINSIC_DECL(eh_unwind_init); LLFunction *hack = GET_INTRINSIC_DECL(eh_unwind_init);
#if LDC_LLVM_VER >= 307
gIR->ir->CreateCall(hack, {}); gIR->ir->CreateCall(hack, {});
#else
gIR->ir->CreateCall(hack, "");
#endif
} }
// give the 'this' parameter (an lvalue) storage and debug info // give the 'this' parameter (an lvalue) storage and debug info

View file

@ -112,13 +112,8 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
llvm::SMDiagnostic err; llvm::SMDiagnostic err;
#if LDC_LLVM_VER >= 306
std::unique_ptr<llvm::Module> m = std::unique_ptr<llvm::Module> m =
llvm::parseAssemblyString(stream.str().c_str(), err, gIR->context()); llvm::parseAssemblyString(stream.str().c_str(), err, gIR->context());
#else
llvm::Module *m = llvm::ParseAssemblyString(stream.str().c_str(), NULL, err,
gIR->context());
#endif
std::string errstr = err.getMessage(); std::string errstr = err.getMessage();
if (!errstr.empty()) { if (!errstr.empty()) {
@ -134,15 +129,8 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308
llvm::Linker(gIR->module).linkInModule(std::move(m)); llvm::Linker(gIR->module).linkInModule(std::move(m));
#elif LDC_LLVM_VER >= 306
llvm::Linker(&gIR->module).linkInModule(m.get());
#else #else
errstr.clear(); llvm::Linker(&gIR->module).linkInModule(m.get());
llvm::Linker(&gIR->module).linkInModule(m, &errstr);
if (!errstr.empty()) {
error(tinst->loc, "Error when linking in llvm inline ir: %s",
errstr.c_str());
}
#endif #endif
} }

View file

@ -222,10 +222,8 @@ public:
/// Vector of options passed to the linker as metadata in object file. /// Vector of options passed to the linker as metadata in object file.
#if LDC_LLVM_VER >= 500 #if LDC_LLVM_VER >= 500
llvm::SmallVector<llvm::MDNode *, 5> LinkerMetadataArgs; llvm::SmallVector<llvm::MDNode *, 5> LinkerMetadataArgs;
#elif LDC_LLVM_VER >= 306
llvm::SmallVector<llvm::Metadata *, 5> LinkerMetadataArgs;
#else #else
llvm::SmallVector<llvm::Value *, 5> LinkerMetadataArgs; llvm::SmallVector<llvm::Metadata *, 5> LinkerMetadataArgs;
#endif #endif
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308

View file

@ -18,11 +18,6 @@ Dstring traitsGetTargetCPU() {
} }
bool traitsTargetHasFeature(Dstring feature) { bool traitsTargetHasFeature(Dstring feature) {
#if LDC_LLVM_VER < 307
// LLVM below 3.7 does not provide the necessary means to obtain the needed information,
// return the safe "feature not enabled".
return false;
#else
auto feat = llvm::StringRef(feature.ptr, feature.length); auto feat = llvm::StringRef(feature.ptr, feature.length);
// This is a work-around to a missing interface in LLVM to query whether a // This is a work-around to a missing interface in LLVM to query whether a
@ -47,5 +42,4 @@ bool traitsTargetHasFeature(Dstring feature) {
auto newFeatbits = mcinfo.ApplyFeatureFlag(("+" + feat).str()); auto newFeatbits = mcinfo.ApplyFeatureFlag(("+" + feat).str());
return savedFeatbits == newFeatbits; return savedFeatbits == newFeatbits;
} }
#endif
} }

View file

@ -25,11 +25,7 @@
struct IRState; struct IRState;
// An arrayreference type with initializer_list support (C++11): // An arrayreference type with initializer_list support (C++11):
#if LDC_LLVM_VER >= 307
template <class T> using ArrayParam = llvm::ArrayRef<T>; template <class T> using ArrayParam = llvm::ArrayRef<T>;
#else
template <class T> using ArrayParam = std::vector<T>;
#endif
llvm::LLVMContext& getGlobalContext(); llvm::LLVMContext& getGlobalContext();

View file

@ -75,13 +75,8 @@ llvm::Function *buildForwarderFunction(
// ... calling the given functions, and... // ... calling the given functions, and...
for (auto func : funcs) { for (auto func : funcs) {
const auto f = DtoCallee(func); const auto f = DtoCallee(func);
#if LDC_LLVM_VER < 307
const auto call = builder.CreateCall(f, "");
const auto ft = call->getCalledFunction()->getFunctionType();
#else
const auto call = builder.CreateCall(f, {}); const auto call = builder.CreateCall(f, {});
const auto ft = call->getFunctionType(); const auto ft = call->getFunctionType();
#endif
call->setCallingConv(gABI->callingConv(ft, LINKd)); call->setCallingConv(gABI->callingConv(ft, LINKd));
} }

View file

@ -121,14 +121,7 @@ RegistryStyle getModuleRegistryStyle() {
} }
if (t->isOSLinux() || t->isOSFreeBSD() || if (t->isOSLinux() || t->isOSFreeBSD() ||
#if LDC_LLVM_VER > 305 t->isOSNetBSD() || t->isOSOpenBSD() || t->isOSDragonFly()) {
t->isOSNetBSD() || t->isOSOpenBSD() || t->isOSDragonFly()
#else
t->getOS() == llvm::Triple::NetBSD ||
t->getOS() == llvm::Triple::OpenBSD ||
t->getOS() == llvm::Triple::DragonFly
#endif
) {
return RegistryStyle::sectionELF; return RegistryStyle::sectionELF;
} }
@ -196,10 +189,7 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
// put current beginning as the next of this one // put current beginning as the next of this one
LLValue *gep = builder.CreateStructGEP( LLValue *gep = builder.CreateStructGEP(
#if LDC_LLVM_VER >= 307 modulerefTy, thismref, 0, "next");
modulerefTy,
#endif
thismref, 0, "next");
builder.CreateStore(curbeg, gep); builder.CreateStore(curbeg, gep);
// replace beginning // replace beginning
@ -316,7 +306,6 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
llvm::Value *record = b.CreateAlloca(stype); llvm::Value *record = b.CreateAlloca(stype);
unsigned i = 0; unsigned i = 0;
#if LDC_LLVM_VER >= 307
b.CreateStore(version, b.CreateStructGEP(stype, record, i++)); b.CreateStore(version, b.CreateStructGEP(stype, record, i++));
b.CreateStore(dsoSlot, b.CreateStructGEP(stype, record, i++)); b.CreateStore(dsoSlot, b.CreateStructGEP(stype, record, i++));
b.CreateStore(minfoBeg, b.CreateStructGEP(stype, record, i++)); b.CreateStore(minfoBeg, b.CreateStructGEP(stype, record, i++));
@ -325,16 +314,6 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
b.CreateStore(getTlsAnchorPtr, b.CreateStructGEP(stype, record, i++)); b.CreateStore(getTlsAnchorPtr, b.CreateStructGEP(stype, record, i++));
} }
b.CreateStore(minfoUsedPointer, b.CreateStructGEP(stype, record, i++)); b.CreateStore(minfoUsedPointer, b.CreateStructGEP(stype, record, i++));
#else
b.CreateStore(version, b.CreateStructGEP(record, i++));
b.CreateStore(dsoSlot, b.CreateStructGEP(record, i++));
b.CreateStore(minfoBeg, b.CreateStructGEP(record, i++));
b.CreateStore(minfoEnd, b.CreateStructGEP(record, i++));
if (style == RegistryStyle::sectionDarwin) {
b.CreateStore(getTlsAnchorPtr, b.CreateStructGEP(record, i++));
}
b.CreateStore(minfoUsedPointer, b.CreateStructGEP(record, i++));
#endif
b.CreateCall(dsoRegistry, b.CreateBitCast(record, recordPtrTy)); b.CreateCall(dsoRegistry, b.CreateBitCast(record, recordPtrTy));
b.CreateBr(endBB); b.CreateBr(endBB);
@ -520,10 +499,7 @@ void addCoverageAnalysis(Module *m) {
d_cover_valid_slice = d_cover_valid_slice =
DtoConstSlice(DtoConstSize_t(type->getArrayNumElements()), DtoConstSlice(DtoConstSize_t(type->getArrayNumElements()),
llvm::ConstantExpr::getGetElementPtr( llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307 type, m->d_cover_valid, idxs, true));
type,
#endif
m->d_cover_valid, idxs, true));
// Assert that initializer array elements have enough bits // Assert that initializer array elements have enough bits
assert(sizeof(m->d_cover_valid_init[0]) * 8 >= assert(sizeof(m->d_cover_valid_init[0]) * 8 >=
@ -549,10 +525,7 @@ void addCoverageAnalysis(Module *m) {
d_cover_data_slice = d_cover_data_slice =
DtoConstSlice(DtoConstSize_t(type->getArrayNumElements()), DtoConstSlice(DtoConstSize_t(type->getArrayNumElements()),
llvm::ConstantExpr::getGetElementPtr( llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307 type, m->d_cover_data, idxs, true));
type,
#endif
m->d_cover_data, idxs, true));
} }
// Create "static constructor" that calls _d_cover_register2(string filename, // Create "static constructor" that calls _d_cover_register2(string filename,

View file

@ -121,11 +121,7 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
const auto idx = irLocal->nestedIndex; const auto idx = irLocal->nestedIndex;
assert(idx != -1 && "Nested context not yet resolved for variable."); assert(idx != -1 && "Nested context not yet resolved for variable.");
#if LDC_LLVM_VER >= 306 LLSmallVector<int64_t, 2> dwarfAddrOps;
LLSmallVector<int64_t, 2> dwarfAddrOps;
#else
LLSmallVector<LLValue *, 2> dwarfAddrOps;
#endif
LLValue *gep = DtoGEPi(val, 0, idx, vd->toChars()); LLValue *gep = DtoGEPi(val, 0, idx, vd->toChars());
val = gep; val = gep;
@ -501,11 +497,7 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
} }
if (global.params.symdebug) { if (global.params.symdebug) {
#if LDC_LLVM_VER >= 306
LLSmallVector<int64_t, 2> addr; LLSmallVector<int64_t, 2> addr;
#else
LLSmallVector<LLValue *, 2> addr;
#endif
// Because we are passing a GEP instead of an alloca to // Because we are passing a GEP instead of an alloca to
// llvm.dbg.declare, we have to make the address dereference explicit. // llvm.dbg.declare, we have to make the address dereference explicit.
gIR->DBuilder.OpDeref(addr); gIR->DBuilder.OpDeref(addr);

View file

@ -96,9 +96,6 @@ bool objc_isSupported(const llvm::Triple &triple) {
if (triple.isOSDarwin()) { if (triple.isOSDarwin()) {
// Objective-C only supported on Darwin at this time // Objective-C only supported on Darwin at this time
switch (triple.getArch()) { switch (triple.getArch()) {
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
#endif
case llvm::Triple::aarch64: // arm64 iOS, tvOS case llvm::Triple::aarch64: // arm64 iOS, tvOS
case llvm::Triple::arm: // armv6 iOS case llvm::Triple::arm: // armv6 iOS
case llvm::Triple::thumb: // thumbv7 iOS, watchOS case llvm::Triple::thumb: // thumbv7 iOS, watchOS

View file

@ -17,26 +17,16 @@
#include "driver/cl_options_sanitizers.h" #include "driver/cl_options_sanitizers.h"
#include "driver/targetmachine.h" #include "driver/targetmachine.h"
#include "llvm/LinkAllPasses.h" #include "llvm/LinkAllPasses.h"
#if LDC_LLVM_VER >= 307
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
#else
#include "llvm/PassManager.h"
#endif
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/DataLayout.h" #include "llvm/IR/DataLayout.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#if LDC_LLVM_VER >= 400 #if LDC_LLVM_VER >= 400
#include "llvm/Analysis/InlineCost.h" #include "llvm/Analysis/InlineCost.h"
#endif #endif
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/TargetTransformInfo.h"
#endif
#include "llvm/IR/Verifier.h" #include "llvm/IR/Verifier.h"
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#else
#include "llvm/Target/TargetLibraryInfo.h"
#endif
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/IR/LegacyPassNameParser.h" #include "llvm/IR/LegacyPassNameParser.h"
@ -93,8 +83,7 @@ static cl::opt<cl::boolOrDefault, false, opts::FlagParser<cl::boolOrDefault>>
static cl::opt<cl::boolOrDefault, false, opts::FlagParser<cl::boolOrDefault>> static cl::opt<cl::boolOrDefault, false, opts::FlagParser<cl::boolOrDefault>>
enableCrossModuleInlining( enableCrossModuleInlining(
"cross-module-inlining", cl::ZeroOrMore, cl::Hidden, "cross-module-inlining", cl::ZeroOrMore, cl::Hidden,
cl::desc("(*) Enable cross-module function inlining (default disabled) " cl::desc("(*) Enable cross-module function inlining (default disabled)"));
"(LLVM >= 3.7)"));
static cl::opt<bool> unitAtATime("unit-at-a-time", cl::desc("Enable basic IPO"), static cl::opt<bool> unitAtATime("unit-at-a-time", cl::desc("Enable basic IPO"),
cl::ZeroOrMore, cl::init(true)); cl::ZeroOrMore, cl::init(true));
@ -128,15 +117,7 @@ bool willInline() {
} }
bool willCrossModuleInline() { bool willCrossModuleInline() {
#if LDC_LLVM_VER >= 307
return enableCrossModuleInlining == llvm::cl::BOU_TRUE; return enableCrossModuleInlining == llvm::cl::BOU_TRUE;
#else
// Cross-module inlining is disabled for <3.7 because we don't emit symbols in
// COMDAT any groups pre-LLVM3.7. With cross-module inlining enabled, without
// COMDAT any there are multiple-def linker errors when linking druntime.
// See supportsCOMDAT().
return false;
#endif
} }
bool isOptimizationEnabled() { return optimizeLevel != 0; } bool isOptimizationEnabled() { return optimizeLevel != 0; }
@ -251,13 +232,8 @@ static void addPGOPasses(legacy::PassManagerBase &mpm, unsigned optLevel) {
* The selection mirrors Clang behavior and is based on LLVM's * The selection mirrors Clang behavior and is based on LLVM's
* PassManagerBuilder. * PassManagerBuilder.
*/ */
#if LDC_LLVM_VER >= 307
static void addOptimizationPasses(legacy::PassManagerBase &mpm, static void addOptimizationPasses(legacy::PassManagerBase &mpm,
legacy::FunctionPassManager &fpm, legacy::FunctionPassManager &fpm,
#else
static void addOptimizationPasses(PassManagerBase &mpm,
FunctionPassManager &fpm,
#endif
unsigned optLevel, unsigned sizeLevel) { unsigned optLevel, unsigned sizeLevel) {
if (!noVerify) { if (!noVerify) {
fpm.add(createVerifierPass()); fpm.add(createVerifierPass());
@ -358,12 +334,9 @@ static void addOptimizationPasses(PassManagerBase &mpm,
// This function runs optimization passes based on command line arguments. // This function runs optimization passes based on command line arguments.
// Returns true if any optimization passes were invoked. // Returns true if any optimization passes were invoked.
bool ldc_optimize_module(llvm::Module *M) { bool ldc_optimize_module(llvm::Module *M) {
// Create a PassManager to hold and optimize the collection of // Create a PassManager to hold and optimize the collection of
// per-module passes we are about to build. // per-module passes we are about to build.
#if LDC_LLVM_VER >= 307 legacy::PassManager mpm;
legacy::
#endif
PassManager mpm;
// Dont optimise spirv modules because turning GEPs into extracts triggers // Dont optimise spirv modules because turning GEPs into extracts triggers
// asserts in the IR -> SPIR-V translation pass. SPIRV doesn't have a target // asserts in the IR -> SPIR-V translation pass. SPIRV doesn't have a target
@ -375,7 +348,6 @@ bool ldc_optimize_module(llvm::Module *M) {
if (getComputeTargetType(M) == ComputeBackend::SPIRV) if (getComputeTargetType(M) == ComputeBackend::SPIRV)
return false; return false;
#if LDC_LLVM_VER >= 307
// Add an appropriate TargetLibraryInfo pass for the module's triple. // Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl *tlii = TargetLibraryInfoImpl *tlii =
new TargetLibraryInfoImpl(Triple(M->getTargetTriple())); new TargetLibraryInfoImpl(Triple(M->getTargetTriple()));
@ -385,59 +357,22 @@ bool ldc_optimize_module(llvm::Module *M) {
tlii->disableAllFunctions(); tlii->disableAllFunctions();
mpm.add(new TargetLibraryInfoWrapperPass(*tlii)); mpm.add(new TargetLibraryInfoWrapperPass(*tlii));
#else
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns. // The DataLayout is already set at the module (in module.cpp,
if (disableSimplifyLibCalls) { // method Module::genLLVMModule())
tli->disableAllFunctions(); // FIXME: Introduce new command line switch default-data-layout to
} // override the module data layout
mpm.add(tli);
#endif
// Add an appropriate DataLayout instance for this module.
#if LDC_LLVM_VER >= 307
// The DataLayout is already set at the module (in module.cpp,
// method Module::genLLVMModule())
// FIXME: Introduce new command line switch default-data-layout to
// override the module data layout
#elif LDC_LLVM_VER == 306
mpm.add(new DataLayoutPass());
#else
const DataLayout *DL = M->getDataLayout();
assert(DL &&
"DataLayout not set at module");
mpm.add(new DataLayoutPass(*DL));
#endif
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine. // Add internal analysis passes from the target machine.
mpm.add(createTargetTransformInfoWrapperPass( mpm.add(createTargetTransformInfoWrapperPass(
gTargetMachine->getTargetIRAnalysis())); gTargetMachine->getTargetIRAnalysis()));
#else
// Add internal analysis passes from the target machine.
gTargetMachine->addAnalysisPasses(mpm);
#endif
// Also set up a manager for the per-function passes. // Also set up a manager for the per-function passes.
#if LDC_LLVM_VER >= 307 legacy::FunctionPassManager fpm(M);
legacy::
#endif
FunctionPassManager fpm(M);
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine. // Add internal analysis passes from the target machine.
fpm.add(createTargetTransformInfoWrapperPass( fpm.add(createTargetTransformInfoWrapperPass(
gTargetMachine->getTargetIRAnalysis())); gTargetMachine->getTargetIRAnalysis()));
#elif LDC_LLVM_VER >= 306
fpm.add(new DataLayoutPass());
gTargetMachine->addAnalysisPasses(fpm);
#else
fpm.add(new DataLayoutPass(M));
gTargetMachine->addAnalysisPasses(fpm);
#endif
// If the -strip-debug command line option was specified, add it before // If the -strip-debug command line option was specified, add it before
// anything else. // anything else.

View file

@ -157,11 +157,7 @@ static bool isKnownLessThan(Value *Val, uint64_t Limit, const Analysis &A) {
} }
#else #else
APInt KnownZero(Bits, 0), KnownOne(Bits, 0); APInt KnownZero(Bits, 0), KnownOne(Bits, 0);
#if LDC_LLVM_VER >= 307
computeKnownBits(Val, KnownZero, KnownOne, A.DL); computeKnownBits(Val, KnownZero, KnownOne, A.DL);
#else
computeKnownBits(Val, KnownZero, KnownOne, &A.DL);
#endif
if ((KnownZero & Mask) != Mask) { if ((KnownZero & Mask) != Mask) {
return false; return false;
} }
@ -299,24 +295,15 @@ public:
return false; return false;
} }
// Inserting destructor calls is not implemented yet, so classes // Inserting destructor calls is not implemented yet, so classes
// with destructors are ignored for now. // with destructors are ignored for now.
#if LDC_LLVM_VER >= 306
auto hasDestructor = auto hasDestructor =
mdconst::dyn_extract<Constant>(node->getOperand(CD_Finalize)); mdconst::dyn_extract<Constant>(node->getOperand(CD_Finalize));
#else // We can't stack-allocate if the class has a custom deallocator
Constant *hasDestructor = dyn_cast<Constant>(node->getOperand(CD_Finalize)); // (Custom allocators don't get turned into this runtime call, so
#endif // those can be ignored)
// We can't stack-allocate if the class has a custom deallocator
// (Custom allocators don't get turned into this runtime call, so
// those can be ignored)
#if LDC_LLVM_VER >= 306
auto hasCustomDelete = auto hasCustomDelete =
mdconst::dyn_extract<Constant>(node->getOperand(CD_CustomDelete)); mdconst::dyn_extract<Constant>(node->getOperand(CD_CustomDelete));
#else
Constant *hasCustomDelete =
dyn_cast<Constant>(node->getOperand(CD_CustomDelete));
#endif
if (hasDestructor == nullptr || hasCustomDelete == nullptr) { if (hasDestructor == nullptr || hasCustomDelete == nullptr) {
return false; return false;
} }
@ -326,12 +313,8 @@ public:
return false; return false;
} }
#if LDC_LLVM_VER >= 306
Ty = mdconst::dyn_extract<Constant>(node->getOperand(CD_BodyType)) Ty = mdconst::dyn_extract<Constant>(node->getOperand(CD_BodyType))
->getType(); ->getType();
#else
Ty = node->getOperand(CD_BodyType)->getType();
#endif
return A.DL.getTypeAllocSize(Ty) < SizeLimit; return A.DL.getTypeAllocSize(Ty) < SizeLimit;
} }
@ -429,9 +412,6 @@ public:
bool runOnFunction(Function &F) override; bool runOnFunction(Function &F) override;
void getAnalysisUsage(AnalysisUsage &AU) const override { void getAnalysisUsage(AnalysisUsage &AU) const override {
#if LDC_LLVM_VER < 307
AU.addRequired<DataLayoutPass>();
#endif
AU.addRequired<DominatorTreeWrapperPass>(); AU.addRequired<DominatorTreeWrapperPass>();
AU.addPreserved<CallGraphWrapperPass>(); AU.addPreserved<CallGraphWrapperPass>();
} }
@ -488,19 +468,10 @@ isSafeToStackAllocate(BasicBlock::iterator Alloc, Value *V, DominatorTree &DT,
bool GarbageCollect2Stack::runOnFunction(Function &F) { bool GarbageCollect2Stack::runOnFunction(Function &F) {
DEBUG(errs() << "\nRunning -dgc2stack on function " << F.getName() << '\n'); DEBUG(errs() << "\nRunning -dgc2stack on function " << F.getName() << '\n');
#if LDC_LLVM_VER >= 307
const DataLayout &DL = F.getParent()->getDataLayout(); const DataLayout &DL = F.getParent()->getDataLayout();
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
CallGraphWrapperPass *CGPass = getAnalysisIfAvailable<CallGraphWrapperPass>(); CallGraphWrapperPass *CGPass = getAnalysisIfAvailable<CallGraphWrapperPass>();
CallGraph *CG = CGPass ? &CGPass->getCallGraph() : nullptr; CallGraph *CG = CGPass ? &CGPass->getCallGraph() : nullptr;
#else
DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
assert(DLP && "required DataLayoutPass is null");
const DataLayout &DL = DLP->getDataLayout();
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
CallGraphWrapperPass *CGPass = getAnalysisIfAvailable<CallGraphWrapperPass>();
CallGraph *CG = CGPass ? &CGPass->getCallGraph() : nullptr;
#endif
CallGraphNode *CGNode = CG ? (*CG)[&F] : nullptr; CallGraphNode *CGNode = CG ? (*CG)[&F] : nullptr;
Analysis A = {DL, *M, CG, CGNode}; Analysis A = {DL, *M, CG, CGNode};
@ -612,23 +583,15 @@ Type *Analysis::getTypeFor(Value *typeinfo) const {
return nullptr; return nullptr;
} }
#if LDC_LLVM_VER >= 306
Value *ti = llvm::MetadataAsValue::get(node->getContext(), Value *ti = llvm::MetadataAsValue::get(node->getContext(),
node->getOperand(TD_TypeInfo)); node->getOperand(TD_TypeInfo));
#else
Value *ti = node->getOperand(TD_TypeInfo);
#endif
if (!ti || ti->stripPointerCasts() != ti_global) { if (!ti || ti->stripPointerCasts() != ti_global) {
return nullptr; return nullptr;
} }
#if LDC_LLVM_VER >= 306
return llvm::MetadataAsValue::get(node->getContext(), return llvm::MetadataAsValue::get(node->getContext(),
node->getOperand(TD_Type)) node->getOperand(TD_Type))
->getType(); ->getType();
#else
return node->getOperand(TD_Type)->getType();
#endif
} }
/// Returns whether Def is used by any instruction that is reachable from Alloc /// Returns whether Def is used by any instruction that is reachable from Alloc
@ -756,11 +719,7 @@ static bool mayBeUsedAfterRealloc(Instruction *Def, BasicBlock::iterator Alloc,
// (meaning paths through it could lead to users), add the block and // (meaning paths through it could lead to users), add the block and
// the first non-phi to the worklist. // the first non-phi to the worklist.
if (!SeenDef if (!SeenDef
#if LDC_LLVM_VER >= 306
&& Visited.insert(Succ).second && Visited.insert(Succ).second
#else
&& Visited.insert(Succ)
#endif
&& DT.dominates(DefBlock, Succ)) { && DT.dominates(DefBlock, Succ)) {
Worklist.push_back(StartPoint(Succ, BBI)); Worklist.push_back(StartPoint(Succ, BBI));
} }
@ -928,11 +887,7 @@ bool isSafeToStackAllocate(BasicBlock::iterator Alloc, Value *V,
for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end(); for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end();
UI != UE; ++UI) { UI != UE; ++UI) {
Use *U = &(*UI); Use *U = &(*UI);
#if LDC_LLVM_VER >= 306
if (Visited.insert(U).second) { if (Visited.insert(U).second) {
#else
if (Visited.insert(U)) {
#endif
Worklist.push_back(U); Worklist.push_back(U);
} }
} }

View file

@ -18,9 +18,7 @@
#include "Passes.h" #include "Passes.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#if LDC_LLVM_VER >= 307
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#endif
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/Intrinsics.h" #include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
@ -327,11 +325,6 @@ public:
bool runOnce(Function &F, const DataLayout *DL, AliasAnalysisPass &AA); bool runOnce(Function &F, const DataLayout *DL, AliasAnalysisPass &AA);
void getAnalysisUsage(AnalysisUsage &AU) const override { void getAnalysisUsage(AnalysisUsage &AU) const override {
#if LDC_LLVM_VER >= 307
// The DataLayoutPass is removed.
#else
AU.addRequired<DataLayoutPass>();
#endif
AU.addRequired<AliasAnalysisPass>(); AU.addRequired<AliasAnalysisPass>();
} }
}; };
@ -382,12 +375,7 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) {
InitOptimizations(); InitOptimizations();
} }
#if LDC_LLVM_VER >= 307
const DataLayout *DL = &F.getParent()->getDataLayout(); const DataLayout *DL = &F.getParent()->getDataLayout();
#else
DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
#endif
AliasAnalysisPass &AA = getAnalysis<AliasAnalysisPass>(); AliasAnalysisPass &AA = getAnalysis<AliasAnalysisPass>();
// Iterate to catch opportunities opened up by other optimizations, // Iterate to catch opportunities opened up by other optimizations,

View file

@ -36,8 +36,7 @@ class ForStatement;
class ForeachStatement; class ForeachStatement;
class ForeachRangeStatement; class ForeachRangeStatement;
// Disable PGO for LLVM < 3.7, and provide stub CodeGenPGO class with its // Provide stub CodeGenPGO class with its public functions if PGO is disabled.
// public functions
#if !defined(LDC_WITH_PGO) #if !defined(LDC_WITH_PGO)
class CodeGenPGO { class CodeGenPGO {
public: public:

View file

@ -784,11 +784,7 @@ static void emitInstrumentationFn(const char *name) {
gIR->ir->CreateCall(GET_INTRINSIC_DECL(returnaddress), DtoConstInt(0)); gIR->ir->CreateCall(GET_INTRINSIC_DECL(returnaddress), DtoConstInt(0));
auto callee = DtoBitCast(gIR->topfunc(), getVoidPtrType()); auto callee = DtoBitCast(gIR->topfunc(), getVoidPtrType());
#if LDC_LLVM_VER >= 307
gIR->ir->CreateCall(fn, {callee, caller}); gIR->ir->CreateCall(fn, {callee, caller});
#else
gIR->ir->CreateCall2(fn, callee, caller);
#endif
} }
void emitInstrumentationFnEnter(FuncDeclaration *decl) { void emitInstrumentationFnEnter(FuncDeclaration *decl) {

View file

@ -189,12 +189,8 @@ public:
llvm::ConstantInt *zero = llvm::ConstantInt *zero =
LLConstantInt::get(LLType::getInt32Ty(gIR->context()), 0, false); LLConstantInt::get(LLType::getInt32Ty(gIR->context()), 0, false);
LLConstant *idxs[2] = {zero, zero}; LLConstant *idxs[2] = {zero, zero};
#if LDC_LLVM_VER >= 307
LLConstant *arrptr = llvm::ConstantExpr::getGetElementPtr( LLConstant *arrptr = llvm::ConstantExpr::getGetElementPtr(
isaPointer(gvar)->getElementType(), gvar, idxs, true); isaPointer(gvar)->getElementType(), gvar, idxs, true);
#else
LLConstant *arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, true);
#endif
if (t->ty == Tpointer) { if (t->ty == Tpointer) {
result = arrptr; result = arrptr;
@ -219,12 +215,8 @@ public:
if (t1b->ty == Tpointer && e->e2->type->isintegral()) { if (t1b->ty == Tpointer && e->e2->type->isintegral()) {
llvm::Constant *ptr = toConstElem(e->e1); llvm::Constant *ptr = toConstElem(e->e1);
dinteger_t idx = undoStrideMul(e->loc, t1b, e->e2->toInteger()); dinteger_t idx = undoStrideMul(e->loc, t1b, e->e2->toInteger());
#if LDC_LLVM_VER >= 307
result = llvm::ConstantExpr::getGetElementPtr( result = llvm::ConstantExpr::getGetElementPtr(
isaPointer(ptr)->getElementType(), ptr, DtoConstSize_t(idx)); isaPointer(ptr)->getElementType(), ptr, DtoConstSize_t(idx));
#else
result = llvm::ConstantExpr::getGetElementPtr(ptr, DtoConstSize_t(idx));
#endif
} else { } else {
e->error("expression '%s' is not a constant", e->toChars()); e->error("expression '%s' is not a constant", e->toChars());
if (!global.gag) { if (!global.gag) {
@ -245,12 +237,8 @@ public:
dinteger_t idx = undoStrideMul(e->loc, t1b, e->e2->toInteger()); dinteger_t idx = undoStrideMul(e->loc, t1b, e->e2->toInteger());
llvm::Constant *negIdx = llvm::ConstantExpr::getNeg(DtoConstSize_t(idx)); llvm::Constant *negIdx = llvm::ConstantExpr::getNeg(DtoConstSize_t(idx));
#if LDC_LLVM_VER >= 307
result = llvm::ConstantExpr::getGetElementPtr( result = llvm::ConstantExpr::getGetElementPtr(
isaPointer(ptr)->getElementType(), ptr, negIdx); isaPointer(ptr)->getElementType(), ptr, negIdx);
#else
result = llvm::ConstantExpr::getGetElementPtr(ptr, negIdx);
#endif
} else { } else {
e->error("expression '%s' is not a constant", e->toChars()); e->error("expression '%s' is not a constant", e->toChars());
if (!global.gag) { if (!global.gag) {
@ -304,12 +292,8 @@ public:
Type *type = vd->type->toBasetype(); Type *type = vd->type->toBasetype();
if (type->ty == Tarray || type->ty == Tdelegate) { if (type->ty == Tarray || type->ty == Tdelegate) {
LLConstant *idxs[2] = {DtoConstSize_t(0), DtoConstSize_t(1)}; LLConstant *idxs[2] = {DtoConstSize_t(0), DtoConstSize_t(1)};
#if LDC_LLVM_VER >= 307
value = llvm::ConstantExpr::getGetElementPtr( value = llvm::ConstantExpr::getGetElementPtr(
isaPointer(value)->getElementType(), value, idxs, true); isaPointer(value)->getElementType(), value, idxs, true);
#else
value = llvm::ConstantExpr::getGetElementPtr(value, idxs, true);
#endif
} }
result = DtoBitCast(value, DtoType(tb)); result = DtoBitCast(value, DtoType(tb));
} else if (tb->ty == Tclass && e->e1->type->ty == Tclass && } else if (tb->ty == Tclass && e->e1->type->ty == Tclass &&
@ -369,18 +353,12 @@ public:
if (e->offset % elemSize == 0) { if (e->offset % elemSize == 0) {
// We can turn this into a "nice" GEP. // We can turn this into a "nice" GEP.
result = llvm::ConstantExpr::getGetElementPtr( result = llvm::ConstantExpr::getGetElementPtr(nullptr,
#if LDC_LLVM_VER >= 307
nullptr,
#endif
base, DtoConstSize_t(e->offset / elemSize)); base, DtoConstSize_t(e->offset / elemSize));
} else { } else {
// Offset isn't a multiple of base type size, just cast to i8* and // Offset isn't a multiple of base type size, just cast to i8* and
// apply the byte offset. // apply the byte offset.
result = llvm::ConstantExpr::getGetElementPtr( result = llvm::ConstantExpr::getGetElementPtr(nullptr,
#if LDC_LLVM_VER >= 307
nullptr,
#endif
DtoBitCast(base, getVoidPtrType()), DtoConstSize_t(e->offset)); DtoBitCast(base, getVoidPtrType()), DtoConstSize_t(e->offset));
} }
} }
@ -424,12 +402,8 @@ public:
LLConstant *idxs[2] = {DtoConstSize_t(0), index}; LLConstant *idxs[2] = {DtoConstSize_t(0), index};
LLConstant *val = isaConstant(getIrGlobal(vd)->value); LLConstant *val = isaConstant(getIrGlobal(vd)->value);
val = DtoBitCast(val, DtoType(vd->type->pointerTo())); val = DtoBitCast(val, DtoType(vd->type->pointerTo()));
#if LDC_LLVM_VER >= 307
LLConstant *gep = llvm::ConstantExpr::getGetElementPtr( LLConstant *gep = llvm::ConstantExpr::getGetElementPtr(
isaPointer(val)->getElementType(), val, idxs, true); isaPointer(val)->getElementType(), val, idxs, true);
#else
LLConstant *gep = llvm::ConstantExpr::getGetElementPtr(val, idxs, true);
#endif
// bitcast to requested type // bitcast to requested type
assert(e->type->toBasetype()->ty == Tpointer); assert(e->type->toBasetype()->ty == Tpointer);
@ -553,13 +527,8 @@ public:
// build a constant dynamic array reference with the .ptr field pointing // build a constant dynamic array reference with the .ptr field pointing
// into store // into store
LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)}; LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)};
#if LDC_LLVM_VER >= 307
LLConstant *globalstorePtr = llvm::ConstantExpr::getGetElementPtr( LLConstant *globalstorePtr = llvm::ConstantExpr::getGetElementPtr(
isaPointer(store)->getElementType(), store, idxs, true); isaPointer(store)->getElementType(), store, idxs, true);
#else
LLConstant *globalstorePtr =
llvm::ConstantExpr::getGetElementPtr(store, idxs, true);
#endif
result = DtoConstSlice(DtoConstSize_t(e->elements->dim), globalstorePtr); result = DtoConstSlice(DtoConstSize_t(e->elements->dim), globalstorePtr);
} }

View file

@ -414,12 +414,8 @@ public:
llvm::ConstantInt *zero = llvm::ConstantInt *zero =
LLConstantInt::get(LLType::getInt32Ty(gIR->context()), 0, false); LLConstantInt::get(LLType::getInt32Ty(gIR->context()), 0, false);
LLConstant *idxs[2] = {zero, zero}; LLConstant *idxs[2] = {zero, zero};
#if LDC_LLVM_VER >= 307
LLConstant *arrptr = llvm::ConstantExpr::getGetElementPtr( LLConstant *arrptr = llvm::ConstantExpr::getGetElementPtr(
isaPointer(gvar)->getElementType(), gvar, idxs, true); isaPointer(gvar)->getElementType(), gvar, idxs, true);
#else
LLConstant *arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, true);
#endif
if (dtype->ty == Tarray) { if (dtype->ty == Tarray) {
LLConstant *clen = LLConstant *clen =
@ -1865,11 +1861,7 @@ public:
IF_LOG Logger::print("HaltExp::toElem: %s\n", e->toChars()); IF_LOG Logger::print("HaltExp::toElem: %s\n", e->toChars());
LOG_SCOPE; LOG_SCOPE;
#if LDC_LLVM_VER >= 307
p->ir->CreateCall(GET_INTRINSIC_DECL(trap), {}); p->ir->CreateCall(GET_INTRINSIC_DECL(trap), {});
#else
p->ir->CreateCall(GET_INTRINSIC_DECL(trap), "");
#endif
p->ir->CreateUnreachable(); p->ir->CreateUnreachable();
// this terminated the basicblock, start a new one // this terminated the basicblock, start a new one
@ -2469,13 +2461,8 @@ public:
LLConstant *globalstore = new LLGlobalVariable( LLConstant *globalstore = new LLGlobalVariable(
gIR->module, initval->getType(), false, gIR->module, initval->getType(), false,
LLGlobalValue::InternalLinkage, initval, ".aaKeysStorage"); LLGlobalValue::InternalLinkage, initval, ".aaKeysStorage");
#if LDC_LLVM_VER >= 307
LLConstant *slice = llvm::ConstantExpr::getGetElementPtr( LLConstant *slice = llvm::ConstantExpr::getGetElementPtr(
isaPointer(globalstore)->getElementType(), globalstore, idxs, true); isaPointer(globalstore)->getElementType(), globalstore, idxs, true);
#else
LLConstant *slice =
llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, true);
#endif
slice = DtoConstSlice(DtoConstSize_t(e->keys->dim), slice); slice = DtoConstSlice(DtoConstSize_t(e->keys->dim), slice);
LLValue *keysArray = DtoAggrPaint(slice, funcTy->getParamType(1)); LLValue *keysArray = DtoAggrPaint(slice, funcTy->getParamType(1));
@ -2483,12 +2470,8 @@ public:
globalstore = new LLGlobalVariable(gIR->module, initval->getType(), false, globalstore = new LLGlobalVariable(gIR->module, initval->getType(), false,
LLGlobalValue::InternalLinkage, LLGlobalValue::InternalLinkage,
initval, ".aaValuesStorage"); initval, ".aaValuesStorage");
#if LDC_LLVM_VER >= 307
slice = llvm::ConstantExpr::getGetElementPtr( slice = llvm::ConstantExpr::getGetElementPtr(
isaPointer(globalstore)->getElementType(), globalstore, idxs, true); isaPointer(globalstore)->getElementType(), globalstore, idxs, true);
#else
slice = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, true);
#endif
slice = DtoConstSlice(DtoConstSize_t(e->keys->dim), slice); slice = DtoConstSlice(DtoConstSize_t(e->keys->dim), slice);
LLValue *valuesArray = DtoAggrPaint(slice, funcTy->getParamType(2)); LLValue *valuesArray = DtoAggrPaint(slice, funcTy->getParamType(2));

View file

@ -234,11 +234,7 @@ LinkageWithCOMDAT DtoLinkage(Dsymbol *sym) {
} }
bool supportsCOMDAT() { bool supportsCOMDAT() {
#if LDC_LLVM_VER >= 307
return !global.params.targetTriple->isOSBinFormatMachO(); return !global.params.targetTriple->isOSBinFormatMachO();
#else
return false;
#endif
} }
void setLinkage(LinkageWithCOMDAT lwc, llvm::GlobalObject *obj) { void setLinkage(LinkageWithCOMDAT lwc, llvm::GlobalObject *obj) {
@ -282,10 +278,7 @@ llvm::GetElementPtrInst *DtoGEP(LLValue *ptr, llvm::ArrayRef<LLValue *> indices,
(void)p; (void)p;
assert(p && "GEP expects a pointer type"); assert(p && "GEP expects a pointer type");
auto gep = llvm::GetElementPtrInst::Create( auto gep = llvm::GetElementPtrInst::Create(
#if LDC_LLVM_VER >= 307 p->getElementType(), ptr, indices, name, bb ? bb : gIR->scopebb());
p->getElementType(),
#endif
ptr, indices, name, bb ? bb : gIR->scopebb());
gep->setIsInBounds(inBounds); gep->setIsInBounds(inBounds);
return gep; return gep;
} }
@ -319,10 +312,7 @@ LLConstant *DtoGEPi(LLConstant *ptr, unsigned i0, unsigned i1) {
assert(p && "GEP expects a pointer type"); assert(p && "GEP expects a pointer type");
LLValue *indices[] = {DtoConstUint(i0), DtoConstUint(i1)}; LLValue *indices[] = {DtoConstUint(i0), DtoConstUint(i1)};
return llvm::ConstantExpr::getGetElementPtr( return llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307 p->getElementType(), ptr, indices, /* InBounds = */ true);
p->getElementType(),
#endif
ptr, indices, /* InBounds = */ true);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -382,11 +372,7 @@ LLValue *DtoMemCmp(LLValue *lhs, LLValue *rhs, LLValue *nbytes) {
lhs = DtoBitCast(lhs, VoidPtrTy); lhs = DtoBitCast(lhs, VoidPtrTy);
rhs = DtoBitCast(rhs, VoidPtrTy); rhs = DtoBitCast(rhs, VoidPtrTy);
#if LDC_LLVM_VER >= 307
return gIR->ir->CreateCall(fn, {lhs, rhs, nbytes}); return gIR->ir->CreateCall(fn, {lhs, rhs, nbytes});
#else
return gIR->ir->CreateCall3(fn, lhs, rhs, nbytes);
#endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -465,9 +451,7 @@ LLConstant *DtoConstString(const char *str) {
LLConstant *idxs[] = {DtoConstUint(0), DtoConstUint(0)}; LLConstant *idxs[] = {DtoConstUint(0), DtoConstUint(0)};
return DtoConstSlice(DtoConstSize_t(s.size()), return DtoConstSlice(DtoConstSize_t(s.size()),
llvm::ConstantExpr::getGetElementPtr( llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
gvar->getInitializer()->getType(), gvar->getInitializer()->getType(),
#endif
gvar, idxs, true), gvar, idxs, true),
Type::tchar->arrayOf()); Type::tchar->arrayOf());
} }

View file

@ -628,17 +628,11 @@ namespace {
, nullptr , nullptr
#endif #endif
); );
#if LDC_LLVM_VER >= 307
if (!irs.func()->hasLLVMPersonalityFn()) { if (!irs.func()->hasLLVMPersonalityFn()) {
irs.func()->setLLVMPersonalityFn( irs.func()->setLLVMPersonalityFn(
getRuntimeFunction(Loc(), irs.module, "_d_eh_personality")); getRuntimeFunction(Loc(), irs.module, "_d_eh_personality"));
} }
return irs.ir->CreateLandingPad(retType, 0); return irs.ir->CreateLandingPad(retType, 0);
#else
LLFunction *personalityFn =
getRuntimeFunction(Loc(), irs.module, "_d_eh_personality");
return irs.ir->CreateLandingPad(retType, personalityFn, 0);
#endif
} }
} }

View file

@ -93,17 +93,11 @@ static void emitTypeMetadata(TypeInfoDeclaration *tid) {
llvm::NamedMDNode *meta = gIR->module.getNamedMetadata(metaname); llvm::NamedMDNode *meta = gIR->module.getNamedMetadata(metaname);
if (!meta) { if (!meta) {
// Construct the fields // Construct the fields
#if LDC_LLVM_VER >= 306
llvm::Metadata *mdVals[TD_NumFields]; llvm::Metadata *mdVals[TD_NumFields];
mdVals[TD_TypeInfo] = llvm::ValueAsMetadata::get(getIrGlobal(tid)->value); mdVals[TD_TypeInfo] = llvm::ValueAsMetadata::get(getIrGlobal(tid)->value);
mdVals[TD_Type] = llvm::ConstantAsMetadata::get( mdVals[TD_Type] = llvm::ConstantAsMetadata::get(
llvm::UndefValue::get(DtoType(tid->tinfo))); llvm::UndefValue::get(DtoType(tid->tinfo)));
#else
MDNodeField *mdVals[TD_NumFields];
mdVals[TD_TypeInfo] = llvm::cast<MDNodeField>(getIrGlobal(tid)->value);
mdVals[TD_Type] = llvm::UndefValue::get(DtoType(tid->tinfo));
#endif
// Construct the metadata and insert it into the module. // Construct the metadata and insert it into the module.
llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata(metaname); llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata(metaname);

View file

@ -89,8 +89,7 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
LLType *bodyType = llvm::cast<LLPointerType>(type)->getElementType(); LLType *bodyType = llvm::cast<LLPointerType>(type)->getElementType();
bool hasDestructor = (classdecl->dtor != nullptr); bool hasDestructor = (classdecl->dtor != nullptr);
bool hasCustomDelete = (classdecl->aggDelete != nullptr); bool hasCustomDelete = (classdecl->aggDelete != nullptr);
// Construct the fields // Construct the fields
#if LDC_LLVM_VER >= 306
llvm::Metadata *mdVals[CD_NumFields]; llvm::Metadata *mdVals[CD_NumFields];
mdVals[CD_BodyType] = mdVals[CD_BodyType] =
llvm::ConstantAsMetadata::get(llvm::UndefValue::get(bodyType)); llvm::ConstantAsMetadata::get(llvm::UndefValue::get(bodyType));
@ -98,14 +97,6 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasDestructor)); LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasDestructor));
mdVals[CD_CustomDelete] = llvm::ConstantAsMetadata::get( mdVals[CD_CustomDelete] = llvm::ConstantAsMetadata::get(
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasCustomDelete)); LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasCustomDelete));
#else
MDNodeField *mdVals[CD_NumFields];
mdVals[CD_BodyType] = llvm::UndefValue::get(bodyType);
mdVals[CD_Finalize] =
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasDestructor);
mdVals[CD_CustomDelete] =
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasCustomDelete);
#endif
// Construct the metadata and insert it into the module. // Construct the metadata and insert it into the module.
llvm::SmallString<64> name; llvm::SmallString<64> name;
llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata( llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata(
@ -286,9 +277,7 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
llvm::GlobalVariable *interfaceInfosZ = getInterfaceArraySymbol(); llvm::GlobalVariable *interfaceInfosZ = getInterfaceArraySymbol();
llvm::Constant *c = llvm::ConstantExpr::getGetElementPtr( llvm::Constant *c = llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
isaPointer(interfaceInfosZ)->getElementType(), isaPointer(interfaceInfosZ)->getElementType(),
#endif
interfaceInfosZ, idxs, true); interfaceInfosZ, idxs, true);
constants.push_back(DtoBitCast(c, voidPtrTy)); constants.push_back(DtoBitCast(c, voidPtrTy));
@ -360,10 +349,8 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
thunk->setUnnamedAddr(true); thunk->setUnnamedAddr(true);
#endif #endif
#if LDC_LLVM_VER >= 307
// thunks don't need exception handling themselves // thunks don't need exception handling themselves
thunk->setPersonalityFn(nullptr); thunk->setPersonalityFn(nullptr);
#endif
// It is necessary to add debug information to the thunk in case it is // It is necessary to add debug information to the thunk in case it is
// subject to inlining. See https://llvm.org/bugs/show_bug.cgi?id=26833 // subject to inlining. See https://llvm.org/bugs/show_bug.cgi?id=26833
@ -564,10 +551,7 @@ LLConstant *IrAggr::getClassInfoInterfaces() {
DtoConstSize_t(n - cd->vtblInterfaces->dim)}; DtoConstSize_t(n - cd->vtblInterfaces->dim)};
LLConstant *ptr = llvm::ConstantExpr::getGetElementPtr( LLConstant *ptr = llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307 isaPointer(ciarr)->getElementType(), ciarr, idxs, true);
isaPointer(ciarr)->getElementType(),
#endif
ciarr, idxs, true);
// return as a slice // return as a slice
return DtoConstSlice(DtoConstSize_t(cd->vtblInterfaces->dim), ptr); return DtoConstSlice(DtoConstSize_t(cd->vtblInterfaces->dim), ptr);

View file

@ -57,7 +57,6 @@ llvm::FunctionType *IrFunction::getLLVMFuncType() const {
return func->getFunctionType(); return func->getFunctionType();
} }
#if LDC_LLVM_VER >= 307
bool IrFunction::hasLLVMPersonalityFn() const { bool IrFunction::hasLLVMPersonalityFn() const {
assert(func != nullptr); assert(func != nullptr);
return func->hasPersonalityFn(); return func->hasPersonalityFn();
@ -67,7 +66,6 @@ void IrFunction::setLLVMPersonalityFn(llvm::Constant *personality) {
assert(func != nullptr); assert(func != nullptr);
func->setPersonalityFn(personality); func->setPersonalityFn(personality);
} }
#endif
llvm::StringRef IrFunction::getLLVMFuncName() const { llvm::StringRef IrFunction::getLLVMFuncName() const {
assert(func != nullptr); assert(func != nullptr);

View file

@ -43,10 +43,8 @@ struct IrFunction {
llvm::FunctionType *getLLVMFuncType() const; llvm::FunctionType *getLLVMFuncType() const;
llvm::StringRef getLLVMFuncName() const; llvm::StringRef getLLVMFuncName() const;
#if LDC_LLVM_VER >= 307
bool hasLLVMPersonalityFn() const; bool hasLLVMPersonalityFn() const;
void setLLVMPersonalityFn(llvm::Constant *personality); void setLLVMPersonalityFn(llvm::Constant *personality);
#endif
/// Returns the associated LLVM function to be used for calls (potentially /// Returns the associated LLVM function to be used for calls (potentially
/// some sort of wrapper, e.g., a JIT wrapper). /// some sort of wrapper, e.g., a JIT wrapper).
@ -71,15 +69,9 @@ struct IrFunction {
llvm::Value *_arguments = nullptr; llvm::Value *_arguments = nullptr;
llvm::Value *_argptr = nullptr; llvm::Value *_argptr = nullptr;
#if LDC_LLVM_VER >= 307
llvm::DISubprogram *diSubprogram = nullptr; llvm::DISubprogram *diSubprogram = nullptr;
std::stack<llvm::DILexicalBlock *> diLexicalBlocks; std::stack<llvm::DILexicalBlock *> diLexicalBlocks;
using VariableMap = llvm::DenseMap<VarDeclaration *, llvm::DILocalVariable *>; using VariableMap = llvm::DenseMap<VarDeclaration *, llvm::DILocalVariable *>;
#else
llvm::DISubprogram diSubprogram;
std::stack<llvm::DILexicalBlock> diLexicalBlocks;
using VariableMap = llvm::DenseMap<VarDeclaration *, llvm::DIVariable>;
#endif
// Debug info for all variables // Debug info for all variables
VariableMap variableMap; VariableMap variableMap;

View file

@ -49,11 +49,7 @@ namespace {
llvm::Type *getReal80Type(llvm::LLVMContext &ctx) { llvm::Type *getReal80Type(llvm::LLVMContext &ctx) {
llvm::Triple::ArchType const a = global.params.targetTriple->getArch(); llvm::Triple::ArchType const a = global.params.targetTriple->getArch();
bool const anyX86 = (a == llvm::Triple::x86) || (a == llvm::Triple::x86_64); bool const anyX86 = (a == llvm::Triple::x86) || (a == llvm::Triple::x86_64);
bool const anyAarch64 = (a == llvm::Triple::aarch64) || (a == llvm::Triple::aarch64_be) bool const anyAarch64 = (a == llvm::Triple::aarch64) || (a == llvm::Triple::aarch64_be);
#if LDC_LLVM_VER == 305
|| (a == llvm::Triple::arm64) || (a == llvm::Triple::arm64_be)
#endif
;
// only x86 has 80bit float - but no support with MS C Runtime! // only x86 has 80bit float - but no support with MS C Runtime!
if (anyX86 && !global.params.targetTriple->isWindowsMSVCEnvironment()) { if (anyX86 && !global.params.targetTriple->isWindowsMSVCEnvironment()) {

View file

@ -67,13 +67,9 @@ public:
void getMemberLocation(VarDeclaration *var, unsigned &fieldIndex, void getMemberLocation(VarDeclaration *var, unsigned &fieldIndex,
unsigned &byteOffset) const; unsigned &byteOffset) const;
/// Composite type debug description. This is not only to cache, but also /// Composite type debug description. This is not only to cache, but also
/// used for resolving forward references. /// used for resolving forward references.
#if LDC_LLVM_VER >= 307
llvm::DIType *diCompositeType = nullptr; llvm::DIType *diCompositeType = nullptr;
#else
llvm::DIType diCompositeType;
#endif
/// true, if the LLVM struct type for the aggregate is declared as packed /// true, if the LLVM struct type for the aggregate is declared as packed
bool packed = false; bool packed = false;

@ -1 +1 @@
Subproject commit cc9335131218cf157af7e562309b64e5b0c51bb3 Subproject commit 6d022a76273fc1ac89184f02ad50b2f85e2f2da2

View file

@ -1,6 +1,5 @@
// Tests @target attribute for x86 // Tests @target attribute for x86
// REQUIRES: atleast_llvm307
// REQUIRES: target_X86 // REQUIRES: target_X86
// RUN: %ldc -O -c -mcpu=i386 -mtriple=i386-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll // RUN: %ldc -O -c -mcpu=i386 -mtriple=i386-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll

View file

@ -1,7 +1,5 @@
// See Github issue #1860 // See Github issue #1860
// REQUIRES: atleast_llvm307
// RUN: %ldc -c -output-ll -of=%t.ll -float-abi=soft %s && FileCheck --check-prefix=SOFT %s < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll -float-abi=soft %s && FileCheck --check-prefix=SOFT %s < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll -float-abi=softfp %s && FileCheck --check-prefix=HARD %s < %t.ll // RUN: %ldc -c -output-ll -of=%t.ll -float-abi=softfp %s && FileCheck --check-prefix=HARD %s < %t.ll

View file

@ -1,7 +1,5 @@
// Make sure exported functions can be cross-module inlined without exporting the local function copy. // Make sure exported functions can be cross-module inlined without exporting the local function copy.
// REQUIRES: atleast_llvm307
// RUN: %ldc -O -release -enable-cross-module-inlining -output-ll -of=%t.ll -I%S/inputs %s // RUN: %ldc -O -release -enable-cross-module-inlining -output-ll -of=%t.ll -I%S/inputs %s
// RUN: FileCheck %s < %t.ll // RUN: FileCheck %s < %t.ll

View file

@ -1,7 +1,5 @@
// Test disabling/enabling of cross-module inlining // Test disabling/enabling of cross-module inlining
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -I%S -c -output-ll -enable-cross-module-inlining -O0 -of=%t.ENA.ll && FileCheck %s --check-prefix ENABLED < %t.ENA.ll // RUN: %ldc %s -I%S -c -output-ll -enable-cross-module-inlining -O0 -of=%t.ENA.ll && FileCheck %s --check-prefix ENABLED < %t.ENA.ll
// RUN: %ldc %s -I%S -c -output-ll -disable-cross-module-inlining -O3 -of=%t.DIS.ll && FileCheck %s --check-prefix DISABLED < %t.DIS.ll // RUN: %ldc %s -I%S -c -output-ll -disable-cross-module-inlining -O3 -of=%t.DIS.ll && FileCheck %s --check-prefix DISABLED < %t.DIS.ll

View file

@ -1,7 +1,5 @@
// Test inlining of imported functions // Test inlining of imported functions
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll
import inputs.inlinables; import inputs.inlinables;

View file

@ -5,8 +5,6 @@
// FIXME: Currently cross-module inlining is completely disabled per default, also for pragma(inline,true) functions. // FIXME: Currently cross-module inlining is completely disabled per default, also for pragma(inline,true) functions.
// The `-enable-cross-module-inlining` flag is therefore necessary for now, but should be removed in the future. // The `-enable-cross-module-inlining` flag is therefore necessary for now, but should be removed in the future.
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -I%S -c -output-ll -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPTNONE < %t.O0.ll // RUN: %ldc %s -I%S -c -output-ll -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPTNONE < %t.O0.ll
// RUN: %ldc %s -I%S -c -output-ll -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -I%S -c -output-ll -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll

View file

@ -1,8 +1,6 @@
// Test that inlining does not leak definitions without marking them as available_externally // Test that inlining does not leak definitions without marking them as available_externally
// "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols). // "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols).
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll
// RUN: %ldc %s -I%S -c -output-ll -release -enable-inlining -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc %s -I%S -c -output-ll -release -enable-inlining -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll
// RUN: %ldc -I%S -enable-inlining -enable-cross-module-inlining %S/inputs/inlinables.d -run %s // RUN: %ldc -I%S -enable-inlining -enable-cross-module-inlining %S/inputs/inlinables.d -run %s

View file

@ -2,7 +2,6 @@
// "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols). // "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols).
// REQUIRES: target_X86 // REQUIRES: target_X86
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -mtriple=x86_64-linux-gnu -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -mtriple=x86_64-linux-gnu -I%S -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll
// RUN: %ldc %s -mtriple=x86_64-linux-gnu -I%S -c -output-ll -release -enable-inlining -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc %s -mtriple=x86_64-linux-gnu -I%S -c -output-ll -release -enable-inlining -O0 -enable-cross-module-inlining -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll

View file

@ -1,7 +1,5 @@
// Test cross-module inlining involving static variables // Test cross-module inlining involving static variables
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -I%S -c -output-ll -O3 -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -I%S -c -output-ll -O3 -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll
// RUN: %ldc %s -I%S -c -output-ll -enable-inlining -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc %s -I%S -c -output-ll -enable-inlining -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll
// RUN: %ldc -I%S -enable-inlining %S/inputs/inlinables_staticvar.d -run %s // RUN: %ldc -I%S -enable-inlining %S/inputs/inlinables_staticvar.d -run %s

View file

@ -1,7 +1,5 @@
// Test inlining of some standard library functions // Test inlining of some standard library functions
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -c -output-ll -release -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll // RUN: %ldc %s -c -output-ll -release -O0 -of=%t.O0.ll && FileCheck %s --check-prefix OPT0 < %t.O0.ll
// RUN: %ldc %s -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll // RUN: %ldc %s -c -output-ll -release -O3 -enable-cross-module-inlining -of=%t.O3.ll && FileCheck %s --check-prefix OPT3 < %t.O3.ll

View file

@ -1,8 +1,6 @@
// Test inlining of templates // Test inlining of templates
// Templates that would otherwise not be codegenned, _should_ be codegenned for inlining when pragma(inline, true) is specified. // Templates that would otherwise not be codegenned, _should_ be codegenned for inlining when pragma(inline, true) is specified.
// REQUIRES: atleast_llvm307
// RUN: %ldc %s -I%S -c -output-ll -release -enable-inlining -enable-cross-module-inlining -O0 -of=%t.O0.ll && FileCheck %s < %t.O0.ll // RUN: %ldc %s -I%S -c -output-ll -release -enable-inlining -enable-cross-module-inlining -O0 -of=%t.O0.ll && FileCheck %s < %t.O0.ll
// RUN: %ldc -singleobj %S/inputs/inlinables.d %s -I%S -c -output-ll -release -enable-inlining -enable-cross-module-inlining -O0 -of=%t.singleobj.O0.ll && FileCheck %s < %t.singleobj.O0.ll // RUN: %ldc -singleobj %S/inputs/inlinables.d %s -I%S -c -output-ll -release -enable-inlining -enable-cross-module-inlining -O0 -of=%t.singleobj.O0.ll && FileCheck %s < %t.singleobj.O0.ll

@ -1 +1 @@
Subproject commit e3a00505f911dd2785d4e12e83ee39fb5aed050e Subproject commit 166806af590c2c2c0b12ddf143253e4b74c048f8

View file

@ -1,27 +0,0 @@
// Tests debug info generation for nested functions
// REQUIRES: atmost_llvm306
// RUN: %ldc -g -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll
// CHECK-LABEL: define {{.*}} @_D{{.*}}8encloserFiiZv
void encloser(int arg0, int arg1)
{
// CHECK: @llvm.dbg.declare{{.*}}%enc_n{{.*}}enc_n
int enc_n;
// CHECK-LABEL: define {{.*}} @_D{{.*}}encloser{{.*}}nested
void nested(int nes_i)
{
// CHECK: %arg0 = getelementptr inbounds %nest.encloser
// CHECK: @llvm.dbg.declare{{.*}}%arg0
// CHECK: %arg1 = getelementptr inbounds %nest.encloser
// CHECK: @llvm.dbg.declare{{.*}}%arg1
// CHECK: %enc_n = getelementptr inbounds %nest.encloser
// CHECK: @llvm.dbg.declare{{.*}}%enc_n
arg0 = arg1 = enc_n = nes_i; // accessing arg0, arg1 and enc_n from a nested function turns them into closure variables
}
}
// CHECK: @_D{{.*}}8encloserFiiZv{{.*}}DW_TAG_subprogram
// CHECK: @_D{{.*}}8encloserFiiZ6nested{{.*}}DW_TAG_subprogram
// CHECK: nes_i{{.*}}DW_TAG_arg_variable
// CHECK: arg1{{.*}}DW_TAG_auto_variable

View file

@ -1,7 +1,5 @@
// Test linking with an LLVM bitcode file // Test linking with an LLVM bitcode file
// REQUIRES: atleast_llvm306
// RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input.d -of=%t.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input.d -of=%t.bc
// RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_import.d -of=%t2.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_import.d -of=%t2.bc
// RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input3.d -of=%t3.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input3.d -of=%t3.bc

View file

@ -1,6 +1,5 @@
// Test passing of LLVM bitcode file with Linker Options set // Test passing of LLVM bitcode file with Linker Options set
// REQUIRES: atleast_llvm306
// LLVM >= 5.0 uses llvm.linker.options instead. See link_bitcode_libs_500.d. // LLVM >= 5.0 uses llvm.linker.options instead. See link_bitcode_libs_500.d.
// REQUIRES: atmost_llvm400 // REQUIRES: atmost_llvm400

View file

@ -51,7 +51,7 @@ config.available_features.add("llvm%d" % config.llvm_version)
# config.llvm_version: 308, 309, 400, 500, ... # config.llvm_version: 308, 309, 400, 500, ...
# plusoneable_llvmversion: 38, 39, 40, 50, ... # plusoneable_llvmversion: 38, 39, 40, 50, ...
plusoneable_llvmversion = config.llvm_version // 10 + config.llvm_version%10 plusoneable_llvmversion = config.llvm_version // 10 + config.llvm_version%10
for version in range(35, plusoneable_llvmversion+1): for version in range(37, plusoneable_llvmversion+1):
config.available_features.add("atleast_llvm%d0%d" % (version//10, version%10)) config.available_features.add("atleast_llvm%d0%d" % (version//10, version%10))
for version in range(plusoneable_llvmversion, 91): for version in range(plusoneable_llvmversion, 91):
config.available_features.add("atmost_llvm%d0%d" % (version//10, version%10)) config.available_features.add("atmost_llvm%d0%d" % (version//10, version%10))

View file

@ -8,44 +8,25 @@
// Important: LLVM's default CPU selection already enables some features (like sse3) // Important: LLVM's default CPU selection already enables some features (like sse3)
// Querying feature information is only available from LLVM 3.7.
// Below 3.7, __traits(targetHasFeature,...) should always return false.
version (LDC_LLVM_305)
{
}
else version (LDC_LLVM_306)
{
}
else
{
version = HASFEATURE;
}
void main() void main()
{ {
version (CPU_HASWELL) version (CPU_HASWELL)
{ {
static assert(__traits(targetCPU) == "haswell"); static assert(__traits(targetCPU) == "haswell");
version (HASFEATURE) static assert(__traits(targetHasFeature, "sse3"));
{ static assert(__traits(targetHasFeature, "sse4.1"));
static assert(__traits(targetHasFeature, "sse3"));
static assert(__traits(targetHasFeature, "sse4.1"));
}
static assert(!__traits(targetHasFeature, "sse4")); static assert(!__traits(targetHasFeature, "sse4"));
static assert(!__traits(targetHasFeature, "sse4a")); static assert(!__traits(targetHasFeature, "sse4a"));
static assert(!__traits(targetHasFeature, "unrecognized feature")); static assert(!__traits(targetHasFeature, "unrecognized feature"));
} }
version (ATTR_FMA) version (ATTR_FMA)
{ {
version (HASFEATURE) static assert(__traits(targetHasFeature, "sse"));
{ static assert(__traits(targetHasFeature, "sse2"));
static assert(__traits(targetHasFeature, "sse")); static assert(__traits(targetHasFeature, "sse3"));
static assert(__traits(targetHasFeature, "sse2")); static assert(__traits(targetHasFeature, "sse4.1"));
static assert(__traits(targetHasFeature, "sse3")); static assert(__traits(targetHasFeature, "fma"));
static assert(__traits(targetHasFeature, "sse4.1")); static assert(__traits(targetHasFeature, "avx"));
static assert(__traits(targetHasFeature, "fma"));
static assert(__traits(targetHasFeature, "avx"));
}
static assert(!__traits(targetHasFeature, "avx2")); static assert(!__traits(targetHasFeature, "avx2"));
static assert(!__traits(targetHasFeature, "unrecognized feature")); static assert(!__traits(targetHasFeature, "unrecognized feature"));
} }

View file

@ -16,10 +16,7 @@ void main()
// CHECK: Error: string expected as argument of __traits targetHasFeature instead of 1 // CHECK: Error: string expected as argument of __traits targetHasFeature instead of 1
enum e = __traits(targetHasFeature, 1); enum e = __traits(targetHasFeature, 1);
// Diagnostics of an unrecognized feature depends on the LLVM version (LLVM < 3.7 does not warn at all) // CHECK: 夜畔' is not a recognized feature for this target (ignoring feature)
// Newer LLVM versions do warn.
// TODO: Re-enable test when LLVM < 3.7 is no longer supported.
// CHE CK: 夜畔' is not a recognized feature for this target (ignoring feature)
enum f = __traits(targetHasFeature, "夜畔"); enum f = __traits(targetHasFeature, "夜畔");
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -83,11 +83,7 @@ string dtype(Record* rec, bool readOnlyMem)
string attributes(ListInit* propertyList) string attributes(ListInit* propertyList)
{ {
string prop = string prop =
#if LDC_LLVM_VER >= 307
propertyList->size() propertyList->size()
#else
propertyList->getSize()
#endif
? propertyList->getElementAsRecord(0)->getName() : ""; ? propertyList->getElementAsRecord(0)->getName() : "";
return return
@ -117,24 +113,14 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
ListInit* propsList = rec.getValueAsListInit("Properties"); ListInit* propsList = rec.getValueAsListInit("Properties");
#endif #endif
string prop = string prop =
#if LDC_LLVM_VER >= 307
propsList->size() propsList->size()
#else
propsList->getSize()
#endif
? propsList->getElementAsRecord(0)->getName() : ""; ? propsList->getElementAsRecord(0)->getName() : "";
bool readOnlyMem = prop == "IntrReadArgMem" || prop == "IntrReadMem"; bool readOnlyMem = prop == "IntrReadArgMem" || prop == "IntrReadMem";
ListInit* paramsList = rec.getValueAsListInit("ParamTypes"); ListInit* paramsList = rec.getValueAsListInit("ParamTypes");
vector<string> params; vector<string> params;
for(unsigned int i = 0; i < for(unsigned int i = 0; i < paramsList->size(); i++)
#if LDC_LLVM_VER >= 307
paramsList->size();
#else
paramsList->getSize();
#endif
i++)
{ {
string t = dtype(paramsList->getElementAsRecord(i), readOnlyMem); string t = dtype(paramsList->getElementAsRecord(i), readOnlyMem);
if(t == "") if(t == "")
@ -145,11 +131,7 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
ListInit* retList = rec.getValueAsListInit("RetTypes"); ListInit* retList = rec.getValueAsListInit("RetTypes");
string ret; string ret;
#if LDC_LLVM_VER >= 307
size_t sz = retList->size(); size_t sz = retList->size();
#else
size_t sz = retList->getSize();
#endif
if(sz == 0) if(sz == 0)
ret = "void"; ret = "void";
else if(sz == 1) else if(sz == 1)
@ -181,11 +163,7 @@ bool emit(raw_ostream& os, RecordKeeper& records)
os << arch; os << arch;
os << "; \n\nimport core.simd;\n\nnothrow @nogc:\n\n"; os << "; \n\nimport core.simd;\n\nnothrow @nogc:\n\n";
#if LDC_LLVM_VER >= 306
const auto &defs = records.getDefs(); const auto &defs = records.getDefs();
#else
map<string, Record*> defs = records.getDefs();
#endif
for (const auto& d : defs) for (const auto& d : defs)
processRecord(os, *d.second, arch); processRecord(os, *d.second, arch);

View file

@ -32,25 +32,16 @@ int main(int argc, const char **argv) {
if (argc == 0) if (argc == 0)
return 1; return 1;
#if LDC_LLVM_VER <= 305
auto Program = sys::FindProgramByName(argv[0]);
#else
auto Program = sys::findProgramByName(argv[0]); auto Program = sys::findProgramByName(argv[0]);
if (!Program) { if (!Program) {
errs() << "Error: Unable to find `" << argv[0] errs() << "Error: Unable to find `" << argv[0]
<< "' in PATH: " << Program.getError().message() << "\n"; << "' in PATH: " << Program.getError().message() << "\n";
return 1; return 1;
} }
#endif
std::string ErrMsg; std::string ErrMsg;
#if LDC_LLVM_VER <= 305
int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0,
&ErrMsg);
#else
int Result = sys::ExecuteAndWait(*Program, argv, nullptr, nullptr, 0, 0, int Result = sys::ExecuteAndWait(*Program, argv, nullptr, nullptr, 0, 0,
&ErrMsg); &ErrMsg);
#endif
#ifdef _WIN32 #ifdef _WIN32
// Handle abort() in msvcrt -- It has exit code as 3. abort(), aka // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
// unreachable, should be recognized as a crash. However, some binaries use // unreachable, should be recognized as a crash. However, some binaries use