1 //===- llvm/Transforms/Utils/IntegerDivision.h ------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TRANSFORMS_UTILS_INTEGERDIVISION_H
17 #define LLVM_TRANSFORMS_UTILS_INTEGERDIVISION_H
25 /// Generate code to calculate the remainder of two integers, replacing Rem
26 /// with the generated code. This currently generates code using the udiv
27 /// expansion, but future work includes generating more specialized code,
28 /// e.g. when more information about the operands are known. Implements both
29 /// 32bit and 64bit scalar division.
31 /// Replace Rem with generated code.
32 bool expandRemainder(BinaryOperator
*Rem
);
34 /// Generate code to divide two integers, replacing Div with the generated
35 /// code. This currently generates code similarly to compiler-rt's
36 /// implementations, but future work includes generating more specialized code
37 /// when more information about the operands are known. Implements both
38 /// 32bit and 64bit scalar division.
40 /// Replace Div with generated code.
41 bool expandDivision(BinaryOperator
* Div
);
43 /// Generate code to calculate the remainder of two integers, replacing Rem
44 /// with the generated code. Uses ExpandReminder with a 32bit Rem which
45 /// makes it useful for targets with little or no support for less than
46 /// 32 bit arithmetic.
48 /// Replace Rem with generated code.
49 bool expandRemainderUpTo32Bits(BinaryOperator
*Rem
);
51 /// Generate code to calculate the remainder of two integers, replacing Rem
52 /// with the generated code. Uses ExpandReminder with a 64bit Rem.
54 /// Replace Rem with generated code.
55 bool expandRemainderUpTo64Bits(BinaryOperator
*Rem
);
57 /// Generate code to divide two integers, replacing Div with the generated
58 /// code. Uses ExpandDivision with a 32bit Div which makes it useful for
59 /// targets with little or no support for less than 32 bit arithmetic.
61 /// Replace Rem with generated code.
62 bool expandDivisionUpTo32Bits(BinaryOperator
*Div
);
64 /// Generate code to divide two integers, replacing Div with the generated
65 /// code. Uses ExpandDivision with a 64bit Div.
67 /// Replace Rem with generated code.
68 bool expandDivisionUpTo64Bits(BinaryOperator
*Div
);
70 } // End llvm namespace