LLVM  7.0.0svn
Record.h
Go to the documentation of this file.
1 //===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the main TableGen data structures, including the TableGen
11 // types, values, and high-level data structures.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TABLEGEN_RECORD_H
16 #define LLVM_TABLEGEN_RECORD_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/SMLoc.h"
28 #include <algorithm>
29 #include <cassert>
30 #include <cstddef>
31 #include <cstdint>
32 #include <map>
33 #include <memory>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 namespace llvm {
39 
40 class ListRecTy;
41 struct MultiClass;
42 class Record;
43 class RecordKeeper;
44 class RecordVal;
45 class StringInit;
46 
47 //===----------------------------------------------------------------------===//
48 // Type Classes
49 //===----------------------------------------------------------------------===//
50 
51 class RecTy {
52 public:
53  /// \brief Subclass discriminator (for dyn_cast<> et al.)
54  enum RecTyKind {
63  };
64 
65 private:
66  RecTyKind Kind;
67  ListRecTy *ListTy = nullptr;
68 
69 public:
70  RecTy(RecTyKind K) : Kind(K) {}
71  virtual ~RecTy() = default;
72 
73  RecTyKind getRecTyKind() const { return Kind; }
74 
75  virtual std::string getAsString() const = 0;
76  void print(raw_ostream &OS) const { OS << getAsString(); }
77  void dump() const;
78 
79  /// Return true if all values of 'this' type can be converted to the specified
80  /// type.
81  virtual bool typeIsConvertibleTo(const RecTy *RHS) const;
82 
83  /// Returns the type representing list<this>.
85 };
86 
87 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
88  Ty.print(OS);
89  return OS;
90 }
91 
92 /// 'bit' - Represent a single bit
93 class BitRecTy : public RecTy {
94  static BitRecTy Shared;
95 
97 
98 public:
99  static bool classof(const RecTy *RT) {
100  return RT->getRecTyKind() == BitRecTyKind;
101  }
102 
103  static BitRecTy *get() { return &Shared; }
104 
105  std::string getAsString() const override { return "bit"; }
106 
107  bool typeIsConvertibleTo(const RecTy *RHS) const override;
108 };
109 
110 /// 'bits<n>' - Represent a fixed number of bits
111 class BitsRecTy : public RecTy {
112  unsigned Size;
113 
114  explicit BitsRecTy(unsigned Sz) : RecTy(BitsRecTyKind), Size(Sz) {}
115 
116 public:
117  static bool classof(const RecTy *RT) {
118  return RT->getRecTyKind() == BitsRecTyKind;
119  }
120 
121  static BitsRecTy *get(unsigned Sz);
122 
123  unsigned getNumBits() const { return Size; }
124 
125  std::string getAsString() const override;
126 
127  bool typeIsConvertibleTo(const RecTy *RHS) const override;
128 };
129 
130 /// 'code' - Represent a code fragment
131 class CodeRecTy : public RecTy {
132  static CodeRecTy Shared;
133 
135 
136 public:
137  static bool classof(const RecTy *RT) {
138  return RT->getRecTyKind() == CodeRecTyKind;
139  }
140 
141  static CodeRecTy *get() { return &Shared; }
142 
143  std::string getAsString() const override { return "code"; }
144 
145  bool typeIsConvertibleTo(const RecTy *RHS) const override;
146 };
147 
148 /// 'int' - Represent an integer value of no particular size
149 class IntRecTy : public RecTy {
150  static IntRecTy Shared;
151 
152  IntRecTy() : RecTy(IntRecTyKind) {}
153 
154 public:
155  static bool classof(const RecTy *RT) {
156  return RT->getRecTyKind() == IntRecTyKind;
157  }
158 
159  static IntRecTy *get() { return &Shared; }
160 
161  std::string getAsString() const override { return "int"; }
162 
163  bool typeIsConvertibleTo(const RecTy *RHS) const override;
164 };
165 
166 /// 'string' - Represent an string value
167 class StringRecTy : public RecTy {
168  static StringRecTy Shared;
169 
171 
172 public:
173  static bool classof(const RecTy *RT) {
174  return RT->getRecTyKind() == StringRecTyKind ||
175  RT->getRecTyKind() == CodeRecTyKind;
176  }
177 
178  static StringRecTy *get() { return &Shared; }
179 
180  std::string getAsString() const override;
181 
182  bool typeIsConvertibleTo(const RecTy *RHS) const override;
183 };
184 
185 /// 'list<Ty>' - Represent a list of values, all of which must be of
186 /// the specified type.
187 class ListRecTy : public RecTy {
188  friend ListRecTy *RecTy::getListTy();
189 
190  RecTy *Ty;
191 
192  explicit ListRecTy(RecTy *T) : RecTy(ListRecTyKind), Ty(T) {}
193 
194 public:
195  static bool classof(const RecTy *RT) {
196  return RT->getRecTyKind() == ListRecTyKind;
197  }
198 
199  static ListRecTy *get(RecTy *T) { return T->getListTy(); }
200  RecTy *getElementType() const { return Ty; }
201 
202  std::string getAsString() const override;
203 
204  bool typeIsConvertibleTo(const RecTy *RHS) const override;
205 };
206 
207 /// 'dag' - Represent a dag fragment
208 class DagRecTy : public RecTy {
209  static DagRecTy Shared;
210 
211  DagRecTy() : RecTy(DagRecTyKind) {}
212 
213 public:
214  static bool classof(const RecTy *RT) {
215  return RT->getRecTyKind() == DagRecTyKind;
216  }
217 
218  static DagRecTy *get() { return &Shared; }
219 
220  std::string getAsString() const override;
221 };
222 
223 /// '[classname]' - Represent an instance of a class, such as:
224 /// (R32 X = EAX).
225 class RecordRecTy : public RecTy {
226  friend class Record;
227 
228  Record *Rec;
229 
230  explicit RecordRecTy(Record *R) : RecTy(RecordRecTyKind), Rec(R) {}
231 
232 public:
233  static bool classof(const RecTy *RT) {
234  return RT->getRecTyKind() == RecordRecTyKind;
235  }
236 
237  static RecordRecTy *get(Record *R);
238 
239  Record *getRecord() const { return Rec; }
240 
241  std::string getAsString() const override;
242 
243  bool typeIsConvertibleTo(const RecTy *RHS) const override;
244 };
245 
246 /// Find a common type that T1 and T2 convert to.
247 /// Return 0 if no such type exists.
249 
250 //===----------------------------------------------------------------------===//
251 // Initializer Classes
252 //===----------------------------------------------------------------------===//
253 
254 class Init {
255 protected:
256  /// \brief Discriminator enum (for isa<>, dyn_cast<>, et al.)
257  ///
258  /// This enum is laid out by a preorder traversal of the inheritance
259  /// hierarchy, and does not contain an entry for abstract classes, as per
260  /// the recommendation in docs/HowToSetUpLLVMStyleRTTI.rst.
261  ///
262  /// We also explicitly include "first" and "last" values for each
263  /// interior node of the inheritance tree, to make it easier to read the
264  /// corresponding classof().
265  ///
266  /// We could pack these a bit tighter by not having the IK_FirstXXXInit
267  /// and IK_LastXXXInit be their own values, but that would degrade
268  /// readability for really no benefit.
269  enum InitKind : uint8_t {
270  IK_First, // unused; silence a spurious warning
290  IK_UnsetInit
291  };
292 
293 private:
294  const InitKind Kind;
295 
296 protected:
297  uint8_t Opc; // Used by UnOpInit, BinOpInit, and TernOpInit
298 
299 private:
300  virtual void anchor();
301 
302 public:
303  InitKind getKind() const { return Kind; }
304 
305 protected:
306  explicit Init(InitKind K, uint8_t Opc = 0) : Kind(K), Opc(Opc) {}
307 
308 public:
309  Init(const Init &) = delete;
310  Init &operator=(const Init &) = delete;
311  virtual ~Init() = default;
312 
313  /// This virtual method should be overridden by values that may
314  /// not be completely specified yet.
315  virtual bool isComplete() const { return true; }
316 
317  /// Print out this value.
318  void print(raw_ostream &OS) const { OS << getAsString(); }
319 
320  /// Convert this value to a string form.
321  virtual std::string getAsString() const = 0;
322  /// Convert this value to a string form,
323  /// without adding quote markers. This primaruly affects
324  /// StringInits where we will not surround the string value with
325  /// quotes.
326  virtual std::string getAsUnquotedString() const { return getAsString(); }
327 
328  /// Debugging method that may be called through a debugger, just
329  /// invokes print on stderr.
330  void dump() const;
331 
332  /// This virtual function converts to the appropriate
333  /// Init based on the passed in type.
334  virtual Init *convertInitializerTo(RecTy *Ty) const = 0;
335 
336  /// This method is used to implement the bitrange
337  /// selection operator. Given an initializer, it selects the specified bits
338  /// out, returning them as a new init of bits type. If it is not legal to use
339  /// the bit subscript operator on this initializer, return null.
341  return nullptr;
342  }
343 
344  /// This method is used to implement the list slice
345  /// selection operator. Given an initializer, it selects the specified list
346  /// elements, returning them as a new init of list type. If it is not legal
347  /// to take a slice of this, return null.
348  virtual Init *convertInitListSlice(ArrayRef<unsigned> Elements) const {
349  return nullptr;
350  }
351 
352  /// This method is used to implement the FieldInit class.
353  /// Implementors of this method should return the type of the named field if
354  /// they are of record type.
355  virtual RecTy *getFieldType(StringInit *FieldName) const {
356  return nullptr;
357  }
358 
359  /// This method complements getFieldType to return the
360  /// initializer for the specified field. If getFieldType returns non-null
361  /// this method should return non-null, otherwise it returns null.
362  virtual Init *getFieldInit(Record &R, const RecordVal *RV,
363  StringInit *FieldName) const {
364  return nullptr;
365  }
366 
367  /// This method is used by classes that refer to other
368  /// variables which may not be defined at the time the expression is formed.
369  /// If a value is set for the variable later, this method will be called on
370  /// users of the value to allow the value to propagate out.
371  virtual Init *resolveReferences(Record &R, const RecordVal *RV) const {
372  return const_cast<Init *>(this);
373  }
374 
375  /// This method is used to return the initializer for the specified
376  /// bit.
377  virtual Init *getBit(unsigned Bit) const = 0;
378 
379  /// This method is used to retrieve the initializer for bit
380  /// reference. For non-VarBitInit, it simply returns itself.
381  virtual Init *getBitVar() const { return const_cast<Init*>(this); }
382 
383  /// This method is used to retrieve the bit number of a bit
384  /// reference. For non-VarBitInit, it simply returns 0.
385  virtual unsigned getBitNum() const { return 0; }
386 };
387 
388 inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
389  I.print(OS); return OS;
390 }
391 
392 /// This is the common super-class of types that have a specific,
393 /// explicit, type.
394 class TypedInit : public Init {
395  RecTy *Ty;
396 
397 protected:
398  explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
399  : Init(K, Opc), Ty(T) {}
400 
401 public:
402  TypedInit(const TypedInit &) = delete;
403  TypedInit &operator=(const TypedInit &) = delete;
404 
405  static bool classof(const Init *I) {
406  return I->getKind() >= IK_FirstTypedInit &&
407  I->getKind() <= IK_LastTypedInit;
408  }
409 
410  RecTy *getType() const { return Ty; }
411 
412  Init *convertInitializerTo(RecTy *Ty) const override;
413 
414  Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
415  Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
416 
417  /// This method is used to implement the FieldInit class.
418  /// Implementors of this method should return the type of the named field if
419  /// they are of record type.
420  ///
421  RecTy *getFieldType(StringInit *FieldName) const override;
422 
423  /// This method is used to implement
424  /// VarListElementInit::resolveReferences. If the list element is resolvable
425  /// now, we return the resolved value, otherwise we return null.
426  virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
427  unsigned Elt) const = 0;
428 };
429 
430 /// '?' - Represents an uninitialized value
431 class UnsetInit : public Init {
432  UnsetInit() : Init(IK_UnsetInit) {}
433 
434 public:
435  UnsetInit(const UnsetInit &) = delete;
436  UnsetInit &operator=(const UnsetInit &) = delete;
437 
438  static bool classof(const Init *I) {
439  return I->getKind() == IK_UnsetInit;
440  }
441 
442  static UnsetInit *get();
443 
444  Init *convertInitializerTo(RecTy *Ty) const override;
445 
446  Init *getBit(unsigned Bit) const override {
447  return const_cast<UnsetInit*>(this);
448  }
449 
450  bool isComplete() const override { return false; }
451  std::string getAsString() const override { return "?"; }
452 };
453 
454 /// 'true'/'false' - Represent a concrete initializer for a bit.
455 class BitInit final : public TypedInit {
456  bool Value;
457 
458  explicit BitInit(bool V) : TypedInit(IK_BitInit, BitRecTy::get()), Value(V) {}
459 
460 public:
461  BitInit(const BitInit &) = delete;
462  BitInit &operator=(BitInit &) = delete;
463 
464  static bool classof(const Init *I) {
465  return I->getKind() == IK_BitInit;
466  }
467 
468  static BitInit *get(bool V);
469 
470  bool getValue() const { return Value; }
471 
472  Init *convertInitializerTo(RecTy *Ty) const override;
473 
475  unsigned Elt) const override {
476  llvm_unreachable("Illegal element reference off bit");
477  }
478 
479  Init *getBit(unsigned Bit) const override {
480  assert(Bit < 1 && "Bit index out of range!");
481  return const_cast<BitInit*>(this);
482  }
483 
484  std::string getAsString() const override { return Value ? "1" : "0"; }
485 };
486 
487 /// '{ a, b, c }' - Represents an initializer for a BitsRecTy value.
488 /// It contains a vector of bits, whose size is determined by the type.
489 class BitsInit final : public TypedInit, public FoldingSetNode,
490  public TrailingObjects<BitsInit, Init *> {
491  unsigned NumBits;
492 
493  BitsInit(unsigned N)
494  : TypedInit(IK_BitsInit, BitsRecTy::get(N)), NumBits(N) {}
495 
496 public:
497  BitsInit(const BitsInit &) = delete;
498  BitsInit &operator=(const BitsInit &) = delete;
499 
500  // Do not use sized deallocation due to trailing objects.
501  void operator delete(void *p) { ::operator delete(p); }
502 
503  static bool classof(const Init *I) {
504  return I->getKind() == IK_BitsInit;
505  }
506 
507  static BitsInit *get(ArrayRef<Init *> Range);
508 
509  void Profile(FoldingSetNodeID &ID) const;
510 
511  unsigned getNumBits() const { return NumBits; }
512 
513  Init *convertInitializerTo(RecTy *Ty) const override;
514  Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
515 
516  bool isComplete() const override {
517  for (unsigned i = 0; i != getNumBits(); ++i)
518  if (!getBit(i)->isComplete()) return false;
519  return true;
520  }
521 
522  bool allInComplete() const {
523  for (unsigned i = 0; i != getNumBits(); ++i)
524  if (getBit(i)->isComplete()) return false;
525  return true;
526  }
527 
528  std::string getAsString() const override;
529 
530  /// This method is used to implement
531  /// VarListElementInit::resolveReferences. If the list element is resolvable
532  /// now, we return the resolved value, otherwise we return null.
534  unsigned Elt) const override {
535  llvm_unreachable("Illegal element reference off bits<n>");
536  }
537 
538  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
539 
540  Init *getBit(unsigned Bit) const override {
541  assert(Bit < NumBits && "Bit index out of range!");
542  return getTrailingObjects<Init *>()[Bit];
543  }
544 };
545 
546 /// '7' - Represent an initialization by a literal integer value.
547 class IntInit : public TypedInit {
548  int64_t Value;
549 
550  explicit IntInit(int64_t V)
551  : TypedInit(IK_IntInit, IntRecTy::get()), Value(V) {}
552 
553 public:
554  IntInit(const IntInit &) = delete;
555  IntInit &operator=(const IntInit &) = delete;
556 
557  static bool classof(const Init *I) {
558  return I->getKind() == IK_IntInit;
559  }
560 
561  static IntInit *get(int64_t V);
562 
563  int64_t getValue() const { return Value; }
564 
565  Init *convertInitializerTo(RecTy *Ty) const override;
566  Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
567 
568  std::string getAsString() const override;
569 
570  /// This method is used to implement
571  /// VarListElementInit::resolveReferences. If the list element is resolvable
572  /// now, we return the resolved value, otherwise we return null.
574  unsigned Elt) const override {
575  llvm_unreachable("Illegal element reference off int");
576  }
577 
578  Init *getBit(unsigned Bit) const override {
579  return BitInit::get((Value & (1ULL << Bit)) != 0);
580  }
581 };
582 
583 /// "foo" - Represent an initialization by a string value.
584 class StringInit : public TypedInit {
586 
587  explicit StringInit(StringRef V)
588  : TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
589 
590 public:
591  StringInit(const StringInit &) = delete;
592  StringInit &operator=(const StringInit &) = delete;
593 
594  static bool classof(const Init *I) {
595  return I->getKind() == IK_StringInit;
596  }
597 
598  static StringInit *get(StringRef);
599 
600  StringRef getValue() const { return Value; }
601 
602  Init *convertInitializerTo(RecTy *Ty) const override;
603 
604  std::string getAsString() const override { return "\"" + Value.str() + "\""; }
605 
606  std::string getAsUnquotedString() const override { return Value; }
607 
608  /// resolveListElementReference - This method is used to implement
609  /// VarListElementInit::resolveReferences. If the list element is resolvable
610  /// now, we return the resolved value, otherwise we return null.
612  unsigned Elt) const override {
613  llvm_unreachable("Illegal element reference off string");
614  }
615 
616  Init *getBit(unsigned Bit) const override {
617  llvm_unreachable("Illegal bit reference off string");
618  }
619 };
620 
621 class CodeInit : public TypedInit {
623 
624  explicit CodeInit(StringRef V)
625  : TypedInit(IK_CodeInit, static_cast<RecTy *>(CodeRecTy::get())),
626  Value(V) {}
627 
628 public:
629  CodeInit(const StringInit &) = delete;
630  CodeInit &operator=(const StringInit &) = delete;
631 
632  static bool classof(const Init *I) {
633  return I->getKind() == IK_CodeInit;
634  }
635 
636  static CodeInit *get(StringRef);
637 
638  StringRef getValue() const { return Value; }
639 
640  Init *convertInitializerTo(RecTy *Ty) const override;
641 
642  std::string getAsString() const override {
643  return "[{" + Value.str() + "}]";
644  }
645 
646  std::string getAsUnquotedString() const override { return Value; }
647 
648  /// This method is used to implement
649  /// VarListElementInit::resolveReferences. If the list element is resolvable
650  /// now, we return the resolved value, otherwise we return null.
652  unsigned Elt) const override {
653  llvm_unreachable("Illegal element reference off string");
654  }
655 
656  Init *getBit(unsigned Bit) const override {
657  llvm_unreachable("Illegal bit reference off string");
658  }
659 };
660 
661 /// [AL, AH, CL] - Represent a list of defs
662 ///
663 class ListInit final : public TypedInit, public FoldingSetNode,
664  public TrailingObjects<ListInit, Init *> {
665  unsigned NumValues;
666 
667 public:
668  using const_iterator = Init *const *;
669 
670 private:
671  explicit ListInit(unsigned N, RecTy *EltTy)
672  : TypedInit(IK_ListInit, ListRecTy::get(EltTy)), NumValues(N) {}
673 
674 public:
675  ListInit(const ListInit &) = delete;
676  ListInit &operator=(const ListInit &) = delete;
677 
678  // Do not use sized deallocation due to trailing objects.
679  void operator delete(void *p) { ::operator delete(p); }
680 
681  static bool classof(const Init *I) {
682  return I->getKind() == IK_ListInit;
683  }
684  static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
685 
686  void Profile(FoldingSetNodeID &ID) const;
687 
688  Init *getElement(unsigned i) const {
689  assert(i < NumValues && "List element index out of range!");
690  return getTrailingObjects<Init *>()[i];
691  }
693  return cast<ListRecTy>(getType())->getElementType();
694  }
695 
696  Record *getElementAsRecord(unsigned i) const;
697 
698  Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
699 
700  Init *convertInitializerTo(RecTy *Ty) const override;
701 
702  /// This method is used by classes that refer to other
703  /// variables which may not be defined at the time they expression is formed.
704  /// If a value is set for the variable later, this method will be called on
705  /// users of the value to allow the value to propagate out.
706  ///
707  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
708 
709  std::string getAsString() const override;
710 
712  return makeArrayRef(getTrailingObjects<Init *>(), NumValues);
713  }
714 
715  const_iterator begin() const { return getTrailingObjects<Init *>(); }
716  const_iterator end () const { return begin() + NumValues; }
717 
718  size_t size () const { return NumValues; }
719  bool empty() const { return NumValues == 0; }
720 
721  /// This method is used to implement
722  /// VarListElementInit::resolveReferences. If the list element is resolvable
723  /// now, we return the resolved value, otherwise we return null.
724  Init *resolveListElementReference(Record &R, const RecordVal *RV,
725  unsigned Elt) const override;
726 
727  Init *getBit(unsigned Bit) const override {
728  llvm_unreachable("Illegal bit reference off list");
729  }
730 };
731 
732 /// Base class for operators
733 ///
734 class OpInit : public TypedInit {
735 protected:
736  explicit OpInit(InitKind K, RecTy *Type, uint8_t Opc)
737  : TypedInit(K, Type, Opc) {}
738 
739 public:
740  OpInit(const OpInit &) = delete;
741  OpInit &operator=(OpInit &) = delete;
742 
743  static bool classof(const Init *I) {
744  return I->getKind() >= IK_FirstOpInit &&
745  I->getKind() <= IK_LastOpInit;
746  }
747 
748  // Clone - Clone this operator, replacing arguments with the new list
749  virtual OpInit *clone(ArrayRef<Init *> Operands) const = 0;
750 
751  virtual unsigned getNumOperands() const = 0;
752  virtual Init *getOperand(unsigned i) const = 0;
753 
754  // Fold - If possible, fold this to a simpler init. Return this if not
755  // possible to fold.
756  virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
757 
758  Init *resolveListElementReference(Record &R, const RecordVal *RV,
759  unsigned Elt) const override;
760 
761  Init *getBit(unsigned Bit) const override;
762 };
763 
764 /// !op (X) - Transform an init.
765 ///
766 class UnOpInit : public OpInit, public FoldingSetNode {
767 public:
768  enum UnaryOp : uint8_t { CAST, HEAD, TAIL, SIZE, EMPTY };
769 
770 private:
771  Init *LHS;
772 
773  UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
774  : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
775 
776 public:
777  UnOpInit(const UnOpInit &) = delete;
778  UnOpInit &operator=(const UnOpInit &) = delete;
779 
780  static bool classof(const Init *I) {
781  return I->getKind() == IK_UnOpInit;
782  }
783 
784  static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
785 
786  void Profile(FoldingSetNodeID &ID) const;
787 
788  // Clone - Clone this operator, replacing arguments with the new list
789  OpInit *clone(ArrayRef<Init *> Operands) const override {
790  assert(Operands.size() == 1 &&
791  "Wrong number of operands for unary operation");
792  return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
793  }
794 
795  unsigned getNumOperands() const override { return 1; }
796 
797  Init *getOperand(unsigned i) const override {
798  assert(i == 0 && "Invalid operand id for unary operator");
799  return getOperand();
800  }
801 
802  UnaryOp getOpcode() const { return (UnaryOp)Opc; }
803  Init *getOperand() const { return LHS; }
804 
805  // Fold - If possible, fold this to a simpler init. Return this if not
806  // possible to fold.
807  Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
808 
809  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
810 
811  std::string getAsString() const override;
812 };
813 
814 /// !op (X, Y) - Combine two inits.
815 class BinOpInit : public OpInit, public FoldingSetNode {
816 public:
817  enum BinaryOp : uint8_t { ADD, AND, OR, SHL, SRA, SRL, LISTCONCAT,
818  STRCONCAT, CONCAT, EQ };
819 
820 private:
821  Init *LHS, *RHS;
822 
823  BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
824  OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
825 
826 public:
827  BinOpInit(const BinOpInit &) = delete;
828  BinOpInit &operator=(const BinOpInit &) = delete;
829 
830  static bool classof(const Init *I) {
831  return I->getKind() == IK_BinOpInit;
832  }
833 
834  static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
835  RecTy *Type);
836 
837  void Profile(FoldingSetNodeID &ID) const;
838 
839  // Clone - Clone this operator, replacing arguments with the new list
840  OpInit *clone(ArrayRef<Init *> Operands) const override {
841  assert(Operands.size() == 2 &&
842  "Wrong number of operands for binary operation");
843  return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
844  }
845 
846  unsigned getNumOperands() const override { return 2; }
847  Init *getOperand(unsigned i) const override {
848  switch (i) {
849  default: llvm_unreachable("Invalid operand id for binary operator");
850  case 0: return getLHS();
851  case 1: return getRHS();
852  }
853  }
854 
855  BinaryOp getOpcode() const { return (BinaryOp)Opc; }
856  Init *getLHS() const { return LHS; }
857  Init *getRHS() const { return RHS; }
858 
859  // Fold - If possible, fold this to a simpler init. Return this if not
860  // possible to fold.
861  Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
862 
863  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
864 
865  std::string getAsString() const override;
866 };
867 
868 /// !op (X, Y, Z) - Combine two inits.
869 class TernOpInit : public OpInit, public FoldingSetNode {
870 public:
871  enum TernaryOp : uint8_t { SUBST, FOREACH, IF };
872 
873 private:
874  Init *LHS, *MHS, *RHS;
875 
876  TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
877  RecTy *Type) :
878  OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
879 
880 public:
881  TernOpInit(const TernOpInit &) = delete;
882  TernOpInit &operator=(const TernOpInit &) = delete;
883 
884  static bool classof(const Init *I) {
885  return I->getKind() == IK_TernOpInit;
886  }
887 
888  static TernOpInit *get(TernaryOp opc, Init *lhs,
889  Init *mhs, Init *rhs,
890  RecTy *Type);
891 
892  void Profile(FoldingSetNodeID &ID) const;
893 
894  // Clone - Clone this operator, replacing arguments with the new list
895  OpInit *clone(ArrayRef<Init *> Operands) const override {
896  assert(Operands.size() == 3 &&
897  "Wrong number of operands for ternary operation");
898  return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
899  getType());
900  }
901 
902  unsigned getNumOperands() const override { return 3; }
903  Init *getOperand(unsigned i) const override {
904  switch (i) {
905  default: llvm_unreachable("Invalid operand id for ternary operator");
906  case 0: return getLHS();
907  case 1: return getMHS();
908  case 2: return getRHS();
909  }
910  }
911 
912  TernaryOp getOpcode() const { return (TernaryOp)Opc; }
913  Init *getLHS() const { return LHS; }
914  Init *getMHS() const { return MHS; }
915  Init *getRHS() const { return RHS; }
916 
917  // Fold - If possible, fold this to a simpler init. Return this if not
918  // possible to fold.
919  Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
920 
921  bool isComplete() const override {
922  return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
923  }
924 
925  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
926 
927  std::string getAsString() const override;
928 };
929 
930 /// 'Opcode' - Represent a reference to an entire variable object.
931 class VarInit : public TypedInit {
932  Init *VarName;
933 
934  explicit VarInit(Init *VN, RecTy *T)
935  : TypedInit(IK_VarInit, T), VarName(VN) {}
936 
937 public:
938  VarInit(const VarInit &) = delete;
939  VarInit &operator=(const VarInit &) = delete;
940 
941  static bool classof(const Init *I) {
942  return I->getKind() == IK_VarInit;
943  }
944 
945  static VarInit *get(StringRef VN, RecTy *T);
946  static VarInit *get(Init *VN, RecTy *T);
947 
948  StringRef getName() const;
949  Init *getNameInit() const { return VarName; }
950 
951  std::string getNameInitAsString() const {
952  return getNameInit()->getAsUnquotedString();
953  }
954 
955  Init *resolveListElementReference(Record &R, const RecordVal *RV,
956  unsigned Elt) const override;
957 
958  RecTy *getFieldType(StringInit *FieldName) const override;
959  Init *getFieldInit(Record &R, const RecordVal *RV,
960  StringInit *FieldName) const override;
961 
962  /// This method is used by classes that refer to other
963  /// variables which may not be defined at the time they expression is formed.
964  /// If a value is set for the variable later, this method will be called on
965  /// users of the value to allow the value to propagate out.
966  ///
967  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
968 
969  Init *getBit(unsigned Bit) const override;
970 
971  std::string getAsString() const override { return getName(); }
972 };
973 
974 /// Opcode{0} - Represent access to one bit of a variable or field.
975 class VarBitInit final : public TypedInit {
976  TypedInit *TI;
977  unsigned Bit;
978 
979  VarBitInit(TypedInit *T, unsigned B)
980  : TypedInit(IK_VarBitInit, BitRecTy::get()), TI(T), Bit(B) {
981  assert(T->getType() &&
982  (isa<IntRecTy>(T->getType()) ||
983  (isa<BitsRecTy>(T->getType()) &&
984  cast<BitsRecTy>(T->getType())->getNumBits() > B)) &&
985  "Illegal VarBitInit expression!");
986  }
987 
988 public:
989  VarBitInit(const VarBitInit &) = delete;
990  VarBitInit &operator=(const VarBitInit &) = delete;
991 
992  static bool classof(const Init *I) {
993  return I->getKind() == IK_VarBitInit;
994  }
995 
996  static VarBitInit *get(TypedInit *T, unsigned B);
997 
998  Init *convertInitializerTo(RecTy *Ty) const override;
999 
1000  Init *getBitVar() const override { return TI; }
1001  unsigned getBitNum() const override { return Bit; }
1002 
1003  std::string getAsString() const override;
1004  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
1005 
1007  unsigned Elt) const override {
1008  llvm_unreachable("Illegal element reference off bit");
1009  }
1010 
1011  Init *getBit(unsigned B) const override {
1012  assert(B < 1 && "Bit index out of range!");
1013  return const_cast<VarBitInit*>(this);
1014  }
1015 };
1016 
1017 /// List[4] - Represent access to one element of a var or
1018 /// field.
1020  TypedInit *TI;
1021  unsigned Element;
1022 
1023  VarListElementInit(TypedInit *T, unsigned E)
1024  : TypedInit(IK_VarListElementInit,
1025  cast<ListRecTy>(T->getType())->getElementType()),
1026  TI(T), Element(E) {
1027  assert(T->getType() && isa<ListRecTy>(T->getType()) &&
1028  "Illegal VarBitInit expression!");
1029  }
1030 
1031 public:
1032  VarListElementInit(const VarListElementInit &) = delete;
1033  VarListElementInit &operator=(const VarListElementInit &) = delete;
1034 
1035  static bool classof(const Init *I) {
1036  return I->getKind() == IK_VarListElementInit;
1037  }
1038 
1039  static VarListElementInit *get(TypedInit *T, unsigned E);
1040 
1041  TypedInit *getVariable() const { return TI; }
1042  unsigned getElementNum() const { return Element; }
1043 
1044  /// This method is used to implement
1045  /// VarListElementInit::resolveReferences. If the list element is resolvable
1046  /// now, we return the resolved value, otherwise we return null.
1047  Init *resolveListElementReference(Record &R, const RecordVal *RV,
1048  unsigned Elt) const override;
1049 
1050  std::string getAsString() const override;
1051  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
1052 
1053  Init *getBit(unsigned Bit) const override;
1054 };
1055 
1056 /// AL - Represent a reference to a 'def' in the description
1057 class DefInit : public TypedInit {
1058  friend class Record;
1059 
1060  Record *Def;
1061 
1062  DefInit(Record *D, RecordRecTy *T) : TypedInit(IK_DefInit, T), Def(D) {}
1063 
1064 public:
1065  DefInit(const DefInit &) = delete;
1066  DefInit &operator=(const DefInit &) = delete;
1067 
1068  static bool classof(const Init *I) {
1069  return I->getKind() == IK_DefInit;
1070  }
1071 
1072  static DefInit *get(Record*);
1073 
1074  Init *convertInitializerTo(RecTy *Ty) const override;
1075 
1076  Record *getDef() const { return Def; }
1077 
1078  //virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);
1079 
1080  RecTy *getFieldType(StringInit *FieldName) const override;
1081  Init *getFieldInit(Record &R, const RecordVal *RV,
1082  StringInit *FieldName) const override;
1083 
1084  std::string getAsString() const override;
1085 
1086  Init *getBit(unsigned Bit) const override {
1087  llvm_unreachable("Illegal bit reference off def");
1088  }
1089 
1090  /// This method is used to implement
1091  /// VarListElementInit::resolveReferences. If the list element is resolvable
1092  /// now, we return the resolved value, otherwise we return null.
1094  unsigned Elt) const override {
1095  llvm_unreachable("Illegal element reference off def");
1096  }
1097 };
1098 
1099 /// X.Y - Represent a reference to a subfield of a variable
1100 class FieldInit : public TypedInit {
1101  Init *Rec; // Record we are referring to
1102  StringInit *FieldName; // Field we are accessing
1103 
1104  FieldInit(Init *R, StringInit *FN)
1105  : TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
1106  assert(getType() && "FieldInit with non-record type!");
1107  }
1108 
1109 public:
1110  FieldInit(const FieldInit &) = delete;
1111  FieldInit &operator=(const FieldInit &) = delete;
1112 
1113  static bool classof(const Init *I) {
1114  return I->getKind() == IK_FieldInit;
1115  }
1116 
1117  static FieldInit *get(Init *R, StringInit *FN);
1118 
1119  Init *getBit(unsigned Bit) const override;
1120 
1121  Init *resolveListElementReference(Record &R, const RecordVal *RV,
1122  unsigned Elt) const override;
1123 
1124  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
1125 
1126  std::string getAsString() const override {
1127  return Rec->getAsString() + "." + FieldName->getValue().str();
1128  }
1129 };
1130 
1131 /// (v a, b) - Represent a DAG tree value. DAG inits are required
1132 /// to have at least one value then a (possibly empty) list of arguments. Each
1133 /// argument can have a name associated with it.
1134 class DagInit final : public TypedInit, public FoldingSetNode,
1135  public TrailingObjects<DagInit, Init *, StringInit *> {
1136  friend TrailingObjects;
1137 
1138  Init *Val;
1139  StringInit *ValName;
1140  unsigned NumArgs;
1141  unsigned NumArgNames;
1142 
1143  DagInit(Init *V, StringInit *VN, unsigned NumArgs, unsigned NumArgNames)
1144  : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
1145  NumArgs(NumArgs), NumArgNames(NumArgNames) {}
1146 
1147  size_t numTrailingObjects(OverloadToken<Init *>) const { return NumArgs; }
1148 
1149 public:
1150  DagInit(const DagInit &) = delete;
1151  DagInit &operator=(const DagInit &) = delete;
1152 
1153  static bool classof(const Init *I) {
1154  return I->getKind() == IK_DagInit;
1155  }
1156 
1157  static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
1158  ArrayRef<StringInit*> NameRange);
1159  static DagInit *get(Init *V, StringInit *VN,
1161 
1162  void Profile(FoldingSetNodeID &ID) const;
1163 
1164  Init *convertInitializerTo(RecTy *Ty) const override;
1165 
1166  Init *getOperator() const { return Val; }
1167 
1168  StringInit *getName() const { return ValName; }
1169 
1171  return ValName ? ValName->getValue() : StringRef();
1172  }
1173 
1174  unsigned getNumArgs() const { return NumArgs; }
1175 
1176  Init *getArg(unsigned Num) const {
1177  assert(Num < NumArgs && "Arg number out of range!");
1178  return getTrailingObjects<Init *>()[Num];
1179  }
1180 
1181  StringInit *getArgName(unsigned Num) const {
1182  assert(Num < NumArgNames && "Arg number out of range!");
1183  return getTrailingObjects<StringInit *>()[Num];
1184  }
1185 
1186  StringRef getArgNameStr(unsigned Num) const {
1187  StringInit *Init = getArgName(Num);
1188  return Init ? Init->getValue() : StringRef();
1189  }
1190 
1192  return makeArrayRef(getTrailingObjects<Init *>(), NumArgs);
1193  }
1194 
1196  return makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames);
1197  }
1198 
1199  Init *resolveReferences(Record &R, const RecordVal *RV) const override;
1200 
1201  std::string getAsString() const override;
1202 
1205 
1206  inline const_arg_iterator arg_begin() const { return getArgs().begin(); }
1207  inline const_arg_iterator arg_end () const { return getArgs().end(); }
1208 
1209  inline size_t arg_size () const { return NumArgs; }
1210  inline bool arg_empty() const { return NumArgs == 0; }
1211 
1212  inline const_name_iterator name_begin() const { return getArgNames().begin();}
1213  inline const_name_iterator name_end () const { return getArgNames().end(); }
1214 
1215  inline size_t name_size () const { return NumArgNames; }
1216  inline bool name_empty() const { return NumArgNames == 0; }
1217 
1218  Init *getBit(unsigned Bit) const override {
1219  llvm_unreachable("Illegal bit reference off dag");
1220  }
1221 
1223  unsigned Elt) const override {
1224  llvm_unreachable("Illegal element reference off dag");
1225  }
1226 };
1227 
1228 //===----------------------------------------------------------------------===//
1229 // High-Level Classes
1230 //===----------------------------------------------------------------------===//
1231 
1232 class RecordVal {
1233  friend class Record;
1234 
1235  Init *Name;
1237  Init *Value;
1238 
1239 public:
1240  RecordVal(Init *N, RecTy *T, bool P);
1241 
1242  StringRef getName() const;
1243  Init *getNameInit() const { return Name; }
1244 
1245  std::string getNameInitAsString() const {
1246  return getNameInit()->getAsUnquotedString();
1247  }
1248 
1249  bool getPrefix() const { return TyAndPrefix.getInt(); }
1250  RecTy *getType() const { return TyAndPrefix.getPointer(); }
1251  Init *getValue() const { return Value; }
1252 
1253  bool setValue(Init *V) {
1254  if (V) {
1255  Value = V->convertInitializerTo(getType());
1256  assert(!Value || !isa<TypedInit>(Value) ||
1257  cast<TypedInit>(Value)->getType()->typeIsConvertibleTo(getType()));
1258  return Value == nullptr;
1259  }
1260  Value = nullptr;
1261  return false;
1262  }
1263 
1264  void dump() const;
1265  void print(raw_ostream &OS, bool PrintSem = true) const;
1266 };
1267 
1268 inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
1269  RV.print(OS << " ");
1270  return OS;
1271 }
1272 
1273 class Record {
1274  static unsigned LastID;
1275 
1276  Init *Name;
1277  // Location where record was instantiated, followed by the location of
1278  // multiclass prototypes used.
1279  SmallVector<SMLoc, 4> Locs;
1280  SmallVector<Init *, 0> TemplateArgs;
1283 
1284  // Tracks Record instances. Not owned by Record.
1285  RecordKeeper &TrackedRecords;
1286 
1287  DefInit *TheInit = nullptr;
1288 
1289  // Unique record ID.
1290  unsigned ID;
1291 
1292  bool IsAnonymous;
1293 
1294  // Class-instance values can be used by other defs. For example, Struct<i>
1295  // is used here as a template argument to another class:
1296  //
1297  // multiclass MultiClass<int i> {
1298  // def Def : Class<Struct<i>>;
1299  //
1300  // These need to get fully resolved before instantiating any other
1301  // definitions that use them (e.g. Def). However, inside a multiclass they
1302  // can't be immediately resolved so we mark them ResolveFirst to fully
1303  // resolve them later as soon as the multiclass is instantiated.
1304  bool ResolveFirst = false;
1305 
1306  void init();
1307  void checkName();
1308 
1309 public:
1310  // Constructs a record.
1311  explicit Record(Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1312  bool Anonymous = false) :
1313  Name(N), Locs(locs.begin(), locs.end()), TrackedRecords(records),
1314  ID(LastID++), IsAnonymous(Anonymous) {
1315  init();
1316  }
1317 
1318  explicit Record(StringRef N, ArrayRef<SMLoc> locs, RecordKeeper &records,
1319  bool Anonymous = false)
1320  : Record(StringInit::get(N), locs, records, Anonymous) {}
1321 
1322  // When copy-constructing a Record, we must still guarantee a globally unique
1323  // ID number. Don't copy TheInit either since it's owned by the original
1324  // record. All other fields can be copied normally.
1325  Record(const Record &O) :
1326  Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
1327  Values(O.Values), SuperClasses(O.SuperClasses),
1328  TrackedRecords(O.TrackedRecords), ID(LastID++),
1329  IsAnonymous(O.IsAnonymous), ResolveFirst(O.ResolveFirst) { }
1330 
1331  static unsigned getNewUID() { return LastID++; }
1332 
1333  unsigned getID() const { return ID; }
1334 
1335  StringRef getName() const { return cast<StringInit>(Name)->getValue(); }
1336 
1337  Init *getNameInit() const {
1338  return Name;
1339  }
1340 
1341  const std::string getNameInitAsString() const {
1342  return getNameInit()->getAsUnquotedString();
1343  }
1344 
1345  void setName(Init *Name); // Also updates RecordKeeper.
1346 
1347  ArrayRef<SMLoc> getLoc() const { return Locs; }
1348 
1349  /// get the corresponding DefInit.
1350  DefInit *getDefInit();
1351 
1353  return TemplateArgs;
1354  }
1355 
1356  ArrayRef<RecordVal> getValues() const { return Values; }
1357 
1359  return SuperClasses;
1360  }
1361 
1362  bool isTemplateArg(Init *Name) const {
1363  for (Init *TA : TemplateArgs)
1364  if (TA == Name) return true;
1365  return false;
1366  }
1367 
1368  const RecordVal *getValue(const Init *Name) const {
1369  for (const RecordVal &Val : Values)
1370  if (Val.Name == Name) return &Val;
1371  return nullptr;
1372  }
1373 
1374  const RecordVal *getValue(StringRef Name) const {
1375  return getValue(StringInit::get(Name));
1376  }
1377 
1378  RecordVal *getValue(const Init *Name) {
1379  return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
1380  }
1381 
1383  return const_cast<RecordVal *>(static_cast<const Record *>(this)->getValue(Name));
1384  }
1385 
1386  void addTemplateArg(Init *Name) {
1387  assert(!isTemplateArg(Name) && "Template arg already defined!");
1388  TemplateArgs.push_back(Name);
1389  }
1390 
1391  void addValue(const RecordVal &RV) {
1392  assert(getValue(RV.getNameInit()) == nullptr && "Value already added!");
1393  Values.push_back(RV);
1394  if (Values.size() > 1)
1395  // Keep NAME at the end of the list. It makes record dumps a
1396  // bit prettier and allows TableGen tests to be written more
1397  // naturally. Tests can use CHECK-NEXT to look for Record
1398  // fields they expect to see after a def. They can't do that if
1399  // NAME is the first Record field.
1400  std::swap(Values[Values.size() - 2], Values[Values.size() - 1]);
1401  }
1402 
1403  void removeValue(Init *Name) {
1404  for (unsigned i = 0, e = Values.size(); i != e; ++i)
1405  if (Values[i].getNameInit() == Name) {
1406  Values.erase(Values.begin()+i);
1407  return;
1408  }
1409  llvm_unreachable("Cannot remove an entry that does not exist!");
1410  }
1411 
1412  void removeValue(StringRef Name) {
1413  removeValue(StringInit::get(Name));
1414  }
1415 
1416  bool isSubClassOf(const Record *R) const {
1417  for (const auto &SCPair : SuperClasses)
1418  if (SCPair.first == R)
1419  return true;
1420  return false;
1421  }
1422 
1423  bool isSubClassOf(StringRef Name) const {
1424  for (const auto &SCPair : SuperClasses) {
1425  if (const auto *SI = dyn_cast<StringInit>(SCPair.first->getNameInit())) {
1426  if (SI->getValue() == Name)
1427  return true;
1428  } else if (SCPair.first->getNameInitAsString() == Name) {
1429  return true;
1430  }
1431  }
1432  return false;
1433  }
1434 
1435  void addSuperClass(Record *R, SMRange Range) {
1436  assert(!isSubClassOf(R) && "Already subclassing record!");
1437  SuperClasses.push_back(std::make_pair(R, Range));
1438  }
1439 
1440  /// If there are any field references that refer to fields
1441  /// that have been filled in, we can propagate the values now.
1442  void resolveReferences() { resolveReferencesTo(nullptr); }
1443 
1444  /// If anything in this record refers to RV, replace the
1445  /// reference to RV with the RHS of RV. If RV is null, we resolve all
1446  /// possible references.
1447  void resolveReferencesTo(const RecordVal *RV);
1448 
1450  return TrackedRecords;
1451  }
1452 
1453  bool isAnonymous() const {
1454  return IsAnonymous;
1455  }
1456 
1457  bool isResolveFirst() const {
1458  return ResolveFirst;
1459  }
1460 
1461  void setResolveFirst(bool b) {
1462  ResolveFirst = b;
1463  }
1464 
1465  void print(raw_ostream &OS) const;
1466  void dump() const;
1467 
1468  //===--------------------------------------------------------------------===//
1469  // High-level methods useful to tablegen back-ends
1470  //
1471 
1472  /// Return the initializer for a value with the specified name,
1473  /// or throw an exception if the field does not exist.
1474  Init *getValueInit(StringRef FieldName) const;
1475 
1476  /// Return true if the named field is unset.
1477  bool isValueUnset(StringRef FieldName) const {
1478  return isa<UnsetInit>(getValueInit(FieldName));
1479  }
1480 
1481  /// This method looks up the specified field and returns
1482  /// its value as a string, throwing an exception if the field does not exist
1483  /// or if the value is not a string.
1484  StringRef getValueAsString(StringRef FieldName) const;
1485 
1486  /// This method looks up the specified field and returns
1487  /// its value as a BitsInit, throwing an exception if the field does not exist
1488  /// or if the value is not the right type.
1489  BitsInit *getValueAsBitsInit(StringRef FieldName) const;
1490 
1491  /// This method looks up the specified field and returns
1492  /// its value as a ListInit, throwing an exception if the field does not exist
1493  /// or if the value is not the right type.
1494  ListInit *getValueAsListInit(StringRef FieldName) const;
1495 
1496  /// This method looks up the specified field and
1497  /// returns its value as a vector of records, throwing an exception if the
1498  /// field does not exist or if the value is not the right type.
1499  std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
1500 
1501  /// This method looks up the specified field and
1502  /// returns its value as a vector of integers, throwing an exception if the
1503  /// field does not exist or if the value is not the right type.
1504  std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
1505 
1506  /// This method looks up the specified field and
1507  /// returns its value as a vector of strings, throwing an exception if the
1508  /// field does not exist or if the value is not the right type.
1509  std::vector<StringRef> getValueAsListOfStrings(StringRef FieldName) const;
1510 
1511  /// This method looks up the specified field and returns its
1512  /// value as a Record, throwing an exception if the field does not exist or if
1513  /// the value is not the right type.
1514  Record *getValueAsDef(StringRef FieldName) const;
1515 
1516  /// This method looks up the specified field and returns its
1517  /// value as a bit, throwing an exception if the field does not exist or if
1518  /// the value is not the right type.
1519  bool getValueAsBit(StringRef FieldName) const;
1520 
1521  /// This method looks up the specified field and
1522  /// returns its value as a bit. If the field is unset, sets Unset to true and
1523  /// returns false.
1524  bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const;
1525 
1526  /// This method looks up the specified field and returns its
1527  /// value as an int64_t, throwing an exception if the field does not exist or
1528  /// if the value is not the right type.
1529  int64_t getValueAsInt(StringRef FieldName) const;
1530 
1531  /// This method looks up the specified field and returns its
1532  /// value as an Dag, throwing an exception if the field does not exist or if
1533  /// the value is not the right type.
1534  DagInit *getValueAsDag(StringRef FieldName) const;
1535 };
1536 
1537 raw_ostream &operator<<(raw_ostream &OS, const Record &R);
1538 
1539 struct MultiClass {
1540  Record Rec; // Placeholder for template args and Name.
1541  using RecordVector = std::vector<std::unique_ptr<Record>>;
1543 
1544  void dump() const;
1545 
1547  Rec(Name, Loc, Records) {}
1548 };
1549 
1551  using RecordMap = std::map<std::string, std::unique_ptr<Record>>;
1552  RecordMap Classes, Defs;
1553 
1554 public:
1555  const RecordMap &getClasses() const { return Classes; }
1556  const RecordMap &getDefs() const { return Defs; }
1557 
1559  auto I = Classes.find(Name);
1560  return I == Classes.end() ? nullptr : I->second.get();
1561  }
1562 
1564  auto I = Defs.find(Name);
1565  return I == Defs.end() ? nullptr : I->second.get();
1566  }
1567 
1568  void addClass(std::unique_ptr<Record> R) {
1569  bool Ins = Classes.insert(std::make_pair(R->getName(),
1570  std::move(R))).second;
1571  (void)Ins;
1572  assert(Ins && "Class already exists");
1573  }
1574 
1575  void addDef(std::unique_ptr<Record> R) {
1576  bool Ins = Defs.insert(std::make_pair(R->getName(),
1577  std::move(R))).second;
1578  (void)Ins;
1579  assert(Ins && "Record already exists");
1580  }
1581 
1582  //===--------------------------------------------------------------------===//
1583  // High-level helper methods, useful for tablegen backends...
1584 
1585  /// This method returns all concrete definitions
1586  /// that derive from the specified class name. A class with the specified
1587  /// name must exist.
1588  std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
1589 
1590  void dump() const;
1591 };
1592 
1593 /// Sorting predicate to sort record pointers by name.
1594 struct LessRecord {
1595  bool operator()(const Record *Rec1, const Record *Rec2) const {
1596  return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
1597  }
1598 };
1599 
1600 /// Sorting predicate to sort record pointers by their
1601 /// unique ID. If you just need a deterministic order, use this, since it
1602 /// just compares two `unsigned`; the other sorting predicates require
1603 /// string manipulation.
1605  bool operator()(const Record *LHS, const Record *RHS) const {
1606  return LHS->getID() < RHS->getID();
1607  }
1608 };
1609 
1610 /// Sorting predicate to sort record pointers by their
1611 /// name field.
1613  bool operator()(const Record *Rec1, const Record *Rec2) const {
1614  return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
1615  }
1616 };
1617 
1619  static bool ascii_isdigit(char x) { return x >= '0' && x <= '9'; }
1620 
1621  struct RecordParts {
1623 
1625  if (Rec.empty())
1626  return;
1627 
1628  size_t Len = 0;
1629  const char *Start = Rec.data();
1630  const char *Curr = Start;
1631  bool isDigitPart = ascii_isdigit(Curr[0]);
1632  for (size_t I = 0, E = Rec.size(); I != E; ++I, ++Len) {
1633  bool isDigit = ascii_isdigit(Curr[I]);
1634  if (isDigit != isDigitPart) {
1635  Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
1636  Len = 0;
1637  Start = &Curr[I];
1638  isDigitPart = ascii_isdigit(Curr[I]);
1639  }
1640  }
1641  // Push the last part.
1642  Parts.push_back(std::make_pair(isDigitPart, StringRef(Start, Len)));
1643  }
1644 
1645  size_t size() { return Parts.size(); }
1646 
1647  std::pair<bool, StringRef> getPart(size_t i) {
1648  assert (i < Parts.size() && "Invalid idx!");
1649  return Parts[i];
1650  }
1651  };
1652 
1653  bool operator()(const Record *Rec1, const Record *Rec2) const {
1654  RecordParts LHSParts(StringRef(Rec1->getName()));
1655  RecordParts RHSParts(StringRef(Rec2->getName()));
1656 
1657  size_t LHSNumParts = LHSParts.size();
1658  size_t RHSNumParts = RHSParts.size();
1659  assert (LHSNumParts && RHSNumParts && "Expected at least one part!");
1660 
1661  if (LHSNumParts != RHSNumParts)
1662  return LHSNumParts < RHSNumParts;
1663 
1664  // We expect the registers to be of the form [_a-zA-Z]+([0-9]*[_a-zA-Z]*)*.
1665  for (size_t I = 0, E = LHSNumParts; I < E; I+=2) {
1666  std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
1667  std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
1668  // Expect even part to always be alpha.
1669  assert (LHSPart.first == false && RHSPart.first == false &&
1670  "Expected both parts to be alpha.");
1671  if (int Res = LHSPart.second.compare(RHSPart.second))
1672  return Res < 0;
1673  }
1674  for (size_t I = 1, E = LHSNumParts; I < E; I+=2) {
1675  std::pair<bool, StringRef> LHSPart = LHSParts.getPart(I);
1676  std::pair<bool, StringRef> RHSPart = RHSParts.getPart(I);
1677  // Expect odd part to always be numeric.
1678  assert (LHSPart.first == true && RHSPart.first == true &&
1679  "Expected both parts to be numeric.");
1680  if (LHSPart.second.size() != RHSPart.second.size())
1681  return LHSPart.second.size() < RHSPart.second.size();
1682 
1683  unsigned LHSVal, RHSVal;
1684 
1685  bool LHSFailed = LHSPart.second.getAsInteger(10, LHSVal); (void)LHSFailed;
1686  assert(!LHSFailed && "Unable to convert LHS to integer.");
1687  bool RHSFailed = RHSPart.second.getAsInteger(10, RHSVal); (void)RHSFailed;
1688  assert(!RHSFailed && "Unable to convert RHS to integer.");
1689 
1690  if (LHSVal != RHSVal)
1691  return LHSVal < RHSVal;
1692  }
1693  return LHSNumParts < RHSNumParts;
1694  }
1695 };
1696 
1698 
1699 /// Return an Init with a qualifier prefix referring
1700 /// to CurRec's name.
1701 Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass,
1702  Init *Name, StringRef Scoper);
1703 
1704 } // end namespace llvm
1705 
1706 #endif // LLVM_TABLEGEN_RECORD_H
Init * getOperand() const
Definition: Record.h:803
static BinOpInit * get(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:769
unsigned getNumBits() const
Definition: Record.h:511
RecordVal * getValue(const Init *Name)
Definition: Record.h:1378
Represents a range in source code.
Definition: SMLoc.h:49
static bool classof(const Init *I)
Definition: Record.h:1035
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:1222
std::string getAsString() const override
Definition: Record.h:143
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:245
RecTyKind
Subclass discriminator (for dyn_cast<> et al.)
Definition: Record.h:54
void print(raw_ostream &OS) const
Definition: Record.h:76
bool getValue() const
Definition: Record.h:470
const_name_iterator name_end() const
Definition: Record.h:1213
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:236
bool allInComplete() const
Definition: Record.h:522
Init * getValue() const
Definition: Record.h:1251
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:329
Sorting predicate to sort record pointers by name.
Definition: Record.h:1594
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
X.Y - Represent a reference to a subfield of a variable.
Definition: Record.h:1100
PointerTy getPointer() const
virtual std::string getAsUnquotedString() const
Convert this value to a string form, without adding quote markers.
Definition: Record.h:326
bool empty() const
Definition: Record.h:719
[AL, AH, CL] - Represent a list of defs
Definition: Record.h:663
iterator begin() const
Definition: ArrayRef.h:137
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
&#39;7&#39; - Represent an initialization by a literal integer value.
Definition: Record.h:547
StringRef getNameStr() const
Definition: Record.h:1170
virtual RecTy * getFieldType(StringInit *FieldName) const
This method is used to implement the FieldInit class.
Definition: Record.h:355
static bool classof(const RecTy *RT)
Definition: Record.h:155
&#39;list<Ty>&#39; - Represent a list of values, all of which must be of the specified type.
Definition: Record.h:187
!op (X, Y) - Combine two inits.
Definition: Record.h:815
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:604
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
resolveListElementReference - This method is used to implement VarListElementInit::resolveReferences...
Definition: Record.h:611
Init * getRHS() const
Definition: Record.h:915
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:533
Sorting predicate to sort record pointers by their name field.
Definition: Record.h:1612
AL - Represent a reference to a &#39;def&#39; in the description.
Definition: Record.h:1057
static bool classof(const Init *I)
Definition: Record.h:830
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static UnOpInit * get(UnaryOp opc, Init *lhs, RecTy *Type)
Definition: Record.cpp:622
static bool classof(const Init *I)
Definition: Record.h:503
void addDef(std::unique_ptr< Record > R)
Definition: Record.h:1575
Init * getOperand(unsigned i) const override
Definition: Record.h:797
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:1093
static bool classof(const RecTy *RT)
Definition: Record.h:99
std::string getAsString() const override
Definition: Record.h:105
static CodeRecTy * get()
Definition: Record.h:141
void setResolveFirst(bool b)
Definition: Record.h:1461
static bool classof(const Init *I)
Definition: Record.h:1068
void removeValue(StringRef Name)
Definition: Record.h:1412
&#39;{ a, b, c }&#39; - Represents an initializer for a BitsRecTy value.
Definition: Record.h:489
std::pair< bool, StringRef > getPart(size_t i)
Definition: Record.h:1647
std::string getNameInitAsString() const
Definition: Record.h:1245
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:474
static BitRecTy * get()
Definition: Record.h:103
static bool classof(const Init *I)
Definition: Record.h:405
Sorting predicate to sort record pointers by their unique ID.
Definition: Record.h:1604
static bool classof(const Init *I)
Definition: Record.h:632
Init * getArg(unsigned Num) const
Definition: Record.h:1176
ArrayRef< std::pair< Record *, SMRange > > getSuperClasses() const
Definition: Record.h:1358
&#39;?&#39; - Represents an uninitialized value
Definition: Record.h:431
static bool classof(const Init *I)
Definition: Record.h:464
void addSuperClass(Record *R, SMRange Range)
Definition: Record.h:1435
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:446
&#39;true&#39;/&#39;false&#39; - Represent a concrete initializer for a bit.
Definition: Record.h:455
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1218
TypedInit * getVariable() const
Definition: Record.h:1041
static bool classof(const Init *I)
Definition: Record.h:743
static BitsRecTy * get(unsigned Sz)
Definition: Record.cpp:74
Record * getDef() const
Definition: Record.h:1076
static bool classof(const RecTy *RT)
Definition: Record.h:233
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:616
static bool classof(const Init *I)
Definition: Record.h:557
This is the common super-class of types that have a specific, explicit, type.
Definition: Record.h:394
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
Shift and rotation operations.
Definition: ISDOpcodes.h:380
void addClass(std::unique_ptr< Record > R)
Definition: Record.h:1568
RecTy * getElementType() const
Definition: Record.h:200
static StringRecTy * get()
Definition: Record.h:178
ArrayRef< Init * > getTemplateArgs() const
Definition: Record.h:1352
List[4] - Represent access to one element of a var or field.
Definition: Record.h:1019
&#39;[classname]&#39; - Represent an instance of a class, such as: (R32 X = EAX).
Definition: Record.h:225
virtual bool isComplete() const
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:315
bool isAnonymous() const
Definition: Record.h:1453
static StringRef getName(Value *V)
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:1595
Init * getLHS() const
Definition: Record.h:856
void print(raw_ostream &OS, bool PrintSem=true) const
Definition: Record.cpp:1595
const_iterator end() const
Definition: Record.h:716
StringInit * getArgName(unsigned Num) const
Definition: Record.h:1181
virtual Init * convertInitializerBitRange(ArrayRef< unsigned > Bits) const
This method is used to implement the bitrange selection operator.
Definition: Record.h:340
bool operator()(const Record *LHS, const Record *RHS) const
Definition: Record.h:1605
Record * getClass(StringRef Name) const
Definition: Record.h:1558
SmallVectorImpl< Init * >::const_iterator const_arg_iterator
Definition: Record.h:1203
ArrayRef< SMLoc > getLoc() const
Definition: Record.h:1347
virtual Init * resolveReferences(Record &R, const RecordVal *RV) const
This method is used by classes that refer to other variables which may not be defined at the time the...
Definition: Record.h:371
&#39;bits<n>&#39; - Represent a fixed number of bits
Definition: Record.h:111
bool isTemplateArg(Init *Name) const
Definition: Record.h:1362
IntType getInt() const
#define T
RecTy * getType() const
Definition: Record.h:1250
StringRef getValue() const
Definition: Record.h:638
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:201
void resolveReferences()
If there are any field references that refer to fields that have been filled in, we can propagate the...
Definition: Record.h:1442
bool isSubClassOf(const Record *R) const
Definition: Record.h:1416
static bool classof(const RecTy *RT)
Definition: Record.h:195
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
Record(Init *N, ArrayRef< SMLoc > locs, RecordKeeper &records, bool Anonymous=false)
Definition: Record.h:1311
ArrayRef< Init * > getValues() const
Definition: Record.h:711
ArrayRef< Init * > getArgs() const
Definition: Record.h:1191
OpInit(InitKind K, RecTy *Type, uint8_t Opc)
Definition: Record.h:736
static bool classof(const Init *I)
Definition: Record.h:992
static bool classof(const RecTy *RT)
Definition: Record.h:214
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:1613
static bool classof(const RecTy *RT)
Definition: Record.h:173
static bool classof(const Init *I)
Definition: Record.h:1113
unsigned getNumBits() const
Definition: Record.h:123
void print(raw_ostream &OS) const
Print out this value.
Definition: Record.h:318
#define EQ(a, b)
Definition: regexec.c:112
virtual Init * convertInitListSlice(ArrayRef< unsigned > Elements) const
This method is used to implement the list slice selection operator.
Definition: Record.h:348
ArrayRef< RecordVal > getValues() const
Definition: Record.h:1356
&#39;code&#39; - Represent a code fragment
Definition: Record.h:131
SmallVectorImpl< StringInit * >::const_iterator const_name_iterator
Definition: Record.h:1204
virtual Init * convertInitializerTo(RecTy *Ty) const =0
This virtual function converts to the appropriate Init based on the passed in type.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:306
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:971
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:1006
unsigned getElementNum() const
Definition: Record.h:1042
Base class for operators.
Definition: Record.h:734
#define P(N)
MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records)
Definition: Record.h:1546
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:406
OpInit * clone(ArrayRef< Init *> Operands) const override
Definition: Record.h:840
RecTy(RecTyKind K)
Definition: Record.h:70
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1086
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:651
RecTy * getType() const
Definition: Record.h:410
Init * getElement(unsigned i) const
Definition: Record.h:688
Init * getNameInit() const
Definition: Record.h:1243
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:46
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:516
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
"foo" - Represent an initialization by a string value.
Definition: Record.h:584
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:116
RecordVector DefPrototypes
Definition: Record.h:1542
unsigned getNumOperands() const override
Definition: Record.h:846
Record * getRecord() const
Definition: Record.h:239
Init * getRHS() const
Definition: Record.h:857
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:31
bool setValue(Init *V)
Definition: Record.h:1253
!op (X) - Transform an init.
Definition: Record.h:766
Init * getOperand(unsigned i) const override
Definition: Record.h:903
const std::string getNameInitAsString() const
Definition: Record.h:1341
bool getPrefix() const
Definition: Record.h:1249
SmallVector< std::pair< bool, StringRef >, 4 > Parts
Definition: Record.h:1622
bool name_empty() const
Definition: Record.h:1216
void dump() const
Definition: Record.cpp:52
See the file comment for details on the usage of the TrailingObjects type.
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:1714
OpInit * clone(ArrayRef< Init *> Operands) const override
Definition: Record.h:895
UnaryOp getOpcode() const
Definition: Record.h:802
static bool classof(const Init *I)
Definition: Record.h:780
virtual ~RecTy()=default
int64_t getValue() const
Definition: Record.h:563
&#39;string&#39; - Represent an string value
Definition: Record.h:167
static BitInit * get(bool V)
Definition: Record.cpp:208
size_t arg_size() const
Definition: Record.h:1209
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:451
const RecordVal * getValue(StringRef Name) const
Definition: Record.h:1374
static bool classof(const Init *I)
Definition: Record.h:884
std::string getAsUnquotedString() const override
Convert this value to a string form, without adding quote markers.
Definition: Record.h:646
iterator erase(const_iterator CI)
Definition: SmallVector.h:447
StringInit * getName() const
Definition: Record.h:1168
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:921
virtual Init * getFieldInit(Record &R, const RecordVal *RV, StringInit *FieldName) const
This method complements getFieldType to return the initializer for the specified field.
Definition: Record.h:362
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool classof(const Init *I)
Definition: Record.h:438
Record(StringRef N, ArrayRef< SMLoc > locs, RecordKeeper &records, bool Anonymous=false)
Definition: Record.h:1318
void addTemplateArg(Init *Name)
Definition: Record.h:1386
static bool classof(const Init *I)
Definition: Record.h:594
const RecordVal * getValue(const Init *Name) const
Definition: Record.h:1368
const RecordMap & getClasses() const
Definition: Record.h:1555
Init * getOperator() const
Definition: Record.h:1166
Init * getMHS() const
Definition: Record.h:914
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
RecordVal * getValue(StringRef Name)
Definition: Record.h:1382
static StringInit * get(StringRef)
Definition: Record.cpp:434
static bool classof(const RecTy *RT)
Definition: Record.h:137
Init * QualifyName(Record &CurRec, MultiClass *CurMultiClass, Init *Name, StringRef Scoper)
Return an Init with a qualifier prefix referring to CurRec&#39;s name.
Definition: Record.cpp:1906
static bool classof(const RecTy *RT)
Definition: Record.h:117
RecordKeeper & getRecords() const
Definition: Record.h:1449
unsigned getNumArgs() const
Definition: Record.h:1174
bool isSubClassOf(StringRef Name) const
Definition: Record.h:1423
unsigned getID() const
Definition: Record.h:1333
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
uint8_t Opc
Definition: Record.h:297
RecTy * getElementType() const
Definition: Record.h:692
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:578
virtual Init * getBitVar() const
This method is used to retrieve the initializer for bit reference.
Definition: Record.h:381
bool arg_empty() const
Definition: Record.h:1210
Init * resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const override
This method is used to implement VarListElementInit::resolveReferences.
Definition: Record.h:573
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:924
std::vector< std::unique_ptr< Record > > RecordVector
Definition: Record.h:1541
static unsigned getNewUID()
Definition: Record.h:1331
Init * getBitVar() const override
This method is used to retrieve the initializer for bit reference.
Definition: Record.h:1000
void removeValue(Init *Name)
Definition: Record.h:1403
bool operator()(const Record *Rec1, const Record *Rec2) const
Definition: Record.h:1653
static bool classof(const Init *I)
Definition: Record.h:681
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:540
&#39;int&#39; - Represent an integer value of no particular size
Definition: Record.h:149
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:642
OpInit * clone(ArrayRef< Init *> Operands) const override
Definition: Record.h:789
InitKind getKind() const
Definition: Record.h:303
static bool ascii_isdigit(char x)
Definition: Record.h:1619
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
Definition: StringExtras.h:67
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:363
std::string getNameInitAsString() const
Definition: Record.h:951
std::string getAsString() const override
Definition: Record.h:161
Init * getNameInit() const
Definition: Record.h:1337
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:136
size_t name_size() const
Definition: Record.h:1215
TypedInit(InitKind K, RecTy *T, uint8_t Opc=0)
Definition: Record.h:398
Init * getBit(unsigned B) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:1011
static DagRecTy * get()
Definition: Record.h:218
void addValue(const RecordVal &RV)
Definition: Record.h:1391
static TernOpInit * get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type)
Definition: Record.cpp:924
const_iterator begin() const
Definition: Record.h:715
#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:151
Opcode{0} - Represent access to one bit of a variable or field.
Definition: Record.h:975
bool isComplete() const override
This virtual method should be overridden by values that may not be completely specified yet...
Definition: Record.h:450
&#39;Opcode&#39; - Represent a reference to an entire variable object.
Definition: Record.h:931
Init(InitKind K, uint8_t Opc=0)
Definition: Record.h:306
&#39;bit&#39; - Represent a single bit
Definition: Record.h:93
!op (X, Y, Z) - Combine two inits.
Definition: Record.h:869
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2018
Init * getOperand(unsigned i) const override
Definition: Record.h:847
const_name_iterator name_begin() const
Definition: Record.h:1212
RecTyKind getRecTyKind() const
Definition: Record.h:73
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:61
StringRef getValue() const
Definition: Record.h:600
&#39;dag&#39; - Represent a dag fragment
Definition: Record.h:208
unsigned getNumOperands() const override
Definition: Record.h:795
Record * getDef(StringRef Name) const
Definition: Record.h:1563
ArrayRef< StringInit * > getArgNames() const
Definition: Record.h:1195
StringRef getName() const
Definition: Record.h:1335
virtual unsigned getBitNum() const
This method is used to retrieve the bit number of a bit reference.
Definition: Record.h:385
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:656
BinaryOp getOpcode() const
Definition: Record.h:855
TernaryOp getOpcode() const
Definition: Record.h:912
LLVM Value Representation.
Definition: Value.h:73
(v a, b) - Represent a DAG tree value.
Definition: Record.h:1134
virtual std::string getAsString() const =0
Convert this value to a string form.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
size_t size() const
Definition: Record.h:718
This header defines support for implementing classes that have some trailing object (or arrays of obj...
unsigned getNumOperands() const override
Definition: Record.h:902
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:727
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:484
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
InitKind
Discriminator enum (for isa<>, dyn_cast<>, et al.)
Definition: Record.h:269
Init *const * const_iterator
Definition: Record.h:668
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
unsigned getBitNum() const override
This method is used to retrieve the bit number of a bit reference.
Definition: Record.h:1001
std::string getAsUnquotedString() const override
Convert this value to a string form, without adding quote markers.
Definition: Record.h:606
static bool classof(const Init *I)
Definition: Record.h:1153
Init * getBit(unsigned Bit) const override
This method is used to return the initializer for the specified bit.
Definition: Record.h:479
std::string getAsString() const override
Convert this value to a string form.
Definition: Record.h:1126
Init * getLHS() const
Definition: Record.h:913
virtual std::string getAsString() const =0
Represents a location in source code.
Definition: SMLoc.h:24
ListRecTy * getListTy()
Returns the type representing list<this>.
Definition: Record.cpp:55
Init * getNameInit() const
Definition: Record.h:949
const_arg_iterator arg_begin() const
Definition: Record.h:1206
bool isResolveFirst() const
Definition: Record.h:1457
Record(const Record &O)
Definition: Record.h:1325
StringRef getArgNameStr(unsigned Num) const
Definition: Record.h:1186
bool isValueUnset(StringRef FieldName) const
Return true if the named field is unset.
Definition: Record.h:1477
const RecordMap & getDefs() const
Definition: Record.h:1556
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
#define T1
static bool classof(const Init *I)
Definition: Record.h:941
static IntRecTy * get()
Definition: Record.h:159
const_arg_iterator arg_end() const
Definition: Record.h:1207