about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/src/abi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_codegen_gcc/src/abi.rs')
-rw-r--r--compiler/rustc_codegen_gcc/src/abi.rs65
1 files changed, 42 insertions, 23 deletions
diff --git a/compiler/rustc_codegen_gcc/src/abi.rs b/compiler/rustc_codegen_gcc/src/abi.rs
index a96b18e01c0..d882d3eecf4 100644
--- a/compiler/rustc_codegen_gcc/src/abi.rs
+++ b/compiler/rustc_codegen_gcc/src/abi.rs
@@ -9,9 +9,9 @@ use rustc_middle::ty::Ty;
 use rustc_middle::ty::layout::LayoutOf;
 #[cfg(feature = "master")]
 use rustc_session::config;
-#[cfg(feature = "master")]
-use rustc_target::callconv::Conv;
 use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
+#[cfg(feature = "master")]
+use rustc_target::callconv::{Conv, RiscvInterruptKind};
 
 use crate::builder::Builder;
 use crate::context::CodegenCx;
@@ -240,38 +240,57 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
 
 #[cfg(feature = "master")]
 pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<'gcc>> {
-    // TODO: handle the calling conventions returning None.
     let attribute = match conv {
-        Conv::C
-        | Conv::Rust
-        | Conv::CCmseNonSecureCall
-        | Conv::CCmseNonSecureEntry
-        | Conv::RiscvInterrupt { .. } => return None,
-        Conv::Cold => return None,
+        Conv::C | Conv::Rust => return None,
+        Conv::CCmseNonSecureCall => {
+            if arch == "arm" {
+                FnAttribute::ArmCmseNonsecureCall
+            } else {
+                return None;
+            }
+        }
+        Conv::CCmseNonSecureEntry => {
+            if arch == "arm" {
+                FnAttribute::ArmCmseNonsecureEntry
+            } else {
+                return None;
+            }
+        }
+        Conv::Cold => FnAttribute::Cold,
+        // NOTE: the preserve attributes are not yet implemented in GCC:
+        // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899
         Conv::PreserveMost => return None,
         Conv::PreserveAll => return None,
         Conv::GpuKernel => {
-            // TODO(antoyo): remove clippy allow attribute when this is implemented.
-            #[allow(clippy::if_same_then_else)]
             if arch == "amdgpu" {
-                return None;
+                FnAttribute::GcnAmdGpuHsaKernel
             } else if arch == "nvptx64" {
-                return None;
+                FnAttribute::NvptxKernel
             } else {
                 panic!("Architecture {} does not support GpuKernel calling convention", arch);
             }
         }
-        Conv::AvrInterrupt => return None,
-        Conv::AvrNonBlockingInterrupt => return None,
-        Conv::ArmAapcs => return None,
-        Conv::Msp430Intr => return None,
-        Conv::X86Fastcall => return None,
-        Conv::X86Intr => return None,
-        Conv::X86Stdcall => return None,
-        Conv::X86ThisCall => return None,
+        // TODO(antoyo): check if those AVR attributes are mapped correctly.
+        Conv::AvrInterrupt => FnAttribute::AvrSignal,
+        Conv::AvrNonBlockingInterrupt => FnAttribute::AvrInterrupt,
+        Conv::ArmAapcs => FnAttribute::ArmPcs("aapcs"),
+        Conv::Msp430Intr => FnAttribute::Msp430Interrupt,
+        Conv::RiscvInterrupt { kind } => {
+            let kind = match kind {
+                RiscvInterruptKind::Machine => "machine",
+                RiscvInterruptKind::Supervisor => "supervisor",
+            };
+            FnAttribute::RiscvInterrupt(kind)
+        }
+        Conv::X86Fastcall => FnAttribute::X86FastCall,
+        Conv::X86Intr => FnAttribute::X86Interrupt,
+        Conv::X86Stdcall => FnAttribute::X86Stdcall,
+        Conv::X86ThisCall => FnAttribute::X86ThisCall,
+        // NOTE: the vectorcall calling convention is not yet implemented in GCC:
+        // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
         Conv::X86VectorCall => return None,
-        Conv::X86_64SysV => FnAttribute::SysvAbi,
-        Conv::X86_64Win64 => FnAttribute::MsAbi,
+        Conv::X86_64SysV => FnAttribute::X86SysvAbi,
+        Conv::X86_64Win64 => FnAttribute::X86MsAbi,
     };
     Some(attribute)
 }