Skip to content

Commit 140a9b4

Browse files
committed
Auto merge of rust-lang#140414 - ChrisDenton:rollup-sgoos3d, r=ChrisDenton
Rollup of 10 pull requests Successful merges: - rust-lang#139308 (add autodiff inline) - rust-lang#139656 (Stabilize `slice_as_chunks` library feature) - rust-lang#140022 (allow deref patterns to move out of boxes) - rust-lang#140276 (Do not compute type_of for impl item if impl where clauses are unsatisfied) - rust-lang#140302 (Move inline asm check to typeck, properly handle aliases) - rust-lang#140323 (Implement the internal feature `cfg_target_has_reliable_f16_f128`) - rust-lang#140391 (Rename sub_ptr to offset_from_unsigned in docs) - rust-lang#140394 (Make bootstrap git tests more self-contained) - rust-lang#140396 (Workaround for windows-gnu rust-lld test failure) - rust-lang#140402 (only return nested goals for `Certainty::Yes`) Failed merges: - rust-lang#139765 ([beta] Delay `hash_extract_if` stabilization from 1.87 to 1.88) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 25cdf1f + d5ecdab commit 140a9b4

File tree

82 files changed

+1693
-519
lines changed

Some content is hidden

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

82 files changed

+1693
-519
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,6 @@ dependencies = [
37573757
"rustc_middle",
37583758
"rustc_session",
37593759
"rustc_span",
3760-
"rustc_target",
37613760
"rustc_trait_selection",
37623761
"smallvec",
37633762
"tracing",
@@ -3796,6 +3795,7 @@ dependencies = [
37963795
"rustc_middle",
37973796
"rustc_session",
37983797
"rustc_span",
3798+
"rustc_target",
37993799
"rustc_trait_selection",
38003800
"smallvec",
38013801
"tracing",

compiler/rustc_codegen_cranelift/src/lib.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use std::sync::Arc;
4141

4242
use cranelift_codegen::isa::TargetIsa;
4343
use cranelift_codegen::settings::{self, Configurable};
44-
use rustc_codegen_ssa::CodegenResults;
4544
use rustc_codegen_ssa::traits::CodegenBackend;
45+
use rustc_codegen_ssa::{CodegenResults, TargetConfig};
4646
use rustc_metadata::EncodedMetadata;
4747
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4848
use rustc_session::Session;
@@ -178,7 +178,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
178178
}
179179
}
180180

181-
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
181+
fn target_config(&self, sess: &Session) -> TargetConfig {
182182
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
183183
let target_features = if sess.target.arch == "x86_64" && sess.target.os != "none" {
184184
// x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
@@ -197,7 +197,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
197197
};
198198
// FIXME do `unstable_target_features` properly
199199
let unstable_target_features = target_features.clone();
200-
(target_features, unstable_target_features)
200+
201+
TargetConfig {
202+
target_features,
203+
unstable_target_features,
204+
// Cranelift does not yet support f16 or f128
205+
has_reliable_f16: false,
206+
has_reliable_f16_math: false,
207+
has_reliable_f128: false,
208+
has_reliable_f128_math: false,
209+
}
201210
}
202211

203212
fn print_version(&self) {

compiler/rustc_codegen_gcc/src/gcc_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
5555
)
5656
} else if let Some(feature) = feature.strip_prefix('-') {
5757
// FIXME: Why do we not remove implied features on "-" here?
58-
// We do the equivalent above in `target_features_cfg`.
58+
// We do the equivalent above in `target_config`.
5959
// See <https://github.com/rust-lang/rust/issues/134792>.
6060
all_rust_features.push((false, feature));
6161
} else if !feature.is_empty() && diagnostics {

compiler/rustc_codegen_gcc/src/lib.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ use rustc_codegen_ssa::back::write::{
102102
};
103103
use rustc_codegen_ssa::base::codegen_crate;
104104
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods};
105-
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
105+
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
106106
use rustc_data_structures::fx::FxIndexMap;
107107
use rustc_data_structures::sync::IntoDynSyncSend;
108108
use rustc_errors::DiagCtxtHandle;
@@ -260,8 +260,8 @@ impl CodegenBackend for GccCodegenBackend {
260260
.join(sess)
261261
}
262262

263-
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
264-
target_features_cfg(sess, &self.target_info)
263+
fn target_config(&self, sess: &Session) -> TargetConfig {
264+
target_config(sess, &self.target_info)
265265
}
266266
}
267267

@@ -485,10 +485,7 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
485485
}
486486

487487
/// Returns the features that should be set in `cfg(target_feature)`.
488-
fn target_features_cfg(
489-
sess: &Session,
490-
target_info: &LockedTargetInfo,
491-
) -> (Vec<Symbol>, Vec<Symbol>) {
488+
fn target_config(sess: &Session, target_info: &LockedTargetInfo) -> TargetConfig {
492489
// TODO(antoyo): use global_gcc_features.
493490
let f = |allow_unstable| {
494491
sess.target
@@ -523,5 +520,14 @@ fn target_features_cfg(
523520

524521
let target_features = f(false);
525522
let unstable_target_features = f(true);
526-
(target_features, unstable_target_features)
523+
524+
TargetConfig {
525+
target_features,
526+
unstable_target_features,
527+
// There are no known bugs with GCC support for f16 or f128
528+
has_reliable_f16: true,
529+
has_reliable_f16_math: true,
530+
has_reliable_f128: true,
531+
has_reliable_f128_math: true,
532+
}
527533
}

compiler/rustc_codegen_llvm/src/attributes.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Set and unset common attributes on LLVM values.
2-
32
use rustc_attr_parsing::{InlineAttr, InstructionSetAttr, OptimizeAttr};
43
use rustc_codegen_ssa::traits::*;
54
use rustc_hir::def_id::DefId;
@@ -28,6 +27,22 @@ pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[
2827
}
2928
}
3029

30+
pub(crate) fn has_attr(llfn: &Value, idx: AttributePlace, attr: AttributeKind) -> bool {
31+
llvm::HasAttributeAtIndex(llfn, idx, attr)
32+
}
33+
34+
pub(crate) fn has_string_attr(llfn: &Value, name: &str) -> bool {
35+
llvm::HasStringAttribute(llfn, name)
36+
}
37+
38+
pub(crate) fn remove_from_llfn(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
39+
llvm::RemoveRustEnumAttributeAtIndex(llfn, place, kind);
40+
}
41+
42+
pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: &str) {
43+
llvm::RemoveStringAttrFromFn(llfn, name);
44+
}
45+
3146
/// Get LLVM attribute for the provided inline heuristic.
3247
#[inline]
3348
fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll Attribute> {

compiler/rustc_codegen_llvm/src/back/lto.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ use crate::back::write::{
2828
use crate::errors::{
2929
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
3030
};
31+
use crate::llvm::AttributePlace::Function;
3132
use crate::llvm::{self, build_string};
32-
use crate::{LlvmCodegenBackend, ModuleLlvm};
33+
use crate::{LlvmCodegenBackend, ModuleLlvm, SimpleCx, attributes};
3334

3435
/// We keep track of the computed LTO cache keys from the previous
3536
/// session to determine which CGUs we can reuse.
@@ -666,6 +667,31 @@ pub(crate) fn run_pass_manager(
666667
}
667668

668669
if cfg!(llvm_enzyme) && enable_ad && !thin {
670+
let cx =
671+
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
672+
673+
for function in cx.get_functions() {
674+
let enzyme_marker = "enzyme_marker";
675+
if attributes::has_string_attr(function, enzyme_marker) {
676+
// Sanity check: Ensure 'noinline' is present before replacing it.
677+
assert!(
678+
!attributes::has_attr(function, Function, llvm::AttributeKind::NoInline),
679+
"Expected __enzyme function to have 'noinline' before adding 'alwaysinline'"
680+
);
681+
682+
attributes::remove_from_llfn(function, Function, llvm::AttributeKind::NoInline);
683+
attributes::remove_string_attr_from_llfn(function, enzyme_marker);
684+
685+
assert!(
686+
!attributes::has_string_attr(function, enzyme_marker),
687+
"Expected function to not have 'enzyme_marker'"
688+
);
689+
690+
let always_inline = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
691+
attributes::apply_to_llfn(function, Function, &[always_inline]);
692+
}
693+
}
694+
669695
let opt_stage = llvm::OptStage::FatLTO;
670696
let stage = write::AutodiffStage::PostAD;
671697
if !config.autodiff.contains(&config::AutoDiff::NoPostopt) {

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

+5
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ fn generate_enzyme_call<'ll>(
361361
let attr = llvm::AttributeKind::NoInline.create_attr(cx.llcx);
362362
attributes::apply_to_llfn(ad_fn, Function, &[attr]);
363363

364+
// We add a made-up attribute just such that we can recognize it after AD to update
365+
// (no)-inline attributes. We'll then also remove this attribute.
366+
let enzyme_marker_attr = llvm::CreateAttrString(cx.llcx, "enzyme_marker");
367+
attributes::apply_to_llfn(outer_fn, Function, &[enzyme_marker_attr]);
368+
364369
// first, remove all calls from fnc
365370
let entry = llvm::LLVMGetFirstBasicBlock(outer_fn);
366371
let br = llvm::LLVMRustGetTerminator(entry);

compiler/rustc_codegen_llvm/src/context.rs

+10
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,16 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
698698
llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr() as *const c_char, name.len())
699699
})
700700
}
701+
702+
pub(crate) fn get_functions(&self) -> Vec<&'ll Value> {
703+
let mut functions = vec![];
704+
let mut func = unsafe { llvm::LLVMGetFirstFunction(self.llmod()) };
705+
while let Some(f) = func {
706+
functions.push(f);
707+
func = unsafe { llvm::LLVMGetNextFunction(f) }
708+
}
709+
functions
710+
}
701711
}
702712

703713
impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {

compiler/rustc_codegen_llvm/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ use back::owned_target_machine::OwnedTargetMachine;
2929
use back::write::{create_informational_target_machine, create_target_machine};
3030
use context::SimpleCx;
3131
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig};
32-
use llvm_util::target_features_cfg;
32+
use llvm_util::target_config;
3333
use rustc_ast::expand::allocator::AllocatorKind;
3434
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
3535
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
3636
use rustc_codegen_ssa::back::write::{
3737
CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryConfig, TargetMachineFactoryFn,
3838
};
3939
use rustc_codegen_ssa::traits::*;
40-
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
40+
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
4141
use rustc_data_structures::fx::FxIndexMap;
4242
use rustc_errors::{DiagCtxtHandle, FatalError};
4343
use rustc_metadata::EncodedMetadata;
@@ -338,8 +338,8 @@ impl CodegenBackend for LlvmCodegenBackend {
338338
llvm_util::print_version();
339339
}
340340

341-
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
342-
target_features_cfg(sess)
341+
fn target_config(&self, sess: &Session) -> TargetConfig {
342+
target_config(sess)
343343
}
344344

345345
fn codegen_crate<'tcx>(

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ unsafe extern "C" {
1919
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
2020
pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool;
2121
pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64;
22+
pub(crate) fn LLVMRustHasFnAttribute(
23+
F: &Value,
24+
Name: *const c_char,
25+
NameLen: libc::size_t,
26+
) -> bool;
27+
pub(crate) fn LLVMRustRemoveFnAttribute(F: &Value, Name: *const c_char, NameLen: libc::size_t);
28+
pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>;
29+
pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>;
30+
pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex(
31+
Fn: &Value,
32+
index: c_uint,
33+
kind: AttributeKind,
34+
);
2235
}
2336

2437
unsafe extern "C" {

compiler/rustc_codegen_llvm/src/llvm/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@ pub(crate) fn AddFunctionAttributes<'ll>(
4141
}
4242
}
4343

44+
pub(crate) fn HasAttributeAtIndex<'ll>(
45+
llfn: &'ll Value,
46+
idx: AttributePlace,
47+
kind: AttributeKind,
48+
) -> bool {
49+
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx.as_uint(), kind) }
50+
}
51+
52+
pub(crate) fn HasStringAttribute<'ll>(llfn: &'ll Value, name: &str) -> bool {
53+
unsafe { LLVMRustHasFnAttribute(llfn, name.as_c_char_ptr(), name.len()) }
54+
}
55+
56+
pub(crate) fn RemoveStringAttrFromFn<'ll>(llfn: &'ll Value, name: &str) {
57+
unsafe { LLVMRustRemoveFnAttribute(llfn, name.as_c_char_ptr(), name.len()) }
58+
}
59+
60+
pub(crate) fn RemoveRustEnumAttributeAtIndex(
61+
llfn: &Value,
62+
place: AttributePlace,
63+
kind: AttributeKind,
64+
) {
65+
unsafe {
66+
LLVMRustRemoveEnumAttributeAtIndex(llfn, place.as_uint(), kind);
67+
}
68+
}
69+
4470
pub(crate) fn AddCallSiteAttributes<'ll>(
4571
callsite: &'ll Value,
4672
idx: AttributePlace,

0 commit comments

Comments
 (0)