CIRCT  19.0.0git
FIRRTLTypes.h
Go to the documentation of this file.
1 //===- FIRRTLTypes.h - FIRRTL Type System -----------------------*- 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 type system for the FIRRTL Dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_FIRRTL_TYPES_H
14 #define CIRCT_DIALECT_FIRRTL_TYPES_H
15 
20 #include "circt/Support/LLVM.h"
21 #include "mlir/IR/OpDefinition.h"
22 #include "mlir/IR/Types.h"
23 #include "llvm/ADT/TypeSwitch.h"
24 
25 namespace circt {
26 namespace firrtl {
27 namespace detail {
28 struct FIRRTLBaseTypeStorage;
29 struct WidthTypeStorage;
30 struct BundleTypeStorage;
31 struct FVectorTypeStorage;
32 struct FEnumTypeStorage;
33 struct CMemoryTypeStorage;
34 struct RefTypeStorage;
35 struct BaseTypeAliasStorage;
36 struct OpenBundleTypeStorage;
37 struct OpenVectorTypeStorage;
38 struct ClassTypeStorage;
39 } // namespace detail.
40 
41 class AnyRefType;
42 class ClassType;
43 class ClockType;
44 class ResetType;
45 class AsyncResetType;
46 class SIntType;
47 class UIntType;
48 class AnalogType;
49 class BundleType;
50 class OpenBundleType;
51 class OpenVectorType;
52 class FVectorType;
53 class FEnumType;
54 class RefType;
55 class PropertyType;
56 class StringType;
57 class FIntegerType;
58 class ListType;
59 class PathType;
60 class BoolType;
61 class DoubleType;
62 class BaseTypeAliasType;
63 
64 /// A collection of bits indicating the recursive properties of a type.
66  /// Whether the type only contains passive elements.
67  bool isPassive : 1;
68  /// Whether the type contains a reference type.
70  /// Whether the type contains an analog type.
71  bool containsAnalog : 1;
72  /// Whether the type contains a const type.
73  bool containsConst : 1;
74  /// Whether the type contains a type alias.
76  /// Whether the type has any uninferred bit widths.
78  /// Whether the type has any uninferred reset.
80 };
81 
82 // This is a common base class for all FIRRTL types.
83 class FIRRTLType : public Type {
84 public:
85  /// Support method to enable LLVM-style type casting.
86  static bool classof(Type type) {
87  return llvm::isa<FIRRTLDialect>(type.getDialect());
88  }
89 
90  /// Return the recursive properties of the type, containing the `isPassive`,
91  /// `containsAnalog`, and `hasUninferredWidth` bits, among others.
93 
94  //===--------------------------------------------------------------------===//
95  // Convenience methods for accessing recursive type properties
96  //===--------------------------------------------------------------------===//
97 
98  /// Returns true if this is or contains a 'const' type.
100 
101  /// Return true if this is or contains an Analog type.
103 
104  /// Return true if this is or contains a Reference type.
107  }
108 
109  /// Return true if this is an anonymous type (no type alias).
112  }
113 
114  /// Return true if this type contains an uninferred bit width.
117  }
118 
119  /// Return true if this type contains an uninferred bit reset.
122  }
123 
124  //===--------------------------------------------------------------------===//
125  // Type classifications
126  //===--------------------------------------------------------------------===//
127 
128  /// Return true if this is a 'ground' type, aka a non-aggregate type.
129  bool isGround();
130 
131  /// Returns true if this is a 'const' type that can only hold compile-time
132  /// constant values
133  bool isConst();
134 
135 protected:
136  using Type::Type;
137 };
138 
139 // Common base class for all base FIRRTL types.
141  : public FIRRTLType::TypeBase<FIRRTLBaseType, FIRRTLType,
142  detail::FIRRTLBaseTypeStorage> {
143 public:
144  using Base::Base;
145 
146  /// Returns true if this is a 'const' type that can only hold compile-time
147  /// constant values
148  bool isConst();
149 
150  /// Return true if this is a "passive" type - one that contains no "flip"
151  /// types recursively within itself.
152  bool isPassive() const { return getRecursiveTypeProperties().isPassive; }
153 
154  /// Return this type with any flip types recursively removed from itself.
156 
157  /// Return this type with any type alias types recursively removed from
158  /// itself.
160 
161  /// Return a 'const' or non-'const' version of this type.
163 
164  /// Return this type with a 'const' modifiers dropped
166 
167  /// Return this type with all ground types replaced with UInt<1>. This is
168  /// used for `mem` operations.
170 
171  /// Return this type with widths of all ground types removed. This
172  /// enables two types to be compared by structure and name ignoring
173  /// widths.
175 
176  /// If this is an IntType, AnalogType, or sugar type for a single bit (Clock,
177  /// Reset, etc) then return the bitwidth. Return -1 if the is one of these
178  /// types but without a specified bitwidth. Return -2 if this isn't a simple
179  /// type.
180  int32_t getBitWidthOrSentinel();
181 
182  /// Support method to enable LLVM-style type casting.
183  static bool classof(Type type) {
184  return llvm::isa<FIRRTLDialect>(type.getDialect()) &&
185  !llvm::isa<PropertyType, RefType, OpenBundleType, OpenVectorType>(
186  type);
187  }
188 
189  /// Returns true if this is a non-const "passive" that which is not analog.
190  bool isRegisterType() {
191  return isPassive() && !containsAnalog() && !containsConst();
192  }
193 
194  /// Return true if this is a valid "reset" type.
195  bool isResetType();
196 };
197 
198 /// Returns true if this is a 'const' type whose value is guaranteed to be
199 /// unchanging at circuit execution time
200 bool isConst(Type type);
201 
202 /// Returns true if the type is or contains a 'const' type whose value is
203 /// guaranteed to be unchanging at circuit execution time
204 bool containsConst(Type type);
205 
206 /// Return true if the type has zero bit width.
207 bool hasZeroBitWidth(FIRRTLType type);
208 
209 /// Returns whether the two types are equivalent. This implements the exact
210 /// definition of type equivalence in the FIRRTL spec. If the types being
211 /// compared have any outer flips that encode FIRRTL module directions (input or
212 /// output), these should be stripped before using this method.
213 bool areTypesEquivalent(FIRRTLType destType, FIRRTLType srcType,
214  bool destOuterTypeIsConst = false,
215  bool srcOuterTypeIsConst = false,
216  bool requireSameWidths = false);
217 
218 /// Returns true if two types are weakly equivalent. See the FIRRTL spec,
219 /// Section 4.6, for a full definition of this. Roughly, the oriented types
220 /// (the types with any flips pushed to the leaves) must match. This allows for
221 /// types with flips in different positions to be equivalent.
222 bool areTypesWeaklyEquivalent(FIRRTLType destType, FIRRTLType srcType,
223  bool destFlip = false, bool srcFlip = false,
224  bool destOuterTypeIsConst = false,
225  bool srcOuterTypeIsConst = false);
226 
227 /// Returns whether the srcType can be const-casted to the destType.
228 bool areTypesConstCastable(FIRRTLType destType, FIRRTLType srcType,
229  bool srcOuterTypeIsConst = false);
230 
231 /// Return true if destination ref type can be cast from source ref type,
232 /// per FIRRTL spec rules they must be identical or destination has
233 /// more general versions of the corresponding type in the source.
234 bool areTypesRefCastable(Type dstType, Type srcType);
235 
236 /// Returns true if the destination is at least as wide as a source. The source
237 /// and destination types must be equivalent non-analog types. The types are
238 /// recursively connected to ensure that the destination is larger than the
239 /// source: ground types are compared on width, vector types are checked
240 /// recursively based on their elements and bundles are compared
241 /// field-by-field. Types with unresolved widths are assumed to fit into or
242 /// hold their counterparts.
243 bool isTypeLarger(FIRRTLBaseType dstType, FIRRTLBaseType srcType);
244 
245 /// Return true if anonymous types of given arguments are equivalent by pointer
246 /// comparison.
247 bool areAnonymousTypesEquivalent(FIRRTLBaseType lhs, FIRRTLBaseType rhs);
248 bool areAnonymousTypesEquivalent(mlir::Type lhs, mlir::Type rhs);
249 
250 mlir::Type getPassiveType(mlir::Type anyBaseFIRRTLType);
251 
252 /// Returns true if the given type has some flipped (aka unaligned) dataflow.
253 /// This will be true if the port contains either bi-directional signals or
254 /// analog types. Non-HW types (e.g., ref types) are never considered InOut.
255 bool isTypeInOut(mlir::Type type);
256 
257 //===----------------------------------------------------------------------===//
258 // Width Qualified Ground Types
259 //===----------------------------------------------------------------------===//
260 
261 /// Trait for types which have a width.
262 /// Users must implement:
263 /// ```c++
264 /// /// Return the width if known, or -1 if unknown.
265 /// int32_t getWidthOrSentinel();
266 /// ```
267 template <typename ConcreteType>
269  : public mlir::TypeTrait::TraitBase<ConcreteType, WidthQualifiedTypeTrait> {
270 public:
271  /// Return an optional containing the width, if the width is known (or empty
272  /// if width is unknown).
273  std::optional<int32_t> getWidth() const {
274  auto width = static_cast<const ConcreteType *>(this)->getWidthOrSentinel();
275  if (width < 0)
276  return std::nullopt;
277  return width;
278  }
279 
280  /// Return true if this integer type has a known width.
281  bool hasWidth() const {
282  return 0 <= static_cast<const ConcreteType *>(this)->getWidthOrSentinel();
283  }
284 };
285 
286 //===----------------------------------------------------------------------===//
287 // IntType
288 //===----------------------------------------------------------------------===//
289 
290 class SIntType;
291 class UIntType;
292 
293 /// This is the common base class between SIntType and UIntType.
294 class IntType : public FIRRTLBaseType, public WidthQualifiedTypeTrait<IntType> {
295 public:
296  using FIRRTLBaseType::FIRRTLBaseType;
297 
298  /// Return an SIntType or UIntType with the specified signedness, width, and
299  /// constness.
300  static IntType get(MLIRContext *context, bool isSigned,
301  int32_t widthOrSentinel = -1, bool isConst = false);
302 
303  bool isSigned() { return isa<SIntType>(); }
304  bool isUnsigned() { return isa<UIntType>(); }
305 
306  /// Return the width of this type, or -1 if it has none specified.
307  int32_t getWidthOrSentinel() const;
308 
309  /// Return a 'const' or non-'const' version of this type.
311 
312  static bool classof(Type type) { return llvm::isa<SIntType, UIntType>(type); }
313 };
314 
315 //===----------------------------------------------------------------------===//
316 // PropertyTypes
317 //===----------------------------------------------------------------------===//
318 
319 class PropertyType : public FIRRTLType {
320 public:
321  /// Support method to enable LLVM-style type casting.
322  static bool classof(Type type) {
323  return llvm::isa<AnyRefType, ClassType, StringType, FIntegerType, ListType,
324  PathType, BoolType, DoubleType>(type);
325  }
326 
327 protected:
328  using FIRRTLType::FIRRTLType;
329 };
330 
331 //===----------------------------------------------------------------------===//
332 // ClassElement
333 //===----------------------------------------------------------------------===//
334 
335 struct ClassElement {
338 
339  StringAttr name;
340  Type type;
342 
343  StringRef getName() const { return name.getValue(); }
344 
345  /// Return true if this is a simple output-only element. If you want the
346  /// direction of the port, use the \p direction field directly.
347  bool isInput() const { return direction == Direction::In && !isInOut(); }
348 
349  /// Return true if this is a simple input-only element. If you want the
350  /// direction of the port, use the \p direction field directly.
351  bool isOutput() const { return direction == Direction::Out && !isInOut(); }
352 
353  /// Return true if this is an inout port. This will be true if the port
354  /// contains either bi-directional signals or analog types.
355  /// Non-HW types (e.g., ref types) are never considered InOut.
356  bool isInOut() const { return isTypeInOut(type); }
357 
358  bool operator==(const ClassElement &rhs) const {
359  return name == rhs.name && type == rhs.type;
360  }
361 
362  bool operator!=(const ClassElement &rhs) const { return !(*this == rhs); }
363 };
364 
365 // NOLINTNEXTLINE(readability-identifier-naming)
366 inline llvm::hash_code hash_value(const ClassElement &element) {
367  return llvm::hash_combine(element.name, element.type, element.direction);
368 }
369 
370 //===----------------------------------------------------------------------===//
371 // Type helpers
372 //===----------------------------------------------------------------------===//
373 
374 // Get the bit width for this type, return None if unknown. Unlike
375 // getBitWidthOrSentinel(), this can recursively compute the bitwidth of
376 // aggregate types. For bundle and vectors, recursively get the width of each
377 // field element and return the total bit width of the aggregate type. This
378 // returns None, if any of the bundle fields is a flip type, or ground type with
379 // unknown bit width.
380 std::optional<int64_t> getBitWidth(FIRRTLBaseType type,
381  bool ignoreFlip = false);
382 
383 // Parse a FIRRTL type without a leading `!firrtl.` dialect tag.
384 ParseResult parseNestedType(FIRRTLType &result, AsmParser &parser);
385 ParseResult parseNestedBaseType(FIRRTLBaseType &result, AsmParser &parser);
386 ParseResult parseNestedPropertyType(PropertyType &result, AsmParser &parser);
387 
388 // Print a FIRRTL type without a leading `!firrtl.` dialect tag.
389 void printNestedType(Type type, AsmPrinter &os);
390 
391 using FIRRTLValue = mlir::TypedValue<FIRRTLType>;
392 using FIRRTLBaseValue = mlir::TypedValue<FIRRTLBaseType>;
393 using FIRRTLPropertyValue = mlir::TypedValue<PropertyType>;
394 
395 } // namespace firrtl
396 } // namespace circt
397 
398 // Include generated types.
399 #define GET_TYPEDEF_CLASSES
400 #include "circt/Dialect/FIRRTL/FIRRTLTypes.h.inc"
401 
402 namespace llvm {
403 
404 // Type hash just like pointers.
405 template <>
406 struct DenseMapInfo<circt::firrtl::FIRRTLType> {
409  auto pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
410  return FIRRTLType(static_cast<mlir::Type::ImplType *>(pointer));
411  }
413  auto pointer = llvm::DenseMapInfo<void *>::getTombstoneKey();
414  return FIRRTLType(static_cast<mlir::Type::ImplType *>(pointer));
415  }
416  static unsigned getHashValue(FIRRTLType val) { return mlir::hash_value(val); }
417  static bool isEqual(FIRRTLType LHS, FIRRTLType RHS) { return LHS == RHS; }
418 };
419 
420 } // namespace llvm
421 
422 namespace circt {
423 namespace firrtl {
424 //===--------------------------------------------------------------------===//
425 // Utility for type aliases
426 //===--------------------------------------------------------------------===//
427 
428 /// A struct to check if there is a type derived from FIRRTLBaseType.
429 /// `ContainAliasableTypes<BaseTy>::value` returns true if `BaseTy` is derived
430 /// from `FIRRTLBaseType` and not `FIRRTLBaseType` itself, or is not FIRRTL type
431 /// to cover type interfaces.
432 template <typename head, typename... tail>
434 public:
435  static constexpr bool value = ContainAliasableTypes<head>::value ||
437 };
438 
439 template <typename BaseTy>
441  static constexpr bool isFIRRTLBaseType =
442  std::is_base_of<FIRRTLBaseType, BaseTy>::value &&
443  !std::is_same_v<FIRRTLBaseType, BaseTy>;
444  static constexpr bool isFIRRTLType =
445  std::is_base_of<FIRRTLType, BaseTy>::value;
446 
447 public:
448  static constexpr bool value = isFIRRTLBaseType || !isFIRRTLType;
449 };
450 
451 template <typename... BaseTy>
452 bool type_isa(Type type) { // NOLINT(readability-identifier-naming)
453  // First check if the type is the requested type.
454  if (isa<BaseTy...>(type))
455  return true;
456 
457  // If the requested type is a subtype of FIRRTLBaseType, then check if it is a
458  // type alias wrapping the requested type.
460  if (auto alias = dyn_cast<BaseTypeAliasType>(type))
461  return type_isa<BaseTy...>(alias.getInnerType());
462  }
463 
464  return false;
465 }
466 
467 // type_isa for a nullable argument.
468 template <typename... BaseTy>
469 bool type_isa_and_nonnull(Type type) { // NOLINT(readability-identifier-naming)
470  if (!type)
471  return false;
472  return type_isa<BaseTy...>(type);
473 }
474 
475 template <typename BaseTy>
476 BaseTy type_cast(Type type) { // NOLINT(readability-identifier-naming)
477  assert(type_isa<BaseTy>(type) && "type must convert to requested type");
478 
479  // If the type is the requested type, return it.
480  if (isa<BaseTy>(type))
481  return cast<BaseTy>(type);
482 
483  // Otherwise, it must be a type alias wrapping the requested type.
484  if constexpr (ContainAliasableTypes<BaseTy>::value) {
485  if (auto alias = dyn_cast<BaseTypeAliasType>(type))
486  return type_cast<BaseTy>(alias.getInnerType());
487  }
488 
489  // Otherwise, it should fail. `cast` should cause a better assertion failure,
490  // so just use it.
491  return cast<BaseTy>(type);
492 }
493 
494 template <typename BaseTy>
495 BaseTy type_dyn_cast(Type type) { // NOLINT(readability-identifier-naming)
496  if (type_isa<BaseTy>(type))
497  return type_cast<BaseTy>(type);
498  return {};
499 }
500 
501 template <typename BaseTy>
502 BaseTy
503 type_dyn_cast_or_null(Type type) { // NOLINT(readability-identifier-naming)
504  if (type_isa_and_nonnull<BaseTy>(type))
505  return type_cast<BaseTy>(type);
506  return {};
507 }
508 
509 //===--------------------------------------------------------------------===//
510 // Type alias aware TypeSwitch.
511 //===--------------------------------------------------------------------===//
512 
513 /// This class implements the same functionality as TypeSwitch except that
514 /// it uses firrtl::type_dyn_cast for dynamic cast. llvm::TypeSwitch is not
515 /// customizable so this class currently duplicates the code.
516 template <typename T, typename ResultT = void>
518  : public llvm::detail::TypeSwitchBase<FIRRTLTypeSwitch<T, ResultT>, T> {
519 public:
521  using BaseT::BaseT;
522  using BaseT::Case;
523  FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other) = default;
524 
525  /// Add a case on the given type.
526  template <typename CaseT, typename CallableT>
528  Case(CallableT &&caseFn) { // NOLINT(readability-identifier-naming)
529  if (result)
530  return *this;
531 
532  // Check to see if CaseT applies to 'value'. Use `type_dyn_cast` here.
533  if (auto caseValue = circt::firrtl::type_dyn_cast<CaseT>(this->value))
534  result.emplace(caseFn(caseValue));
535  return *this;
536  }
537 
538  /// As a default, invoke the given callable within the root value.
539  template <typename CallableT>
540  [[nodiscard]] ResultT
541  Default(CallableT &&defaultFn) { // NOLINT(readability-identifier-naming)
542  if (result)
543  return std::move(*result);
544  return defaultFn(this->value);
545  }
546 
547  /// As a default, return the given value.
548  [[nodiscard]] ResultT
549  Default(ResultT defaultResult) { // NOLINT(readability-identifier-naming)
550  if (result)
551  return std::move(*result);
552  return defaultResult;
553  }
554 
555  [[nodiscard]] operator ResultT() {
556  assert(result && "Fell off the end of a type-switch");
557  return std::move(*result);
558  }
559 
560 private:
561  /// The pointer to the result of this switch statement, once known,
562  /// null before that.
563  std::optional<ResultT> result;
564 };
565 
566 /// Specialization of FIRRTLTypeSwitch for void returning callables.
567 template <typename T>
568 class FIRRTLTypeSwitch<T, void>
569  : public llvm::detail::TypeSwitchBase<FIRRTLTypeSwitch<T, void>, T> {
570 public:
572  using BaseT::BaseT;
573  using BaseT::Case;
574  FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other) = default;
575 
576  /// Add a case on the given type.
577  template <typename CaseT, typename CallableT>
579  Case(CallableT &&caseFn) { // NOLINT(readability-identifier-naming)
580  if (foundMatch)
581  return *this;
582 
583  // Check to see if any of the types apply to 'value'.
584  if (auto caseValue = circt::firrtl::type_dyn_cast<CaseT>(this->value)) {
585  caseFn(caseValue);
586  foundMatch = true;
587  }
588  return *this;
589  }
590 
591  /// As a default, invoke the given callable within the root value.
592  template <typename CallableT>
593  void Default(CallableT &&defaultFn) { // NOLINT(readability-identifier-naming)
594  if (!foundMatch)
595  defaultFn(this->value);
596  }
597 
598 private:
599  /// A flag detailing if we have already found a match.
600  bool foundMatch = false;
601 };
602 
603 template <typename BaseTy>
605  : public ::mlir::Type::TypeBase<BaseTypeAliasOr<BaseTy>,
606  firrtl::FIRRTLBaseType,
607  detail::FIRRTLBaseTypeStorage> {
608 
609 public:
611  detail::FIRRTLBaseTypeStorage>::Base::Base;
612  // Support LLVM isa/cast/dyn_cast to BaseTy.
613  static bool classof(Type other) { return type_isa<BaseTy>(other); }
614 
615  // Support C++ implicit conversions to BaseTy.
616  operator BaseTy() const { return circt::firrtl::type_cast<BaseTy>(*this); }
617 
618  BaseTy base() const { return circt::firrtl::type_cast<BaseTy>(*this); }
619 };
620 
621 } // namespace firrtl
622 } // namespace circt
623 
624 #endif // CIRCT_DIALECT_FIRRTL_TYPES_H
assert(baseType &&"element must be base type")
int32_t width
Definition: FIRRTL.cpp:36
static bool classof(Type other)
Definition: FIRRTLTypes.h:613
A struct to check if there is a type derived from FIRRTLBaseType.
Definition: FIRRTLTypes.h:433
FIRRTLBaseType getAnonymousType()
Return this type with any type alias types recursively removed from itself.
static bool classof(Type type)
Support method to enable LLVM-style type casting.
Definition: FIRRTLTypes.h:183
bool isResetType()
Return true if this is a valid "reset" type.
bool isRegisterType()
Returns true if this is a non-const "passive" that which is not analog.
Definition: FIRRTLTypes.h:190
FIRRTLBaseType getMaskType()
Return this type with all ground types replaced with UInt<1>.
FIRRTLBaseType getPassiveType()
Return this type with any flip types recursively removed from itself.
int32_t getBitWidthOrSentinel()
If this is an IntType, AnalogType, or sugar type for a single bit (Clock, Reset, etc) then return the...
bool isConst()
Returns true if this is a 'const' type that can only hold compile-time constant values.
FIRRTLBaseType getAllConstDroppedType()
Return this type with a 'const' modifiers dropped.
bool isPassive() const
Return true if this is a "passive" type - one that contains no "flip" types recursively within itself...
Definition: FIRRTLTypes.h:152
FIRRTLBaseType getConstType(bool isConst)
Return a 'const' or non-'const' version of this type.
FIRRTLBaseType getWidthlessType()
Return this type with widths of all ground types removed.
Specialization of FIRRTLTypeSwitch for void returning callables.
Definition: FIRRTLTypes.h:569
FIRRTLTypeSwitch< T, void > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition: FIRRTLTypes.h:579
void Default(CallableT &&defaultFn)
As a default, invoke the given callable within the root value.
Definition: FIRRTLTypes.h:593
FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other)=default
This class implements the same functionality as TypeSwitch except that it uses firrtl::type_dyn_cast ...
Definition: FIRRTLTypes.h:518
ResultT Default(ResultT defaultResult)
As a default, return the given value.
Definition: FIRRTLTypes.h:549
FIRRTLTypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition: FIRRTLTypes.h:528
FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other)=default
ResultT Default(CallableT &&defaultFn)
As a default, invoke the given callable within the root value.
Definition: FIRRTLTypes.h:541
std::optional< ResultT > result
The pointer to the result of this switch statement, once known, null before that.
Definition: FIRRTLTypes.h:563
bool containsReference()
Return true if this is or contains a Reference type.
Definition: FIRRTLTypes.h:105
bool isGround()
Return true if this is a 'ground' type, aka a non-aggregate type.
static bool classof(Type type)
Support method to enable LLVM-style type casting.
Definition: FIRRTLTypes.h:86
bool isConst()
Returns true if this is a 'const' type that can only hold compile-time constant values.
bool hasUninferredWidth()
Return true if this type contains an uninferred bit width.
Definition: FIRRTLTypes.h:115
bool containsTypeAlias()
Return true if this is an anonymous type (no type alias).
Definition: FIRRTLTypes.h:110
RecursiveTypeProperties getRecursiveTypeProperties() const
Return the recursive properties of the type, containing the isPassive, containsAnalog,...
bool hasUninferredReset()
Return true if this type contains an uninferred bit reset.
Definition: FIRRTLTypes.h:120
bool containsAnalog()
Return true if this is or contains an Analog type.
Definition: FIRRTLTypes.h:102
bool containsConst()
Returns true if this is or contains a 'const' type.
Definition: FIRRTLTypes.h:99
This is the common base class between SIntType and UIntType.
Definition: FIRRTLTypes.h:294
static bool classof(Type type)
Definition: FIRRTLTypes.h:312
int32_t getWidthOrSentinel() const
Return the width of this type, or -1 if it has none specified.
static IntType get(MLIRContext *context, bool isSigned, int32_t widthOrSentinel=-1, bool isConst=false)
Return an SIntType or UIntType with the specified signedness, width, and constness.
IntType getConstType(bool isConst)
Return a 'const' or non-'const' version of this type.
static bool classof(Type type)
Support method to enable LLVM-style type casting.
Definition: FIRRTLTypes.h:322
Trait for types which have a width.
Definition: FIRRTLTypes.h:269
std::optional< int32_t > getWidth() const
Return an optional containing the width, if the width is known (or empty if width is unknown).
Definition: FIRRTLTypes.h:273
bool hasWidth() const
Return true if this integer type has a known width.
Definition: FIRRTLTypes.h:281
BaseTy type_cast(Type type)
Definition: FIRRTLTypes.h:476
Direction
This represents the direction of a single port.
mlir::TypedValue< FIRRTLBaseType > FIRRTLBaseValue
Definition: FIRRTLTypes.h:392
ParseResult parseNestedType(FIRRTLType &result, AsmParser &parser)
Parse a FIRRTLType.
bool areAnonymousTypesEquivalent(FIRRTLBaseType lhs, FIRRTLBaseType rhs)
Return true if anonymous types of given arguments are equivalent by pointer comparison.
bool type_isa_and_nonnull(Type type)
Definition: FIRRTLTypes.h:469
ParseResult parseNestedBaseType(FIRRTLBaseType &result, AsmParser &parser)
bool isTypeInOut(mlir::Type type)
Returns true if the given type has some flipped (aka unaligned) dataflow.
bool areTypesRefCastable(Type dstType, Type srcType)
Return true if destination ref type can be cast from source ref type, per FIRRTL spec rules they must...
bool areTypesEquivalent(FIRRTLType destType, FIRRTLType srcType, bool destOuterTypeIsConst=false, bool srcOuterTypeIsConst=false, bool requireSameWidths=false)
Returns whether the two types are equivalent.
bool areTypesWeaklyEquivalent(FIRRTLType destType, FIRRTLType srcType, bool destFlip=false, bool srcFlip=false, bool destOuterTypeIsConst=false, bool srcOuterTypeIsConst=false)
Returns true if two types are weakly equivalent.
mlir::Type getPassiveType(mlir::Type anyBaseFIRRTLType)
bool isTypeLarger(FIRRTLBaseType dstType, FIRRTLBaseType srcType)
Returns true if the destination is at least as wide as a source.
bool containsConst(Type type)
Returns true if the type is or contains a 'const' type whose value is guaranteed to be unchanging at ...
mlir::TypedValue< FIRRTLType > FIRRTLValue
Definition: FIRRTLTypes.h:391
bool hasZeroBitWidth(FIRRTLType type)
Return true if the type has zero bit width.
BaseTy type_dyn_cast(Type type)
Definition: FIRRTLTypes.h:495
void printNestedType(Type type, AsmPrinter &os)
Print a type defined by this dialect.
BaseTy type_dyn_cast_or_null(Type type)
Definition: FIRRTLTypes.h:503
mlir::TypedValue< PropertyType > FIRRTLPropertyValue
Definition: FIRRTLTypes.h:393
bool isConst(Type type)
Returns true if this is a 'const' type whose value is guaranteed to be unchanging at circuit executio...
llvm::hash_code hash_value(const ClassElement &element)
Definition: FIRRTLTypes.h:366
bool areTypesConstCastable(FIRRTLType destType, FIRRTLType srcType, bool srcOuterTypeIsConst=false)
Returns whether the srcType can be const-casted to the destType.
bool type_isa(Type type)
Definition: FIRRTLTypes.h:452
ParseResult parseNestedPropertyType(PropertyType &result, AsmParser &parser)
std::optional< int64_t > getBitWidth(FIRRTLBaseType type, bool ignoreFlip=false)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
llvm::hash_code hash_value(const T &e)
bool isInOut() const
Return true if this is an inout port.
Definition: FIRRTLTypes.h:356
ClassElement(StringAttr name, Type type, Direction direction)
Definition: FIRRTLTypes.h:336
bool isOutput() const
Return true if this is a simple input-only element.
Definition: FIRRTLTypes.h:351
bool isInput() const
Return true if this is a simple output-only element.
Definition: FIRRTLTypes.h:347
StringRef getName() const
Definition: FIRRTLTypes.h:343
bool operator!=(const ClassElement &rhs) const
Definition: FIRRTLTypes.h:362
bool operator==(const ClassElement &rhs) const
Definition: FIRRTLTypes.h:358
A collection of bits indicating the recursive properties of a type.
Definition: FIRRTLTypes.h:65
bool containsReference
Whether the type contains a reference type.
Definition: FIRRTLTypes.h:69
bool isPassive
Whether the type only contains passive elements.
Definition: FIRRTLTypes.h:67
bool containsAnalog
Whether the type contains an analog type.
Definition: FIRRTLTypes.h:71
bool hasUninferredReset
Whether the type has any uninferred reset.
Definition: FIRRTLTypes.h:79
bool containsTypeAlias
Whether the type contains a type alias.
Definition: FIRRTLTypes.h:75
bool containsConst
Whether the type contains a const type.
Definition: FIRRTLTypes.h:73
bool hasUninferredWidth
Whether the type has any uninferred bit widths.
Definition: FIRRTLTypes.h:77
static unsigned getHashValue(FIRRTLType val)
Definition: FIRRTLTypes.h:416
static bool isEqual(FIRRTLType LHS, FIRRTLType RHS)
Definition: FIRRTLTypes.h:417