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