<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 21, 2015 at 11:32 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Thu May 21 13:32:07 2015<br>
New Revision: 237930<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D237930-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=0zGyubp5DWthcljEpKuRrzJRiJPF2MLYfbU1A6SV570&s=KwRvjMpKd7hc_0bbHbc-OmtF6Q7v8SUD1OoWRhphhww&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237930&view=rev</a><br>
Log:<br>
[LoopDistribute] Remove a layer of pointer indirection.<br>
<br>
Just store InstPartitions directly into the std::list. No functional change<br>
intended.<br></blockquote><div><br>Chance of using std::forward_list? I know it's a bit awkward in some ways, but shaves an extra pointer off, of course.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_Scalar_LoopDistribute.cpp-3Frev-3D237930-26r1-3D237929-26r2-3D237930-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=0zGyubp5DWthcljEpKuRrzJRiJPF2MLYfbU1A6SV570&s=jhd83ovRoNu5qcTC30A6-2KoKHQy5bLlCQ_7Ojje5Ns&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp?rev=237930&r1=237929&r2=237930&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp Thu May 21 13:32:07 2015<br>
@@ -234,7 +234,7 @@ public:<br>
}<br>
}<br>
<br>
- void print() {<br>
+ void print() const {<br>
if (DepCycle)<br>
dbgs() << " (cycle)\n";<br>
for (auto *I : Set)<br>
@@ -287,11 +287,10 @@ public:<br>
/// contain cycles. Otherwise start a new partition for it.<br>
void addToCyclicPartition(Instruction *Inst) {<br>
// If the current partition is non-cyclic. Start a new one.<br>
- if (PartitionContainer.empty() || !PartitionContainer.back()->hasDepCycle())<br>
- PartitionContainer.push_back(<br>
- llvm::make_unique<InstPartition>(Inst, L, true));<br>
+ if (PartitionContainer.empty() || !PartitionContainer.back().hasDepCycle())<br>
+ PartitionContainer.emplace_back(Inst, L, /*DepCycle=*/true);<br>
else<br>
- PartitionContainer.back()->add(Inst);<br>
+ PartitionContainer.back().add(Inst);<br>
}<br>
<br>
/// \brief Adds \p Inst into a partition that is not marked to contain<br>
@@ -300,7 +299,7 @@ public:<br>
// Initially we isolate memory instructions into as many partitions as<br>
// possible, then later we may merge them back together.<br>
void addToNewNonCyclicPartition(Instruction *Inst) {<br>
- PartitionContainer.push_back(llvm::make_unique<InstPartition>(Inst, L));<br>
+ PartitionContainer.emplace_back(Inst, L);<br>
}<br>
<br>
/// \brief Merges adjacent non-cyclic partitions.<br>
@@ -360,7 +359,7 @@ public:<br>
for (PartitionContainerT::iterator I = PartitionContainer.begin(),<br>
E = PartitionContainer.end();<br>
I != E; ++I) {<br>
- auto *PartI = I->get();<br>
+ auto *PartI = &*I;<br>
<br>
// If a load occurs in two partitions PartI and PartJ, merge all<br>
// partitions (PartI, PartJ] into PartI.<br>
@@ -379,8 +378,8 @@ public:<br>
auto PartJ = I;<br>
do {<br>
--PartJ;<br>
- ToBeMerged.unionSets(PartI, PartJ->get());<br>
- } while (PartJ->get() != LoadToPart->second);<br>
+ ToBeMerged.unionSets(PartI, &*PartJ);<br>
+ } while (&*PartJ != LoadToPart->second);<br>
}<br>
}<br>
}<br>
@@ -402,13 +401,8 @@ public:<br>
}<br>
<br>
// Remove the empty partitions.<br>
- for (PartitionContainerT::iterator PartI = PartitionContainer.begin(),<br>
- E = PartitionContainer.end();<br>
- PartI != E;)<br>
- if ((*PartI)->empty())<br>
- PartI = PartitionContainer.erase(PartI);<br>
- else<br>
- ++PartI;<br>
+ PartitionContainer.remove_if(<br>
+ [](const InstPartition &P) { return P.empty(); });<br>
<br>
return true;<br>
}<br>
@@ -417,8 +411,8 @@ public:<br>
/// instruction is duplicated across multiple partitions, set the entry to -1.<br>
void setupPartitionIdOnInstructions() {<br>
int PartitionID = 0;<br>
- for (auto &PartitionPtr : PartitionContainer) {<br>
- for (Instruction *Inst : *PartitionPtr) {<br>
+ for (const auto &Partition : PartitionContainer) {<br>
+ for (Instruction *Inst : Partition) {<br>
bool NewElt;<br>
InstToPartitionIdT::iterator Iter;<br>
<br>
@@ -435,7 +429,7 @@ public:<br>
/// instructions require.<br>
void populateUsedSet() {<br>
for (auto &P : PartitionContainer)<br>
- P->populateUsedSet();<br>
+ P.populateUsedSet();<br>
}<br>
<br>
/// \brief This performs the main chunk of the work of cloning the loops for<br>
@@ -461,10 +455,10 @@ public:<br>
// update PH to point to the newly added preheader.<br>
BasicBlock *TopPH = OrigPH;<br>
unsigned Index = getSize() - 1;<br>
- for (auto I = std::next(PartitionContainer.crbegin()),<br>
- E = PartitionContainer.crend();<br>
+ for (auto I = std::next(PartitionContainer.rbegin()),<br>
+ E = PartitionContainer.rend();<br>
I != E; ++I, --Index, TopPH = NewLoop->getLoopPreheader()) {<br>
- auto &Part = *I;<br>
+ auto *Part = &*I;<br>
<br>
NewLoop = Part->cloneLoopWithPreheader(TopPH, Pred, Index, LI, DT);<br>
<br>
@@ -481,14 +475,14 @@ public:<br>
E = PartitionContainer.cend();<br>
Next != E; ++Curr, ++Next)<br>
DT->changeImmediateDominator(<br>
- (*Next)->getDistributedLoop()->getLoopPreheader(),<br>
- (*Curr)->getDistributedLoop()->getExitingBlock());<br>
+ Next->getDistributedLoop()->getLoopPreheader(),<br>
+ Curr->getDistributedLoop()->getExitingBlock());<br>
}<br>
<br>
/// \brief Removes the dead instructions from the cloned loops.<br>
void removeUnusedInsts() {<br>
- for (auto &PartitionPtr : PartitionContainer)<br>
- PartitionPtr->removeUnusedInsts();<br>
+ for (auto &Partition : PartitionContainer)<br>
+ Partition.removeUnusedInsts();<br>
}<br>
<br>
/// \brief For each memory pointer, it computes the partitionId the pointer is<br>
@@ -532,9 +526,9 @@ public:<br>
<br>
void print(raw_ostream &OS) const {<br>
unsigned Index = 0;<br>
- for (auto &P : PartitionContainer) {<br>
- OS << "Partition " << Index++ << " (" << P.get() << "):\n";<br>
- P->print();<br>
+ for (const auto &P : PartitionContainer) {<br>
+ OS << "Partition " << Index++ << " (" << &P << "):\n";<br>
+ P.print();<br>
}<br>
}<br>
<br>
@@ -550,14 +544,14 @@ public:<br>
<br>
void printBlocks() const {<br>
unsigned Index = 0;<br>
- for (auto &P : PartitionContainer) {<br>
- dbgs() << "\nPartition " << Index++ << " (" << P.get() << "):\n";<br>
- P->printBlocks();<br>
+ for (const auto &P : PartitionContainer) {<br>
+ dbgs() << "\nPartition " << Index++ << " (" << &P << "):\n";<br>
+ P.printBlocks();<br>
}<br>
}<br>
<br>
private:<br>
- typedef std::list<std::unique_ptr<InstPartition>> PartitionContainerT;<br>
+ typedef std::list<InstPartition> PartitionContainerT;<br>
<br>
/// \brief List of partitions.<br>
PartitionContainerT PartitionContainer;<br>
@@ -576,12 +570,12 @@ private:<br>
void mergeAdjacentPartitionsIf(UnaryPredicate Predicate) {<br>
InstPartition *PrevMatch = nullptr;<br>
for (auto I = PartitionContainer.begin(); I != PartitionContainer.end();) {<br>
- auto DoesMatch = Predicate(I->get());<br>
+ auto DoesMatch = Predicate(&*I);<br>
if (PrevMatch == nullptr && DoesMatch) {<br>
- PrevMatch = I->get();<br>
+ PrevMatch = &*I;<br>
++I;<br>
} else if (PrevMatch != nullptr && DoesMatch) {<br>
- (*I)->moveTo(*PrevMatch);<br>
+ I->moveTo(*PrevMatch);<br>
I = PartitionContainer.erase(I);<br>
} else {<br>
PrevMatch = nullptr;<br>
@@ -616,9 +610,7 @@ public:<br>
MemoryInstructionDependences(<br>
const SmallVectorImpl<Instruction *> &Instructions,<br>
const SmallVectorImpl<Dependence> &InterestingDependences) {<br>
- std::transform(Instructions.begin(), Instructions.end(),<br>
- std::back_inserter(Accesses),<br>
- [](Instruction *Inst) { return Entry(Inst); });<br>
+ Accesses.append(Instructions.begin(), Instructions.end());<br>
<br>
DEBUG(dbgs() << "Backward dependences:\n");<br>
for (auto &Dep : InterestingDependences)<br>
@@ -710,11 +702,10 @@ public:<br>
for (auto *Inst : DefsUsedOutside) {<br>
auto *NonDistInst = cast<Instruction>(VMap[Inst]);<br>
PHINode *PN;<br>
- BasicBlock::iterator I;<br>
<br>
// First see if we have a single-operand PHI with the value defined by the<br>
// original loop.<br>
- for (I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) {<br>
+ for (auto I = PHIBlock->begin(); (PN = dyn_cast<PHINode>(I)); ++I) {<br>
assert(PN->getNumOperands() == 1 &&<br>
"Exit block should only have on predecessor");<br>
if (PN->getIncomingValue(0) == Inst)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>