LLVM: lib/Analysis/LoopUnrollAnalyzer.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
21
22using namespace llvm;
23
24
25
26
27
28
29
30
31
32bool UnrolledInstAnalyzer::simplifyInstWithSCEV(Instruction *I) {
33 if (!SE.isSCEVable(I->getType()))
34 return false;
35
36 const SCEV *S = SE.getSCEV(I);
38 SimplifiedValues[I] = SC->getValue();
39 return true;
40 }
41
42
43
44 if (!IterationNumber->isZero() && SE.isLoopInvariant(S, L))
45 return true;
46
48 if (!AR || AR->getLoop() != L)
49 return false;
50
51 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
52
54 SimplifiedValues[I] = SC->getValue();
55 return true;
56 }
57
58
60 if (!Base)
61 return false;
62 std::optional Offset =
63 SE.computeConstantDifference(ValueAtIteration, Base);
65 return false;
66 SimplifiedAddress Address;
67 Address.Base = Base->getValue();
69 SimplifiedAddresses[I] = Address;
70 return false;
71}
72
73
74
75
76
77
78bool UnrolledInstAnalyzer::visitBinaryOperator(BinaryOperator &I) {
79 Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
81 if (Value *SimpleLHS = SimplifiedValues.lookup(LHS))
82 LHS = SimpleLHS;
84 if (Value *SimpleRHS = SimplifiedValues.lookup(RHS))
85 RHS = SimpleRHS;
86
87 Value *SimpleV = nullptr;
88 const DataLayout &DL = I.getDataLayout();
90 SimpleV =
92 else
94
95 if (SimpleV) {
96 SimplifiedValues[&I] = SimpleV;
97 return true;
98 }
100}
101
102
103bool UnrolledInstAnalyzer::visitLoad(LoadInst &I) {
104 Value *AddrOp = I.getPointerOperand();
105
106 auto AddressIt = SimplifiedAddresses.find(AddrOp);
107 if (AddressIt == SimplifiedAddresses.end())
108 return false;
109
111
112
113 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
114 return false;
115
118 AddressIt->second.Offset, I.getDataLayout());
119 if (!Res)
120 return false;
121
122 SimplifiedValues[&I] = Res;
123 return true;
124}
125
126
127bool UnrolledInstAnalyzer::visitCastInst(CastInst &I) {
129 if (Value *Simplified = SimplifiedValues.lookup(Op))
131
132
133
134
136 const DataLayout &DL = I.getDataLayout();
139 return true;
140 }
141 }
142
144}
145
146
147bool UnrolledInstAnalyzer::visitCmpInst(CmpInst &I) {
148 Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
149
150
152 if (Value *SimpleLHS = SimplifiedValues.lookup(LHS))
153 LHS = SimpleLHS;
155 if (Value *SimpleRHS = SimplifiedValues.lookup(RHS))
156 RHS = SimpleRHS;
157
159 auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
160 if (SimplifiedLHS != SimplifiedAddresses.end()) {
161 auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
162 if (SimplifiedRHS != SimplifiedAddresses.end()) {
163 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
164 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
165 if (LHSAddr.Base == RHSAddr.Base) {
166
167
168
169
170
172 I.getPredicate());
174 return true;
175 }
176 }
177 }
178 }
179
180 const DataLayout &DL = I.getDataLayout();
183 return true;
184 }
185
187}
188
189bool UnrolledInstAnalyzer::visitPHINode(PHINode &PN) {
190
191
193 return true;
194
195
196 return PN.getParent() == L->getHeader();
197}
198
199bool UnrolledInstAnalyzer::visitInstruction(Instruction &I) {
200 return simplifyInstWithSCEV(&I);
201}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This is the base class for all instructions that perform data casts.
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
This class is the base class for the comparison instructions.
static LLVM_ABI ConstantInt * getBool(LLVMContext &Context, bool V)
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool visitCmpInst(CmpInst &I)
bool visitPHINode(PHINode &I)
bool visitBinaryOperator(BinaryOperator &I)
bool visitCastInst(CastInst &I)
An instruction for reading from memory.
const ParentTy * getParent() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
LLVM_ABI Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
DWARFExpression::Operation Op
LLVM_ABI Value * simplifyCmpInst(CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.