CIRCT  20.0.0git
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 
20 #include "circt/Support/FieldRef.h"
22 #include "circt/Support/LLVM.h"
23 #include "mlir/IR/OpDefinition.h"
24 #include "mlir/IR/SymbolTable.h"
25 
26 namespace circt {
27 namespace hw {
28 
29 void populateHWModuleLikeTypeConversionPattern(StringRef moduleLikeOpName,
30  RewritePatternSet &patterns,
31  TypeConverter &converter);
32 
33 class InnerSymbolOpInterface;
34 /// Verification hook for verifying InnerSym Attribute.
35 LogicalResult verifyInnerSymAttr(InnerSymbolOpInterface op);
36 
37 namespace detail {
38 LogicalResult verifyInnerRefNamespace(Operation *op);
39 } // namespace detail
40 
41 /// Classify operations that are InnerRefNamespace-like,
42 /// until structure is in place to do this via Traits.
43 /// Useful for getParentOfType<>, or scheduling passes.
44 /// Prefer putting the trait on operations here or downstream.
46  /// Return if this operation is explicitly an IRN or appears compatible.
47  static bool classof(mlir::Operation *op);
48  /// Return if this operation is explicitly an IRN or appears compatible.
49  static bool classof(const mlir::RegisteredOperationName *opInfo);
50 };
51 
52 } // namespace hw
53 } // namespace circt
54 
55 namespace mlir {
56 namespace OpTrait {
57 
58 /// This trait is for operations that define a scope for resolving InnerRef's,
59 /// and provides verification for InnerRef users (via InnerRefUserOpInterface).
60 template <typename ConcreteType>
61 class InnerRefNamespace : public TraitBase<ConcreteType, InnerRefNamespace> {
62 public:
63  static LogicalResult verifyRegionTrait(Operation *op) {
64  static_assert(
65  ConcreteType::template hasTrait<::mlir::OpTrait::SymbolTable>(),
66  "expected operation to be a SymbolTable");
67 
68  if (op->getNumRegions() != 1)
69  return op->emitError("expected operation to have a single region");
70  if (!op->getRegion(0).hasOneBlock())
71  return op->emitError("expected operation to have a single block");
72 
73  // Verify all InnerSymbolTable's and InnerRef users.
75  }
76 };
77 
78 /// A trait for inner symbol table functionality on an operation.
79 template <typename ConcreteType>
80 class InnerSymbolTable : public TraitBase<ConcreteType, InnerSymbolTable> {
81 public:
82  static LogicalResult verifyRegionTrait(Operation *op) {
83  // Insist that ops with InnerSymbolTable's provide a Symbol, this is
84  // essential to how InnerRef's work.
85  static_assert(
86  ConcreteType::template hasTrait<::mlir::SymbolOpInterface::Trait>(),
87  "expected operation to define a Symbol");
88 
89  // InnerSymbolTable's must be directly nested within an InnerRefNamespace.
90  auto *parent = op->getParentOp();
91  if (!parent || !isa<circt::hw::InnerRefNamespaceLike>(parent))
92  return op->emitError(
93  "InnerSymbolTable must have InnerRefNamespace parent");
94 
95  return success();
96  }
97 };
98 } // namespace OpTrait
99 } // namespace mlir
100 
101 #include "circt/Dialect/HW/HWOpInterfaces.h.inc"
102 
103 #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)
void populateHWModuleLikeTypeConversionPattern(StringRef moduleLikeOpName, RewritePatternSet &patterns, TypeConverter &converter)
LogicalResult verifyInnerSymAttr(InnerSymbolOpInterface op)
Verification hook for verifying InnerSym Attribute.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
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.