LLVM  5.0.0
RDFRegisters.h
Go to the documentation of this file.
1 //===--- RDFRegisters.h -----------------------------------------*- 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 #ifndef LLVM_LIB_TARGET_HEXAGON_RDFREGISTERS_H
11 #define LLVM_LIB_TARGET_HEXAGON_RDFREGISTERS_H
12 
13 #include "llvm/ADT/BitVector.h"
15 
16 #include <set>
17 #include <unordered_map>
18 #include <vector>
19 
20 namespace llvm {
21 namespace rdf {
22 
24 
25  // Template class for a map translating uint32_t into arbitrary types.
26  // The map will act like an indexed set: upon insertion of a new object,
27  // it will automatically assign a new index to it. Index of 0 is treated
28  // as invalid and is never allocated.
29  template <typename T, unsigned N = 32>
30  struct IndexedSet {
31  IndexedSet() : Map() { Map.reserve(N); }
32 
33  T get(uint32_t Idx) const {
34  // Index Idx corresponds to Map[Idx-1].
35  assert(Idx != 0 && !Map.empty() && Idx-1 < Map.size());
36  return Map[Idx-1];
37  }
38 
39  uint32_t insert(T Val) {
40  // Linear search.
41  auto F = llvm::find(Map, Val);
42  if (F != Map.end())
43  return F - Map.begin() + 1;
44  Map.push_back(Val);
45  return Map.size(); // Return actual_index + 1.
46  }
47 
48  uint32_t find(T Val) const {
49  auto F = llvm::find(Map, Val);
50  assert(F != Map.end());
51  return F - Map.begin() + 1;
52  }
53 
54  uint32_t size() const { return Map.size(); }
55 
56  typedef typename std::vector<T>::const_iterator const_iterator;
57  const_iterator begin() const { return Map.begin(); }
58  const_iterator end() const { return Map.end(); }
59 
60  private:
61  std::vector<T> Map;
62  };
63 
64  struct RegisterRef {
67 
68  RegisterRef() = default;
70  : Reg(R), Mask(R != 0 ? M : LaneBitmask::getNone()) {}
71 
72  operator bool() const {
73  return Reg != 0 && Mask.any();
74  }
75  bool operator== (const RegisterRef &RR) const {
76  return Reg == RR.Reg && Mask == RR.Mask;
77  }
78  bool operator!= (const RegisterRef &RR) const {
79  return !operator==(RR);
80  }
81  bool operator< (const RegisterRef &RR) const {
82  return Reg < RR.Reg || (Reg == RR.Reg && Mask < RR.Mask);
83  }
84  };
85 
86 
89  const MachineFunction &mf);
90 
91  static bool isRegMaskId(RegisterId R) {
93  }
95  return TargetRegisterInfo::index2StackSlot(RegMasks.find(RM));
96  }
98  return RegMasks.get(TargetRegisterInfo::stackSlot2Index(R));
99  }
101 
102  bool alias(RegisterRef RA, RegisterRef RB) const {
103  if (!isRegMaskId(RA.Reg))
104  return !isRegMaskId(RB.Reg) ? aliasRR(RA, RB) : aliasRM(RA, RB);
105  return !isRegMaskId(RB.Reg) ? aliasRM(RB, RA) : aliasMM(RA, RB);
106  }
107  std::set<RegisterId> getAliasSet(RegisterId Reg) const;
108 
110  return RegisterRef(UnitInfos[U].Reg, UnitInfos[U].Mask);
111  }
112  const BitVector &getMaskUnits(RegisterId MaskId) const {
113  return MaskInfos[TargetRegisterInfo::stackSlot2Index(MaskId)].Units;
114  }
115  RegisterRef mapTo(RegisterRef RR, unsigned R) const;
116 
117  const TargetRegisterInfo &getTRI() const { return TRI; }
118 
119  private:
120  struct RegInfo {
121  const TargetRegisterClass *RegClass = nullptr;
122  };
123  struct UnitInfo {
124  RegisterId Reg = 0;
126  };
127  struct MaskInfo {
128  BitVector Units;
129  };
130 
131  const TargetRegisterInfo &TRI;
132  IndexedSet<const uint32_t*> RegMasks;
133  std::vector<RegInfo> RegInfos;
134  std::vector<UnitInfo> UnitInfos;
135  std::vector<MaskInfo> MaskInfos;
136 
137  bool aliasRR(RegisterRef RA, RegisterRef RB) const;
138  bool aliasRM(RegisterRef RR, RegisterRef RM) const;
139  bool aliasMM(RegisterRef RM, RegisterRef RN) const;
140  };
141 
142 
143  struct RegisterAggr {
145  : Units(pri.getTRI().getNumRegUnits()), PRI(pri) {}
146  RegisterAggr(const RegisterAggr &RG) = default;
147 
148  bool empty() const { return Units.none(); }
149  bool hasAliasOf(RegisterRef RR) const;
150  bool hasCoverOf(RegisterRef RR) const;
151  static bool isCoverOf(RegisterRef RA, RegisterRef RB,
152  const PhysicalRegisterInfo &PRI) {
153  return RegisterAggr(PRI).insert(RA).hasCoverOf(RB);
154  }
155 
157  RegisterAggr &insert(const RegisterAggr &RG);
159  RegisterAggr &intersect(const RegisterAggr &RG);
161  RegisterAggr &clear(const RegisterAggr &RG);
162 
164  RegisterRef clearIn(RegisterRef RR) const;
165  RegisterRef makeRegRef() const;
166 
167  void print(raw_ostream &OS) const;
168 
169  struct rr_iterator {
170  typedef std::map<RegisterId,LaneBitmask> MapType;
171  private:
172  MapType Masks;
173  MapType::iterator Pos;
174  unsigned Index;
175  const RegisterAggr *Owner;
176  public:
177  rr_iterator(const RegisterAggr &RG, bool End);
179  return RegisterRef(Pos->first, Pos->second);
180  }
182  ++Pos;
183  ++Index;
184  return *this;
185  }
186  bool operator==(const rr_iterator &I) const {
187  assert(Owner == I.Owner);
188  return Index == I.Index;
189  }
190  bool operator!=(const rr_iterator &I) const {
191  return !(*this == I);
192  }
193  };
194 
196  return rr_iterator(*this, false);
197  }
198  rr_iterator rr_end() const {
199  return rr_iterator(*this, true);
200  }
201 
202  private:
203  BitVector Units;
204  const PhysicalRegisterInfo &PRI;
205  };
206 
207 
208  // Optionally print the lane mask, if it is not ~0.
212  };
214 
215 } // namespace rdf
216 } // namespace llvm
217 
218 #endif
219 
raw_ostream & operator<<(raw_ostream &OS, const PrintLaneMaskOpt &P)
Definition: RDFGraph.cpp:47
std::set< RegisterId > getAliasSet(RegisterId Reg) const
PrintLaneMaskOpt(LaneBitmask M)
Definition: RDFRegisters.h:210
const_iterator end() const
Definition: RDFRegisters.h:58
bool none() const
none - Returns true if none of the bits are set.
Definition: BitVector.h:202
rr_iterator rr_end() const
Definition: RDFRegisters.h:198
bool operator==(const RegisterRef &RR) const
Definition: RDFRegisters.h:75
static LaneBitmask getAll()
Definition: LaneBitmask.h:77
uint32_t RegisterId
Definition: RDFRegisters.h:23
RegisterId getRegMaskId(const uint32_t *RM) const
Definition: RDFRegisters.h:94
RegisterRef(RegisterId R, LaneBitmask M=LaneBitmask::getAll())
Definition: RDFRegisters.h:69
static int stackSlot2Index(unsigned Reg)
Compute the frame index from a register value representing a stack slot.
uint32_t size() const
Definition: RDFRegisters.h:54
Reg
All possible values of the reg field in the ModR/M byte.
constexpr bool any() const
Definition: LaneBitmask.h:53
RegisterRef mapTo(RegisterRef RR, unsigned R) const
std::vector< T >::const_iterator const_iterator
Definition: RDFRegisters.h:56
#define F(x, y, z)
Definition: MD5.cpp:55
RegisterRef makeRegRef() const
T get(uint32_t Idx) const
Definition: RDFRegisters.h:33
void print(raw_ostream &OS) const
uint32_t find(T Val) const
Definition: RDFRegisters.h:48
uint32_t insert(T Val)
Definition: RDFRegisters.h:39
const_iterator begin() const
Definition: RDFRegisters.h:57
PhysicalRegisterInfo(const TargetRegisterInfo &tri, const MachineFunction &mf)
RegisterAggr & clear(RegisterRef RR)
const TargetRegisterInfo & getTRI() const
Definition: RDFRegisters.h:117
#define P(N)
bool hasCoverOf(RegisterRef RR) const
static const unsigned End
bool operator!=(const RegisterRef &RR) const
Definition: RDFRegisters.h:78
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const BitVector & getMaskUnits(RegisterId MaskId) const
Definition: RDFRegisters.h:112
RegisterRef intersectWith(RegisterRef RR) const
static bool isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful the be able to store a non-negative frame index in a variable th...
RegisterAggr & insert(RegisterRef RR)
RegisterRef normalize(RegisterRef RR) const
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:839
RegisterAggr(const PhysicalRegisterInfo &pri)
Definition: RDFRegisters.h:144
bool operator!=(const rr_iterator &I) const
Definition: RDFRegisters.h:190
static LaneBitmask getNone()
Definition: LaneBitmask.h:76
bool alias(RegisterRef RA, RegisterRef RB) const
Definition: RDFRegisters.h:102
const size_t N
rr_iterator(const RegisterAggr &RG, bool End)
const uint32_t * getRegMaskBits(RegisterId R) const
Definition: RDFRegisters.h:97
RegisterRef getRefForUnit(uint32_t U) const
Definition: RDFRegisters.h:109
RegisterRef clearIn(RegisterRef RR) const
std::map< RegisterId, LaneBitmask > MapType
Definition: RDFRegisters.h:170
#define I(x, y, z)
Definition: MD5.cpp:58
bool operator<(const RegisterRef &RR) const
Definition: RDFRegisters.h:81
rr_iterator rr_begin() const
Definition: RDFRegisters.h:195
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isRegMaskId(RegisterId R)
Definition: RDFRegisters.h:91
static bool isCoverOf(RegisterRef RA, RegisterRef RB, const PhysicalRegisterInfo &PRI)
Definition: RDFRegisters.h:151
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
bool hasAliasOf(RegisterRef RR) const
bool operator==(const rr_iterator &I) const
Definition: RDFRegisters.h:186
static unsigned index2StackSlot(int FI)
Convert a non-negative frame index to a stack slot register value.
RegisterAggr & intersect(RegisterRef RR)