@@ -138,6 +138,8 @@ class AvarBoundsInference {
138
138
bool hasImpossibleBounds (BoundsKey BK);
139
139
// Set the given pointer to have impossible bounds.
140
140
void setImpossibleBounds (BoundsKey BK);
141
+ // Infer bounds of the given pointer key from potential bounds.
142
+ bool inferFromPotentialBounds (BoundsKey BK, AVarGraph &BKGraph);
141
143
142
144
AVarBoundsInfo *BI;
143
145
@@ -147,6 +149,31 @@ class AvarBoundsInference {
147
149
std::set<BoundsKey> BKsFailedFlowInference;
148
150
};
149
151
152
+ // Class that maintains information about potential bounds for
153
+ // various pointer variables.
154
+ class PotentialBoundsInfo {
155
+ public:
156
+ PotentialBoundsInfo () {
157
+ PotentialCntBounds.clear ();
158
+ PotentialCntPOneBounds.clear ();
159
+ }
160
+ // Count Bounds, i.e., count(i).
161
+ bool hasPotentialCountBounds (BoundsKey PtrBK);
162
+ std::set<BoundsKey> &getPotentialBounds (BoundsKey PtrBK);
163
+ void addPotentialBounds (BoundsKey BK, const std::set<BoundsKey> &PotK);
164
+
165
+ // Count Bounds Plus one, i.e., count(i+1).
166
+ bool hasPotentialCountPOneBounds (BoundsKey PtrBK);
167
+ std::set<BoundsKey> &getPotentialBoundsPOne (BoundsKey PtrBK);
168
+ void addPotentialBoundsPOne (BoundsKey BK, const std::set<BoundsKey> &PotK);
169
+ private:
170
+ // This is the map of pointer variable bounds key and set of bounds key
171
+ // which can be the count bounds.
172
+ std::map<BoundsKey, std::set<BoundsKey>> PotentialCntBounds;
173
+ // Potential count + 1 bounds.
174
+ std::map<BoundsKey, std::set<BoundsKey>> PotentialCntPOneBounds;
175
+ };
176
+
150
177
class AVarBoundsInfo {
151
178
public:
152
179
AVarBoundsInfo () : ProgVarGraph(this ), CtxSensProgVarGraph(this ),
@@ -171,7 +198,10 @@ class AVarBoundsInfo {
171
198
bool replaceBounds (BoundsKey L, BoundsPriority P, ABounds *B);
172
199
ABounds *getBounds (BoundsKey L, BoundsPriority ReqP = Invalid,
173
200
BoundsPriority *RetP = nullptr );
174
- bool updatePotentialCountBounds (BoundsKey BK, std::set<BoundsKey> &CntBK);
201
+ void updatePotentialCountBounds (BoundsKey BK,
202
+ const std::set<BoundsKey> &CntBK);
203
+ void updatePotentialCountPOneBounds (BoundsKey BK,
204
+ const std::set<BoundsKey> &CntBK);
175
205
176
206
// Try and get BoundsKey, into R, for the given declaration. If the
177
207
// declaration does not have a BoundsKey then return false.
@@ -316,9 +346,8 @@ class AVarBoundsInfo {
316
346
AVarGraph RevCtxSensProgVarGraph;
317
347
// Stats on techniques used to find length for various variables.
318
348
AVarBoundsStats BoundsInferStats;
319
- // This is the map of pointer variable bounds key and set of bounds key
320
- // which can be the count bounds.
321
- std::map<BoundsKey, std::set<BoundsKey>> PotentialCntBounds;
349
+ // Information about potential bounds.
350
+ PotentialBoundsInfo PotBoundsInfo;
322
351
// Context-sensitive bounds key handler
323
352
CtxSensitiveBoundsKeyHandler CSBKeyHandler;
324
353
@@ -351,7 +380,8 @@ class AVarBoundsInfo {
351
380
// Perform worklist based inference on the requested array variables using
352
381
// the provided graph and potential length variables.
353
382
bool performWorkListInference (const std::set<BoundsKey> &ArrNeededBounds,
354
- AVarGraph &BKGraph, AvarBoundsInference &BI);
383
+ AVarGraph &BKGraph, AvarBoundsInference &BI,
384
+ bool FromPB);
355
385
356
386
void insertParamKey (ParamDeclType ParamDecl, BoundsKey NK);
357
387
};
0 commit comments