Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
Line
Count
Source
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
13
#include "llvm/Transforms/Scalar/WarnMissedTransforms.h"
14
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
15
#include "llvm/Transforms/Utils/LoopUtils.h"
16
17
using namespace llvm;
18
19
29
#define DEBUG_TYPE "transform-warning"
20
21
/// Emit warnings for forced (i.e. user-defined) loop transformations which have
22
/// still not been performed.
23
static void warnAboutLeftoverTransformations(Loop *L,
24
184k
                                             OptimizationRemarkEmitter *ORE) {
25
184k
  if (hasUnrollTransformation(L) == TM_ForcedByUser) {
26
4
    LLVM_DEBUG(dbgs() << "Leftover unroll transformation\n");
27
4
    ORE->emit(
28
4
        DiagnosticInfoOptimizationFailure(DEBUG_TYPE,
29
4
                                          "FailedRequestedUnrolling",
30
4
                                          L->getStartLoc(), L->getHeader())
31
4
        << "loop not unrolled: the optimizer was unable to perform the "
32
4
           "requested transformation; the transformation might be disabled or "
33
4
           "specified as part of an unsupported transformation ordering");
34
4
  }
35
184k
36
184k
  if (hasUnrollAndJamTransformation(L) == TM_ForcedByUser) {
37
4
    LLVM_DEBUG(dbgs() << "Leftover unroll-and-jam transformation\n");
38
4
    ORE->emit(
39
4
        DiagnosticInfoOptimizationFailure(DEBUG_TYPE,
40
4
                                          "FailedRequestedUnrollAndJamming",
41
4
                                          L->getStartLoc(), L->getHeader())
42
4
        << "loop not unroll-and-jammed: the optimizer was unable to perform "
43
4
           "the requested transformation; the transformation might be disabled "
44
4
           "or specified as part of an unsupported transformation ordering");
45
4
  }
46
184k
47
184k
  if (hasVectorizeTransformation(L) == TM_ForcedByUser) {
48
17
    LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
49
17
    Optional<int> VectorizeWidth =
50
17
        getOptionalIntLoopAttribute(L, "llvm.loop.vectorize.width");
51
17
    Optional<int> InterleaveCount =
52
17
        getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
53
17
54
17
    if (VectorizeWidth.getValueOr(0) != 1)
55
16
      ORE->emit(
56
16
          DiagnosticInfoOptimizationFailure(DEBUG_TYPE,
57
16
                                            "FailedRequestedVectorization",
58
16
                                            L->getStartLoc(), L->getHeader())
59
16
          << "loop not vectorized: the optimizer was unable to perform the "
60
16
             "requested transformation; the transformation might be disabled "
61
16
             "or specified as part of an unsupported transformation ordering");
62
1
    else if (InterleaveCount.getValueOr(0) != 1)
63
1
      ORE->emit(
64
1
          DiagnosticInfoOptimizationFailure(DEBUG_TYPE,
65
1
                                            "FailedRequestedInterleaving",
66
1
                                            L->getStartLoc(), L->getHeader())
67
1
          << "loop not interleaved: the optimizer was unable to perform the "
68
1
             "requested transformation; the transformation might be disabled "
69
1
             "or specified as part of an unsupported transformation ordering");
70
17
  }
71
184k
72
184k
  if (hasDistributeTransformation(L) == TM_ForcedByUser) {
73
4
    LLVM_DEBUG(dbgs() << "Leftover distribute transformation\n");
74
4
    ORE->emit(
75
4
        DiagnosticInfoOptimizationFailure(DEBUG_TYPE,
76
4
                                          "FailedRequestedDistribution",
77
4
                                          L->getStartLoc(), L->getHeader())
78
4
        << "loop not distributed: the optimizer was unable to perform the "
79
4
           "requested transformation; the transformation might be disabled or "
80
4
           "specified as part of an unsupported transformation ordering");
81
4
  }
82
184k
}
83
84
static void warnAboutLeftoverTransformations(Function *F, LoopInfo *LI,
85
279k
                                             OptimizationRemarkEmitter *ORE) {
86
279k
  for (auto *L : LI->getLoopsInPreorder())
87
184k
    warnAboutLeftoverTransformations(L, ORE);
88
279k
}
89
90
// New pass manager boilerplate
91
PreservedAnalyses
92
877
WarnMissedTransformationsPass::run(Function &F, FunctionAnalysisManager &AM) {
93
877
  // Do not warn about not applied transformations if optimizations are
94
877
  // disabled.
95
877
  if (F.hasOptNone())
96
3
    return PreservedAnalyses::all();
97
874
98
874
  auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
99
874
  auto &LI = AM.getResult<LoopAnalysis>(F);
100
874
101
874
  warnAboutLeftoverTransformations(&F, &LI, &ORE);
102
874
103
874
  return PreservedAnalyses::all();
104
874
}
105
106
// Legacy pass manager boilerplate
107
namespace {
108
class WarnMissedTransformationsLegacy : public FunctionPass {
109
public:
110
  static char ID;
111
112
13.4k
  explicit WarnMissedTransformationsLegacy() : FunctionPass(ID) {
113
13.4k
    initializeWarnMissedTransformationsLegacyPass(
114
13.4k
        *PassRegistry::getPassRegistry());
115
13.4k
  }
116
117
278k
  bool runOnFunction(Function &F) override {
118
278k
    if (skipFunction(F))
119
45
      return false;
120
278k
121
278k
    auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
122
278k
    auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
123
278k
124
278k
    warnAboutLeftoverTransformations(&F, &LI, &ORE);
125
278k
    return false;
126
278k
  }
127
128
13.4k
  void getAnalysisUsage(AnalysisUsage &AU) const override {
129
13.4k
    AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
130
13.4k
    AU.addRequired<LoopInfoWrapperPass>();
131
13.4k
132
13.4k
    AU.setPreservesAll();
133
13.4k
  }
134
};
135
} // end anonymous namespace
136
137
char WarnMissedTransformationsLegacy::ID = 0;
138
139
48.9k
INITIALIZE_PASS_BEGIN(WarnMissedTransformationsLegacy, "transform-warning",
140
48.9k
                      "Warn about non-applied transformations", false, false)
141
48.9k
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
142
48.9k
INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
143
48.9k
INITIALIZE_PASS_END(WarnMissedTransformationsLegacy, "transform-warning",
144
                    "Warn about non-applied transformations", false, false)
145
146
13.4k
Pass *llvm::createWarnMissedTransformationsPass() {
147
13.4k
  return new WarnMissedTransformationsLegacy();
148
13.4k
}