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