llvm.org GIT mirror llvm / be43b88
[TableGen] Merge RecTy::typeIsConvertibleTo and RecTy::baseClassOf. NFC typeIsConvertibleTo was just calling baseClassOf(this) on the argument passed to it, but there weren't different signatures for baseClassOf so passing 'this' didn't really do anything interesting. typeIsConvertibleTo could have just been a non-virtual method in RecTy. But since that would be kind of a silly method, I instead re-distributed the logic from baseClassOf into typeIsConvertibleTo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238648 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 5 years ago
2 changed file(s) with 22 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
8080 private:
8181 RecTyKind Kind;
8282 std::unique_ptr ListTy;
83 virtual void anchor();
8483
8584 public:
8685 RecTyKind getRecTyKind() const { return Kind; }
9493
9594 /// typeIsConvertibleTo - Return true if all values of 'this' type can be
9695 /// converted to the specified type.
97 virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
96 virtual bool typeIsConvertibleTo(const RecTy *RHS) const;
9897
9998 /// getListTy - Returns the type representing list.
10099 ListRecTy *getListTy();
101
102 virtual bool baseClassOf(const RecTy*) const;
103100 };
104101
105102 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
122119
123120 std::string getAsString() const override { return "bit"; }
124121
125 bool typeIsConvertibleTo(const RecTy *RHS) const override {
126 return RHS->baseClassOf(this);
127 }
128 bool baseClassOf(const RecTy*) const override;
122 bool typeIsConvertibleTo(const RecTy *RHS) const override;
129123 };
130124
131125 /// BitsRecTy - 'bits' - Represent a fixed number of bits
145139
146140 std::string getAsString() const override;
147141
148 bool typeIsConvertibleTo(const RecTy *RHS) const override {
149 return RHS->baseClassOf(this);
150 }
151 bool baseClassOf(const RecTy*) const override;
142 bool typeIsConvertibleTo(const RecTy *RHS) const override;
152143 };
153144
154145 /// IntRecTy - 'int' - Represent an integer value of no particular size
166157
167158 std::string getAsString() const override { return "int"; }
168159
169 bool typeIsConvertibleTo(const RecTy *RHS) const override {
170 return RHS->baseClassOf(this);
171 }
172
173 bool baseClassOf(const RecTy*) const override;
160 bool typeIsConvertibleTo(const RecTy *RHS) const override;
174161 };
175162
176163 /// StringRecTy - 'string' - Represent an string value
179166 static StringRecTy Shared;
180167 StringRecTy() : RecTy(StringRecTyKind) {}
181168
182 void anchor() override;
169 virtual void anchor();
183170 public:
184171 static bool classof(const RecTy *RT) {
185172 return RT->getRecTyKind() == StringRecTyKind;
188175 static StringRecTy *get() { return &Shared; }
189176
190177 std::string getAsString() const override { return "string"; }
191
192 bool typeIsConvertibleTo(const RecTy *RHS) const override {
193 return RHS->baseClassOf(this);
194 }
195178 };
196179
197180 /// ListRecTy - 'list' - Represent a list of values, all of which must be of
212195
213196 std::string getAsString() const override;
214197
215 bool typeIsConvertibleTo(const RecTy *RHS) const override {
216 return RHS->baseClassOf(this);
217 }
218
219 bool baseClassOf(const RecTy*) const override;
198 bool typeIsConvertibleTo(const RecTy *RHS) const override;
220199 };
221200
222201 /// DagRecTy - 'dag' - Represent a dag fragment
225204 static DagRecTy Shared;
226205 DagRecTy() : RecTy(DagRecTyKind) {}
227206
228 void anchor() override;
207 virtual void anchor();
229208 public:
230209 static bool classof(const RecTy *RT) {
231210 return RT->getRecTyKind() == DagRecTyKind;
234213 static DagRecTy *get() { return &Shared; }
235214
236215 std::string getAsString() const override { return "dag"; }
237
238 bool typeIsConvertibleTo(const RecTy *RHS) const override {
239 return RHS->baseClassOf(this);
240 }
241216 };
242217
243218 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
259234
260235 std::string getAsString() const override;
261236
262 bool typeIsConvertibleTo(const RecTy *RHS) const override {
263 return RHS->baseClassOf(this);
264 }
265 bool baseClassOf(const RecTy*) const override;
237 bool typeIsConvertibleTo(const RecTy *RHS) const override;
266238 };
267239
268240 /// resolveTypes - Find a common type that T1 and T2 convert to.
8585 StringRecTy StringRecTy::Shared;
8686 DagRecTy DagRecTy::Shared;
8787
88 void RecTy::anchor() { }
8988 void RecTy::dump() const { print(errs()); }
9089
9190 void StringRecTy::anchor() { }
9796 return ListTy.get();
9897 }
9998
100 bool RecTy::baseClassOf(const RecTy *RHS) const {
101 assert (RHS && "NULL pointer");
99 bool RecTy::typeIsConvertibleTo(const RecTy *RHS) const {
100 assert(RHS && "NULL pointer");
102101 return Kind == RHS->getRecTyKind();
103102 }
104103
105 bool BitRecTy::baseClassOf(const RecTy *RHS) const{
106 if(RecTy::baseClassOf(RHS) || RHS->getRecTyKind() == IntRecTyKind)
104 bool BitRecTy::typeIsConvertibleTo(const RecTy *RHS) const{
105 if(RecTy::typeIsConvertibleTo(RHS) || RHS->getRecTyKind() == IntRecTyKind)
107106 return true;
108107 if(const BitsRecTy *BitsTy = dyn_cast(RHS))
109108 return BitsTy->getNumBits() == 1;
124123 return "bits<" + utostr(Size) + ">";
125124 }
126125
127 bool BitsRecTy::baseClassOf(const RecTy *RHS) const{
128 if (RecTy::baseClassOf(RHS)) //argument and the receiver are the same type
126 bool BitsRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
127 if (RecTy::typeIsConvertibleTo(RHS)) //argument and the sender are same type
129128 return cast(RHS)->Size == Size;
130129 RecTyKind kind = RHS->getRecTyKind();
131130 return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
132131 }
133132
134 bool IntRecTy::baseClassOf(const RecTy *RHS) const{
133 bool IntRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
135134 RecTyKind kind = RHS->getRecTyKind();
136135 return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
137136 }
141140 return "list<" + Ty->getAsString() + ">";
142141 }
143142
144 bool ListRecTy::baseClassOf(const RecTy *RHS) const{
145 if(const ListRecTy* ListTy = dyn_cast(RHS))
146 return ListTy->getElementType()->typeIsConvertibleTo(Ty);
143 bool ListRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
144 if (const auto *ListTy = dyn_cast(RHS))
145 return Ty->typeIsConvertibleTo(ListTy->getElementType());
147146 return false;
148147 }
149148
155154 return Rec->getName();
156155 }
157156
158 bool RecordRecTy::baseClassOf(const RecTy *RHS) const{
157 bool RecordRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
159158 const RecordRecTy *RTy = dyn_cast(RHS);
160159 if (!RTy)
161160 return false;
162161
163 if (Rec == RTy->getRecord() || RTy->getRecord()->isSubClassOf(Rec))
162 if (RTy->getRecord() == Rec || Rec->isSubClassOf(RTy->getRecord()))
164163 return true;
165164
166 const std::vector &SC = Rec->getSuperClasses();
167 for (unsigned i = 0, e = SC.size(); i != e; ++i)
168 if (RTy->getRecord()->isSubClassOf(SC[i]))
165 for (Record *SC : RTy->getRecord()->getSuperClasses())
166 if (Rec->isSubClassOf(SC))
169167 return true;
170168
171169 return false;