LLVM  9.0.0svn
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 
16 
17 using namespace llvm;
18 
19 #define DEBUG_TYPE "transform-warning"
20 
21 /// Emit warnings for forced (i.e. user-defined) loop transformations which have
22 /// still not been performed.
26  LLVM_DEBUG(dbgs() << "Leftover unroll transformation\n");
27  ORE->emit(
29  "FailedRequestedUnrolling",
30  L->getStartLoc(), L->getHeader())
31  << "loop not unrolled: the optimizer was unable to perform the "
32  "requested transformation; the transformation might be disabled or "
33  "specified as part of an unsupported transformation ordering");
34  }
35 
37  LLVM_DEBUG(dbgs() << "Leftover unroll-and-jam transformation\n");
38  ORE->emit(
40  "FailedRequestedUnrollAndJamming",
41  L->getStartLoc(), L->getHeader())
42  << "loop not unroll-and-jammed: the optimizer was unable to perform "
43  "the requested transformation; the transformation might be disabled "
44  "or specified as part of an unsupported transformation ordering");
45  }
46 
48  LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
49  Optional<int> VectorizeWidth =
50  getOptionalIntLoopAttribute(L, "llvm.loop.vectorize.width");
51  Optional<int> InterleaveCount =
52  getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
53 
54  if (VectorizeWidth.getValueOr(0) != 1)
55  ORE->emit(
57  "FailedRequestedVectorization",
58  L->getStartLoc(), L->getHeader())
59  << "loop not vectorized: the optimizer was unable to perform the "
60  "requested transformation; the transformation might be disabled "
61  "or specified as part of an unsupported transformation ordering");
62  else if (InterleaveCount.getValueOr(0) != 1)
63  ORE->emit(
65  "FailedRequestedInterleaving",
66  L->getStartLoc(), L->getHeader())
67  << "loop not interleaved: 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  }
71 
73  LLVM_DEBUG(dbgs() << "Leftover distribute transformation\n");
74  ORE->emit(
76  "FailedRequestedDistribution",
77  L->getStartLoc(), L->getHeader())
78  << "loop not distributed: the optimizer was unable to perform the "
79  "requested transformation; the transformation might be disabled or "
80  "specified as part of an unsupported transformation ordering");
81  }
82 }
83 
86  for (auto *L : LI->getLoopsInPreorder())
88 }
89 
90 // New pass manager boilerplate
93  // Do not warn about not applied transformations if optimizations are
94  // disabled.
95  if (F.hasOptNone())
96  return PreservedAnalyses::all();
97 
99  auto &LI = AM.getResult<LoopAnalysis>(F);
100 
101  warnAboutLeftoverTransformations(&F, &LI, &ORE);
102 
103  return PreservedAnalyses::all();
104 }
105 
106 // Legacy pass manager boilerplate
107 namespace {
108 class WarnMissedTransformationsLegacy : public FunctionPass {
109 public:
110  static char ID;
111 
112  explicit WarnMissedTransformationsLegacy() : FunctionPass(ID) {
115  }
116 
117  bool runOnFunction(Function &F) override {
118  if (skipFunction(F))
119  return false;
120 
121  auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
122  auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
123 
124  warnAboutLeftoverTransformations(&F, &LI, &ORE);
125  return false;
126  }
127 
128  void getAnalysisUsage(AnalysisUsage &AU) const override {
131 
132  AU.setPreservesAll();
133  }
134 };
135 } // end anonymous namespace
136 
138 
139 INITIALIZE_PASS_BEGIN(WarnMissedTransformationsLegacy, "transform-warning",
140  "Warn about non-applied transformations", false, false)
143 INITIALIZE_PASS_END(WarnMissedTransformationsLegacy, "transform-warning",
144  "Warn about non-applied transformations", false, false)
145 
147  return new WarnMissedTransformationsLegacy();
148 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:776
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool hasOptNone() const
Do not optimize this function (-O0).
Definition: Function.h:597
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:266
F(f)
transform warning
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
Diagnostic information for optimization failures.
TransformationMode hasUnrollAndJamTransformation(Loop *L)
Definition: LoopUtils.cpp:356
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:952
BlockT * getHeader() const
Definition: LoopInfo.h:100
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
llvm::Optional< int > getOptionalIntLoopAttribute(Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
Definition: LoopUtils.cpp:236
transform Warn about non applied transformations
Represent the analysis usage information of a pass.
TransformationMode hasDistributeTransformation(Loop *L)
Definition: LoopUtils.cpp:409
TransformationMode hasVectorizeTransformation(Loop *L)
Definition: LoopUtils.cpp:374
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
Pass * createWarnMissedTransformationsPass()
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
Definition: LoopInfo.cpp:355
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file. ...
The transformation was directed by the user, e.g.
Definition: LoopUtils.h:235
#define DEBUG_TYPE
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:465
TransformationMode hasUnrollTransformation(Loop *L)
Definition: LoopUtils.cpp:335
INITIALIZE_PASS_BEGIN(WarnMissedTransformationsLegacy, "transform-warning", "Warn about non-applied transformations", false, false) INITIALIZE_PASS_END(WarnMissedTransformationsLegacy
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &)
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
Definition: STLExtras.h:1267
SmallVector< LoopT *, 4 > getLoopsInPreorder()
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
Definition: LoopInfoImpl.h:582
OptimizationRemarkEmitter legacy analysis pass.
static void warnAboutLeftoverTransformations(Loop *L, OptimizationRemarkEmitter *ORE)
Emit warnings for forced (i.e.
The legacy pass manager&#39;s analysis pass to compute loop information.
Definition: LoopInfo.h:977
A container for analyses that lazily runs them and caches their results.
#define LLVM_DEBUG(X)
Definition: Debug.h:122
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
The optimization diagnostic interface.