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