CIRCT 23.0.0git
Loading...
Searching...
No Matches
HWOps.h
Go to the documentation of this file.
1//===- HWOps.h - Declare HW dialect operations ------------------*- 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 classes for the HW dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_HW_OPS_H
14#define CIRCT_DIALECT_HW_OPS_H
15
23#include "mlir/IR/BuiltinOps.h"
24#include "mlir/IR/ImplicitLocOpBuilder.h"
25#include "mlir/IR/OpImplementation.h"
26#include "mlir/IR/RegionKindInterface.h"
27#include "mlir/IR/SymbolTable.h"
28#include "mlir/Interfaces/ControlFlowInterfaces.h"
29#include "mlir/Interfaces/FunctionInterfaces.h"
30#include "mlir/Interfaces/InferIntRangeInterface.h"
31#include "mlir/Interfaces/InferTypeOpInterface.h"
32#include "mlir/Interfaces/SideEffectInterfaces.h"
33#include "llvm/ADT/StringExtras.h"
34
35namespace circt {
36namespace hw {
37
38class EnumFieldAttr;
39
40/// Flip a port direction.
42
43/// TODO: Move all these functions to a hw::ModuleLike interface.
44
45// Helpers for working with modules.
46
47/// Return true if isAnyModule or instance.
48bool isAnyModuleOrInstance(Operation *module);
49
50/// Return the signature for the specified module as a function type.
51FunctionType getModuleType(Operation *module);
52
53/// Returns the verilog module name attribute or symbol name of any module-like
54/// operations.
55StringAttr getVerilogModuleNameAttr(Operation *module);
56inline StringRef getVerilogModuleName(Operation *module) {
57 return getVerilogModuleNameAttr(module).getValue();
58}
59
60// Index width should be exactly clog2 (size of array), or either 0 or 1 if the
61// array is a singleton.
62bool isValidIndexBitWidth(Value index, Value array);
63
64/// Return true if the specified operation is a combinational logic op.
65bool isCombinational(Operation *op);
66
67/// Return true if the specified attribute tree is made up of nodes that are
68/// valid in a parameter expression.
69bool isValidParameterExpression(Attribute attr, Operation *module);
70
71/// Check parameter specified by `value` to see if it is valid within the scope
72/// of the specified module `module`. If not, emit an error at the location of
73/// `usingOp` and return failure, otherwise return success.
74///
75/// If `disallowParamRefs` is true, then parameter references are not allowed.
76LogicalResult checkParameterInContext(Attribute value, Operation *module,
77 Operation *usingOp,
78 bool disallowParamRefs = false);
79
80/// Check parameter specified by `value` to see if it is valid according to the
81/// module's parameters. If not, emit an error to the diagnostic provided as an
82/// argument to the lambda 'instanceError' and return failure, otherwise return
83/// success.
84///
85/// If `disallowParamRefs` is true, then parameter references are not allowed.
86LogicalResult checkParameterInContext(
87 Attribute value, ArrayAttr moduleParameters,
88 const std::function<void(std::function<bool(InFlightDiagnostic &)>)>
89 &instanceError,
90 bool disallowParamRefs = false);
91
92// Check whether an integer value is an offset from a base.
93bool isOffset(Value base, Value index, uint64_t offset);
94
95// A class for providing access to the in- and output ports of a module through
96// use of the HWModuleBuilder.
98
99public:
100 HWModulePortAccessor(Location loc, const ModulePortInfo &info,
101 Region &bodyRegion);
102
103 // Returns the i'th/named input port of the module.
104 Value getInput(unsigned i);
105 Value getInput(StringRef name);
106 ValueRange getInputs() { return inputArgs; }
107
108 // Assigns the i'th/named output port of the module.
109 void setOutput(unsigned i, Value v);
110 void setOutput(StringRef name, Value v);
111
112 const ModulePortInfo &getPortList() const { return info; }
113 const llvm::SmallVector<Value> &getOutputOperands() const {
114 return outputOperands;
115 }
116
117private:
118 llvm::StringMap<unsigned> inputIdx, outputIdx;
119 llvm::SmallVector<Value> inputArgs;
120 llvm::SmallVector<Value> outputOperands;
122};
123
125 llvm::function_ref<void(OpBuilder &, HWModulePortAccessor &)>;
126
127} // namespace hw
128} // namespace circt
129
130#define GET_OP_CLASSES
131#include "circt/Dialect/HW/HW.h.inc"
132
133#endif // CIRCT_DIALECT_HW_OPS_H
void setOutput(unsigned i, Value v)
Definition HWOps.cpp:241
const ModulePortInfo & getPortList() const
Definition HWOps.h:112
Value getInput(unsigned i)
Definition HWOps.cpp:247
const llvm::SmallVector< Value > & getOutputOperands() const
Definition HWOps.h:113
llvm::SmallVector< Value > outputOperands
Definition HWOps.h:120
llvm::SmallVector< Value > inputArgs
Definition HWOps.h:119
llvm::StringMap< unsigned > outputIdx
Definition HWOps.h:118
llvm::StringMap< unsigned > inputIdx
Definition HWOps.h:118
bool isOffset(Value base, Value index, uint64_t offset)
Definition HWOps.cpp:1722
llvm::function_ref< void(OpBuilder &, HWModulePortAccessor &)> HWModuleBuilder
Definition HWOps.h:125
bool isCombinational(Operation *op)
Return true if the specified operation is a combinational logic op.
Definition HWOps.cpp:59
StringRef getVerilogModuleName(Operation *module)
Definition HWOps.h:56
ModulePort::Direction flip(ModulePort::Direction direction)
Flip a port direction.
Definition HWOps.cpp:36
FunctionType getModuleType(Operation *module)
Return the signature for the specified module as a function type.
Definition HWOps.cpp:533
LogicalResult checkParameterInContext(Attribute value, Operation *module, Operation *usingOp, bool disallowParamRefs=false)
Check parameter specified by value to see if it is valid within the scope of the specified module mod...
Definition HWOps.cpp:202
bool isValidParameterExpression(Attribute attr, Operation *module)
Return true if the specified attribute tree is made up of nodes that are valid in a parameter express...
Definition HWOps.cpp:221
bool isValidIndexBitWidth(Value index, Value array)
Definition HWOps.cpp:48
bool isAnyModuleOrInstance(Operation *module)
TODO: Move all these functions to a hw::ModuleLike interface.
Definition HWOps.cpp:527
StringAttr getVerilogModuleNameAttr(Operation *module)
Returns the verilog module name attribute or symbol name of any module-like operations.
Definition HWOps.cpp:551
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition hw.py:1
This holds a decoded list of input/inout and output ports for a module or instance.