LLVM  8.0.1
VPlanValue.h
Go to the documentation of this file.
1 //===- VPlanValue.h - Represent Values in Vectorizer Plan -----------------===//
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 /// \file
11 /// This file contains the declarations of the entities induced by Vectorization
12 /// Plans, e.g. the instructions the VPlan intends to generate if executed.
13 /// VPlan models the following entities:
14 /// VPValue
15 /// |-- VPUser
16 /// | |-- VPInstruction
17 /// These are documented in docs/VectorizationPlan.rst.
18 ///
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
22 #define LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
23 
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/IR/Value.h"
27 #include "llvm/Support/Debug.h"
29 
30 namespace llvm {
31 
32 // Forward declarations.
33 class VPUser;
34 
35 // This is the base class of the VPlan Def/Use graph, used for modeling the data
36 // flow into, within and out of the VPlan. VPValues can stand for live-ins
37 // coming from the input IR, instructions which VPlan will generate if executed
38 // and live-outs which the VPlan will need to fix accordingly.
39 class VPValue {
40  friend class VPBuilder;
41  friend class VPlanHCFGTransforms;
42  friend class VPBasicBlock;
44 
45 private:
46  const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
47 
49 
50 protected:
51  // Hold the underlying Value, if any, attached to this VPValue.
53 
54  VPValue(const unsigned char SC, Value *UV = nullptr)
55  : SubclassID(SC), UnderlyingVal(UV) {}
56 
57  // DESIGN PRINCIPLE: Access to the underlying IR must be strictly limited to
58  // the front-end and back-end of VPlan so that the middle-end is as
59  // independent as possible of the underlying IR. We grant access to the
60  // underlying IR using friendship. In that way, we should be able to use VPlan
61  // for multiple underlying IRs (Polly?) by providing a new VPlan front-end,
62  // back-end and analysis information for the new IR.
63 
64  /// Return the underlying Value attached to this VPValue.
66 
67  // Set \p Val as the underlying Value of this VPValue.
69  assert(!UnderlyingVal && "Underlying Value is already set.");
70  UnderlyingVal = Val;
71  }
72 
73 public:
74  /// An enumeration for keeping track of the concrete subclass of VPValue that
75  /// are actually instantiated. Values of this enumeration are kept in the
76  /// SubclassID field of the VPValue objects. They are used for concrete
77  /// type identification.
79 
80  VPValue(Value *UV = nullptr) : VPValue(VPValueSC, UV) {}
81  VPValue(const VPValue &) = delete;
82  VPValue &operator=(const VPValue &) = delete;
83 
84  /// \return an ID for the concrete type of this object.
85  /// This is used to implement the classof checks. This should not be used
86  /// for any other purpose, as the values may change as LLVM evolves.
87  unsigned getVPValueID() const { return SubclassID; }
88 
89  void printAsOperand(raw_ostream &OS) const {
90  OS << "%vp" << (unsigned short)(unsigned long long)this;
91  }
92 
93  unsigned getNumUsers() const { return Users.size(); }
94  void addUser(VPUser &User) { Users.push_back(&User); }
95 
100 
101  user_iterator user_begin() { return Users.begin(); }
102  const_user_iterator user_begin() const { return Users.begin(); }
103  user_iterator user_end() { return Users.end(); }
104  const_user_iterator user_end() const { return Users.end(); }
105  user_range users() { return user_range(user_begin(), user_end()); }
106  const_user_range users() const {
107  return const_user_range(user_begin(), user_end());
108  }
109 
110  /// Returns true if the value has more than one unique user.
112  if (getNumUsers() == 0)
113  return false;
114 
115  // Check if all users match the first user.
116  auto Current = std::next(user_begin());
117  while (Current != user_end() && *user_begin() == *Current)
118  Current++;
119  return Current != user_end();
120  }
121 
122  void replaceAllUsesWith(VPValue *New);
123 };
124 
127 
128 raw_ostream &operator<<(raw_ostream &OS, const VPValue &V);
129 
130 /// This class augments VPValue with operands which provide the inverse def-use
131 /// edges from VPValue's users to their defs.
132 class VPUser : public VPValue {
133 private:
134  SmallVector<VPValue *, 2> Operands;
135 
136 protected:
137  VPUser(const unsigned char SC) : VPValue(SC) {}
138  VPUser(const unsigned char SC, ArrayRef<VPValue *> Operands) : VPValue(SC) {
139  for (VPValue *Operand : Operands)
140  addOperand(Operand);
141  }
142 
143 public:
145  VPUser(ArrayRef<VPValue *> Operands) : VPUser(VPValue::VPUserSC, Operands) {}
146  VPUser(std::initializer_list<VPValue *> Operands)
147  : VPUser(ArrayRef<VPValue *>(Operands)) {}
148  VPUser(const VPUser &) = delete;
149  VPUser &operator=(const VPUser &) = delete;
150 
151  /// Method to support type inquiry through isa, cast, and dyn_cast.
152  static inline bool classof(const VPValue *V) {
153  return V->getVPValueID() >= VPUserSC &&
155  }
156 
157  void addOperand(VPValue *Operand) {
158  Operands.push_back(Operand);
159  Operand->addUser(*this);
160  }
161 
162  unsigned getNumOperands() const { return Operands.size(); }
163  inline VPValue *getOperand(unsigned N) const {
164  assert(N < Operands.size() && "Operand index out of bounds");
165  return Operands[N];
166  }
167 
168  void setOperand(unsigned I, VPValue *New) { Operands[I] = New; }
169 
174 
175  operand_iterator op_begin() { return Operands.begin(); }
176  const_operand_iterator op_begin() const { return Operands.begin(); }
177  operand_iterator op_end() { return Operands.end(); }
178  const_operand_iterator op_end() const { return Operands.end(); }
179  operand_range operands() { return operand_range(op_begin(), op_end()); }
180  const_operand_range operands() const {
181  return const_operand_range(op_begin(), op_end());
182  }
183 };
184 
185 } // namespace llvm
186 
187 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
iterator_range< user_iterator > user_range
Definition: VPlanValue.h:98
DenseMap< VPValue *, Value * > VPValue2ValueTy
Definition: VPlanValue.h:126
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:328
This class represents lattice values for constants.
Definition: AllocatorList.h:24
SmallVectorImpl< VPValue * >::const_iterator const_operand_iterator
Definition: VPlanValue.h:171
bool hasMoreThanOneUniqueUser()
Returns true if the value has more than one unique user.
Definition: VPlanValue.h:111
void setUnderlyingValue(Value *Val)
Definition: VPlanValue.h:68
user_range users()
Definition: VPlanValue.h:105
iv Induction Variable Users
Definition: IVUsers.cpp:52
VPValue * getOperand(unsigned N) const
Definition: VPlanValue.h:163
SmallVectorImpl< VPValue * >::iterator operand_iterator
Definition: VPlanValue.h:170
VPValue(const unsigned char SC, Value *UV=nullptr)
Definition: VPlanValue.h:54
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
iterator_range< const_operand_iterator > const_operand_range
Definition: VPlanValue.h:173
user_iterator user_end()
Definition: VPlanValue.h:103
VPUser(const unsigned char SC)
Definition: VPlanValue.h:137
SmallVectorImpl< VPUser * >::const_iterator const_user_iterator
Definition: VPlanValue.h:97
operand_range operands()
Definition: VPlanValue.h:179
const_operand_range operands() const
Definition: VPlanValue.h:180
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
unsigned getVPValueID() const
Definition: VPlanValue.h:87
operand_iterator op_end()
Definition: VPlanValue.h:177
void setOperand(unsigned I, VPValue *New)
Definition: VPlanValue.h:168
Value * getUnderlyingValue()
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:65
This class augments VPValue with operands which provide the inverse def-use edges from VPValue&#39;s user...
Definition: VPlanValue.h:132
VPUser(const unsigned char SC, ArrayRef< VPValue *> Operands)
Definition: VPlanValue.h:138
VPlan-based builder utility analogous to IRBuilder.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
void addUser(VPUser &User)
Definition: VPlanValue.h:94
user_iterator user_begin()
Definition: VPlanValue.h:101
const_user_range users() const
Definition: VPlanValue.h:106
void printAsOperand(raw_ostream &OS) const
Definition: VPlanValue.h:89
const_user_iterator user_begin() const
Definition: VPlanValue.h:102
const_operand_iterator op_begin() const
Definition: VPlanValue.h:176
size_t size() const
Definition: SmallVector.h:53
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:965
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Value * UnderlyingVal
Definition: VPlanValue.h:52
CHAIN = SC CHAIN, Imm128 - System call.
const_operand_iterator op_end() const
Definition: VPlanValue.h:178
A range adaptor for a pair of iterators.
iterator_range< const_user_iterator > const_user_range
Definition: VPlanValue.h:99
VPValue & operator=(const VPValue &)=delete
iterator_range< operand_iterator > operand_range
Definition: VPlanValue.h:172
typename SuperClass::iterator iterator
Definition: SmallVector.h:327
void replaceAllUsesWith(VPValue *New)
Definition: VPlan.cpp:690
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
static bool classof(const VPValue *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlanValue.h:152
VPUser(std::initializer_list< VPValue *> Operands)
Definition: VPlanValue.h:146
operand_iterator op_begin()
Definition: VPlanValue.h:175
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
DenseMap< Value *, VPValue * > Value2VPValueTy
Definition: VPlanValue.h:125
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2039
unsigned getNumOperands() const
Definition: VPlanValue.h:162
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
unsigned getNumUsers() const
Definition: VPlanValue.h:93
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
SmallVectorImpl< VPUser * >::iterator user_iterator
Definition: VPlanValue.h:96
VPUser(ArrayRef< VPValue *> Operands)
Definition: VPlanValue.h:145
VPValue(Value *UV=nullptr)
Definition: VPlanValue.h:80
const_user_iterator user_end() const
Definition: VPlanValue.h:104
void addOperand(VPValue *Operand)
Definition: VPlanValue.h:157