[llvm] [LV] Strip unnecessary cl::opts from headers (NFC) (PR #221891)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 03:15:16 PDT 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/221891
>From 401bfd67d2236faa910fa77521d679b18d1d57ad Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 8 Sep 2026 07:45:27 +0100
Subject: [PATCH] [LV] Strip unnecessary cl::opts from headers (NFC)
Mark the ones which are static as such, strip declarations in headers to
avoid unnecessary dependencies, and nest the non-static ones under the
llvm namespace.
---
.../Vectorize/LoopVectorizationPlanner.cpp | 15 ++++---
.../Vectorize/LoopVectorizationPlanner.h | 4 --
.../Transforms/Vectorize/LoopVectorize.cpp | 40 ++++++++++---------
llvm/lib/Transforms/Vectorize/VPlan.cpp | 6 +--
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 4 ++
5 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp
index 7ecedd6e189e9..0d197da96ef8d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.cpp
@@ -29,8 +29,6 @@ using namespace LoopVectorizationUtils;
#define DEBUG_TYPE "loop-vectorize"
-extern cl::opt<bool> VPlanBuildOuterloopStressTest;
-
static cl::opt<bool> MaximizeBandwidth(
"vectorizer-maximize-bandwidth", cl::init(false), cl::Hidden,
cl::desc("Maximize bandwidth when selecting vectorization factor which "
@@ -51,10 +49,15 @@ static cl::opt<bool> ForceTargetSupportsScalableVectors(
"Pretend that scalable vectors are supported, even if the target does "
"not support them. This flag should only be used for testing."));
-cl::opt<bool> llvm::PreferInLoopReductions(
- "prefer-inloop-reductions", cl::init(false), cl::Hidden,
- cl::desc("Prefer in-loop vector reductions, "
- "overriding the targets preference."));
+namespace llvm {
+extern cl::opt<bool> VPlanBuildOuterloopStressTest;
+
+cl::opt<bool>
+ PreferInLoopReductions("prefer-inloop-reductions", cl::init(false),
+ cl::Hidden,
+ cl::desc("Prefer in-loop vector reductions, "
+ "overriding the targets preference."));
+} // namespace llvm
/// Note: This currently only applies to `llvm.masked.load` and
/// `llvm.masked.store`. TODO: Extend this to cover other operations as needed.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index 4ceac108ae8c7..108a245aac4cc 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -50,10 +50,6 @@ class VPRecipeBuilder;
struct VPRegisterUsage;
struct VFRange;
-extern cl::opt<bool> EnableVPlanNativePath;
-extern cl::opt<unsigned> ForceTargetInstructionCost;
-extern cl::opt<bool> PreferInLoopReductions;
-
/// \return An upper bound for vscale based on TTI or the vscale_range
/// attribute.
std::optional<unsigned> getMaxVScale(const Function &F);
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2493d2aca6265..bcc93ced01380 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -282,12 +282,6 @@ static cl::opt<unsigned> ForceTargetMaxVectorInterleaveFactor(
cl::desc("A flag that overrides the target's max interleave factor for "
"vectorized loops."));
-cl::opt<unsigned> llvm::ForceTargetInstructionCost(
- "force-target-instruction-cost", cl::init(0), cl::Hidden,
- cl::desc("A flag that overrides the target's expected cost for "
- "an instruction to a single constant value. Mostly "
- "useful for getting consistent testing."));
-
static cl::opt<unsigned> SmallLoopCost(
"small-loop-cost", cl::init(20), cl::Hidden,
cl::desc(
@@ -305,11 +299,6 @@ static cl::opt<bool> EnableLoadStoreRuntimeInterleave(
cl::desc(
"Enable runtime interleaving until load/store ports are saturated"));
-/// The number of stores in a loop that are allowed to need predication.
-cl::opt<unsigned> NumberOfStoresToPredicate(
- "vectorize-num-stores-pred", cl::init(1), cl::Hidden,
- cl::desc("Max number of stores to be predicated behind an if."));
-
// TODO: Move size-based thresholds out of legality checking, make cost based
// decisions instead of hard thresholds.
static cl::opt<unsigned> VectorizeSCEVCheckThreshold(
@@ -340,7 +329,7 @@ static cl::opt<bool> PreferPredicatedReductionSelect(
cl::desc(
"Prefer predicating a reduction operation over an after loop select."));
-cl::opt<bool> llvm::EnableVPlanNativePath(
+static cl::opt<bool> EnableVPlanNativePath(
"enable-vplan-native-path", cl::Hidden,
cl::desc("Enable VPlan-native vectorization path with "
"support for outer loop vectorization."));
@@ -378,6 +367,25 @@ cl::opt<bool> llvm::VPlanPrintVectorRegionScope(
"`-vplan-print-after*` if the plan has one."));
#endif
+cl::opt<bool> llvm::EnableLoopInterleaving(
+ "interleave-loops", cl::init(true), cl::Hidden,
+ cl::desc("Enable loop interleaving in Loop vectorization passes"));
+cl::opt<bool> llvm::EnableLoopVectorization(
+ "vectorize-loops", cl::init(true), cl::Hidden,
+ cl::desc("Run the Loop vectorization passes"));
+
+namespace llvm {
+cl::opt<unsigned> ForceTargetInstructionCost(
+ "force-target-instruction-cost", cl::init(0), cl::Hidden,
+ cl::desc("A flag that overrides the target's expected cost for "
+ "an instruction to a single constant value. Mostly "
+ "useful for getting consistent testing."));
+
+/// The number of stores in a loop that are allowed to need predication.
+cl::opt<unsigned> NumberOfStoresToPredicate(
+ "vectorize-num-stores-pred", cl::init(1), cl::Hidden,
+ cl::desc("Max number of stores to be predicated behind an if."));
+
// This flag enables the stress testing of the VPlan H-CFG construction in the
// VPlan-native vectorization path. It must be used in conjuction with
// -enable-vplan-native-path. -vplan-verify-hcfg can also be used to enable the
@@ -388,13 +396,7 @@ cl::opt<bool> VPlanBuildOuterloopStressTest(
"Build VPlan for every supported loop nest in the function and bail "
"out right after the build (stress test the VPlan H-CFG construction "
"in the VPlan-native vectorization path)."));
-
-cl::opt<bool> llvm::EnableLoopInterleaving(
- "interleave-loops", cl::init(true), cl::Hidden,
- cl::desc("Enable loop interleaving in Loop vectorization passes"));
-cl::opt<bool> llvm::EnableLoopVectorization(
- "vectorize-loops", cl::init(true), cl::Hidden,
- cl::desc("Run the Loop vectorization passes"));
+} // namespace llvm
static cl::opt<cl::boolOrDefault>
ForceMaskedDivRem("force-widen-divrem-via-masked-intrinsic", cl::Hidden,
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 8b42ccb6803c8..896962d5e9620 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -55,6 +55,8 @@ using namespace llvm::VPlanPatternMatch;
namespace llvm {
extern cl::opt<bool> ProfcheckDisableMetadataFixes;
+extern cl::opt<unsigned> ForceTargetInstructionCost;
+extern cl::opt<unsigned> NumberOfStoresToPredicate;
} // namespace llvm
/// @{
@@ -66,10 +68,6 @@ const char LLVMLoopVectorizeFollowupEpilogue[] =
"llvm.loop.vectorize.followup_epilogue";
/// @}
-extern cl::opt<unsigned> ForceTargetInstructionCost;
-
-extern cl::opt<unsigned> NumberOfStoresToPredicate;
-
static cl::opt<bool> PrintVPlansInDotFormat(
"vplan-print-in-dot-format", cl::Hidden,
cl::desc("Use dot format instead of plain text when dumping VPlans"));
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1a6119b22c9d3..5213b5bc57de9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -58,6 +58,10 @@ static cl::opt<bool> VPlanPrintMetadata(
cl::desc("Controls the printing of recipe metadata when debugging."));
#endif
+namespace llvm {
+extern cl::opt<unsigned> ForceTargetInstructionCost;
+} // namespace llvm
+
bool VPRecipeBase::mayWriteToMemory() const {
switch (getVPRecipeID()) {
case VPExpressionSC:
More information about the llvm-commits
mailing list