llvm.org GIT mirror llvm / 37fda19
Simplify TableGen type-compatibility checks. Patch by Elior Malul! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171684 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Silva 7 years ago
2 changed file(s) with 45 addition(s) and 75 deletion(s). Raw diff Collapse all Expand all
127127 return convertValue((TypedInit*)FI);
128128 }
129129
130 public: // These methods should only be called by subclasses of RecTy.
131 // baseClassOf - These virtual methods should be overloaded to return true iff
132 // all values of type 'RHS' can be converted to the 'this' type.
133 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
134 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
135 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
136 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
137 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
138 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
139 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
130 public:
131 virtual bool baseClassOf(const RecTy*) const;
140132 };
141133
142134 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
178170 virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
179171 return RHS->baseClassOf(this);
180172 }
181 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
182 virtual bool baseClassOf(const BitsRecTy *RHS) const;
183 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
184 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
185 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
186 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
187 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
188
173 virtual bool baseClassOf(const RecTy*) const;
189174 };
190175
191176
225210 virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
226211 return RHS->baseClassOf(this);
227212 }
228 virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
229 virtual bool baseClassOf(const BitsRecTy *RHS) const {
230 return RHS->Size == Size;
231 }
232 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
233 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
234 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
235 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
236 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
237
213 virtual bool baseClassOf(const RecTy*) const;
238214 };
239215
240216
272248 return RHS->baseClassOf(this);
273249 }
274250
275 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
276 virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
277 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
278 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
279 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
280 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
281 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
282
251 virtual bool baseClassOf(const RecTy*) const;
283252 };
284253
285254 /// StringRecTy - 'string' - Represent an string value
316285 virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
317286 return RHS->baseClassOf(this);
318287 }
319
320 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
321 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
322 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
323 virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
324 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
325 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
326 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
327288 };
328289
329290 // ListRecTy - 'list' - Represent a list of values, all of which must be of
365326 return RHS->baseClassOf(this);
366327 }
367328
368 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
369 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
370 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
371 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
372 virtual bool baseClassOf(const ListRecTy *RHS) const {
373 return RHS->getElementType()->typeIsConvertibleTo(Ty);
374 }
375 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
376 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
329 virtual bool baseClassOf(const RecTy*) const;
377330 };
378331
379332 /// DagRecTy - 'dag' - Represent a dag fragment
409362 virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
410363 return RHS->baseClassOf(this);
411364 }
412
413 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
414 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
415 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
416 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
417 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
418 virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
419 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
420365 };
421366
422367
457402 virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
458403 return RHS->baseClassOf(this);
459404 }
460 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
461 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
462 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
463 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
464 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
465 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
466 virtual bool baseClassOf(const RecordRecTy *RHS) const;
405 virtual bool baseClassOf(const RecTy*) const;
467406 };
468407
469408 /// resolveTypes - Find a common type that T1 and T2 convert to.
9494 return ListTy;
9595 }
9696
97 bool RecTy::baseClassOf(const RecTy *RHS) const{
98 assert (RHS && "NULL pointer");
99 return Kind == RHS->getRecTyKind();
100 }
101
97102 Init *BitRecTy::convertValue(BitsInit *BI) {
98103 if (BI->getNumBits() != 1) return 0; // Only accept if just one bit!
99104 return BI->getBit(0);
100 }
101
102 bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
103 return RHS->getNumBits() == 1;
104105 }
105106
106107 Init *BitRecTy::convertValue(IntInit *II) {
115116 if (isa(Ty) || isa(Ty) || isa(Ty))
116117 return VI; // Accept variable if it is already of bit type!
117118 return 0;
119 }
120
121 bool BitRecTy::baseClassOf(const RecTy *RHS) const{
122 if(RecTy::baseClassOf(RHS) || getRecTyKind() == IntRecTyKind)
123 return true;
124 if(const BitsRecTy *BitsTy = dyn_cast(RHS))
125 return BitsTy->getNumBits() == 1;
126 return false;
118127 }
119128
120129 BitsRecTy *BitsRecTy::get(unsigned Sz) {
192201 return 0;
193202 }
194203
204 bool BitsRecTy::baseClassOf(const RecTy *RHS) const{
205 if (RecTy::baseClassOf(RHS)) //argument and the receiver are the same type
206 return cast(RHS)->Size == Size;
207 RecTyKind kind = RHS->getRecTyKind();
208 return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
209 }
210
195211 Init *IntRecTy::convertValue(BitInit *BI) {
196212 return IntInit::get(BI->getValue());
197213 }
211227 if (TI->getType()->typeIsConvertibleTo(this))
212228 return TI; // Accept variable if already of the right type!
213229 return 0;
230 }
231
232 bool IntRecTy::baseClassOf(const RecTy *RHS) const{
233 RecTyKind kind = RHS->getRecTyKind();
234 return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
214235 }
215236
216237 Init *StringRecTy::convertValue(UnOpInit *BO) {
274295 return 0;
275296 }
276297
298 bool ListRecTy::baseClassOf(const RecTy *RHS) const{
299 if(const ListRecTy* ListTy = dyn_cast(RHS))
300 return ListTy->getElementType()->typeIsConvertibleTo(Ty);
301 return false;
302 }
303
277304 Init *DagRecTy::convertValue(TypedInit *TI) {
278305 if (TI->getType()->typeIsConvertibleTo(this))
279306 return TI;
327354 return 0;
328355 }
329356
330 bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const {
331 if (Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec))
357 bool RecordRecTy::baseClassOf(const RecTy *RHS) const{
358 const RecordRecTy *RTy = dyn_cast(RHS);
359 if (!RTy)
360 return false;
361
362 if (Rec == RTy->getRecord() || RTy->getRecord()->isSubClassOf(Rec))
332363 return true;
333364
334365 const std::vector &SC = Rec->getSuperClasses();
335366 for (unsigned i = 0, e = SC.size(); i != e; ++i)
336 if (RHS->getRecord()->isSubClassOf(SC[i]))
367 if (RTy->getRecord()->isSubClassOf(SC[i]))
337368 return true;
338369
339370 return false;