LLVM  8.0.1
WarnMissedTransforms.cpp
Go to the documentation of this file.
1 //===- LoopTransformWarning.cpp - ----------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Emit warnings if forced code transformations have not been performed.
11 //
12 //===----------------------------------------------------------------------===//
13 
17 
18 using 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  Optional<int> VectorizeWidth =
51  getOptionalIntLoopAttribute(L, "llvm.loop.vectorize.width");
52  Optional<int> InterleaveCount =
53  getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
54 
55  if (VectorizeWidth.getValueOr(0) != 1)
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.getValueOr(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.
97  return PreservedAnalyses::all();
98 
100  auto &LI = AM.getResult<LoopAnalysis>(F);
101 
102  warnAboutLeftoverTransformations(&F, &LI, &ORE);
103 
104  return PreservedAnalyses::all();
105 }
106 
107 // Legacy pass manager boilerplate
108 namespace {
109 class WarnMissedTransformationsLegacy : public FunctionPass {
110 public:
111  static char ID;
112 
113  explicit WarnMissedTransformationsLegacy() : FunctionPass(ID) {
116  }
117 
118  bool runOnFunction(Function &F) override {
119  if (skipFunction(F))
120  return false;
121 
122  auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
123  auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
124 
125  warnAboutLeftoverTransformations(&F, &LI, &ORE);
126  return false;
127  }
128 
129  void getAnalysisUsage(AnalysisUsage &AU) const override {
132 
133  AU.setPreservesAll();
134  }
135 };
136 } // end anonymous namespace
137 
139 
140 INITIALIZE_PASS_BEGIN(WarnMissedTransformationsLegacy, "transform-warning",
141  "Warn about non-applied transformations", false, false)
144 INITIALIZE_PASS_END(WarnMissedTransformationsLegacy, "transform-warning",
145  "Warn about non-applied transformations", false, false)
146 
148  return new WarnMissedTransformationsLegacy();
149 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
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:770
This class represents lattice values for constants.
Definition: AllocatorList.h:24
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:172
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:321
F(f)
transform warning
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
Diagnostic information for optimization failures.
TransformationMode hasUnrollAndJamTransformation(Loop *L)
Definition: LoopUtils.cpp:352
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:945
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:154
llvm::Optional< int > getOptionalIntLoopAttribute(Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
Definition: LoopUtils.cpp:232
transform Warn about non applied transformations
Represent the analysis usage information of a pass.
TransformationMode hasDistributeTransformation(Loop *L)
Definition: LoopUtils.cpp:405
TransformationMode hasVectorizeTransformation(Loop *L)
Definition: LoopUtils.cpp:370
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
Pass * createWarnMissedTransformationsPass()
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
Definition: LoopInfo.cpp:365
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:229
#define DEBUG_TYPE
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
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:331
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:1268
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:583
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:970
A container for analyses that lazily runs them and caches their results.
#define LLVM_DEBUG(X)
Definition: Debug.h:123
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
The optimization diagnostic interface.