[PATCH] D138228: [LoopPeel] Expose ValueMap of last peeled iteration. NFC
Anna Thomas via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 17 10:46:24 PST 2022
anna created this revision.
anna added reviewers: nikic, fhahn, mkazantsev, apilipenko.
Herald added subscribers: zzheng, hiraditya.
Herald added a project: All.
anna requested review of this revision.
Herald added a project: LLVM.
The value map of last peeled iteration is computed within peelLoop API.
This patch exposes it for callers of peelLoop.
While this is not currently used by upstream passes, we have a usecase
downstream which benefits from this API update. Future users of peelLoop
can also use the ValueMap if needed.
Similar value maps are exposed by other loop utilities such as loop
cloning.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138228
Files:
llvm/include/llvm/Transforms/Utils/LoopPeel.h
llvm/lib/Transforms/Scalar/LoopFuse.cpp
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/lib/Transforms/Utils/LoopPeel.cpp
Index: llvm/lib/Transforms/Utils/LoopPeel.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -741,7 +741,7 @@
/// optimizations.
bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
ScalarEvolution *SE, DominatorTree &DT, AssumptionCache *AC,
- bool PreserveLCSSA) {
+ bool PreserveLCSSA, ValueToValueMapTy &LVMap) {
assert(PeelCount > 0 && "Attempt to peel out zero iterations?");
assert(canPeel(L) && "Attempt to peel a loop which is not peelable?");
@@ -833,8 +833,6 @@
InsertBot->setName(Header->getName() + ".peel.next");
NewPreHeader->setName(PreHeader->getName() + ".peel.newph");
- ValueToValueMapTy LVMap;
-
Instruction *LatchTerm =
cast<Instruction>(cast<BasicBlock>(Latch)->getTerminator());
Index: llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -1289,7 +1289,8 @@
<< " iterations";
});
- if (peelLoop(L, PP.PeelCount, LI, &SE, DT, &AC, PreserveLCSSA)) {
+ ValueToValueMapTy VMap;
+ if (peelLoop(L, PP.PeelCount, LI, &SE, DT, &AC, PreserveLCSSA, VMap)) {
simplifyLoopAfterUnroll(L, true, LI, &SE, &DT, &AC, &TTI);
// If the loop was peeled, we already "used up" the profile information
// we had, so we don't want to unroll or peel again.
Index: llvm/lib/Transforms/Scalar/LoopFuse.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -767,7 +767,8 @@
LLVM_DEBUG(dbgs() << "Attempting to peel first " << PeelCount
<< " iterations of the first loop. \n");
- FC0.Peeled = peelLoop(FC0.L, PeelCount, &LI, &SE, DT, &AC, true);
+ ValueToValueMapTy VMap;
+ FC0.Peeled = peelLoop(FC0.L, PeelCount, &LI, &SE, DT, &AC, true, VMap);
if (FC0.Peeled) {
LLVM_DEBUG(dbgs() << "Done Peeling\n");
Index: llvm/include/llvm/Transforms/Utils/LoopPeel.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/LoopPeel.h
+++ llvm/include/llvm/Transforms/Utils/LoopPeel.h
@@ -15,13 +15,17 @@
#define LLVM_TRANSFORMS_UTILS_LOOPPEEL_H
#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/Transforms/Utils/ValueMapper.h"
namespace llvm {
bool canPeel(Loop *L);
+/// VMap is the value-map that maps instructions from the original loop to
+/// instructions in the last peeled-off iteration.
bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
- DominatorTree &DT, AssumptionCache *AC, bool PreserveLCSSA);
+ DominatorTree &DT, AssumptionCache *AC, bool PreserveLCSSA,
+ ValueToValueMapTy &VMap);
TargetTransformInfo::PeelingPreferences
gatherPeelingPreferences(Loop *L, ScalarEvolution &SE,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138228.476180.patch
Type: text/x-patch
Size: 3113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221117/744ecb6a/attachment.bin>
More information about the llvm-commits
mailing list