1- use astoir_mir:: { blocks:: MIRBlockHeldInstruction , ctx:: MIRContext , insts:: MIRInstruction , vals:: { base:: BaseMIRValue , float:: { MIRFloatValue } , int:: MIRIntValue , ptr:: MIRPointerValue } } ;
1+ use astoir_mir:: { blocks:: MIRBlockHeldInstruction , ctx:: MIRContext , insts:: { MIRInstruction } , vals:: { base:: BaseMIRValue , float:: MIRFloatValue , int:: MIRIntValue , ptr:: MIRPointerValue } } ;
22use compiler_typing:: { raw:: RawType } ;
3- use inkwell:: { IntPredicate , module:: Linkage , types:: { BasicType , BasicTypeEnum , StringRadix } , values:: { BasicValue , BasicValueEnum , FloatValue , IntValue } } ;
3+ use inkwell:: { IntPredicate , module:: Linkage , types:: { BasicType , BasicTypeEnum , StringRadix } , values:: { BasicValue , BasicValueEnum , FastMathFlags , FloatValue , IntValue } } ;
44
55use crate :: { ctx:: LLVMBridgeContext , llvm_to_base, llvm_to_base_returnless, utils:: LLVMBasicValue } ;
66
@@ -32,19 +32,23 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
3232 None
3333 }
3434
35- MIRInstruction :: IntegerAdd { signed : _, left, right } => {
35+ MIRInstruction :: IntegerAdd { signed : _, fast , left, right } => {
3636 let left: BaseMIRValue = MIRIntValue :: into ( left) ;
3737 let right: BaseMIRValue = MIRIntValue :: into ( right) ;
3838
3939 let l = bridge. values [ & left. get_ssa_index ( ) ] . clone ( ) ;
4040 let r = bridge. values [ & right. get_ssa_index ( ) ] . clone ( ) ;
4141
42- let res: IntValue < ' static > = llvm_to_base ! ( bridge. builder. build_int_add( l. into_int_value( ) , r. into_int_value( ) , "" ) ) ;
42+ let res = llvm_to_base ! ( bridge. builder. build_int_add( l. into_int_value( ) , r. into_int_value( ) , "" ) ) ;
43+
44+ if fast {
45+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
46+ }
4347
4448 Some ( res. into ( ) )
4549 } ,
4650
47- MIRInstruction :: IntegerSub { signed : _, left, right } => {
51+ MIRInstruction :: IntegerSub { signed : _, fast , left, right } => {
4852 let left: BaseMIRValue = MIRIntValue :: into ( left) ;
4953 let right: BaseMIRValue = MIRIntValue :: into ( right) ;
5054
@@ -53,10 +57,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
5357
5458 let res: IntValue < ' static > = llvm_to_base ! ( bridge. builder. build_int_sub( l. into_int_value( ) , r. into_int_value( ) , "" ) ) ;
5559
60+ if fast {
61+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
62+ }
63+
5664 Some ( res. into ( ) )
5765 } ,
5866
59- MIRInstruction :: IntegerMul { signed : _, left, right } => {
67+ MIRInstruction :: IntegerMul { signed : _, fast , left, right } => {
6068 let left: BaseMIRValue = MIRIntValue :: into ( left) ;
6169 let right: BaseMIRValue = MIRIntValue :: into ( right) ;
6270
@@ -65,10 +73,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
6573
6674 let res: IntValue < ' static > = llvm_to_base ! ( bridge. builder. build_int_mul( l. into_int_value( ) , r. into_int_value( ) , "" ) ) ;
6775
76+ if fast {
77+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
78+ }
79+
6880 Some ( res. into ( ) )
6981 } ,
7082
71- MIRInstruction :: IntegerDiv { signed, left, right } => {
83+ MIRInstruction :: IntegerDiv { signed, fast , left, right } => {
7284 let left: BaseMIRValue = MIRIntValue :: into ( left) ;
7385 let right: BaseMIRValue = MIRIntValue :: into ( right) ;
7486
@@ -83,10 +95,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
8395 res = llvm_to_base ! ( bridge. builder. build_int_unsigned_div( l. into_int_value( ) , r. into_int_value( ) , "" ) )
8496 }
8597
98+ if fast {
99+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
100+ }
101+
86102 Some ( res. into ( ) )
87103 } ,
88104
89- MIRInstruction :: IntegerMod { signed, left, right } => {
105+ MIRInstruction :: IntegerMod { signed, fast , left, right } => {
90106 let left: BaseMIRValue = MIRIntValue :: into ( left) ;
91107 let right: BaseMIRValue = MIRIntValue :: into ( right) ;
92108
@@ -101,10 +117,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
101117 res = llvm_to_base ! ( bridge. builder. build_int_unsigned_rem( l. into_int_value( ) , r. into_int_value( ) , "" ) )
102118 }
103119
120+ if fast {
121+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
122+ }
123+
104124 Some ( res. into ( ) )
105125 }
106126
107- MIRInstruction :: FloatAdd { signed : _, left, right } => {
127+ MIRInstruction :: FloatAdd { signed : _, fast , left, right } => {
108128 let left: BaseMIRValue = MIRFloatValue :: into ( left) ;
109129 let right: BaseMIRValue = MIRFloatValue :: into ( right) ;
110130
@@ -113,10 +133,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
113133
114134 let res: FloatValue < ' static > = llvm_to_base ! ( bridge. builder. build_float_add( l. into_float_value( ) , r. into_float_value( ) , "" ) ) ;
115135
136+ if fast {
137+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
138+ }
139+
116140 Some ( res. into ( ) )
117141 } ,
118142
119- MIRInstruction :: FloatSub { signed : _, left, right } => {
143+ MIRInstruction :: FloatSub { signed : _, fast , left, right } => {
120144 let left: BaseMIRValue = MIRFloatValue :: into ( left) ;
121145 let right: BaseMIRValue = MIRFloatValue :: into ( right) ;
122146
@@ -125,10 +149,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
125149
126150 let res: FloatValue < ' static > = llvm_to_base ! ( bridge. builder. build_float_sub( l. into_float_value( ) , r. into_float_value( ) , "" ) ) ;
127151
152+ if fast {
153+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
154+ }
155+
128156 Some ( res. into ( ) )
129157 } ,
130158
131- MIRInstruction :: FloatMul { signed : _, left, right } => {
159+ MIRInstruction :: FloatMul { signed : _, fast , left, right } => {
132160 let left: BaseMIRValue = MIRFloatValue :: into ( left) ;
133161 let right: BaseMIRValue = MIRFloatValue :: into ( right) ;
134162
@@ -137,10 +165,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
137165
138166 let res: FloatValue < ' static > = llvm_to_base ! ( bridge. builder. build_float_mul( l. into_float_value( ) , r. into_float_value( ) , "" ) ) ;
139167
168+ if fast {
169+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
170+ }
171+
140172 Some ( res. into ( ) )
141173 } ,
142174
143- MIRInstruction :: FloatDiv { signed : _, left, right } => {
175+ MIRInstruction :: FloatDiv { signed : _, fast , left, right } => {
144176 let left: BaseMIRValue = MIRFloatValue :: into ( left) ;
145177 let right: BaseMIRValue = MIRFloatValue :: into ( right) ;
146178
@@ -149,10 +181,14 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
149181
150182 let res: FloatValue < ' static > = llvm_to_base ! ( bridge. builder. build_float_div( l. into_float_value( ) , r. into_float_value( ) , "" ) ) ;
151183
184+ if fast {
185+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
186+ }
187+
152188 Some ( res. into ( ) )
153189 } ,
154190
155- MIRInstruction :: FloatMod { signed : _, left, right } => {
191+ MIRInstruction :: FloatMod { signed : _, fast , left, right } => {
156192 let left: BaseMIRValue = MIRFloatValue :: into ( left) ;
157193 let right: BaseMIRValue = MIRFloatValue :: into ( right) ;
158194
@@ -161,6 +197,10 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
161197
162198 let res: FloatValue < ' static > = llvm_to_base ! ( bridge. builder. build_float_rem( l. into_float_value( ) , r. into_float_value( ) , "" ) ) ;
163199
200+ if fast {
201+ llvm_to_base_returnless ! ( res. as_instruction_value( ) . unwrap( ) . set_fast_math_flags( FastMathFlags :: all( ) ) )
202+ }
203+
164204 Some ( res. into ( ) )
165205 }
166206
0 commit comments