LLVM  9.0.0svn
Record.h
Go to the documentation of this file.
1 //===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the main TableGen data structures, including the TableGen
10 // types, values, and high-level data structures.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TABLEGEN_RECORD_H
15 #define LLVM_TABLEGEN_RECORD_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/ADT/FoldingSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/Casting.h"
26 #include "llvm/Support/SMLoc.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <cstdint>
33 #include <map>
34 #include <memory>
35 #include <string>
36 #include <utility>
37 #include <vector>
38 
39 namespace llvm {
40 
41 class ListRecTy;
42 struct MultiClass;
43 class Record;
44 class RecordKeeper;
45 class RecordVal;
46 class Resolver;
47 class StringInit;
48 class TypedInit;
49 
50 //===----------------------------------------------------------------------===//
51 // Type Classes
52 //===----------------------------------------------------------------------===//
53 
54 class RecTy {
55 public:
56  /// Subclass discriminator (for dyn_cast<> et al.)
57  enum RecTyKind {
66  };
67 
68 private:
69  RecTyKind Kind;
70  ListRecTy *ListTy = nullptr;
71 
72 public:
73  RecTy(RecTyKind K) : Kind(K) {}
74  virtual ~RecTy() = default;
75 
76  RecTyKind getRecTyKind() const { return Kind; }
77 
78  virtual std::string getAsString() const = 0;
79  void print(raw_ostream &OS) const { OS << getAsString(); }
80  void dump() const;
81 
82  /// Return true if all values of 'this' type can be converted to the specified
83  /// type.
84  virtual bool typeIsConvertibleTo(const RecTy *RHS) const;
85 
86  /// Return true if 'this' type is equal to or a subtype of RHS. For example,
87  /// a bit set is not an int, but they are convertible.
88  virtual bool typeIsA(const RecTy *RHS) const;
89 
90  /// Returns the type representing list<this>.
92 };
93 
94 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
95  Ty.print(OS);
96  return OS;
97 }
98 
99 /// 'bit' - Represent a single bit
100 class BitRecTy : public RecTy {
101  static BitRecTy Shared;
102 
103  BitRecTy() : RecTy(BitRecTyKind) {}
104 
105 public:
106  static bool classof(const RecTy *RT) {
107  return RT->getRecTyKind() == BitRecTyKind;
108  }
109 
110  static BitRecTy *get() { return &Shared; }
111 
112  std::string getAsString() const override { return "bit"; }
113 
114  bool typeIsConvertibleTo(const RecTy *RHS) const override;
115 };
116 
117 /// 'bits<n>' - Represent a fixed number of bits
118 class BitsRecTy : public RecTy {
119  unsigned Size;
120 
121  explicit BitsRecTy(unsigned Sz) : RecTy(BitsRecTyKind), Size(Sz) {}
122 
123 public:
124  static bool classof(const RecTy *RT) {
125  return RT->getRecTyKind() == BitsRecTyKind;
126  }
127 
128  static BitsRecTy *get(unsigned Sz);
129 
130  unsigned getNumBits() const { return Size; }
131 
132  std::string getAsString() const override;
133 
134  bool typeIsConvertibleTo(const RecTy *RHS) const override;
135 
136  bool typeIsA(const RecTy *RHS) const override;
137 };
138 
139 /// 'code' - Represent a code fragment
140 class CodeRecTy : public RecTy {
141  static CodeRecTy Shared;
142 
144 
145 public:
146  static bool classof(const RecTy *RT) {
147  return RT->getRecTyKind() == CodeRecTyKind;
148  }
149 
150  static CodeRecTy *get() { return &Shared; }
151 
152  std::string getAsString() const override { return "code"; }
153 
154  bool typeIsConvertibleTo(const RecTy *RHS) const override;
155 };
156 
157 /// 'int' - Represent an integer value of no particular size
158 class IntRecTy : public RecTy {
159  static IntRecTy Shared;
160 
161  IntRecTy() : RecTy(IntRecTyKind) {}
162 
163 public:
164  static bool classof(const RecTy *RT) {
165  return RT->getRecTyKind() == IntRecTyKind;
166  }
167 
168  static IntRecTy *get() { return &Shared; }
169 
170  std::string getAsString() const override { return "int"; }
171 
172  bool typeIsConvertibleTo(const RecTy *RHS) const override;
173 };
174 
175 /// 'string' - Represent an string value
176 class StringRecTy : public RecTy {
177  static StringRecTy Shared;
178 
180 
181 public:
182  static bool classof(const RecTy *RT) {
183  return RT->getRecTyKind() == StringRecTyKind;
184  }
185 
186  static StringRecTy *get() { return &Shared; }
187 
188  std::string getAsString() const override;
189 
190  bool typeIsConvertibleTo(const RecTy *RHS) const override;
191 };
192 
193 /// 'list<Ty>' - Represent a list of values, all of which must be of
194 /// the specified type.
195 class ListRecTy : public RecTy {
196  friend ListRecTy *RecTy::getListTy();
197 
198  RecTy *Ty;
199 
200  explicit ListRecTy(RecTy *T) : RecTy(ListRecTyKind), Ty(T) {}
201 
202 public:
203  static bool classof(const RecTy *RT) {
204  return RT->getRecTyKind() == ListRecTyKind;
205  }
206 
207  static ListRecTy *get(RecTy *T) { return T->getListTy(); }
208  RecTy *getElementType() const { return Ty; }
209 
210  std::string getAsString() const override;
211 
212  bool typeIsConvertibleTo(const RecTy *RHS) const override;
213 
214  bool typeIsA(const RecTy *RHS) const override;
215 };
216 
217 /// 'dag' - Represent a dag fragment
218 class DagRecTy : public RecTy {
219  static DagRecTy Shared;
220 
221  DagRecTy() : RecTy(DagRecTyKind) {}
222 
223 public:
224  static bool classof(const RecTy *RT) {
225  return RT->getRecTyKind() == DagRecTyKind;
226  }
227 
228  static DagRecTy *get() { return &Shared; }
229 
230  std::string getAsString() const override;
231 };
232 
233 /// '[classname]' - Type of record values that have zero or more superclasses.
234 ///
235 /// The list of superclasses is non-redundant, i.e. only contains classes that
236 /// are not the superclass of some other listed class.
237 class RecordRecTy final : public RecTy, public FoldingSetNode,
238  public TrailingObjects<RecordRecTy, Record *> {
239  friend class Record;
240 
241  unsigned NumClasses;
242 
243  explicit RecordRecTy(unsigned Num)
244  : RecTy(RecordRecTyKind), NumClasses(Num) {}
245 
246 public:
247  RecordRecTy(const RecordRecTy &) = delete;
248  RecordRecTy &operator=(const RecordRecTy &) = delete;
249 
250  // Do not use sized deallocation due to trailing objects.
251  void operator delete(void *p) { ::operator delete(p); }
252 
253  static bool classof(const RecTy *RT) {
254  return RT->getRecTyKind() == RecordRecTyKind;
255  }
256 
257  /// Get the record type with the given non-redundant list of superclasses.
258  static RecordRecTy *get(ArrayRef<Record *> Classes);
259 
260  void Profile(FoldingSetNodeID &ID) const;
261 
263  return makeArrayRef(getTrailingObjects<Record *>(), NumClasses);
264  }
265 
266  using const_record_iterator = Record * const *;
267 
268  const_record_iterator classes_begin() const { return getClasses().begin(); }
269  const_record_iterator classes_end() const { return getClasses().end(); }
270 
271  std::string getAsString() const override;
272 
273  bool isSubClassOf(Record *Class) const;
274  bool typeIsConvertibleTo(const RecTy *RHS) const override;
275 
276  bool typeIsA(const RecTy *RHS) const override;
277 };
278 
279 /// Find a common type that T1 and T2 convert to.
280 /// Return 0 if no such type exists.
282 
283 //===----------------------------------------------------------------------===//
284 // Initializer Classes
285 //===----------------------------------------------------------------------===//
286 
287 class Init {
288 protected:
289  /// Discriminator enum (for isa<>, dyn_cast<>, et al.)
290  ///
291  /// This enum is laid out by a preorder traversal of the inheritance
292  /// hierarchy, and does not contain an entry for abstract classes, as per
293  /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
294  ///
295  /// We also explicitly include "first" and "last" values for each
296  /// interior node of the inheritance tree, to make it easier to read the
297  /// corresponding classof().
298  ///
299  /// We could pack these a bit tighter by not having the IK_FirstXXXInit
300  /// and IK_LastXXXInit be their own values, but that would degrade
301  /// readability for really no benefit.
302  enum InitKind : uint8_t {
303  IK_First, // unused; silence a spurious warning
327  IK_UnsetInit
328  };
329 
330 private:
331  const InitKind Kind;
332 
333 protected:
334  uint8_t Opc; // Used by UnOpInit, BinOpInit, and TernOpInit
335 
336 private:
337  virtual void anchor();
338 
339 public:
340  InitKind getKind() const { return Kind; }
341 
342 protected:
343  explicit Init(InitKind K, uint8_t Opc = 0) : Kind(K), Opc(Opc) {}
344 
345 public:
346  Init(const Init &) = delete;
347  Init &operator=(const Init &) = delete;
348  virtual ~Init() = default;
349 
350  /// This virtual method should be overridden by values that may
351  /// not be completely specified yet.
352  virtual bool isComplete() const { return true; }
353 
354  /// Is this a concrete and fully resolved value without any references or
355  /// stuck operations? Unset values are concrete.
356  virtual bool isConcrete() const { return false; }
357 
358  /// Print out this value.
359  void print(raw_ostream &OS) const { OS << getAsString(); }
360 
361  /// Convert this value to a string form.
362  virtual std::string getAsString() const = 0;
363  /// Convert this value to a string form,
364  /// without adding quote markers. This primaruly affects
365  /// StringInits where we will not surround the string value with
366  /// quotes.
367  virtual std::string getAsUnquotedString() const { return getAsString(); }
368 
369  /// Debugging method that may be called through a debugger, just
370  /// invokes print on stderr.
371  void dump() const;
372 
373  /// If this initializer is convertible to Ty, return an initializer whose
374  /// type is-a Ty, generating a !cast operation if required. Otherwise, return
375  /// nullptr.
376  virtual Init *getCastTo(RecTy *Ty) const = 0;
377 
378  /// Convert to an initializer whose type is-a Ty, or return nullptr if this
379  /// is not possible (this can happen if the initializer's type is convertible
380  /// to Ty, but there are unresolved references).
381  virtual Init *convertInitializerTo(RecTy *Ty) const = 0;
382 
383  /// This method is used to implement the bitrange
384  /// selection operator. Given an initializer, it selects the specified bits
385  /// out, returning them as a new init of bits type. If it is not legal to use
386  /// the bit subscript operator on this initializer, return null.
388  return nullptr;
389  }
390 
391  /// This method is used to implement the list slice
392  /// selection operator. Given an initializer, it selects the specified list
393  /// elements, returning them as a new init of list type. If it is not legal
394  /// to take a slice of this, return null.
395  virtual Init *convertInitListSlice(ArrayRef<unsigned> Elements) const {
396  return nullptr;
397  }
398 
399  /// This method is used to implement the FieldInit class.
400  /// Implementors of this method should return the type of the named field if
401  /// they are of record type.
402  virtual RecTy *getFieldType(StringInit *FieldName) const {
403  return nullptr;
404  }
405 
406  /// This method is used by classes that refer to other
407  /// variables which may not be defined at the time the expression is formed.
408  /// If a value is set for the variable later, this method will be called on
409  /// users of the value to allow the value to propagate out.
410  virtual Init *resolveReferences(Resolver &R) const {
411  return const_cast<Init *>(this);
412  }
413 
414  /// This method is used to return the initializer for the specified
415  /// bit.
416  virtual Init *getBit(unsigned Bit) const = 0;
417 };
418 
419 inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
420  I.print(OS); return OS;
421 }
422 
423 /// This is the common super-class of types that have a specific,
424 /// explicit, type.
425 class TypedInit : public Init {
426  RecTy *Ty;
427 
428 protected:
429  explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
430  : Init(K, Opc), Ty(T) {}
431 
432 public:
433  TypedInit(const TypedInit &) = delete;
434  TypedInit &operator=(const TypedInit &) = delete;
435 
436  static bool classof(const Init *I) {
437  return I->getKind() >= IK_FirstTypedInit &&
438  I->getKind() <= IK_LastTypedInit;
439  }
440 
441  RecTy *getType() const { return Ty; }
442 
443  Init *getCastTo(RecTy *Ty) const override;
444  Init *convertInitializerTo(RecTy *Ty) const override;
445 
446  Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
447  Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
448 
449  /// This method is used to implement the FieldInit class.
450  /// Implementors of this method should return the type of the named field if
451  /// they are of record type.
452  ///
453  RecTy *getFieldType(StringInit *FieldName) const override;
454 };
455 
456 /// '?' - Represents an uninitialized value
457 class UnsetInit : public Init {
458  UnsetInit() : Init(IK_UnsetInit) {}
459 
460 public:
461  UnsetInit(const UnsetInit &) = delete;
462  UnsetInit &operator=(const UnsetInit &) = delete;
463 
464  static bool classof(const Init *I) {
465  return I->getKind() == IK_UnsetInit;
466  }
467 
468  static UnsetInit *get();
469 
470  Init *getCastTo(RecTy *Ty) const override;
471  Init *convertInitializerTo(RecTy *Ty) const override;
472 
473  Init *getBit(unsigned Bit) const override {
474  return const_cast<UnsetInit*>(this);
475  }
476 
477  bool isComplete() const override { return false; }
478  bool isConcrete() const override { return true; }
479  std::string getAsString() const override { return "?"; }
480 };
481 
482 /// 'true'/'false' - Represent a concrete initializer for a bit.
483 class BitInit final : public TypedInit {
484  bool Value;
485 
486  explicit BitInit(bool V) : TypedInit(IK_BitInit, BitRecTy::get()), Value(V) {}
487 
488 public:
489  BitInit(const BitInit &) = delete;
490  BitInit &operator=(BitInit &) = delete;
491 
492  static bool classof(const Init *I) {
493  return I->getKind() == IK_BitInit;
494  }
495 
496  static BitInit *get(bool V);
497 
498  bool getValue() const { return Value; }
499 
500  Init *convertInitializerTo(RecTy *Ty) const override;
501 
502  Init *getBit(unsigned Bit) const override {
503  assert(Bit < 1 && "Bit index out of range!");
504  return const_cast<BitInit*>(this);
505  }
506 
507  bool isConcrete() const override { return true; }
508  std::string getAsString() const override { return Value ? "1" : "0"; }
509 };
510 
511 /// '{ a, b, c }' - Represents an initializer for a BitsRecTy value.
512 /// It contains a vector of bits, whose size is determined by the type.
513 class BitsInit final : public TypedInit, public FoldingSetNode,
514  public TrailingObjects<BitsInit, Init *> {
515  unsigned NumBits;
516 
517  BitsInit(unsigned N)
518  : TypedInit(IK_BitsInit, BitsRecTy::get(N)), NumBits(N) {}
519 
520 public:
521  BitsInit(const BitsInit &) = delete;
522  BitsInit &operator=(const BitsInit &) = delete;
523 
524  // Do not use sized deallocation due to trailing objects.
525  void operator delete(void *p) { ::operator delete(p); }
526 
527  static bool classof(const Init *I) {
528  return I->getKind() == IK_BitsInit;
529  }
530 
531  static BitsInit *get(ArrayRef<Init *> Range);
532 
533  void Profile(FoldingSetNodeID &ID) const;
534 
535  unsigned getNumBits() const { return NumBits; }
536 
537  Init *convertInitializerTo(RecTy *Ty) const override;
538  Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
539 
540  bool isComplete() const override {
541  for (unsigned i = 0; i != getNumBits(); ++i)
542  if (!getBit(i)->isComplete()) return false;
543  return true;
544  }
545 
546  bool allInComplete() const {
547  for (unsigned i = 0; i != getNumBits(); ++i)
548  if (getBit(i)->isComplete()) return false;
549  return true;
550  }
551 
552  bool isConcrete() const override;
553  std::string getAsString() const override;
554 
555  Init *resolveReferences(Resolver &R) const override;
556 
557  Init *getBit(unsigned Bit) const override {
558  assert(Bit < NumBits && "Bit index out of range!");
559  return getTrailingObjects<Init *>()[Bit];
560  }
561 };
562 
563 /// '7' - Represent an initialization by a literal integer value.
564 class IntInit : public TypedInit {
565  int64_t Value;
566 
567  explicit IntInit(int64_t V)
568  : TypedInit(IK_IntInit, IntRecTy::get()), Value(V) {}
569 
570 public:
571  IntInit(const IntInit &) = delete;
572  IntInit &operator=(const IntInit &) = delete;
573 
574  static bool classof(const Init *I) {
575  return I->getKind() == IK_IntInit;
576  }
577 
578  static IntInit *get(int64_t V);
579 
580  int64_t getValue() const { return Value; }
581 
582  Init *convertInitializerTo(RecTy *Ty) const override;
583  Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
584 
585  bool isConcrete() const override { return true; }
586  std::string getAsString() const override;
587 
588  Init *getBit(unsigned Bit) const override {
589  return BitInit::get((Value & (1ULL << Bit)) != 0);
590  }
591 };
592 
593 /// "foo" - Represent an initialization by a string value.
594 class StringInit : public TypedInit {
596 
597  explicit StringInit(StringRef V)
598  : TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
599 
600 public:
601  StringInit(const StringInit &) = delete;
602  StringInit &operator=(const StringInit &) = delete;
603 
604  static bool classof(const Init *I) {
605  return I->getKind() == IK_StringInit;
606  }
607 
608  static StringInit *get(StringRef);
609 
610  StringRef getValue() const { return Value; }
611 
612  Init *convertInitializerTo(RecTy *Ty) const override;
613 
614  bool isConcrete() const override { return true; }
615  std::string getAsString() const override { return "\"" + Value.str() + "\""; }
616 
617  std::string getAsUnquotedString() const override { return Value; }
618 
619  Init *getBit(unsigned Bit) const override {
620  llvm_unreachable("Illegal bit reference off string");
621  }
622 };
623 
624 class CodeInit : public TypedInit {
626  SMLoc Loc;
627 
628  explicit CodeInit(StringRef V, const SMLoc &Loc)
629  : TypedInit(IK_CodeInit, static_cast<RecTy *>(CodeRecTy::get())),
630  Value(V), Loc(Loc) {}
631 
632 public:
633  CodeInit(const StringInit &) = delete;
634  CodeInit &operator=(const StringInit &) = delete;
635 
636  static bool classof(const Init *I) {
637  return I->getKind() == IK_CodeInit;
638  }
639 
640  static CodeInit *get(StringRef, const SMLoc &Loc);
641 
642  StringRef getValue() const { return Value; }
643  const SMLoc &getLoc() const { return Loc; }
644 
645  Init *convertInitializerTo(RecTy *Ty) const override;
646 
647  bool isConcrete() const override { return true; }
648  std::string getAsString() const override {
649  return "[{" + Value.str() + "}]";
650  }
651 
652  std::string getAsUnquotedString() const override { return Value; }
653 
654  Init *getBit(unsigned Bit) const override {
655  llvm_unreachable("Illegal bit reference off string");
656  }
657 };
658 
659 /// [AL, AH, CL] - Represent a list of defs
660 ///
661 class ListInit final : public TypedInit, public FoldingSetNode,
662  public TrailingObjects<ListInit, Init *> {
663  unsigned NumValues;
664 
665 public:
666  using const_iterator = Init *const *;
667 
668 private:
669  explicit ListInit(unsigned N, RecTy *EltTy)
670  : TypedInit(IK_ListInit, ListRecTy::get(EltTy)), NumValues(N) {}
671 
672 public:
673  ListInit(const ListInit &) = delete;
674  ListInit &operator=(const ListInit &) = delete;
675 
676  // Do not use sized deallocation due to trailing objects.
677  void operator delete(void *p) { ::operator delete(p); }
678 
679  static bool classof(const Init *I) {
680  return I->getKind() == IK_ListInit;
681  }
682  static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
683 
684  void Profile(FoldingSetNodeID &ID) const;
685 
686  Init *getElement(unsigned i) const {
687  assert(i < NumValues && "List element index out of range!");
688  return getTrailingObjects<Init *>()[i];
689  }
691  return cast<ListRecTy>(getType())->getElementType();
692  }
693 
694  Record *getElementAsRecord(unsigned i) const;
695 
696  Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
697 
698  Init *convertInitializerTo(RecTy *Ty) const override;
699 
700  /// This method is used by classes that refer to other
701  /// variables which may not be defined at the time they expression is formed.
702  /// If a value is set for the variable later, this method will be called on
703  /// users of the value to allow the value to propagate out.
704  ///
705  Init *resolveReferences(Resolver &R) const override;
706 
707  bool isConcrete() const override;
708  std::string getAsString() const override;
709 
711  return makeArrayRef(getTrailingObjects<Init *>(), NumValues);
712  }
713 
714  const_iterator begin() const { return getTrailingObjects<Init *>(); }
715  const_iterator end () const { return begin() + NumValues; }
716 
717  size_t size () const { return NumValues; }
718  bool empty() const { return NumValues == 0; }
719 
720  Init *getBit(unsigned Bit) const override {
721  llvm_unreachable("Illegal bit reference off list");
722  }
723 };
724 
725 /// Base class for operators
726 ///
727 class OpInit : public TypedInit {
728 protected:
729  explicit OpInit(InitKind K, RecTy *Type, uint8_t Opc)
730  : TypedInit(K, Type, Opc) {}
731 
732 public:
733  OpInit(const OpInit &) = delete;
734  OpInit &operator=(OpInit &) = delete;
735 
736  static bool classof(const Init *I) {
737  return I->getKind() >= IK_FirstOpInit &&
738  I->getKind() <= IK_LastOpInit;
739  }
740 
741  // Clone - Clone this operator, replacing arguments with the new list
742  virtual OpInit *clone(ArrayRef<Init *> Operands) const = 0;
743 
744  virtual unsigned getNumOperands() const = 0;
745  virtual Init *getOperand(unsigned i) const = 0;
746 
747  Init *getBit(unsigned Bit) const override;
748 };
749 
750 /// !op (X) - Transform an init.
751 ///
752 class UnOpInit : public OpInit, public FoldingSetNode {
753 public:
754  enum UnaryOp : uint8_t { CAST, HEAD, TAIL, SIZE, EMPTY };
755 
756 private:
757  Init *LHS;
758 
759  UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
760  : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
761 
762 public:
763  UnOpInit(const UnOpInit &) = delete;
764  UnOpInit &operator=(const UnOpInit &) = delete;
765 
766  static bool classof(const Init *I) {
767  return I->getKind() == IK_UnOpInit;
768  }
769 
770  static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
771 
772  void Profile(FoldingSetNodeID &ID) const;
773 
774  // Clone - Clone this operator, replacing arguments with the new list
775  OpInit *clone(ArrayRef<Init *> Operands) const override {
776  assert(Operands.size() == 1 &&
777  "Wrong number of operands for unary operation");
778  return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
779  }
780 
781  unsigned getNumOperands() const override { return 1; }
782 
783  Init *getOperand(unsigned i) const override {
784  assert(i == 0 && "Invalid operand id for unary operator");
785  return getOperand();
786  }
787 
788  UnaryOp getOpcode() const { return (UnaryOp)Opc; }
789  Init *getOperand() const { return LHS; }
790 
791  // Fold - If possible, fold this to a simpler init. Return this if not
792  // possible to fold.
793  Init *Fold(Record *CurRec, bool IsFinal = false) const;
794 
795  Init *resolveReferences(Resolver &R) const override;
796 
797  std::string getAsString() const override;
798 };
799 
800 /// !op (X, Y) - Combine two inits.
801 class BinOpInit : public OpInit, public FoldingSetNode {
802 public:
803  enum BinaryOp : uint8_t { ADD, MUL, AND, OR, SHL, SRA, SRL, LISTCONCAT,
804  STRCONCAT, CONCAT, EQ, NE, LE, LT, GE, GT };
805 
806 private:
807  Init *LHS, *RHS;
808 
809  BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
810  OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
811 
812 public:
813  BinOpInit(const BinOpInit &) = delete;
814  BinOpInit &operator=(const BinOpInit &) = delete;
815 
816  static bool classof(const Init *I) {
817  return I->getKind() == IK_BinOpInit;
818  }
819 
820  static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
821  RecTy *Type);
822  static Init *getStrConcat(Init *lhs, Init *rhs);
823  static Init *getListConcat(TypedInit *lhs, Init *rhs);
824 
825  void Profile(FoldingSetNodeID &ID) const;
826 
827  // Clone - Clone this operator, replacing arguments with the new list
828  OpInit *clone(ArrayRef<Init *> Operands) const override {
829  assert(Operands.size() == 2 &&
830  "Wrong number of operands for binary operation");
831  return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
832  }
833 
834  unsigned getNumOperands() const override { return 2; }
835  Init *getOperand(unsigned i) const override {
836  switch (i) {
837  default: llvm_unreachable("Invalid operand id for binary operator");
838  case 0: return getLHS();
839  case 1: return getRHS();
840  }
841  }
842 
843  BinaryOp getOpcode() const { return (BinaryOp)Opc; }
844  Init *getLHS() const { return LHS; }
845  Init *getRHS() const { return RHS; }
846 
847  // Fold - If possible, fold this to a simpler init. Return this if not
848  // possible to fold.
849  Init *Fold(Record *CurRec) const;
850 
851  Init *resolveReferences(Resolver &R) const override;
852 
853  std::string getAsString() const override;
854 };
855 
856 /// !op (X, Y, Z) - Combine two inits.
857 class TernOpInit : public OpInit, public FoldingSetNode {
858 public:
859  enum TernaryOp : uint8_t { SUBST, FOREACH, IF, DAG };
860 
861 private:
862  Init *LHS, *MHS, *RHS;
863 
864  TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
865  RecTy *Type) :
866  OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
867 
868 public:
869  TernOpInit(const TernOpInit &) = delete;
870  TernOpInit &operator=(const TernOpInit &) = delete;
871 
872  static bool classof(const Init *I) {
873  return I->getKind() == IK_TernOpInit;
874  }
875 
876  static TernOpInit *get(TernaryOp opc, Init *lhs,
877  Init *mhs, Init *rhs,
878  RecTy *Type);
879 
880  void Profile(FoldingSetNodeID &ID) const;
881 
882  // Clone - Clone this operator, replacing arguments with the new list
883  OpInit *clone(ArrayRef<Init *> Operands) const override {
884  assert(Operands.size() == 3 &&
885  "Wrong number of operands for ternary operation");
886  return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
887  getType());
888  }
889 
890  unsigned getNumOperands() const override { return 3; }
891  Init *getOperand(unsigned i) const override {
892  switch (i) {
893  default: llvm_unreachable("Invalid operand id for ternary operator");
894  case 0: return getLHS();
895  case 1: return getMHS();
896  case 2: return getRHS();
897  }
898  }
899 
900  TernaryOp getOpcode() const { return (TernaryOp)Opc; }
901  Init *getLHS() const { return LHS; }
902  Init *getMHS() const { return MHS; }
903  Init *getRHS() const { return RHS; }
904 
905  // Fold - If possible, fold this to a simpler init. Return this if not
906  // possible to fold.
907  Init *Fold(Record *CurRec) const;
908 
909  bool isComplete() const override {
910  return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
911  }
912 
913  Init *resolveReferences(Resolver &R) const override;
914 
915  std::string getAsString() const override;
916 };
917 
918 /// !cond(condition_1: value1, ... , condition_n: value)
919 /// Selects the first value for which condition is true.
920 /// Otherwise reports an error.
921 class CondOpInit final : public TypedInit, public FoldingSetNode,
922  public TrailingObjects<CondOpInit, Init *> {
923  unsigned NumConds;
924  RecTy *ValType;
925 
926  CondOpInit(unsigned NC, RecTy *Type)
927  : TypedInit(IK_CondOpInit, Type),
928  NumConds(NC), ValType(Type) {}
929 
930  size_t numTrailingObjects(OverloadToken<Init *>) const {
931  return 2*NumConds;
932  }
933 
934 public:
935  CondOpInit(const CondOpInit &) = delete;
936  CondOpInit &operator=(const CondOpInit &) = delete;
937 
938  static bool classof(const Init *I) {
939  return I->getKind() == IK_CondOpInit;
940  }
941 
943  RecTy *Type);
944 
945  void Profile(FoldingSetNodeID &ID) const;
946 
947  RecTy *getValType() const { return ValType; }
948 
949  unsigned getNumConds() const { return NumConds; }
950 
951  Init *getCond(unsigned Num) const {
952  assert(Num < NumConds && "Condition number out of range!");
953  return getTrailingObjects<Init *>()[Num];
954  }
955 
956  Init *getVal(unsigned Num) const {
957  assert(Num < NumConds && "Val number out of range!");
958  return getTrailingObjects<Init *>()[Num+NumConds];
959  }
960 
962  return makeArrayRef(getTrailingObjects<Init *>(), NumConds);
963  }
964 
966  return makeArrayRef(getTrailingObjects<Init *>()+NumConds, NumConds);
967  }
968 
969  Init *Fold(Record *CurRec) const;
970 
971  Init *resolveReferences(Resolver &R) const override;
972 
973  bool isConcrete() const override;
974  bool isComplete() const override;
975  std::string getAsString() const override;
976 
979 
980  inline const_case_iterator arg_begin() const { return getConds().begin(); }
981  inline const_case_iterator arg_end () const { return getConds().end(); }
982 
983  inline size_t case_size () const { return NumConds; }
984  inline bool case_empty() const { return NumConds == 0; }
985 
986  inline const_val_iterator name_begin() const { return getVals().begin();}
987  inline const_val_iterator name_end () const { return getVals().end(); }
988 
989  inline size_t val_size () const { return NumConds; }
990  inline bool val_empty() const { return NumConds == 0; }
991 
992  Init *getBit(unsigned Bit) const override;
993 };
994 
995 /// !foldl (a, b, expr, start, lst) - Fold over a list.
996 class FoldOpInit : public TypedInit, public FoldingSetNode {
997 private:
998  Init *Start;
999  Init *List;
1000  Init *A;
1001  Init *B;
1002  Init *Expr;
1003 
1004  FoldOpInit(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
1005  : TypedInit(IK_FoldOpInit, Type), Start(Start), List(List), A(A), B(B),
1006  Expr(Expr) {}
1007 
1008 public:
1009  FoldOpInit(const FoldOpInit &) = delete;
1010  FoldOpInit &operator=(const FoldOpInit &) = delete;
1011 
1012  static bool classof(const Init *I) { return I->getKind() == IK_FoldOpInit; }
1013 
1014  static FoldOpInit *get(Init *Start, Init *List, Init *A, Init *B, Init *Expr,
1015  RecTy *Type);
1016 
1017  void Profile(FoldingSetNodeID &ID) const;
1018 
1019  // Fold - If possible, fold this to a simpler init. Return this if not
1020  // possible to fold.
1021  Init *Fold(Record *CurRec) const;
1022 
1023  bool isComplete() const override { return false; }
1024 
1025  Init *resolveReferences(Resolver &R) const override;
1026 
1027  Init *getBit(unsigned Bit) const override;
1028 
1029  std::string getAsString() const override;
1030 };
1031 
1032 /// !isa<type>(expr) - Dynamically determine the type of an expression.
1033 class IsAOpInit : public TypedInit, public FoldingSetNode {
1034 private:
1035  RecTy *CheckType;
1036  Init *Expr;
1037 
1038  IsAOpInit(RecTy *CheckType, Init *Expr)
1039  : TypedInit(IK_IsAOpInit, IntRecTy::get()), CheckType(CheckType),
1040  Expr(Expr) {}
1041 
1042 public:
1043  IsAOpInit(const IsAOpInit &) = delete;
1044  IsAOpInit &operator=(const IsAOpInit &) = delete;
1045 
1046  static bool classof(const Init *I) { return I->getKind() == IK_IsAOpInit; }
1047 
1048  static IsAOpInit *get(RecTy *CheckType, Init *Expr);
1049 
1050  void Profile(FoldingSetNodeID &ID) const;
1051 
1052  // Fold - If possible, fold this to a simpler init. Return this if not
1053  // possible to fold.
1054  Init *Fold() const;
1055 
1056  bool isComplete() const override { return false; }
1057 
1058  Init *resolveReferences(Resolver &R) const override;
1059 
1060  Init *getBit(unsigned Bit) const override;
1061 
1062  std::string getAsString() const override;
1063 };
1064 
1065 /// 'Opcode' - Represent a reference to an entire variable object.
1066 class VarInit : public TypedInit {
1067  Init *VarName;
1068 
1069  explicit VarInit(Init *VN, RecTy *T)
1070  : TypedInit(IK_VarInit, T), VarName(VN) {}
1071 
1072 public:
1073  VarInit(const VarInit &) = delete;
1074  VarInit &operator=(const VarInit &) = delete;
1075 
1076  static bool classof(const Init *I) {
1077  return I->getKind() == IK_VarInit;
1078  }
1079 
1080  static VarInit *get(StringRef VN, RecTy *T);
1081  static VarInit *get(Init *VN, RecTy *T);
1082 
1083  StringRef getName() const;
1084  Init *getNameInit() const { return VarName; }
1085 
1086  std::string getNameInitAsString() const {
1087  return getNameInit()->getAsUnquotedString();
1088  }
1089 
1090  /// This method is used by classes that refer to other
1091  /// variables which may not be defined at the time they expression is formed.
1092  /// If a value is set for the variable later, this method will be called on
1093  /// users of the value to allow the value to propagate out.
1094  ///
1095  Init *resolveReferences(Resolver &R) const override;
1096 
1097  Init *getBit(unsigned Bit) const override;
1098 
1099  std::string getAsString() const override { return getName(); }
1100 };
1101 
1102 /// Opcode{0} - Represent access to one bit of a variable or field.
1103 class VarBitInit final : public TypedInit {
1104  TypedInit *TI;
1105  unsigned Bit;
1106 
1107  VarBitInit(TypedInit *T, unsigned B)
1108  : TypedInit(IK_VarBitInit, BitRecTy::get()), TI(T), Bit(B) {
1109  assert(T->getType() &&
1110  (isa<IntRecTy>(T->getType()) ||
1111  (isa<BitsRecTy>(T->getType()) &&
1112  cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
1113  "Illegal VarBitInit expression!");
1114  }
1115 
1116 public:
1117  VarBitInit(const VarBitInit &) = delete;
1118  VarBitInit &operator=(const VarBitInit &) = delete;
1119 
1120  static bool classof(const Init *I) {
1121  return I->getKind() == IK_VarBitInit;
1122  }
1123 
1124  static VarBitInit *get(TypedInit *T, unsigned B);
1125 
1126  Init *getBitVar() const { return TI; }
1127  unsigned getBitNum() const { return Bit; }
1128 
1129  std::string getAsString() const override;
1130  Init *resolveReferences(Resolver &R) const override;
1131 
1132  Init *getBit(unsigned B) const override {
1133  assert(B < 1 && "Bit index out of range!");
1134  return const_cast<VarBitInit*>(this);
1135  }
1136 };
1137 
1138 /// List[4] - Represent access to one element of a var or
1139 /// field.
1141  TypedInit *TI;
1142  unsigned Element;
1143 
1144  VarListElementInit(TypedInit *T, unsigned E)
1145  : TypedInit(IK_VarListElementInit,
1146  cast<ListRecTy>(T->getType())->getElementType()),
1147  TI(T), Element(E) {
1148  assert(T->getType() && isa<ListRecTy>(T->getType()) &&
1149  "Illegal VarBitInit expression!");
1150  }
1151 
1152 public:
1153  VarListElementInit(const VarListElementInit &) = delete;
1154  VarListElementInit &operator=(const VarListElementInit &) = delete;
1155 
1156  static bool classof(const Init *I) {
1157  return I->getKind() == IK_VarListElementInit;
1158  }
1159 
1160  static VarListElementInit *get(TypedInit *T, unsigned E);
1161 
1162  TypedInit *getVariable() const { return TI; }
1163  unsigned getElementNum() const { return Element; }
1164 
1165  std::string getAsString() const override;
1166  Init *resolveReferences(Resolver &R) const override;
1167 
1168  Init *getBit(unsigned Bit) const override;
1169 };
1170 
1171 /// AL - Represent a reference to a 'def' in the description
1172 class DefInit : public TypedInit {
1173  friend class Record;
1174 
1175  Record *Def;
1176 
1177  explicit DefInit(Record *D);
1178 
1179 public:
1180  DefInit(const DefInit &) = delete;
1181  DefInit &operator=(const DefInit &) = delete;
1182 
1183  static bool classof(const Init *I) {
1184  return I->getKind() == IK_DefInit;
1185  }
1186 
1187  static DefInit *get(Record*);
1188 
1189  Init *convertInitializerTo(RecTy *Ty) const override;
1190 
1191  Record *getDef() const { return Def; }
1192 
1193  //virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);
1194 
1195  RecTy *getFieldType(StringInit *FieldName) const override;
1196 
1197  bool isConcrete() const override { return true; }
1198  std::string getAsString() const override;
1199 
1200  Init *getBit(unsigned Bit) const override {
1201  llvm_unreachable("Illegal bit reference off def");
1202  }
1203 };
1204 
1205 /// classname<targs...> - Represent an uninstantiated anonymous class
1206 /// instantiation.
1207 class VarDefInit final : public TypedInit, public FoldingSetNode,
1208  public TrailingObjects<VarDefInit, Init *> {
1209  Record *Class;
1210  DefInit *Def = nullptr; // after instantiation
1211  unsigned NumArgs;
1212 
1213  explicit VarDefInit(Record *Class, unsigned N)
1214  : TypedInit(IK_VarDefInit, RecordRecTy::get(Class)), Class(Class), NumArgs(N) {}
1215 
1216  DefInit *instantiate();
1217 
1218 public:
1219  VarDefInit(const VarDefInit &) = delete;
1220  VarDefInit &operator=(const VarDefInit &) = delete;
1221 
1222  // Do not use sized deallocation due to trailing objects.
1223  void operator delete(void *p) { ::operator delete(p); }
1224 
1225  static bool classof(const Init *I) {
1226  return I->getKind() == IK_VarDefInit;
1227  }
1228  static VarDefInit *get(Record *Class, ArrayRef<Init *> Args);
1229 
1230  void Profile(FoldingSetNodeID &ID) const;
1231 
1232  Init *resolveReferences(Resolver &R) const override;
1233  Init *Fold() const;
1234 
1235  std::string getAsString() const override;
1236 
1237  Init *getArg(unsigned i) const {
1238  assert(i < NumArgs && "Argument index out of range!");
1239  return getTrailingObjects<Init *>()[i];
1240  }
1241 
1242  using const_iterator = Init *const *;
1243 
1244  const_iterator args_begin() const { return getTrailingObjects<Init *>(); }
1245  const_iterator args_end () const { return args_begin() + NumArgs; }
1246 
1247  size_t args_size () const { return NumArgs; }
1248  bool args_empty() const { return NumArgs == 0; }
1249 
1250  ArrayRef<Init *> args() const { return makeArrayRef(args_begin(), NumArgs); }
1251 
1252  Init *getBit(unsigned Bit) const override {
1253  llvm_unreachable("Illegal bit reference off anonymous def");
1254  }
1255 };
1256 
1257 /// X.Y - Represent a reference to a subfield of a variable
1258 class FieldInit : public TypedInit {
1259  Init *Rec; // Record we are referring to
1260  StringInit *FieldName; // Field we are accessing
1261 
1262  FieldInit(Init *R, StringInit *FN)
1263  : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
1264  assert(getType() && "FieldInit with non-record type!");
1265  }
1266 
1267 public:
1268  FieldInit(const FieldInit &) = delete;
1269  FieldInit &operator=(const FieldInit &) = delete;
1270 
1271  static bool classof(const Init *I) {
1272  return I->getKind() == IK_FieldInit;
1273  }
1274 
1275  static FieldInit *get(Init *R, StringInit *FN);
1276 
1277  Init *getRecord() const { return Rec; }
1278  StringInit *getFieldName() const { return FieldName; }
1279 
1280  Init *getBit(unsigned Bit) const override;
1281 
1282  Init *resolveReferences(Resolver &R) const override;
1283  Init *Fold(Record *CurRec) const;
1284 
1285  std::string getAsString() const override {
1286  return Rec->getAsString() + "." + FieldName->getValue().str();
1287  }
1288 };
1289 
1290 /// (v a, b) - Represent a DAG tree value. DAG inits are required
1291 /// to have at least one value then a (possibly empty) list of arguments. Each
1292 /// argument can have a name associated with it.
1293 class DagInit final : public TypedInit, public FoldingSetNode,
1294  public TrailingObjects<DagInit, Init *, StringInit *> {
1295  friend TrailingObjects;
1296 
1297  Init *Val;
1298  StringInit *ValName;
1299  unsigned NumArgs;
1300  unsigned NumArgNames;
1301 
1302  DagInit(Init *V, StringInit *VN, unsigned NumArgs, unsigned NumArgNames)
1303  : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
1304  NumArgs(NumArgs), NumArgNames(NumArgNames) {}
1305 
1306  size_t numTrailingObjects(OverloadToken<Init *>) const { return NumArgs; }
1307 
1308 public:
1309  DagInit(const DagInit &) = delete;
1310  DagInit &operator=(const DagInit &) = delete;
1311 
1312  static bool classof(const Init *I) {
1313  return I->getKind() == IK_DagInit;
1314  }
1315 
1316  static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
1317  ArrayRef<StringInit*> NameRange);
1318  static DagInit *get(Init *V, StringInit *VN,
1320 
1321  void Profile(FoldingSetNodeID &ID) const;
1322 
1323  Init *getOperator() const { return Val; }
1324 
1325  StringInit *getName() const { return ValName; }
1326 
1328  return ValName ? ValName->getValue() : StringRef();
1329  }
1330 
1331  unsigned getNumArgs() const { return NumArgs; }
1332 
1333  Init *getArg(unsigned Num) const {
1334  assert(Num < NumArgs && "Arg number out of range!");
1335  return getTrailingObjects<Init *>()[Num];
1336  }
1337 
1338  StringInit *getArgName(unsigned Num) const {
1339  assert(Num < NumArgNames && "Arg number out of range!");
1340  return getTrailingObjects<StringInit *>()[Num];
1341  }
1342 
1343  StringRef getArgNameStr(unsigned Num) const {
1344  StringInit *Init = getArgName(Num);
1345  return Init ? Init->getValue() : StringRef();
1346  }
1347 
1349  return makeArrayRef(getTrailingObjects<Init *>(), NumArgs);
1350  }
1351 
1353  return makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames);
1354  }
1355 
1356  Init *resolveReferences(Resolver &R) const override;
1357 
1358  bool isConcrete() const override;
1359  std::string getAsString() const override;
1360 
1363 
1364  inline const_arg_iterator arg_begin() const { return getArgs().begin(); }
1365  inline const_arg_iterator arg_end () const { return getArgs().end(); }
1366 
1367  inline size_t arg_size () const { return NumArgs; }
1368  inline bool arg_empty() const { return NumArgs == 0; }
1369 
1370  inline const_name_iterator name_begin() const { return getArgNames().begin();}
1371  inline const_name_iterator name_end () const { return getArgNames().end(); }
1372 
1373  inline size_t name_size () const { return NumArgNames; }
1374  inline bool name_empty() const { return NumArgNames == 0; }
1375 
1376  Init *getBit(unsigned Bit) const override {
1377  llvm_unreachable("Illegal bit reference off dag");
1378  }
1379 };
1380 
1381 //===----------------------------------------------------------------------===//
1382 // High-Level Classes
1383 //===----------------------------------------------------------------------===//
1384 
1385 class RecordVal {
1386  friend class Record;
1387 
1388  Init *Name;
1390  Init *Value;
1391 
1392 public:
1393  RecordVal(Init *N, RecTy *T, bool P);
1394 
1395  StringRef getName() const;
1396  Init *getNameInit() const { return Name; }
1397 
1398  std::string getNameInitAsString() const {
1399  return getNameInit()->getAsUnquotedString();
1400  }
1401 
1402  bool getPrefix() const { return TyAndPrefix.getInt(); }
1403  RecTy *getType() const { return TyAndPrefix.getPointer(); }
1404  Init *getValue() const { return Value; }
1405 
1406  bool setValue(Init *V);
1407 
1408  void dump() const;
1409  void print(raw_ostream &OS, bool PrintSem = true) const;
1410 };
1411 
1412 inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
1413  RV.print(OS << " ");
1414  return OS;
1415 }
1416 
1417 class Record {
1418  static unsigned LastID;
1419 
1420  Init *Name;
1421  // Location where record was instantiated, followed by the location of
1422  // multiclass prototypes used.
1423  SmallVector<SMLoc, 4> Locs;
1426 
1427  // All superclasses in the inheritance forest in reverse preorder (yes, it
1428  // must be a forest; diamond-shaped inheritance is not allowed).
1430 
1431  // Tracks Record instances. Not owned by Record.
1432  RecordKeeper &TrackedRecords;
1433 
1434  DefInit *TheInit = nullptr;
1435 
1436  // Unique record ID.
1437  unsigned ID;
1438 
1439  bool IsAnonymous;
1440  bool IsClass;
1441 
1442  void checkName();
1443 
1444 public:
1445  // Constructs a record.
1446  explicit Record(Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1447  bool Anonymous = false, bool Class = false)
1448  : Name(N), Locs(locs.begin(), locs.end()), TrackedRecords(records),
1449  ID(LastID++), IsAnonymous(Anonymous), IsClass(Class) {
1450  checkName();
1451  }
1452 
1453  explicit Record(StringRef N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1454  bool Class = false)
1455  : Record(StringInit::get(N), locs, records, false, Class) {}
1456 
1457  // When copy-constructing a Record, we must still guarantee a globally unique
1458  // ID number. Don't copy TheInit either since it's owned by the original
1459  // record. All other fields can be copied normally.
1460  Record(const Record &O)
1461  : Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
1462  Values(O.Values), SuperClasses(O.SuperClasses),
1463  TrackedRecords(O.TrackedRecords), ID(LastID++),
1464  IsAnonymous(O.IsAnonymous), IsClass(O.IsClass) { }
1465 
1466  static unsigned getNewUID() { return LastID++; }
1467 
1468  unsigned getID() const { return ID; }
1469 
1470  StringRef getName() const { return cast<StringInit>(Name)->getValue(); }
1471 
1472  Init *getNameInit() const {
1473  return Name;
1474  }
1475 
1476  const std::string getNameInitAsString() const {
1477  return getNameInit()->getAsUnquotedString();
1478  }
1479 
1480  void setName(Init *Name); // Also updates RecordKeeper.
1481 
1482  ArrayRef<SMLoc> getLoc() const { return Locs; }
1483  void appendLoc(SMLoc Loc) { Locs.push_back(Loc); }
1484 
1485  // Make the type that this record should have based on its superclasses.
1486  RecordRecTy *getType();
1487 
1488  /// get the corresponding DefInit.
1489  DefInit *getDefInit();
1490 
1491  bool isClass() const { return IsClass; }
1492 
1494  return TemplateArgs;
1495  }
1496 
1497  ArrayRef<RecordVal> getValues() const { return Values; }
1498 
1500  return SuperClasses;
1501  }
1502 
1503  /// Append the direct super classes of this record to Classes.
1504  void getDirectSuperClasses(SmallVectorImpl<Record *> &Classes) const;
1505 
1506  bool isTemplateArg(Init *Name) const {
1507  for (Init *TA : TemplateArgs)
1508  if (TA == Name) return true;
1509  return false;
1510  }
1511 
1512  const RecordVal *getValue(const Init *Name) const {
1513  for (const RecordVal &Val : Values)
1514  if (Val.Name == Name) return &Val;
1515  return nullptr;
1516  }
1517 
1518  const RecordVal *getValue(StringRef Name) const {
1519  return getValue(StringInit::get(Name));
1520  }
1521 
1522  RecordVal *getValue(const Init *Name) {
1523  return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
1524  }
1525 
1527  return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
1528  }
1529 
1530  void addTemplateArg(Init *Name) {
1531  assert(!isTemplateArg(Name) && "Template arg already defined!");
1532  TemplateArgs.push_back(Name);
1533  }
1534 
1535  void addValue(const RecordVal &RV) {
1536  assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
1537  Values.push_back(RV);
1538  }
1539 
1540  void removeValue(Init *Name) {
1541  for (unsigned i = 0, e = Values.size(); i != e; ++i)
1542  if (Values[i].getNameInit() == Name) {
1543  Values.erase(Values.begin()+i);
1544  return;
1545  }
1546  llvm_unreachable("Cannot remove an entry that does not exist!");
1547  }
1548 
1549  void removeValue(StringRef Name) {
1550  removeValue(StringInit::get(Name));
1551  }
1552 
1553  bool isSubClassOf(const Record *R) const {
1554  for (const auto &SCPair : SuperClasses)
1555  if (SCPair.first == R)
1556  return true;
1557  return false;
1558  }
1559 
1560  bool isSubClassOf(StringRef Name) const {
1561  for (const auto &SCPair : SuperClasses) {
1562  if (const auto *SI = dyn_cast<StringInit>(SCPair.first->getNameInit())) {
1563  if (SI->getValue() == Name)
1564  return true;
1565  } else if (SCPair.first->getNameInitAsString() == Name) {
1566  return true;
1567  }
1568  }
1569  return false;
1570  }
1571 
1572  void addSuperClass(Record *R, SMRange Range) {
1573  assert(!TheInit && "changing type of record after it has been referenced");
1574  assert(!isSubClassOf(R) && "Already subclassing record!");
1575  SuperClasses.push_back(std::make_pair(R, Range));
1576  }
1577 
1578  /// If there are any field references that refer to fields
1579  /// that have been filled in, we can propagate the values now.
1580  ///
1581  /// This is a final resolve: any error messages, e.g. due to undefined
1582  /// !cast references, are generated now.
1583  void resolveReferences();
1584 
1585  /// Apply the resolver to the name of the record as well as to the
1586  /// initializers of all fields of the record except SkipVal.
1587  ///
1588  /// The resolver should not resolve any of the fields itself, to avoid
1589  /// recursion / infinite loops.
1590  void resolveReferences(Resolver &R, const RecordVal *SkipVal = nullptr);
1591 
1592  /// If anything in this record refers to RV, replace the
1593  /// reference to RV with the RHS of RV. If RV is null, we resolve all
1594  /// possible references.
1595  void resolveReferencesTo(const RecordVal *RV);
1596 
1598  return TrackedRecords;
1599  }
1600 
1601  bool isAnonymous() const {
1602  return IsAnonymous;
1603  }
1604 
1605  void print(raw_ostream &OS) const;
1606  void dump() const;
1607 
1608  //===--------------------------------------------------------------------===//
1609  // High-level methods useful to tablegen back-ends
1610  //
1611 
1612  /// Return the initializer for a value with the specified name,
1613  /// or throw an exception if the field does not exist.
1614  Init *getValueInit(StringRef FieldName) const;
1615 
1616  /// Return true if the named field is unset.
1617  bool isValueUnset(StringRef FieldName) const {
1618  return isa<UnsetInit>(getValueInit(FieldName));
1619  }
1620 
1621  /// This method looks up the specified field and returns
1622  /// its value as a string, throwing an exception if the field does not exist
1623  /// or if the value is not a string.
1624  StringRef getValueAsString(StringRef FieldName) const;
1625 
1626  /// This method looks up the specified field and returns
1627  /// its value as a BitsInit, throwing an exception if the field does not exist
1628  /// or if the value is not the right type.
1629  BitsInit *getValueAsBitsInit(StringRef FieldName) const;
1630 
1631  /// This method looks up the specified field and returns
1632  /// its value as a ListInit, throwing an exception if the field does not exist
1633  /// or if the value is not the right type.
1634  ListInit *getValueAsListInit(StringRef FieldName) const;
1635 
1636  /// This method looks up the specified field and
1637  /// returns its value as a vector of records, throwing an exception if the
1638  /// field does not exist or if the value is not the right type.
1639  std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
1640 
1641  /// This method looks up the specified field and
1642  /// returns its value as a vector of integers, throwing an exception if the
1643  /// field does not exist or if the value is not the right type.
1644  std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
1645 
1646  /// This method looks up the specified field and
1647  /// returns its value as a vector of strings, throwing an exception if the
1648  /// field does not exist or if the value is not the right type.
1649  std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
1650 
1651  /// This method looks up the specified field and returns its
1652  /// value as a Record, throwing an exception if the field does not exist or if
1653  /// the value is not the right type.
1654  Record *getValueAsDef(StringRef FieldName) const;
1655 
1656  /// This method looks up the specified field and returns its
1657  /// value as a bit, throwing an exception if the field does not exist or if
1658  /// the value is not the right type.
1659  bool getValueAsBit(StringRef FieldName) const;
1660 
1661  /// This method looks up the specified field and
1662  /// returns its value as a bit. If the field is unset, sets Unset to true and
1663  /// returns false.
1664  bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
1665 
1666  /// This method looks up the specified field and returns its
1667  /// value as an int64_t, throwing an exception if the field does not exist or
1668  /// if the value is not the right type.
1669  int64_t getValueAsInt(StringRef FieldName) const;
1670 
1671  /// This method looks up the specified field and returns its
1672  /// value as an Dag, throwing an exception if the field does not exist or if
1673  /// the value is not the right type.
1674  DagInit *getValueAsDag(StringRef FieldName) const;
1675 };
1676 
1677 raw_ostream &operator<<(raw_ostream &OS, const Record &R);
1678 
1680  friend class RecordRecTy;
1681  using RecordMap = std::map<std::string, std::unique_ptr<Record>>;
1682  RecordMap Classes, Defs;
1683  FoldingSet<RecordRecTy> RecordTypePool;
1684  std::map<std::string, Init *> ExtraGlobals;
1685  unsigned AnonCounter = 0;
1686 
1687 public:
1688  const RecordMap &getClasses() const { return Classes; }
1689  const RecordMap &getDefs() const { return Defs; }
1690 
1692  auto I = Classes.find(Name);
1693  return I == Classes.end() ? nullptr : I->second.get();
1694  }
1695 
1697  auto I = Defs.find(Name);
1698  return I == Defs.end() ? nullptr : I->second.get();
1699  }
1700 
1702  if (Record *R = getDef(Name))
1703  return R->getDefInit();
1704  auto It = ExtraGlobals.find(Name);
1705  return It == ExtraGlobals.end() ? nullptr : It->second;
1706  }
1707 
1708  void addClass(std::unique_ptr<Record> R) {
1709  bool Ins = Classes.insert(std::make_pair(R->getName(),
1710  std::move(R))).second;
1711  (void)Ins;
1712  assert(Ins && "Class already exists");
1713  }
1714 
1715  void addDef(std::unique_ptr<Record> R) {
1716  bool Ins = Defs.insert(std::make_pair(R->getName(),
1717  std::move(R))).second;
1718  (void)Ins;
1719  assert(Ins && "Record already exists");
1720  }
1721 
1723  bool Ins = ExtraGlobals.insert(std::make_pair(Name, I)).second;
1724  (void)Ins;
1725  assert(!getDef(Name));
1726  assert(Ins && "Global already exists");
1727  }
1728 
1729  Init *getNewAnonymousName();
1730 
1731  //===--------------------------------------------------------------------===//
1732  // High-level helper methods, useful for tablegen backends...
1733 
1734  /// This method returns all concrete definitions
1735  /// that derive from the specified class name. A class with the specified
1736  /// name must exist.
1737  std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
1738 
1739  void dump() const;
1740 };
1741 
1742 /// Sorting predicate to sort record pointers by name.
1743 struct LessRecord {
1744  bool operator()(const Record *Rec1, const Record *Rec2) const {
1745  return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
1746  }
1747 };
1748 
1749 /// Sorting predicate to sort record pointers by their
1750 /// unique ID. If you just need a deterministic order, use this, since it
1751 /// just compares two `unsigned`; the other sorting predicates require
1752 /// string manipulation.
1754  bool operator()(const Record *LHS, const Record *RHS) const {
1755  return LHS->getID() < RHS->getID();
1756  }
1757 };
1758 
1759 /// Sorting predicate to sort record pointers by their
1760 /// name field.
1762  bool operator()(const Record *Rec1, const Record *Rec2) const {
1763  return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
1764  }
1765 };
1766 
1768  static bool ascii_isdigit(char x) { return x >= '0' && x <= '9'; }
1769 
1770  struct RecordParts {
1772 
1774  if (Rec.empty())
1775  return;
1776 
1777  size_t Len = 0;
1778  const char *Start = Rec.data();
1779  const char *Curr = Start;
1780  bool isDigitPart = ascii_isdigit(Curr[0]);
1781  for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
1782  bool isDigit = ascii_isdigit(Curr[I]);
1783  if (isDigit != isDigitPart) {
1784  Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
1785  Len = 0;
1786  Start = &Curr[I];
1787  isDigitPart = ascii_isdigit(Curr[I]);
1788  }
1789  }
1790  // Push the last part.
1791  Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
1792  }
1793 
1794  size_t size() { return Parts.size(); }
1795 
1796  std::pair<bool, StringRef> getPart(size_t i) {
1797  assert (i < Parts.size() && "Invalid idx!");
1798  return Parts[i];
1799  }
1800  };
1801 
1802  bool operator()(const Record *Rec1, const Record *Rec2) const {
1803  RecordParts LHSParts(StringRef(Rec1->getName()));
1804  RecordParts RHSParts(StringRef(Rec2->getName()));
1805 
1806  size_t LHSNumParts = LHSParts.size();
1807  size_t RHSNumParts = RHSParts.size();
1808  assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
1809 
1810  if (LHSNumParts != RHSNumParts)
1811  return LHSNumParts < RHSNumParts;
1812 
1813  // We expect the registers to be of the form [_a-zA-Z]+([0-9]*[_a-zA-Z]*)*.
1814  for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
1815  std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
1816  std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
1817  // Expect even part to always be alpha.
1818  assert (LHSPart.first == false && RHSPart.first == false &&
1819  "Expected both parts to be alpha.");
1820  if (int Res = LHSPart.second.compare(RHSPart.second))
1821  return Res < 0;
1822  }
1823  for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
1824  std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
1825  std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
1826  // Expect odd part to always be numeric.
1827  assert (LHSPart.first == true && RHSPart.first == true &&
1828  "Expected both parts to be numeric.");
1829  if (LHSPart.second.size() != RHSPart.second.size())
1830  return LHSPart.second.size() < RHSPart.second.size();
1831 
1832  unsigned LHSVal, RHSVal;
1833 
1834  bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
1835  assert(!LHSFailed && "Unable to convert LHS to integer.");
1836  bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
1837  assert(!RHSFailed && "Unable to convert RHS to integer.");
1838 
1839  if (LHSVal != RHSVal)
1840  return LHSVal < RHSVal;
1841  }
1842  return LHSNumParts < RHSNumParts;
1843  }
1844 };
1845 
1847 
1848 //===----------------------------------------------------------------------===//
1849 // Resolvers
1850 //===----------------------------------------------------------------------===//
1851 
1852 /// Interface for looking up the initializer for a variable name, used by
1853 /// Init::resolveReferences.
1854 class Resolver {
1855  Record *CurRec;
1856  bool IsFinal = false;
1857 
1858 public:
1859  explicit Resolver(Record *CurRec) : CurRec(CurRec) {}
1860  virtual ~Resolver() {}
1861 
1862  Record *getCurrentRecord() const { return CurRec; }
1863 
1864  /// Return the initializer for the given variable name (should normally be a
1865  /// StringInit), or nullptr if the name could not be resolved.
1866  virtual Init *resolve(Init *VarName) = 0;
1867 
1868  // Whether bits in a BitsInit should stay unresolved if resolving them would
1869  // result in a ? (UnsetInit). This behavior is used to represent instruction
1870  // encodings by keeping references to unset variables within a record.
1871  virtual bool keepUnsetBits() const { return false; }
1872 
1873  // Whether this is the final resolve step before adding a record to the
1874  // RecordKeeper. Error reporting during resolve and related constant folding
1875  // should only happen when this is true.
1876  bool isFinal() const { return IsFinal; }
1877 
1878  void setFinal(bool Final) { IsFinal = Final; }
1879 };
1880 
1881 /// Resolve arbitrary mappings.
1882 class MapResolver final : public Resolver {
1883  struct MappedValue {
1884  Init *V;
1885  bool Resolved;
1886 
1887  MappedValue() : V(nullptr), Resolved(false) {}
1888  MappedValue(Init *V, bool Resolved) : V(V), Resolved(Resolved) {}
1889  };
1890 
1892 
1893 public:
1894  explicit MapResolver(Record *CurRec = nullptr) : Resolver(CurRec) {}
1895 
1896  void set(Init *Key, Init *Value) { Map[Key] = {Value, false}; }
1897 
1898  Init *resolve(Init *VarName) override;
1899 };
1900 
1901 /// Resolve all variables from a record except for unset variables.
1902 class RecordResolver final : public Resolver {
1904  SmallVector<Init *, 4> Stack;
1905 
1906 public:
1907  explicit RecordResolver(Record &R) : Resolver(&R) {}
1908 
1909  Init *resolve(Init *VarName) override;
1910 
1911  bool keepUnsetBits() const override { return true; }
1912 };
1913 
1914 /// Resolve all references to a specific RecordVal.
1915 //
1916 // TODO: This is used for resolving references to template arguments, in a
1917 // rather inefficient way. Change those uses to resolve all template
1918 // arguments simultaneously and get rid of this class.
1919 class RecordValResolver final : public Resolver {
1920  const RecordVal *RV;
1921 
1922 public:
1923  explicit RecordValResolver(Record &R, const RecordVal *RV)
1924  : Resolver(&R), RV(RV) {}
1925 
1926  Init *resolve(Init *VarName) override {
1927  if (VarName == RV->getNameInit())
1928  return RV->getValue();
1929  return nullptr;
1930  }
1931 };
1932 
1933 /// Delegate resolving to a sub-resolver, but shadow some variable names.
1934 class ShadowResolver final : public Resolver {
1935  Resolver &R;
1936  DenseSet<Init *> Shadowed;
1937 
1938 public:
1940  : Resolver(R.getCurrentRecord()), R(R) {
1941  setFinal(R.isFinal());
1942  }
1943 
1944  void addShadow(Init *Key) { Shadowed.insert(Key); }
1945 
1946  Init *resolve(Init *VarName) override {
1947  if (Shadowed.count(VarName))
1948  return nullptr;
1949  return R.resolve(VarName);
1950  }
1951 };
1952 
1953 /// (Optionally) delegate resolving to a sub-resolver, and keep track whether
1954 /// there were unresolved references.
1955 class TrackUnresolvedResolver final : public Resolver {
1956  Resolver *R;
1957  bool FoundUnresolved = false;
1958 
1959 public:
1960  explicit TrackUnresolvedResolver(Resolver *R = nullptr)
1961  : Resolver(R ? R->getCurrentRecord() : nullptr), R(R) {}
1962 
1963  bool foundUnresolved() const { return FoundUnresolved; }
1964 
1965  Init *resolve(Init *VarName) override;
1966 };
1967 
1968 /// Do not resolve anything, but keep track of whether a given variable was
1969 /// referenced.
1970 class HasReferenceResolver final : public Resolver {
1971  Init *VarNameToTrack;
1972  bool Found = false;
1973 
1974 public:
1975  explicit HasReferenceResolver(Init *VarNameToTrack)
1976  : Resolver(nullptr), VarNameToTrack(VarNameToTrack) {}
1977 
1978  bool found() const { return Found; }
1979 
1980  Init *resolve(Init *VarName) override;
1981 };
1982 
1983 void EmitJSON(RecordKeeper &RK, raw_ostream &OS);
1984 
1985 } // end namespace llvm
1986 
1987 #endif // LLVM_TABLEGEN_RECORD_H
Init * getOperand() const
Definition: Record.h:789
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:825
Init * getCond(unsigned Num) const
Definition: Record.h:951
uint64_t CallInst * C
unsigned getNumBits() const
Definition: Record.h:535
RecordVal * getValue(const Init *Name)
Definition: Record.h:1522
Represents a range in source code.
Definition: SMLoc.h:48
unsigned getNumConds() const
Definition: Record.h:949
static bool classof(const Init *I)
Definition: Record.h:1156
std::string getAsString() const override
Definition: Record.h:152
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:614
RecTyKind
Subclass discriminator (for dyn_cast<> et al.)
Definition: Record.h:57
void print(raw_ostream &OS) const
Definition: Record.h:79
bool getValue() const
Definition: Record.h:498
const_name_iterator name_end() const
Definition: Record.h:1371
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:218
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
bool allInComplete() const
Definition: Record.h:546
Init * getValue() const
Definition: Record.h:1404
const_case_iterator arg_end() const
Definition: Record.h:981
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:320
Sorting predicate to sort record pointers by name.
Definition: Record.h:1743
This class represents lattice values for constants.
Definition: AllocatorList.h:23
X.Y - Represent a reference to a subfield of a variable.
Definition: Record.h:1258
PointerTy getPointer() const
Resolver(Record *CurRec)
Definition: Record.h:1859
virtual std::string getAsUnquotedString() const
Convert this value to a string form, without adding quote markers.
Definition: Record.h:367
Record * getCurrentRecord() const
Definition: Record.h:1862
bool foundUnresolved() const
Definition: Record.h:1963
bool empty() const
Definition: Record.h:718
[AL, AH, CL] - Represent a list of defs
Definition: Record.h:661
iterator begin() const
Definition: ArrayRef.h:136
&#39;7&#39; - Represent an initialization by a literal integer value.
Definition: Record.h:564
StringRef getNameStr() const
Definition: Record.h:1327
virtual RecTy * getFieldType(StringInit *FieldName) const
This method is used to implement the FieldInit class.
Definition: Record.h:402
static bool classof(const RecTy *RT)
Definition: Record.h:164
&#39;list<Ty>&#39; - Represent a list of values, all of which must be of the specified type.
Definition: Record.h:195
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
!op (X, Y) - Combine two inits.
Definition: Record.h:801
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:615
Init * getRHS() const
Definition: Record.h:903
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
Sorting predicate to sort record pointers by their name field.
Definition: Record.h:1761
AL - Represent a reference to a &#39;def&#39; in the description.
Definition: Record.h:1172
static bool classof(const Init *I)
Definition: Record.h:816
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
Definition: Record.cpp:693
static bool classof(const Init *I)
Definition: Record.h:527
void addDef(std::unique_ptr< Record > R)
Definition: Record.h:1715
static bool classof(const Init *I)
Definition: Record.h:1012
Init * getOperand(unsigned i) const override
Definition: Record.h:783
static bool classof(const RecTy *RT)
Definition: Record.h:106
std::string getAsString() const override
Definition: Record.h:112
HasReferenceResolver(Init *VarNameToTrack)
Definition: Record.h:1975
size_t val_size() const
Definition: Record.h:989
Resolve all references to a specific RecordVal.
Definition: Record.h:1919
static CodeRecTy * get()
Definition: Record.h:150
const_record_iterator classes_begin() const
Definition: Record.h:268
static bool classof(const Init *I)
Definition: Record.h:1183
void removeValue(StringRef Name)
Definition: Record.h:1549
Resolve all variables from a record except for unset variables.
Definition: Record.h:1902
&#39;{ a, b, c }&#39; - Represents an initializer for a BitsRecTy value.
Definition: Record.h:513
Init * getArg(unsigned i) const
Definition: Record.h:1237
std::pair< bool, StringRef > getPart(size_t i)
Definition: Record.h:1796
std::string getNameInitAsString() const
Definition: Record.h:1398
static BitRecTy * get()
Definition: Record.h:110
static bool classof(const Init *I)
Definition: Record.h:436
(Optionally) delegate resolving to a sub-resolver, and keep track whether there were unresolved refer...
Definition: Record.h:1955
Sorting predicate to sort record pointers by their unique ID.
Definition: Record.h:1753
static bool classof(const Init *I)
Definition: Record.h:636
Init * getArg(unsigned Num) const
Definition: Record.h:1333
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const
Definition: Record.h:1499
&#39;?&#39; - Represents an uninitialized value
Definition: Record.h:457
static bool classof(const Init *I)
Definition: Record.h:492
void addSuperClass(Record *R, SMRange Range)
Definition: Record.h:1572
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:473
&#39;true&#39;/&#39;false&#39; - Represent a concrete initializer for a bit.
Definition: Record.h:483
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1376
TypedInit * getVariable() const
Definition: Record.h:1162
SmallVectorImpl< Init * >::const_iterator const_val_iterator
Definition: Record.h:978
static bool classof(const Init *I)
Definition: Record.h:736
static BitsRecTy * get(unsigned Sz)
Definition: Record.cpp:84
Record * getDef() const
Definition: Record.h:1191
static bool classof(const RecTy *RT)
Definition: Record.h:253
const_val_iterator name_end() const
Definition: Record.h:987
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:619
static bool classof(const Init *I)
Definition: Record.h:574
This is the common super-class of types that have a specific, explicit, type.
Definition: Record.h:425
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
Shift and rotation operations.
Definition: ISDOpcodes.h:409
Init *const * const_iterator
Definition: Record.h:1242
void addClass(std::unique_ptr< Record > R)
Definition: Record.h:1708
RecTy * getElementType() const
Definition: Record.h:208
static StringRecTy * get()
Definition: Record.h:186
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:196
ArrayRef< Init * > getTemplateArgs() const
Definition: Record.h:1493
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
List[4] - Represent access to one element of a var or field.
Definition: Record.h:1140
&#39;[classname]&#39; - Type of record values that have zero or more superclasses.
Definition: Record.h:237
virtual bool isComplete() const
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:352
const_iterator args_begin() const
Definition: Record.h:1244
bool isAnonymous() const
Definition: Record.h:1601
static StringRef getName(Value *V)
bool case_empty() const
Definition: Record.h:984
!foldl (a, b, expr, start, lst) - Fold over a list.
Definition: Record.h:996
const_iterator args_end() const
Definition: Record.h:1245
bool args_empty() const
Definition: Record.h:1248
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:1744
Init * getLHS() const
Definition: Record.h:844
RecordResolver(Record &R)
Definition: Record.h:1907
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
!cond(condition_1: value1, ...
Definition: Record.h:921
void print(raw_ostream &OS, bool PrintSem=true) const
Definition: Record.cpp:2001
unsigned getBitNum() const
Definition: Record.h:1127
const_iterator end() const
Definition: Record.h:715
StringInit * getArgName(unsigned Num) const
Definition: Record.h:1338
virtual Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const
This method is used to implement the bitrange selection operator.
Definition: Record.h:387
Key
PAL metadata keys.
bool operator()(const Record *LHS, const Record *RHS) const
Definition: Record.h:1754
Record * getClass(StringRef Name) const
Definition: Record.h:1691
SmallVectorImpl< Init * >::const_iterator const_arg_iterator
Definition: Record.h:1361
ArrayRef< SMLoc > getLoc() const
Definition: Record.h:1482
&#39;bits<n>&#39; - Represent a fixed number of bits
Definition: Record.h:118
ArrayRef< Record * > getClasses() const
Definition: Record.h:262
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:1056
bool isTemplateArg(Init *Name) const
Definition: Record.h:1506
IntType getInt() const
#define T
RecTy * getType() const
Definition: Record.h:1403
StringRef getValue() const
Definition: Record.h:642
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
bool isSubClassOf(const Record *R) const
Definition: Record.h:1553
static bool classof(const RecTy *RT)
Definition: Record.h:203
ArrayRef< Init * > getValues() const
Definition: Record.h:710
ArrayRef< Init * > getArgs() const
Definition: Record.h:1348
OpInit(InitKind K, RecTy *Type, uint8_t Opc)
Definition: Record.h:729
static bool classof(const Init *I)
Definition: Record.h:1120
bool isFinal() const
Definition: Record.h:1876
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
static bool classof(const RecTy *RT)
Definition: Record.h:224
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:1762
static bool classof(const RecTy *RT)
Definition: Record.h:182
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:1023
static bool classof(const Init *I)
Definition: Record.h:1271
unsigned getNumBits() const
Definition: Record.h:130
void print(raw_ostream &OS) const
Print out this value.
Definition: Record.h:359
#define EQ(a, b)
Definition: regexec.c:112
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1252
Init * getBitVar() const
Definition: Record.h:1126
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:478
virtual Init * convertInitListSlice(ArrayRef< unsigned > Elements) const
This method is used to implement the list slice selection operator.
Definition: Record.h:395
ArrayRef< RecordVal > getValues() const
Definition: Record.h:1497
const_record_iterator classes_end() const
Definition: Record.h:269
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:585
&#39;code&#39; - Represent a code fragment
Definition: Record.h:140
ArrayRef< Init * > getVals() const
Definition: Record.h:965
SmallVectorImpl< StringInit * >::const_iterator const_name_iterator
Definition: Record.h:1362
void addShadow(Init *Key)
Definition: Record.h:1944
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:305
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:1099
unsigned getElementNum() const
Definition: Record.h:1163
Base class for operators.
Definition: Record.h:727
#define P(N)
static bool classof(const Init *I)
Definition: Record.h:1046
OpInit * clone(ArrayRef< Init *> Operands) const override
Definition: Record.h:828
RecTy(RecTyKind K)
Definition: Record.h:73
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1200
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:647
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
RecTy * getType() const
Definition: Record.h:441
Init * getElement(unsigned i) const
Definition: Record.h:686
Resolve arbitrary mappings.
Definition: Record.h:1882
Init * getNameInit() const
Definition: Record.h:1396
bool isClass() const
Definition: Record.h:1491
PointerIntPair - This class implements a pair of a pointer and small integer.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool keepUnsetBits() const override
Definition: Record.h:1911
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:540
virtual bool isConcrete() const
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:356
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
size_t args_size() const
Definition: Record.h:1247
"foo" - Represent an initialization by a string value.
Definition: Record.h:594
unsigned getNumOperands() const override
Definition: Record.h:834
void addExtraGlobal(StringRef Name, Init *I)
Definition: Record.h:1722
Init * getRHS() const
Definition: Record.h:845
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:1854
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:30
ArrayRef< Init * > args() const
Definition: Record.h:1250
!op (X) - Transform an init.
Definition: Record.h:752
bool val_empty() const
Definition: Record.h:990
Init * getOperand(unsigned i) const override
Definition: Record.h:891
StringInit * getFieldName() const
Definition: Record.h:1278
const std::string getNameInitAsString() const
Definition: Record.h:1476
bool getPrefix() const
Definition: Record.h:1402
SmallVector< std::pair< bool, StringRef >, 4 > Parts
Definition: Record.h:1771
bool name_empty() const
Definition: Record.h:1374
void dump() const
Definition: Record.cpp:60
See the file comment for details on the usage of the TrailingObjects type.
size_t case_size() const
Definition: Record.h:983
StringRef getValueAsString(StringRef FieldName) const
This method looks up the specified field and returns its value as a string, throwing an exception if ...
Definition: Record.cpp:2148
OpInit * clone(ArrayRef< Init *> Operands) const override
Definition: Record.h:883
UnaryOp getOpcode() const
Definition: Record.h:788
static bool classof(const Init *I)
Definition: Record.h:766
virtual ~RecTy()=default
int64_t getValue() const
Definition: Record.h:580
void EmitJSON(RecordKeeper &RK, raw_ostream &OS)
&#39;string&#39; - Represent an string value
Definition: Record.h:176
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:1197
static BitInit * get(bool V)
Definition: Record.cpp:311
size_t arg_size() const
Definition: Record.h:1367
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:479
const RecordVal * getValue(StringRef Name) const
Definition: Record.h:1518
static bool classof(const Init *I)
Definition: Record.h:872
DefInit * getDefInit()
get the corresponding DefInit.
Definition: Record.cpp:2027
std::string getAsUnquotedString() const override
Convert this value to a string form, without adding quote markers.
Definition: Record.h:652
virtual ~Resolver()
Definition: Record.h:1860
iterator erase(const_iterator CI)
Definition: SmallVector.h:438
size_t size() const
Definition: SmallVector.h:52
StringInit * getName() const
Definition: Record.h:1325
static wasm::ValType getType(const TargetRegisterClass *RC)
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:909
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:473
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool classof(const Init *I)
Definition: Record.h:464
static RecordRecTy * get(ArrayRef< Record *> Classes)
Get the record type with the given non-redundant list of superclasses.
Definition: Record.cpp:157
Record(Init *N, ArrayRef< SMLoc > locs, RecordKeeper &records, bool Anonymous=false, bool Class=false)
Definition: Record.h:1446
Delegate resolving to a sub-resolver, but shadow some variable names.
Definition: Record.h:1934
void setFinal(bool Final)
Definition: Record.h:1878
virtual Init * resolveReferences(Resolver &R) const
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.h:410
void addTemplateArg(Init *Name)
Definition: Record.h:1530
static bool classof(const Init *I)
Definition: Record.h:604
virtual bool typeIsA(const RecTy *RHS) const
Return true if &#39;this&#39; type is equal to or a subtype of RHS.
Definition: Record.cpp:74
const RecordVal * getValue(const Init *Name) const
Definition: Record.h:1512
SmallVectorImpl< Init * >::const_iterator const_case_iterator
Definition: Record.h:977
const RecordMap & getClasses() const
Definition: Record.h:1688
Init * getOperator() const
Definition: Record.h:1323
Init * getMHS() const
Definition: Record.h:902
TrackUnresolvedResolver(Resolver *R=nullptr)
Definition: Record.h:1960
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
RecordVal * getValue(StringRef Name)
Definition: Record.h:1526
static StringInit * get(StringRef)
Definition: Record.cpp:533
static bool classof(const RecTy *RT)
Definition: Record.h:146
static bool classof(const RecTy *RT)
Definition: Record.h:124
RecordKeeper & getRecords() const
Definition: Record.h:1597
const_case_iterator arg_begin() const
Definition: Record.h:980
unsigned getNumArgs() const
Definition: Record.h:1331
bool isSubClassOf(StringRef Name) const
Definition: Record.h:1560
unsigned getID() const
Definition: Record.h:1468
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
uint8_t Opc
Definition: Record.h:334
RecTy * getElementType() const
Definition: Record.h:690
classname<targs...> - Represent an uninstantiated anonymous class instantiation.
Definition: Record.h:1207
#define NC
Definition: regutils.h:42
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:588
bool arg_empty() const
Definition: Record.h:1368
static unsigned getNewUID()
Definition: Record.h:1466
!isa<type>(expr) - Dynamically determine the type of an expression.
Definition: Record.h:1033
Record(StringRef N, ArrayRef< SMLoc > locs, RecordKeeper &records, bool Class=false)
Definition: Record.h:1453
void removeValue(Init *Name)
Definition: Record.h:1540
const SMLoc & getLoc() const
Definition: Record.h:643
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:1802
static bool classof(const Init *I)
Definition: Record.h:679
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:557
&#39;int&#39; - Represent an integer value of no particular size
Definition: Record.h:158
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:648
OpInit * clone(ArrayRef< Init *> Operands) const override
Definition: Record.h:775
InitKind getKind() const
Definition: Record.h:340
static bool ascii_isdigit(char x)
Definition: Record.h:1768
void appendLoc(SMLoc Loc)
Definition: Record.h:1483
RecTy * getValType() const
Definition: Record.h:947
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
Definition: StringExtras.h:76
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:386
std::string getNameInitAsString() const
Definition: Record.h:1086
std::string getAsString() const override
Definition: Record.h:170
Init * getNameInit() const
Definition: Record.h:1472
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:135
size_t name_size() const
Definition: Record.h:1373
TypedInit(InitKind K, RecTy *T, uint8_t Opc=0)
Definition: Record.h:429
Do not resolve anything, but keep track of whether a given variable was referenced.
Definition: Record.h:1970
Init * getGlobal(StringRef Name) const
Definition: Record.h:1701
Init * getBit(unsigned B) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1132
Record *const * const_record_iterator
Definition: Record.h:266
static DagRecTy * get()
Definition: Record.h:228
void addValue(const RecordVal &RV)
Definition: Record.h:1535
ArrayRef< Init * > getConds() const
Definition: Record.h:961
const NodeList & List
Definition: RDFGraph.cpp:201
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:1040
const_iterator begin() const
Definition: Record.h:714
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
RecTy * resolveTypes(RecTy *T1, RecTy *T2)
Find a common type that T1 and T2 convert to.
Definition: Record.cpp:262
Opcode{0} - Represent access to one bit of a variable or field.
Definition: Record.h:1103
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:477
&#39;Opcode&#39; - Represent a reference to an entire variable object.
Definition: Record.h:1066
Init(InitKind K, uint8_t Opc=0)
Definition: Record.h:343
uint32_t Size
Definition: Profile.cpp:46
&#39;bit&#39; - Represent a single bit
Definition: Record.h:100
!op (X, Y, Z) - Combine two inits.
Definition: Record.h:857
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
static bool classof(const Init *I)
Definition: Record.h:938
RecordValResolver(Record &R, const RecordVal *RV)
Definition: Record.h:1923
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2038
Init * getOperand(unsigned i) const override
Definition: Record.h:835
const_name_iterator name_begin() const
Definition: Record.h:1370
virtual bool keepUnsetBits() const
Definition: Record.h:1871
RecTyKind getRecTyKind() const
Definition: Record.h:76
virtual bool typeIsConvertibleTo(const RecTy *RHS) const
Return true if all values of &#39;this&#39; type can be converted to the specified type.
Definition: Record.cpp:69
StringRef getValue() const
Definition: Record.h:610
&#39;dag&#39; - Represent a dag fragment
Definition: Record.h:218
unsigned getNumOperands() const override
Definition: Record.h:781
Record * getDef(StringRef Name) const
Definition: Record.h:1696
ArrayRef< StringInit * > getArgNames() const
Definition: Record.h:1352
static LLVM_ATTRIBUTE_ALWAYS_INLINE bool CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N, const TargetLowering *TLI, const DataLayout &DL)
StringRef getName() const
Definition: Record.h:1470
MapResolver(Record *CurRec=nullptr)
Definition: Record.h:1894
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:122
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:654
BinaryOp getOpcode() const
Definition: Record.h:843
TernaryOp getOpcode() const
Definition: Record.h:900
LLVM Value Representation.
Definition: Value.h:72
(v a, b) - Represent a DAG tree value.
Definition: Record.h:1293
virtual std::string getAsString() const =0
Convert this value to a string form.
size_t size() const
Definition: Record.h:717
This header defines support for implementing classes that have some trailing object (or arrays of obj...
unsigned getNumOperands() const override
Definition: Record.h:890
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:720
const_val_iterator name_begin() const
Definition: Record.h:986
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:508
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
InitKind
Discriminator enum (for isa<>, dyn_cast<>, et al.)
Definition: Record.h:302
Init * getVal(unsigned Num) const
Definition: Record.h:956
Init *const * const_iterator
Definition: Record.h:666
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool isConcrete() const override
Is this a concrete and fully resolved value without any references or stuck operations? Unset values are concrete.
Definition: Record.h:507
std::string getAsUnquotedString() const override
Convert this value to a string form, without adding quote markers.
Definition: Record.h:617
static bool classof(const Init *I)
Definition: Record.h:1312
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:502
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:1285
Init * getLHS() const
Definition: Record.h:901
virtual std::string getAsString() const =0
Represents a location in source code.
Definition: SMLoc.h:23
ListRecTy * getListTy()
Returns the type representing list<this>.
Definition: Record.cpp:63
Init * getNameInit() const
Definition: Record.h:1084
const_arg_iterator arg_begin() const
Definition: Record.h:1364
Init * getRecord() const
Definition: Record.h:1277
Record(const Record &O)
Definition: Record.h:1460
StringRef getArgNameStr(unsigned Num) const
Definition: Record.h:1343
bool isValueUnset(StringRef FieldName) const
Return true if the named field is unset.
Definition: Record.h:1617
const RecordMap & getDefs() const
Definition: Record.h:1689
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
#define T1
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
Definition: Record.h:1946
static bool classof(const Init *I)
Definition: Record.h:1076
static IntRecTy * get()
Definition: Record.h:168
const_arg_iterator arg_end() const
Definition: Record.h:1365
Init * resolve(Init *VarName) override
Return the initializer for the given variable name (should normally be a StringInit), or nullptr if the name could not be resolved.
Definition: Record.h:1926
static bool classof(const Init *I)
Definition: Record.h:1225
ShadowResolver(Resolver &R)
Definition: Record.h:1939