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