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