Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 45745d3

Browse files
committed
Auto merge of rust-lang#140411 - ChrisDenton:rollup-3ftqm0d, r=ChrisDenton
Rollup of 9 pull requests Successful merges: - rust-lang#139308 (add autodiff inline) - 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#140374 (Resolve instance for SymFn in global/naked asm) - 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`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 25cdf1f + 82d1b72 commit 45745d3

File tree

84 files changed

+1473
-442
lines changed

Some content is hidden

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

84 files changed

+1473
-442
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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/global_asm.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
6565

6666
let ty = tcx.typeck(item_id.owner_id).expr_ty(expr);
6767
let instance = match ty.kind() {
68-
&ty::FnDef(def_id, args) => Instance::new(def_id, args),
68+
&ty::FnDef(def_id, args) => Instance::expect_resolve(
69+
tcx,
70+
ty::TypingEnv::fully_monomorphized(),
71+
def_id,
72+
args,
73+
expr.span,
74+
),
6975
_ => span_bug!(op_sp, "asm sym is not a function"),
7076
};
7177
let symbol = tcx.symbol_name(instance);

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
12821282
intrinsic.name,
12831283
);
12841284
}
1285-
return Err(Instance::new(instance.def_id(), instance.args));
1285+
return Err(Instance::new_raw(instance.def_id(), instance.args));
12861286
}
12871287
}
12881288

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 12 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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/intrinsic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
399399
}
400400

401401
// Fall back to default body
402-
_ => return Err(Instance::new(instance.def_id(), instance.args)),
402+
_ => return Err(Instance::new_raw(instance.def_id(), instance.args)),
403403
};
404404

405405
if !fn_abi.ret.is_ignore() {

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 14 additions & 8 deletions
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

Lines changed: 16 additions & 1 deletion
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

Lines changed: 27 additions & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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);

0 commit comments

Comments
 (0)