[llvm-branch-commits] [llvm] [polly] [Support] Use block numbers for LoopInfo BBMap (PR #103400)
Alexis Engelke via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 19 03:09:43 PDT 2026
https://github.com/aengelke updated https://github.com/llvm/llvm-project/pull/103400
>From 73f4ec0be01c2301bfd05d5adc382616081755e4 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Thu, 19 Mar 2026 08:37:21 +0000
Subject: [PATCH 1/2] fix polly + remove abi breaking checks condition
Created using spr 1.3.8-wip
---
llvm/include/llvm/Support/GenericLoopInfo.h | 31 +++++--------------
.../llvm/Support/GenericLoopInfoImpl.h | 6 ++++
llvm/lib/Transforms/Utils/LoopUtils.cpp | 3 +-
polly/lib/CodeGen/IslNodeBuilder.cpp | 3 +-
4 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/llvm/include/llvm/Support/GenericLoopInfo.h b/llvm/include/llvm/Support/GenericLoopInfo.h
index c2a574b254309..888b0414e0521 100644
--- a/llvm/include/llvm/Support/GenericLoopInfo.h
+++ b/llvm/include/llvm/Support/GenericLoopInfo.h
@@ -530,10 +530,8 @@ template <class BlockT, class LoopT> class LoopInfoBase {
BBMap;
using ParentT = decltype(std::declval<const BlockT *>()->getParent());
-#if LLVM_ENABLE_ABI_BREAKING_CHECKS
- mutable ParentT ParentPtr = nullptr;
- mutable unsigned BlockNumberEpoch;
-#endif
+ ParentT ParentPtr = nullptr;
+ unsigned BlockNumberEpoch;
std::vector<LoopT *> TopLevelLoops;
BumpPtrAllocator LoopAllocator;
@@ -552,19 +550,15 @@ template <class BlockT, class LoopT> class LoopInfoBase {
: BBMap(std::move(Arg.BBMap)),
TopLevelLoops(std::move(Arg.TopLevelLoops)),
LoopAllocator(std::move(Arg.LoopAllocator)) {
-#if LLVM_ENABLE_ABI_BREAKING_CHECKS
ParentPtr = Arg.ParentPtr;
BlockNumberEpoch = Arg.BlockNumberEpoch;
-#endif
// We have to clear the arguments top level loops as we've taken ownership.
Arg.TopLevelLoops.clear();
}
LoopInfoBase &operator=(LoopInfoBase &&RHS) {
BBMap = std::move(RHS.BBMap);
-#if LLVM_ENABLE_ABI_BREAKING_CHECKS
ParentPtr = RHS.ParentPtr;
BlockNumberEpoch = RHS.BlockNumberEpoch;
-#endif
for (auto *L : TopLevelLoops)
L->~LoopT();
@@ -577,9 +571,6 @@ template <class BlockT, class LoopT> class LoopInfoBase {
void releaseMemory() {
BBMap.clear();
-#if LLVM_ENABLE_ABI_BREAKING_CHECKS
- ParentPtr = nullptr;
-#endif
for (auto *L : TopLevelLoops)
L->~LoopT();
@@ -625,21 +616,13 @@ template <class BlockT, class LoopT> class LoopInfoBase {
/// Verify that used block numbers are still valid. Initializes the block
/// number epoch and parent when no blocks exist so far.
void verifyBlockNumberEpoch(ParentT BBParent) const {
-#if LLVM_ENABLE_ABI_BREAKING_CHECKS
if constexpr (GraphHasNodeNumbers<BlockT *>) {
- if (ParentPtr == nullptr)
- ParentPtr = BBParent;
- else
- assert(ParentPtr == BBParent &&
- "loop info queried with block of other function");
- if (BBMap.empty())
- BlockNumberEpoch = GraphTraits<ParentT>::getNumberEpoch(ParentPtr);
- else
- assert(BlockNumberEpoch ==
- GraphTraits<ParentT>::getNumberEpoch(ParentPtr) &&
- "loop info used with outdated block numbers");
+ assert(ParentPtr == BBParent &&
+ "loop info queried with block of other function");
+ assert(BlockNumberEpoch ==
+ GraphTraits<ParentT>::getNumberEpoch(ParentPtr) &&
+ "loop info used with outdated block numbers");
}
-#endif
}
public:
diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index cae13ecb6945c..67dcfea0c9c79 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -578,6 +578,12 @@ template <class BlockT, class LoopT>
void LoopInfoBase<BlockT, LoopT>::analyze(const DomTreeBase<BlockT> &DomTree) {
// Postorder traversal of the dominator tree.
const DomTreeNodeBase<BlockT> *DomRoot = DomTree.getRootNode();
+ if constexpr (GraphHasNodeNumbers<const BlockT *>) {
+ ParentPtr = DomRoot->getBlock()->getParent();
+ BlockNumberEpoch = GraphTraits<ParentT>::getNumberEpoch(ParentPtr);
+ unsigned Max = GraphTraits<ParentT>::getMaxNumber(ParentPtr);
+ BBMap.resize(Max);
+ }
for (auto DomNode : post_order(DomRoot)) {
BlockT *Header = DomNode->getBlock();
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index aa0f08fd82a2c..7573467917c73 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -682,8 +682,7 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
MSSA->verifyMemorySSA();
if (LI) {
- SmallPtrSet<BasicBlock *, 8> Blocks;
- Blocks.insert(L->block_begin(), L->block_end());
+ SmallPtrSet<BasicBlock *, 8> Blocks(llvm::from_range, L->blocks());
// Erase the instructions and the blocks without having to worry
// about ordering because we already dropped the references.
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index 299c98b21d702..d620ac768abd6 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -234,7 +234,8 @@ static void findReferencesInStmt(ScopStmt *Stmt, SetVector<Value *> &Values,
LoopInfo *LI = Stmt->getParent()->getLI();
BasicBlock *BB = Stmt->getBasicBlock();
- Loop *Scope = LI->getLoopFor(BB);
+ // TODO: Should BB ever be null?
+ Loop *Scope = BB ? LI->getLoopFor(BB) : nullptr;
for (Instruction *Inst : Stmt->getInstructions())
findReferencesInInst(Inst, Stmt, Scope, GlobalMap, Values, SCEVs);
>From 55e9e57331c5881941fa77dd14a03bb11dc08020 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Thu, 19 Mar 2026 10:09:08 +0000
Subject: [PATCH 2/2] fix outdated comment
Created using spr 1.3.8-wip
---
llvm/include/llvm/Support/GenericLoopInfo.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Support/GenericLoopInfo.h b/llvm/include/llvm/Support/GenericLoopInfo.h
index 888b0414e0521..2fb8c2c377a02 100644
--- a/llvm/include/llvm/Support/GenericLoopInfo.h
+++ b/llvm/include/llvm/Support/GenericLoopInfo.h
@@ -613,8 +613,7 @@ template <class BlockT, class LoopT> class LoopInfoBase {
SmallVector<LoopT *, 4> getLoopsInReverseSiblingPreorder() const;
private:
- /// Verify that used block numbers are still valid. Initializes the block
- /// number epoch and parent when no blocks exist so far.
+ /// Verify that used block numbers are still valid.
void verifyBlockNumberEpoch(ParentT BBParent) const {
if constexpr (GraphHasNodeNumbers<BlockT *>) {
assert(ParentPtr == BBParent &&
More information about the llvm-branch-commits
mailing list