LLVM 20.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 ORE->emit(
30 "FailedRequestedUnrolling",
31 L->getStartLoc(), L->getHeader())
32 << "loop not unrolled: the optimizer was unable to perform the "
33 "requested transformation; the transformation might be disabled or "
34 "specified as part of an unsupported transformation ordering");
35 }
36
38 LLVM_DEBUG(dbgs() << "Leftover unroll-and-jam transformation\n");
39 ORE->emit(
41 "FailedRequestedUnrollAndJamming",
42 L->getStartLoc(), L->getHeader())
43 << "loop not unroll-and-jammed: the optimizer was unable to perform "
44 "the requested transformation; the transformation might be disabled "
45 "or specified as part of an unsupported transformation ordering");
46 }
47
49 LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
50 std::optional<ElementCount> VectorizeWidth =
52 std::optional<int> InterleaveCount =
53 getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
54
55 if (!VectorizeWidth || VectorizeWidth->isVector())
56 ORE->emit(
58 "FailedRequestedVectorization",
59 L->getStartLoc(), L->getHeader())
60 << "loop not vectorized: the optimizer was unable to perform the "
61 "requested transformation; the transformation might be disabled "
62 "or specified as part of an unsupported transformation ordering");
63 else if (InterleaveCount.value_or(0) != 1)
64 ORE->emit(
66 "FailedRequestedInterleaving",
67 L->getStartLoc(), L->getHeader())
68 << "loop not interleaved: the optimizer was unable to perform the "
69 "requested transformation; the transformation might be disabled "
70 "or specified as part of an unsupported transformation ordering");
71 }
72
74 LLVM_DEBUG(dbgs() << "Leftover distribute transformation\n");
75 ORE->emit(
77 "FailedRequestedDistribution",
78 L->getStartLoc(), L->getHeader())
79 << "loop not distributed: the optimizer was unable to perform the "
80 "requested transformation; the transformation might be disabled or "
81 "specified as part of an unsupported transformation ordering");
82 }
83}
84
87 for (auto *L : LI->getLoopsInPreorder())
89}
90
91// New pass manager boilerplate
94 // Do not warn about not applied transformations if optimizations are
95 // disabled.
96 if (F.hasOptNone())
98
100 auto &LI = AM.getResult<LoopAnalysis>(F);
101
103
104 return PreservedAnalyses::all();
105}
#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:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
Diagnostic information for optimization failures.
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:566
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:39
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: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
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:1101
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
Definition: LoopUtils.h:294