Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/Analysis/ScopPass.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ScopPass.cpp - The base class of Passes that operate on Polly IR ---===//
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
// This file contains the definitions of the ScopPass members.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "polly/ScopPass.h"
14
#include "polly/ScopInfo.h"
15
16
#include "llvm/Analysis/AssumptionCache.h"
17
#include "llvm/Analysis/BasicAliasAnalysis.h"
18
#include "llvm/Analysis/GlobalsModRef.h"
19
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
20
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
21
#include "llvm/Analysis/TargetTransformInfo.h"
22
23
using namespace llvm;
24
using namespace polly;
25
26
6.56k
bool ScopPass::runOnRegion(Region *R, RGPassManager &RGM) {
27
6.56k
  S = nullptr;
28
6.56k
29
6.56k
  if (skipRegion(*R))
30
0
    return false;
31
6.56k
32
6.56k
  if ((S = getAnalysis<ScopInfoRegionPass>().getScop()))
33
1.62k
    return runOnScop(*S);
34
4.94k
35
4.94k
  return false;
36
4.94k
}
37
38
1.95k
void ScopPass::print(raw_ostream &OS, const Module *M) const {
39
1.95k
  if (S)
40
457
    printScop(OS, *S);
41
1.95k
}
42
43
962
void ScopPass::getAnalysisUsage(AnalysisUsage &AU) const {
44
962
  AU.addRequired<ScopInfoRegionPass>();
45
962
46
962
  AU.addPreserved<AAResultsWrapperPass>();
47
962
  AU.addPreserved<BasicAAWrapperPass>();
48
962
  AU.addPreserved<LoopInfoWrapperPass>();
49
962
  AU.addPreserved<DominatorTreeWrapperPass>();
50
962
  AU.addPreserved<GlobalsAAWrapperPass>();
51
962
  AU.addPreserved<ScopDetectionWrapperPass>();
52
962
  AU.addPreserved<ScalarEvolutionWrapperPass>();
53
962
  AU.addPreserved<SCEVAAWrapperPass>();
54
962
  AU.addPreserved<OptimizationRemarkEmitterWrapperPass>();
55
962
  AU.addPreserved<RegionInfoPass>();
56
962
  AU.addPreserved<ScopInfoRegionPass>();
57
962
  AU.addPreserved<TargetTransformInfoWrapperPass>();
58
962
}
59
60
namespace polly {
61
template class OwningInnerAnalysisManagerProxy<ScopAnalysisManager, Function>;
62
}
63
64
namespace llvm {
65
66
template class PassManager<Scop, ScopAnalysisManager,
67
                           ScopStandardAnalysisResults &, SPMUpdater &>;
68
template class InnerAnalysisManagerProxy<ScopAnalysisManager, Function>;
69
template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Scop,
70
                                         ScopStandardAnalysisResults &>;
71
72
template <>
73
PreservedAnalyses
74
PassManager<Scop, ScopAnalysisManager, ScopStandardAnalysisResults &,
75
            SPMUpdater &>::run(Scop &S, ScopAnalysisManager &AM,
76
0
                               ScopStandardAnalysisResults &AR, SPMUpdater &U) {
77
0
  auto PA = PreservedAnalyses::all();
78
0
  for (auto &Pass : Passes) {
79
0
    auto PassPA = Pass->run(S, AM, AR, U);
80
0
81
0
    AM.invalidate(S, PassPA);
82
0
    PA.intersect(std::move(PassPA));
83
0
  }
84
0
85
0
  // All analyses for 'this' Scop have been invalidated above.
86
0
  // If ScopPasses affect break other scops they have to propagate this
87
0
  // information through the updater
88
0
  PA.preserveSet<AllAnalysesOn<Scop>>();
89
0
  return PA;
90
0
}
91
92
bool ScopAnalysisManagerFunctionProxy::Result::invalidate(
93
    Function &F, const PreservedAnalyses &PA,
94
0
    FunctionAnalysisManager::Invalidator &Inv) {
95
0
96
0
  // First, check whether our ScopInfo is about to be invalidated
97
0
  auto PAC = PA.getChecker<ScopAnalysisManagerFunctionProxy>();
98
0
  if (!(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>()) ||
99
0
      Inv.invalidate<ScopInfoAnalysis>(F, PA) ||
100
0
      Inv.invalidate<ScalarEvolutionAnalysis>(F, PA) ||
101
0
      Inv.invalidate<LoopAnalysis>(F, PA) ||
102
0
      Inv.invalidate<DominatorTreeAnalysis>(F, PA)) {
103
0
104
0
    // As everything depends on ScopInfo, we must drop all existing results
105
0
    for (auto &S : *SI)
106
0
      if (auto *scop = S.second.get())
107
0
        if (InnerAM)
108
0
          InnerAM->clear(*scop, scop->getName());
109
0
110
0
    InnerAM = nullptr;
111
0
    return true; // Invalidate the proxy result as well.
112
0
  }
113
0
114
0
  bool allPreserved = PA.allAnalysesInSetPreserved<AllAnalysesOn<Scop>>();
115
0
116
0
  // Invalidate all non-preserved analyses
117
0
  // Even if all analyses were preserved, we still need to run deferred
118
0
  // invalidation
119
0
  for (auto &S : *SI) {
120
0
    Optional<PreservedAnalyses> InnerPA;
121
0
    auto *scop = S.second.get();
122
0
    if (!scop)
123
0
      continue;
124
0
125
0
    if (auto *OuterProxy =
126
0
            InnerAM->getCachedResult<FunctionAnalysisManagerScopProxy>(*scop)) {
127
0
      for (const auto &InvPair : OuterProxy->getOuterInvalidations()) {
128
0
        auto *OuterAnalysisID = InvPair.first;
129
0
        const auto &InnerAnalysisIDs = InvPair.second;
130
0
131
0
        if (Inv.invalidate(OuterAnalysisID, F, PA)) {
132
0
          if (!InnerPA)
133
0
            InnerPA = PA;
134
0
          for (auto *InnerAnalysisID : InnerAnalysisIDs)
135
0
            InnerPA->abandon(InnerAnalysisID);
136
0
        }
137
0
      }
138
0
139
0
      if (InnerPA) {
140
0
        InnerAM->invalidate(*scop, *InnerPA);
141
0
        continue;
142
0
      }
143
0
    }
144
0
145
0
    if (!allPreserved)
146
0
      InnerAM->invalidate(*scop, PA);
147
0
  }
148
0
149
0
  return false; // This proxy is still valid
150
0
}
151
152
template <>
153
ScopAnalysisManagerFunctionProxy::Result
154
ScopAnalysisManagerFunctionProxy::run(Function &F,
155
0
                                      FunctionAnalysisManager &FAM) {
156
0
  return Result(*InnerAM, FAM.getResult<ScopInfoAnalysis>(F));
157
0
}
158
} // namespace llvm
159
160
namespace polly {
161
template <>
162
OwningScopAnalysisManagerFunctionProxy::Result
163
OwningScopAnalysisManagerFunctionProxy::run(Function &F,
164
0
                                            FunctionAnalysisManager &FAM) {
165
0
  return Result(InnerAM, FAM.getResult<ScopInfoAnalysis>(F));
166
0
}
167
} // namespace polly