Skip to content

Commit

Permalink
Vectorize: Remove implicit ilist iterator conversions, NFC
Browse files Browse the repository at this point in the history
Besides the usual, I finally added an overload to
`BasicBlock::splitBasicBlock()` that accepts an `Instruction*` instead
of `BasicBlock::iterator`.  Someone can go back and remove this overload
later (after updating the callers I'm going to skip going forward), but
the most common call seems to be
`BB->splitBasicBlock(BB->getTerminator(), ...)` and I'm not sure it's
better to add `->getIterator()` to every one than have the overload.
It's pretty hard to get the usage wrong.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250745 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Oct 19, 2015
1 parent 3b75c04 commit f792618
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 85 deletions.
3 changes: 3 additions & 0 deletions include/llvm/IR/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class BasicBlock : public Value, // Basic blocks are data objects also
/// Also note that this doesn't preserve any passes. To split blocks while
/// keeping loop information consistent, use the SplitBlock utility function.
BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "");
BasicBlock *splitBasicBlock(Instruction *I, const Twine &BBName = "") {
return splitBasicBlock(I->getIterator(), BBName);
}

/// \brief Returns true if there are any uses of this basic block other than
/// direct branches, switches, etc. to it.
Expand Down
56 changes: 31 additions & 25 deletions lib/Transforms/Vectorize/BBVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,20 +1247,23 @@ namespace {
if (I == Start) IAfterStart = true;

bool IsSimpleLoadStore;
if (!isInstVectorizable(I, IsSimpleLoadStore)) continue;
if (!isInstVectorizable(&*I, IsSimpleLoadStore))
continue;

// Look for an instruction with which to pair instruction *I...
DenseSet<Value *> Users;
AliasSetTracker WriteSet(*AA);
if (I->mayWriteToMemory()) WriteSet.add(I);
if (I->mayWriteToMemory())
WriteSet.add(&*I);

bool JAfterStart = IAfterStart;
BasicBlock::iterator J = std::next(I);
for (unsigned ss = 0; J != E && ss <= Config.SearchLimit; ++J, ++ss) {
if (J == Start) JAfterStart = true;
if (&*J == Start)
JAfterStart = true;

// Determine if J uses I, if so, exit the loop.
bool UsesI = trackUsesOfI(Users, WriteSet, I, J, !Config.FastDep);
bool UsesI = trackUsesOfI(Users, WriteSet, &*I, &*J, !Config.FastDep);
if (Config.FastDep) {
// Note: For this heuristic to be effective, independent operations
// must tend to be intermixed. This is likely to be true from some
Expand All @@ -1277,25 +1280,26 @@ namespace {
// J does not use I, and comes before the first use of I, so it can be
// merged with I if the instructions are compatible.
int CostSavings, FixedOrder;
if (!areInstsCompatible(I, J, IsSimpleLoadStore, NonPow2Len,
CostSavings, FixedOrder)) continue;
if (!areInstsCompatible(&*I, &*J, IsSimpleLoadStore, NonPow2Len,
CostSavings, FixedOrder))
continue;

// J is a candidate for merging with I.
if (PairableInsts.empty() ||
PairableInsts[PairableInsts.size()-1] != I) {
PairableInsts.push_back(I);
PairableInsts[PairableInsts.size() - 1] != &*I) {
PairableInsts.push_back(&*I);
}

CandidatePairs[I].push_back(J);
CandidatePairs[&*I].push_back(&*J);
++TotalPairs;
if (TTI)
CandidatePairCostSavings.insert(ValuePairWithCost(ValuePair(I, J),
CostSavings));
CandidatePairCostSavings.insert(
ValuePairWithCost(ValuePair(&*I, &*J), CostSavings));

if (FixedOrder == 1)
FixedOrderPairs.insert(ValuePair(I, J));
FixedOrderPairs.insert(ValuePair(&*I, &*J));
else if (FixedOrder == -1)
FixedOrderPairs.insert(ValuePair(J, I));
FixedOrderPairs.insert(ValuePair(&*J, &*I));

// The next call to this function must start after the last instruction
// selected during this invocation.
Expand Down Expand Up @@ -1476,14 +1480,16 @@ namespace {
BasicBlock::iterator E = BB.end(), EL =
BasicBlock::iterator(cast<Instruction>(PairableInsts.back()));
for (BasicBlock::iterator I = BB.getFirstInsertionPt(); I != E; ++I) {
if (IsInPair.find(I) == IsInPair.end()) continue;
if (IsInPair.find(&*I) == IsInPair.end())
continue;

DenseSet<Value *> Users;
AliasSetTracker WriteSet(*AA);
if (I->mayWriteToMemory()) WriteSet.add(I);
if (I->mayWriteToMemory())
WriteSet.add(&*I);

for (BasicBlock::iterator J = std::next(I); J != E; ++J) {
(void) trackUsesOfI(Users, WriteSet, I, J);
(void)trackUsesOfI(Users, WriteSet, &*I, &*J);

if (J == EL)
break;
Expand All @@ -1492,7 +1498,7 @@ namespace {
for (DenseSet<Value *>::iterator U = Users.begin(), E = Users.end();
U != E; ++U) {
if (IsInPair.find(*U) == IsInPair.end()) continue;
PairableInstUsers.insert(ValuePair(I, *U));
PairableInstUsers.insert(ValuePair(&*I, *U));
}

if (I == EL)
Expand Down Expand Up @@ -2873,7 +2879,7 @@ namespace {
if (I->mayWriteToMemory()) WriteSet.add(I);

for (; cast<Instruction>(L) != J; ++L)
(void) trackUsesOfI(Users, WriteSet, I, L, true, &LoadMoveSetPairs);
(void)trackUsesOfI(Users, WriteSet, I, &*L, true, &LoadMoveSetPairs);

assert(cast<Instruction>(L) == J &&
"Tracking has not proceeded far enough to check for dependencies");
Expand All @@ -2895,9 +2901,9 @@ namespace {
if (I->mayWriteToMemory()) WriteSet.add(I);

for (; cast<Instruction>(L) != J;) {
if (trackUsesOfI(Users, WriteSet, I, L, true, &LoadMoveSetPairs)) {
if (trackUsesOfI(Users, WriteSet, I, &*L, true, &LoadMoveSetPairs)) {
// Move this instruction
Instruction *InstToMove = L; ++L;
Instruction *InstToMove = &*L++;

DEBUG(dbgs() << "BBV: moving: " << *InstToMove <<
" to after " << *InsertionPt << "\n");
Expand Down Expand Up @@ -2928,11 +2934,11 @@ namespace {
// Note: We cannot end the loop when we reach J because J could be moved
// farther down the use chain by another instruction pairing. Also, J
// could be before I if this is an inverted input.
for (BasicBlock::iterator E = BB.end(); cast<Instruction>(L) != E; ++L) {
if (trackUsesOfI(Users, WriteSet, I, L)) {
for (BasicBlock::iterator E = BB.end(); L != E; ++L) {
if (trackUsesOfI(Users, WriteSet, I, &*L)) {
if (L->mayReadFromMemory()) {
LoadMoveSet[L].push_back(I);
LoadMoveSetPairs.insert(ValuePair(L, I));
LoadMoveSet[&*L].push_back(I);
LoadMoveSetPairs.insert(ValuePair(&*L, I));
}
}
}
Expand Down Expand Up @@ -2995,7 +3001,7 @@ namespace {
DEBUG(dbgs() << "BBV: initial: \n" << BB << "\n");

for (BasicBlock::iterator PI = BB.getFirstInsertionPt(); PI != BB.end();) {
DenseMap<Value *, Value *>::iterator P = ChosenPairs.find(PI);
DenseMap<Value *, Value *>::iterator P = ChosenPairs.find(&*PI);
if (P == ChosenPairs.end()) {
++PI;
continue;
Expand Down
Loading

0 comments on commit f792618

Please sign in to comment.