[LoopDist] Improve variable names and comments in LoopVersioning class, NFC

As with the previous patch, the goal is to turn the class into a general
loop-versioning class.  This patch removes any references to loop
distribution.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240352 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adam Nemet
2015-06-22 22:59:40 +00:00
parent 0c17f95006
commit 08056a49f1
3 changed files with 36 additions and 32 deletions

View File

@ -635,10 +635,11 @@ public:
LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI,
DominatorTree *DT, DominatorTree *DT,
const SmallVector<int, 8> *PtrToPartition = nullptr) const SmallVector<int, 8> *PtrToPartition = nullptr)
: OrigLoop(L), NonDistributedLoop(nullptr), : VersionedLoop(L), NonVersionedLoop(nullptr),
PtrToPartition(PtrToPartition), LAI(LAI), LI(LI), DT(DT) {} PtrToPartition(PtrToPartition), LAI(LAI), LI(LI), DT(DT) {}
/// \brief Returns true if we need memchecks to distribute the loop. /// \brief Returns true if we need memchecks to disambiguate may-aliasing
/// accesses.
bool needsRuntimeChecks() const { bool needsRuntimeChecks() const {
return LAI.getRuntimePointerCheck()->needsAnyChecking(PtrToPartition); return LAI.getRuntimePointerCheck()->needsAnyChecking(PtrToPartition);
} }
@ -649,49 +650,51 @@ public:
Instruction *FirstCheckInst; Instruction *FirstCheckInst;
Instruction *MemRuntimeCheck; Instruction *MemRuntimeCheck;
// Add the memcheck in the original preheader (this is empty initially). // Add the memcheck in the original preheader (this is empty initially).
BasicBlock *MemCheckBB = OrigLoop->getLoopPreheader(); BasicBlock *MemCheckBB = VersionedLoop->getLoopPreheader();
std::tie(FirstCheckInst, MemRuntimeCheck) = std::tie(FirstCheckInst, MemRuntimeCheck) =
LAI.addRuntimeCheck(MemCheckBB->getTerminator(), PtrToPartition); LAI.addRuntimeCheck(MemCheckBB->getTerminator(), PtrToPartition);
assert(MemRuntimeCheck && "called even though needsAnyChecking = false"); assert(MemRuntimeCheck && "called even though needsAnyChecking = false");
// Rename the block to make the IR more readable. // Rename the block to make the IR more readable.
MemCheckBB->setName(OrigLoop->getHeader()->getName() + ".ldist.memcheck"); MemCheckBB->setName(VersionedLoop->getHeader()->getName() +
".lver.memcheck");
// Create empty preheader for the loop (and after cloning for the // Create empty preheader for the loop (and after cloning for the
// original/nondist loop). // non-versioned loop).
BasicBlock *PH = BasicBlock *PH =
SplitBlock(MemCheckBB, MemCheckBB->getTerminator(), DT, LI); SplitBlock(MemCheckBB, MemCheckBB->getTerminator(), DT, LI);
PH->setName(OrigLoop->getHeader()->getName() + ".ph"); PH->setName(VersionedLoop->getHeader()->getName() + ".ph");
// Clone the loop including the preheader. // Clone the loop including the preheader.
// //
// FIXME: This does not currently preserve SimplifyLoop because the exit // FIXME: This does not currently preserve SimplifyLoop because the exit
// block is a join between the two loops. // block is a join between the two loops.
SmallVector<BasicBlock *, 8> NonDistributedLoopBlocks; SmallVector<BasicBlock *, 8> NonVersionedLoopBlocks;
NonDistributedLoop = NonVersionedLoop =
cloneLoopWithPreheader(PH, MemCheckBB, OrigLoop, VMap, ".ldist.nondist", cloneLoopWithPreheader(PH, MemCheckBB, VersionedLoop, VMap,
LI, DT, NonDistributedLoopBlocks); ".lver.orig", LI, DT, NonVersionedLoopBlocks);
remapInstructionsInLoop(NonDistributedLoopBlocks, VMap); remapInstructionsInLoop(NonVersionedLoopBlocks, VMap);
// Insert the conditional branch based on the result of the memchecks. // Insert the conditional branch based on the result of the memchecks.
Instruction *OrigTerm = MemCheckBB->getTerminator(); Instruction *OrigTerm = MemCheckBB->getTerminator();
BranchInst::Create(NonDistributedLoop->getLoopPreheader(), BranchInst::Create(NonVersionedLoop->getLoopPreheader(),
OrigLoop->getLoopPreheader(), MemRuntimeCheck, OrigTerm); VersionedLoop->getLoopPreheader(), MemRuntimeCheck,
OrigTerm);
OrigTerm->eraseFromParent(); OrigTerm->eraseFromParent();
// The loops merge in the original exit block. This is now dominated by the // The loops merge in the original exit block. This is now dominated by the
// memchecking block. // memchecking block.
DT->changeImmediateDominator(OrigLoop->getExitBlock(), MemCheckBB); DT->changeImmediateDominator(VersionedLoop->getExitBlock(), MemCheckBB);
} }
/// \brief Adds the necessary PHI nodes for the versioned loops based on the /// \brief Adds the necessary PHI nodes for the versioned loops based on the
/// loop-defined values used outside of the loop. /// loop-defined values used outside of the loop.
void addPHINodes(const SmallVectorImpl<Instruction *> &DefsUsedOutside) { void addPHINodes(const SmallVectorImpl<Instruction *> &DefsUsedOutside) {
BasicBlock *PHIBlock = OrigLoop->getExitBlock(); BasicBlock *PHIBlock = VersionedLoop->getExitBlock();
assert(PHIBlock && "No single successor to loop exit block"); assert(PHIBlock && "No single successor to loop exit block");
for (auto *Inst : DefsUsedOutside) { for (auto *Inst : DefsUsedOutside) {
auto *NonDistInst = cast<Instruction>(VMap[Inst]); auto *NonVersionedLoopInst = cast<Instruction>(VMap[Inst]);
PHINode *PN; PHINode *PN;
// 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
@ -704,24 +707,25 @@ public:
} }
// If not create it. // If not create it.
if (!PN) { if (!PN) {
PN = PHINode::Create(Inst->getType(), 2, Inst->getName() + ".ldist", PN = PHINode::Create(Inst->getType(), 2, Inst->getName() + ".lver",
PHIBlock->begin()); PHIBlock->begin());
for (auto *User : Inst->users()) for (auto *User : Inst->users())
if (!OrigLoop->contains(cast<Instruction>(User)->getParent())) if (!VersionedLoop->contains(cast<Instruction>(User)->getParent()))
User->replaceUsesOfWith(Inst, PN); User->replaceUsesOfWith(Inst, PN);
PN->addIncoming(Inst, OrigLoop->getExitingBlock()); PN->addIncoming(Inst, VersionedLoop->getExitingBlock());
} }
// Add the new incoming value from the non-distributed loop. // Add the new incoming value from the non-versioned loop.
PN->addIncoming(NonDistInst, NonDistributedLoop->getExitingBlock()); PN->addIncoming(NonVersionedLoopInst,
NonVersionedLoop->getExitingBlock());
} }
} }
private: private:
/// \brief The original loop. This becomes the "versioned" one, i.e. control /// \brief The original loop. This becomes the "versioned" one, i.e. control
/// goes if the memchecks all pass. /// goes if the memchecks all pass.
Loop *OrigLoop; Loop *VersionedLoop;
/// \brief The fall-back loop, i.e. if any of the memchecks fail. /// \brief The fall-back loop, i.e. if any of the memchecks fail.
Loop *NonDistributedLoop; Loop *NonVersionedLoop;
/// \brief For each memory pointer it contains the partitionId it is used in. /// \brief For each memory pointer it contains the partitionId it is used in.
/// If nullptr, no partitioning is used. /// If nullptr, no partitioning is used.
@ -730,8 +734,8 @@ private:
/// If the pointer is used in multiple partitions the entry is set to -1. /// If the pointer is used in multiple partitions the entry is set to -1.
const SmallVector<int, 8> *PtrToPartition; const SmallVector<int, 8> *PtrToPartition;
/// \brief This maps the instructions from OrigLoop to their counterpart in /// \brief This maps the instructions from VersionedLoop to their counterpart
/// NonDistributedLoop. /// in NonVersionedLoop.
ValueToValueMapTy VMap; ValueToValueMapTy VMap;
/// \brief Analyses used. /// \brief Analyses used.

View File

@ -35,7 +35,7 @@ entry:
; We have two compares for each array overlap check which is a total of 10 ; We have two compares for each array overlap check which is a total of 10
; compares. ; compares.
; ;
; CHECK: for.body.ldist.memcheck: ; CHECK: for.body.lver.memcheck:
; CHECK: = icmp ; CHECK: = icmp
; CHECK: = icmp ; CHECK: = icmp
@ -52,14 +52,14 @@ entry:
; CHECK: = icmp ; CHECK: = icmp
; CHECK-NOT: = icmp ; CHECK-NOT: = icmp
; CHECK: br i1 %memcheck.conflict, label %for.body.ph.ldist.nondist, label %for.body.ph.ldist1 ; CHECK: br i1 %memcheck.conflict, label %for.body.ph.lver.orig, label %for.body.ph.ldist1
; The non-distributed loop that the memchecks fall back on. ; The non-distributed loop that the memchecks fall back on.
; CHECK: for.body.ph.ldist.nondist: ; CHECK: for.body.ph.lver.orig:
; CHECK: br label %for.body.ldist.nondist ; CHECK: br label %for.body.lver.orig
; CHECK: for.body.ldist.nondist: ; CHECK: for.body.lver.orig:
; CHECK: br i1 %exitcond.ldist.nondist, label %for.end, label %for.body.ldist.nondist ; CHECK: br i1 %exitcond.lver.orig, label %for.end, label %for.body.lver.orig
; Verify the two distributed loops. ; Verify the two distributed loops.

View File

@ -37,7 +37,7 @@ entry:
; CHECK: for.body: ; CHECK: for.body:
; CHECK: %sum_add = add nuw nsw i32 %sum, %loadC ; CHECK: %sum_add = add nuw nsw i32 %sum, %loadC
; CHECK: for.end: ; CHECK: for.end:
; CHECK: %sum_add.ldist = phi i32 [ %sum_add, %for.body ], [ %sum_add.ldist.nondist, %for.body.ldist.nondist ] ; CHECK: %sum_add.lver = phi i32 [ %sum_add, %for.body ], [ %sum_add.lver.orig, %for.body.lver.orig ]
for.body: ; preds = %for.body, %entry for.body: ; preds = %for.body, %entry
%ind = phi i64 [ 0, %entry ], [ %add, %for.body ] %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]