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