LLVM 23.0.0git
WarnMissedTransforms.cpp
Go to the documentation of this file.
1//===- LoopTransformWarning.cpp - ----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Emit warnings if forced code transformations have not been performed.
10//
11//===----------------------------------------------------------------------===//
12
17
18using namespace llvm;
19
20#define DEBUG_TYPE "transform-warning"
21
22/// Emit warnings for forced (i.e. user-defined) loop transformations which have
23/// still not been performed.
27 LLVM_DEBUG(dbgs() << "Leftover unroll transformation\n");
28
29 // Determine whether this loop originated from the vectorizer so we can
30 // produce more informative remarks.
32
33 ORE->emit(
35 "FailedRequestedUnrolling",
36 L->getStartLoc(), L->getHeader())
37 << LoopKind.str() +
38 "loop not unrolled: the optimizer was unable to perform the "
39 "requested transformation; the transformation might be disabled "
40 "or "
41 "specified as part of an unsupported transformation ordering");
42 }
43
45 LLVM_DEBUG(dbgs() << "Leftover unroll-and-jam transformation\n");
46 ORE->emit(
48 "FailedRequestedUnrollAndJamming",
49 L->getStartLoc(), L->getHeader())
50 << "loop not unroll-and-jammed: the optimizer was unable to perform "
51 "the requested transformation; the transformation might be disabled "
52 "or specified as part of an unsupported transformation ordering");
53 }
54
56 LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
57 std::optional<ElementCount> VectorizeWidth =
59 std::optional<int> InterleaveCount =
60 getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
61
62 if (!VectorizeWidth || VectorizeWidth->isVector())
63 ORE->emit(
65 "FailedRequestedVectorization",
66 L->getStartLoc(), L->getHeader())
67 << "loop not vectorized: the optimizer was unable to perform the "
68 "requested transformation; the transformation might be disabled "
69 "or specified as part of an unsupported transformation ordering");
70 else if (InterleaveCount.value_or(0) != 1)
71 ORE->emit(
73 "FailedRequestedInterleaving",
74 L->getStartLoc(), L->getHeader())
75 << "loop not interleaved: the optimizer was unable to perform the "
76 "requested transformation; the transformation might be disabled "
77 "or specified as part of an unsupported transformation ordering");
78 }
79
81 LLVM_DEBUG(dbgs() << "Leftover distribute transformation\n");
82 ORE->emit(
84 "FailedRequestedDistribution",
85 L->getStartLoc(), L->getHeader())
86 << "loop not distributed: the optimizer was unable to perform the "
87 "requested transformation; the transformation might be disabled or "
88 "specified as part of an unsupported transformation ordering");
89 }
90}
91
97
98// New pass manager boilerplate
101 // Do not warn about not applied transformations if optimizations are
102 // disabled.
103 if (F.hasOptNone())
104 return PreservedAnalyses::all();
105
107 auto &LI = AM.getResult<LoopAnalysis>(F);
108
110
111 return PreservedAnalyses::all();
112}
#define DEBUG_TYPE
#define F(x, y, z)
Definition MD5.cpp:54
#define LLVM_DEBUG(...)
Definition Debug.h:114
static void warnAboutLeftoverTransformations(Loop *L, OptimizationRemarkEmitter *ORE)
Emit warnings for forced (i.e.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Diagnostic information for optimization failures.
Analysis pass that exposes the LoopInfo for a function.
Definition LoopInfo.h:589
SmallVector< LoopT *, 4 > getLoopsInPreorder() const
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
The optimization diagnostic interface.
LLVM_ABI void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:222
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::optional< ElementCount > getOptionalElementCountLoopAttribute(const Loop *TheLoop)
Find a combination of metadata ("llvm.loop.vectorize.width" and "llvm.loop.vectorize....
LLVM_ABI TransformationMode hasVectorizeTransformation(const Loop *L)
LLVM_ABI TransformationMode hasUnrollAndJamTransformation(const Loop *L)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
LLVM_ABI TransformationMode hasUnrollTransformation(const Loop *L)
LLVM_ABI TransformationMode hasDistributeTransformation(const Loop *L)
LLVM_ABI std::optional< int > getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
Definition LoopUtils.h:300
LLVM_ABI StringRef getLoopVectorizeKindPrefix(const Loop *L)
Return a short prefix describing the loop's vectorizer origin based on the llvm.loop....
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.