1
1
use std:: cell:: Cell ;
2
2
use std:: ffi:: CString ;
3
3
use std:: mem;
4
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
4
5
5
6
use llvm:: { BasicBlock , Sub } ;
6
7
use llvm:: Builder ;
7
8
use llvm:: Function ;
8
9
use llvm:: Value ;
9
10
10
- use super :: super :: wasm:: ImplementedFunction ;
11
-
12
- use super :: block:: compile_block;
13
- use super :: breakout:: BreakoutTarget ;
14
- use super :: type_conversions:: wasm_type_to_zeroed_value;
15
- use super :: ModuleCtx ;
16
11
use wasmparser:: TypeOrFuncType ;
17
12
13
+ use crate :: codegen:: block:: compile_block;
14
+ use crate :: codegen:: breakout:: BreakoutTarget ;
15
+ use crate :: codegen:: type_conversions:: wasm_type_to_zeroed_value;
16
+ use crate :: codegen:: ModuleCtx ;
17
+
18
+ use crate :: wasm:: ImplementedFunction ;
19
+
18
20
pub struct FunctionCtx < ' a > {
19
21
pub llvm_f : & ' a Function ,
20
22
pub builder : & ' a Builder ,
@@ -31,29 +33,33 @@ impl<'a> FunctionCtx<'a> {
31
33
}
32
34
}
33
35
34
- unsafe fn add_string_attr ( k : & str , v : & str , v_ref : * mut llvm_sys :: LLVMValue , ctx : & ModuleCtx ) {
35
- let idx = llvm_sys :: LLVMAttributeFunctionIndex ;
36
+ unsafe fn add_string_attr ( k : & str , v : & str , v_ref : * mut llvm :: ffi :: LLVMValue , ctx : & ModuleCtx ) {
37
+ let idx = crate :: llvm_externs :: LLVMAttributeFunctionIndex ;
36
38
37
39
let target_features_key = CString :: new ( k) . unwrap ( ) ;
38
40
let target_features_value = CString :: new ( v) . unwrap ( ) ;
39
41
40
- let llvm_ctx: * mut llvm_sys :: LLVMContext = mem:: transmute ( ctx. llvm_ctx as & llvm:: Context ) ;
41
- let attr_ref = llvm_sys :: core :: LLVMCreateStringAttribute (
42
+ let llvm_ctx: * mut llvm :: ffi :: LLVMContext = mem:: transmute ( ctx. llvm_ctx as & llvm:: Context ) ;
43
+ let attr_ref = crate :: llvm_externs :: LLVMCreateStringAttribute (
42
44
llvm_ctx,
43
45
target_features_key. as_ptr ( ) ,
44
46
target_features_key. as_bytes ( ) . len ( ) as u32 ,
45
47
target_features_value. as_ptr ( ) ,
46
48
target_features_value. as_bytes ( ) . len ( ) as u32 ,
47
49
) ;
48
50
49
- llvm_sys :: core :: LLVMAddAttributeAtIndex (
51
+ crate :: llvm_externs :: LLVMAddAttributeAtIndex (
50
52
v_ref,
51
53
idx,
52
54
attr_ref
53
55
) ;
54
56
55
57
}
56
58
59
+ // HACK: We only want to emit a note about the cortex-m override once
60
+ // TODO: Is this clearer than doing it up a level in the code?
61
+ static CORTEX_OVERRIDE_MESSAGE_SENT : AtomicBool = AtomicBool :: new ( false ) ;
62
+
57
63
pub fn compile_function ( ctx : & ModuleCtx , f : & ImplementedFunction ) {
58
64
let llvm_f = ctx. llvm_module . get_function ( & f. generated_name ) . unwrap ( ) ;
59
65
@@ -86,20 +92,25 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) {
86
92
} ;
87
93
88
94
unsafe {
89
- let v_ref: * mut llvm_sys :: LLVMValue = mem:: transmute ( llvm_f. to_super ( ) as & Value ) ;
90
- let llvm_ctx: * mut llvm_sys :: LLVMContext = mem:: transmute ( ctx. llvm_ctx as & llvm:: Context ) ;
95
+ let v_ref: * mut llvm :: ffi :: LLVMValue = mem:: transmute ( llvm_f. to_super ( ) as & Value ) ;
96
+ let llvm_ctx: * mut llvm :: ffi :: LLVMContext = mem:: transmute ( ctx. llvm_ctx as & llvm:: Context ) ;
91
97
92
98
let nounwind = CString :: new ( "nounwind" ) . unwrap ( ) ;
93
- let kind = llvm_sys :: core :: LLVMGetEnumAttributeKindForName ( nounwind. as_ptr ( ) , nounwind. as_bytes ( ) . len ( ) ) ;
94
- let attr_ref = llvm_sys :: core :: LLVMCreateEnumAttribute ( llvm_ctx, kind, 0 ) ;
99
+ let kind = crate :: llvm_externs :: LLVMGetEnumAttributeKindForName ( nounwind. as_ptr ( ) , nounwind. as_bytes ( ) . len ( ) ) ;
100
+ let attr_ref = crate :: llvm_externs :: LLVMCreateEnumAttribute ( llvm_ctx, kind, 0 ) ;
95
101
96
- llvm_sys :: core :: LLVMAddAttributeAtIndex (
102
+ crate :: llvm_externs :: LLVMAddAttributeAtIndex (
97
103
v_ref,
98
- llvm_sys :: LLVMAttributeFunctionIndex ,
104
+ crate :: llvm_externs :: LLVMAttributeFunctionIndex ,
99
105
attr_ref
100
106
) ;
101
107
if cm_override {
102
- info ! ( "engaging cortex-m override" ) ;
108
+ if !CORTEX_OVERRIDE_MESSAGE_SENT . load ( Ordering :: Relaxed ) {
109
+ info ! ( "engaging cortex-m override" ) ;
110
+
111
+ // Only send the message once!
112
+ CORTEX_OVERRIDE_MESSAGE_SENT . store ( true , Ordering :: Relaxed ) ;
113
+ }
103
114
104
115
add_string_attr (
105
116
"correctly-rounded-divide-sqrt-fp-math" ,
0 commit comments