[llvm-commits] [llvm] r157183 - in /llvm/trunk: include/llvm/Support/CRSBuilder.h lib/ExecutionEngine/Interpreter/Execution.cpp lib/VMCore/Verifier.cpp

Stepan Dyatkovskiy stpworld at narod.ru
Mon May 21 03:44:40 PDT 2012


Author: dyatkovskiy
Date: Mon May 21 05:44:40 2012
New Revision: 157183

URL: http://llvm.org/viewvc/llvm-project?rev=157183&view=rev
Log:
PR1255 (case ranges: work with ConstantRangesSet instead of ConstantInt) related changes for Execution and Verifier.


Modified:
    llvm/trunk/include/llvm/Support/CRSBuilder.h
    llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp
    llvm/trunk/lib/VMCore/Verifier.cpp

Modified: llvm/trunk/include/llvm/Support/CRSBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CRSBuilder.h?rev=157183&r1=157182&r2=157183&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CRSBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/CRSBuilder.h Mon May 21 05:44:40 2012
@@ -100,14 +100,16 @@
     Sorted = false;
   }
   
-  bool verify() {
+  bool verify(RangeIterator& errItem) {
     if (Items.empty())
       return true;
     sort();
     for (CaseItemIt i = Items.begin(), j = i+1, e = Items.end();
          j != e; i = j++) {
-      if (isIntersected(j, i) && j->second != i->second)
+      if (isIntersected(j, i) && j->second != i->second) {
+        errItem = j;
         return false;
+      }
     }
     return true;
   }
@@ -185,11 +187,14 @@
 
 template <class SuccessorClass>
 class CRSBuilderT : public CRSBuilderBase<SuccessorClass, false> {
+public:
   
   typedef typename CRSBuilderBase<SuccessorClass, false>::RangeTy RangeTy;
   typedef typename CRSBuilderBase<SuccessorClass, false>::RangeIterator
       RangeIterator;
   
+private:
+  
   typedef std::list<RangeTy> RangesCollection;
   typedef typename RangesCollection::iterator RangesCollectionIt;
   

Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp?rev=157183&r1=157182&r2=157183&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Interpreter/Execution.cpp Mon May 21 05:44:40 2012
@@ -651,10 +651,16 @@
   // Check to see if any of the cases match...
   BasicBlock *Dest = 0;
   for (SwitchInst::CaseIt i = I.case_begin(), e = I.case_end(); i != e; ++i) {
-    GenericValue CaseVal = getOperandValue(i.getCaseValue(), SF);
-    if (executeICMP_EQ(CondVal, CaseVal, ElTy).IntVal != 0) {
-      Dest = cast<BasicBlock>(i.getCaseSuccessor());
-      break;
+    ConstantRangesSet Case = i.getCaseValueEx();
+    for (unsigned n = 0, en = Case.getNumItems(); n != en; ++n) {
+      ConstantRangesSet::Range r = Case.getItem(n);
+      GenericValue Low = getOperandValue(r.Low, SF);
+      GenericValue High = getOperandValue(r.High, SF);
+      if (executeICMP_ULE(Low, CondVal, ElTy).IntVal != 0 &&
+          executeICMP_ULE(CondVal, High, ElTy).IntVal != 0) {
+        Dest = cast<BasicBlock>(i.getCaseSuccessor());
+        break;        
+      }
     }
   }
   if (!Dest) Dest = I.getDefaultDest();   // No cases matched: use default

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=157183&r1=157182&r2=157183&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Mon May 21 05:44:40 2012
@@ -804,14 +804,28 @@
   // Check to make sure that all of the constants in the switch instruction
   // have the same type as the switched-on value.
   Type *SwitchTy = SI.getCondition()->getType();
-  SmallPtrSet<ConstantInt*, 32> Constants;
+  CRSBuilder Builder;
+  std::map<ConstantRangesSet::Range, unsigned> RangeSetMap;
   for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end(); i != e; ++i) {
-    Assert1(i.getCaseValue()->getType() == SwitchTy,
-            "Switch constants must all be same type as switch value!", &SI);
-    Assert2(Constants.insert(i.getCaseValue()),
-            "Duplicate integer as switch case", &SI, i.getCaseValue());
+    ConstantRangesSet RS = i.getCaseValueEx();
+    for (unsigned ri = 0, rie = RS.getNumItems(); ri < rie; ++ri) {
+      ConstantRangesSet::Range r = RS.getItem(ri);
+      Assert1(r.Low->getType() == SwitchTy,
+              "Switch constants must all be same type as switch value!", &SI);
+      Assert1(r.High->getType() == SwitchTy,
+              "Switch constants must all be same type as switch value!", &SI);
+      Builder.add(r);
+      RangeSetMap[r] = i.getCaseIndex();
+    }
   }
-
+  
+  CRSBuilder::RangeIterator errItem;
+  if (!Builder.verify(errItem)) {
+    unsigned CaseIndex = RangeSetMap[errItem->first];
+    SwitchInst::CaseIt i(&SI, CaseIndex);
+    Assert2(false, "Duplicate integer as switch case", &SI, i.getCaseValueEx());
+  }
+  
   visitTerminatorInst(SI);
 }
 





More information about the llvm-commits mailing list