@@ -42,8 +42,6 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
42
42
options : InlineAsmOptions ,
43
43
destination : Option < mir:: BasicBlock > ,
44
44
) {
45
- // FIXME add .eh_frame unwind info directives
46
-
47
45
// Used by panic_abort on Windows, but uses a syntax which only happens to work with
48
46
// asm!() by accident and breaks with the GNU assembler as well as global_asm!() for
49
47
// the LLVM backend.
@@ -135,12 +133,33 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
135
133
} )
136
134
. collect :: < Vec < _ > > ( ) ;
137
135
136
+ codegen_inline_asm_inner ( fx, template, & operands, options) ;
137
+
138
+ match destination {
139
+ Some ( destination) => {
140
+ let destination_block = fx. get_block ( destination) ;
141
+ fx. bcx . ins ( ) . jump ( destination_block, & [ ] ) ;
142
+ }
143
+ None => {
144
+ fx. bcx . ins ( ) . trap ( TrapCode :: UnreachableCodeReached ) ;
145
+ }
146
+ }
147
+ }
148
+
149
+ fn codegen_inline_asm_inner < ' tcx > (
150
+ fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
151
+ template : & [ InlineAsmTemplatePiece ] ,
152
+ operands : & [ CInlineAsmOperand < ' tcx > ] ,
153
+ options : InlineAsmOptions ,
154
+ ) {
155
+ // FIXME add .eh_frame unwind info directives
156
+
138
157
let mut asm_gen = InlineAssemblyGenerator {
139
158
tcx : fx. tcx ,
140
159
arch : fx. tcx . sess . asm_arch . unwrap ( ) ,
141
160
enclosing_def_id : fx. instance . def_id ( ) ,
142
161
template,
143
- operands : & operands ,
162
+ operands,
144
163
options,
145
164
registers : Vec :: new ( ) ,
146
165
stack_slots_clobber : Vec :: new ( ) ,
@@ -185,16 +204,6 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
185
204
}
186
205
187
206
call_inline_asm ( fx, & asm_name, asm_gen. stack_slot_size , inputs, outputs) ;
188
-
189
- match destination {
190
- Some ( destination) => {
191
- let destination_block = fx. get_block ( destination) ;
192
- fx. bcx . ins ( ) . jump ( destination_block, & [ ] ) ;
193
- }
194
- None => {
195
- fx. bcx . ins ( ) . trap ( TrapCode :: UnreachableCodeReached ) ;
196
- }
197
- }
198
207
}
199
208
200
209
struct InlineAssemblyGenerator < ' a , ' tcx > {
@@ -754,14 +763,9 @@ pub(crate) fn codegen_xgetbv<'tcx>(
754
763
] ;
755
764
let options = InlineAsmOptions :: NOSTACK | InlineAsmOptions :: PURE | InlineAsmOptions :: NOMEM ;
756
765
757
- let mut inputs = Vec :: new ( ) ;
758
- let mut outputs = Vec :: new ( ) ;
759
-
760
- let mut asm_gen = InlineAssemblyGenerator {
761
- tcx : fx. tcx ,
762
- arch : fx. tcx . sess . asm_arch . unwrap ( ) ,
763
- enclosing_def_id : fx. instance . def_id ( ) ,
764
- template : & [ InlineAsmTemplatePiece :: String (
766
+ codegen_inline_asm_inner (
767
+ fx,
768
+ & [ InlineAsmTemplatePiece :: String (
765
769
"
766
770
xgetbv
767
771
// out = rdx << 32 | rax
@@ -770,41 +774,7 @@ pub(crate) fn codegen_xgetbv<'tcx>(
770
774
"
771
775
. to_string ( ) ,
772
776
) ] ,
773
- operands : & operands,
777
+ & operands,
774
778
options,
775
- registers : Vec :: new ( ) ,
776
- stack_slots_clobber : Vec :: new ( ) ,
777
- stack_slots_input : Vec :: new ( ) ,
778
- stack_slots_output : Vec :: new ( ) ,
779
- stack_slot_size : Size :: from_bytes ( 0 ) ,
780
- } ;
781
- asm_gen. allocate_registers ( ) ;
782
- asm_gen. allocate_stack_slots ( ) ;
783
-
784
- let inline_asm_index = fx. cx . inline_asm_index . get ( ) ;
785
- fx. cx . inline_asm_index . set ( inline_asm_index + 1 ) ;
786
- let asm_name = format ! (
787
- "__inline_asm_{}_n{}" ,
788
- fx. cx. cgu_name. as_str( ) . replace( '.' , "__" ) . replace( '-' , "_" ) ,
789
- inline_asm_index
790
779
) ;
791
-
792
- let generated_asm = asm_gen. generate_asm_wrapper ( & asm_name) ;
793
- fx. cx . global_asm . push_str ( & generated_asm) ;
794
-
795
- for ( i, operand) in operands. iter ( ) . enumerate ( ) {
796
- match operand {
797
- CInlineAsmOperand :: In { reg : _, value } => {
798
- inputs. push ( ( asm_gen. stack_slots_input [ i] . unwrap ( ) , * value) ) ;
799
- }
800
- CInlineAsmOperand :: Out { reg : _, late : _, place } => {
801
- if let Some ( place) = place {
802
- outputs. push ( ( asm_gen. stack_slots_output [ i] . unwrap ( ) , * place) ) ;
803
- }
804
- }
805
- _ => unreachable ! ( ) ,
806
- }
807
- }
808
-
809
- call_inline_asm ( fx, & asm_name, asm_gen. stack_slot_size , inputs, outputs) ;
810
780
}
0 commit comments