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

Method analyzeArrayLen

lib/propanalysis/ArrayAnalyzer.cpp:75–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void ArrayAnalyzer::analyzeArrayLen(Instruction &I, ArgFlow &AF) {
76 auto &LA = FAM.getResult<LoopAnalysis>(*AF.getLLVMArg().getParent());
77 Value *TrackingV = nullptr;
78 assert(I.getNumOperands() > 1 && "Unexpected Program State");
79
80 if (auto *L = LA.getLoopFor(I.getParent())) {
81 // Array ptr/index is invariant in the loop
82 if (L->isLoopInvariant(I.getOperand(0)) &&
83 L->isLoopInvariant(I.getOperand(1))) {
84 TrackingV = I.getOperand(1);
85 } else {
86 // Get the variable need to check
87 // if the count of iterations in the loop is dependent on the
88 // Argument/Field
89 TrackingV = getTrackingVariable(*L);
90 }
91 } else {
92 TrackingV = I.getOperand(1);
93 }
94 if (!TrackingV)
95 return;
96
97 // Check variable has dependency with Argument/Field
98 if (AF.isField())
99 AF.collectRelatedLengthField(*TrackingV);
100 else
101 AF.collectRelatedLengthArg(*TrackingV);
102
103 // if SizeFields has elements,
104 // it's means ArrayLen is realted to Argument/Field,
105 // get a ArgFlow for the Argument/Field, then set to ArrayLen
106 if (AF.isField()) { // For Field
107 auto FI = AF.getFieldInfo();
108 assert(FI && "Unexpected Program State");
109
110 auto &ParentFlow = FI->Parent;
111 for (auto FieldNum : FI->SizeFields) {
112 auto &FiedFlow = ParentFlow.getOrCreateFieldFlow(FieldNum);
113 FiedFlow.setToArrLen(FI->FieldNum);
114 }
115 } else { // For Argument
116 for (auto SizeArg : AF.getSizeArgs()) {
117 auto &A = AF.getLLVMArg();
118 if (SizeArg->getParent() != A.getParent())
119 continue;
120
121 analyze(*SizeArg);
122 auto &LenFlow = getOrCreateArgFlow(*SizeArg);
123 LenFlow.setToArrLen(A);
124 }
125 }
126}
127
128// This API returns a variable would be tracked
129// TODO:

Callers

nothing calls this directly

Calls 5

isFieldMethod · 0.80
getFieldInfoMethod · 0.80
setToArrLenMethod · 0.80

Tested by

no test coverage detected