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