[llvm] [LV][NFC] Introduce LoopVectorizationUtils for shared utility functions (PR #194951)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Fri May 8 03:29:37 PDT 2026
================
@@ -0,0 +1,86 @@
+//===- LoopVectorizationUtils.h - Utilities for LoopVectorize -------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file provides declaration for stateless functions that are used by the
+/// LoopVectorize and its related files.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONUTILS_H
+#define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONUTILS_H
+
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
+#include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/Support/Compiler.h"
+
+namespace llvm {
+namespace LoopVectorizationUtils {
+
+// Loop vectorization hints how the epilogue/tail loop should be
+// lowered.
+enum EpilogueLowering {
+
+ // The default: allowing epilogues.
+ EpilogueAllowed,
+
+ // Vectorization with OptForSize: don't allow epilogues.
+ EpilogueNotAllowedOptSize,
+
+ // A special case of vectorisation with OptForSize: loops with a very small
+ // trip count are considered for vectorization under OptForSize, thereby
+ // making sure the cost of their loop body is dominant, free of runtime
+ // guards and scalar iteration overheads.
+ EpilogueNotAllowedLowTripLoop,
+
+ // Loop hint indicating an epilogue is undesired, apply tail folding.
+ EpilogueNotNeededFoldTail,
+
+ // Directive indicating we must either fold the epilogue/tail or not vectorize
+ EpilogueNotAllowedFoldTail
+};
+
+/// Reports a vectorization failure: print \p DebugMsg for debugging
+/// purposes along with the corresponding optimization remark \p RemarkName.
+/// If \p I is passed, it is an instruction that prevents vectorization.
+/// Otherwise, the loop \p TheLoop is used for the location of the remark.
+void reportVectorizationFailure(const char *PassName, const StringRef DebugMsg,
----------------
david-arm wrote:
It might be nicer if these functions live outside the namespace, because at the moment it forces the caller to be more verbose everywhere, i.e. by calling `LoopVectorizationUtils::reportVectorizationFailure`. Alternatively, in LoopVectorize.cpp and LoopVectorizationPlanner.cpp perhaps you could add the `use namespace LoopVectorizationUtils` to the start of the files so that you can simplify the call to just `reportVectorizationFailure`?
At the moment I don't really see other parts of LLVM clashing with the name `reportVectorizationFailure`, especially since this header file is only visible to files in lib/Transforms/Vectorize/***
https://github.com/llvm/llvm-project/pull/194951
More information about the llvm-commits
mailing list