Coverage Report

Created: 2017-05-24 08:03

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/Support/VirtualInstruction.cpp
Line
Count
Source (jump to first uncovered line)
1
//===------ VirtualInstruction.cpp ------------------------------*- C++ -*-===//
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
// Tools for determining which instructions are within a statement and the
11
// nature of their operands.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "polly/Support/VirtualInstruction.h"
16
#include "polly/Support/SCEVValidator.h"
17
18
using namespace polly;
19
using namespace llvm;
20
21
0
VirtualUse VirtualUse ::create(Scop *S, Use &U, LoopInfo *LI, bool Virtual) {
22
0
  auto *UserBB = getUseBlock(U);
23
0
  auto *UserStmt = S->getStmtFor(UserBB);
24
0
  auto *UserScope = LI->getLoopFor(UserBB);
25
0
  return create(S, UserStmt, UserScope, U.get(), Virtual);
26
0
}
27
28
VirtualUse VirtualUse::create(Scop *S, ScopStmt *UserStmt, Loop *UserScope,
29
25.0k
                              Value *Val, bool Virtual) {
30
25.0k
  assert(!isa<StoreInst>(Val) && "a StoreInst cannot be used");
31
25.0k
32
25.0k
  if (isa<BasicBlock>(Val))
33
536
    return VirtualUse(UserStmt, Val, Block, nullptr, nullptr);
34
25.0k
35
24.5k
  
if (24.5k
isa<llvm::Constant>(Val)24.5k
)
36
6.23k
    return VirtualUse(UserStmt, Val, Constant, nullptr, nullptr);
37
24.5k
38
24.5k
  // Is the value synthesizable? If the user has been pruned
39
24.5k
  // (UserStmt == nullptr), it is either not used anywhere or is synthesizable.
40
24.5k
  // We assume synthesizable which practically should have the same effect.
41
18.2k
  auto *SE = S->getSE();
42
18.2k
  if (
SE->isSCEVable(Val->getType())18.2k
)
{16.7k
43
16.7k
    auto *ScevExpr = SE->getSCEVAtScope(Val, UserScope);
44
16.7k
    if (
!UserStmt || 16.7k
canSynthesize(Val, *UserStmt->getParent(), SE, UserScope)16.7k
)
45
13.3k
      return VirtualUse(UserStmt, Val, Synthesizable, ScevExpr, nullptr);
46
16.7k
  }
47
18.2k
48
18.2k
  // FIXME: Inconsistency between lookupInvariantEquivClass and
49
18.2k
  // getRequiredInvariantLoads. Querying one of them should be enough.
50
4.96k
  auto &RIL = S->getRequiredInvariantLoads();
51
4.96k
  if (
S->lookupInvariantEquivClass(Val) || 4.96k
RIL.count(dyn_cast<LoadInst>(Val))4.86k
)
52
459
    return VirtualUse(UserStmt, Val, Hoisted, nullptr, nullptr);
53
4.96k
54
4.96k
  // ReadOnly uses may have MemoryAccesses that we want to associate with the
55
4.96k
  // use. This is why we look for a MemoryAccess here already.
56
4.50k
  MemoryAccess *InputMA = nullptr;
57
4.50k
  if (
UserStmt && 4.50k
Virtual4.50k
)
58
721
    InputMA = UserStmt->lookupValueReadOf(Val);
59
4.50k
60
4.50k
  // Uses are read-only if they have been defined before the SCoP, i.e., they
61
4.50k
  // cannot be written to inside the SCoP. Arguments are defined before any
62
4.50k
  // instructions, hence also before the SCoP. If the user has been pruned
63
4.50k
  // (UserStmt == nullptr) and is not SCEVable, assume it is read-only as it is
64
4.50k
  // neither an intra- nor an inter-use.
65
4.50k
  if (
!UserStmt || 4.50k
isa<Argument>(Val)4.50k
)
66
47
    return VirtualUse(UserStmt, Val, ReadOnly, nullptr, InputMA);
67
4.50k
68
4.45k
  auto Inst = cast<Instruction>(Val);
69
4.45k
  if (!S->contains(Inst))
70
19
    return VirtualUse(UserStmt, Val, ReadOnly, nullptr, InputMA);
71
4.45k
72
4.45k
  // A use is inter-statement if either it is defined in another statement, or
73
4.45k
  // there is a MemoryAccess that reads its value that has been written by
74
4.45k
  // another statement.
75
4.43k
  
if (4.43k
InputMA || 4.43k
(!Virtual && 4.37k
!UserStmt->contains(Inst->getParent())3.73k
))
76
336
    return VirtualUse(UserStmt, Val, Inter, nullptr, InputMA);
77
4.43k
78
4.10k
  return VirtualUse(UserStmt, Val, Intra, nullptr, nullptr);
79
4.43k
}
80
81
0
void VirtualUse::print(raw_ostream &OS, bool Reproducible) const {
82
0
  OS << "User: [" << User->getBaseName() << "] ";
83
0
  switch (Kind) {
84
0
  case VirtualUse::Constant:
85
0
    OS << "Constant Op:";
86
0
    break;
87
0
  case VirtualUse::Block:
88
0
    OS << "BasicBlock Op:";
89
0
    break;
90
0
  case VirtualUse::Synthesizable:
91
0
    OS << "Synthesizable Op:";
92
0
    break;
93
0
  case VirtualUse::Hoisted:
94
0
    OS << "Hoisted load Op:";
95
0
    break;
96
0
  case VirtualUse::ReadOnly:
97
0
    OS << "Read-Only Op:";
98
0
    break;
99
0
  case VirtualUse::Intra:
100
0
    OS << "Intra Op:";
101
0
    break;
102
0
  case VirtualUse::Inter:
103
0
    OS << "Inter Op:";
104
0
    break;
105
0
  }
106
0
107
0
  
if (0
Val0
)
{0
108
0
    OS << ' ';
109
0
    if (Reproducible)
110
0
      OS << '"' << Val->getName() << '"';
111
0
    else
112
0
      Val->print(OS, true);
113
0
  }
114
0
  if (
ScevExpr0
)
{0
115
0
    OS << ' ';
116
0
    ScevExpr->print(OS);
117
0
  }
118
0
  if (
InputMA && 0
!Reproducible0
)
119
0
    OS << ' ' << InputMA;
120
0
}
121
122
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
123
void VirtualUse::dump() const {
124
  print(errs(), false);
125
  errs() << '\n';
126
}
127
#endif