MCPcopy Create free account
hub / github.com/Samsung/UTopia / getRelatedIndV

Method getRelatedIndV

lib/propanalysis/ArrayAnalyzer.cpp:220–266  ·  view source on GitHub ↗

This API returns an induction variable or A variable dependent on the induction variable

Source from the content-addressed store, hash-verified

218// This API returns an induction variable or
219// A variable dependent on the induction variable
220Value *ArrayAnalyzer::getRelatedIndV(Loop &L, ScalarEvolution &SEA) {
221 if (!L.isLoopSimplifyForm())
222 return nullptr;
223
224 auto *Header = L.getHeader();
225 assert(Header && "Unexpected Program State");
226
227 ICmpInst *CmpInst = getLoopExitCond(L);
228 if (!CmpInst)
229 return nullptr;
230 assert(CmpInst->getNumOperands() > 1 && "Unexpected Program State");
231
232 auto *LatchCmpOp0 = dyn_cast<Instruction>(CmpInst->getOperand(0));
233 auto *LatchCmpOp1 = dyn_cast<Instruction>(CmpInst->getOperand(1));
234
235 for (auto &IndVar : Header->phis()) {
236 InductionDescriptor IndDesc;
237 if (!InductionDescriptor::isInductionPHI(&IndVar, &L, &SEA, IndDesc))
238 continue;
239
240 // case 1: Induction Variable
241 if (&IndVar == LatchCmpOp0 || &IndVar == LatchCmpOp1)
242 return &IndVar;
243
244 // case 2: If IndVar is related to the operands of ICMP inst,
245 // it also depend on the count of loop
246 // ex) for (i = 0; i+1 < len; i++) : "i+1" dependent on IndVar
247 if (LatchCmpOp0) {
248 for (unsigned Opnum = 0; Opnum < LatchCmpOp0->getNumOperands(); Opnum++) {
249 if (LatchCmpOp0->getOperand(Opnum) != &IndVar)
250 continue;
251 return LatchCmpOp0;
252 }
253 }
254
255 // ex) for (i = 0; len > i+1; i++)
256 if (LatchCmpOp1) {
257 for (unsigned Opnum = 0; Opnum < LatchCmpOp1->getNumOperands(); Opnum++) {
258 if (LatchCmpOp1->getOperand(Opnum) != &IndVar)
259 continue;
260 return LatchCmpOp1;
261 }
262 }
263 }
264
265 return nullptr;
266}
267
268void ArrayAnalyzer::handleStackFrame(StackFrame &Frame,
269 std::stack<StackFrame> &DefUseChains,

Callers

nothing calls this directly

Calls 1

getLoopExitCondFunction · 0.85

Tested by

no test coverage detected