[llvm] [NFC] Add `const` for readability (PR #116611)
Piotr Fusik via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 10:16:47 PST 2024
================
@@ -581,30 +581,30 @@ class InnerLoopVectorizer {
virtual void printDebugTracesAtEnd() {}
/// The original loop.
- Loop *OrigLoop;
+ Loop *const OrigLoop;
/// A wrapper around ScalarEvolution used to add runtime SCEV checks. Applies
/// dynamic knowledge to simplify SCEV expressions and converts them to a
/// more usable form.
PredicatedScalarEvolution &PSE;
/// Loop Info.
- LoopInfo *LI;
+ LoopInfo *const LI;
----------------
pfusik wrote:
My change says "`LI` cannot be mutated".
Your change would say "`*LI` cannot be mutated" and it does not compile:
```diff
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index ca89d7676677..d4cf5046b722 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -589,7 +589,7 @@ protected:
PredicatedScalarEvolution &PSE;
/// Loop Info.
- LoopInfo *const LI;
+ const LoopInfo *LI;
/// Dominator Tree.
DominatorTree *const DT;
```
```
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp: In member function ‘void llvm::InnerLoopVectorizer::emitIterationCountCheck(llvm::BasicBlock*)’:
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2498:67: error: invalid conversion from ‘const llvm::LoopInfo*’ to ‘llvm::LoopInfo*’ [-fpermissive]
2498 | SplitBlock(TCCheckBlock, TCCheckBlock->getTerminator(), DT, LI, nullptr,
| ^~
| |
| const llvm::LoopInfo*
In file included from /home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:135:
/home/p.fusik/upstream/llvm-project/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h:288:34: note: initializing argument 4 of ‘llvm::BasicBlock* llvm::SplitBlock(llvm::BasicBlock*, llvm::Instruction*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, const llvm::Twine&, bool)’
288 | LoopInfo *LI = nullptr,
| ~~~~~~~~~~^~~~~~~~~~~~
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp: In member function ‘void llvm::InnerLoopVectorizer::createVectorLoopSkeleton(llvm::StringRef)’:
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2577:18: error: invalid conversion from ‘const llvm::LoopInfo*’ to ‘llvm::LoopInfo*’ [-fpermissive]
2577 | LI, nullptr, Twine(Prefix) + "middle.block");
| ^~
| |
| const llvm::LoopInfo*
In file included from /home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:135:
/home/p.fusik/upstream/llvm-project/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h:288:34: note: initializing argument 4 of ‘llvm::BasicBlock* llvm::SplitBlock(llvm::BasicBlock*, llvm::Instruction*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, const llvm::Twine&, bool)’
288 | LoopInfo *LI = nullptr,
| ~~~~~~~~~~^~~~~~~~~~~~
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2579:73: error: invalid conversion from ‘const llvm::LoopInfo*’ to ‘llvm::LoopInfo*’ [-fpermissive]
2579 | SplitBlock(LoopMiddleBlock, LoopMiddleBlock->getTerminator(), DT, LI,
| ^~
| |
| const llvm::LoopInfo*
In file included from /home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:135:
/home/p.fusik/upstream/llvm-project/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h:288:34: note: initializing argument 4 of ‘llvm::BasicBlock* llvm::SplitBlock(llvm::BasicBlock*, llvm::Instruction*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, const llvm::Twine&, bool)’
288 | LoopInfo *LI = nullptr,
| ~~~~~~~~~~^~~~~~~~~~~~
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp: In member function ‘llvm::BasicBlock* llvm::EpilogueVectorizerMainLoop::emitIterationCountCheck(llvm::BasicBlock*, bool)’:
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7882:40: error: invalid conversion from ‘const llvm::LoopInfo*’ to ‘llvm::LoopInfo*’ [-fpermissive]
7882 | DT, LI, nullptr, "vector.ph");
| ^~
| |
| const llvm::LoopInfo*
In file included from /home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:135:
/home/p.fusik/upstream/llvm-project/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h:288:34: note: initializing argument 4 of ‘llvm::BasicBlock* llvm::SplitBlock(llvm::BasicBlock*, llvm::Instruction*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, const llvm::Twine&, bool)’
288 | LoopInfo *LI = nullptr,
| ~~~~~~~~~~^~~~~~~~~~~~
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp: In member function ‘virtual std::pair<llvm::BasicBlock*, llvm::Value*> llvm::EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton(const SCEV2ValueTy&)’:
/home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7923:73: error: invalid conversion from ‘const llvm::LoopInfo*’ to ‘llvm::LoopInfo*’ [-fpermissive]
7923 | SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->begin(), DT, LI,
| ^~
| |
| const llvm::LoopInfo*
In file included from /home/p.fusik/upstream/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:135:
/home/p.fusik/upstream/llvm-project/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h:284:34: note: initializing argument 4 of ‘llvm::BasicBlock* llvm::SplitBlock(llvm::BasicBlock*, llvm::BasicBlock::iterator, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, const llvm::Twine&, bool)’
284 | LoopInfo *LI = nullptr,
| ~~~~~~~~~~^~~~~~~~~~~~
```
https://github.com/llvm/llvm-project/pull/116611
More information about the llvm-commits
mailing list