Skip to content

Commit bc68571

Browse files
author
GYT
committed
Refactor the printing of the new messages
1 parent a509ea9 commit bc68571

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ class LoopVectorizeHints {
196196

197197
/// Interface to emit optimization remarks.
198198
OptimizationRemarkEmitter &ORE;
199+
200+
/// Reports a condition where loop vectorization is disallowed: prints
201+
/// \p DebugMsg for debugging purposes along with the corresponding
202+
/// optimization remark \p RemarkName , with \p RemarkMsg as the user-facing
203+
/// message. The loop \p L is used for the location of the remark.
204+
void LoopVectorizeHints::reportDisallowedVectorization(
205+
const StringRef DebugMsg, const StringRef RemarkName,
206+
const StringRef RemarkMsg, const Loop *L) const;
199207
};
200208

201209
/// This holds vectorization requirements that must be verified late in

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,42 +179,40 @@ void LoopVectorizeHints::setAlreadyVectorized() {
179179
IsVectorized.Value = 1;
180180
}
181181

182+
void LoopVectorizeHints::reportDisallowedVectorization(
183+
const StringRef DebugMsg, const StringRef RemarkName,
184+
const StringRef RemarkMsg, const Loop *L) const {
185+
LLVM_DEBUG(dbgs() << "LV: Not vectorizing: " << DebugMsg << ".\n");
186+
ORE.emit(OptimizationRemarkMissed(LV_NAME, RemarkName, L->getStartLoc(),
187+
L->getHeader())
188+
<< "loop not vectorized: " << RemarkMsg);
189+
}
190+
182191
bool LoopVectorizeHints::allowVectorization(
183192
Function *F, Loop *L, bool VectorizeOnlyWhenForced) const {
184193
if (getForce() == LoopVectorizeHints::FK_Disabled) {
185194
if (Force.Value == LoopVectorizeHints::FK_Disabled) {
186-
LLVM_DEBUG(dbgs() << "LV: Not vectorizing: #pragma vectorize disable.\n");
187-
ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedExplicitlyDisabled",
188-
TheLoop->getStartLoc(),
189-
TheLoop->getHeader())
190-
<< "loop not vectorized: vectorization is explicitly disabled");
191-
} else if (hasDisableAllTransformsHint(TheLoop)) {
192-
LLVM_DEBUG(
193-
dbgs() << "LV: Not vectorizing: loop hasDisableAllTransformsHint.\n");
194-
ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedTransformsDisabled",
195-
TheLoop->getStartLoc(),
196-
TheLoop->getHeader())
197-
<< "loop not vectorized: loop transformations are disabled");
195+
reportDisallowedVectorization("#pragma vectorize disable",
196+
"MissedExplicitlyDisabled",
197+
"vectorization is explicitly disabled");
198+
} else if (hasDisableAllTransformsHint(L)) {
199+
reportDisallowedVectorization("loop hasDisableAllTransformsHint",
200+
"MissedTransformsDisabled",
201+
"loop transformations are disabled");
198202
} else {
199203
// This should be unreachable unless there is a bug.
200-
ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedUnknown",
201-
TheLoop->getStartLoc(),
202-
TheLoop->getHeader())
203-
<< "loop not vectorized: unknown reason, please file a bug "
204-
"report on the LLVM issue tracker");
204+
reportDisallowedVectorization(
205+
"disabled for an unknown reason", "MissedUnknown",
206+
"unknown reason, please file a bug report on the LLVM issue tracker");
205207
llvm_unreachable("loop vect disabled for an unknown reason");
206208
}
207209
return false;
208210
}
209211

210212
if (VectorizeOnlyWhenForced && getForce() != LoopVectorizeHints::FK_Enabled) {
211-
LLVM_DEBUG(dbgs() << "LV: Not vectorizing: VectorizeOnlyWhenForced is set, "
212-
"and no #pragma vectorize enable.\n");
213-
ORE.emit(OptimizationRemarkMissed(LV_NAME, "MissedForceOnly",
214-
TheLoop->getStartLoc(),
215-
TheLoop->getHeader())
216-
<< "loop not vectorized: only vectorizing loops that "
217-
"explicitly request it");
213+
reportDisallowedVectorization(
214+
"VectorizeOnlyWhenForced is set, and no #pragma vectorize enable",
215+
"MissedForceOnly", "only vectorizing loops that explicitly request it");
218216
return false;
219217
}
220218

0 commit comments

Comments
 (0)