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

Method handleUser

lib/propanalysis/ArrayAnalyzer.cpp:287–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287void ArrayAnalyzer::handleUser(StackFrame &Frame, llvm::Value &User,
288 std::stack<StackFrame> &DefUseChains,
289 std::set<llvm::Value *> &VisitedNodes) {
290 Value *Def = Frame.Value;
291 ArgFlow &DefFlow = Frame.AnalysisResult;
292 auto &A = DefFlow.getLLVMArg();
293
294 if (auto *GEPI = dyn_cast<GetElementPtrInst>(&User)) {
295 if (GEPI->getNumIndices() > 2)
296 return;
297
298 auto *Op0 = GEPI->getOperand(0);
299 assert(Op0 && "Unexpected Program State");
300 auto *ST = getAsStructType(*Op0);
301 auto NumIndices = GEPI->getNumIndices();
302
303 if (NumIndices > 1 && !getAsArrayType(*Op0)) {
304 if (ST) {
305 assert((GEPI->getNumOperands() > NumIndices) &&
306 "Unexpected Program State");
307
308 if (const auto *CI =
309 dyn_cast<ConstantInt>(GEPI->getOperand(NumIndices))) {
310 DefFlow.setStruct(ST);
311 auto &FieldFlow = DefFlow.getOrCreateFieldFlow(CI->getLimitedValue());
312 FieldFlow.getFieldInfo()->Values.insert(GEPI);
313 DefUseChains.emplace(GEPI, FieldFlow);
314 return;
315 }
316 }
317 } else if (ST) { // for Struct Array
318 DefUseChains.emplace(GEPI, DefFlow);
319 }
320
321 if (VisitedNodes.find(Op0) != VisitedNodes.end()) {
322 assert((GEPI->getNumOperands() > NumIndices) &&
323 "Unexpected Program State");
324
325 if (const auto *CI =
326 dyn_cast<ConstantInt>(GEPI->getOperand(NumIndices))) {
327 if (CI->isZeroValue()) {
328 DefUseChains.emplace(GEPI, DefFlow);
329 return;
330 }
331
332 DefFlow.getArrIndices().insert(CI->getZExtValue());
333
334 auto &LI = FAM.getResult<LoopAnalysis>(*A.getParent());
335 if (LI.getLoopFor(GEPI->getParent()))
336 DefFlow.setIsVariableLenArray(true);
337 } else
338 DefFlow.setIsVariableLenArray(true);
339
340 if (DefFlow.isVariableLenArray())
341 analyzeArrayLen(*GEPI, DefFlow);
342
343 DefFlow.setIsArray(true);
344 }

Callers

nothing calls this directly

Calls 11

getAsArrayTypeFunction · 0.85
getCalledFunctionFunction · 0.85
isUnionFieldAccessFunction · 0.85
setStructMethod · 0.80
getFieldInfoMethod · 0.80
endMethod · 0.80
setIsVariableLenArrayMethod · 0.80
isVariableLenArrayMethod · 0.80
setIsArrayMethod · 0.80
mergeArrayMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected