@@ -128,7 +128,7 @@ impl<'ll, 'tcx> HasCodegen<'tcx> for Builder<'_, 'll, 'tcx> {
128
128
type CodegenCx = CodegenCx < ' ll , ' tcx > ;
129
129
}
130
130
131
- macro_rules! builder_methods_for_value_instructions {
131
+ macro_rules! math_builder_methods {
132
132
( $( $name: ident( $( $arg: ident) ,* ) => $llvm_capi: ident) ,+ $( , ) ?) => {
133
133
$( fn $name( & mut self , $( $arg: & ' ll Value ) ,* ) -> & ' ll Value {
134
134
unsafe {
@@ -138,6 +138,18 @@ macro_rules! builder_methods_for_value_instructions {
138
138
}
139
139
}
140
140
141
+ macro_rules! set_math_builder_methods {
142
+ ( $( $name: ident( $( $arg: ident) ,* ) => ( $llvm_capi: ident, $llvm_set_math: ident) ) ,+ $( , ) ?) => {
143
+ $( fn $name( & mut self , $( $arg: & ' ll Value ) ,* ) -> & ' ll Value {
144
+ unsafe {
145
+ let instr = llvm:: $llvm_capi( self . llbuilder, $( $arg, ) * UNNAMED ) ;
146
+ llvm:: $llvm_set_math( instr) ;
147
+ instr
148
+ }
149
+ } ) +
150
+ }
151
+ }
152
+
141
153
impl < ' a , ' ll , ' tcx > BuilderMethods < ' a , ' tcx > for Builder < ' a , ' ll , ' tcx > {
142
154
fn build ( cx : & ' a CodegenCx < ' ll , ' tcx > , llbb : & ' ll BasicBlock ) -> Self {
143
155
let bx = Builder :: with_cx ( cx) ;
@@ -273,7 +285,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
273
285
}
274
286
}
275
287
276
- builder_methods_for_value_instructions ! {
288
+ math_builder_methods ! {
277
289
add( a, b) => LLVMBuildAdd ,
278
290
fadd( a, b) => LLVMBuildFAdd ,
279
291
sub( a, b) => LLVMBuildSub ,
@@ -305,84 +317,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
305
317
unchecked_umul( x, y) => LLVMBuildNUWMul ,
306
318
}
307
319
308
- fn fadd_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
309
- unsafe {
310
- let instr = llvm:: LLVMBuildFAdd ( self . llbuilder , lhs, rhs, UNNAMED ) ;
311
- llvm:: LLVMRustSetFastMath ( instr) ;
312
- instr
313
- }
314
- }
315
-
316
- fn fsub_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
317
- unsafe {
318
- let instr = llvm:: LLVMBuildFSub ( self . llbuilder , lhs, rhs, UNNAMED ) ;
319
- llvm:: LLVMRustSetFastMath ( instr) ;
320
- instr
321
- }
322
- }
323
-
324
- fn fmul_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
325
- unsafe {
326
- let instr = llvm:: LLVMBuildFMul ( self . llbuilder , lhs, rhs, UNNAMED ) ;
327
- llvm:: LLVMRustSetFastMath ( instr) ;
328
- instr
329
- }
330
- }
331
-
332
- fn fdiv_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
333
- unsafe {
334
- let instr = llvm:: LLVMBuildFDiv ( self . llbuilder , lhs, rhs, UNNAMED ) ;
335
- llvm:: LLVMRustSetFastMath ( instr) ;
336
- instr
337
- }
338
- }
339
-
340
- fn frem_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
341
- unsafe {
342
- let instr = llvm:: LLVMBuildFRem ( self . llbuilder , lhs, rhs, UNNAMED ) ;
343
- llvm:: LLVMRustSetFastMath ( instr) ;
344
- instr
345
- }
346
- }
347
-
348
- fn fadd_algebraic ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
349
- unsafe {
350
- let instr = llvm:: LLVMBuildFAdd ( self . llbuilder , lhs, rhs, UNNAMED ) ;
351
- llvm:: LLVMRustSetAlgebraicMath ( instr) ;
352
- instr
353
- }
354
- }
355
-
356
- fn fsub_algebraic ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
357
- unsafe {
358
- let instr = llvm:: LLVMBuildFSub ( self . llbuilder , lhs, rhs, UNNAMED ) ;
359
- llvm:: LLVMRustSetAlgebraicMath ( instr) ;
360
- instr
361
- }
362
- }
363
-
364
- fn fmul_algebraic ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
365
- unsafe {
366
- let instr = llvm:: LLVMBuildFMul ( self . llbuilder , lhs, rhs, UNNAMED ) ;
367
- llvm:: LLVMRustSetAlgebraicMath ( instr) ;
368
- instr
369
- }
370
- }
371
-
372
- fn fdiv_algebraic ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
373
- unsafe {
374
- let instr = llvm:: LLVMBuildFDiv ( self . llbuilder , lhs, rhs, UNNAMED ) ;
375
- llvm:: LLVMRustSetAlgebraicMath ( instr) ;
376
- instr
377
- }
378
- }
379
-
380
- fn frem_algebraic ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
381
- unsafe {
382
- let instr = llvm:: LLVMBuildFRem ( self . llbuilder , lhs, rhs, UNNAMED ) ;
383
- llvm:: LLVMRustSetAlgebraicMath ( instr) ;
384
- instr
385
- }
320
+ set_math_builder_methods ! {
321
+ fadd_fast( x, y) => ( LLVMBuildFAdd , LLVMRustSetFastMath ) ,
322
+ fsub_fast( x, y) => ( LLVMBuildFSub , LLVMRustSetFastMath ) ,
323
+ fmul_fast( x, y) => ( LLVMBuildFMul , LLVMRustSetFastMath ) ,
324
+ fdiv_fast( x, y) => ( LLVMBuildFDiv , LLVMRustSetFastMath ) ,
325
+ frem_fast( x, y) => ( LLVMBuildFRem , LLVMRustSetFastMath ) ,
326
+ fadd_algebraic( x, y) => ( LLVMBuildFAdd , LLVMRustSetAlgebraicMath ) ,
327
+ fsub_algebraic( x, y) => ( LLVMBuildFSub , LLVMRustSetAlgebraicMath ) ,
328
+ fmul_algebraic( x, y) => ( LLVMBuildFMul , LLVMRustSetAlgebraicMath ) ,
329
+ fdiv_algebraic( x, y) => ( LLVMBuildFDiv , LLVMRustSetAlgebraicMath ) ,
330
+ frem_algebraic( x, y) => ( LLVMBuildFRem , LLVMRustSetAlgebraicMath ) ,
386
331
}
387
332
388
333
fn checked_binop (
@@ -465,6 +410,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
465
410
val
466
411
}
467
412
}
413
+
468
414
fn to_immediate_scalar ( & mut self , val : Self :: Value , scalar : abi:: Scalar ) -> Self :: Value {
469
415
if scalar. is_bool ( ) {
470
416
return self . trunc ( val, self . cx ( ) . type_i1 ( ) ) ;
@@ -1166,6 +1112,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
1166
1112
( val, success)
1167
1113
}
1168
1114
}
1115
+
1169
1116
fn atomic_rmw (
1170
1117
& mut self ,
1171
1118
op : rustc_codegen_ssa:: common:: AtomicRmwBinOp ,
0 commit comments