1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Part of r159527. Splitted into series of patches and gone with fixed PR13256:

IntegersSubsetMapping
  - Replaced type of Items field from std::list with std::map. In neares future I'll test it with DenseMap and do the correspond replacement
    if possible.

llvm-svn: 159659
This commit is contained in:
Stepan Dyatkovskiy 2012-07-03 13:46:45 +00:00
parent 037528232b
commit a646b05bfe
3 changed files with 18 additions and 42 deletions

View File

@ -58,22 +58,15 @@ public:
protected: protected:
typedef std::list<Cluster> CaseItems; typedef std::map<RangeEx, SuccessorClass*> CaseItems;
typedef typename CaseItems::iterator CaseItemIt; typedef typename CaseItems::iterator CaseItemIt;
typedef typename CaseItems::const_iterator CaseItemConstIt; typedef typename CaseItems::const_iterator CaseItemConstIt;
// TODO: Change unclean CRS prefixes to SubsetMap for example. // TODO: Change unclean CRS prefixes to SubsetMap for example.
typedef std::map<SuccessorClass*, RangesCollection > CRSMap; typedef std::map<SuccessorClass*, RangesCollection > CRSMap;
typedef typename CRSMap::iterator CRSMapIt; typedef typename CRSMap::iterator CRSMapIt;
struct ClustersCmp {
bool operator()(const Cluster &C1, const Cluster &C2) {
return C1.first < C2.first;
}
};
CaseItems Items; CaseItems Items;
bool Sorted;
bool SingleNumbersOnly; bool SingleNumbersOnly;
bool isIntersected(CaseItemIt& LItem, CaseItemIt& RItem) { bool isIntersected(CaseItemIt& LItem, CaseItemIt& RItem) {
@ -92,18 +85,6 @@ protected:
return LItem->first.getHigh() >= RLow; return LItem->first.getHigh() >= RLow;
} }
void sort() {
if (!Sorted) {
std::vector<Cluster> clustersVector;
clustersVector.reserve(Items.size());
clustersVector.insert(clustersVector.begin(), Items.begin(), Items.end());
std::sort(clustersVector.begin(), clustersVector.end(), ClustersCmp());
Items.clear();
Items.insert(Items.begin(), clustersVector.begin(), clustersVector.end());
Sorted = true;
}
}
enum DiffProcessState { enum DiffProcessState {
L_OPENED, L_OPENED,
INTERSECT_OPENED, INTERSECT_OPENED,
@ -300,15 +281,11 @@ public:
typedef std::pair<SuccessorClass*, IntegersSubsetTy> Case; typedef std::pair<SuccessorClass*, IntegersSubsetTy> Case;
typedef std::list<Case> Cases; typedef std::list<Case> Cases;
IntegersSubsetMapping() { IntegersSubsetMapping() : SingleNumbersOnly(true) {}
Sorted = false;
SingleNumbersOnly = true;
}
bool verify(RangeIterator& errItem) { bool verify(RangeIterator& errItem) {
if (Items.empty()) if (Items.empty())
return true; return true;
sort();
for (CaseItemIt j = Items.begin(), i = j++, e = Items.end(); for (CaseItemIt j = Items.begin(), i = j++, e = Items.end();
j != e; i = j++) { j != e; i = j++) {
if (isIntersected(i, j) && i->second != j->second) { if (isIntersected(i, j) && i->second != j->second) {
@ -318,11 +295,10 @@ public:
} }
return true; return true;
} }
void optimize() { void optimize() {
if (Items.size() < 2) if (Items.size() < 2)
return; return;
sort();
CaseItems OldItems = Items; CaseItems OldItems = Items;
Items.clear(); Items.clear();
const IntTy *Low = &OldItems.begin()->first.getLow(); const IntTy *Low = &OldItems.begin()->first.getLow();
@ -347,8 +323,6 @@ public:
} }
RangeEx R(*Low, *High, Weight); RangeEx R(*Low, *High, Weight);
add(R, Successor); add(R, Successor);
// We recollected the Items, but we kept it sorted.
Sorted = true;
} }
/// Adds a constant value. /// Adds a constant value.
@ -367,7 +341,7 @@ public:
add(REx, S); add(REx, S);
} }
void add(const RangeEx &R, SuccessorClass *S = 0) { void add(const RangeEx &R, SuccessorClass *S = 0) {
Items.push_back(std::make_pair(R, S)); Items.insert(std::make_pair(R, S));
if (!R.isSingleNumber()) if (!R.isSingleNumber())
SingleNumbersOnly = false; SingleNumbersOnly = false;
} }
@ -382,7 +356,7 @@ public:
} }
void add(self& RHS) { void add(self& RHS) {
Items.insert(Items.end(), RHS.Items.begin(), RHS.Items.end()); Items.insert(RHS.Items.begin(), RHS.Items.end());
if (!RHS.SingleNumbersOnly) if (!RHS.SingleNumbersOnly)
SingleNumbersOnly = false; SingleNumbersOnly = false;
} }

View File

@ -2450,22 +2450,23 @@ size_t SelectionDAGBuilder::Clusterify(CaseVector& Cases,
size_t numCmps = 0; size_t numCmps = 0;
for (Clusterifier::RangeIterator i = TheClusterifier.begin(), for (Clusterifier::RangeIterator i = TheClusterifier.begin(),
e = TheClusterifier.end(); i != e; ++i, ++numCmps) { e = TheClusterifier.end(); i != e; ++i, ++numCmps) {
Clusterifier::Cluster &C = *i; const Clusterifier::RangeEx &R = i->first;
MachineBasicBlock *MBB = i->second;
unsigned W = 0; unsigned W = 0;
if (BPI) { if (BPI) {
W = BPI->getEdgeWeight(SI.getParent(), C.second->getBasicBlock()); W = BPI->getEdgeWeight(SI.getParent(), MBB->getBasicBlock());
if (!W) if (!W)
W = 16; W = 16;
W *= C.first.Weight; W *= R.Weight;
BPI->setEdgeWeight(SI.getParent(), C.second->getBasicBlock(), W); BPI->setEdgeWeight(SI.getParent(), MBB->getBasicBlock(), W);
} }
// FIXME: Currently work with ConstantInt based numbers. // FIXME: Currently work with ConstantInt based numbers.
// Changing it to APInt based is a pretty heavy for this commit. // Changing it to APInt based is a pretty heavy for this commit.
Cases.push_back(Case(C.first.getLow().toConstantInt(), Cases.push_back(Case(R.getLow().toConstantInt(),
C.first.getHigh().toConstantInt(), C.second, W)); R.getHigh().toConstantInt(), MBB, W));
if (C.first.getLow() != C.first.getHigh()) if (R.getLow() != R.getHigh())
// A range counts double, since it requires two compares. // A range counts double, since it requires two compares.
++numCmps; ++numCmps;
} }

View File

@ -238,13 +238,14 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) {
size_t numCmps = 0; size_t numCmps = 0;
for (IntegersSubsetToBB::RangeIterator i = TheClusterifier.begin(), for (IntegersSubsetToBB::RangeIterator i = TheClusterifier.begin(),
e = TheClusterifier.end(); i != e; ++i, ++numCmps) { e = TheClusterifier.end(); i != e; ++i, ++numCmps) {
IntegersSubsetToBB::Cluster &C = *i; const IntegersSubsetToBB::RangeTy &R = i->first;
BasicBlock *S = i->second;
// FIXME: Currently work with ConstantInt based numbers. // FIXME: Currently work with ConstantInt based numbers.
// Changing it to APInt based is a pretty heavy for this commit. // Changing it to APInt based is a pretty heavy for this commit.
Cases.push_back(CaseRange(C.first.getLow().toConstantInt(), Cases.push_back(CaseRange(R.getLow().toConstantInt(),
C.first.getHigh().toConstantInt(), C.second)); R.getHigh().toConstantInt(), S));
if (C.first.isSingleNumber()) if (R.isSingleNumber())
// A range counts double, since it requires two compares. // A range counts double, since it requires two compares.
++numCmps; ++numCmps;
} }