LLVM  14.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 
14 #include "llvm/Analysis/LoopInfo.h"
16 #include "llvm/InitializePasses.h"
18 
19 using 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  Optional<ElementCount> VectorizeWidth =
53  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.getValueOr(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())
98  return PreservedAnalyses::all();
99 
101  auto &LI = AM.getResult<LoopAnalysis>(F);
102 
103  warnAboutLeftoverTransformations(&F, &LI, &ORE);
104 
105  return PreservedAnalyses::all();
106 }
107 
108 // Legacy pass manager boilerplate
109 namespace {
110 class WarnMissedTransformationsLegacy : public FunctionPass {
111 public:
112  static char ID;
113 
114  explicit WarnMissedTransformationsLegacy() : FunctionPass(ID) {
117  }
118 
119  bool runOnFunction(Function &F) override {
120  if (skipFunction(F))
121  return false;
122 
123  auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
124  auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
125 
126  warnAboutLeftoverTransformations(&F, &LI, &ORE);
127  return false;
128  }
129 
130  void getAnalysisUsage(AnalysisUsage &AU) const override {
133 
134  AU.setPreservesAll();
135  }
136 };
137 } // end anonymous namespace
138 
140 
141 INITIALIZE_PASS_BEGIN(WarnMissedTransformationsLegacy, "transform-warning",
142  "Warn about non-applied transformations", false, false)
145 INITIALIZE_PASS_END(WarnMissedTransformationsLegacy, "transform-warning",
146  "Warn about non-applied transformations", false, false)
147 
149  return new WarnMissedTransformationsLegacy();
150 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm::hasUnrollTransformation
TransformationMode hasUnrollTransformation(const Loop *L)
Definition: LoopUtils.cpp:360
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:783
llvm::Function
Definition: Function.h:62
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
llvm::Loop::getStartLoc
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
Definition: LoopInfo.cpp:633
OptimizationRemarkEmitter.h
llvm::LoopInfoWrapperPass
The legacy pass manager's analysis pass to compute loop information.
Definition: LoopInfo.h:1268
llvm::Optional
Definition: APInt.h:33
warning
transform warning
Definition: WarnMissedTransforms.cpp:145
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::hasDistributeTransformation
TransformationMode hasDistributeTransformation(const Loop *L)
Definition: LoopUtils.cpp:435
llvm::getOptionalIntLoopAttribute
llvm::Optional< int > getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
Definition: LoopInfo.cpp:1091
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:142
llvm::initializeWarnMissedTransformationsLegacyPass
void initializeWarnMissedTransformationsLegacyPass(PassRegistry &)
transformations
transform Warn about non applied transformations
Definition: WarnMissedTransforms.cpp:146
LoopUtils.h
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
LoopInfo.h
llvm::WarnMissedTransformationsPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: WarnMissedTransforms.cpp:94
llvm::Optional::getValueOr
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:297
llvm::hasUnrollAndJamTransformation
TransformationMode hasUnrollAndJamTransformation(const Loop *L)
Definition: LoopUtils.cpp:381
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::OptimizationRemarkEmitter::emit
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Output the remark via the diagnostic handler and to the optimization record file.
Definition: OptimizationRemarkEmitter.cpp:77
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(WarnMissedTransformationsLegacy, "transform-warning", "Warn about non-applied transformations", false, false) INITIALIZE_PASS_END(WarnMissedTransformationsLegacy
llvm::ElementCount::isVector
bool isVector() const
One or more elements.
Definition: TypeSize.h:398
llvm::LoopInfo
Definition: LoopInfo.h:1083
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::TM_ForcedByUser
@ TM_ForcedByUser
The transformation was directed by the user, e.g.
Definition: LoopUtils.h:283
llvm::getOptionalElementCountLoopAttribute
Optional< ElementCount > getOptionalElementCountLoopAttribute(const Loop *TheLoop)
Find a combination of metadata ("llvm.loop.vectorize.width" and "llvm.loop.vectorize....
Definition: LoopUtils.cpp:258
llvm::transform
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
Definition: STLExtras.h:1648
DEBUG_TYPE
#define DEBUG_TYPE
Definition: WarnMissedTransforms.cpp:21
llvm::LoopInfoBase::getLoopsInPreorder
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:578
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
llvm::OptimizationRemarkEmitterWrapperPass
OptimizationRemarkEmitter legacy analysis pass.
Definition: OptimizationRemarkEmitter.h:146
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
llvm::LoopBase::getHeader
BlockT * getHeader() const
Definition: LoopInfo.h:104
llvm::DiagnosticInfoOptimizationFailure
Diagnostic information for optimization failures.
Definition: DiagnosticInfo.h:972
WarnMissedTransforms.h
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::hasVectorizeTransformation
TransformationMode hasVectorizeTransformation(const Loop *L)
Definition: LoopUtils.cpp:399
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::createWarnMissedTransformationsPass
Pass * createWarnMissedTransformationsPass()
Definition: WarnMissedTransforms.cpp:148
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
InitializePasses.h
llvm::OptimizationRemarkEmitterAnalysis
Definition: OptimizationRemarkEmitter.h:164
llvm::LoopAnalysis
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:1243
warnAboutLeftoverTransformations
static void warnAboutLeftoverTransformations(Loop *L, OptimizationRemarkEmitter *ORE)
Emit warnings for forced (i.e.
Definition: WarnMissedTransforms.cpp:25
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37