CIRCT 23.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;
40struct DomainTypeStorage;
41} // namespace detail.
42
43class AnyRefType;
44class ClassType;
45class ClockType;
46class ResetType;
47class AsyncResetType;
48class SIntType;
49class UIntType;
50class AnalogType;
51class BundleType;
52class OpenBundleType;
53class OpenVectorType;
54class FVectorType;
55class FEnumType;
56class RefType;
57class LHSType;
58class PropertyType;
59class StringType;
60class FIntegerType;
61class DomainFieldAttr;
62class ListType;
63class PathType;
64class BoolType;
65class DoubleType;
66class BaseTypeAliasType;
67class FStringType;
68class DomainType;
69class DomainOp;
70
71/// A collection of bits indicating the recursive properties of a type.
73 /// Whether the type only contains passive elements.
74 bool isPassive : 1;
75 /// Whether the type contains a reference type.
77 /// Whether the type contains an analog type.
79 /// Whether the type contains a const type.
80 bool containsConst : 1;
81 /// Whether the type contains a type alias.
83 /// Whether the type has any uninferred bit widths.
85 /// Whether the type has any uninferred reset.
87};
88
89// This is a common base class for all FIRRTL types.
90class FIRRTLType : public Type {
91public:
92 /// Support method to enable LLVM-style type casting.
93 static bool classof(Type type) {
94 return llvm::isa<FIRRTLDialect>(type.getDialect());
95 }
96
97 /// Return the recursive properties of the type, containing the `isPassive`,
98 /// `containsAnalog`, and `hasUninferredWidth` bits, among others.
100
101 //===--------------------------------------------------------------------===//
102 // Convenience methods for accessing recursive type properties
103 //===--------------------------------------------------------------------===//
104
105 /// Returns true if this is or contains a 'const' type.
107
108 /// Return true if this is or contains an Analog type.
110
111 /// Return true if this is or contains a Reference type.
115
116 /// Return true if this is an anonymous type (no type alias).
120
121 /// Return true if this type contains an uninferred bit width.
125
126 /// Return true if this type contains an uninferred bit reset.
130
131 //===--------------------------------------------------------------------===//
132 // Type classifications
133 //===--------------------------------------------------------------------===//
134
135 /// Return true if this is a 'ground' type, aka a non-aggregate type.
136 bool isGround();
137
138 /// Returns true if this is a 'const' type that can only hold compile-time
139 /// constant values
140 bool isConst() const;
141
142protected:
143 using Type::Type;
144};
145
146// Common base class for all base FIRRTL types.
148 : public FIRRTLType::TypeBase<FIRRTLBaseType, FIRRTLType,
149 detail::FIRRTLBaseTypeStorage> {
150public:
151 using Base::Base;
152
153 /// Returns true if this is a 'const' type that can only hold compile-time
154 /// constant values
155 bool isConst() const;
156
157 /// Return true if this is a "passive" type - one that contains no "flip"
158 /// types recursively within itself.
159 bool isPassive() const { return getRecursiveTypeProperties().isPassive; }
160
161 /// Return this type with any flip types recursively removed from itself.
163
164 /// Return this type with any type alias types recursively removed from
165 /// itself.
167
168 /// Return a 'const' or non-'const' version of this type.
170
171 /// Return this type with a 'const' modifiers dropped
173
174 /// Return this type with all ground types replaced with UInt<1>. This is
175 /// used for `mem` operations.
177
178 /// Return this type with widths of all ground types removed. This
179 /// enables two types to be compared by structure and name ignoring
180 /// widths.
182
183 /// If this is an IntType, AnalogType, or sugar type for a single bit (Clock,
184 /// Reset, etc) then return the bitwidth. Return -1 if the is one of these
185 /// types but without a specified bitwidth. Return -2 if this isn't a simple
186 /// type.
187 int32_t getBitWidthOrSentinel();
188
189 /// Support method to enable LLVM-style type casting.
190 static bool classof(Type type) {
191 return llvm::isa<FIRRTLDialect>(type.getDialect()) &&
192 !llvm::isa<PropertyType, RefType, LHSType, OpenBundleType,
193 OpenVectorType, FStringType, DomainType>(type);
194 }
195
196 /// Returns true if this is a non-const "passive" that which is not analog.
198 return isPassive() && !containsAnalog() && !containsConst();
199 }
200
201 /// Return true if this is a valid "reset" type.
202 bool isResetType();
203};
204
205/// Returns true if this is a 'const' type whose value is guaranteed to be
206/// unchanging at circuit execution time
207bool isConst(Type type);
208
209/// Returns true if the type is or contains a 'const' type whose value is
210/// guaranteed to be unchanging at circuit execution time
211bool containsConst(Type type);
212
213/// Return true if the type has zero bit width.
214bool hasZeroBitWidth(FIRRTLType type);
215
216/// Returns whether the two types are equivalent. This implements the exact
217/// definition of type equivalence in the FIRRTL spec. If the types being
218/// compared have any outer flips that encode FIRRTL module directions (input or
219/// output), these should be stripped before using this method.
220bool areTypesEquivalent(FIRRTLType destType, FIRRTLType srcType,
221 bool destOuterTypeIsConst = false,
222 bool srcOuterTypeIsConst = false,
223 bool requireSameWidths = false);
224
225/// Returns true if two types are weakly equivalent. See the FIRRTL spec,
226/// Section 4.6, for a full definition of this. Roughly, the oriented types
227/// (the types with any flips pushed to the leaves) must match. This allows for
228/// types with flips in different positions to be equivalent.
230 bool destFlip = false, bool srcFlip = false,
231 bool destOuterTypeIsConst = false,
232 bool srcOuterTypeIsConst = false);
233
234/// Returns whether the srcType can be const-casted to the destType.
235bool areTypesConstCastable(FIRRTLType destType, FIRRTLType srcType,
236 bool srcOuterTypeIsConst = false);
237
238/// Return true if destination ref type can be cast from source ref type,
239/// per FIRRTL spec rules they must be identical or destination has
240/// more general versions of the corresponding type in the source.
241bool areTypesRefCastable(Type dstType, Type srcType);
242
243/// Returns true if the destination is at least as wide as a source. The source
244/// and destination types must be equivalent non-analog types. The types are
245/// recursively connected to ensure that the destination is larger than the
246/// source: ground types are compared on width, vector types are checked
247/// recursively based on their elements and bundles are compared
248/// field-by-field. Types with unresolved widths are assumed to fit into or
249/// hold their counterparts.
250bool isTypeLarger(FIRRTLBaseType dstType, FIRRTLBaseType srcType);
251
252/// Return true if anonymous types of given arguments are equivalent by pointer
253/// comparison.
255bool areAnonymousTypesEquivalent(mlir::Type lhs, mlir::Type rhs);
256
257mlir::Type getPassiveType(mlir::Type anyBaseFIRRTLType);
258
259/// Returns true if the given type has some flipped (aka unaligned) dataflow.
260/// This will be true if the port contains either bi-directional signals or
261/// analog types. Non-HW types (e.g., ref types) are never considered InOut.
262bool isTypeInOut(mlir::Type type);
263
264/// Return true if the given type contains any elements of hardware types.
266
267//===----------------------------------------------------------------------===//
268// Width Qualified Ground Types
269//===----------------------------------------------------------------------===//
270
271/// Trait for types which have a width.
272/// Users must implement:
273/// ```c++
274/// /// Return the width if known, or -1 if unknown.
275/// int32_t getWidthOrSentinel();
276/// ```
277template <typename ConcreteType>
279 : public mlir::TypeTrait::TraitBase<ConcreteType, WidthQualifiedTypeTrait> {
280public:
281 /// Return an optional containing the width, if the width is known (or empty
282 /// if width is unknown).
283 std::optional<int32_t> getWidth() const {
284 auto width = static_cast<const ConcreteType *>(this)->getWidthOrSentinel();
285 if (width < 0)
286 return std::nullopt;
287 return width;
288 }
289
290 /// Return true if this integer type has a known width.
291 bool hasWidth() const {
292 return 0 <= static_cast<const ConcreteType *>(this)->getWidthOrSentinel();
293 }
294};
295
296//===----------------------------------------------------------------------===//
297// IntType
298//===----------------------------------------------------------------------===//
299
300class SIntType;
301class UIntType;
302
303/// This is the common base class between SIntType and UIntType.
304class IntType : public FIRRTLBaseType, public WidthQualifiedTypeTrait<IntType> {
305public:
306 using FIRRTLBaseType::FIRRTLBaseType;
307
308 /// Return an SIntType or UIntType with the specified signedness, width, and
309 /// constness.
310 static IntType get(MLIRContext *context, bool isSigned,
311 int32_t widthOrSentinel = -1, bool isConst = false);
312
313 bool isSigned() { return mlir::isa<SIntType>(*this); }
314 bool isUnsigned() { return mlir::isa<UIntType>(*this); }
315
316 /// Return the width of this type, or -1 if it has none specified.
317 int32_t getWidthOrSentinel() const;
318
319 /// Return a 'const' or non-'const' version of this type.
320 IntType getConstType(bool isConst) const;
321
322 static bool classof(Type type) { return mlir::isa<SIntType, UIntType>(type); }
323};
324
325//===----------------------------------------------------------------------===//
326// PropertyTypes
327//===----------------------------------------------------------------------===//
328
329class PropertyType : public FIRRTLType {
330public:
331 /// Support method to enable LLVM-style type casting.
332 static bool classof(Type type) {
333 return llvm::isa<AnyRefType, ClassType, StringType, FIntegerType, ListType,
334 PathType, BoolType, DoubleType>(type);
335 }
336
337protected:
338 using FIRRTLType::FIRRTLType;
339};
340
341//===----------------------------------------------------------------------===//
342// ClassElement
343//===----------------------------------------------------------------------===//
344
348
349 StringAttr name;
350 Type type;
352
353 StringRef getName() const { return name.getValue(); }
354
355 /// Return true if this is a simple output-only element. If you want the
356 /// direction of the port, use the \p direction field directly.
357 bool isInput() const { return direction == Direction::In && !isInOut(); }
358
359 /// Return true if this is a simple input-only element. If you want the
360 /// direction of the port, use the \p direction field directly.
361 bool isOutput() const { return direction == Direction::Out && !isInOut(); }
362
363 /// Return true if this is an inout port. This will be true if the port
364 /// contains either bi-directional signals or analog types.
365 /// Non-HW types (e.g., ref types) are never considered InOut.
366 bool isInOut() const { return isTypeInOut(type); }
367
368 bool operator==(const ClassElement &rhs) const {
369 return name == rhs.name && type == rhs.type;
370 }
371
372 bool operator!=(const ClassElement &rhs) const { return !(*this == rhs); }
373};
374
375// NOLINTNEXTLINE(readability-identifier-naming)
376inline llvm::hash_code hash_value(const ClassElement &element) {
377 return llvm::hash_combine(element.name, element.type, element.direction);
378}
379
380//===----------------------------------------------------------------------===//
381// Type helpers
382//===----------------------------------------------------------------------===//
383
384// Get the bit width for this type, return None if unknown. Unlike
385// getBitWidthOrSentinel(), this can recursively compute the bitwidth of
386// aggregate types. For bundle and vectors, recursively get the width of each
387// field element and return the total bit width of the aggregate type. This
388// returns None, if any of the bundle fields is a flip type, or ground type with
389// unknown bit width.
390std::optional<int64_t> getBitWidth(FIRRTLBaseType type,
391 bool ignoreFlip = false);
392
393// Parse a FIRRTL type without a leading `!firrtl.` dialect tag.
394ParseResult parseNestedType(FIRRTLType &result, AsmParser &parser);
395ParseResult parseNestedBaseType(FIRRTLBaseType &result, AsmParser &parser);
396ParseResult parseNestedPropertyType(PropertyType &result, AsmParser &parser);
397
398// Print a FIRRTL type without a leading `!firrtl.` dialect tag.
399void printNestedType(Type type, AsmPrinter &os);
400
401using FIRRTLValue = mlir::TypedValue<FIRRTLType>;
402using FIRRTLBaseValue = mlir::TypedValue<FIRRTLBaseType>;
403using FIRRTLPropertyValue = mlir::TypedValue<PropertyType>;
404
405} // namespace firrtl
406} // namespace circt
407
408// Include generated types.
409#define GET_TYPEDEF_CLASSES
410#include "circt/Dialect/FIRRTL/FIRRTLTypes.h.inc"
411
412namespace llvm {
413
414// Type hash just like pointers.
415template <>
416struct DenseMapInfo<circt::firrtl::FIRRTLType> {
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//===--------------------------------------------------------------------===//
627// Subelement Visitors
628//===--------------------------------------------------------------------===//
629
630/// Allow walking and replacing the subelements of a ClassElement.
631template <>
632struct mlir::AttrTypeSubElementHandler<circt::firrtl::ClassElement> {
634
635 static void walk(ClassElement param,
636 AttrTypeImmediateSubElementWalker &walker) {
637 walker.walk(param.name);
638 walker.walk(param.type);
639 }
641 AttrSubElementReplacements &attrRepls,
642 TypeSubElementReplacements &typeRepls) {
643 return ClassElement(cast<StringAttr>(attrRepls.take_front(1)[0]),
644 typeRepls.take_front(1)[0], param.direction);
645 }
646};
647
648/// Allow walking and replacing the subelements of a BundleElement.
649template <>
650struct mlir::AttrTypeSubElementHandler<
651 circt::firrtl::BundleType::BundleElement> {
652 using BundleElement = circt::firrtl::BundleType::BundleElement;
653
654 static void walk(const BundleElement &param,
655 AttrTypeImmediateSubElementWalker &walker) {
656 walker.walk(param.name);
657 walker.walk(param.type);
658 }
660 AttrSubElementReplacements &attrRepls,
661 TypeSubElementReplacements &typeRepls) {
662 return BundleElement(
663 cast<StringAttr>(attrRepls.take_front(1)[0]), param.isFlip,
664 cast<circt::firrtl::FIRRTLBaseType>(typeRepls.take_front(1)[0]));
665 }
666};
667
668/// Allow walking and replacing the subelements of an OpenBundleElement.
669template <>
670struct mlir::AttrTypeSubElementHandler<
671 circt::firrtl::OpenBundleType::BundleElement> {
672 using BundleElement = circt::firrtl::OpenBundleType::BundleElement;
673
674 static void walk(const BundleElement &param,
675 AttrTypeImmediateSubElementWalker &walker) {
676 walker.walk(param.name);
677 walker.walk(param.type);
678 }
680 AttrSubElementReplacements &attrRepls,
681 TypeSubElementReplacements &typeRepls) {
682 return BundleElement(
683 cast<StringAttr>(attrRepls.take_front(1)[0]), param.isFlip,
684 cast<circt::firrtl::FIRRTLType>(typeRepls.take_front(1)[0]));
685 }
686};
687
688/// Allow walking and replacing the subelements of an EnumElement.
689template <>
690struct mlir::AttrTypeSubElementHandler<circt::firrtl::FEnumType::EnumElement> {
691 using EnumElement = circt::firrtl::FEnumType::EnumElement;
692
693 static void walk(const EnumElement &param,
694 AttrTypeImmediateSubElementWalker &walker) {
695 walker.walk(param.name);
696 walker.walk(param.value);
697 walker.walk(param.type);
698 }
699 static EnumElement replace(const EnumElement &param,
700 AttrSubElementReplacements &attrRepls,
701 TypeSubElementReplacements &typeRepls) {
702 auto attrs = attrRepls.take_front(2);
703 return EnumElement(
704 cast<StringAttr>(attrs[0]), cast<IntegerAttr>(attrs[1]),
705 cast<circt::firrtl::FIRRTLBaseType>(typeRepls.take_front(1)[0]));
706 }
707};
708
709#endif // CIRCT_DIALECT_FIRRTL_TYPES_H
assert(baseType &&"element must be base type")
static std::unique_ptr< Context > context
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:93
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
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...
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.
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:72
bool containsReference
Whether the type contains a reference type.
Definition FIRRTLTypes.h:76
bool isPassive
Whether the type only contains passive elements.
Definition FIRRTLTypes.h:74
bool containsAnalog
Whether the type contains an analog type.
Definition FIRRTLTypes.h:78
bool hasUninferredReset
Whether the type has any uninferred reset.
Definition FIRRTLTypes.h:86
bool containsTypeAlias
Whether the type contains a type alias.
Definition FIRRTLTypes.h:82
bool containsConst
Whether the type contains a const type.
Definition FIRRTLTypes.h:80
bool hasUninferredWidth
Whether the type has any uninferred bit widths.
Definition FIRRTLTypes.h:84
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)