CIRCT  18.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 /// Returns whether the two types are equivalent. This implements the exact
207 /// definition of type equivalence in the FIRRTL spec. If the types being
208 /// compared have any outer flips that encode FIRRTL module directions (input or
209 /// output), these should be stripped before using this method.
210 bool areTypesEquivalent(FIRRTLType destType, FIRRTLType srcType,
211  bool destOuterTypeIsConst = false,
212  bool srcOuterTypeIsConst = false,
213  bool requireSameWidths = false);
214 
215 /// Returns true if two types are weakly equivalent. See the FIRRTL spec,
216 /// Section 4.6, for a full definition of this. Roughly, the oriented types
217 /// (the types with any flips pushed to the leaves) must match. This allows for
218 /// types with flips in different positions to be equivalent.
219 bool areTypesWeaklyEquivalent(FIRRTLType destType, FIRRTLType srcType,
220  bool destFlip = false, bool srcFlip = false,
221  bool destOuterTypeIsConst = false,
222  bool srcOuterTypeIsConst = false);
223 
224 /// Returns whether the srcType can be const-casted to the destType.
225 bool areTypesConstCastable(FIRRTLType destType, FIRRTLType srcType,
226  bool srcOuterTypeIsConst = false);
227 
228 /// Return true if destination ref type can be cast from source ref type,
229 /// per FIRRTL spec rules they must be identical or destination has
230 /// more general versions of the corresponding type in the source.
231 bool areTypesRefCastable(Type dstType, Type srcType);
232 
233 /// Returns true if the destination is at least as wide as a source. The source
234 /// and destination types must be equivalent non-analog types. The types are
235 /// recursively connected to ensure that the destination is larger than the
236 /// source: ground types are compared on width, vector types are checked
237 /// recursively based on their elements and bundles are compared
238 /// field-by-field. Types with unresolved widths are assumed to fit into or
239 /// hold their counterparts.
240 bool isTypeLarger(FIRRTLBaseType dstType, FIRRTLBaseType srcType);
241 
242 /// Return true if anonymous types of given arguments are equivalent by pointer
243 /// comparison.
244 bool areAnonymousTypesEquivalent(FIRRTLBaseType lhs, FIRRTLBaseType rhs);
245 bool areAnonymousTypesEquivalent(mlir::Type lhs, mlir::Type rhs);
246 
247 mlir::Type getPassiveType(mlir::Type anyBaseFIRRTLType);
248 
249 /// Returns true if the given type has some flipped (aka unaligned) dataflow.
250 /// This will be true if the port contains either bi-directional signals or
251 /// analog types. Non-HW types (e.g., ref types) are never considered InOut.
252 bool isTypeInOut(mlir::Type type);
253 
254 //===----------------------------------------------------------------------===//
255 // Width Qualified Ground Types
256 //===----------------------------------------------------------------------===//
257 
258 /// Trait for types which have a width.
259 /// Users must implement:
260 /// ```c++
261 /// /// Return the width if known, or -1 if unknown.
262 /// int32_t getWidthOrSentinel();
263 /// ```
264 template <typename ConcreteType>
266  : public mlir::TypeTrait::TraitBase<ConcreteType, WidthQualifiedTypeTrait> {
267 public:
268  /// Return an optional containing the width, if the width is known (or empty
269  /// if width is unknown).
270  std::optional<int32_t> getWidth() const {
271  auto width = static_cast<const ConcreteType *>(this)->getWidthOrSentinel();
272  if (width < 0)
273  return std::nullopt;
274  return width;
275  }
276 
277  /// Return true if this integer type has a known width.
278  bool hasWidth() const {
279  return 0 <= static_cast<const ConcreteType *>(this)->getWidthOrSentinel();
280  }
281 };
282 
283 //===----------------------------------------------------------------------===//
284 // IntType
285 //===----------------------------------------------------------------------===//
286 
287 class SIntType;
288 class UIntType;
289 
290 /// This is the common base class between SIntType and UIntType.
291 class IntType : public FIRRTLBaseType, public WidthQualifiedTypeTrait<IntType> {
292 public:
293  using FIRRTLBaseType::FIRRTLBaseType;
294 
295  /// Return an SIntType or UIntType with the specified signedness, width, and
296  /// constness.
297  static IntType get(MLIRContext *context, bool isSigned,
298  int32_t widthOrSentinel = -1, bool isConst = false);
299 
300  bool isSigned() { return isa<SIntType>(); }
301  bool isUnsigned() { return isa<UIntType>(); }
302 
303  /// Return the width of this type, or -1 if it has none specified.
304  int32_t getWidthOrSentinel() const;
305 
306  /// Return a 'const' or non-'const' version of this type.
308 
309  static bool classof(Type type) { return llvm::isa<SIntType, UIntType>(type); }
310 };
311 
312 //===----------------------------------------------------------------------===//
313 // PropertyTypes
314 //===----------------------------------------------------------------------===//
315 
316 class PropertyType : public FIRRTLType {
317 public:
318  /// Support method to enable LLVM-style type casting.
319  static bool classof(Type type) {
320  return llvm::isa<AnyRefType, ClassType, StringType, FIntegerType, ListType,
321  PathType, BoolType, DoubleType>(type);
322  }
323 
324 protected:
325  using FIRRTLType::FIRRTLType;
326 };
327 
328 //===----------------------------------------------------------------------===//
329 // ClassElement
330 //===----------------------------------------------------------------------===//
331 
332 struct ClassElement {
335 
336  StringAttr name;
337  Type type;
339 
340  StringRef getName() const { return name.getValue(); }
341 
342  /// Return true if this is a simple output-only element. If you want the
343  /// direction of the port, use the \p direction field directly.
344  bool isInput() const { return direction == Direction::In && !isInOut(); }
345 
346  /// Return true if this is a simple input-only element. If you want the
347  /// direction of the port, use the \p direction field directly.
348  bool isOutput() const { return direction == Direction::Out && !isInOut(); }
349 
350  /// Return true if this is an inout port. This will be true if the port
351  /// contains either bi-directional signals or analog types.
352  /// Non-HW types (e.g., ref types) are never considered InOut.
353  bool isInOut() const { return isTypeInOut(type); }
354 
355  bool operator==(const ClassElement &rhs) const {
356  return name == rhs.name && type == rhs.type;
357  }
358 
359  bool operator!=(const ClassElement &rhs) const { return !(*this == rhs); }
360 };
361 
362 // NOLINTNEXTLINE(readability-identifier-naming)
363 inline llvm::hash_code hash_value(const ClassElement &element) {
364  return llvm::hash_combine(element.name, element.type, element.direction);
365 }
366 
367 //===----------------------------------------------------------------------===//
368 // Type helpers
369 //===----------------------------------------------------------------------===//
370 
371 // Get the bit width for this type, return None if unknown. Unlike
372 // getBitWidthOrSentinel(), this can recursively compute the bitwidth of
373 // aggregate types. For bundle and vectors, recursively get the width of each
374 // field element and return the total bit width of the aggregate type. This
375 // returns None, if any of the bundle fields is a flip type, or ground type with
376 // unknown bit width.
377 std::optional<int64_t> getBitWidth(FIRRTLBaseType type,
378  bool ignoreFlip = false);
379 
380 // Parse a FIRRTL type without a leading `!firrtl.` dialect tag.
381 ParseResult parseNestedType(FIRRTLType &result, AsmParser &parser);
382 ParseResult parseNestedBaseType(FIRRTLBaseType &result, AsmParser &parser);
383 ParseResult parseNestedPropertyType(PropertyType &result, AsmParser &parser);
384 
385 // Print a FIRRTL type without a leading `!firrtl.` dialect tag.
386 void printNestedType(Type type, AsmPrinter &os);
387 
388 using FIRRTLValue = mlir::TypedValue<FIRRTLType>;
389 using FIRRTLBaseValue = mlir::TypedValue<FIRRTLBaseType>;
390 using FIRRTLPropertyValue = mlir::TypedValue<PropertyType>;
391 
392 } // namespace firrtl
393 } // namespace circt
394 
395 // Include generated types.
396 #define GET_TYPEDEF_CLASSES
397 #include "circt/Dialect/FIRRTL/FIRRTLTypes.h.inc"
398 
399 namespace llvm {
400 
401 // Type hash just like pointers.
402 template <>
403 struct DenseMapInfo<circt::firrtl::FIRRTLType> {
406  auto pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
407  return FIRRTLType(static_cast<mlir::Type::ImplType *>(pointer));
408  }
410  auto pointer = llvm::DenseMapInfo<void *>::getTombstoneKey();
411  return FIRRTLType(static_cast<mlir::Type::ImplType *>(pointer));
412  }
413  static unsigned getHashValue(FIRRTLType val) { return mlir::hash_value(val); }
414  static bool isEqual(FIRRTLType LHS, FIRRTLType RHS) { return LHS == RHS; }
415 };
416 
417 } // namespace llvm
418 
419 namespace circt {
420 namespace firrtl {
421 //===--------------------------------------------------------------------===//
422 // Utility for type aliases
423 //===--------------------------------------------------------------------===//
424 
425 /// A struct to check if there is a type derived from FIRRTLBaseType.
426 /// `ContainAliasableTypes<BaseTy>::value` returns true if `BaseTy` is derived
427 /// from `FIRRTLBaseType` and not `FIRRTLBaseType` itself, or is not FIRRTL type
428 /// to cover type interfaces.
429 template <typename head, typename... tail>
431 public:
432  static constexpr bool value = ContainAliasableTypes<head>::value ||
434 };
435 
436 template <typename BaseTy>
438  static constexpr bool isFIRRTLBaseType =
440  !std::is_same_v<FIRRTLBaseType, BaseTy>;
441  static constexpr bool isFIRRTLType =
443 
444 public:
445  static constexpr bool value = isFIRRTLBaseType || !isFIRRTLType;
446 };
447 
448 template <typename... BaseTy>
449 bool type_isa(Type type) { // NOLINT(readability-identifier-naming)
450  // First check if the type is the requested type.
451  if (isa<BaseTy...>(type))
452  return true;
453 
454  // If the requested type is a subtype of FIRRTLBaseType, then check if it is a
455  // type alias wrapping the requested type.
457  if (auto alias = dyn_cast<BaseTypeAliasType>(type))
458  return type_isa<BaseTy...>(alias.getInnerType());
459  }
460 
461  return false;
462 }
463 
464 // type_isa for a nullable argument.
465 template <typename... BaseTy>
466 bool type_isa_and_nonnull(Type type) { // NOLINT(readability-identifier-naming)
467  if (!type)
468  return false;
469  return type_isa<BaseTy...>(type);
470 }
471 
472 template <typename BaseTy>
473 BaseTy type_cast(Type type) { // NOLINT(readability-identifier-naming)
474  assert(type_isa<BaseTy>(type) && "type must convert to requested type");
475 
476  // If the type is the requested type, return it.
477  if (isa<BaseTy>(type))
478  return cast<BaseTy>(type);
479 
480  // Otherwise, it must be a type alias wrapping the requested type.
481  if constexpr (ContainAliasableTypes<BaseTy>::value) {
482  if (auto alias = dyn_cast<BaseTypeAliasType>(type))
483  return type_cast<BaseTy>(alias.getInnerType());
484  }
485 
486  // Otherwise, it should fail. `cast` should cause a better assertion failure,
487  // so just use it.
488  return cast<BaseTy>(type);
489 }
490 
491 template <typename BaseTy>
492 BaseTy type_dyn_cast(Type type) { // NOLINT(readability-identifier-naming)
493  if (type_isa<BaseTy>(type))
494  return type_cast<BaseTy>(type);
495  return {};
496 }
497 
498 template <typename BaseTy>
499 BaseTy
500 type_dyn_cast_or_null(Type type) { // NOLINT(readability-identifier-naming)
501  if (type_isa_and_nonnull<BaseTy>(type))
502  return type_cast<BaseTy>(type);
503  return {};
504 }
505 
506 //===--------------------------------------------------------------------===//
507 // Type alias aware TypeSwitch.
508 //===--------------------------------------------------------------------===//
509 
510 /// This class implements the same functionality as TypeSwitch except that
511 /// it uses firrtl::type_dyn_cast for dynamic cast. llvm::TypeSwitch is not
512 /// customizable so this class currently duplicates the code.
513 template <typename T, typename ResultT = void>
515  : public llvm::detail::TypeSwitchBase<FIRRTLTypeSwitch<T, ResultT>, T> {
516 public:
518  using BaseT::BaseT;
519  using BaseT::Case;
520  FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other) = default;
521 
522  /// Add a case on the given type.
523  template <typename CaseT, typename CallableT>
525  Case(CallableT &&caseFn) { // NOLINT(readability-identifier-naming)
526  if (result)
527  return *this;
528 
529  // Check to see if CaseT applies to 'value'. Use `type_dyn_cast` here.
530  if (auto caseValue = circt::firrtl::type_dyn_cast<CaseT>(this->value))
531  result.emplace(caseFn(caseValue));
532  return *this;
533  }
534 
535  /// As a default, invoke the given callable within the root value.
536  template <typename CallableT>
537  [[nodiscard]] ResultT
538  Default(CallableT &&defaultFn) { // NOLINT(readability-identifier-naming)
539  if (result)
540  return std::move(*result);
541  return defaultFn(this->value);
542  }
543 
544  /// As a default, return the given value.
545  [[nodiscard]] ResultT
546  Default(ResultT defaultResult) { // NOLINT(readability-identifier-naming)
547  if (result)
548  return std::move(*result);
549  return defaultResult;
550  }
551 
552  [[nodiscard]] operator ResultT() {
553  assert(result && "Fell off the end of a type-switch");
554  return std::move(*result);
555  }
556 
557 private:
558  /// The pointer to the result of this switch statement, once known,
559  /// null before that.
560  std::optional<ResultT> result;
561 };
562 
563 /// Specialization of FIRRTLTypeSwitch for void returning callables.
564 template <typename T>
565 class FIRRTLTypeSwitch<T, void>
566  : public llvm::detail::TypeSwitchBase<FIRRTLTypeSwitch<T, void>, T> {
567 public:
569  using BaseT::BaseT;
570  using BaseT::Case;
571  FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other) = default;
572 
573  /// Add a case on the given type.
574  template <typename CaseT, typename CallableT>
576  Case(CallableT &&caseFn) { // NOLINT(readability-identifier-naming)
577  if (foundMatch)
578  return *this;
579 
580  // Check to see if any of the types apply to 'value'.
581  if (auto caseValue = circt::firrtl::type_dyn_cast<CaseT>(this->value)) {
582  caseFn(caseValue);
583  foundMatch = true;
584  }
585  return *this;
586  }
587 
588  /// As a default, invoke the given callable within the root value.
589  template <typename CallableT>
590  void Default(CallableT &&defaultFn) { // NOLINT(readability-identifier-naming)
591  if (!foundMatch)
592  defaultFn(this->value);
593  }
594 
595 private:
596  /// A flag detailing if we have already found a match.
597  bool foundMatch = false;
598 };
599 
600 template <typename BaseTy>
602  : public ::mlir::Type::TypeBase<BaseTypeAliasOr<BaseTy>,
603  firrtl::FIRRTLBaseType,
604  detail::FIRRTLBaseTypeStorage> {
605 
606 public:
608  detail::FIRRTLBaseTypeStorage>::Base::Base;
609  // Support LLVM isa/cast/dyn_cast to BaseTy.
610  static bool classof(Type other) { return type_isa<BaseTy>(other); }
611 
612  // Support C++ implicit conversions to BaseTy.
613  operator BaseTy() const { return circt::firrtl::type_cast<BaseTy>(*this); }
614 
615  BaseTy get() const { return circt::firrtl::type_cast<BaseTy>(*this); }
616 };
617 
618 } // namespace firrtl
619 } // namespace circt
620 
621 #endif // CIRCT_DIALECT_FIRRTL_TYPES_H
lowerAnnotationsNoRefTypePorts FirtoolPreserveValuesMode value
Definition: Firtool.cpp:95
assert(baseType &&"element must be base type")
int32_t width
Definition: FIRRTL.cpp:27
static bool classof(Type other)
Definition: FIRRTLTypes.h:610
A struct to check if there is a type derived from FIRRTLBaseType.
Definition: FIRRTLTypes.h:430
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:566
FIRRTLTypeSwitch< T, void > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition: FIRRTLTypes.h:576
void Default(CallableT &&defaultFn)
As a default, invoke the given callable within the root value.
Definition: FIRRTLTypes.h:590
FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other)=default
This class implements the same functionality as TypeSwitch except that it uses firrtl::type_dyn_cast ...
Definition: FIRRTLTypes.h:515
ResultT Default(ResultT defaultResult)
As a default, return the given value.
Definition: FIRRTLTypes.h:546
FIRRTLTypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition: FIRRTLTypes.h:525
FIRRTLTypeSwitch(FIRRTLTypeSwitch &&other)=default
ResultT Default(CallableT &&defaultFn)
As a default, invoke the given callable within the root value.
Definition: FIRRTLTypes.h:538
std::optional< ResultT > result
The pointer to the result of this switch statement, once known, null before that.
Definition: FIRRTLTypes.h:560
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:291
static bool classof(Type type)
Definition: FIRRTLTypes.h:309
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:319
Trait for types which have a width.
Definition: FIRRTLTypes.h:266
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:270
bool hasWidth() const
Return true if this integer type has a known width.
Definition: FIRRTLTypes.h:278
BaseTy type_cast(Type type)
Definition: FIRRTLTypes.h:473
Direction
This represents the direction of a single port.
mlir::TypedValue< FIRRTLBaseType > FIRRTLBaseValue
Definition: FIRRTLTypes.h:389
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:466
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:388
BaseTy type_dyn_cast(Type type)
Definition: FIRRTLTypes.h:492
void printNestedType(Type type, AsmPrinter &os)
Print a type defined by this dialect.
BaseTy type_dyn_cast_or_null(Type type)
Definition: FIRRTLTypes.h:500
mlir::TypedValue< PropertyType > FIRRTLPropertyValue
Definition: FIRRTLTypes.h:390
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:363
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:449
ParseResult parseNestedPropertyType(PropertyType &result, AsmParser &parser)
std::optional< int64_t > getBitWidth(FIRRTLBaseType type, bool ignoreFlip=false)
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
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:353
ClassElement(StringAttr name, Type type, Direction direction)
Definition: FIRRTLTypes.h:333
bool isOutput() const
Return true if this is a simple input-only element.
Definition: FIRRTLTypes.h:348
bool isInput() const
Return true if this is a simple output-only element.
Definition: FIRRTLTypes.h:344
StringRef getName() const
Definition: FIRRTLTypes.h:340
bool operator!=(const ClassElement &rhs) const
Definition: FIRRTLTypes.h:359
bool operator==(const ClassElement &rhs) const
Definition: FIRRTLTypes.h:355
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:413
static bool isEqual(FIRRTLType LHS, FIRRTLType RHS)
Definition: FIRRTLTypes.h:414