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