Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::attributes::{self, llfn_attrs_from_instance};
use crate::builder::Builder;
use crate::context::CodegenCx;
use crate::llvm::{self, Attribute, AttributePlace, Type, Value};
use crate::llvm_util;
use crate::type_of::LayoutLlvmExt;

trait ArgAttributesExt {
Expand All @@ -46,6 +45,12 @@ const OPTIMIZATION_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 4] = [
(ArgAttribute::NoUndef, llvm::AttributeKind::NoUndef),
];

const CAPTURES_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 3] = [
(ArgAttribute::CapturesNone, llvm::AttributeKind::CapturesNone),
(ArgAttribute::CapturesAddress, llvm::AttributeKind::CapturesAddress),
(ArgAttribute::CapturesReadOnly, llvm::AttributeKind::CapturesReadOnly),
];

fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'ll Attribute; 8]> {
let mut regular = this.regular;

Expand Down Expand Up @@ -82,18 +87,10 @@ fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'
attrs.push(llattr.create_attr(cx.llcx));
}
}
// captures(...) is only available since LLVM 21.
if (21, 0, 0) <= llvm_util::get_version() {
const CAPTURES_ATTRIBUTES: [(ArgAttribute, llvm::AttributeKind); 3] = [
(ArgAttribute::CapturesNone, llvm::AttributeKind::CapturesNone),
(ArgAttribute::CapturesAddress, llvm::AttributeKind::CapturesAddress),
(ArgAttribute::CapturesReadOnly, llvm::AttributeKind::CapturesReadOnly),
];
for (attr, llattr) in CAPTURES_ATTRIBUTES {
if regular.contains(attr) {
attrs.push(llattr.create_attr(cx.llcx));
break;
}
for (attr, llattr) in CAPTURES_ATTRIBUTES {
if regular.contains(attr) {
attrs.push(llattr.create_attr(cx.llcx));
break;
}
}
} else if cx.tcx.sess.sanitizers().contains(SanitizerSet::MEMORY) {
Expand Down Expand Up @@ -508,9 +505,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
}
PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => {
let i = apply(attrs);
if cx.sess().opts.optimize != config::OptLevel::No
&& llvm_util::get_version() >= (21, 0, 0)
{
if cx.sess().opts.optimize != config::OptLevel::No {
attributes::apply_to_llfn(
llfn,
llvm::AttributePlace::Argument(i),
Expand Down
14 changes: 5 additions & 9 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,11 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
to_add.push(llvm::CreateAllocKindAttr(cx.llcx, AllocKindFlags::Free));
// applies to argument place instead of function place
let allocated_pointer = AttributeKind::AllocatedPointer.create_attr(cx.llcx);
let attrs: &[_] = if llvm_util::get_version() >= (21, 0, 0) {
// "Does not capture provenance" means "if the function call stashes the pointer somewhere,
// accessing that pointer after the function returns is UB". That is definitely the case here since
// freeing will destroy the provenance.
let captures_addr = AttributeKind::CapturesAddress.create_attr(cx.llcx);
&[allocated_pointer, captures_addr]
} else {
&[allocated_pointer]
};
// "Does not capture provenance" means "if the function call stashes the pointer somewhere,
// accessing that pointer after the function returns is UB". That is definitely the case here since
// freeing will destroy the provenance.
let captures_addr = AttributeKind::CapturesAddress.create_attr(cx.llcx);
let attrs = &[allocated_pointer, captures_addr];
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), attrs);
}
if let Some(align) = codegen_fn_attrs.alignment {
Expand Down
16 changes: 0 additions & 16 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,6 @@ pub(crate) unsafe fn create_module<'ll>(
let mut target_data_layout = sess.target.data_layout.to_string();
let llvm_version = llvm_util::get_version();

if llvm_version < (21, 0, 0) {
if sess.target.arch == Arch::Nvptx64 {
// LLVM 21 updated the default layout on nvptx: https://github.com/llvm/llvm-project/pull/124961
target_data_layout = target_data_layout.replace("e-p6:32:32-i64", "e-i64");
}
if sess.target.arch == Arch::AmdGpu {
// LLVM 21 adds the address width for address space 8.
// See https://github.com/llvm/llvm-project/pull/139419
target_data_layout = target_data_layout.replace("p8:128:128:128:48", "p8:128:128")
}
}
if llvm_version < (22, 0, 0) {
if sess.target.arch == Arch::Avr {
// LLVM 22.0 updated the default layout on avr: https://github.com/llvm/llvm-project/pull/153010
Expand Down Expand Up @@ -342,11 +331,6 @@ pub(crate) unsafe fn create_module<'ll>(
// Add "kcfi-arity" module flag if KCFI arity indicator is enabled. (See
// https://github.com/llvm/llvm-project/pull/117121.)
if sess.is_sanitizer_kcfi_arity_enabled() {
// KCFI arity indicator requires LLVM 21.0.0 or later.
if llvm_version < (21, 0, 0) {
tcx.dcx().emit_err(crate::errors::SanitizerKcfiArityRequiresLLVM2100);
}

llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Override,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,3 @@ pub(crate) struct MismatchedDataLayout<'a> {
pub(crate) struct FixedX18InvalidArch<'a> {
pub arch: &'a str,
}

#[derive(Diagnostic)]
#[diag("`-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later")]
pub(crate) struct SanitizerKcfiArityRequiresLLVM2100;
20 changes: 0 additions & 20 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
},

// Filter out features that are not supported by the current LLVM version
Arch::LoongArch32 | Arch::LoongArch64 => match s {
"32s" if major < 21 => None,
s => Some(LLVMFeature::new(s)),
},
Arch::PowerPC | Arch::PowerPC64 => match s {
"power8-crypto" => Some(LLVMFeature::new("crypto")),
s => Some(LLVMFeature::new(s)),
Expand Down Expand Up @@ -372,23 +368,12 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
let (major, _, _) = version;

cfg.has_reliable_f16 = match (target_arch, target_os) {
// LLVM crash without neon <https://github.com/llvm/llvm-project/issues/129394> (fixed in LLVM 20.1.1)
(Arch::AArch64, _)
if !cfg.target_features.iter().any(|f| f.as_str() == "neon")
&& version < (20, 1, 1) =>
{
false
}
// Unsupported <https://github.com/llvm/llvm-project/issues/94434> (fixed in llvm22)
(Arch::Arm64EC, _) if major < 22 => false,
// Selection failure <https://github.com/llvm/llvm-project/issues/50374> (fixed in llvm21)
(Arch::S390x, _) if major < 21 => false,
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
(Arch::CSky, _) if major < 22 => false, // (fixed in llvm22)
(Arch::Hexagon, _) if major < 21 => false, // (fixed in llvm21)
(Arch::LoongArch32 | Arch::LoongArch64, _) if major < 21 => false, // (fixed in llvm21)
(Arch::PowerPC | Arch::PowerPC64, _) if major < 22 => false, // (fixed in llvm22)
(Arch::Sparc | Arch::Sparc64, _) if major < 22 => false, // (fixed in llvm22)
(Arch::Wasm32 | Arch::Wasm64, _) if major < 22 => false, // (fixed in llvm22)
Expand All @@ -403,8 +388,6 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
(Arch::AmdGpu, _) => false,
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
(Arch::Arm64EC, _) => false,
// Selection bug <https://github.com/llvm/llvm-project/issues/96432> (fixed in LLVM 20.1.0)
(Arch::Mips64 | Arch::Mips64r6, _) if version < (20, 1, 0) => false,
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>. This issue is closed
// but basic math still does not work.
(Arch::Nvptx64, _) => false,
Expand All @@ -413,9 +396,6 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
(Arch::PowerPC | Arch::PowerPC64, _) => false,
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
(Arch::Sparc, _) => false,
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
// not fail if our compiler-builtins is linked. (fixed in llvm21)
(Arch::X86, _) if major < 21 => false,
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
// There are no known problems on other platforms, so the only requirement is that symbols
Expand Down
29 changes: 1 addition & 28 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(

std::string Error;
auto Trip = Triple(Triple::normalize(TripleStr));
const llvm::Target *TheTarget =
#if LLVM_VERSION_GE(21, 0)
TargetRegistry::lookupTarget(Trip, Error);
#else
TargetRegistry::lookupTarget(Trip.getTriple(), Error);
#endif
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip, Error);
if (TheTarget == nullptr) {
LLVMRustSetLastError(Error.c_str());
return nullptr;
Expand Down Expand Up @@ -367,13 +362,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(

Options.EmitStackSizeSection = EmitStackSizeSection;

#if LLVM_VERSION_GE(21, 0)
TargetMachine *TM = TheTarget->createTargetMachine(Trip, CPU, Feature,
Options, RM, CM, OptLevel);
#else
TargetMachine *TM = TheTarget->createTargetMachine(
Trip.getTriple(), CPU, Feature, Options, RM, CM, OptLevel);
#endif

if (LargeDataThreshold != 0) {
TM->setLargeDataThreshold(LargeDataThreshold);
Expand Down Expand Up @@ -701,12 +691,8 @@ extern "C" LLVMRustResult LLVMRustOptimize(
if (LintIR) {
PipelineStartEPCallbacks.push_back([](ModulePassManager &MPM,
OptimizationLevel Level) {
#if LLVM_VERSION_GE(21, 0)
MPM.addPass(
createModuleToFunctionPassAdaptor(LintPass(/*AbortOnError=*/true)));
#else
MPM.addPass(createModuleToFunctionPassAdaptor(LintPass()));
#endif
});
}

Expand Down Expand Up @@ -1210,12 +1196,8 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, size_t num_modules,
// Convert the preserved symbols set from string to GUID, this is then needed
// for internalization.
for (size_t i = 0; i < num_symbols; i++) {
#if LLVM_VERSION_GE(21, 0)
auto GUID =
GlobalValue::getGUIDAssumingExternalLinkage(preserved_symbols[i]);
#else
auto GUID = GlobalValue::getGUID(preserved_symbols[i]);
#endif
Ret->GUIDPreservedSymbols.insert(GUID);
}

Expand Down Expand Up @@ -1474,21 +1456,12 @@ extern "C" void LLVMRustComputeLTOCacheKey(RustStringRef KeyOut,
DenseSet<GlobalValue::GUID> CfiFunctionDecls;

// Based on the 'InProcessThinBackend' constructor in LLVM
#if LLVM_VERSION_GE(21, 0)
for (auto &Name : Data->Index.cfiFunctionDefs().symbols())
CfiFunctionDefs.insert(GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(Name)));
for (auto &Name : Data->Index.cfiFunctionDecls().symbols())
CfiFunctionDecls.insert(GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(Name)));
#else
for (auto &Name : Data->Index.cfiFunctionDefs())
CfiFunctionDefs.insert(
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
for (auto &Name : Data->Index.cfiFunctionDecls())
CfiFunctionDecls.insert(
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));
#endif

Key = llvm::computeLTOCacheKey(conf, Data->Index, ModId, ImportList,
ExportList, ResolvedODR, DefinedGlobals,
Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ extern "C" void LLVMRustSetLastError(const char *Err) {

extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
const char *Target) {
#if LLVM_VERSION_GE(21, 0)
unwrap(M)->setTargetTriple(Triple(Triple::normalize(Target)));
#else
unwrap(M)->setTargetTriple(Triple::normalize(Target));
#endif
}

extern "C" void LLVMRustPrintPassTimings(RustStringRef OutBuf) {
Expand Down Expand Up @@ -452,11 +448,7 @@ static Attribute::AttrKind fromRust(LLVMRustAttributeKind Kind) {
case LLVMRustAttributeKind::DeadOnUnwind:
return Attribute::DeadOnUnwind;
case LLVMRustAttributeKind::DeadOnReturn:
#if LLVM_VERSION_GE(21, 0)
return Attribute::DeadOnReturn;
#else
report_fatal_error("DeadOnReturn attribute requires LLVM 21 or later");
#endif
case LLVMRustAttributeKind::CapturesAddress:
case LLVMRustAttributeKind::CapturesReadOnly:
case LLVMRustAttributeKind::CapturesNone:
Expand Down Expand Up @@ -514,7 +506,6 @@ extern "C" void LLVMRustEraseInstFromParent(LLVMValueRef Instr) {

extern "C" LLVMAttributeRef
LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) {
#if LLVM_VERSION_GE(21, 0)
if (RustAttr == LLVMRustAttributeKind::CapturesNone) {
return wrap(Attribute::getWithCaptureInfo(*unwrap(C), CaptureInfo::none()));
}
Expand All @@ -527,7 +518,6 @@ LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) {
*unwrap(C), CaptureInfo(CaptureComponents::Address |
CaptureComponents::ReadProvenance)));
}
#endif
#if LLVM_VERSION_GE(23, 0)
if (RustAttr == LLVMRustAttributeKind::DeadOnReturn) {
return wrap(Attribute::getWithDeadOnReturnInfo(*unwrap(C),
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,11 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
let version = get_llvm_version(builder, llvm_config);
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
if let (Some(major), Some(_minor)) = (parts.next(), parts.next())
&& major >= 20
&& major >= 21
{
return;
}
panic!("\n\nbad LLVM version: {version}, need >=20\n\n")
panic!("\n\nbad LLVM version: {version}, need >=21\n\n")
}

fn configure_cmake(
Expand Down
8 changes: 4 additions & 4 deletions src/ci/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ To run a specific CI job locally, you can use the `citool` Rust crate:
cargo run --manifest-path src/ci/citool/Cargo.toml run-local <job-name>
```

For example, to run the `x86_64-gnu-llvm-20-1` job:
For example, to run the `x86_64-gnu-llvm-21-1` job:
```
cargo run --manifest-path src/ci/citool/Cargo.toml run-local x86_64-gnu-llvm-20-1
cargo run --manifest-path src/ci/citool/Cargo.toml run-local x86_64-gnu-llvm-21-1
```

The job will output artifacts in an `obj/<image-name>` dir at the root of a repository. Note
Expand All @@ -27,10 +27,10 @@ Docker image executed in the given CI job.
while locally, to the `obj/<image-name>` directory. This is primarily to prevent
strange linker errors when using multiple Docker images.

For some Linux workflows (for example `x86_64-gnu-llvm-20-N`), the process is more involved. You will need to see which script is executed for the given workflow inside the [`jobs.yml`](../github-actions/jobs.yml) file and pass it through the `DOCKER_SCRIPT` environment variable. For example, to reproduce the `x86_64-gnu-llvm-20-3` workflow, you can run the following script:
For some Linux workflows (for example `x86_64-gnu-llvm-21-N`), the process is more involved. You will need to see which script is executed for the given workflow inside the [`jobs.yml`](../github-actions/jobs.yml) file and pass it through the `DOCKER_SCRIPT` environment variable. For example, to reproduce the `x86_64-gnu-llvm-21-3` workflow, you can run the following script:

```
DOCKER_SCRIPT=x86_64-gnu-llvm3.sh ./src/ci/docker/run.sh x86_64-gnu-llvm-20
DOCKER_SCRIPT=x86_64-gnu-llvm3.sh ./src/ci/docker/run.sh x86_64-gnu-llvm-21
```

## Local Development
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
sudo \
gdb \
llvm-20-tools \
llvm-20-dev \
llvm-21-tools \
llvm-21-dev \
libedit-dev \
libssl-dev \
pkg-config \
Expand All @@ -42,7 +42,7 @@ ENV EXTERNAL_LLVM="1"

# Using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS="--build=aarch64-unknown-linux-gnu \
--llvm-root=/usr/lib/llvm-20 \
--llvm-root=/usr/lib/llvm-21 \
--enable-llvm-link-shared \
--set rust.randomize-layout=true \
--set rust.thin-lto-import-instr-limit=10"
Expand Down
Loading
Loading