aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
diff options
context:
space:
mode:
authorMichael Berg <93234525+mcberg2021@users.noreply.github.com>2025-08-22 11:05:31 -0700
committerGitHub <noreply@github.com>2025-08-22 11:05:31 -0700
commitefa99eccfcbf52ae2576eb49c4793df6be865a55 (patch)
tree5bc73585b156dcb9a5dd64ab1e0c471029d54c47 /llvm/lib/Transforms/Scalar/LoopDistribute.cpp
parent839d0aa88100aeb620024d34fa17ecf233952807 (diff)
downloadllvm-efa99eccfcbf52ae2576eb49c4793df6be865a55.zip
llvm-efa99eccfcbf52ae2576eb49c4793df6be865a55.tar.gz
llvm-efa99eccfcbf52ae2576eb49c4793df6be865a55.tar.bz2
[LoopDist] Add metadata for checking post process state of distribute… (#153902)
…d loops Add a count of the number of partitions LoopDist made when distributing a loop in meta data, then check for loops which are already distributed to prevent reprocessing. We see this happen on some spec apps, LD is on by default at SiFive.
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopDistribute.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopDistribute.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
index 27d3004..1099aa3 100644
--- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
@@ -113,6 +113,8 @@ static cl::opt<bool> EnableLoopDistribute(
cl::desc("Enable the new, experimental LoopDistribution Pass"),
cl::init(false));
+static const char *DistributedMetaData = "llvm.loop.isdistributed";
+
STATISTIC(NumLoopsDistributed, "Number of loops distributed");
namespace {
@@ -826,6 +828,8 @@ public:
{LLVMLoopDistributeFollowupAll, LLVMLoopDistributeFollowupFallback},
"llvm.loop.distribute.", true);
LVer.getNonVersionedLoop()->setLoopID(UnversionedLoopID);
+ addStringMetadataToLoop(LVer.getNonVersionedLoop(), DistributedMetaData,
+ true);
}
// Create identical copies of the original loop for each partition and hook
@@ -986,6 +990,13 @@ static bool runImpl(Function &F, LoopInfo *LI, DominatorTree *DT,
for (Loop *L : Worklist) {
LoopDistributeForLoop LDL(L, &F, LI, DT, SE, LAIs, ORE);
+ // Do not reprocess loops we already distributed
+ if (getOptionalBoolLoopAttribute(L, DistributedMetaData).value_or(false)) {
+ LLVM_DEBUG(
+ dbgs() << "LDist: Distributed loop guarded for reprocessing\n");
+ continue;
+ }
+
// If distribution was forced for the specific loop to be
// enabled/disabled, follow that. Otherwise use the global flag.
if (LDL.isForced().value_or(EnableLoopDistribute))