LLVM  7.0.0
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 private:
42  const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
43 
45 
46 protected:
47  // Hold the underlying Value, if any, attached to this VPValue.
49 
50  VPValue(const unsigned char SC, Value *UV = nullptr)
51  : SubclassID(SC), UnderlyingVal(UV) {}
52 
53  // DESIGN PRINCIPLE: Access to the underlying IR must be strictly limited to
54  // the front-end and back-end of VPlan so that the middle-end is as
55  // independent as possible of the underlying IR. We grant access to the
56  // underlying IR using friendship. In that way, we should be able to use VPlan
57  // for multiple underlying IRs (Polly?) by providing a new VPlan front-end,
58  // back-end and analysis information for the new IR.
59 
60  /// Return the underlying Value attached to this VPValue.
62 
63  // Set \p Val as the underlying Value of this VPValue.
65  assert(!UnderlyingVal && "Underlying Value is already set.");
66  UnderlyingVal = Val;
67  }
68 
69 public:
70  /// An enumeration for keeping track of the concrete subclass of VPValue that
71  /// are actually instantiated. Values of this enumeration are kept in the
72  /// SubclassID field of the VPValue objects. They are used for concrete
73  /// type identification.
75 
76  VPValue(Value *UV = nullptr) : VPValue(VPValueSC, UV) {}
77  VPValue(const VPValue &) = delete;
78  VPValue &operator=(const VPValue &) = delete;
79 
80  /// \return an ID for the concrete type of this object.
81  /// This is used to implement the classof checks. This should not be used
82  /// for any other purpose, as the values may change as LLVM evolves.
83  unsigned getVPValueID() const { return SubclassID; }
84 
85  void printAsOperand(raw_ostream &OS) const {
86  OS << "%vp" << (unsigned short)(unsigned long long)this;
87  }
88 
89  unsigned getNumUsers() const { return Users.size(); }
90  void addUser(VPUser &User) { Users.push_back(&User); }
91 
96 
97  user_iterator user_begin() { return Users.begin(); }
98  const_user_iterator user_begin() const { return Users.begin(); }
99  user_iterator user_end() { return Users.end(); }
100  const_user_iterator user_end() const { return Users.end(); }
101  user_range users() { return user_range(user_begin(), user_end()); }
102  const_user_range users() const {
103  return const_user_range(user_begin(), user_end());
104  }
105 };
106 
109 
110 raw_ostream &operator<<(raw_ostream &OS, const VPValue &V);
111 
112 /// This class augments VPValue with operands which provide the inverse def-use
113 /// edges from VPValue's users to their defs.
114 class VPUser : public VPValue {
115 private:
116  SmallVector<VPValue *, 2> Operands;
117 
118 protected:
119  VPUser(const unsigned char SC) : VPValue(SC) {}
120  VPUser(const unsigned char SC, ArrayRef<VPValue *> Operands) : VPValue(SC) {
121  for (VPValue *Operand : Operands)
122  addOperand(Operand);
123  }
124 
125 public:
127  VPUser(ArrayRef<VPValue *> Operands) : VPUser(VPValue::VPUserSC, Operands) {}
128  VPUser(std::initializer_list<VPValue *> Operands)
129  : VPUser(ArrayRef<VPValue *>(Operands)) {}
130  VPUser(const VPUser &) = delete;
131  VPUser &operator=(const VPUser &) = delete;
132 
133  /// Method to support type inquiry through isa, cast, and dyn_cast.
134  static inline bool classof(const VPValue *V) {
135  return V->getVPValueID() >= VPUserSC &&
137  }
138 
139  void addOperand(VPValue *Operand) {
140  Operands.push_back(Operand);
141  Operand->addUser(*this);
142  }
143 
144  unsigned getNumOperands() const { return Operands.size(); }
145  inline VPValue *getOperand(unsigned N) const {
146  assert(N < Operands.size() && "Operand index out of bounds");
147  return Operands[N];
148  }
149 
154 
155  operand_iterator op_begin() { return Operands.begin(); }
156  const_operand_iterator op_begin() const { return Operands.begin(); }
157  operand_iterator op_end() { return Operands.end(); }
158  const_operand_iterator op_end() const { return Operands.end(); }
159  operand_range operands() { return operand_range(op_begin(), op_end()); }
160  const_operand_range operands() const {
161  return const_operand_range(op_begin(), op_end());
162  }
163 };
164 
165 } // namespace llvm
166 
167 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
iterator_range< user_iterator > user_range
Definition: VPlanValue.h:94
DenseMap< VPValue *, Value * > VPValue2ValueTy
Definition: VPlanValue.h:108
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:328
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
SmallVectorImpl< VPValue * >::const_iterator const_operand_iterator
Definition: VPlanValue.h:151
void setUnderlyingValue(Value *Val)
Definition: VPlanValue.h:64
user_range users()
Definition: VPlanValue.h:101
iv Induction Variable Users
Definition: IVUsers.cpp:52
VPValue * getOperand(unsigned N) const
Definition: VPlanValue.h:145
SmallVectorImpl< VPValue * >::iterator operand_iterator
Definition: VPlanValue.h:150
VPValue(const unsigned char SC, Value *UV=nullptr)
Definition: VPlanValue.h:50
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
iterator_range< const_operand_iterator > const_operand_range
Definition: VPlanValue.h:153
user_iterator user_end()
Definition: VPlanValue.h:99
VPUser(const unsigned char SC)
Definition: VPlanValue.h:119
SmallVectorImpl< VPUser * >::const_iterator const_user_iterator
Definition: VPlanValue.h:93
operand_range operands()
Definition: VPlanValue.h:159
const_operand_range operands() const
Definition: VPlanValue.h:160
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:83
operand_iterator op_end()
Definition: VPlanValue.h:157
Value * getUnderlyingValue()
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:61
This class augments VPValue with operands which provide the inverse def-use edges from VPValue&#39;s user...
Definition: VPlanValue.h:114
VPUser(const unsigned char SC, ArrayRef< VPValue *> Operands)
Definition: VPlanValue.h:120
VPlan-based builder utility analogous to IRBuilder.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
void addUser(VPUser &User)
Definition: VPlanValue.h:90
user_iterator user_begin()
Definition: VPlanValue.h:97
const_user_range users() const
Definition: VPlanValue.h:102
void printAsOperand(raw_ostream &OS) const
Definition: VPlanValue.h:85
const_user_iterator user_begin() const
Definition: VPlanValue.h:98
const_operand_iterator op_begin() const
Definition: VPlanValue.h:156
size_t size() const
Definition: SmallVector.h:53
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:48
CHAIN = SC CHAIN, Imm128 - System call.
const_operand_iterator op_end() const
Definition: VPlanValue.h:158
A range adaptor for a pair of iterators.
iterator_range< const_user_iterator > const_user_range
Definition: VPlanValue.h:95
VPValue & operator=(const VPValue &)=delete
iterator_range< operand_iterator > operand_range
Definition: VPlanValue.h:152
typename SuperClass::iterator iterator
Definition: SmallVector.h:327
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:134
VPUser(std::initializer_list< VPValue *> Operands)
Definition: VPlanValue.h:128
operand_iterator op_begin()
Definition: VPlanValue.h:155
#define N
DenseMap< Value *, VPValue * > Value2VPValueTy
Definition: VPlanValue.h:107
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2032
unsigned getNumOperands() const
Definition: VPlanValue.h:144
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
unsigned getNumUsers() const
Definition: VPlanValue.h:89
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:92
VPUser(ArrayRef< VPValue *> Operands)
Definition: VPlanValue.h:127
VPValue(Value *UV=nullptr)
Definition: VPlanValue.h:76
const_user_iterator user_end() const
Definition: VPlanValue.h:100
void addOperand(VPValue *Operand)
Definition: VPlanValue.h:139