LLVM 17.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
18
19using namespace llvm;
20
21#define DEBUG_TYPE "transform-warning"
22
23/// Emit warnings for forced (i.e. user-defined) loop transformations which have
24/// still not been performed.
28 LLVM_DEBUG(dbgs() << "Leftover unroll transformation\n");
29 ORE->emit(
31 "FailedRequestedUnrolling",
32 L->getStartLoc(), L->getHeader())
33 << "loop not unrolled: the optimizer was unable to perform the "
34 "requested transformation; the transformation might be disabled or "
35 "specified as part of an unsupported transformation ordering");
36 }
37
39 LLVM_DEBUG(dbgs() << "Leftover unroll-and-jam transformation\n");
40 ORE->emit(
42 "FailedRequestedUnrollAndJamming",
43 L->getStartLoc(), L->getHeader())
44 << "loop not unroll-and-jammed: the optimizer was unable to perform "
45 "the requested transformation; the transformation might be disabled "
46 "or specified as part of an unsupported transformation ordering");
47 }
48
50 LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
51 std::optional<ElementCount> VectorizeWidth =
53 std::optional<int> InterleaveCount =
54 getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
55
56 if (!VectorizeWidth || VectorizeWidth->isVector())
57 ORE->emit(
59 "FailedRequestedVectorization",
60 L->getStartLoc(), L->getHeader())
61 << "loop not vectorized: the optimizer was unable to perform the "
62 "requested transformation; the transformation might be disabled "
63 "or specified as part of an unsupported transformation ordering");
64 else if (InterleaveCount.value_or(0) != 1)
65 ORE->emit(
67 "FailedRequestedInterleaving",
68 L->getStartLoc(), L->getHeader())
69 << "loop not interleaved: the optimizer was unable to perform the "
70 "requested transformation; the transformation might be disabled "
71 "or specified as part of an unsupported transformation ordering");
72 }
73
75 LLVM_DEBUG(dbgs() << "Leftover distribute transformation\n");
76 ORE->emit(
78 "FailedRequestedDistribution",
79 L->getStartLoc(), L->getHeader())
80 << "loop not distributed: the optimizer was unable to perform the "
81 "requested transformation; the transformation might be disabled or "
82 "specified as part of an unsupported transformation ordering");
83 }
84}
85
88 for (auto *L : LI->getLoopsInPreorder())
90}
91
92// New pass manager boilerplate
95 // Do not warn about not applied transformations if optimizations are
96 // disabled.
97 if (F.hasOptNone())
99
101 auto &LI = AM.getResult<LoopAnalysis>(F);
102
104
105 return PreservedAnalyses::all();
106}
#define LLVM_DEBUG(X)
Definition: Debug.h:101
#define F(x, y, z)
Definition: MD5.cpp:55
#define DEBUG_TYPE
static void warnAboutLeftoverTransformations(Loop *L, OptimizationRemarkEmitter *ORE)
Emit warnings for forced (i.e.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
Diagnostic information for optimization failures.
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:1268
SmallVector< LoopT *, 4 > getLoopsInPreorder() const
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
Definition: LoopInfoImpl.h:587
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:547
The optimization diagnostic interface.
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: PassManager.h:152
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::optional< ElementCount > getOptionalElementCountLoopAttribute(const Loop *TheLoop)
Find a combination of metadata ("llvm.loop.vectorize.width" and "llvm.loop.vectorize....
Definition: LoopUtils.cpp:250
TransformationMode hasVectorizeTransformation(const Loop *L)
Definition: LoopUtils.cpp:391
TransformationMode hasUnrollAndJamTransformation(const Loop *L)
Definition: LoopUtils.cpp:373
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
TransformationMode hasUnrollTransformation(const Loop *L)
Definition: LoopUtils.cpp:352
TransformationMode hasDistributeTransformation(const Loop *L)
Definition: LoopUtils.cpp:427
std::optional< int > getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
Definition: LoopInfo.cpp:1089
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
Definition: LoopUtils.h:288