Skip to content

Commit 53ffdf1

Browse files
authored
Merge pull request #4911 from kinke/llvm-20_2
Add support for LLVM 20 (modulo dynamic-compile regressions)
2 parents a47fb2a + ad4a35a commit 53ffdf1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+11256
-120
lines changed

.cirrus.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clone_steps_template: &CLONE_STEPS_TEMPLATE
1212
common_steps_template: &COMMON_STEPS_TEMPLATE
1313
install_lit_script: |
1414
# Install lit
15-
rm -f /usr/lib/python3.12/EXTERNALLY-MANAGED # required for Ubuntu 24.04
15+
rm -f /usr/lib/python3.13/EXTERNALLY-MANAGED # required for Ubuntu 25.04
1616
python3 -m pip install --user lit
1717
python3 -c "import lit.main; lit.main.main();" --version . | head -n 1
1818
clone_submodules_script: |
@@ -197,8 +197,14 @@ task:
197197
environment:
198198
CI_ARCH: x86_64
199199
CI_OS: linux
200-
EXTRA_APT_PACKAGES: "gdmd llvm-dev libclang-common-19-dev lld"
201-
EXTRA_CMAKE_FLAGS: "-DBUILD_SHARED_LIBS=ON -DBUILD_LTO_LIBS=ON -DD_COMPILER=gdmd -DLDC_LINK_MANUALLY=ON"
200+
EXTRA_APT_PACKAGES: "gdmd llvm-dev libclang-common-20-dev lld libcurl4-openssl-dev"
201+
# need `-DCMAKE_EXE_LINKER_FLAGS=-lcurl` to work around libcurl dependency for ldc-profdata (distro LLVM apparently built with non-default LLVM_ENABLE_CURL=ON)
202+
EXTRA_CMAKE_FLAGS: >-
203+
-DBUILD_SHARED_LIBS=ON
204+
-DBUILD_LTO_LIBS=ON
205+
-DD_COMPILER=gdmd
206+
-DLDC_LINK_MANUALLY=ON
207+
-DCMAKE_EXE_LINKER_FLAGS=-lcurl
202208
PARALLELISM: 8
203209
# for gdmd:
204210
LANG: C.UTF-8

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ jobs:
242242
os: android
243243
arch: armv7a
244244
android_x86_arch: i686
245+
extra_cmake_flags: >-
246+
-DLDC_INSTALL_LLVM_RUNTIME_LIBS_ARCH=arm-android
245247
246248
- job_name: Android aarch64
247249
host_os: ubuntu-22.04

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,15 @@ if (LDC_INSTALL_LLVM_RUNTIME_LIBS)
898898
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
899899
set(compilerrt_arch_suffix "i386")
900900
endif()
901-
copy_compilerrt_lib("clang_rt.asan-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
902-
copy_compilerrt_lib("clang_rt.lsan-${compilerrt_arch_suffix}.lib" "ldc_rt.lsan.lib" FALSE)
901+
if(LDC_LLVM_VER LESS 2000)
902+
copy_compilerrt_lib("clang_rt.asan-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
903+
copy_compilerrt_lib("clang_rt.lsan-${compilerrt_arch_suffix}.lib" "ldc_rt.lsan.lib" FALSE)
904+
else()
905+
copy_compilerrt_lib("clang_rt.asan_static_runtime_thunk-${compilerrt_arch_suffix}.lib" "ldc_rt.asan_static_runtime_thunk.lib" FALSE)
906+
copy_compilerrt_lib("clang_rt.asan_dynamic_runtime_thunk-${compilerrt_arch_suffix}.lib" "ldc_rt.asan_dynamic_runtime_thunk.lib" FALSE)
907+
copy_compilerrt_lib("clang_rt.asan_dynamic-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
908+
copy_compilerrt_lib("clang_rt.asan_dynamic-${compilerrt_arch_suffix}.dll" "clang_rt.asan_dynamic-${compilerrt_arch_suffix}.dll" FALSE)
909+
endif()
903910
copy_compilerrt_lib("clang_rt.builtins-${compilerrt_arch_suffix}.lib" "ldc_rt.builtins.lib" FALSE)
904911
copy_compilerrt_lib("clang_rt.profile-${compilerrt_arch_suffix}.lib" "ldc_rt.profile.lib" FALSE)
905912
copy_compilerrt_lib("clang_rt.fuzzer-${compilerrt_arch_suffix}.lib" "ldc_rt.fuzzer.lib" FALSE)

cmake/Modules/FindLLVM.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the
3333
# system default locations such as /usr/local/bin. Executing find_program()
3434
# multiples times is the approach recommended in the docs.
35-
set(llvm_config_names llvm-config-19.1 llvm-config191 llvm-config-19
35+
set(llvm_config_names llvm-config-20.1 llvm-config201 llvm-config-20
36+
llvm-config-19.1 llvm-config191 llvm-config-19
3637
llvm-config-18.1 llvm-config181 llvm-config-18
3738
llvm-config-17.0 llvm-config170 llvm-config-17
3839
llvm-config-16.0 llvm-config160 llvm-config-16
@@ -47,11 +48,11 @@ if(APPLE)
4748
# extra fallbacks for MacPorts & Homebrew
4849
find_program(LLVM_CONFIG
4950
NAMES ${llvm_config_names}
50-
PATHS /opt/local/libexec/llvm-19/bin
51+
PATHS /opt/local/libexec/llvm-20/bin /opt/local/libexec/llvm-19/bin
5152
/opt/local/libexec/llvm-18/bin /opt/local/libexec/llvm-17/bin
5253
/opt/local/libexec/llvm-16/bin /opt/local/libexec/llvm-15/bin
5354
/opt/local/libexec/llvm/bin
54-
/usr/local/opt/llvm@19/bin
55+
/usr/local/opt/llvm@20/bin /usr/local/opt/llvm@19/bin
5556
/usr/local/opt/llvm@18/bin /usr/local/opt/llvm@17/bin
5657
/usr/local/opt/llvm@16/bin /usr/local/opt/llvm@15/bin
5758
/usr/local/opt/llvm/bin

driver/cl_options.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -818,17 +818,21 @@ void hideLLVMOptions() {
818818
"amdgpu-dump-hsa-metadata", "amdgpu-enable-flat-scratch",
819819
"amdgpu-enable-global-sgpr-addr", "amdgpu-enable-merge-m0",
820820
"amdgpu-enable-power-sched", "amdgpu-igrouplp",
821-
"amdgpu-kernarg-preload-count", "amdgpu-promote-alloca-to-vector-limit",
821+
"amdgpu-indirect-call-specialization-threshold",
822+
"amdgpu-kernarg-preload-count", "amdgpu-module-splitting-max-depth",
823+
"amdgpu-promote-alloca-to-vector-limit",
822824
"amdgpu-reserve-vgpr-for-sgpr-spill", "amdgpu-sdwa-peephole",
823825
"amdgpu-use-aa-in-codegen", "amdgpu-verify-hsa-metadata",
824-
"amdgpu-vgpr-index-mode", "arm-add-build-attributes",
826+
"amdgpu-vgpr-index-mode", "argext-abi-check",
827+
"arm-add-build-attributes",
825828
"arm-implicit-it", "asm-instrumentation", "asm-show-inst",
826829
"atomic-counter-update-promoted", "atomic-first-counter",
827-
"basic-block-sections",
830+
"basic-block-address-map", "basic-block-sections",
828831
"basicblock-sections", "bounds-checking-single-trap",
829832
"bounds-checking-unique-traps", "bpf-stack-size", "cfg-hide-cold-paths",
830833
"cfg-hide-deoptimize-paths", "cfg-hide-unreachable-paths",
831-
"code-model", "cost-kind", "cppfname", "cppfor", "cppgen",
834+
"check-functions-filter", "code-model", "conditional-counter-update",
835+
"cost-kind", "cppfname", "cppfor", "cppgen", "crel",
832836
"cvp-dont-add-nowrap-flags",
833837
"cvp-dont-process-adds", "debug-counter", "debug-entry-values",
834838
"debugger-tune", "debugify-func-limit", "debugify-level",
@@ -847,27 +851,32 @@ void hideLLVMOptions() {
847851
"enable-cse-in-irtranslator", "enable-cse-in-legalizer",
848852
"enable-emscripten-cxx-exceptions", "enable-emscripten-sjlj",
849853
"enable-fp-mad", "enable-gvn-hoist", "enable-gvn-memdep",
854+
"enable-gvn-memoryssa",
850855
"enable-gvn-sink", "enable-implicit-null-checks", "enable-jmc-instrument",
851-
"enable-load-in-loop-pre",
856+
"enable-jump-table-to-switch", "enable-load-in-loop-pre",
852857
"enable-load-pre", "enable-loop-simplifycfg-term-folding",
853858
"enable-misched", "enable-name-compression", "enable-no-infs-fp-math",
854859
"enable-no-nans-fp-math", "enable-no-signed-zeros-fp-math",
855860
"enable-no-trapping-fp-math", "enable-objc-arc-annotations",
856-
"enable-objc-arc-opts", "enable-pie", "enable-scoped-noalias",
861+
"enable-objc-arc-opts", "enable-pgo-force-function-attrs",
862+
"enable-pie", "enable-scoped-noalias",
857863
"enable-split-backedge-in-load-pre", "enable-split-loopiv-heuristic",
858864
"enable-tbaa", "enable-tlsdesc", "enable-unsafe-fp-math",
859-
"exception-model", "exhaustive-register-search", "expensive-combines",
865+
"enable-vtable-profile-use", "enable-vtable-value-profiling",
866+
"exception-model", "exhaustive-register-search",
867+
"expand-variadics-override", "expensive-combines",
860868
"experimental-debug-variable-locations",
861869
"experimental-debuginfo-iterators",
862-
"fatal-assembler-warnings", "filter-print-funcs",
870+
"fatal-assembler-warnings", "fdpic", "filter-print-funcs",
863871
"force-dwarf-frame-section", "force-opaque-pointers",
864872
"force-tail-folding-style",
865873
"fs-profile-debug-bw-threshold", "fs-profile-debug-prob-diff-threshold",
866874
"generate-merged-base-profiles",
867-
"gpsize", "hash-based-counter-split", "hexagon-rdf-limit",
868-
"hot-cold-split", "ignore-xcoff-visibility",
875+
"gpsize", "hash-based-counter-split", "hexagon-add-build-attributes",
876+
"hexagon-rdf-limit", "hot-cold-split", "hwasan-percentile-cutoff-hot",
877+
"hwasan-random-rate", "ignore-xcoff-visibility",
869878
"imp-null-check-page-size", "imp-null-max-insts-to-consider",
870-
"import-all-index", "incremental-linker-compatible",
879+
"implicit-mapsyms", "import-all-index", "incremental-linker-compatible",
871880
"instcombine-code-sinking", "instcombine-guard-widening-window",
872881
"instcombine-max-iterations", "instcombine-max-num-phis",
873882
"instcombine-max-sink-users",
@@ -876,7 +885,9 @@ void hideLLVMOptions() {
876885
"instrprof-atomic-counter-update-all", "internalize-public-api-file",
877886
"internalize-public-api-list", "iterative-counter-promotion",
878887
"join-liveintervals", "jump-table-type", "large-data-threshold",
879-
"limit-float-precision", "lower-global-dtors-via-cxa-atexit",
888+
"limit-float-precision", "lint-abort-on-error", "loongarch-use-aa",
889+
"lower-allow-check-percentile-cutoff-hot",
890+
"lower-allow-check-random-rate", "lower-global-dtors-via-cxa-atexit",
880891
"lto-embed-bitcode", "matrix-default-layout",
881892
"matrix-print-after-transpose-opt", "matrix-propagate-shape",
882893
"max-counter-promotions", "max-counter-promotions-per-loop",
@@ -888,7 +899,7 @@ void hideLLVMOptions() {
888899
"mno-fixup", "mno-ldc1-sdc1", "mno-pairing", "mwarn-missing-parenthesis",
889900
"mwarn-noncontigious-register", "mwarn-sign-mismatch", "mxcoff-roptr",
890901
"no-discriminators", "no-integrated-as", "no-type-check", "no-xray-index",
891-
"nozero-initialized-in-bss", "nvptx-sched4reg",
902+
"nozero-initialized-in-bss", "nvptx-approx-log2f32", "nvptx-sched4reg",
892903
"objc-arc-annotation-target-identifier",
893904
"object-size-offset-visitor-max-visit-instructions",
894905
"pgo-block-coverage", "pgo-temporal-instrumentation",
@@ -900,21 +911,26 @@ void hideLLVMOptions() {
900911
"print-pipeline-passes", "profile-correlate",
901912
"profile-estimator-loop-weight", "profile-estimator-loop-weight",
902913
"profile-file", "profile-info-file", "profile-verifier-noassert",
903-
"pseudo-probe-for-profiling",
914+
"promote-alloca-vector-loop-user-weight", "pseudo-probe-for-profiling",
904915
"r600-ir-structurize", "rdf-dump", "rdf-limit", "recip", "regalloc",
905916
"relax-elf-relocations", "remarks-section", "rewrite-map-file",
906917
"riscv-add-build-attributes", "riscv-use-aa", "rng-seed",
907918
"runtime-counter-relocation", "safepoint-ir-verifier-print-only",
908919
"sample-profile-check-record-coverage",
909920
"sample-profile-check-sample-coverage",
910921
"sample-profile-inline-hot-threshold",
911-
"sample-profile-max-propagate-iterations", "shrink-wrap", "simplify-mir",
922+
"sample-profile-max-propagate-iterations",
923+
"sampled-instr-burst-duration", "sampled-instr-period",
924+
"sampled-instrumentation", "save-temp-labels", "separate-named-sections",
925+
"shrink-wrap", "simplify-mir",
912926
"skip-ret-exit-block",
913927
"speculative-counter-promotion-max-exiting",
914928
"speculative-counter-promotion-to-loop", "spiller", "spirv-debug",
915-
"spirv-erase-cl-md", "spirv-lower-const-expr", "spirv-mem2reg",
929+
"spirv-erase-cl-md", "spirv-ext", "spirv-lower-const-expr",
930+
"spirv-mem2reg",
916931
"spirv-no-deref-attr", "spirv-text", "spirv-verify-regularize-passes",
917932
"split-machine-functions", "spv-dump-deps",
933+
"spv-emit-nonsemantic-debug-info",
918934
"spv-lower-saddwithoverflow-validate", "spvbool-validate",
919935
"spvmemmove-validate", "stack-alignment", "stack-protector-guard",
920936
"stack-protector-guard-offset", "stack-protector-guard-reg",
@@ -923,21 +939,23 @@ void hideLLVMOptions() {
923939
"static-func-strip-dirname-prefix", "stats", "stats-json", "strict-dwarf",
924940
"strip-debug", "struct-path-tbaa", "summary-file", "sve-tail-folding",
925941
"swift-async-fp",
926-
"tail-predication", "tailcallopt", "thinlto-assume-merged",
942+
"tail-predication", "tailcallopt", "target-abi", "thinlto-assume-merged",
927943
"thread-model", "time-passes", "time-trace-granularity", "tls-size",
944+
"translator-compatibility-mode",
928945
"type-based-intrinsic-cost", "unfold-element-atomic-memcpy-max-elements",
929946
"unique-basic-block-section-names", "unique-bb-section-names",
930947
"unique-section-names", "unit-at-a-time", "use-ctors",
931948
"vec-extabi", "verify-debug-info", "verify-dom-info",
932949
"verify-legalizer-debug-locs", "verify-loop-info",
933950
"verify-loop-lcssa", "verify-machine-dom-info", "verify-regalloc",
934951
"verify-region-info", "verify-scev", "verify-scev-maps",
935-
"vp-counters-per-site", "vp-static-alloc",
936-
"wasm-enable-eh", "wasm-enable-sjlj",
952+
"vp-counters-per-site", "vp-static-alloc", "wasm-enable-eh",
953+
"wasm-enable-exnref", "wasm-enable-sjlj", "wasm-use-legacy-eh",
954+
"wholeprogramdevirt-cutoff", "write-experimental-debuginfo",
937955
"x86-align-branch", "x86-align-branch-boundary",
938956
"x86-branches-within-32B-boundaries", "x86-early-ifcvt",
939-
"x86-pad-max-prefix-size",
940-
"x86-recip-refinement-steps", "x86-use-vzeroupper",
957+
"x86-pad-max-prefix-size", "x86-recip-refinement-steps",
958+
"x86-relax-relocations", "x86-sse2avx", "x86-use-vzeroupper",
941959
"xcoff-traceback-table", "xray-function-index",
942960

943961
// We enable -fdata-sections/-ffunction-sections by default where it makes

driver/cl_options_sanitizers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
#pragma once
1515

1616
#include "driver/cl_helpers.h"
17+
#if LDC_LLVM_VER >= 2000
18+
#include "llvm/Transforms/Utils/Instrumentation.h"
19+
#else
1720
#include "llvm/Transforms/Instrumentation.h"
21+
#endif
1822

1923
class FuncDeclaration;
2024
namespace llvm {

driver/linker-msvc.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@ void addLibIfFound(std::vector<std::string> &args, const llvm::Twine &name) {
7373
}
7474
}
7575

76-
void addSanitizerLibs(std::vector<std::string> &args) {
76+
void addSanitizerLibs(bool useInternalToolchain,
77+
std::vector<std::string> &args) {
7778
if (opts::isSanitizerEnabled(opts::AddressSanitizer)) {
7879
args.push_back("ldc_rt.asan.lib");
80+
#if LDC_LLVM_VER >= 2000 // extra library since LLVM 20
81+
const bool linkStaticCRT =
82+
getMscrtLibName(&useInternalToolchain).contains_lower("libcmt");
83+
args.push_back((llvm::Twine("ldc_rt.asan_") +
84+
(linkStaticCRT ? "static" : "dynamic") +
85+
"_runtime_thunk.lib")
86+
.str());
87+
#endif
7988
} else if (opts::isSanitizerEnabled(opts::LeakSanitizer)) {
8089
// If ASan is enabled, it includes LSan. So only add LSan link flags if ASan is _not_ enabled already.
8190
args.push_back("ldc_rt.lsan.lib");
@@ -187,7 +196,7 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
187196

188197
// LLVM compiler-rt libs
189198
addLibIfFound(args, "ldc_rt.builtins.lib");
190-
addSanitizerLibs(args);
199+
addSanitizerLibs(useInternalToolchain, args);
191200
if (opts::isInstrumentingForPGO()) {
192201
args.push_back("ldc_rt.profile.lib");
193202
// it depends on ws2_32 for symbol `gethostname`

driver/targetmachine.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@
5151
#endif
5252

5353
#ifdef LDC_LLVM_SUPPORTS_MACHO_DWARF_LINE_AS_REGULAR_SECTION
54-
// LDC-LLVM >= 6.0.1:
55-
// On Mac, emit __debug_line section in __DWARF segment as regular (non-debug)
56-
// section, like DMD, to enable file/line infos in backtraces. See
54+
// LDC-LLVM >= 20:
55+
// On Darwin, emit __debug_line section in __DWARF segment as regular
56+
// (non-debug) section, like DMD, to enable file/line infos in backtraces
57+
// without having to resort to an atos process. See
58+
// https://github.com/ldc-developers/ldc/issues/4895
5759
// https://github.com/dlang/dmd/commit/2bf7d0db29416eacbb01a91e6502140e354ee0ef
58-
// https://github.com/ldc-developers/llvm-project/commit/110deda1bc1cf195983fea8c1107886057987955
60+
// https://github.com/ldc-developers/llvm-project/commit/356e996bd217afd883adf3da5fe9a16c1102b273
5961
static llvm::cl::opt<bool, true> preserveDwarfLineSection(
6062
"preserve-dwarf-line-section",
61-
llvm::cl::desc("Mac: preserve DWARF line section during linking for "
62-
"file/line infos in backtraces. Defaults to true."),
63+
llvm::cl::desc("Darwin: preserve DWARF __debug_line section during linking "
64+
"for builtin file/line infos in backtraces without having "
65+
"to resort to an atos process."),
6366
llvm::cl::Hidden, llvm::cl::ZeroOrMore,
6467
llvm::cl::location(ldc::emitMachODwarfLineAsRegularSection),
6568
llvm::cl::init(false));

gen/abi/aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct AArch64TargetABI : TargetABI {
130130
// compiler magic: pass va_list args implicitly by reference
131131
if (!isReturnVal && isAAPCS64VaList(t)) {
132132
arg.byref = true;
133-
arg.ltype = arg.ltype->getPointerTo();
133+
arg.ltype = LLPointerType::getUnqual(arg.ltype);
134134
return;
135135
}
136136

gen/classes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ DValue *DtoDynamicCastObject(Loc loc, DValue *val, Type *_to) {
382382
// Object _d_dynamic_cast(Object o, ClassInfo c)
383383
llvm::Function *func =
384384
getRuntimeFunction(loc, gIR->module, "_d_dynamic_cast");
385-
LLFunctionType *funcTy = func->getFunctionType();
385+
[[maybe_unused]] LLFunctionType *funcTy = func->getFunctionType();
386386

387387
// Object o
388388
LLValue *obj = DtoRVal(val);
@@ -483,7 +483,7 @@ DtoVirtualFunctionPointer(DValue *inst, FuncDeclaration *fdecl) {
483483
// get the vtbl for objects
484484
vtable = DtoGEP(irtc->getMemoryLLType(), vthis, 0u, 0);
485485
// load vtbl ptr
486-
vtable = DtoLoad(vtblType->getPointerTo(), vtable);
486+
vtable = DtoLoad(LLPointerType::getUnqual(vtblType), vtable);
487487
// index vtbl
488488
const std::string name = fdecl->toChars();
489489
const auto vtblname = name + "@vtbl";

gen/dcompute/druntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct DcomputePointer {
4141
int as = addrspace;
4242
if (translate)
4343
as = gIR->dcomputetarget->mapping[as];
44-
return llType->getPointerTo(as);
44+
return LLPointerType::get(llType, as);
4545
}
4646
};
4747
llvm::Optional<DcomputePointer> toDcomputePointer(StructDeclaration *sd);

0 commit comments

Comments
 (0)