LLVM: lib/CodeGen/ExpandLargeDivRem.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
32
33using namespace llvm;
34
38 cl::desc("div and rem instructions on integers with "
39 "more than bits are expanded."));
40
43 if ()
44 return false;
45
48 Val = -Val;
50}
51
52static bool isSigned(unsigned int Opcode) {
53 return Opcode == Instruction::SDiv || Opcode == Instruction::SRem;
54}
55
59
61
62 unsigned NumElements = VTy->getElementCount().getFixedValue();
64 for (unsigned Idx = 0; Idx < NumElements; ++Idx) {
68 Result = Builder.CreateInsertElement(Result, Op, Idx);
70 NewBO->copyIRFlags(Op, true);
72 }
73 }
77}
78
83
87
89 return false;
90
92 switch (I.getOpcode()) {
93 case Instruction::UDiv:
94 case Instruction::SDiv:
95 case Instruction::URem:
96 case Instruction::SRem: {
97
98 if (I.getOperand(0)->getType()->isScalableTy())
99 continue;
100
102 if (!IntTy || IntTy->getIntegerBitWidth() <= MaxLegalDivRemBitWidth)
103 continue;
104
105
106
108 continue;
109
110 if (I.getOperand(0)->getType()->isVectorTy())
112 else
115 break;
116 }
117 default:
118 break;
119 }
120 }
121
122 while (!ReplaceVector.empty()) {
125 }
126
127 if (Replace.empty())
128 return false;
129
130 while (!Replace.empty()) {
132
133 if (I->getOpcode() == Instruction::UDiv ||
134 I->getOpcode() == Instruction::SDiv) {
136 } else {
138 }
139 }
140
142}
143
144namespace {
145class ExpandLargeDivRemLegacyPass : public FunctionPass {
146public:
147 static char ID;
148
149 ExpandLargeDivRemLegacyPass() : FunctionPass(ID) {
151 }
152
154 auto *TM = &getAnalysis().getTM();
155 auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering();
157 }
158
159 void getAnalysisUsage(AnalysisUsage &AU) const override {
163 }
164};
165}
166
173
174char ExpandLargeDivRemLegacyPass::ID = 0;
176 "Expand large div/rem", false, false)
179
181 return new ExpandLargeDivRemLegacyPass();
182}
Expand Atomic instructions
static bool runOnFunction(Function &F, bool PostInlining)
static bool runImpl(Function &F, const TargetLowering &TLI, const LibcallLoweringInfo &Libcalls, AssumptionCache *AC)
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 bits are expanded."))
static bool isSigned(unsigned int Opcode)
Definition ExpandLargeDivRem.cpp:52
static void scalarize(BinaryOperator *BO, SmallVectorImpl< BinaryOperator * > &Replace)
Definition ExpandLargeDivRem.cpp:56
static bool runImpl(Function &F, const TargetLowering &TLI)
Definition ExpandLargeDivRem.cpp:79
static bool isConstantPowerOfTwo(llvm::Value *V, bool SignedOp)
Definition ExpandLargeDivRem.cpp:41
This is the interface for a simple mod/ref and alias analysis over globals.
This header defines various interfaces for pass management in LLVM.
FunctionAnalysisManager FAM
#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.
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.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
BinaryOps getOpcode() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition ExpandLargeDivRem.cpp:167
FunctionPass class - This class is used to implement most global optimizations.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetLowering * getTargetLowering() const
void dropAllReferences()
Drop all references to operands.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
@ 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.
LLVM_ABI bool expandDivision(BinaryOperator *Div)
Generate code to divide two integers, replacing Div with the generated code.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI FunctionPass * createExpandLargeDivRemPass()
Definition ExpandLargeDivRem.cpp:180
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI bool expandRemainder(BinaryOperator *Rem)
Generate code to calculate the remainder of two integers, replacing Rem with the generated code.
LLVM_ABI void initializeExpandLargeDivRemLegacyPassPass(PassRegistry &)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.