From: Stepan Dyatkovskiy Date: Mon, 21 May 2012 10:44:40 +0000 (+0000) Subject: PR1255 (case ranges: work with ConstantRangesSet instead of ConstantInt) related... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1c8f4b8c34a75e184ec40251225c2699efecedac;p=oota-llvm.git PR1255 (case ranges: work with ConstantRangesSet instead of ConstantInt) related changes for Execution and Verifier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157183 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/CRSBuilder.h b/include/llvm/Support/CRSBuilder.h index 1fd1683f713..56089319369 100644 --- a/include/llvm/Support/CRSBuilder.h +++ b/include/llvm/Support/CRSBuilder.h @@ -100,14 +100,16 @@ public: 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 @@ public: template class CRSBuilderT : public CRSBuilderBase { +public: typedef typename CRSBuilderBase::RangeTy RangeTy; typedef typename CRSBuilderBase::RangeIterator RangeIterator; +private: + typedef std::list RangesCollection; typedef typename RangesCollection::iterator RangesCollectionIt; diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index af47be9c5b5..298ce2c2b95 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -651,10 +651,16 @@ void Interpreter::visitSwitchInst(SwitchInst &I) { // 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(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(i.getCaseSuccessor()); + break; + } } } if (!Dest) Dest = I.getDefaultDest(); // No cases matched: use default diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 47baef3e29d..f11efff9f18 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -804,14 +804,28 @@ void Verifier::visitSwitchInst(SwitchInst &SI) { // 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 Constants; + CRSBuilder Builder; + std::map 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); }