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