1
1
//! Argument passing
2
2
3
- use cranelift_codegen:: ir:: { ArgumentExtension , ArgumentPurpose } ;
3
+ use cranelift_codegen:: ir:: ArgumentPurpose ;
4
4
use rustc_abi:: { Reg , RegKind } ;
5
5
use rustc_target:: callconv:: {
6
6
ArgAbi , ArgAttributes , ArgExtension as RustcArgExtension , CastTarget , PassMode ,
@@ -32,13 +32,12 @@ fn reg_to_abi_param(reg: Reg) -> AbiParam {
32
32
AbiParam :: new ( clif_ty)
33
33
}
34
34
35
- fn apply_arg_attrs_to_abi_param ( mut param : AbiParam , arg_attrs : ArgAttributes ) -> AbiParam {
35
+ fn apply_attrs_to_abi_param ( param : AbiParam , arg_attrs : ArgAttributes ) -> AbiParam {
36
36
match arg_attrs. arg_ext {
37
- RustcArgExtension :: None => { }
38
- RustcArgExtension :: Zext => param. extension = ArgumentExtension :: Uext ,
39
- RustcArgExtension :: Sext => param. extension = ArgumentExtension :: Sext ,
37
+ RustcArgExtension :: None => param ,
38
+ RustcArgExtension :: Zext => param. uext ( ) ,
39
+ RustcArgExtension :: Sext => param. sext ( ) ,
40
40
}
41
- param
42
41
}
43
42
44
43
fn cast_target_to_abi_params ( cast : & CastTarget ) -> SmallVec < [ AbiParam ; 2 ] > {
@@ -82,7 +81,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
82
81
match self . mode {
83
82
PassMode :: Ignore => smallvec ! [ ] ,
84
83
PassMode :: Direct ( attrs) => match self . layout . backend_repr {
85
- BackendRepr :: Scalar ( scalar) => smallvec ! [ apply_arg_attrs_to_abi_param (
84
+ BackendRepr :: Scalar ( scalar) => smallvec ! [ apply_attrs_to_abi_param (
86
85
AbiParam :: new( scalar_to_clif_type( tcx, scalar) ) ,
87
86
attrs
88
87
) ] ,
@@ -97,8 +96,8 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
97
96
let a = scalar_to_clif_type ( tcx, a) ;
98
97
let b = scalar_to_clif_type ( tcx, b) ;
99
98
smallvec ! [
100
- apply_arg_attrs_to_abi_param ( AbiParam :: new( a) , attrs_a) ,
101
- apply_arg_attrs_to_abi_param ( AbiParam :: new( b) , attrs_b) ,
99
+ apply_attrs_to_abi_param ( AbiParam :: new( a) , attrs_a) ,
100
+ apply_attrs_to_abi_param ( AbiParam :: new( b) , attrs_b) ,
102
101
]
103
102
}
104
103
_ => unreachable ! ( "{:?}" , self . layout. backend_repr) ,
@@ -112,19 +111,19 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
112
111
// Abi requires aligning struct size to pointer size
113
112
let size = self . layout . size . align_to ( tcx. data_layout . pointer_align . abi ) ;
114
113
let size = u32:: try_from ( size. bytes ( ) ) . unwrap ( ) ;
115
- smallvec ! [ apply_arg_attrs_to_abi_param (
114
+ smallvec ! [ apply_attrs_to_abi_param (
116
115
AbiParam :: special( pointer_ty( tcx) , ArgumentPurpose :: StructArgument ( size) , ) ,
117
116
attrs
118
117
) ]
119
118
} else {
120
- smallvec ! [ apply_arg_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ]
119
+ smallvec ! [ apply_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ]
121
120
}
122
121
}
123
122
PassMode :: Indirect { attrs, meta_attrs : Some ( meta_attrs) , on_stack } => {
124
123
assert ! ( !on_stack) ;
125
124
smallvec ! [
126
- apply_arg_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ,
127
- apply_arg_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , meta_attrs) ,
125
+ apply_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ,
126
+ apply_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , meta_attrs) ,
128
127
]
129
128
}
130
129
}
@@ -133,30 +132,46 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
133
132
fn get_abi_return ( & self , tcx : TyCtxt < ' tcx > ) -> ( Option < AbiParam > , Vec < AbiParam > ) {
134
133
match self . mode {
135
134
PassMode :: Ignore => ( None , vec ! [ ] ) ,
136
- PassMode :: Direct ( _) => match self . layout . backend_repr {
137
- BackendRepr :: Scalar ( scalar) => {
138
- ( None , vec ! [ AbiParam :: new( scalar_to_clif_type( tcx, scalar) ) ] )
139
- }
135
+ PassMode :: Direct ( attrs) => match self . layout . backend_repr {
136
+ BackendRepr :: Scalar ( scalar) => (
137
+ None ,
138
+ vec ! [ apply_attrs_to_abi_param(
139
+ AbiParam :: new( scalar_to_clif_type( tcx, scalar) ) ,
140
+ attrs,
141
+ ) ] ,
142
+ ) ,
140
143
BackendRepr :: SimdVector { .. } => {
141
144
let vector_ty = crate :: intrinsics:: clif_vector_type ( tcx, self . layout ) ;
142
- ( None , vec ! [ AbiParam :: new( vector_ty) ] )
145
+ ( None , vec ! [ apply_attrs_to_abi_param ( AbiParam :: new( vector_ty) , attrs ) ] )
143
146
}
144
147
_ => unreachable ! ( "{:?}" , self . layout. backend_repr) ,
145
148
} ,
146
- PassMode :: Pair ( _ , _ ) => match self . layout . backend_repr {
149
+ PassMode :: Pair ( attrs_a , attrs_b ) => match self . layout . backend_repr {
147
150
BackendRepr :: ScalarPair ( a, b) => {
148
151
let a = scalar_to_clif_type ( tcx, a) ;
149
152
let b = scalar_to_clif_type ( tcx, b) ;
150
- ( None , vec ! [ AbiParam :: new( a) , AbiParam :: new( b) ] )
153
+ (
154
+ None ,
155
+ vec ! [
156
+ apply_attrs_to_abi_param( AbiParam :: new( a) , attrs_a) ,
157
+ apply_attrs_to_abi_param( AbiParam :: new( b) , attrs_b) ,
158
+ ] ,
159
+ )
151
160
}
152
161
_ => unreachable ! ( "{:?}" , self . layout. backend_repr) ,
153
162
} ,
154
163
PassMode :: Cast { ref cast, .. } => {
155
164
( None , cast_target_to_abi_params ( cast) . into_iter ( ) . collect ( ) )
156
165
}
157
- PassMode :: Indirect { attrs : _ , meta_attrs : None , on_stack } => {
166
+ PassMode :: Indirect { attrs, meta_attrs : None , on_stack } => {
158
167
assert ! ( !on_stack) ;
159
- ( Some ( AbiParam :: special ( pointer_ty ( tcx) , ArgumentPurpose :: StructReturn ) ) , vec ! [ ] )
168
+ (
169
+ Some ( apply_attrs_to_abi_param (
170
+ AbiParam :: special ( pointer_ty ( tcx) , ArgumentPurpose :: StructReturn ) ,
171
+ attrs,
172
+ ) ) ,
173
+ vec ! [ ] ,
174
+ )
160
175
}
161
176
PassMode :: Indirect { attrs : _, meta_attrs : Some ( _) , on_stack : _ } => {
162
177
unreachable ! ( "unsized return value" )
0 commit comments