CIRCT  20.0.0git
HWInstanceImplementation.h
Go to the documentation of this file.
1 //===- HWInstanceImplementation.h - Instance-like Op utilities --*- 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 provides utility functions for implementing instance-like
10 // operations, in particular, parsing, and printing common to instance-like
11 // operations.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef CIRCT_DIALECT_HW_HWINSTANCEIMPLEMENTATION_H
16 #define CIRCT_DIALECT_HW_HWINSTANCEIMPLEMENTATION_H
17 
19 #include "circt/Support/LLVM.h"
20 #include <functional>
21 
22 namespace circt {
23 namespace hw {
24 // Forward declarations.
25 class HWSymbolCache;
26 
27 namespace instance_like_impl {
28 
29 /// Whenever the nested function returns true, a note referring to the
30 /// referenced module is attached to the error.
31 using EmitErrorFn =
32  std::function<void(std::function<bool(InFlightDiagnostic &)>)>;
33 
34 /// Verify that the instance refers to a valid HW module.
35 LogicalResult verifyReferencedModule(Operation *instanceOp,
36  SymbolTableCollection &symbolTable,
37  mlir::FlatSymbolRefAttr moduleName,
38  Operation *&module);
39 
40 /// Stores a resolved version of each type in @param types wherein any parameter
41 /// reference has been evaluated based on the set of provided @param parameters
42 /// in @param resolvedTypes
43 LogicalResult resolveParametricTypes(Location loc, ArrayAttr parameters,
44  ArrayRef<Type> types,
45  SmallVectorImpl<Type> &resolvedTypes,
46  const EmitErrorFn &emitError);
47 
48 /// Verify that the list of inputs of the instance and the module match in terms
49 /// of length, names, and types.
50 LogicalResult verifyInputs(ArrayAttr argNames, ArrayAttr moduleArgNames,
51  TypeRange inputTypes,
52  ArrayRef<Type> moduleInputTypes,
53  const EmitErrorFn &emitError);
54 
55 /// Verify that the list of outputs of the instance and the module match in
56 /// terms of length, names, and types.
57 LogicalResult verifyOutputs(ArrayAttr resultNames, ArrayAttr moduleResultNames,
58  TypeRange resultTypes,
59  ArrayRef<Type> moduleResultTypes,
60  const EmitErrorFn &emitError);
61 
62 /// Verify that the parameter lists of the instance and the module match in
63 /// terms of length, names, and types.
64 LogicalResult verifyParameters(ArrayAttr parameters, ArrayAttr moduleParameters,
65  const EmitErrorFn &emitError);
66 
67 /// Combines verifyReferencedModule, verifyInputs, verifyOutputs, and
68 /// verifyParameters. It is only allowed to call this function when the instance
69 /// refers to a HW module. The @param parameters attribute may be null in which
70 /// case not parameters are verified.
71 LogicalResult verifyInstanceOfHWModule(
72  Operation *instance, FlatSymbolRefAttr moduleRef, OperandRange inputs,
73  TypeRange results, ArrayAttr argNames, ArrayAttr resultNames,
74  ArrayAttr parameters, SymbolTableCollection &symbolTable);
75 
76 /// Check that all the parameter values specified to the instance are
77 /// structurally valid.
78 LogicalResult verifyParameterStructure(ArrayAttr parameters,
79  ArrayAttr moduleParameters,
80  const EmitErrorFn &emitError);
81 
82 /// Return the name at the specified index of the ArrayAttr or null if it cannot
83 /// be determined.
84 StringAttr getName(ArrayAttr names, size_t idx);
85 
86 /// Change the name at the specified index of the @param oldNames ArrayAttr to
87 /// @param name
88 ArrayAttr updateName(ArrayAttr oldNames, size_t i, StringAttr name);
89 
90 /// Suggest a name for each result value based on the saved result names
91 /// attribute.
92 void getAsmResultNames(OpAsmSetValueNameFn setNameFn, StringRef instanceName,
93  ArrayAttr resultNames, ValueRange results);
94 
95 /// Return the port list of an instance, based on the name, type and location
96 /// attributes present on the instance.
97 SmallVector<PortInfo> getPortList(Operation *instanceOp);
98 
99 } // namespace instance_like_impl
100 } // namespace hw
101 } // namespace circt
102 
103 #endif // CIRCT_DIALECT_HW_HWINSTANCEIMPLEMENTATION_H
LogicalResult verifyParameterStructure(ArrayAttr parameters, ArrayAttr moduleParameters, const EmitErrorFn &emitError)
Check that all the parameter values specified to the instance are structurally valid.
std::function< void(std::function< bool(InFlightDiagnostic &)>)> EmitErrorFn
Whenever the nested function returns true, a note referring to the referenced module is attached to t...
LogicalResult verifyOutputs(ArrayAttr resultNames, ArrayAttr moduleResultNames, TypeRange resultTypes, ArrayRef< Type > moduleResultTypes, const EmitErrorFn &emitError)
Verify that the list of outputs of the instance and the module match in terms of length,...
LogicalResult verifyInstanceOfHWModule(Operation *instance, FlatSymbolRefAttr moduleRef, OperandRange inputs, TypeRange results, ArrayAttr argNames, ArrayAttr resultNames, ArrayAttr parameters, SymbolTableCollection &symbolTable)
Combines verifyReferencedModule, verifyInputs, verifyOutputs, and verifyParameters.
SmallVector< PortInfo > getPortList(Operation *instanceOp)
Return the port list of an instance, based on the name, type and location attributes present on the i...
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
LogicalResult resolveParametricTypes(Location loc, ArrayAttr parameters, ArrayRef< Type > types, SmallVectorImpl< Type > &resolvedTypes, const EmitErrorFn &emitError)
Stores a resolved version of each type in.
LogicalResult verifyInputs(ArrayAttr argNames, ArrayAttr moduleArgNames, TypeRange inputTypes, ArrayRef< Type > moduleInputTypes, const EmitErrorFn &emitError)
Verify that the list of inputs of the instance and the module match in terms of length,...
ArrayAttr updateName(ArrayAttr oldNames, size_t i, StringAttr name)
Change the name at the specified index of the.
LogicalResult verifyReferencedModule(Operation *instanceOp, SymbolTableCollection &symbolTable, mlir::FlatSymbolRefAttr moduleName, Operation *&module)
Verify that the instance refers to a valid HW module.
void getAsmResultNames(OpAsmSetValueNameFn setNameFn, StringRef instanceName, ArrayAttr resultNames, ValueRange results)
Suggest a name for each result value based on the saved result names attribute.
LogicalResult verifyParameters(ArrayAttr parameters, ArrayAttr moduleParameters, const EmitErrorFn &emitError)
Verify that the parameter lists of the instance and the module match in terms of length,...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: hw.py:1
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn
Definition: LLVM.h:182