diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-05-29 00:25:14 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-05-30 00:19:23 -0700 |
| commit | e90be842fb9129aa27e5b6412f245ca39999f9f1 (patch) | |
| tree | 96cc6b49f01fae44002f56140f28014cceaa07e4 /compiler | |
| parent | 0acc4a35853215a6f9388ab61455ced309711003 (diff) | |
| download | rust-e90be842fb9129aa27e5b6412f245ca39999f9f1.tar.gz rust-e90be842fb9129aa27e5b6412f245ca39999f9f1.zip | |
Add support for emitting functions with `coldcc` in LLVM
The eventual goal is to try using this for things like the internal panicking stuff, to see whether it helps.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_passes/src/feature_gate.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/abi/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/abi.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/layout.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_target/src/abi/call/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_target/src/spec/abi.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_target/src/spec/mod.rs | 3 |
9 files changed, 25 insertions, 3 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index f0b94047ed9..77dd4ccd64e 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -113,6 +113,14 @@ impl<'a> PostExpansionVisitor<'a> { "rust-call ABI is subject to change" ); } + "rust-cold" => { + gate_feature_post!( + &self, + rust_cold_cc, + span, + "rust-cold is experimental and subject to change" + ); + } "ptx-kernel" => { gate_feature_post!( &self, diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index decb7841990..59a7316c1c0 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -22,7 +22,7 @@ fn clif_sig_from_fn_abi<'tcx>( fn_abi: &FnAbi<'tcx, Ty<'tcx>>, ) -> Signature { let call_conv = match fn_abi.conv { - Conv::Rust | Conv::C => default_call_conv, + Conv::Rust | Conv::C | Conv::RustCold => default_call_conv, Conv::X86_64SysV => CallConv::SystemV, Conv::X86_64Win64 => CallConv::WindowsFastcall, Conv::ArmAapcs diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index b9baa87bac7..cc8b3a1a4e4 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -393,6 +393,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { fn llvm_cconv(&self) -> llvm::CallConv { match self.conv { Conv::C | Conv::Rust | Conv::CCmseNonSecureCall => llvm::CCallConv, + Conv::RustCold => llvm::ColdCallConv, Conv::AmdGpuKernel => llvm::AmdGpuKernel, Conv::AvrInterrupt => llvm::AvrInterrupt, Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt, diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 5a02661513c..cece92bfe85 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -496,6 +496,8 @@ declare_features! ( (incomplete, repr128, "1.16.0", Some(56071), None), /// Allows `repr(simd)` and importing the various simd intrinsics. (active, repr_simd, "1.4.0", Some(27731), None), + /// Allows `extern "rust-cold"`. + (active, rust_cold_cc, "1.63.0", Some(97544), None), /// Allows the use of SIMD types in functions declared in `extern` blocks. (active, simd_ffi, "1.0.0", Some(27731), None), /// Allows specialization of implementations (RFC 1210). diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 30552c685a3..3b05e42a53e 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2971,7 +2971,7 @@ pub fn fn_can_unwind<'tcx>(tcx: TyCtxt<'tcx>, fn_def_id: Option<DefId>, abi: Spe | RustIntrinsic | PlatformIntrinsic | Unadjusted => false, - Rust | RustCall => tcx.sess.panic_strategy() == PanicStrategy::Unwind, + Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind, } } @@ -2980,6 +2980,7 @@ pub fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv { use rustc_target::spec::abi::Abi::*; match tcx.sess.target.adjust_abi(abi) { RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::Rust, + RustCold => Conv::RustCold, // It's the ABI's job to select this, not ours. System { .. } => bug!("system abi should be selected elsewhere"), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6989763f75a..cfbf17e17c8 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1160,6 +1160,7 @@ symbols! { rust_2024, rust_2024_preview, rust_begin_unwind, + rust_cold_cc, rust_eh_catch_typeinfo, rust_eh_personality, rust_eh_register_frames, diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index afce10ff1cb..ca1d1302ec6 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -580,6 +580,11 @@ pub enum Conv { C, Rust, + /// For things unlikely to be called, where smaller caller codegen is + /// preferred over raw speed. + /// Stronger than just `#[cold]` because `fn` pointers might be incompatible. + RustCold, + // Target-specific calling conventions. ArmAapcs, CCmseNonSecureCall, diff --git a/compiler/rustc_target/src/spec/abi.rs b/compiler/rustc_target/src/spec/abi.rs index d9e571c72e5..337554dc96e 100644 --- a/compiler/rustc_target/src/spec/abi.rs +++ b/compiler/rustc_target/src/spec/abi.rs @@ -35,6 +35,7 @@ pub enum Abi { RustCall, PlatformIntrinsic, Unadjusted, + RustCold, } #[derive(Copy, Clone)] @@ -81,6 +82,7 @@ const AbiDatas: &[AbiData] = &[ AbiData { abi: Abi::RustCall, name: "rust-call" }, AbiData { abi: Abi::PlatformIntrinsic, name: "platform-intrinsic" }, AbiData { abi: Abi::Unadjusted, name: "unadjusted" }, + AbiData { abi: Abi::RustCold, name: "rust-cold" }, ]; /// Returns the ABI with the given name (if any). @@ -139,6 +141,7 @@ impl Abi { RustCall => 31, PlatformIntrinsic => 32, Unadjusted => 33, + RustCold => 34, }; debug_assert!( AbiDatas diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 6dd245b047c..866cd5f0fe7 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1618,7 +1618,8 @@ impl Target { | PlatformIntrinsic | Unadjusted | Cdecl { .. } - | EfiApi => true, + | EfiApi + | RustCold => true, X86Interrupt => ["x86", "x86_64"].contains(&&self.arch[..]), Aapcs { .. } => "arm" == self.arch, CCmseNonSecureCall => ["arm", "aarch64"].contains(&&self.arch[..]), |
