1 //===- VPlanValue.h - Represent Values in Vectorizer Plan -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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:
16 /// | |-- VPInstruction
17 /// These are documented in docs/VectorizationPlan.rst.
19 //===----------------------------------------------------------------------===//
21 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
22 #define LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/IR/Value.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/raw_ostream.h"
32 // Forward declarations.
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.
41 const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
43 SmallVector<VPUser *, 1> Users;
46 VPValue(const unsigned char SC) : SubclassID(SC) {}
49 /// An enumeration for keeping track of the concrete subclass of VPValue that
50 /// are actually instantiated. Values of this enumeration are kept in the
51 /// SubclassID field of the VPValue objects. They are used for concrete
52 /// type identification.
53 enum { VPValueSC, VPUserSC, VPInstructionSC };
55 VPValue() : SubclassID(VPValueSC) {}
56 VPValue(const VPValue &) = delete;
57 VPValue &operator=(const VPValue &) = delete;
59 /// \return an ID for the concrete type of this object.
60 /// This is used to implement the classof checks. This should not be used
61 /// for any other purpose, as the values may change as LLVM evolves.
62 unsigned getVPValueID() const { return SubclassID; }
64 void printAsOperand(raw_ostream &OS) const {
65 OS << "%vp" << (unsigned short)(unsigned long long)this;
68 unsigned getNumUsers() const { return Users.size(); }
69 void addUser(VPUser &User) { Users.push_back(&User); }
71 typedef SmallVectorImpl<VPUser *>::iterator user_iterator;
72 typedef SmallVectorImpl<VPUser *>::const_iterator const_user_iterator;
73 typedef iterator_range<user_iterator> user_range;
74 typedef iterator_range<const_user_iterator> const_user_range;
76 user_iterator user_begin() { return Users.begin(); }
77 const_user_iterator user_begin() const { return Users.begin(); }
78 user_iterator user_end() { return Users.end(); }
79 const_user_iterator user_end() const { return Users.end(); }
80 user_range users() { return user_range(user_begin(), user_end()); }
81 const_user_range users() const {
82 return const_user_range(user_begin(), user_end());
86 typedef DenseMap<Value *, VPValue *> Value2VPValueTy;
87 typedef DenseMap<VPValue *, Value *> VPValue2ValueTy;
89 raw_ostream &operator<<(raw_ostream &OS, const VPValue &V);
91 /// This class augments VPValue with operands which provide the inverse def-use
92 /// edges from VPValue's users to their defs.
93 class VPUser : public VPValue {
95 SmallVector<VPValue *, 2> Operands;
97 void addOperand(VPValue *Operand) {
98 Operands.push_back(Operand);
99 Operand->addUser(*this);
103 VPUser(const unsigned char SC) : VPValue(SC) {}
104 VPUser(const unsigned char SC, ArrayRef<VPValue *> Operands) : VPValue(SC) {
105 for (VPValue *Operand : Operands)
110 VPUser() : VPValue(VPValue::VPUserSC) {}
111 VPUser(ArrayRef<VPValue *> Operands) : VPUser(VPValue::VPUserSC, Operands) {}
112 VPUser(std::initializer_list<VPValue *> Operands)
113 : VPUser(ArrayRef<VPValue *>(Operands)) {}
114 VPUser(const VPUser &) = delete;
115 VPUser &operator=(const VPUser &) = delete;
117 /// Method to support type inquiry through isa, cast, and dyn_cast.
118 static inline bool classof(const VPValue *V) {
119 return V->getVPValueID() >= VPUserSC &&
120 V->getVPValueID() <= VPInstructionSC;
123 unsigned getNumOperands() const { return Operands.size(); }
124 inline VPValue *getOperand(unsigned N) const {
125 assert(N < Operands.size() && "Operand index out of bounds");
129 typedef SmallVectorImpl<VPValue *>::iterator operand_iterator;
130 typedef SmallVectorImpl<VPValue *>::const_iterator const_operand_iterator;
131 typedef iterator_range<operand_iterator> operand_range;
132 typedef iterator_range<const_operand_iterator> const_operand_range;
134 operand_iterator op_begin() { return Operands.begin(); }
135 const_operand_iterator op_begin() const { return Operands.begin(); }
136 operand_iterator op_end() { return Operands.end(); }
137 const_operand_iterator op_end() const { return Operands.end(); }
138 operand_range operands() { return operand_range(op_begin(), op_end()); }
139 const_operand_range operands() const {
140 return const_operand_range(op_begin(), op_end());
146 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H