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