@@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
6
6
use cranelift_module:: ModuleError ;
7
7
use rustc_ast:: InlineAsmOptions ;
8
8
use rustc_index:: IndexVec ;
9
+ use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
9
10
use rustc_middle:: ty:: adjustment:: PointerCoercion ;
10
11
use rustc_middle:: ty:: layout:: FnAbiOf ;
11
12
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
@@ -14,6 +15,7 @@ use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphizat
14
15
15
16
use crate :: constant:: ConstantCx ;
16
17
use crate :: debuginfo:: { FunctionDebugContext , TypeDebugContext } ;
18
+ use crate :: inline_asm:: codegen_naked_asm;
17
19
use crate :: prelude:: * ;
18
20
use crate :: pretty_clif:: CommentWriter ;
19
21
@@ -32,7 +34,7 @@ pub(crate) fn codegen_fn<'tcx>(
32
34
cached_func : Function ,
33
35
module : & mut dyn Module ,
34
36
instance : Instance < ' tcx > ,
35
- ) -> CodegenedFunction {
37
+ ) -> Option < CodegenedFunction > {
36
38
debug_assert ! ( !instance. args. has_infer( ) ) ;
37
39
38
40
let symbol_name = tcx. symbol_name ( instance) . name . to_string ( ) ;
@@ -48,6 +50,37 @@ pub(crate) fn codegen_fn<'tcx>(
48
50
String :: from_utf8_lossy ( & buf) . into_owned ( )
49
51
} ) ;
50
52
53
+ if tcx. codegen_fn_attrs ( instance. def_id ( ) ) . flags . contains ( CodegenFnAttrFlags :: NAKED ) {
54
+ assert_eq ! ( mir. basic_blocks. len( ) , 1 ) ;
55
+ assert ! ( mir. basic_blocks[ START_BLOCK ] . statements. is_empty( ) ) ;
56
+
57
+ match & mir. basic_blocks [ START_BLOCK ] . terminator ( ) . kind {
58
+ TerminatorKind :: InlineAsm {
59
+ template,
60
+ operands,
61
+ options,
62
+ line_spans : _,
63
+ targets : _,
64
+ unwind : _,
65
+ } => {
66
+ codegen_naked_asm (
67
+ tcx,
68
+ cx,
69
+ module,
70
+ instance,
71
+ mir. basic_blocks [ START_BLOCK ] . terminator ( ) . source_info . span ,
72
+ & symbol_name,
73
+ template,
74
+ operands,
75
+ * options,
76
+ ) ;
77
+ }
78
+ _ => unreachable ! ( ) ,
79
+ }
80
+
81
+ return None ;
82
+ }
83
+
51
84
// Declare function
52
85
let sig = get_function_sig ( tcx, module. target_config ( ) . default_call_conv , instance) ;
53
86
let func_id = module. declare_function ( & symbol_name, Linkage :: Local , & sig) . unwrap ( ) ;
@@ -128,7 +161,7 @@ pub(crate) fn codegen_fn<'tcx>(
128
161
// Verify function
129
162
verify_func ( tcx, & clif_comments, & func) ;
130
163
131
- CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
164
+ Some ( CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx } )
132
165
}
133
166
134
167
pub ( crate ) fn compile_fn (
0 commit comments