llvm.org GIT mirror llvm / f3a9e36
Cleanup. Refactor out the applying of value ranges to its own method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35719 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 12 years ago
1 changed file(s) with 35 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
460460 ToRepoint.push_back(V);
461461
462462 if (unsigned Conflict = getNode(V, Subtree)) {
463 // XXX: NodeMap.size() exceeds 68,000 entries compiling kimwitu++!
464463 for (NodeMapType::iterator I = NodeMap.begin(), E = NodeMap.end();
465464 I != E; ++I) {
466465 if (I->index == Conflict && Subtree->DominatedBy(I->Subtree))
511510 // Suppose we're adding %n1 < %n2. Find all the %a < %n1 and
512511 // add %a < %n2 too. This keeps the graph fully connected.
513512 if (LV1 != NE) {
514 // Someone with a head for this sort of logic, please review this.
515 // Given that %x SLTUGT %y and %a SLE %x, what is the relationship
516 // between %a and %y? I believe the below code is correct, but I don't
517 // think it's the most efficient solution.
513 // Break up the relationship into signed and unsigned comparison parts.
514 // If the signed parts of %a op1 %n1 match that of %n1 op2 %n2, and
515 // op1 and op2 aren't NE, then add %a op3 %n2. The new relationship
516 // should have the EQ_BIT iff it's set for both op1 and op2.
518517
519518 unsigned LV1_s = LV1 & (SLT_BIT|SGT_BIT);
520519 unsigned LV1_u = LV1 & (ULT_BIT|UGT_BIT);
520
521521 for (Node::iterator I = N1->begin(), E = N1->end(); I != E; ++I) {
522522 if (I->LV != NE && I->To != n2) {
523
523524 ETNode *Local_Subtree = NULL;
524525 if (Subtree->DominatedBy(I->Subtree))
525526 Local_Subtree = Subtree;
534535
535536 if (LV1_s != (SLT_BIT|SGT_BIT) && ILV_s == LV1_s)
536537 new_relationship |= ILV_s;
537
538538 if (LV1_u != (ULT_BIT|UGT_BIT) && ILV_u == LV1_u)
539539 new_relationship |= ILV_u;
540540
718718 // Also, we have to tighten any edge that Subtree dominates.
719719 for (iterator B = begin(); I->V == V; --I) {
720720 if (I->Subtree->DominatedBy(Subtree)) {
721 CR = CR.intersectWith(I->CR);
722 assert(!CR.isEmptySet() &&
721 I->CR = CR.intersectWith(I->CR);
722 assert(!I->CR.isEmptySet() &&
723723 "Empty intersection of ConstantRanges!");
724 I->CR = CR;
725724 }
726725 if (I == B) break;
727726 }
905904 }
906905 }
907906
908 void addToWorklist(Value *V, const APInt *I, ICmpInst::Predicate Pred,
907 void addToWorklist(Value *V, Constant *C, ICmpInst::Predicate Pred,
909908 VRPSolver *VRP);
910909
911910 void mergeInto(Value **I, unsigned n, Value *New, ETNode *Subtree,
926925
927926 if (Merged.isFullSet() || Merged == CR_New) return;
928927
929 if (Merged.isSingleElement())
930 addToWorklist(New, Merged.getSingleElement(),
928 applyRange(New, Merged, Subtree, VRP);
929 }
930
931 void applyRange(Value *V, const ConstantRange &CR, ETNode *Subtree,
932 VRPSolver *VRP) {
933 assert(isCanonical(V, Subtree, VRP) && "Value not canonical.");
934
935 if (const APInt *I = CR.getSingleElement()) {
936 const Type *Ty = V->getType();
937 if (Ty->isInteger()) {
938 addToWorklist(V, ConstantInt::get(*I), ICmpInst::ICMP_EQ, VRP);
939 return;
940 } else if (const PointerType *PTy = dyn_cast(Ty)) {
941 assert(*I == 0 && "Pointer is null but not zero?");
942 addToWorklist(V, ConstantPointerNull::get(PTy),
931943 ICmpInst::ICMP_EQ, VRP);
932 else
933 update(New, Merged, Subtree);
944 return;
945 }
946 }
947
948 update(V, CR, Subtree);
934949 }
935950
936951 void addInequality(Value *V1, Value *V2, ETNode *Subtree, LatticeVal LV,
952967
953968 if (!CR1.isSingleElement()) {
954969 ConstantRange NewCR1 = CR1.intersectWith(create(LV, CR2));
955 if (NewCR1 != CR1) {
956 if (NewCR1.isSingleElement())
957 addToWorklist(V1, NewCR1.getSingleElement(),
958 ICmpInst::ICMP_EQ, VRP);
959 else
960 update(V1, NewCR1, Subtree);
961 }
970 if (NewCR1 != CR1)
971 applyRange(V1, NewCR1, Subtree, VRP);
962972 }
963973
964974 if (!CR2.isSingleElement()) {
965975 ConstantRange NewCR2 = CR2.intersectWith(create(reversePredicate(LV),
966976 CR1));
967 if (NewCR2 != CR2) {
968 if (NewCR2.isSingleElement())
969 addToWorklist(V2, NewCR2.getSingleElement(),
970 ICmpInst::ICMP_EQ, VRP);
971 else
972 update(V2, NewCR2, Subtree);
973 }
977 if (NewCR2 != CR2)
978 applyRange(V2, NewCR2, Subtree, VRP);
974979 }
975980 }
976981 };
18461851 }
18471852 };
18481853
1849 void ValueRanges::addToWorklist(Value *V, const APInt *I,
1854 void ValueRanges::addToWorklist(Value *V, Constant *C,
18501855 ICmpInst::Predicate Pred, VRPSolver *VRP) {
1851 VRP->add(V, ConstantInt::get(*I), Pred, VRP->TopInst);
1856 VRP->add(V, C, Pred, VRP->TopInst);
18521857 }
18531858
18541859 #ifndef NDEBUG