11#[ cfg( feature = "master" ) ]
22use gccjit:: FnAttribute ;
33use gccjit:: { ToLValue , ToRValue , Type } ;
4- use rustc_abi:: { Reg , RegKind } ;
4+ use rustc_abi:: { ArmCall , CanonAbi , InterruptKind , Reg , RegKind , X86Call } ;
55use rustc_codegen_ssa:: traits:: { AbiBuilderMethods , BaseTypeCodegenMethods } ;
66use rustc_data_structures:: fx:: FxHashSet ;
77use rustc_middle:: bug;
@@ -10,12 +10,9 @@ use rustc_middle::ty::layout::LayoutOf;
1010#[ cfg( feature = "master" ) ]
1111use rustc_session:: config;
1212use rustc_target:: callconv:: { ArgAttributes , CastTarget , FnAbi , PassMode } ;
13- #[ cfg( feature = "master" ) ]
14- use rustc_target:: callconv:: { Conv , RiscvInterruptKind } ;
1513
1614use crate :: builder:: Builder ;
1715use crate :: context:: CodegenCx ;
18- use crate :: intrinsic:: ArgAbiExt ;
1916use crate :: type_of:: LayoutGccExt ;
2017
2118impl AbiBuilderMethods for Builder < ' _ , ' _ , ' _ > {
@@ -125,7 +122,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
125122 PassMode :: Direct ( _) | PassMode :: Pair ( ..) => self . ret . layout . immediate_gcc_type ( cx) ,
126123 PassMode :: Cast { ref cast, .. } => cast. gcc_type ( cx) ,
127124 PassMode :: Indirect { .. } => {
128- argument_tys. push ( cx. type_ptr_to ( self . ret . memory_ty ( cx) ) ) ;
125+ argument_tys. push ( cx. type_ptr_to ( self . ret . layout . gcc_type ( cx) ) ) ;
129126 cx. type_void ( )
130127 }
131128 } ;
@@ -176,13 +173,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
176173 PassMode :: Indirect { attrs : _, meta_attrs : None , on_stack : true } => {
177174 // This is a "byval" argument, so we don't apply the `restrict` attribute on it.
178175 on_stack_param_indices. insert ( argument_tys. len ( ) ) ;
179- arg. memory_ty ( cx)
176+ arg. layout . gcc_type ( cx)
180177 }
181178 PassMode :: Direct ( attrs) => {
182179 apply_attrs ( arg. layout . immediate_gcc_type ( cx) , & attrs, argument_tys. len ( ) )
183180 }
184181 PassMode :: Indirect { attrs, meta_attrs : None , on_stack : false } => {
185- apply_attrs ( cx. type_ptr_to ( arg. memory_ty ( cx) ) , & attrs, argument_tys. len ( ) )
182+ apply_attrs ( cx. type_ptr_to ( arg. layout . gcc_type ( cx) ) , & attrs, argument_tys. len ( ) )
186183 }
187184 PassMode :: Indirect { attrs, meta_attrs : Some ( meta_attrs) , on_stack } => {
188185 assert ! ( !on_stack) ;
@@ -239,29 +236,16 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
239236}
240237
241238#[ cfg( feature = "master" ) ]
242- pub fn conv_to_fn_attribute < ' gcc > ( conv : Conv , arch : & str ) -> Option < FnAttribute < ' gcc > > {
239+ pub fn conv_to_fn_attribute < ' gcc > ( conv : CanonAbi , arch : & str ) -> Option < FnAttribute < ' gcc > > {
243240 let attribute = match conv {
244- Conv :: C | Conv :: Rust => return None ,
245- Conv :: CCmseNonSecureCall => {
246- if arch == "arm" {
247- FnAttribute :: ArmCmseNonsecureCall
248- } else {
249- return None ;
250- }
251- }
252- Conv :: CCmseNonSecureEntry => {
253- if arch == "arm" {
254- FnAttribute :: ArmCmseNonsecureEntry
255- } else {
256- return None ;
257- }
258- }
259- Conv :: Cold => FnAttribute :: Cold ,
260- // NOTE: the preserve attributes are not yet implemented in GCC:
261- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899
262- Conv :: PreserveMost => return None ,
263- Conv :: PreserveAll => return None ,
264- Conv :: GpuKernel => {
241+ CanonAbi :: C | CanonAbi :: Rust => return None ,
242+ CanonAbi :: Arm ( arm_call) => match arm_call {
243+ ArmCall :: CCmseNonSecureCall => FnAttribute :: ArmCmseNonsecureCall ,
244+ ArmCall :: CCmseNonSecureEntry => FnAttribute :: ArmCmseNonsecureEntry ,
245+ ArmCall :: Aapcs => FnAttribute :: ArmPcs ( "aapcs" ) ,
246+ } ,
247+ CanonAbi :: RustCold => FnAttribute :: Cold ,
248+ CanonAbi :: GpuKernel => {
265249 if arch == "amdgpu" {
266250 FnAttribute :: GcnAmdGpuHsaKernel
267251 } else if arch == "nvptx64" {
@@ -271,26 +255,24 @@ pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<
271255 }
272256 }
273257 // TODO(antoyo): check if those AVR attributes are mapped correctly.
274- Conv :: AvrInterrupt => FnAttribute :: AvrSignal ,
275- Conv :: AvrNonBlockingInterrupt => FnAttribute :: AvrInterrupt ,
276- Conv :: ArmAapcs => FnAttribute :: ArmPcs ( "aapcs" ) ,
277- Conv :: Msp430Intr => FnAttribute :: Msp430Interrupt ,
278- Conv :: RiscvInterrupt { kind } => {
279- let kind = match kind {
280- RiscvInterruptKind :: Machine => "machine" ,
281- RiscvInterruptKind :: Supervisor => "supervisor" ,
282- } ;
283- FnAttribute :: RiscvInterrupt ( kind)
284- }
285- Conv :: X86Fastcall => FnAttribute :: X86FastCall ,
286- Conv :: X86Intr => FnAttribute :: X86Interrupt ,
287- Conv :: X86Stdcall => FnAttribute :: X86Stdcall ,
288- Conv :: X86ThisCall => FnAttribute :: X86ThisCall ,
289- // NOTE: the vectorcall calling convention is not yet implemented in GCC:
290- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
291- Conv :: X86VectorCall => return None ,
292- Conv :: X86_64SysV => FnAttribute :: X86SysvAbi ,
293- Conv :: X86_64Win64 => FnAttribute :: X86MsAbi ,
258+ CanonAbi :: Interrupt ( interrupt_kind) => match interrupt_kind {
259+ InterruptKind :: Avr => FnAttribute :: AvrSignal ,
260+ InterruptKind :: AvrNonBlocking => FnAttribute :: AvrInterrupt ,
261+ InterruptKind :: Msp430 => FnAttribute :: Msp430Interrupt ,
262+ InterruptKind :: RiscvMachine => FnAttribute :: RiscvInterrupt ( "machine" ) ,
263+ InterruptKind :: RiscvSupervisor => FnAttribute :: RiscvInterrupt ( "supervisor" ) ,
264+ InterruptKind :: X86 => FnAttribute :: X86Interrupt ,
265+ } ,
266+ CanonAbi :: X86 ( x86_call) => match x86_call {
267+ X86Call :: Fastcall => FnAttribute :: X86FastCall ,
268+ X86Call :: Stdcall => FnAttribute :: X86Stdcall ,
269+ X86Call :: Thiscall => FnAttribute :: X86ThisCall ,
270+ // // NOTE: the vectorcall calling convention is not yet implemented in GCC:
271+ // // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
272+ X86Call :: Vectorcall => return None ,
273+ X86Call :: SysV64 => FnAttribute :: X86SysvAbi ,
274+ X86Call :: Win64 => FnAttribute :: X86MsAbi ,
275+ } ,
294276 } ;
295277 Some ( attribute)
296278}
0 commit comments