xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Transforms/Utils/IntegerDivision.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- llvm/Transforms/Utils/IntegerDivision.h ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains an implementation of 32bit and 64bit scalar integer
10 // division for targets that don't have native support. It's largely derived
11 // from compiler-rt's implementations of __udivsi3 and __udivmoddi4,
12 // but hand-tuned for targets that prefer less control flow.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_TRANSFORMS_UTILS_INTEGERDIVISION_H
17 #define LLVM_TRANSFORMS_UTILS_INTEGERDIVISION_H
18 
19 #include "llvm/Support/Compiler.h"
20 
21 namespace llvm {
22   class BinaryOperator;
23 }
24 
25 namespace llvm {
26 
27   /// Generate code to calculate the remainder of two integers, replacing Rem
28   /// with the generated code. This currently generates code using the udiv
29   /// expansion, but future work includes generating more specialized code,
30   /// e.g. when more information about the operands are known. Implements both
31   /// 32bit and 64bit scalar division.
32   ///
33   /// Replace Rem with generated code.
34 LLVM_ABI bool expandRemainder(BinaryOperator *Rem);
35 
36 /// Generate code to divide two integers, replacing Div with the generated
37 /// code. This currently generates code similarly to compiler-rt's
38 /// implementations, but future work includes generating more specialized code
39 /// when more information about the operands are known. Implements both
40 /// 32bit and 64bit scalar division.
41 ///
42 /// Replace Div with generated code.
43 LLVM_ABI bool expandDivision(BinaryOperator *Div);
44 
45 /// Generate code to calculate the remainder of two integers, replacing Rem
46 /// with the generated code. Uses ExpandReminder with a 32bit Rem which
47 /// makes it useful for targets with little or no support for less than
48 /// 32 bit arithmetic.
49 ///
50 /// Replace Rem with generated code.
51 LLVM_ABI bool expandRemainderUpTo32Bits(BinaryOperator *Rem);
52 
53 /// Generate code to calculate the remainder of two integers, replacing Rem
54 /// with the generated code. Uses ExpandReminder with a 64bit Rem.
55 ///
56 /// Replace Rem with generated code.
57 LLVM_ABI bool expandRemainderUpTo64Bits(BinaryOperator *Rem);
58 
59 /// Generate code to divide two integers, replacing Div with the generated
60 /// code. Uses ExpandDivision with a 32bit Div which makes it useful for
61 /// targets with little or no support for less than 32 bit arithmetic.
62 ///
63 /// Replace Rem with generated code.
64 LLVM_ABI bool expandDivisionUpTo32Bits(BinaryOperator *Div);
65 
66 /// Generate code to divide two integers, replacing Div with the generated
67 /// code. Uses ExpandDivision with a 64bit Div.
68 ///
69 /// Replace Rem with generated code.
70 LLVM_ABI bool expandDivisionUpTo64Bits(BinaryOperator *Div);
71 
72 } // End llvm namespace
73 
74 #endif
75