[LoopDistribute] Remove a layer of pointer indirection.

Just store InstPartitions directly into the std::list. No functional change
intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237930 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2015-05-21 18:32:07 +00:00
parent 430cdabf46
commit 4c919af335

View File

@ -234,7 +234,7 @@ public:
} }
} }
void print() { void print() const {
if (DepCycle) if (DepCycle)
dbgs() << " (cycle)\n"; dbgs() << " (cycle)\n";
for (auto *I : Set) for (auto *I : Set)
@ -287,11 +287,10 @@ public:
/// contain cycles. Otherwise start a new partition for it. /// contain cycles. Otherwise start a new partition for it.
void addToCyclicPartition(Instruction *Inst) { void addToCyclicPartition(Instruction *Inst) {
// If the current partition is non-cyclic. Start a new one. // If the current partition is non-cyclic. Start a new one.
if (PartitionContainer.empty() || !PartitionContainer.back()->hasDepCycle()) if (PartitionContainer.empty() || !PartitionContainer.back().hasDepCycle())
PartitionContainer.push_back( PartitionContainer.emplace_back(Inst, L, /*DepCycle=*/true);
llvm::make_unique<InstPartition>(Inst, L, true));
else else
PartitionContainer.back()->add(Inst); PartitionContainer.back().add(Inst);
} }
/// \brief Adds \p Inst into a partition that is not marked to contain /// \brief Adds \p Inst into a partition that is not marked to contain
@ -300,7 +299,7 @@ public:
// Initially we isolate memory instructions into as many partitions as // Initially we isolate memory instructions into as many partitions as
// possible, then later we may merge them back together. // possible, then later we may merge them back together.
void addToNewNonCyclicPartition(Instruction *Inst) { void addToNewNonCyclicPartition(Instruction *Inst) {
PartitionContainer.push_back(llvm::make_unique<InstPartition>(Inst, L)); PartitionContainer.emplace_back(Inst, L);
} }
/// \brief Merges adjacent non-cyclic partitions. /// \brief Merges adjacent non-cyclic partitions.
@ -360,7 +359,7 @@ public:
for (PartitionContainerT::iterator I = PartitionContainer.begin(), for (PartitionContainerT::iterator I = PartitionContainer.begin(),
E = PartitionContainer.end(); E = PartitionContainer.end();
I != E; ++I) { I != E; ++I) {
auto *PartI = I->get(); auto *PartI = &*I;
// If a load occurs in two partitions PartI and PartJ, merge all // If a load occurs in two partitions PartI and PartJ, merge all
// partitions (PartI, PartJ] into PartI. // partitions (PartI, PartJ] into PartI.
@ -379,8 +378,8 @@ public:
auto PartJ = I; auto PartJ = I;
do { do {
--PartJ; --PartJ;
ToBeMerged.unionSets(PartI, PartJ->get()); ToBeMerged.unionSets(PartI, &*PartJ);
} while (PartJ->get() != LoadToPart->second); } while (&*PartJ != LoadToPart->second);
} }
} }
} }
@ -402,13 +401,8 @@ public:
} }
// Remove the empty partitions. // Remove the empty partitions.
for (PartitionContainerT::iterator PartI = PartitionContainer.begin(), PartitionContainer.remove_if(
E = PartitionContainer.end(); [](const InstPartition &P) { return P.empty(); });
PartI != E;)
if ((*PartI)->empty())
PartI = PartitionContainer.erase(PartI);
else
++PartI;
return true; return true;
} }
@ -417,8 +411,8 @@ public:
/// instruction is duplicated across multiple partitions, set the entry to -1. /// instruction is duplicated across multiple partitions, set the entry to -1.
void setupPartitionIdOnInstructions() { void setupPartitionIdOnInstructions() {
int PartitionID = 0; int PartitionID = 0;
for (auto &PartitionPtr : PartitionContainer) { for (const auto &Partition : PartitionContainer) {
for (Instruction *Inst : *PartitionPtr) { for (Instruction *Inst : Partition) {
bool NewElt; bool NewElt;
InstToPartitionIdT::iterator Iter; InstToPartitionIdT::iterator Iter;
@ -435,7 +429,7 @@ public:
/// instructions require. /// instructions require.
void populateUsedSet() { void populateUsedSet() {
for (auto &P : PartitionContainer) for (auto &P : PartitionContainer)
P->populateUsedSet(); P.populateUsedSet();
} }
/// \brief This performs the main chunk of the work of cloning the loops for /// \brief This performs the main chunk of the work of cloning the loops for
@ -461,10 +455,10 @@ public:
// update PH to point to the newly added preheader. // update PH to point to the newly added preheader.
BasicBlock *TopPH = OrigPH; BasicBlock *TopPH = OrigPH;
unsigned Index = getSize() - 1; unsigned Index = getSize() - 1;
for (auto I = std::next(PartitionContainer.crbegin()), for (auto I = std::next(PartitionContainer.rbegin()),
E = PartitionContainer.crend(); E = PartitionContainer.rend();
I != E; ++I, --Index, TopPH = NewLoop->getLoopPreheader()) { I != E; ++I, --Index, TopPH = NewLoop->getLoopPreheader()) {
auto &Part = *I; auto *Part = &*I;
NewLoop = Part->cloneLoopWithPreheader(TopPH, Pred, Index, LI, DT); NewLoop = Part->cloneLoopWithPreheader(TopPH, Pred, Index, LI, DT);
@ -481,14 +475,14 @@ public:
E = PartitionContainer.cend(); E = PartitionContainer.cend();
Next != E; ++Curr, ++Next) Next != E; ++Curr, ++Next)
DT->changeImmediateDominator( DT->changeImmediateDominator(
(*Next)->getDistributedLoop()->getLoopPreheader(), Next->getDistributedLoop()->getLoopPreheader(),
(*Curr)->getDistributedLoop()->getExitingBlock()); Curr->getDistributedLoop()->getExitingBlock());
} }
/// \brief Removes the dead instructions from the cloned loops. /// \brief Removes the dead instructions from the cloned loops.
void removeUnusedInsts() { void removeUnusedInsts() {
for (auto &PartitionPtr : PartitionContainer) for (auto &Partition : PartitionContainer)
PartitionPtr->removeUnusedInsts(); Partition.removeUnusedInsts();
} }
/// \brief For each memory pointer, it computes the partitionId the pointer is /// \brief For each memory pointer, it computes the partitionId the pointer is
@ -532,9 +526,9 @@ public:
void print(raw_ostream &OS) const { void print(raw_ostream &OS) const {
unsigned Index = 0; unsigned Index = 0;
for (auto &P : PartitionContainer) { for (const auto &P : PartitionContainer) {
OS << "Partition " << Index++ << " (" << P.get() << "):\n"; OS << "Partition " << Index++ << " (" << &P << "):\n";
P->print(); P.print();
} }
} }
@ -550,14 +544,14 @@ public:
void printBlocks() const { void printBlocks() const {
unsigned Index = 0; unsigned Index = 0;
for (auto &P : PartitionContainer) { for (const auto &P : PartitionContainer) {
dbgs() << "\nPartition " << Index++ << " (" << P.get() << "):\n"; dbgs() << "\nPartition " << Index++ << " (" << &P << "):\n";
P->printBlocks(); P.printBlocks();
} }
} }
private: private:
typedef std::list<std::unique_ptr<InstPartition>> PartitionContainerT; typedef std::list<InstPartition> PartitionContainerT;
/// \brief List of partitions. /// \brief List of partitions.
PartitionContainerT PartitionContainer; PartitionContainerT PartitionContainer;
@ -576,12 +570,12 @@ private:
void mergeAdjacentPartitionsIf(UnaryPredicate Predicate) { void mergeAdjacentPartitionsIf(UnaryPredicate Predicate) {
InstPartition *PrevMatch = nullptr; InstPartition *PrevMatch = nullptr;
for (auto I = PartitionContainer.begin(); I != PartitionContainer.end();) { for (auto I = PartitionContainer.begin(); I != PartitionContainer.end();) {
auto DoesMatch = Predicate(I->get()); auto DoesMatch = Predicate(&*I);
if (PrevMatch == nullptr && DoesMatch) { if (PrevMatch == nullptr && DoesMatch) {
PrevMatch = I->get(); PrevMatch = &*I;
++I; ++I;
} else if (PrevMatch != nullptr && DoesMatch) { } else if (PrevMatch != nullptr && DoesMatch) {
(*I)->moveTo(*PrevMatch); I->moveTo(*PrevMatch);
I = PartitionContainer.erase(I); I = PartitionContainer.erase(I);
} else { } else {
PrevMatch = nullptr; PrevMatch = nullptr;
@ -616,9 +610,7 @@ public:
MemoryInstructionDependences( MemoryInstructionDependences(
const SmallVectorImpl<Instruction *> &Instructions, const SmallVectorImpl<Instruction *> &Instructions,
const SmallVectorImpl<Dependence> &InterestingDependences) { const SmallVectorImpl<Dependence> &InterestingDependences) {
std::transform(Instructions.begin(), Instructions.end(), Accesses.append(Instructions.begin(), Instructions.end());
std::back_inserter(Accesses),
[](Instruction *Inst) { return Entry(Inst); });
DEBUG(dbgs() << "Backward dependences:\n"); DEBUG(dbgs() << "Backward dependences:\n");
for (auto &Dep : InterestingDependences) for (auto &Dep : InterestingDependences)
@ -710,11 +702,10 @@ public:
for (auto *Inst : DefsUsedOutside) { for (auto *Inst : DefsUsedOutside) {
auto *NonDistInst = cast<Instruction>(VMap[Inst]); auto *NonDistInst = cast<Instruction>(VMap[Inst]);
PHINode *PN; PHINode *PN;
BasicBlock::iterator I;
// First see if we have a single-operand PHI with the value defined by the // First see if we have a single-operand PHI with the value defined by the
// original loop. // original loop.
for (I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) { for (auto I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) {
assert(PN->getNumOperands() == 1 && assert(PN->getNumOperands() == 1 &&
"Exit block should only have on predecessor"); "Exit block should only have on predecessor");
if (PN->getIncomingValue(0) == Inst) if (PN->getIncomingValue(0) == Inst)