diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Instructions.h | 20 | ||||
-rw-r--r-- | include/llvm/Support/IntegersSubset.h (renamed from include/llvm/Support/ConstantRangesSet.h) | 4 | ||||
-rw-r--r-- | include/llvm/Support/IntegersSubsetMapping.h (renamed from include/llvm/Support/CRSBuilder.h) | 112 |
3 files changed, 61 insertions, 75 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 3f67e26f73..89a5a307f2 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -20,8 +20,8 @@ #include "llvm/DerivedTypes.h" #include "llvm/Attributes.h" #include "llvm/CallingConv.h" -#include "llvm/Support/ConstantRangesSet.h" -#include "llvm/Support/CRSBuilder.h" +#include "llvm/Support/IntegersSubset.h" +#include "llvm/Support/IntegersSubsetMapping.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/ErrorHandling.h" @@ -2589,7 +2589,7 @@ public: /// Note: /// This action invalidates case_end(). Old case_end() iterator will /// point to the added case. - void addCase(ConstantRangesSet& OnVal, BasicBlock *Dest); + void addCase(IntegersSubset& OnVal, BasicBlock *Dest); /// removeCase - This method removes the specified case and its successor /// from the switch instruction. Note that this operation may reorder the @@ -2654,9 +2654,9 @@ public: /// @Deprecated ConstantIntTy *getCaseValue() { assert(Index < SI->getNumCases() && "Index out the number of cases."); - ConstantRangesSet CRS = + IntegersSubset CaseRanges = reinterpret_cast<Constant*>(SI->getOperand(2 + Index*2)); - ConstantRangesSet::Range R = CRS.getItem(0); + IntegersSubset::Range R = CaseRanges.getItem(0); // FIXME: Currently we work with ConstantInt based cases. // So return CaseValue as ConstantInt. @@ -2664,7 +2664,7 @@ public: } /// Resolves case value for current case. - ConstantRangesSet getCaseValueEx() { + IntegersSubset getCaseValueEx() { assert(Index < SI->getNumCases() && "Index out the number of cases."); return reinterpret_cast<Constant*>(SI->getOperand(2 + Index*2)); } @@ -2736,16 +2736,16 @@ public: /// @Deprecated. void setValue(ConstantInt *V) { assert(Index < SI->getNumCases() && "Index out the number of cases."); - CRSBuilder CB; + IntegersSubsetToBB Mapping; // FIXME: Currently we work with ConstantInt based cases. // So inititalize IntItem container directly from ConstantInt. - CB.add(IntItem::fromConstantInt(V)); + Mapping.add(IntItem::fromConstantInt(V)); SI->setOperand(2 + Index*2, - reinterpret_cast<Value*>((Constant*)CB.getCase())); + reinterpret_cast<Value*>((Constant*)Mapping.getCase())); } /// Sets the new value for current case. - void setValueEx(ConstantRangesSet& V) { + void setValueEx(IntegersSubset& V) { assert(Index < SI->getNumCases() && "Index out the number of cases."); SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V)); } diff --git a/include/llvm/Support/ConstantRangesSet.h b/include/llvm/Support/IntegersSubset.h index 109bd5b26e..894b104da9 100644 --- a/include/llvm/Support/ConstantRangesSet.h +++ b/include/llvm/Support/IntegersSubset.h @@ -223,14 +223,14 @@ struct IntRange { /// Note: It is assumed that "holder" is inherited from Constant object. /// ConstantRangesSet may be converted to and from Constant* pointer. /// -class ConstantRangesSet { +class IntegersSubset { Constant *Array; public: bool IsWide; // implicit - ConstantRangesSet(Constant *V) : Array(V) { + IntegersSubset(Constant *V) : Array(V) { ArrayType *ArrTy = cast<ArrayType>(Array->getType()); VectorType *VecTy = cast<VectorType>(ArrTy->getElementType()); IntegerType *IntTy = cast<IntegerType>(VecTy->getElementType()); diff --git a/include/llvm/Support/CRSBuilder.h b/include/llvm/Support/IntegersSubsetMapping.h index c5dfa9f3f1..eaa2f5be2f 100644 --- a/include/llvm/Support/CRSBuilder.h +++ b/include/llvm/Support/IntegersSubsetMapping.h @@ -19,7 +19,7 @@ #ifndef CRSBUILDER_H_ #define CRSBUILDER_H_ -#include "llvm/Support/ConstantRangesSet.h" +#include "llvm/Support/IntegersSubset.h" #include <list> #include <map> #include <vector> @@ -27,13 +27,13 @@ namespace llvm { template <class SuccessorClass> -class CRSBuilderBase { +class IntegersSubsetMapping { public: - typedef ConstantRangesSet::Range RangeTy; + typedef IntegersSubset::Range RangeTy; struct RangeEx : public RangeTy { - typedef ConstantRangesSet::Range RangeTy; + typedef IntegersSubset::Range RangeTy; RangeEx() : Weight(1) {} RangeEx(const RangeTy &R) : RangeTy(R.Low, R.High), Weight(1) {} RangeEx(const IntItem &C) : RangeTy(C), Weight(1) {} @@ -50,6 +50,12 @@ protected: typedef std::vector<Cluster> CaseItems; typedef typename CaseItems::iterator CaseItemIt; typedef typename CaseItems::const_iterator CaseItemConstIt; + + typedef std::list<RangeTy> RangesCollection; + typedef typename RangesCollection::iterator RangesCollectionIt; + + typedef std::map<SuccessorClass*, RangesCollection > CRSMap; + typedef typename CRSMap::iterator CRSMapIt; struct ClustersCmp { bool operator()(const Cluster &C1, const Cluster &C2) { @@ -82,6 +88,31 @@ protected: Sorted = true; } } + + IntegersSubset getCase(RangesCollection& Src) { + std::vector<Constant*> Elts; + Elts.reserve(Src.size()); + for (RangesCollectionIt i = Src.begin(), e = Src.end(); i != e; ++i) { + RangeTy &R = *i; + std::vector<Constant*> r; + if (R.isSingleNumber()) { + r.reserve(2); + // FIXME: Since currently we have ConstantInt based numbers + // use hack-conversion of IntItem to ConstantInt + r.push_back(R.Low.toConstantInt()); + r.push_back(R.High.toConstantInt()); + } else { + r.reserve(1); + r.push_back(R.Low.toConstantInt()); + } + Constant *CV = ConstantVector::get(r); + Elts.push_back(CV); + } + ArrayType *ArrTy = + ArrayType::get(Elts.front()->getType(), (uint64_t)Elts.size()); + Constant *Array = ConstantArray::get(ArrTy, Elts); + return IntegersSubset(Array); + } public: @@ -91,7 +122,10 @@ public: // factory. typedef CaseItemIt RangeIterator; - CRSBuilderBase() { + typedef std::pair<SuccessorClass*, IntegersSubset> Case; + typedef std::list<Case> Cases; + + IntegersSubsetMapping() { Items.reserve(32); Sorted = false; } @@ -164,7 +198,7 @@ public: /// Adds all ranges and values from given ranges set to the current /// CRSBuilder object. - void add(const ConstantRangesSet &CRS, SuccessorClass *S = 0) { + void add(const IntegersSubset &CRS, SuccessorClass *S = 0) { for (unsigned i = 0, e = CRS.getNumItems(); i < e; ++i) { RangeTy R = CRS.getItem(i); add(R, S); @@ -174,59 +208,6 @@ public: /// Removes items from set. void removeItem(RangeIterator i) { Items.erase(i); } - /// Returns true if there is no ranges and values inside. - bool empty() const { return Items.empty(); } - - RangeIterator begin() { return Items.begin(); } - RangeIterator end() { return Items.end(); } -}; - -template <class SuccessorClass> -class CRSBuilderT : public CRSBuilderBase<SuccessorClass> { -public: - - typedef typename CRSBuilderBase<SuccessorClass>::RangeTy RangeTy; - typedef typename CRSBuilderBase<SuccessorClass>::RangeIterator - RangeIterator; - -private: - - typedef std::list<RangeTy> RangesCollection; - typedef typename RangesCollection::iterator RangesCollectionIt; - - typedef std::map<SuccessorClass*, RangesCollection > CRSMap; - typedef typename CRSMap::iterator CRSMapIt; - - ConstantRangesSet getCase(RangesCollection& Src) { - std::vector<Constant*> Elts; - Elts.reserve(Src.size()); - for (RangesCollectionIt i = Src.begin(), e = Src.end(); i != e; ++i) { - RangeTy &R = *i; - std::vector<Constant*> r; - if (R.isSingleNumber()) { - r.reserve(2); - // FIXME: Since currently we have ConstantInt based numbers - // use hack-conversion of IntItem to ConstantInt - r.push_back(R.Low.toConstantInt()); - r.push_back(R.High.toConstantInt()); - } else { - r.reserve(1); - r.push_back(R.Low.toConstantInt()); - } - Constant *CV = ConstantVector::get(r); - Elts.push_back(CV); - } - ArrayType *ArrTy = - ArrayType::get(Elts.front()->getType(), (uint64_t)Elts.size()); - Constant *Array = ConstantArray::get(ArrTy, Elts); - return ConstantRangesSet(Array); - } - -public: - - typedef std::pair<SuccessorClass*, ConstantRangesSet> Case; - typedef std::list<Case> Cases; - /// Builds the finalized case objects. void getCases(Cases& TheCases) { CRSMap TheCRSMap; @@ -238,17 +219,22 @@ public: /// Builds the finalized case objects ignoring successor values, as though /// all ranges belongs to the same successor. - ConstantRangesSet getCase() { + IntegersSubset getCase() { RangesCollection Ranges; for (RangeIterator i = this->begin(); i != this->end(); ++i) Ranges.push_back(i->first); return getCase(Ranges); - } + } + + /// Returns true if there is no ranges and values inside. + bool empty() const { return Items.empty(); } + + RangeIterator begin() { return Items.begin(); } + RangeIterator end() { return Items.end(); } }; class BasicBlock; -typedef CRSBuilderT<BasicBlock> CRSBuilder; -typedef CRSBuilderBase<BasicBlock> CRSBuilderConst; +typedef IntegersSubsetMapping<BasicBlock> IntegersSubsetToBB; } |