CIRCT 22.0.0git
Loading...
Searching...
No Matches
HWOpInterfaces.h
Go to the documentation of this file.
1//===- HWOpInterfaces.h - Declare HW op interfaces --------------*- 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 declares the operation interfaces for the HW dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_HW_HWOPINTERFACES_H
14#define CIRCT_DIALECT_HW_HWOPINTERFACES_H
15
22#include "circt/Support/LLVM.h"
23#include "mlir/IR/OpDefinition.h"
24#include "mlir/IR/SymbolTable.h"
25
26namespace circt {
27namespace hw {
28
29void populateHWModuleLikeTypeConversionPattern(StringRef moduleLikeOpName,
30 RewritePatternSet &patterns,
31 TypeConverter &converter);
32
33class InnerSymbolOpInterface;
34/// Verification hook for verifying InnerSymbol-defining operations.
35LogicalResult verifyInnerSymOp(InnerSymbolOpInterface op);
36
37/// Verification hook for verifying InnerSymbol-defining operations.
38LogicalResult verifyPortInnerSymsIfPortList(Operation *op);
39
40// Verification hook for verifying an inner symbol attribute.
41// Variant accepting 'Type' is for per-field checking.
42// (for when the inner symbol points into fields of a type)
43LogicalResult
44verifyInnerSymAttr(InnerSymAttr innerSym, Type type,
45 llvm::function_ref<InFlightDiagnostic()> emitError);
46inline LogicalResult
47verifyInnerSymAttr(InnerSymAttr innerSym,
48 llvm::function_ref<InFlightDiagnostic()> emitError) {
49 return verifyInnerSymAttr(innerSym, {}, emitError);
50}
51
52namespace detail {
53LogicalResult verifyInnerRefNamespace(Operation *op);
54} // namespace detail
55
56/// Classify operations that are InnerRefNamespace-like,
57/// until structure is in place to do this via Traits.
58/// Useful for getParentOfType<>, or scheduling passes.
59/// Prefer putting the trait on operations here or downstream.
61 /// Return if this operation is explicitly an IRN or appears compatible.
62 static bool classof(mlir::Operation *op);
63 /// Return if this operation is explicitly an IRN or appears compatible.
64 static bool classof(const mlir::RegisteredOperationName *opInfo);
65};
66
67} // namespace hw
68} // namespace circt
69
70namespace mlir {
71namespace OpTrait {
72
73/// This trait is for operations that define a scope for resolving InnerRef's,
74/// and provides verification for InnerRef users (via InnerRefUserOpInterface).
75template <typename ConcreteType>
76class InnerRefNamespace : public TraitBase<ConcreteType, InnerRefNamespace> {
77public:
78 static LogicalResult verifyRegionTrait(Operation *op) {
79 static_assert(
80 ConcreteType::template hasTrait<::mlir::OpTrait::SymbolTable>(),
81 "expected operation to be a SymbolTable");
82
83 if (op->getNumRegions() != 1)
84 return op->emitError("expected operation to have a single region");
85 if (!op->getRegion(0).hasOneBlock())
86 return op->emitError("expected operation to have a single block");
87
88 // Verify all InnerSymbolTable's and InnerRef users.
89 return ::circt::hw::detail::verifyInnerRefNamespace(op);
90 }
91};
92
93/// A trait for inner symbol table functionality on an operation.
94template <typename ConcreteType>
95class InnerSymbolTable : public TraitBase<ConcreteType, InnerSymbolTable> {
96public:
97 static LogicalResult verifyRegionTrait(Operation *op) {
98 // Insist that ops with InnerSymbolTable's provide a Symbol, this is
99 // essential to how InnerRef's work.
100 static_assert(
101 ConcreteType::template hasTrait<::mlir::SymbolOpInterface::Trait>(),
102 "expected operation to define a Symbol");
103
104 // InnerSymbolTable's must be directly nested within an InnerRefNamespace.
105 auto *parent = op->getParentOp();
106 if (!parent || !isa<circt::hw::InnerRefNamespaceLike>(parent))
107 return op->emitError(
108 "InnerSymbolTable must have InnerRefNamespace parent");
109
110 // If also a PortList, walk and verify each port's inner symbol(s).
111 return ::circt::hw::verifyPortInnerSymsIfPortList(op);
112 }
113};
114} // namespace OpTrait
115} // namespace mlir
116
117#include "circt/Dialect/HW/HWOpInterfaces.h.inc"
118
119#endif // CIRCT_DIALECT_HW_HWOPINTERFACES_H
This trait is for operations that define a scope for resolving InnerRef's, and provides verification ...
static LogicalResult verifyRegionTrait(Operation *op)
A trait for inner symbol table functionality on an operation.
static LogicalResult verifyRegionTrait(Operation *op)
LogicalResult verifyInnerRefNamespace(Operation *op)
LogicalResult verifyPortInnerSymsIfPortList(Operation *op)
Verification hook for verifying InnerSymbol-defining operations.
void populateHWModuleLikeTypeConversionPattern(StringRef moduleLikeOpName, RewritePatternSet &patterns, TypeConverter &converter)
LogicalResult verifyInnerSymAttr(InnerSymAttr innerSym, Type type, llvm::function_ref< InFlightDiagnostic()> emitError)
LogicalResult verifyInnerSymOp(InnerSymbolOpInterface op)
Verification hook for verifying InnerSymbol-defining operations.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition hw.py:1
Classify operations that are InnerRefNamespace-like, until structure is in place to do this via Trait...
static bool classof(mlir::Operation *op)
Return if this operation is explicitly an IRN or appears compatible.