From 027e2d7d09f1ca816389f7a32095d7113ec4dede Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Thu, 20 Aug 2015 17:22:29 +0000 Subject: [PATCH] [LVer] Fix FIXME: hide addPHINodes, NFC Since Ashutosh made findDefsUsedOutsideOfLoop public, we can clean this up. Now clients that don't compute DefsUsedOutsideOfLoop can just call versionLoop() and computing DefsUsedOutsideOfLoop will happen implicitly. With that there is no reason to expose addPHINodes anymore. Ashutosh, you can now drop the calls to findDefsUsedOutsideOfLoop and addPHINodes in LVerLICM and things should just work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245579 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/Transforms/Utils/LoopVersioning.h | 20 +++++++++++-------- lib/Transforms/Scalar/LoopDistribute.cpp | 3 +-- lib/Transforms/Utils/LoopVersioning.cpp | 7 ++++++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/llvm/Transforms/Utils/LoopVersioning.h b/include/llvm/Transforms/Utils/LoopVersioning.h index 8c87a62d84c..58a9e5b5a70 100644 --- a/include/llvm/Transforms/Utils/LoopVersioning.h +++ b/include/llvm/Transforms/Utils/LoopVersioning.h @@ -17,6 +17,7 @@ #define LLVM_TRANSFORMS_UTILS_LOOPVERSIONING_H #include "llvm/Transforms/Utils/ValueMapper.h" +#include "llvm/Transforms/Utils/LoopUtils.h" namespace llvm { @@ -55,15 +56,11 @@ public: /// analyze L /// if versioning is necessary version L /// transform L - void versionLoop(); + void versionLoop() { versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop)); } - /// \brief Adds the necessary PHI nodes for the versioned loops based on the - /// loop-defined values used outside of the loop. - /// - /// This needs to be called after versionLoop if there are defs in the loop - /// that are used outside the loop. FIXME: this should be invoked internally - /// by versionLoop and made private. - void addPHINodes(const SmallVectorImpl &DefsUsedOutside); + /// \brief Same but if the client has already precomputed the set of values + /// used outside the loop, this API will allows passing that. + void versionLoop(const SmallVectorImpl &DefsUsedOutside); /// \brief Returns the versioned loop. Control flows here if pointers in the /// loop don't alias (i.e. all memchecks passed). (This loop is actually the @@ -75,6 +72,13 @@ public: Loop *getNonVersionedLoop() { return NonVersionedLoop; } private: + /// \brief Adds the necessary PHI nodes for the versioned loops based on the + /// loop-defined values used outside of the loop. + /// + /// This needs to be called after versionLoop if there are defs in the loop + /// that are used outside the loop. + void addPHINodes(const SmallVectorImpl &DefsUsedOutside); + /// \brief The original loop. This becomes the "versioned" one. I.e., /// control flows here if pointers in the loop don't alias. Loop *VersionedLoop; diff --git a/lib/Transforms/Scalar/LoopDistribute.cpp b/lib/Transforms/Scalar/LoopDistribute.cpp index 82e2f48c4bf..a7769644203 100644 --- a/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/lib/Transforms/Scalar/LoopDistribute.cpp @@ -776,8 +776,7 @@ private: DEBUG(dbgs() << "\nPointers:\n"); DEBUG(LAI.getRuntimePointerChecking()->printChecks(dbgs(), Checks)); LoopVersioning LVer(std::move(Checks), LAI, L, LI, DT); - LVer.versionLoop(); - LVer.addPHINodes(DefsUsedOutside); + LVer.versionLoop(DefsUsedOutside); } // Create identical copies of the original loop for each partition and hook diff --git a/lib/Transforms/Utils/LoopVersioning.cpp b/lib/Transforms/Utils/LoopVersioning.cpp index 11f11adbc5e..bfc877e9836 100644 --- a/lib/Transforms/Utils/LoopVersioning.cpp +++ b/lib/Transforms/Utils/LoopVersioning.cpp @@ -40,7 +40,8 @@ LoopVersioning::LoopVersioning(const LoopAccessInfo &LAInfo, Loop *L, assert(L->getLoopPreheader() && "No preheader"); } -void LoopVersioning::versionLoop() { +void LoopVersioning::versionLoop( + const SmallVectorImpl &DefsUsedOutside) { Instruction *FirstCheckInst; Instruction *MemRuntimeCheck; // Add the memcheck in the original preheader (this is empty initially). @@ -77,6 +78,10 @@ void LoopVersioning::versionLoop() { // The loops merge in the original exit block. This is now dominated by the // memchecking block. DT->changeImmediateDominator(VersionedLoop->getExitBlock(), MemCheckBB); + + // Adds the necessary PHI nodes for the versioned loops based on the + // loop-defined values used outside of the loop. + addPHINodes(DefsUsedOutside); } void LoopVersioning::addPHINodes( -- 2.34.1