1 //===--- InfoByHwMode.h -----------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 // Classes that implement data parameterized by HW modes for instruction
10 // selection. Currently it is ValueTypeByHwMode (parameterized ValueType),
11 // and RegSizeInfoByHwMode (parameterized register/spill size and alignment
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_UTILS_TABLEGEN_INFOBYHWMODE_H
16 #define LLVM_UTILS_TABLEGEN_INFOBYHWMODE_H
18 #include "CodeGenHwModes.h"
19 #include "llvm/CodeGen/MachineValueType.h"
28 struct CodeGenHwModes;
32 template <typename InfoT> struct InfoByHwMode;
34 std::string getModeName(unsigned Mode);
37 DefaultMode = CodeGenHwModes::DefaultMode,
40 template <typename InfoT>
41 std::vector<unsigned> union_modes(const InfoByHwMode<InfoT> &A,
42 const InfoByHwMode<InfoT> &B) {
43 std::vector<unsigned> V;
45 for (const auto &P : A)
47 for (const auto &P : B)
49 // Make sure that the default mode is last on the list.
50 bool HasDefault = U.count(DefaultMode);
55 V.push_back(DefaultMode);
59 template <typename InfoT>
61 typedef std::map<unsigned,InfoT> MapType;
62 typedef typename MapType::value_type PairType;
63 typedef typename MapType::iterator iterator;
64 typedef typename MapType::const_iterator const_iterator;
66 InfoByHwMode() = default;
67 InfoByHwMode(const MapType &M) : Map(M) {}
69 LLVM_ATTRIBUTE_ALWAYS_INLINE
70 iterator begin() { return Map.begin(); }
71 LLVM_ATTRIBUTE_ALWAYS_INLINE
72 iterator end() { return Map.end(); }
73 LLVM_ATTRIBUTE_ALWAYS_INLINE
74 const_iterator begin() const { return Map.begin(); }
75 LLVM_ATTRIBUTE_ALWAYS_INLINE
76 const_iterator end() const { return Map.end(); }
77 LLVM_ATTRIBUTE_ALWAYS_INLINE
78 bool empty() const { return Map.empty(); }
80 LLVM_ATTRIBUTE_ALWAYS_INLINE
81 bool hasMode(unsigned M) const { return Map.find(M) != Map.end(); }
82 LLVM_ATTRIBUTE_ALWAYS_INLINE
83 bool hasDefault() const { return hasMode(DefaultMode); }
85 InfoT &get(unsigned Mode) {
87 assert(hasMode(DefaultMode));
88 Map.insert({Mode, Map.at(DefaultMode)});
92 const InfoT &get(unsigned Mode) const {
93 auto F = Map.find(Mode);
94 if (Mode != DefaultMode && F == Map.end())
95 F = Map.find(DefaultMode);
96 assert(F != Map.end());
100 LLVM_ATTRIBUTE_ALWAYS_INLINE
101 bool isSimple() const {
102 return Map.size() == 1 && Map.begin()->first == DefaultMode;
104 LLVM_ATTRIBUTE_ALWAYS_INLINE
105 InfoT getSimple() const {
107 return Map.begin()->second;
109 void makeSimple(unsigned Mode) {
110 assert(hasMode(Mode) || hasDefault());
113 Map.insert(std::make_pair(DefaultMode, I));
119 struct ValueTypeByHwMode : public InfoByHwMode<MVT> {
120 ValueTypeByHwMode(Record *R, const CodeGenHwModes &CGH);
121 ValueTypeByHwMode(MVT T) { Map.insert({DefaultMode,T}); }
122 ValueTypeByHwMode() = default;
124 bool operator== (const ValueTypeByHwMode &T) const;
125 bool operator< (const ValueTypeByHwMode &T) const;
127 bool isValid() const {
130 MVT getType(unsigned Mode) const { return get(Mode); }
131 MVT &getOrCreateTypeForMode(unsigned Mode, MVT Type);
133 static StringRef getMVTName(MVT T);
134 void writeToStream(raw_ostream &OS) const;
138 ValueTypeByHwMode getValueTypeByHwMode(Record *Rec,
139 const CodeGenHwModes &CGH);
144 unsigned SpillAlignment;
146 RegSizeInfo(Record *R, const CodeGenHwModes &CGH);
147 RegSizeInfo() = default;
148 bool operator< (const RegSizeInfo &I) const;
149 bool operator== (const RegSizeInfo &I) const {
150 return std::tie(RegSize, SpillSize, SpillAlignment) ==
151 std::tie(I.RegSize, I.SpillSize, I.SpillAlignment);
153 bool operator!= (const RegSizeInfo &I) const {
154 return !(*this == I);
157 bool isSubClassOf(const RegSizeInfo &I) const;
158 void writeToStream(raw_ostream &OS) const;
161 struct RegSizeInfoByHwMode : public InfoByHwMode<RegSizeInfo> {
162 RegSizeInfoByHwMode(Record *R, const CodeGenHwModes &CGH);
163 RegSizeInfoByHwMode() = default;
164 bool operator< (const RegSizeInfoByHwMode &VI) const;
165 bool operator== (const RegSizeInfoByHwMode &VI) const;
166 bool operator!= (const RegSizeInfoByHwMode &VI) const {
167 return !(*this == VI);
170 bool isSubClassOf(const RegSizeInfoByHwMode &I) const;
171 bool hasStricterSpillThan(const RegSizeInfoByHwMode &I) const;
173 void writeToStream(raw_ostream &OS) const;
176 raw_ostream &operator<<(raw_ostream &OS, const ValueTypeByHwMode &T);
177 raw_ostream &operator<<(raw_ostream &OS, const RegSizeInfo &T);
178 raw_ostream &operator<<(raw_ostream &OS, const RegSizeInfoByHwMode &T);
182 #endif // LLVM_UTILS_TABLEGEN_INFOBYHWMODE_H