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:
- os: linux
d: ldc
env: LLVM_VERSION=4.0.1
env: LLVM_VERSION=4.0.1 OPTS="-DLIB_SUFFIX=64"
- os: linux
d: ldc-beta
env: LLVM_VERSION=3.9.1 OPTS="-DLIB_SUFFIX=64"
- 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"
env: LLVM_VERSION=3.9.1 OPTS="-DBUILD_SHARED_LIBS=ON"
- os: linux
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
d: dmd
env: LLVM_VERSION=3.5.2 OPTS="-DTEST_COVERAGE=ON"
env: LLVM_VERSION=3.7.1 OPTS="-DTEST_COVERAGE=ON"
- os: osx
d: ldc-beta
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.8.1
- llvm-3.7.1
- llvm-3.6.2
- llvm-3.5.2
addons:
apt:
sources:

View file

@ -19,7 +19,7 @@ endif()
# 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})
math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR})
# Remove LLVMTableGen library from list of libraries
@ -405,15 +405,11 @@ source_group("Generated Files" REGULAR_EXPRESSION "(id\\.[cdh]|impcnvtab\\.c)$")
include(HandleLTOPGOBuildOptions)
#
# Enable PGO if supported for this platform and LLVM version.
# LLVM >= 3.7 is required for PGO.
# Enable PGO if supported for this platform.
#
set(LDC_WITH_PGO False) # must be a valid Python boolean constant (case sensitive)
if (NOT (LDC_LLVM_VER LESS 307))
set(LDC_WITH_PGO True) # must be a valid Python boolean constant (case sensitive)
message(STATUS "Building LDC with PGO support")
append("-DLDC_WITH_PGO" LDC_CXXFLAGS)
set(LDC_WITH_PGO True)
endif()
#
# 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
[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.
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,

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.8 llvm-config38
llvm-config-3.7 llvm-config37
llvm-config-3.6 llvm-config36
llvm-config-3.5 llvm-config35
llvm-config)
find_program(LLVM_CONFIG
NAMES ${llvm_config_names}
@ -85,13 +83,6 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
if(TARGET_AMDGPU GREATER -1)
list(APPEND LLVM_FIND_COMPONENTS AMDGPUUtils)
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]*")
# Versions below 3.9 do not support components debuginfocodeview, globalisel
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
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
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})
if(MSVC)
@ -182,13 +169,6 @@ else()
llvm_set(ROOT_DIR prefix true)
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]*")
# Versions below 3.9 do not support components debuginfocodeview, globalisel
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfocodeview" index)
@ -202,18 +182,12 @@ else()
# Versions below 4.0 do not support component debuginfomsf
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfomsf" index)
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)
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
# using the separate "--system-libs" flag.
llvm_set(SYSTEM_LIBS system-libs)
string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")
endif()
llvm_set(LIBRARY_DIRS libdir true)
llvm_set_libs(LIBRARIES libs)
# 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);
/// Prune the cache to avoid filling up disk space.
///
/// Note: Does nothing for LLVM < 3.7.
void pruneCache();
}

View file

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

View file

@ -75,9 +75,7 @@ extern cl::opt<bool> m64bits;
extern cl::opt<std::string> mCPU;
extern cl::list<std::string> mAttrs;
extern cl::opt<std::string> mTargetTriple;
#if LDC_LLVM_VER >= 307
extern cl::opt<std::string> mABI;
#endif
extern cl::opt<llvm::Reloc::Model> mRelocModel;
extern cl::opt<llvm::CodeModel::Model> mCodeModel;
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
// (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();
for (unsigned i = 0, e = moduleFlags->getNumOperands(); i < e; ++i) {
auto *flag = moduleFlags->getOperand(i);
@ -122,7 +117,6 @@ void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
break;
}
#endif
}
}
#else
@ -261,12 +255,7 @@ void CodeGenerator::writeAndFreeLLModule(const char *filename) {
ir_->module.getOrInsertNamedMetadata("llvm.ident");
std::string Version("ldc version ");
Version.append(global.ldc_version);
#if LDC_LLVM_VER >= 306
llvm::Metadata *IdentNode[] =
#else
llvm::Value *IdentNode[] =
#endif
{llvm::MDString::get(ir_->context(), Version)};
llvm::Metadata *IdentNode[] = {llvm::MDString::get(ir_->context(), Version)};
IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode));
std::unique_ptr<llvm::tool_output_file> diagnosticsOutputFile =

View file

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

View file

@ -429,10 +429,6 @@ void ArgsBuilder::addArch() {
case llvm::Triple::armeb:
case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be:
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
case llvm::Triple::arm64_be:
#endif
break;
default:
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
static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
llvm::LLVMContext &Context) {
@ -110,22 +109,13 @@ static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
llvm::Linker(&M).linkInModule(loadedModule.release());
#endif
}
#endif // LDC_LLVM_VER >= 306
/// Insert LLVM bitcode files into the module
void insertBitcodeFiles(llvm::Module &M, llvm::LLVMContext &Ctx,
Array<const char *> &bitcodeFiles) {
#if LDC_LLVM_VER >= 306
for (const char *fname : bitcodeFiles) {
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/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 306
#include "llvm/Target/TargetSubtargetInfo.h"
#endif
#include "llvm/LinkAllIR.h"
#include "llvm/IR/LLVMContext.h"
#include <assert.h>
@ -638,20 +636,15 @@ void initializePasses() {
initializeTarget(Registry);
// Initialize passes not included above
#if LDC_LLVM_VER < 306
initializeDebugIRPass(Registry);
#endif
#if LDC_LLVM_VER < 308
initializeIPA(Registry);
#endif
#if LDC_LLVM_VER >= 400
initializeRewriteSymbolsLegacyPassPass(Registry);
#elif LDC_LLVM_VER >= 306
#else
initializeRewriteSymbolsPass(Registry);
#endif
#if LDC_LLVM_VER >= 307
initializeSjLjEHPreparePass(Registry);
#endif
}
/// Register the MIPS ABI.
@ -679,12 +672,8 @@ static void registerMipsABI() {
void registerPredefinedFloatABI(const char *soft, const char *hard,
const char *softfp = nullptr) {
// Use target floating point unit instead of s/w float routines
#if LDC_LLVM_VER >= 307
// FIXME: This is a semantic change!
bool useFPU = gTargetMachine->Options.FloatABIType == llvm::FloatABI::Hard;
#else
bool useFPU = !gTargetMachine->Options.UseSoftFloat;
#endif
VersionCondition::addPredefinedGlobalIdent(useFPU ? "D_HardFloat"
: "D_SoftFloat");
@ -746,10 +735,6 @@ void registerPredefinedTargetVersions() {
VersionCondition::addPredefinedGlobalIdent("ARM_Thumb");
registerPredefinedFloatABI("ARM_SoftFloat", "ARM_HardFloat", "ARM_SoftFP");
break;
#if LDC_LLVM_VER == 305
case llvm::Triple::arm64:
case llvm::Triple::arm64_be:
#endif
case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be:
VersionCondition::addPredefinedGlobalIdent("AArch64");
@ -1046,10 +1031,6 @@ int cppmain(int argc, char **argv) {
#if LDC_LLVM_VER >= 308
static llvm::DataLayout DL = gTargetMachine->createDataLayout();
gDataLayout = &DL;
#elif LDC_LLVM_VER >= 307
gDataLayout = gTargetMachine->getDataLayout();
#elif LDC_LLVM_VER >= 306
gDataLayout = gTargetMachine->getSubtargetImpl()->getDataLayout();
#else
gDataLayout = gTargetMachine->getDataLayout();
#endif

View file

@ -13,12 +13,14 @@
//
//===----------------------------------------------------------------------===//
#include "driver/cl_options.h"
#include "driver/targetmachine.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/TargetParser.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
@ -27,10 +29,6 @@
#include "mars.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) {
llvm::StringRef ABIName(opts::mABI);
if (ABIName != "") {
@ -81,12 +79,10 @@ static const char *getABI(const llvm::Triple &triple) {
return "";
}
}
#endif
extern llvm::TargetMachine *gTargetMachine;
MipsABI::Type getMipsABI() {
#if LDC_LLVM_VER >= 307
// eabi can only be set on the commandline
if (strncmp(opts::mABI.c_str(), "eabi", 4) == 0)
return MipsABI::EABI;
@ -106,22 +102,6 @@ MipsABI::Type getMipsABI() {
const auto largestInt = dl.getLargestLegalIntTypeSize();
#endif
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) {
@ -246,10 +226,6 @@ static std::string getTargetCPU(const std::string &cpu,
case llvm::Triple::armeb:
case llvm::Triple::thumb:
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_be:
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.
///
/// 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.
const llvm::Target *target = nullptr;
if (!arch.empty()) {
#if LDC_LLVM_VER >= 307
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()) {
target = &T;
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) {
features.AddFeature(attr);
}
@ -586,34 +486,19 @@ createTargetMachine(std::string targetTriple, std::string arch, std::string cpu,
}
llvm::TargetOptions targetOptions;
#if LDC_LLVM_VER < 307
targetOptions.NoFramePointerElim = noFramePointerElim;
#endif
#if LDC_LLVM_VER >= 307
targetOptions.MCOptions.ABIName = getABI(triple);
#endif
switch (floatABI) {
default:
llvm_unreachable("Floating point ABI type unknown.");
case FloatABI::Soft:
#if LDC_LLVM_VER < 307
targetOptions.UseSoftFloat = true;
#else
features.AddFeature("+soft-float");
#endif
targetOptions.FloatABIType = llvm::FloatABI::Soft;
break;
case FloatABI::SoftFP:
#if LDC_LLVM_VER < 307
targetOptions.UseSoftFloat = false;
#endif
targetOptions.FloatABIType = llvm::FloatABI::Soft;
break;
case FloatABI::Hard:
#if LDC_LLVM_VER < 307
targetOptions.UseSoftFloat = false;
#endif
targetOptions.FloatABIType = llvm::FloatABI::Hard;
break;
}

View file

@ -27,40 +27,22 @@
#else
#include "llvm/Bitcode/ReaderWriter.h"
#endif
#if LDC_LLVM_VER >= 307
#include "llvm/IR/LegacyPassManager.h"
#else
#include "llvm/PassManager.h"
#endif
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Program.h"
#if LDC_LLVM_VER >= 307
#include "llvm/Support/Path.h"
#endif
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
#include "llvm/Support/SPIRV.h"
#endif
#include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetTransformInfo.h"
#endif
#if LDC_LLVM_VER >= 306
#include "llvm/Target/TargetSubtargetInfo.h"
#endif
#include "llvm/IR/Module.h"
#include <cstddef>
#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>
NoIntegratedAssembler("no-integrated-as", llvm::cl::ZeroOrMore,
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
// about to build.
#if LDC_LLVM_VER >= 307
legacy::
#endif
PassManager Passes;
legacy::PassManager Passes;
ComputeBackend::Type cb = getComputeTargetType(&m);
if (cb == ComputeBackend::SPIRV) {
@ -91,37 +70,18 @@ static void codegenModule(llvm::TargetMachine &Target, llvm::Module &m,
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
// Add internal analysis passes from the target machine.
Passes.add(
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 LDC_LLVM_VER >= 307
out,
#else
fout,
#endif
// Always generate assembly for ptx as it is an assembly format
// The PTX backend fails if we pass anything else.
(cb == ComputeBackend::NVPTX) ? llvm::TargetMachine::CGFT_AssemblyFile
@ -196,62 +156,32 @@ namespace {
using namespace llvm;
static void printDebugLoc(const DebugLoc &debugLoc, formatted_raw_ostream &os) {
os << debugLoc.getLine() << ":" << debugLoc.getCol();
#if LDC_LLVM_VER >= 307
if (DILocation *IDL = debugLoc.getInlinedAt()) {
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 {
// Find the MDNode which corresponds to the DISubprogram data that described F.
#if LDC_LLVM_VER >= 307
static DISubprogram *FindSubprogram(const Function *F,
DebugInfoFinder &Finder)
#else
static MDNode *FindSubprogram(const Function *F, DebugInfoFinder &Finder)
#endif
{
#if LDC_LLVM_VER >= 307
for (DISubprogram *Subprogram : Finder.subprograms())
if (Subprogram->describes(F))
return Subprogram;
return nullptr;
#else
for (DISubprogram Subprogram : Finder.subprograms()) {
if (Subprogram.describes(F)) {
return Subprogram;
}
}
return nullptr;
#endif
}
static llvm::StringRef GetDisplayName(const Function *F) {
llvm::DebugInfoFinder Finder;
Finder.processModule(*F->getParent());
#if LDC_LLVM_VER >= 307
if (DISubprogram *N = FindSubprogram(F, Finder))
#else
if (MDNode *N = FindSubprogram(F, Finder))
#endif
{
#if LDC_LLVM_VER >= 500
return N->getName();
#elif LDC_LLVM_VER >= 307
return N->getDisplayName();
#else
llvm::DISubprogram sub(N);
return sub.getDisplayName();
return N->getDisplayName();
#endif
}
return "";
@ -294,12 +224,7 @@ public:
return;
}
#if LDC_LLVM_VER >= 307
if (const DebugLoc &debugLoc = instr->getDebugLoc())
#else
const DebugLoc &debugLoc = instr->getDebugLoc();
if (!debugLoc.isUnknown())
#endif
{
if (!padding) {
os.PadToColumn(50);
@ -311,35 +236,19 @@ public:
os << ']';
}
if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(instr)) {
#if LDC_LLVM_VER >= 307
DILocalVariable *Var(DDI->getVariable());
#else
DIVariable Var(DDI->getVariable());
#endif
if (!padding) {
os.PadToColumn(50);
os << ";";
}
#if LDC_LLVM_VER >= 307
os << " [debug variable = " << Var->getName() << ']';
#else
os << " [debug variable = " << Var.getName() << ']';
#endif
} else if (const DbgValueInst *DVI = dyn_cast<DbgValueInst>(instr)) {
#if LDC_LLVM_VER >= 307
DILocalVariable *Var(DVI->getVariable());
#else
DIVariable Var(DVI->getVariable());
#endif
if (!padding) {
os.PadToColumn(50);
os << ";";
}
#if LDC_LLVM_VER >= 307
os << " [debug variable = " << Var->getName() << ']';
#else
os << " [debug variable = " << Var.getName() << ']';
#endif
} else if (const CallInst *callinstr = dyn_cast<CallInst>(instr)) {
const Function *F = callinstr->getCalledFunction();
if (!F) {
@ -374,20 +283,16 @@ public:
void writeObjectFile(llvm::Module *m, const char *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);
#if LDC_LLVM_VER >= 306
if (!errinfo)
#else
if (errinfo.empty())
#endif
{
codegenModule(*gTargetMachine, *m, out,
llvm::TargetMachine::CGFT_ObjectFile);
} else {
error(Loc(), "cannot write object file '%s': %s", filename,
ERRORINFO_STRING(errinfo));
errinfo.message().c_str());
fatal();
}
}
@ -480,11 +385,11 @@ void writeModule(llvm::Module *m, const char *filename) {
std::string bcpath =
(doLTO && outputObj) ? filename : replaceExtensionWith(global.bc_ext);
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);
if (bos.has_error()) {
error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(),
ERRORINFO_STRING(errinfo));
errinfo.message().c_str());
fatal();
}
if (opts::isUsingThinLTO()) {
@ -517,11 +422,11 @@ void writeModule(llvm::Module *m, const char *filename) {
if (global.params.output_ll) {
const auto llpath = replaceExtensionWith(global.ll_ext);
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);
if (aos.has_error()) {
error(Loc(), "cannot write LLVM IR file '%s': %s", llpath.c_str(),
ERRORINFO_STRING(errinfo));
errinfo.message().c_str());
fatal();
}
AssemblyAnnotator annotator;
@ -540,19 +445,15 @@ void writeModule(llvm::Module *m, const char *filename) {
}
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);
#if LDC_LLVM_VER >= 306
if (!errinfo)
#else
if (errinfo.empty())
#endif
{
codegenModule(*gTargetMachine, *m, out,
llvm::TargetMachine::CGFT_AssemblyFile);
} else {
error(Loc(), "cannot write asm: %s", ERRORINFO_STRING(errinfo));
error(Loc(), "cannot write asm: %s", errinfo.message().c_str());
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) {
#if LDC_LLVM_VER >= 306
llvm::ErrorOr<std::string> res = llvm::sys::findProgramByName(name);
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());
case llvm::Triple::ppc64le:
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_be:
return getAArch64TargetABI();

View file

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

View file

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

View file

@ -34,9 +34,7 @@ void emitCoverageLinecountInc(Loc &loc) {
// Get GEP into _d_cover_data array
LLConstant *idxs[] = {DtoConstUint(0), DtoConstUint(line)};
LLValue *ptr = llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
LLArrayType::get(LLType::getInt32Ty(gIR->context()), m->numlines),
#endif
m->d_cover_data, idxs, true);
// 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;
u.fp = src;
#if LDC_LLVM_VER >= 307
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);
dst = APFloat(*apSemantics, bits);

View file

@ -59,8 +59,6 @@ public:
}
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
llvm::NamedMDNode *na =
_ir->module.getOrInsertNamedMetadata("nvvm.annotations");
@ -72,7 +70,6 @@ public:
llvm::Metadata *arr[] = {fn, kstr, one};
llvm::MDNode *tup = llvm::MDTuple::get(ctx, arr);
na->addOperand(tup);
#endif
}
};
} // anonymous namespace.

View file

@ -54,9 +54,6 @@ public:
// Adapted from clang
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?
// spirv.Source // debug only
// stuff from clang's CGSPIRMetadataAdder.cpp
@ -83,7 +80,6 @@ public:
_ir->module.getOrInsertNamedMetadata("opencl.ocl.version");
OCLVerMD->addOperand(llvm::MDNode::get(ctx, OCLVerElts));
#endif
}
enum KernArgMD {
KernArgMD_addr_space,
@ -99,8 +95,6 @@ public:
// type so that the magic types in ldc.dcompute are transformed into
// 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;
// TODO: Handle Function attibutes
llvm::SmallVector<llvm::Metadata *, 8> kernelMDArgs;
@ -137,7 +131,6 @@ public:
llvm::NamedMDNode *OpenCLKernelMetadata =
_ir->module.getOrInsertNamedMetadata("opencl.kernels");
OpenCLKernelMetadata->addOperand(kernelMDNode);
#endif
}
std::string mod2str(MOD mod) {
@ -166,7 +159,7 @@ public:
ss << t->toChars();
return ss.str();
}
#if LDC_LLVM_VER >= 306
void decodeTypes(std::array<llvm::SmallVector<llvm::Metadata *, 8>,count_KernArgMD> attrs,
VarDeclaration *v)
{
@ -199,7 +192,6 @@ public:
attrs[KernArgMD_type_qual].push_back(llvm::MDString::get(ctx, typeQuals));
attrs[KernArgMD_name].push_back(llvm::MDString::get(ctx, v->ident->toChars()));
}
#endif
};
} // anonymous namespace.

View file

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

View file

@ -43,7 +43,6 @@ extern const llvm::DataLayout *gDataLayout;
namespace ldc {
// Define some basic types
#if LDC_LLVM_VER >= 307
typedef llvm::DIType *DIType;
typedef llvm::DIFile *DIFile;
typedef llvm::DIGlobalVariable *DIGlobalVariable;
@ -54,39 +53,17 @@ typedef llvm::DIScope *DIScope;
typedef llvm::DISubroutineType *DISubroutineType;
typedef llvm::DISubprogram *DISubprogram;
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 {
IRState *const IR;
llvm::DIBuilder DBuilder;
#if LDC_LLVM_VER >= 307
DICompileUnit CUNode;
#else
const llvm::MDNode *CUNode;
#endif
const bool isTargetMSVCx64;
DICompileUnit GetCU() {
#if LDC_LLVM_VER >= 307
return CUNode;
#else
return llvm::DICompileUnit(CUNode);
#endif
}
Loc currentLoc;
@ -147,13 +124,7 @@ public:
void
EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd, Type *type = nullptr,
bool isThisPtr = false, bool forceAsLocal = false,
#if LDC_LLVM_VER >= 306
llvm::ArrayRef<int64_t> addr = llvm::ArrayRef<int64_t>()
#else
llvm::ArrayRef<llvm::Value *> addr =
llvm::ArrayRef<llvm::Value *>()
#endif
);
llvm::ArrayRef<int64_t> addr = llvm::ArrayRef<int64_t>());
/// \brief Emits all things necessary for making debug info for a global
/// variable vd.
@ -168,19 +139,10 @@ private:
llvm::LLVMContext &getContext();
Module *getDefinedModule(Dsymbol *s);
DIScope GetCurrentScope();
void Declare(const Loc &loc, llvm::Value *var, ldc::DILocalVariable divar
#if LDC_LLVM_VER >= 306
,
ldc::DIExpression diexpr
#endif
);
void Declare(const Loc &loc, llvm::Value *var, ldc::DILocalVariable divar,
ldc::DIExpression diexpr);
void AddFields(AggregateDeclaration *sd, ldc::DIFile file,
#if LDC_LLVM_VER >= 306
llvm::SmallVector<llvm::Metadata *, 16> &elems
#else
llvm::SmallVector<llvm::Value *, 16> &elems
#endif
);
llvm::SmallVector<llvm::Metadata *, 16> &elems);
DIFile CreateFile(Loc &loc);
DIFile CreateFile();
DIFile CreateFile(Dsymbol* decl);
@ -212,14 +174,8 @@ public:
uint64_t offset =
gDataLayout->getStructLayout(type)->getElementOffset(index);
#if LDC_LLVM_VER >= 306
addr.push_back(llvm::dwarf::DW_OP_plus);
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) {
@ -237,12 +193,7 @@ public:
return;
}
#if LDC_LLVM_VER >= 306
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");
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)
// functions). This check should be removed when cross-module inlining has
// become more stable.

View file

@ -457,9 +457,6 @@ void applyTargetMachineAttributes(llvm::Function &func,
lessPreciseFPMADOption ? "true" : "false");
func.addFnAttr("no-infs-fp-math", TO.NoInfsFPMath ? "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
func.addFnAttr("no-frame-pointer-elim",
@ -1007,11 +1004,7 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
{
// emit a call to llvm_eh_unwind_init
LLFunction *hack = GET_INTRINSIC_DECL(eh_unwind_init);
#if LDC_LLVM_VER >= 307
gIR->ir->CreateCall(hack, {});
#else
gIR->ir->CreateCall(hack, "");
#endif
}
// 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;
#if LDC_LLVM_VER >= 306
std::unique_ptr<llvm::Module> m =
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();
if (!errstr.empty()) {
@ -134,15 +129,8 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
#if LDC_LLVM_VER >= 308
llvm::Linker(gIR->module).linkInModule(std::move(m));
#elif LDC_LLVM_VER >= 306
llvm::Linker(&gIR->module).linkInModule(m.get());
#else
errstr.clear();
llvm::Linker(&gIR->module).linkInModule(m, &errstr);
if (!errstr.empty()) {
error(tinst->loc, "Error when linking in llvm inline ir: %s",
errstr.c_str());
}
llvm::Linker(&gIR->module).linkInModule(m.get());
#endif
}

View file

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

View file

@ -18,11 +18,6 @@ Dstring traitsGetTargetCPU() {
}
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);
// 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());
return savedFeatbits == newFeatbits;
}
#endif
}

View file

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

View file

@ -75,13 +75,8 @@ llvm::Function *buildForwarderFunction(
// ... calling the given functions, and...
for (auto func : funcs) {
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 ft = call->getFunctionType();
#endif
call->setCallingConv(gABI->callingConv(ft, LINKd));
}

View file

@ -121,14 +121,7 @@ RegistryStyle getModuleRegistryStyle() {
}
if (t->isOSLinux() || t->isOSFreeBSD() ||
#if LDC_LLVM_VER > 305
t->isOSNetBSD() || t->isOSOpenBSD() || t->isOSDragonFly()
#else
t->getOS() == llvm::Triple::NetBSD ||
t->getOS() == llvm::Triple::OpenBSD ||
t->getOS() == llvm::Triple::DragonFly
#endif
) {
t->isOSNetBSD() || t->isOSOpenBSD() || t->isOSDragonFly()) {
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
LLValue *gep = builder.CreateStructGEP(
#if LDC_LLVM_VER >= 307
modulerefTy,
#endif
thismref, 0, "next");
modulerefTy, thismref, 0, "next");
builder.CreateStore(curbeg, gep);
// replace beginning
@ -316,7 +306,6 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
llvm::Value *record = b.CreateAlloca(stype);
unsigned i = 0;
#if LDC_LLVM_VER >= 307
b.CreateStore(version, b.CreateStructGEP(stype, record, i++));
b.CreateStore(dsoSlot, 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(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.CreateBr(endBB);
@ -520,10 +499,7 @@ void addCoverageAnalysis(Module *m) {
d_cover_valid_slice =
DtoConstSlice(DtoConstSize_t(type->getArrayNumElements()),
llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
type,
#endif
m->d_cover_valid, idxs, true));
type, m->d_cover_valid, idxs, true));
// Assert that initializer array elements have enough bits
assert(sizeof(m->d_cover_valid_init[0]) * 8 >=
@ -549,10 +525,7 @@ void addCoverageAnalysis(Module *m) {
d_cover_data_slice =
DtoConstSlice(DtoConstSize_t(type->getArrayNumElements()),
llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
type,
#endif
m->d_cover_data, idxs, true));
type, m->d_cover_data, idxs, true));
}
// 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;
assert(idx != -1 && "Nested context not yet resolved for variable.");
#if LDC_LLVM_VER >= 306
LLSmallVector<int64_t, 2> dwarfAddrOps;
#else
LLSmallVector<LLValue *, 2> dwarfAddrOps;
#endif
LLValue *gep = DtoGEPi(val, 0, idx, vd->toChars());
val = gep;
@ -501,11 +497,7 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
}
if (global.params.symdebug) {
#if LDC_LLVM_VER >= 306
LLSmallVector<int64_t, 2> addr;
#else
LLSmallVector<LLValue *, 2> addr;
#endif
// Because we are passing a GEP instead of an alloca to
// llvm.dbg.declare, we have to make the address dereference explicit.
gIR->DBuilder.OpDeref(addr);

View file

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

View file

@ -17,26 +17,16 @@
#include "driver/cl_options_sanitizers.h"
#include "driver/targetmachine.h"
#include "llvm/LinkAllPasses.h"
#if LDC_LLVM_VER >= 307
#include "llvm/IR/LegacyPassManager.h"
#else
#include "llvm/PassManager.h"
#endif
#include "llvm/IR/Module.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/ADT/Triple.h"
#if LDC_LLVM_VER >= 400
#include "llvm/Analysis/InlineCost.h"
#endif
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetTransformInfo.h"
#endif
#include "llvm/IR/Verifier.h"
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetLibraryInfo.h"
#else
#include "llvm/Target/TargetLibraryInfo.h"
#endif
#include "llvm/Target/TargetMachine.h"
#include "llvm/Support/CommandLine.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>>
enableCrossModuleInlining(
"cross-module-inlining", cl::ZeroOrMore, cl::Hidden,
cl::desc("(*) Enable cross-module function inlining (default disabled) "
"(LLVM >= 3.7)"));
cl::desc("(*) Enable cross-module function inlining (default disabled)"));
static cl::opt<bool> unitAtATime("unit-at-a-time", cl::desc("Enable basic IPO"),
cl::ZeroOrMore, cl::init(true));
@ -128,15 +117,7 @@ bool willInline() {
}
bool willCrossModuleInline() {
#if LDC_LLVM_VER >= 307
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; }
@ -251,13 +232,8 @@ static void addPGOPasses(legacy::PassManagerBase &mpm, unsigned optLevel) {
* The selection mirrors Clang behavior and is based on LLVM's
* PassManagerBuilder.
*/
#if LDC_LLVM_VER >= 307
static void addOptimizationPasses(legacy::PassManagerBase &mpm,
legacy::FunctionPassManager &fpm,
#else
static void addOptimizationPasses(PassManagerBase &mpm,
FunctionPassManager &fpm,
#endif
unsigned optLevel, unsigned sizeLevel) {
if (!noVerify) {
fpm.add(createVerifierPass());
@ -360,10 +336,7 @@ static void addOptimizationPasses(PassManagerBase &mpm,
bool ldc_optimize_module(llvm::Module *M) {
// Create a PassManager to hold and optimize the collection of
// per-module passes we are about to build.
#if LDC_LLVM_VER >= 307
legacy::
#endif
PassManager mpm;
legacy::PassManager mpm;
// Dont optimise spirv modules because turning GEPs into extracts triggers
// 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)
return false;
#if LDC_LLVM_VER >= 307
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl *tlii =
new TargetLibraryInfoImpl(Triple(M->getTargetTriple()));
@ -385,59 +357,22 @@ bool ldc_optimize_module(llvm::Module *M) {
tlii->disableAllFunctions();
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.
if (disableSimplifyLibCalls) {
tli->disableAllFunctions();
}
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.
mpm.add(createTargetTransformInfoWrapperPass(
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.
#if LDC_LLVM_VER >= 307
legacy::
#endif
FunctionPassManager fpm(M);
legacy::FunctionPassManager fpm(M);
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine.
fpm.add(createTargetTransformInfoWrapperPass(
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
// anything else.

View file

@ -157,11 +157,7 @@ static bool isKnownLessThan(Value *Val, uint64_t Limit, const Analysis &A) {
}
#else
APInt KnownZero(Bits, 0), KnownOne(Bits, 0);
#if LDC_LLVM_VER >= 307
computeKnownBits(Val, KnownZero, KnownOne, A.DL);
#else
computeKnownBits(Val, KnownZero, KnownOne, &A.DL);
#endif
if ((KnownZero & Mask) != Mask) {
return false;
}
@ -301,22 +297,13 @@ public:
// Inserting destructor calls is not implemented yet, so classes
// with destructors are ignored for now.
#if LDC_LLVM_VER >= 306
auto hasDestructor =
mdconst::dyn_extract<Constant>(node->getOperand(CD_Finalize));
#else
Constant *hasDestructor = dyn_cast<Constant>(node->getOperand(CD_Finalize));
#endif
// 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 =
mdconst::dyn_extract<Constant>(node->getOperand(CD_CustomDelete));
#else
Constant *hasCustomDelete =
dyn_cast<Constant>(node->getOperand(CD_CustomDelete));
#endif
if (hasDestructor == nullptr || hasCustomDelete == nullptr) {
return false;
}
@ -326,12 +313,8 @@ public:
return false;
}
#if LDC_LLVM_VER >= 306
Ty = mdconst::dyn_extract<Constant>(node->getOperand(CD_BodyType))
->getType();
#else
Ty = node->getOperand(CD_BodyType)->getType();
#endif
return A.DL.getTypeAllocSize(Ty) < SizeLimit;
}
@ -429,9 +412,6 @@ public:
bool runOnFunction(Function &F) override;
void getAnalysisUsage(AnalysisUsage &AU) const override {
#if LDC_LLVM_VER < 307
AU.addRequired<DataLayoutPass>();
#endif
AU.addRequired<DominatorTreeWrapperPass>();
AU.addPreserved<CallGraphWrapperPass>();
}
@ -488,19 +468,10 @@ isSafeToStackAllocate(BasicBlock::iterator Alloc, Value *V, DominatorTree &DT,
bool GarbageCollect2Stack::runOnFunction(Function &F) {
DEBUG(errs() << "\nRunning -dgc2stack on function " << F.getName() << '\n');
#if LDC_LLVM_VER >= 307
const DataLayout &DL = F.getParent()->getDataLayout();
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
CallGraphWrapperPass *CGPass = getAnalysisIfAvailable<CallGraphWrapperPass>();
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;
Analysis A = {DL, *M, CG, CGNode};
@ -612,23 +583,15 @@ Type *Analysis::getTypeFor(Value *typeinfo) const {
return nullptr;
}
#if LDC_LLVM_VER >= 306
Value *ti = llvm::MetadataAsValue::get(node->getContext(),
node->getOperand(TD_TypeInfo));
#else
Value *ti = node->getOperand(TD_TypeInfo);
#endif
if (!ti || ti->stripPointerCasts() != ti_global) {
return nullptr;
}
#if LDC_LLVM_VER >= 306
return llvm::MetadataAsValue::get(node->getContext(),
node->getOperand(TD_Type))
->getType();
#else
return node->getOperand(TD_Type)->getType();
#endif
}
/// 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
// the first non-phi to the worklist.
if (!SeenDef
#if LDC_LLVM_VER >= 306
&& Visited.insert(Succ).second
#else
&& Visited.insert(Succ)
#endif
&& DT.dominates(DefBlock, Succ)) {
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();
UI != UE; ++UI) {
Use *U = &(*UI);
#if LDC_LLVM_VER >= 306
if (Visited.insert(U).second) {
#else
if (Visited.insert(U)) {
#endif
Worklist.push_back(U);
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -628,17 +628,11 @@ namespace {
, nullptr
#endif
);
#if LDC_LLVM_VER >= 307
if (!irs.func()->hasLLVMPersonalityFn()) {
irs.func()->setLLVMPersonalityFn(
getRuntimeFunction(Loc(), irs.module, "_d_eh_personality"));
}
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

@ -94,16 +94,10 @@ static void emitTypeMetadata(TypeInfoDeclaration *tid) {
if (!meta) {
// Construct the fields
#if LDC_LLVM_VER >= 306
llvm::Metadata *mdVals[TD_NumFields];
mdVals[TD_TypeInfo] = llvm::ValueAsMetadata::get(getIrGlobal(tid)->value);
mdVals[TD_Type] = llvm::ConstantAsMetadata::get(
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.
llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata(metaname);

View file

@ -90,7 +90,6 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
bool hasDestructor = (classdecl->dtor != nullptr);
bool hasCustomDelete = (classdecl->aggDelete != nullptr);
// Construct the fields
#if LDC_LLVM_VER >= 306
llvm::Metadata *mdVals[CD_NumFields];
mdVals[CD_BodyType] =
llvm::ConstantAsMetadata::get(llvm::UndefValue::get(bodyType));
@ -98,14 +97,6 @@ LLGlobalVariable *IrAggr::getClassInfoSymbol() {
LLConstantInt::get(LLType::getInt1Ty(gIR->context()), hasDestructor));
mdVals[CD_CustomDelete] = llvm::ConstantAsMetadata::get(
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.
llvm::SmallString<64> name;
llvm::NamedMDNode *node = gIR->module.getOrInsertNamedMetadata(
@ -286,9 +277,7 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
llvm::GlobalVariable *interfaceInfosZ = getInterfaceArraySymbol();
llvm::Constant *c = llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
isaPointer(interfaceInfosZ)->getElementType(),
#endif
interfaceInfosZ, idxs, true);
constants.push_back(DtoBitCast(c, voidPtrTy));
@ -360,10 +349,8 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtbl(BaseClass *b, bool new_instance,
thunk->setUnnamedAddr(true);
#endif
#if LDC_LLVM_VER >= 307
// thunks don't need exception handling themselves
thunk->setPersonalityFn(nullptr);
#endif
// 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
@ -564,10 +551,7 @@ LLConstant *IrAggr::getClassInfoInterfaces() {
DtoConstSize_t(n - cd->vtblInterfaces->dim)};
LLConstant *ptr = llvm::ConstantExpr::getGetElementPtr(
#if LDC_LLVM_VER >= 307
isaPointer(ciarr)->getElementType(),
#endif
ciarr, idxs, true);
isaPointer(ciarr)->getElementType(), ciarr, idxs, true);
// return as a slice
return DtoConstSlice(DtoConstSize_t(cd->vtblInterfaces->dim), ptr);

View file

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

View file

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

View file

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

View file

@ -69,11 +69,7 @@ public:
/// Composite type debug description. This is not only to cache, but also
/// used for resolving forward references.
#if LDC_LLVM_VER >= 307
llvm::DIType *diCompositeType = nullptr;
#else
llvm::DIType diCompositeType;
#endif
/// true, if the LLVM struct type for the aggregate is declared as packed
bool packed = false;

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

View file

@ -1,6 +1,5 @@
// Tests @target attribute for x86
// REQUIRES: atleast_llvm307
// 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

View file

@ -1,7 +1,5 @@
// 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=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.
// REQUIRES: atleast_llvm307
// RUN: %ldc -O -release -enable-cross-module-inlining -output-ll -of=%t.ll -I%S/inputs %s
// RUN: FileCheck %s < %t.ll

View file

@ -1,7 +1,5 @@
// 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 -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
// 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
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.
// 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 -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
// "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 -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

View file

@ -2,7 +2,6 @@
// "Leaking" = symbols definitions in .o file that shouldn't be declarations instead (undefined symbols).
// 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 -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
// 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 -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

View file

@ -1,7 +1,5 @@
// 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 -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
// 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 -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
// 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_import.d -of=%t2.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
// REQUIRES: atleast_llvm306
// LLVM >= 5.0 uses llvm.linker.options instead. See link_bitcode_libs_500.d.
// 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, ...
# plusoneable_llvmversion: 38, 39, 40, 50, ...
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))
for version in range(plusoneable_llvmversion, 91):
config.available_features.add("atmost_llvm%d0%d" % (version//10, version%10))

View file

@ -8,36 +8,18 @@
// 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()
{
version (CPU_HASWELL)
{
static assert(__traits(targetCPU) == "haswell");
version (HASFEATURE)
{
static assert(__traits(targetHasFeature, "sse3"));
static assert(__traits(targetHasFeature, "sse4.1"));
}
static assert(!__traits(targetHasFeature, "sse4"));
static assert(!__traits(targetHasFeature, "sse4a"));
static assert(!__traits(targetHasFeature, "unrecognized feature"));
}
version (ATTR_FMA)
{
version (HASFEATURE)
{
static assert(__traits(targetHasFeature, "sse"));
static assert(__traits(targetHasFeature, "sse2"));
@ -45,7 +27,6 @@ void main()
static assert(__traits(targetHasFeature, "sse4.1"));
static assert(__traits(targetHasFeature, "fma"));
static assert(__traits(targetHasFeature, "avx"));
}
static assert(!__traits(targetHasFeature, "avx2"));
static assert(!__traits(targetHasFeature, "unrecognized feature"));
}

View file

@ -16,9 +16,6 @@ void main()
// CHECK: Error: string expected as argument of __traits targetHasFeature instead of 1
enum e = __traits(targetHasFeature, 1);
// Diagnostics of an unrecognized feature depends on the LLVM version (LLVM < 3.7 does not warn at all)
// Newer LLVM versions do warn.
// TODO: Re-enable test when LLVM < 3.7 is no longer supported.
// CHECK: 夜畔' is not a recognized feature for this target (ignoring feature)
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 prop =
#if LDC_LLVM_VER >= 307
propertyList->size()
#else
propertyList->getSize()
#endif
? propertyList->getElementAsRecord(0)->getName() : "";
return
@ -117,24 +113,14 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
ListInit* propsList = rec.getValueAsListInit("Properties");
#endif
string prop =
#if LDC_LLVM_VER >= 307
propsList->size()
#else
propsList->getSize()
#endif
? propsList->getElementAsRecord(0)->getName() : "";
bool readOnlyMem = prop == "IntrReadArgMem" || prop == "IntrReadMem";
ListInit* paramsList = rec.getValueAsListInit("ParamTypes");
vector<string> params;
for(unsigned int i = 0; i <
#if LDC_LLVM_VER >= 307
paramsList->size();
#else
paramsList->getSize();
#endif
i++)
for(unsigned int i = 0; i < paramsList->size(); i++)
{
string t = dtype(paramsList->getElementAsRecord(i), readOnlyMem);
if(t == "")
@ -145,11 +131,7 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
ListInit* retList = rec.getValueAsListInit("RetTypes");
string ret;
#if LDC_LLVM_VER >= 307
size_t sz = retList->size();
#else
size_t sz = retList->getSize();
#endif
if(sz == 0)
ret = "void";
else if(sz == 1)
@ -181,11 +163,7 @@ bool emit(raw_ostream& os, RecordKeeper& records)
os << arch;
os << "; \n\nimport core.simd;\n\nnothrow @nogc:\n\n";
#if LDC_LLVM_VER >= 306
const auto &defs = records.getDefs();
#else
map<string, Record*> defs = records.getDefs();
#endif
for (const auto& d : defs)
processRecord(os, *d.second, arch);

View file

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