Skip to content

Commit

Permalink
Merge pull request #4423 from kinke/llvm16-2
Browse files Browse the repository at this point in the history
Add support for LLVM 16 and bump LDC-LLVM to v16.0.6 for prebuilt packages
  • Loading branch information
kinke authored Aug 16, 2023
2 parents cf32bac + 4aa5bc1 commit c1105d5
Show file tree
Hide file tree
Showing 39 changed files with 4,057 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ install_macos_prerequisites_template: &INSTALL_MACOS_PREREQUISITES_TEMPLATE
environment:
CIRRUS_CLONE_DEPTH: 50
HOST_LDC_VERSION: 1.31.0
LLVM_VERSION: 15.0.7
LLVM_VERSION: 16.0.6
GITHUB_TOKEN: ENCRYPTED[0955bd48c8d4e5391446fc0149d0719ad0b63df27ec9e6c180a5730a5b10dc7f28f09d1383423db158d21380ee2b022a]

task:
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/1-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ runs:
shell: bash
run: |
set -eux
sudo ln -sf "$(dirname "$PWD")/clang/bin/ld.lld" /usr/bin/ld
sudo ln -sf "$(dirname "$PWD")/llvm/bin/ld.lld" /usr/bin/ld
ld --version
- name: Install ninja
Expand Down
29 changes: 15 additions & 14 deletions .github/actions/3-build-cross/android-llvm-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,37 @@ prefix=@LLVM_INSTALL_DIR@
has_rtti=NO
CPPFLAGS="-I${prefix}/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
CFLAGS="${CPPFLAGS} ${CFLAGS}"
CXXFLAGS="${CFLAGS} -std=c++14 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables"
CXXFLAGS="${CFLAGS} -std=c++17 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables"
if [ "$has_rtti" != "YES" ]; then CXXFLAGS="$CXXFLAGS -fno-rtti"; fi
LDFLAGS="-L${prefix}/lib"
LIBFILE="${prefix}/lib/libLLVM-$version.so"

components="aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils \
aggressiveinstcombine all all-targets analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils \
asmparser asmprinter binaryformat bitreader bitstreamreader bitwriter cfguard codegen core coroutines coverage \
debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker dwp \
engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel instcombine \
instrumentation interfacestub interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler \
debuginfocodeview debuginfodwarf debuginfogsym debuginfologicalview debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker dwarflinkerparallel dwp \
engine executionengine extensions filecheck frontendhlsl frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel instcombine \
instrumentation interfacestub interpreter ipo irprinter irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler \
mcjit mcparser mirparser native nativecodegen objcarcopts objcopy object objectyaml option orcjit orcshared orctargetprocess \
passes profiledata remarks runtimedyld scalaropts selectiondag support symbolize tablegen target textapi \
passes profiledata remarks runtimedyld scalaropts selectiondag spirv spirvcodegen spirvdesc spirvinfo support symbolize tablegen target targetparser textapi \
transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler \
webassemblyinfo webassemblyutils windowsdriver windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info \
x86targetmca xray"
static_libs="-lLLVMWindowsManifest -lLLVMWindowsDriver -lLLVMXRay -lLLVMLibDriver -lLLVMDlltoolDriver -lLLVMCoverage -lLLVMLineEditor \
static_libs="-lLLVMWindowsManifest -lLLVMXRay -lLLVMLibDriver -lLLVMDlltoolDriver -lLLVMCoverage -lLLVMLineEditor \
-lLLVMSPIRVCodeGen -lLLVMSPIRVDesc -lLLVMSPIRVInfo \
-lLLVMX86TargetMCA -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMWebAssemblyDisassembler \
-lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyUtils -lLLVMWebAssemblyInfo -lLLVMARMDisassembler \
-lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMAArch64Disassembler \
-lLLVMAArch64AsmParser -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMOrcJIT \
-lLLVMMCJIT -lLLVMJITLink -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared \
-lLLVMDWP -lLLVMDebugInfoGSYM -lLLVMOption -lLLVMObjectYAML -lLLVMObjCopy -lLLVMMCA \
-lLLVMMCDisassembler -lLLVMLTO -lLLVMPasses -lLLVMCFGuard -lLLVMCoroutines -lLLVMObjCARCOpts -lLLVMipo \
-lLLVMVectorize -lLLVMLinker -lLLVMInstrumentation -lLLVMFrontendOpenMP -lLLVMFrontendOpenACC -lLLVMExtensions \
-lLLVMDWARFLinker -lLLVMGlobalISel -lLLVMMIRParser -lLLVMAsmPrinter -lLLVMSelectionDAG \
-lLLVMCodeGen -lLLVMIRReader -lLLVMAsmParser -lLLVMInterfaceStub -lLLVMFileCheck -lLLVMFuzzMutate -lLLVMTarget \
-lLLVMWindowsDriver -lLLVMMCJIT -lLLVMJITLink -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared \
-lLLVMDWP -lLLVMDebugInfoLogicalView -lLLVMDebugInfoGSYM -lLLVMOption -lLLVMObjectYAML -lLLVMObjCopy -lLLVMMCA \
-lLLVMMCDisassembler -lLLVMLTO -lLLVMPasses -lLLVMCFGuard -lLLVMCoroutines -lLLVMipo \
-lLLVMVectorize -lLLVMLinker -lLLVMInstrumentation -lLLVMFrontendOpenMP -lLLVMFrontendOpenACC -lLLVMFrontendHLSL -lLLVMExtensions \
-lLLVMDWARFLinkerParallel -lLLVMDWARFLinker -lLLVMGlobalISel -lLLVMMIRParser -lLLVMAsmPrinter -lLLVMSelectionDAG \
-lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMIRPrinter -lLLVMInterfaceStub -lLLVMFileCheck -lLLVMFuzzMutate -lLLVMTarget \
-lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis \
-lLLVMProfileData -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView \
-lLLVMBitReader -lLLVMFuzzerCLI -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTableGen -lLLVMSupport \
-lLLVMProfileData -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMIRReader -lLLVMAsmParser -lLLVMMC -lLLVMDebugInfoCodeView \
-lLLVMBitReader -lLLVMFuzzerCLI -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTargetParser -lLLVMTableGen -lLLVMSupport \
-lLLVMDemangle"
shared_libs="-lLLVM-$version"
libs=$static_libs
Expand Down
1 change: 1 addition & 0 deletions .github/actions/5a-ios/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ runs:
{
switches = [
\"-defaultlib=phobos2-ldc,druntime-ldc\",
\"-func-specialization-size-threshold=1000000000\",
\"-Xcc=-target\",
\"-Xcc=$triple\",
\"-Xcc=-miphoneos-version-min=$deployment_target\",
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/merge-macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ runs:
// default switches injected before all explicit command-line switches
switches = [
\"-defaultlib=phobos2-ldc,druntime-ldc\",
\"-func-specialization-size-threshold=1000000000\",
];
// default switches appended after all explicit command-line switches
post-switches = [
Expand All @@ -63,6 +64,7 @@ runs:
{
switches = [
\"-defaultlib=phobos2-ldc,druntime-ldc\",
\"-func-specialization-size-threshold=1000000000\",
\"-Xcc=-target\",
\"-Xcc=x86_64-apple-macos\",
];
Expand All @@ -76,6 +78,7 @@ runs:
{
switches = [
\"-defaultlib=phobos2-ldc,druntime-ldc\",
\"-func-specialization-size-threshold=1000000000\",
\"-Xcc=-target\",
\"-Xcc=arm64-apple-macos\",
];
Expand All @@ -89,6 +92,7 @@ runs:
{
switches = [
\"-defaultlib=phobos2-ldc,druntime-ldc\",
\"-func-specialization-size-threshold=1000000000\",
\"-Xcc=-target\",
\"-Xcc=arm64-apple-ios$ios_version\",
\"-Xcc=-miphoneos-version-min=$ios_version\",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:

env:
CLANG_VERSION: 15.0.6
LLVM_VERSION: 15.0.7
LLVM_VERSION: 16.0.6

jobs:
build-native:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/supported_llvm_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
fail-fast: false
matrix:
include:
- job_name: Ubuntu 20.04, LLVM 16, latest LDC beta
os: ubuntu-20.04
host_dc: ldc-beta
llvm_version: 16.0.6 # LDC-LLVM
- job_name: Ubuntu 20.04, LLVM 15, latest LDC beta
os: ubuntu-20.04
host_dc: ldc-beta
Expand Down Expand Up @@ -91,8 +95,12 @@ jobs:
else
suffix='x86_64-linux-gnu-ubuntu-16.04'
fi
curl -fL --retry 3 --max-time 300 -o llvm.tar.xz \
https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/clang+llvm-$version-$suffix.tar.xz
url="https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/clang+llvm-$version-$suffix.tar.xz"
# FIXME: weird crashes with official v16.0.0 archive; use LDC-LLVM instead
if [[ "$version" =~ ^16\. ]]; then
url="https://github.com/ldc-developers/llvm-project/releases/download/ldc-v$version/llvm-$version-linux-x86_64.tar.xz"
fi
curl -fL --retry 3 --max-time 300 -o llvm.tar.xz "$url"
mkdir llvm
tar -xf llvm.tar.xz --strip 1 -C llvm
rm llvm.tar.xz
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#### Big news
- Frontend, druntime and Phobos are at version [2.104.2](https://dlang.org/changelog/2.104.0.html). (#4440)
- Support for [LLVM 16](https://releases.llvm.org/16.0.0/docs/ReleaseNotes.html). The prebuilt packages use v16.0.6. (#4411, #4423)
- We have come across miscompiles with LLVM 16's newly-enabled-by-default function specializations (on Win64 and macOS). To be on the safe side, LDC disables them by default for all targets via `-func-specialization-size-threshold=1000000000` in `etc/ldc2.conf` (and separately for LTO on Posix platforms). To enable the function specializations, explicitly override it with e.g. `-func-specialization-size-threshold=100` (the LLVM 16 default) and, for LTO on Posix, a similar LTO plugin option in the linker cmdline (see linker cmdline with `-v`).

#### Platform support
- Supports LLVM 11.0 - 15.0.
- Supports LLVM 11.0 - 16.0.

#### Bug fixes

Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,11 @@ else()
endif()
set(LDC_INSTALL_LLVM_RUNTIME_LIBS ${LDC_INSTALL_LLVM_RUNTIME_LIBS_DEFAULT} CACHE BOOL "Copy/install LLVM compiler-rt libraries (ASan, libFuzzer, ...) from LLVM/Clang into LDC lib dir when available.")
function(copy_compilerrt_lib llvm_lib_name ldc_lib_name fixup_dylib)
set(llvm_lib_path ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE_STRING}/lib/${llvm_lib_name})
if(LDC_LLVM_VER LESS 1600)
set(llvm_lib_path ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE_STRING}/lib/${llvm_lib_name})
else()
set(llvm_lib_path ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}/lib/${llvm_lib_name})
endif()
if(EXISTS ${llvm_lib_path})
message(STATUS "-- - ${llvm_lib_path} --> ${ldc_lib_name}")
set(ldc_lib_path ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/${ldc_lib_name})
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ libraries is available on the project wiki for
[Windows](http://wiki.dlang.org/Building_and_hacking_LDC_on_Windows_using_MSVC).

If you have a working C++/D build environment, CMake, and a recent LLVM
version (≥ 6.0) available, there should be no big surprises. Do not
forget to make sure all the submodules (druntime, phobos, dmd-testsuite)
are up to date:
version (≥ 11) available, there should be no big surprises. Do not
forget to make sure the Phobos submodule is up to date:

$ cd ldc
$ git submodule update --init
Expand Down
15 changes: 8 additions & 7 deletions cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the
# system default locations such as /usr/local/bin. Executing find_program()
# multiples times is the approach recommended in the docs.
set(llvm_config_names llvm-config-15.0 llvm-config150 llvm-config-15
set(llvm_config_names 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
Expand All @@ -47,13 +48,13 @@ if(APPLE)
# extra fallbacks for MacPorts & Homebrew
find_program(LLVM_CONFIG
NAMES ${llvm_config_names}
PATHS /opt/local/libexec/llvm-15/bin
/opt/local/libexec/llvm-14/bin /opt/local/libexec/llvm-13/bin /opt/local/libexec/llvm-12/bin
/opt/local/libexec/llvm-11/bin
PATHS /opt/local/libexec/llvm-16/bin /opt/local/libexec/llvm-15/bin
/opt/local/libexec/llvm-14/bin /opt/local/libexec/llvm-13/bin
/opt/local/libexec/llvm-12/bin /opt/local/libexec/llvm-11/bin
/opt/local/libexec/llvm/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@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
NO_DEFAULT_PATH)
endif()
Expand Down
4 changes: 4 additions & 0 deletions driver/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ int executeAndWait(std::vector<const char *> fullArgs,
}

const std::vector<llvm::StringRef> argv = toRefsVector(fullArgs);
#if LDC_LLVM_VER < 1600
auto envVars = llvm::None;
#else
auto envVars = std::nullopt;
#endif

return llvm::sys::ExecuteAndWait(argv[0], argv, envVars, {}, 0, 0, errorMsg);
}
Expand Down
9 changes: 5 additions & 4 deletions driver/cl_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ void hideLLVMOptions() {
"internalize-public-api-list", "iterative-counter-promotion",
"join-liveintervals", "jump-table-type", "limit-float-precision",
"lower-global-dtors-via-cxa-atexit",
"lto-embed-bitcode", "matrix-default-layout", "matrix-propagate-shape",
"lto-embed-bitcode", "matrix-default-layout",
"matrix-print-after-transpose-opt", "matrix-propagate-shape",
"max-counter-promotions", "max-counter-promotions-per-loop",
"mc-relax-all", "mc-x86-disable-arith-relaxation", "mcabac", "meabi",
"memop-size-large", "memop-size-range", "merror-missing-parenthesis",
Expand Down Expand Up @@ -882,9 +883,9 @@ void hideLLVMOptions() {
"speculative-counter-promotion-to-loop", "spiller", "spirv-debug",
"spirv-erase-cl-md", "spirv-lower-const-expr", "spirv-mem2reg",
"spirv-no-deref-attr", "spirv-text", "spirv-verify-regularize-passes",
"split-machine-functions", "spv-lower-saddwithoverflow-validate",
"spvbool-validate", "spvmemmove-validate",
"stack-alignment", "stack-protector-guard",
"split-machine-functions", "spv-dump-deps",
"spv-lower-saddwithoverflow-validate", "spvbool-validate",
"spvmemmove-validate", "stack-alignment", "stack-protector-guard",
"stack-protector-guard-offset", "stack-protector-guard-reg",
"stack-size-section", "stack-symbol-ordering",
"stackmap-version", "static-func-full-module-prefix",
Expand Down
10 changes: 10 additions & 0 deletions driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ void ArgsBuilder::addLTOGoldPluginFlags(bool requirePlugin) {
addLdFlag("-plugin-opt=-function-sections");
if (TO.DataSections)
addLdFlag("-plugin-opt=-data-sections");

#if LDC_LLVM_VER >= 1600 && LDC_LLVM_VER < 1700
// LLVM 16: disable function specializations by default
addLdFlag("-plugin-opt=-func-specialization-size-threshold=1000000000");
#endif
}

// Returns an empty string when libLTO.dylib was not specified nor found.
Expand Down Expand Up @@ -179,6 +184,11 @@ void ArgsBuilder::addDarwinLTOFlags() {
std::string dylibPath = getLTOdylibPath();
if (!dylibPath.empty()) {
addLdFlag("-lto_library", dylibPath);

#if LDC_LLVM_VER >= 1600 && LDC_LLVM_VER < 1700
// LLVM 16: disable function specializations by default
addLdFlag("-mllvm", "-func-specialization-size-threshold=1000000000");
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ static std::vector<std::string> getDefaultLibNames() {
llvm::Optional<std::vector<std::string>> getExplicitPlatformLibs() {
if (platformLib.getNumOccurrences() > 0)
return parseLibNames(platformLib);
#if LDC_LLVM_VER < 1600
return llvm::None;
#else
return std::nullopt;
#endif
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions driver/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ bool linkAgainstSharedDefaultLibs();
/**
* Returns the -platformlib library names, if specified.
*/
#if LDC_LLVM_VER < 1600
llvm::Optional<std::vector<std::string>> getExplicitPlatformLibs();
#else
std::optional<std::vector<std::string>> getExplicitPlatformLibs();
#endif

/**
* Returns the value of -mscrtlib.
Expand Down
2 changes: 2 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ void initializePasses() {
#endif
initializeVectorization(Registry);
initializeInstCombine(Registry);
#if LDC_LLVM_VER < 1600
initializeAggressiveInstCombine(Registry);
#endif
initializeIPO(Registry);
#if LDC_LLVM_VER < 1600
initializeInstrumentation(Registry);
Expand Down
2 changes: 2 additions & 0 deletions driver/targetmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ static std::string getARMTargetCPU(const llvm::Triple &triple) {
}

static std::string getAArch64TargetCPU(const llvm::Triple &triple) {
#if LDC_LLVM_VER < 1600
auto defaultCPU = llvm::AArch64::getDefaultCPU(triple.getArchName());
if (!defaultCPU.empty())
return std::string(defaultCPU);
#endif

return "generic";
}
Expand Down
5 changes: 2 additions & 3 deletions gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,10 @@ void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale,
////////////////////////////////////////////////////////////////////////////////
LLConstant *DtoConstSlice(LLConstant *dim, LLConstant *ptr, Type *type) {
LLConstant *values[2] = {dim, ptr};
llvm::ArrayRef<LLConstant *> valuesRef = llvm::makeArrayRef(values, 2);
LLStructType *lltype =
type ? isaStruct(DtoType(type))
: LLConstantStruct::getTypeForElements(gIR->context(), valuesRef);
return LLConstantStruct::get(lltype, valuesRef);
: LLConstantStruct::getTypeForElements(gIR->context(), values);
return LLConstantStruct::get(lltype, values);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion gen/dcompute/druntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ bool isFromLDC_OpenCL(Dsymbol *sym) {
}

llvm::Optional<DcomputePointer> toDcomputePointer(StructDeclaration *sd) {
if (sd->ident != Id::dcPointer || !isFromLDC_DCompute(sd))
if (sd->ident != Id::dcPointer || !isFromLDC_DCompute(sd)) {
#if LDC_LLVM_VER < 1600
return llvm::Optional<DcomputePointer>(llvm::None);
#else
return std::optional<DcomputePointer>(std::nullopt);
#endif
}

TemplateInstance *ti = sd->isInstantiated();
int addrspace = isExpression((*ti->tiargs)[0])->toInteger();
Expand Down
7 changes: 7 additions & 0 deletions gen/dibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
namespace cl = llvm::cl;
using LLMetadata = llvm::Metadata;

#if LDC_LLVM_VER >= 1600
namespace llvm {
template <typename T> using Optional = std::optional<T>;
inline constexpr std::nullopt_t None = std::nullopt;
}
#endif

static cl::opt<cl::boolOrDefault> emitColumnInfo(
"gcolumn-info", cl::ZeroOrMore, cl::Hidden,
cl::desc("Include column numbers in line debug infos. Defaults to "
Expand Down
5 changes: 5 additions & 0 deletions gen/ms-cxx-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ void cloneBlocks(const std::vector<llvm::BasicBlock *> &srcblocks,
if (!newInst)
newInst = Inst->clone();

#if LDC_LLVM_VER < 1600
nbb->getInstList().push_back(newInst);
#else
newInst->insertInto(nbb, nbb->end());
#endif

VMap[Inst] = newInst; // Add instruction map to value.
if (unwindTo)
if (auto dest = getUnwindDest(Inst))
Expand Down
9 changes: 9 additions & 0 deletions gen/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,13 @@ static llvm::Optional<PGOOptions> getPGOOptions() {
PGOOptions::CSPGOAction::NoCSAction,
debugInfoForProfiling, pseudoProbeForProfiling);
}
#if LDC_LLVM_VER < 1600
return None;
#else
return std::nullopt;
#endif
}

static PipelineTuningOptions getPipelineTuningOptions(unsigned optLevelVal, unsigned sizeLevelVal) {
PipelineTuningOptions pto;

Expand Down Expand Up @@ -621,7 +626,11 @@ void runOptimizationPasses(llvm::Module *M) {
bool debugLogging = false;
ppo.Indent = false;
ppo.SkipAnalyses = false;
#if LDC_LLVM_VER < 1600
StandardInstrumentations si(debugLogging, /*VerifyEach=*/false, ppo);
#else
StandardInstrumentations si(M->getContext(), debugLogging, /*VerifyEach=*/false, ppo);
#endif

si.registerCallbacks(pic, &fam);

Expand Down
Loading

0 comments on commit c1105d5

Please sign in to comment.