Coverage Report

Created: 2017-06-27 13:53

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/include/polly/Support/VirtualInstruction.h
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
#ifndef POLLY_SUPPORT_VIRTUALINSTRUCTION_H
16
#define POLLY_SUPPORT_VIRTUALINSTRUCTION_H
17
18
#include "polly/ScopInfo.h"
19
20
namespace polly {
21
22
/// Determine the nature of a value's use within a statement.
23
///
24
/// These are not always representable by llvm::Use. For instance, scalar write
25
/// MemoryAccesses do use a value, but are not associated with an instruction's
26
/// argument.
27
///
28
/// Despite its name it is not tied to virtual instructions (although it works
29
/// fine with them), but to promote consistent handling of values used in
30
/// statements.
31
class VirtualUse {
32
public:
33
  /// The different types of uses. Handling usually differentiates a lot between
34
  /// these; one can use a switch to handle each case (and get warned by the
35
  /// compiler if one is not handled).
36
  enum UseKind {
37
    // An llvm::Constant.
38
    Constant,
39
40
    // An llvm::BasicBlock.
41
    Block,
42
43
    // A value that can be generated using ScopExpander.
44
    Synthesizable,
45
46
    // A load that always reads the same value throughout the SCoP (address and
47
    // the value located there a SCoP-invariant) and has been hoisted in front
48
    // of the SCoP.
49
    Hoisted,
50
51
    // Definition before the SCoP and not synthesizable. Can be an instruction
52
    // outside the SCoP, a function argument or a global value. Whether there is
53
    // a scalar MemoryAccess in this statement for reading it depends on the
54
    // -polly-analyze-read-only-scalars switch.
55
    ReadOnly,
56
57
    // A definition within the same statement. No MemoryAccess between
58
    // definition and use are necessary.
59
    Intra,
60
61
    // Definition in another statement. There is a scalar MemoryAccess that
62
    // makes it available in this statement.
63
    Inter
64
  };
65
66
private:
67
  /// The statement where a value is used.
68
  ScopStmt *User;
69
70
  /// The value that is used.
71
  Value *Val;
72
73
  /// The type of value use.
74
  UseKind Kind;
75
76
  /// The value represented as llvm::SCEV expression.
77
  const SCEV *ScevExpr;
78
79
  /// If this is an inter-statement (or read-only) use, contains the
80
  /// MemoryAccess that makes the value available in this statement. In case of
81
  /// intra-statement uses, can contain a MemoryKind::Array access. In all other
82
  /// cases, it is a nullptr.
83
  MemoryAccess *InputMA;
84
85
  VirtualUse(ScopStmt *User, Value *Val, UseKind Kind, const SCEV *ScevExpr,
86
             MemoryAccess *InputMA)
87
25.9k
      : User(User), Val(Val), Kind(Kind), ScevExpr(ScevExpr), InputMA(InputMA) {
88
25.9k
  }
89
90
public:
91
  /// Get a VirtualUse for an llvm::Use.
92
  ///
93
  /// @param S       The Scop object.
94
  /// @param U       The llvm::Use the get information for.
95
  /// @param LI      The LoopInfo analysis. Needed to determine whether the
96
  ///                value is synthesizable.
97
  /// @param Virtual Whether to ignore existing MemoryAcccess.
98
  ///
99
  /// @return The VirtualUse representing the same use as @p U.
100
  static VirtualUse create(Scop *S, Use &U, LoopInfo *LI, bool Virtual);
101
102
  /// Get a VirtualUse for any kind of use of a value within a statement.
103
  ///
104
  /// @param S         The Scop object.
105
  /// @param UserStmt  The statement in which @p Val is used. Can be nullptr, in
106
  ///                  which case it assumed that the statement has been
107
  ///                  removed, which is only possible if no instruction in it
108
  ///                  had side-effects or computes a value used by another
109
  ///                  statement.
110
  /// @param UserScope Loop scope in which the value is used. Needed to
111
  ///                  determine whether the value is synthesizable.
112
  /// @param Val       The value being used.
113
  /// @param Virtual   Whether to use (and prioritize over instruction location)
114
  ///                  information about MemoryAccesses.
115
  ///
116
  /// @return A VirtualUse object that gives information about @p Val's use in
117
  ///         @p UserStmt.
118
  static VirtualUse create(Scop *S, ScopStmt *UserStmt, Loop *UserScope,
119
                           Value *Val, bool Virtual);
120
121
  static VirtualUse create(ScopStmt *UserStmt, Loop *UserScope, Value *Val,
122
2.19k
                           bool Virtual) {
123
2.19k
    return create(UserStmt->getParent(), UserStmt, UserScope, Val, Virtual);
124
2.19k
  }
125
126
0
  bool isConstant() const { return Kind == Constant; }
127
0
  bool isBlock() const { return Kind == Block; }
128
0
  bool isSynthesizable() const { return Kind == Synthesizable; }
129
0
  bool isHoisted() const { return Kind == Hoisted; }
130
0
  bool isReadOnly() const { return Kind == ReadOnly; }
131
0
  bool isIntra() const { return Kind == Intra; }
132
301
  bool isInter() const { return Kind == Inter; }
133
134
  /// Return user statement.
135
0
  ScopStmt *getUser() const { return User; }
136
137
  /// Return the used value.
138
0
  llvm::Value *getValue() const { return Val; }
139
140
  /// Return the type of use.
141
25.9k
  UseKind getKind() const { return Kind; }
142
143
  /// Return the ScalarEvolution representation of @p Val.
144
1
  const SCEV *getScevExpr() const { return ScevExpr; }
145
146
  /// Return the MemoryAccess that makes the value available in this statement,
147
  /// if any.
148
0
  MemoryAccess *getMemoryAccess() const { return InputMA; }
149
150
  /// Print a description of this object.
151
  ///
152
  /// @param OS           Stream to print to.
153
  /// @param Reproducible If true, ensures that the output is stable between
154
  /// runs and is suitable to check in regression tests. This excludes printing
155
  /// e.g. pointer values.
156
  ///                     If false, the output should not be used for regression
157
  ///                     tests, but may contain more information useful in
158
  ///                     debugger sessions.
159
  void print(raw_ostream &OS, bool Reproducible = true) const;
160
161
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
162
  void dump() const;
163
#endif
164
};
165
166
} // namespace polly
167
168
#endif /* POLLY_SUPPORT_VIRTUALINSTRUCTION_H */