@@ -100,6 +100,16 @@ impl HasCodegen<'tcx> for Builder<'_, 'll, 'tcx> {
100
100
type CodegenCx = CodegenCx < ' ll , ' tcx > ;
101
101
}
102
102
103
+ macro_rules! builder_methods_for_value_instructions {
104
+ ( $( $name: ident( $( $arg: ident) ,* ) => $llvm_capi: ident) ,+ $( , ) ?) => {
105
+ $( fn $name( & mut self , $( $arg: & ' ll Value ) ,* ) -> & ' ll Value {
106
+ unsafe {
107
+ llvm:: $llvm_capi( self . llbuilder, $( $arg, ) * noname( ) )
108
+ }
109
+ } ) *
110
+ }
111
+ }
112
+
103
113
impl BuilderMethods < ' a , ' tcx > for Builder < ' a , ' ll , ' tcx > {
104
114
fn new_block < ' b > (
105
115
cx : & ' a CodegenCx < ' ll , ' tcx > ,
@@ -227,17 +237,30 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
227
237
}
228
238
}
229
239
230
- /* Arithmetic */
231
- fn add ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
232
- unsafe {
233
- llvm:: LLVMBuildAdd ( self . llbuilder , lhs, rhs, noname ( ) )
234
- }
235
- }
236
-
237
- fn fadd ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
238
- unsafe {
239
- llvm:: LLVMBuildFAdd ( self . llbuilder , lhs, rhs, noname ( ) )
240
- }
240
+ builder_methods_for_value_instructions ! {
241
+ add( a, b) => LLVMBuildAdd ,
242
+ fadd( a, b) => LLVMBuildFAdd ,
243
+ sub( a, b) => LLVMBuildSub ,
244
+ fsub( a, b) => LLVMBuildFSub ,
245
+ mul( a, b) => LLVMBuildMul ,
246
+ fmul( a, b) => LLVMBuildFMul ,
247
+ udiv( a, b) => LLVMBuildUDiv ,
248
+ exactudiv( a, b) => LLVMBuildExactUDiv ,
249
+ sdiv( a, b) => LLVMBuildSDiv ,
250
+ exactsdiv( a, b) => LLVMBuildExactSDiv ,
251
+ fdiv( a, b) => LLVMBuildFDiv ,
252
+ urem( a, b) => LLVMBuildURem ,
253
+ srem( a, b) => LLVMBuildSRem ,
254
+ frem( a, b) => LLVMBuildFRem ,
255
+ shl( a, b) => LLVMBuildShl ,
256
+ lshr( a, b) => LLVMBuildLShr ,
257
+ ashr( a, b) => LLVMBuildAShr ,
258
+ and( a, b) => LLVMBuildAnd ,
259
+ or( a, b) => LLVMBuildOr ,
260
+ xor( a, b) => LLVMBuildXor ,
261
+ neg( x) => LLVMBuildNeg ,
262
+ fneg( x) => LLVMBuildFNeg ,
263
+ not( x) => LLVMBuildNot ,
241
264
}
242
265
243
266
fn fadd_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
@@ -248,18 +271,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
248
271
}
249
272
}
250
273
251
- fn sub ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
252
- unsafe {
253
- llvm:: LLVMBuildSub ( self . llbuilder , lhs, rhs, noname ( ) )
254
- }
255
- }
256
-
257
- fn fsub ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
258
- unsafe {
259
- llvm:: LLVMBuildFSub ( self . llbuilder , lhs, rhs, noname ( ) )
260
- }
261
- }
262
-
263
274
fn fsub_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
264
275
unsafe {
265
276
let instr = llvm:: LLVMBuildFSub ( self . llbuilder , lhs, rhs, noname ( ) ) ;
@@ -268,18 +279,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
268
279
}
269
280
}
270
281
271
- fn mul ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
272
- unsafe {
273
- llvm:: LLVMBuildMul ( self . llbuilder , lhs, rhs, noname ( ) )
274
- }
275
- }
276
-
277
- fn fmul ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
278
- unsafe {
279
- llvm:: LLVMBuildFMul ( self . llbuilder , lhs, rhs, noname ( ) )
280
- }
281
- }
282
-
283
282
fn fmul_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
284
283
unsafe {
285
284
let instr = llvm:: LLVMBuildFMul ( self . llbuilder , lhs, rhs, noname ( ) ) ;
@@ -288,37 +287,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
288
287
}
289
288
}
290
289
291
-
292
- fn udiv ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
293
- unsafe {
294
- llvm:: LLVMBuildUDiv ( self . llbuilder , lhs, rhs, noname ( ) )
295
- }
296
- }
297
-
298
- fn exactudiv ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
299
- unsafe {
300
- llvm:: LLVMBuildExactUDiv ( self . llbuilder , lhs, rhs, noname ( ) )
301
- }
302
- }
303
-
304
- fn sdiv ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
305
- unsafe {
306
- llvm:: LLVMBuildSDiv ( self . llbuilder , lhs, rhs, noname ( ) )
307
- }
308
- }
309
-
310
- fn exactsdiv ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
311
- unsafe {
312
- llvm:: LLVMBuildExactSDiv ( self . llbuilder , lhs, rhs, noname ( ) )
313
- }
314
- }
315
-
316
- fn fdiv ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
317
- unsafe {
318
- llvm:: LLVMBuildFDiv ( self . llbuilder , lhs, rhs, noname ( ) )
319
- }
320
- }
321
-
322
290
fn fdiv_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
323
291
unsafe {
324
292
let instr = llvm:: LLVMBuildFDiv ( self . llbuilder , lhs, rhs, noname ( ) ) ;
@@ -327,24 +295,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
327
295
}
328
296
}
329
297
330
- fn urem ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
331
- unsafe {
332
- llvm:: LLVMBuildURem ( self . llbuilder , lhs, rhs, noname ( ) )
333
- }
334
- }
335
-
336
- fn srem ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
337
- unsafe {
338
- llvm:: LLVMBuildSRem ( self . llbuilder , lhs, rhs, noname ( ) )
339
- }
340
- }
341
-
342
- fn frem ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
343
- unsafe {
344
- llvm:: LLVMBuildFRem ( self . llbuilder , lhs, rhs, noname ( ) )
345
- }
346
- }
347
-
348
298
fn frem_fast ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
349
299
unsafe {
350
300
let instr = llvm:: LLVMBuildFRem ( self . llbuilder , lhs, rhs, noname ( ) ) ;
@@ -353,60 +303,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
353
303
}
354
304
}
355
305
356
- fn shl ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
357
- unsafe {
358
- llvm:: LLVMBuildShl ( self . llbuilder , lhs, rhs, noname ( ) )
359
- }
360
- }
361
-
362
- fn lshr ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
363
- unsafe {
364
- llvm:: LLVMBuildLShr ( self . llbuilder , lhs, rhs, noname ( ) )
365
- }
366
- }
367
-
368
- fn ashr ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
369
- unsafe {
370
- llvm:: LLVMBuildAShr ( self . llbuilder , lhs, rhs, noname ( ) )
371
- }
372
- }
373
-
374
- fn and ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
375
- unsafe {
376
- llvm:: LLVMBuildAnd ( self . llbuilder , lhs, rhs, noname ( ) )
377
- }
378
- }
379
-
380
- fn or ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
381
- unsafe {
382
- llvm:: LLVMBuildOr ( self . llbuilder , lhs, rhs, noname ( ) )
383
- }
384
- }
385
-
386
- fn xor ( & mut self , lhs : & ' ll Value , rhs : & ' ll Value ) -> & ' ll Value {
387
- unsafe {
388
- llvm:: LLVMBuildXor ( self . llbuilder , lhs, rhs, noname ( ) )
389
- }
390
- }
391
-
392
- fn neg ( & mut self , v : & ' ll Value ) -> & ' ll Value {
393
- unsafe {
394
- llvm:: LLVMBuildNeg ( self . llbuilder , v, noname ( ) )
395
- }
396
- }
397
-
398
- fn fneg ( & mut self , v : & ' ll Value ) -> & ' ll Value {
399
- unsafe {
400
- llvm:: LLVMBuildFNeg ( self . llbuilder , v, noname ( ) )
401
- }
402
- }
403
-
404
- fn not ( & mut self , v : & ' ll Value ) -> & ' ll Value {
405
- unsafe {
406
- llvm:: LLVMBuildNot ( self . llbuilder , v, noname ( ) )
407
- }
408
- }
409
-
410
306
fn checked_binop (
411
307
& mut self ,
412
308
oop : OverflowOp ,
0 commit comments