CIRCT 20.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;
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.
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.
85class FIRRTLType : public Type {
86public:
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.
110
111 /// Return true if this is an anonymous type (no type alias).
115
116 /// Return true if this type contains an uninferred bit width.
120
121 /// Return true if this type contains an uninferred bit reset.
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
137protected:
138 using Type::Type;
139};
140
141// Common base class for all base FIRRTL types.
143 : public FIRRTLType::TypeBase<FIRRTLBaseType, FIRRTLType,
144 detail::FIRRTLBaseTypeStorage> {
145public:
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.
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
202bool 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
206bool containsConst(Type type);
207
208/// Return true if the type has zero bit width.
209bool 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.
215bool 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.
230bool 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.
236bool 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.
245bool isTypeLarger(FIRRTLBaseType dstType, FIRRTLBaseType srcType);
246
247/// Return true if anonymous types of given arguments are equivalent by pointer
248/// comparison.
250bool areAnonymousTypesEquivalent(mlir::Type lhs, mlir::Type rhs);
251
252mlir::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.
257bool 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/// ```
269template <typename ConcreteType>
271 : public mlir::TypeTrait::TraitBase<ConcreteType, WidthQualifiedTypeTrait> {
272public:
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
292class SIntType;
293class UIntType;
294
295/// This is the common base class between SIntType and UIntType.
296class IntType : public FIRRTLBaseType, public WidthQualifiedTypeTrait<IntType> {
297public:
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
321class PropertyType : public FIRRTLType {
322public:
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
329protected:
330 using FIRRTLType::FIRRTLType;
331};
332
333//===----------------------------------------------------------------------===//
334// ClassElement
335//===----------------------------------------------------------------------===//
336
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)
368inline 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.
382std::optional<int64_t> getBitWidth(FIRRTLBaseType type,
383 bool ignoreFlip = false);
384
385// Parse a FIRRTL type without a leading `!firrtl.` dialect tag.
386ParseResult parseNestedType(FIRRTLType &result, AsmParser &parser);
387ParseResult parseNestedBaseType(FIRRTLBaseType &result, AsmParser &parser);
388ParseResult parseNestedPropertyType(PropertyType &result, AsmParser &parser);
389
390// Print a FIRRTL type without a leading `!firrtl.` dialect tag.
391void printNestedType(Type type, AsmPrinter &os);
392
393using FIRRTLValue = mlir::TypedValue<FIRRTLType>;
394using FIRRTLBaseValue = mlir::TypedValue<FIRRTLBaseType>;
395using 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
404namespace llvm {
405
406// Type hash just like pointers.
407template <>
408struct DenseMapInfo<circt::firrtl::FIRRTLType> {
412 return FIRRTLType(static_cast<mlir::Type::ImplType *>(pointer));
413 }
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
424namespace circt {
425namespace 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.
434template <typename head, typename... tail>
436public:
437 static constexpr bool value = ContainAliasableTypes<head>::value ||
439};
440
441template <typename 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
449public:
450 static constexpr bool value = isFIRRTLBaseType || !isFIRRTLType;
451};
452
453template <typename... BaseTy>
454bool 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.
461 if constexpr (ContainAliasableTypes<BaseTy...>::value) {
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.
470template <typename... BaseTy>
471bool type_isa_and_nonnull(Type type) { // NOLINT(readability-identifier-naming)
472 if (!type)
473 return false;
474 return type_isa<BaseTy...>(type);
475}
476
477template <typename BaseTy>
478BaseTy 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.
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
496template <typename BaseTy>
497BaseTy 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
503template <typename BaseTy>
504BaseTy
505type_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.
518template <typename T, typename ResultT = void>
520 : public llvm::detail::TypeSwitchBase<FIRRTLTypeSwitch<T, ResultT>, T> {
521public:
523 using BaseT::BaseT;
524 using BaseT::Case;
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
562private:
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.
569template <typename T>
570class FIRRTLTypeSwitch<T, void>
571 : public llvm::detail::TypeSwitchBase<FIRRTLTypeSwitch<T, void>, T> {
572public:
574 using BaseT::BaseT;
575 using BaseT::Case;
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
600private:
601 /// A flag detailing if we have already found a match.
602 bool foundMatch = false;
603};
604
605template <typename BaseTy>
607 : public ::mlir::Type::TypeBase<BaseTypeAliasOr<BaseTy>,
608 firrtl::FIRRTLBaseType,
609 detail::FIRRTLBaseTypeStorage> {
610
611public:
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")
static bool classof(Type other)
A struct to check if there is a type derived from FIRRTLBaseType.
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...
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...
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.
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: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.
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 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.
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.
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.
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: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)
static bool isEqual(FIRRTLType LHS, FIRRTLType RHS)