Skip to content

Commit

Permalink
Drop support for LLVM < 14
Browse files Browse the repository at this point in the history
LLVM 14 is the first version supporting both new pass manager and
opaque IR pointers.
  • Loading branch information
kinke committed May 12, 2024
1 parent 59c0c60 commit e7091dd
Show file tree
Hide file tree
Showing 58 changed files with 85 additions and 10,856 deletions.
35 changes: 10 additions & 25 deletions .github/workflows/supported_llvm_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ jobs:
fail-fast: false
matrix:
include:
- job_name: Ubuntu 20.04, LDC-LLVM 18, latest LDC beta
- job_name: Ubuntu 20.04, LDC-LLVM 18, bootstrap LDC
os: ubuntu-20.04
host_dc: ldc-beta
host_dc: ldc-1.19.0
# FIXME: no usable official package available yet
llvm_version: https://github.com/ldc-developers/llvm-project/releases/download/ldc-v18.1.5/llvm-18.1.5-linux-x86_64.tar.xz
cmake_flags: -DRT_SUPPORT_SANITIZERS=ON
- job_name: macOS 14, LLVM 17, latest LDC beta
os: macos-14
host_dc: ldc-beta
Expand All @@ -30,30 +31,16 @@ jobs:
host_dc: ldc-beta
llvm_version: 16.0.5
cmake_flags: -DBUILD_SHARED_LIBS=OFF -DD_COMPILER_FLAGS=-gcc=/usr/bin/c++ -DCMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/opt/zstd/lib
- job_name: Ubuntu 20.04, LLVM 15, latest LDC beta
- job_name: Ubuntu 20.04, LLVM 15, latest DMD beta
os: ubuntu-20.04
host_dc: ldc-beta
host_dc: dmd-beta
llvm_version: 15.0.6
cmake_flags: -DBUILD_SHARED_LIBS=ON -DRT_SUPPORT_SANITIZERS=ON -DLIB_SUFFIX=64 -DLDC_LINK_MANUALLY=ON
- job_name: macOS 11, LLVM 14, latest DMD beta
os: macos-11
host_dc: dmd-beta
llvm_version: 14.0.6
cmake_flags: -DBUILD_SHARED_LIBS=ON -DRT_SUPPORT_SANITIZERS=ON -DLDC_LINK_MANUALLY=ON -DCMAKE_CXX_COMPILER=/usr/bin/c++ -DCMAKE_C_COMPILER=/usr/bin/cc
- job_name: Ubuntu 20.04, LLVM 13, latest LDC beta
os: ubuntu-20.04
host_dc: ldc-beta
llvm_version: 13.0.1
cmake_flags: -DRT_SUPPORT_SANITIZERS=ON
- job_name: Ubuntu 20.04, LLVM 12, bootstrap LDC
os: ubuntu-20.04
host_dc: ldc-1.19.0
llvm_version: 12.0.1
cmake_flags: -DBUILD_SHARED_LIBS=ON -DLIB_SUFFIX=64
- job_name: Ubuntu 20.04, LLVM 11, latest DMD beta
os: ubuntu-20.04
host_dc: dmd-beta
llvm_version: 11.1.0
cmake_flags: -DBUILD_SHARED_LIBS=OFF -DRT_SUPPORT_SANITIZERS=ON -DLDC_LINK_MANUALLY=ON
name: ${{ matrix.job_name }}
runs-on: ${{ matrix.os }}
env:
Expand Down Expand Up @@ -116,10 +103,8 @@ jobs:
fi
elif [[ "$version" =~ ^1[7-9]\. ]]; then
suffix='x86_64-linux-gnu-ubuntu-22.04' # LLVM 17+
elif [[ "$version" =~ ^1[3-6]\. ]]; then
suffix='x86_64-linux-gnu-ubuntu-18.04' # LLVM 13.0.1+
else
suffix='x86_64-linux-gnu-ubuntu-16.04'
suffix='x86_64-linux-gnu-ubuntu-18.04' # LLVM 14+
fi
url="https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/clang+llvm-$version-$suffix.tar.xz"
Expand All @@ -136,7 +121,7 @@ jobs:
fi
- name: 'Linux: Make lld the default linker'
if: runner.os == 'Linux' && matrix.host_dc != 'ldc-1.9.0'
if: runner.os == 'Linux'
run: |
set -eux
echo "Using lld to work around sporadic failures"
Expand All @@ -161,8 +146,8 @@ jobs:
if: success() || failure()
run: |
set -eux
# LLVM 14+ on Linux: don't use vanilla llvm-symbolizer (no support for zlib-compressed debug sections => failing ASan tests)
if [[ '${{ runner.os }}' == 'Linux' && ! '${{ matrix.llvm_version }}' =~ ^1[1-3]\. ]]; then
# Linux: don't use vanilla llvm-symbolizer (no support for zlib-compressed debug sections => failing ASan tests)
if [[ '${{ runner.os }}' == 'Linux' ]]; then
mv llvm/bin/llvm-symbolizer llvm/bin/llvm-symbolizer.bak
fi
ctest -V -R "lit-tests"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#### Big news

#### Platform support
- Supports LLVM 14 - 18. Support for LLVM 11, 12 and 13 was dropped.

#### Bug fixes

Expand Down
25 changes: 6 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ endfunction()
# Locate LLVM.
#

find_package(LLVM 11.0 REQUIRED
find_package(LLVM 14.0 REQUIRED
all-targets analysis asmparser asmprinter bitreader bitwriter codegen core
debuginfodwarf debuginfomsf debuginfopdb demangle
instcombine ipo instrumentation irreader libdriver linker lto mc
Expand Down Expand Up @@ -604,28 +604,15 @@ if(LDC_WITH_LLD)
else()
set(LDC_LINKERFLAG_LIST -lLLVMSymbolize ${LDC_LINKERFLAG_LIST})
endif()
if (LDC_LLVM_VER LESS 1200 OR NOT LDC_LLVM_VER LESS 1400)
set(LLD_MACHO lldMachO)
else()
set(LLD_MACHO lldMachO2)
endif()
set(LLD_MACHO lldMachO)
if(MSVC)
if(NOT (LDC_LLVM_VER LESS 1400))
list(APPEND LDC_LINKERFLAG_LIST lldMinGW.lib lldCOFF.lib lldELF.lib ${LLD_MACHO}.lib lldWasm.lib lldCommon.lib)
else()
list(APPEND LDC_LINKERFLAG_LIST lldDriver.lib lldMinGW.lib lldCOFF.lib lldELF.lib ${LLD_MACHO}.lib lldWasm.lib lldYAML.lib lldReaderWriter.lib lldCommon.lib lldCore.lib)
endif()
list(APPEND LDC_LINKERFLAG_LIST lldMinGW.lib lldCOFF.lib lldELF.lib ${LLD_MACHO}.lib lldWasm.lib lldCommon.lib)
else()
if(NOT (LDC_LLVM_VER LESS 1400))
set(LDC_LINKERFLAG_LIST -llldMinGW -llldCOFF -llldELF -l${LLD_MACHO} -llldWasm -llldCommon ${LDC_LINKERFLAG_LIST})
else()
set(LDC_LINKERFLAG_LIST -llldDriver -llldMinGW -llldCOFF -llldELF -l${LLD_MACHO} -llldWasm -llldYAML -llldReaderWriter -llldCommon -llldCore ${LDC_LINKERFLAG_LIST})
endif()
set(LDC_LINKERFLAG_LIST -llldMinGW -llldCOFF -llldELF -l${LLD_MACHO} -llldWasm -llldCommon ${LDC_LINKERFLAG_LIST})
endif()
if(APPLE)
if(NOT (LDC_LLVM_VER LESS 1300)) # LLD 13.0.0 on Mac needs libxar
list(APPEND LDC_LINKERFLAG_LIST -lxar)
endif()
# LLD 13.0.0 on Mac needs libxar
list(APPEND LDC_LINKERFLAG_LIST -lxar)
endif()
endif()

Expand Down
7 changes: 1 addition & 6 deletions cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ set(llvm_config_names llvm-config-18.1 llvm-config181 llvm-config-18
llvm-config-16.0 llvm-config160 llvm-config-16
llvm-config-15.0 llvm-config150 llvm-config-15
llvm-config-14.0 llvm-config140 llvm-config-14
llvm-config-13.0 llvm-config130 llvm-config-13
llvm-config-12.0 llvm-config120 llvm-config-12
llvm-config-11.0 llvm-config110 llvm-config-11
llvm-config)
find_program(LLVM_CONFIG
NAMES ${llvm_config_names}
Expand All @@ -57,9 +54,7 @@ if(APPLE)
/opt/local/libexec/llvm/bin
/usr/local/opt/llvm@18/bin /usr/local/opt/llvm@17/bin
/usr/local/opt/llvm@16/bin /usr/local/opt/llvm@15/bin
/usr/local/opt/llvm@14/bin /usr/local/opt/llvm@13/bin
/usr/local/opt/llvm@12/bin /usr/local/opt/llvm@11/bin
/usr/local/opt/llvm/bin
/usr/local/opt/llvm@14/bin /usr/local/opt/llvm/bin
NO_DEFAULT_PATH)
endif()

Expand Down
5 changes: 0 additions & 5 deletions driver/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,12 @@ struct ResponseFile {
return true; // nothing to do

#if defined(_WIN32)
#if LDC_LLVM_VER >= 1200
const llvm::ErrorOr<std::wstring> wcontent =
llvm::sys::flattenWindowsCommandLine(toRefsVector(args));

std::string content;
if (!wcontent || !llvm::convertWideToUTF8(*wcontent, content))
return false;
#else
const std::string content =
llvm::sys::flattenWindowsCommandLine(toRefsVector(args));
#endif
#else
std::string content;
content.reserve(65536);
Expand Down
8 changes: 0 additions & 8 deletions driver/cl_options-llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ Optional<CodeModel::Model> getCodeModel() {
return codegen::getExplicitCodeModel();
}

#if LDC_LLVM_VER >= 1300
using FPK = llvm::FramePointerKind;
#else
using FPK = llvm::FramePointer::FP;
#endif

llvm::Optional<FPK> framePointerUsage() {
// Defaults to `FP::None`; no way to check if set explicitly by user except
Expand All @@ -67,11 +63,7 @@ bool printTargetFeaturesHelp() {
}

TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &triple) {
#if LDC_LLVM_VER >= 1200
return codegen::InitTargetOptionsFromCodeGenFlags(triple);
#else
return codegen::InitTargetOptionsFromCodeGenFlags();
#endif
}

std::string getCPUStr() {
Expand Down
4 changes: 0 additions & 4 deletions driver/cl_options-llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ namespace opts {
std::string getArchStr();
llvm::Optional<llvm::Reloc::Model> getRelocModel();
llvm::Optional<llvm::CodeModel::Model> getCodeModel();
#if LDC_LLVM_VER >= 1300
llvm::Optional<llvm::FramePointerKind> framePointerUsage();
#else
llvm::Optional<llvm::FramePointer::FP> framePointerUsage();
#endif

bool disableRedZone();
bool printTargetFeaturesHelp();
Expand Down
8 changes: 1 addition & 7 deletions driver/cl_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,10 @@ cl::opt<std::string>
"of optimizations performed by LLVM"),
cl::ValueOptional);

#if LDC_LLVM_VER >= 1300
// LLVM < 13 has "--warn-stack-size", but let's not do the effort of forwarding
// the string to that option, and instead let the user do it himself.
cl::opt<unsigned>
fWarnStackSize("fwarn-stack-size", cl::ZeroOrMore, cl::init(UINT_MAX),
cl::desc("Warn for stack size bigger than the given number"),
cl::value_desc("threshold"));
#endif

#if LDC_LLVM_SUPPORTED_TARGET_SPIRV || LDC_LLVM_SUPPORTED_TARGET_NVPTX
cl::list<std::string>
Expand Down Expand Up @@ -728,7 +724,7 @@ cl::opt<bool> dynamicCompileTlsWorkaround(

#if LDC_LLVM_VER >= 1700
bool enableOpaqueIRPointers = true; // typed pointers are no longer supported from LLVM 17
#elif LDC_LLVM_VER >= 1400
#else
bool enableOpaqueIRPointers = false;
#endif

Expand Down Expand Up @@ -790,12 +786,10 @@ void createClashingOptions() {
clEnumValN(FloatABI::Hard, "hard",
"Hardware floating-point ABI and instructions")));

#if LDC_LLVM_VER >= 1400
renameAndHide("opaque-pointers", nullptr); // remove
new cl::opt<bool, true>(
"opaque-pointers", cl::ZeroOrMore, cl::location(enableOpaqueIRPointers),
cl::desc("Use opaque IR pointers (experimental!)"), cl::Hidden);
#endif
}

/// Hides command line options exposed from within LLVM that are unlikely
Expand Down
4 changes: 0 additions & 4 deletions driver/cl_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ extern cl::opt<bool> ltoFatObjects;

extern cl::opt<std::string> saveOptimizationRecord;

#if LDC_LLVM_VER >= 1300
extern cl::opt<unsigned> fWarnStackSize;
#endif

#if LDC_LLVM_SUPPORTED_TARGET_SPIRV || LDC_LLVM_SUPPORTED_TARGET_NVPTX
extern cl::list<std::string> dcomputeTargets;
Expand All @@ -155,7 +153,5 @@ extern cl::opt<bool> dynamicCompileTlsWorkaround;
constexpr bool enableDynamicCompile = false;
#endif

#if LDC_LLVM_VER >= 1400
extern bool enableOpaqueIRPointers;
#endif
}
13 changes: 0 additions & 13 deletions driver/cl_options_sanitizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,8 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SpecialCaseList.h"
#if LDC_LLVM_VER >= 1300
#include "llvm/Support/VirtualFileSystem.h"
#endif

#if LDC_LLVM_VER >= 1400
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
#else
namespace llvm {
// Declaring this simplifies code later, but the option is never used with LLVM
// <= 13.
enum class AsanDetectStackUseAfterReturnMode { Never, Runtime, Always };
}
#endif

using namespace dmd;

Expand Down Expand Up @@ -97,14 +86,12 @@ void parseFSanitizeCoverageParameter(llvm::StringRef name,
else if (name == "trace-gep") {
opts.TraceGep = true;
}
#if LDC_LLVM_VER >= 1400
else if (name == "trace-loads") {
opts.TraceLoads = true;
}
else if (name == "trace-stores") {
opts.TraceStores = true;
}
#endif
else if (name == "8bit-counters") {
opts.Use8bitCounters = true;
}
Expand Down
24 changes: 0 additions & 24 deletions driver/codegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,14 @@
#include "gen/runtime.h"
#include "gen/tollvm.h"
#include "ir/irdsymbol.h"
#if LDC_LLVM_VER >= 1400
#include "llvm/IR/DiagnosticInfo.h"
#endif
#include "llvm/IR/LLVMRemarkStreamer.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/YAMLTraits.h"
#if LDC_MLIR_ENABLED
#if LDC_LLVM_VER >= 1200
#include "mlir/IR/BuiltinOps.h"
#else
#include "mlir/IR/Module.h"
#endif
#include "mlir/IR/MLIRContext.h"
#endif

Expand Down Expand Up @@ -149,19 +143,6 @@ bool inlineAsmDiagnostic(IRState *irs, const llvm::SMDiagnostic &d,
return true;
}

#if LDC_LLVM_VER < 1300
void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context,
unsigned locCookie) {
if (d.getKind() == llvm::SourceMgr::DK_Error) {
++global.errors;
} else if (global.params.warnings == DIAGNOSTICerror &&
d.getKind() == llvm::SourceMgr::DK_Warning) {
++global.warnings;
}

inlineAsmDiagnostic(static_cast<IRState *>(context), d, locCookie);
}
#else
struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler {
IRState *irs;
InlineAsmDiagnosticHandler(IRState *irs) : irs(irs) {}
Expand All @@ -185,7 +166,6 @@ struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler {
return inlineAsmDiagnostic(irs, DISM.getSMDiag(), DISM.getLocCookie());
}
};
#endif

} // anonymous namespace

Expand Down Expand Up @@ -280,12 +260,8 @@ void CodeGenerator::writeAndFreeLLModule(const char *filename) {
llvm::Metadata *IdentNode[] = {llvm::MDString::get(ir_->context(), Version)};
IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode));

#if LDC_LLVM_VER < 1300
context_.setInlineAsmDiagnosticHandler(inlineAsmDiagnosticHandler, ir_);
#else
context_.setDiagnosticHandler(
std::make_unique<InlineAsmDiagnosticHandler>(ir_));
#endif

std::unique_ptr<llvm::ToolOutputFile> diagnosticsOutputFile =
createAndSetDiagnosticsOutputFile(*ir_, context_, filename);
Expand Down
7 changes: 1 addition & 6 deletions driver/cpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ FileName runCPreprocessor(FileName csrcfile, const Loc &loc,
args.push_back("/nologo");
args.push_back("/P"); // preprocess only

const bool isClangCl = llvm::StringRef(cc)
#if LDC_LLVM_VER >= 1300
.contains_insensitive("clang-cl");
#else
.contains_lower("clang-cl");
#endif
const bool isClangCl = llvm::StringRef(cc).contains_insensitive("clang-cl");

if (!isClangCl) {
args.push_back("/PD"); // print all macro definitions
Expand Down
8 changes: 1 addition & 7 deletions driver/ldmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,7 @@ void translateArgs(const llvm::SmallVectorImpl<const char *> &ldmdArgs,
}
} else {
const auto ext = ls::path::extension(p);
if (
#if LDC_LLVM_VER >= 1300
ext.equals_insensitive(".exe")
#else
ext.equals_lower(".exe")
#endif
) {
if (ext.equals_insensitive(".exe")) {
// should be for Windows targets only
ldcArgs.push_back(concat("-of=", p));
continue;
Expand Down
Loading

0 comments on commit e7091dd

Please sign in to comment.