@@ -400,10 +400,12 @@ bool AVarBoundsInfo::addAssignment(BoundsKey L, BoundsKey R) {
400
400
// dependency and never will be able to find the bounds for the return
401
401
// value.
402
402
if (L != R)
403
- ProgVarGraph.addEdge (R, L);
403
+ ProgVarGraph.addUniqueEdge (R, L);
404
404
} else {
405
- ProgVarGraph.addEdge (L, R);
406
- ProgVarGraph.addEdge (R, L);
405
+ ProgVarGraph.addUniqueEdge (R, L);
406
+ ProgramVar *PV = getProgramVar (R);
407
+ if (!(PV && PV->IsNumConstant ()))
408
+ ProgVarGraph.addUniqueEdge (L, R);
407
409
}
408
410
return true ;
409
411
}
@@ -512,25 +514,18 @@ BoundsKey AVarBoundsInfo::getVarKey(PersistentSourceLoc &PSL) {
512
514
}
513
515
514
516
BoundsKey AVarBoundsInfo::getConstKey (uint64_t value) {
515
- BoundsKey NK = ++BCount;
516
- std::string ConsString = std::to_string (value);
517
- ProgramVar *NPV =
518
- ProgramVar::createNewProgramVar (NK,
519
- ConsString,
520
- GlobalScope::getGlobalScope (),
521
- true );
522
- insertProgramVar (NK, NPV);
523
- ConstVarKeys[value].insert (NK);
524
- return NK;
525
- }
526
-
527
- bool AVarBoundsInfo::fetchAllConstKeys (uint64_t value,
528
- std::set<BoundsKey> &AllKeys) {
529
- if (ConstVarKeys.find (value) != ConstVarKeys.end ()) {
530
- AllKeys.insert (ConstVarKeys[value].begin (), ConstVarKeys[value].end ());
531
- return true ;
517
+ if (ConstVarKeys.find (value) == ConstVarKeys.end ()) {
518
+ BoundsKey NK = ++BCount;
519
+ std::string ConsString = std::to_string (value);
520
+ ProgramVar *NPV =
521
+ ProgramVar::createNewProgramVar (NK,
522
+ ConsString,
523
+ GlobalScope::getGlobalScope (),
524
+ true );
525
+ insertProgramVar (NK, NPV);
526
+ ConstVarKeys[value] = NK;
532
527
}
533
- return false ;
528
+ return ConstVarKeys[value] ;
534
529
}
535
530
536
531
BoundsKey AVarBoundsInfo::getVarKey (llvm::APSInt &API) {
@@ -712,15 +707,6 @@ bool AvarBoundsInference::getReachableBoundKeys(const ProgramVarScope *DstScope,
712
707
AllFKeys.clear ();
713
708
AllFKeys.insert (FromVarK);
714
709
715
- // If this is a constant? Then get all bounds keys that
716
- // correspond to the same constant
717
- if (SBVar->IsNumConstant ()) {
718
- uint64_t ConsVal;
719
- std::istringstream IS (SBVar->getVarName ());
720
- IS >> ConsVal;
721
- BI->fetchAllConstKeys (ConsVal, AllFKeys);
722
- }
723
-
724
710
for (auto CurrVarK : AllFKeys) {
725
711
// Find all the in scope variables reachable from the CurrVarK
726
712
// bounds variable.
@@ -731,6 +717,24 @@ bool AvarBoundsInference::getReachableBoundKeys(const ProgramVarScope *DstScope,
731
717
});
732
718
}
733
719
720
+ // This is to get all the constants that are assigned to the variables
721
+ // reachable from FromVarK.
722
+ if (!SBVar->IsNumConstant ()) {
723
+ std::set<BoundsKey> ReachableCons;
724
+ std::set<BoundsKey> Pre;
725
+ for (auto CK : PotK) {
726
+ Pre.clear ();
727
+ BKGraph.getPredecessors (CK, Pre);
728
+ for (auto T : Pre) {
729
+ auto *TVar = BI->getProgramVar (T);
730
+ if (TVar->IsNumConstant ()) {
731
+ ReachableCons.insert (T);
732
+ }
733
+ }
734
+ }
735
+ PotK.insert (ReachableCons.begin (), ReachableCons.end ());
736
+ }
737
+
734
738
return !PotK.empty ();
735
739
}
736
740
@@ -1229,11 +1233,10 @@ bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) {
1229
1233
// Any thing changed? which means bounds of a variable changed
1230
1234
// Which means we need to recompute the flow based bounds for
1231
1235
// all arrays that have flow based bounds.
1232
- if (keepHighestPriorityBounds (ArrPointerBoundsKey)) {
1233
- // Remove flow inferred bounds, if exist for all the array pointers.
1234
- for (auto TBK : ArrPointerBoundsKey)
1235
- removeBounds (TBK, FlowInferred);
1236
- }
1236
+ keepHighestPriorityBounds (ArrPointerBoundsKey);
1237
+ // Remove flow inferred bounds, if exist for all the array pointers.
1238
+ for (auto TBK : ArrPointerBoundsKey)
1239
+ removeBounds (TBK, FlowInferred);
1237
1240
1238
1241
std::set<BoundsKey> ArrNeededBounds, ArrNeededBoundsNew;
1239
1242
ArrNeededBounds.clear ();
0 commit comments