38 cl::desc(
"div and rem instructions on integers with "
39 "more than <N> bits are expanded."));
42 auto *
C = dyn_cast<ConstantInt>(V);
53 return Opcode == Instruction::SDiv || Opcode == Instruction::SRem;
68 switch (
I.getOpcode()) {
69 case Instruction::UDiv:
70 case Instruction::SDiv:
71 case Instruction::URem:
72 case Instruction::SRem: {
74 auto *IntTy = dyn_cast<IntegerType>(
I.getType());
75 if (!IntTy || IntTy->getIntegerBitWidth() <= MaxLegalDivRemBitWidth)
94 while (!Replace.
empty()) {
97 if (
I->getOpcode() == Instruction::UDiv ||
98 I->getOpcode() == Instruction::SDiv) {
109class ExpandLargeDivRemLegacyPass :
public FunctionPass {
119 auto *TLI =
TM->getSubtargetImpl(
F)->getTargetLowering();
131char ExpandLargeDivRemLegacyPass::ID = 0;
133 "Expand large div/rem",
false,
false)
138 return new ExpandLargeDivRemLegacyPass();
static cl::opt< unsigned > ExpandDivRemBits("expand-div-rem-bits", cl::Hidden, cl::init(llvm::IntegerType::MAX_INT_BITS), cl::desc("div and rem instructions on integers with " "more than <N> bits are expanded."))
static bool isSigned(unsigned int Opcode)
static bool runImpl(Function &F, const TargetLowering &TLI)
static bool isConstantPowerOfTwo(llvm::Value *V, bool SignedOp)
static Expected< BitVector > expand(StringRef S, StringRef Original)
This is the interface for a simple mod/ref and alias analysis over globals.
Select target instructions out of generic instructions
const char LLVMTargetMachineRef TM
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
Class for arbitrary precision integers.
bool isNegative() const
Determine sign of this APInt.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Legacy wrapper pass to provide the GlobalsAAResult object.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getMaxDivRemBitWidthSupported() const
Returns the size in bits of the maximum div/rem the backend supports.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
Target-Independent Code Generator Pass Configuration Options.
LLVM Value Representation.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool expandDivision(BinaryOperator *Div)
Generate code to divide two integers, replacing Div with the generated code.
void initializeExpandLargeDivRemLegacyPassPass(PassRegistry &)
FunctionPass * createExpandLargeDivRemPass()
bool expandRemainder(BinaryOperator *Rem)
Generate code to calculate the remainder of two integers, replacing Rem with the generated code.