CIRCT 24.0.0git
Loading...
Searching...
No Matches
SimTypes.h
Go to the documentation of this file.
1//===- SimTypes.h - Sim dialect types ---------------------------*- 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#ifndef CIRCT_DIALECT_SIM_SIMTYPES_H
10#define CIRCT_DIALECT_SIM_SIMTYPES_H
11
13#include "mlir/IR/BuiltinAttributes.h"
14#include "mlir/IR/BuiltinTypes.h"
15#include "mlir/IR/Types.h"
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/SmallVector.h"
18
19namespace circt {
20namespace hw {
21class ModuleType;
22} // namespace hw
23namespace sim {
24
25// Forward-declare the tablegen enum (defined in SimEnums.h.inc).
26enum class DPIDirection : uint32_t;
27
28/// Return the keyword string for a DPIDirection (e.g. "in", "return").
29llvm::StringRef stringifyDPIDirectionKeyword(DPIDirection dir);
30
31/// Parse a keyword string to a DPIDirection. Returns std::nullopt on failure.
32std::optional<DPIDirection> parseDPIDirectionKeyword(llvm::StringRef keyword);
33
34/// True if an argument with this direction is a call operand (input/inout/ref).
35bool isCallOperandDir(DPIDirection dir);
36
37/// A single argument in a DPI function type.
39 mlir::StringAttr name;
40 mlir::Type type;
41 DPIDirection dir;
42};
43
44static inline bool operator==(const DPIArgument &a, const DPIArgument &b) {
45 return a.dir == b.dir && a.name == b.name && a.type == b.type;
46}
47static inline llvm::hash_code hash_value(const DPIArgument &arg) {
48 return llvm::hash_combine(static_cast<uint32_t>(arg.dir), arg.name, arg.type);
49}
50
51namespace detail {
52struct DPIFunctionTypeStorage : public mlir::TypeStorage {
53 DPIFunctionTypeStorage(llvm::ArrayRef<DPIArgument> args);
54
55 using KeyTy = llvm::ArrayRef<DPIArgument>;
56
57 bool operator==(const KeyTy &key) const {
58 return llvm::equal(key, arguments);
59 }
60
61 static llvm::hash_code hashKey(const KeyTy &key) {
62 return llvm::hash_combine_range(key.begin(), key.end());
63 }
64
66 construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key);
67
68 KeyTy getAsKey() const { return arguments; }
69
70 llvm::ArrayRef<DPIArgument> getArguments() const { return arguments; }
71
72 /// Return the cached MLIR FunctionType for the call shape.
73 mlir::FunctionType getCachedFunctionType() const { return cachedFuncType; }
74
75 llvm::SmallVector<DPIArgument> arguments;
76 llvm::SmallVector<size_t> inputToAbs;
77 llvm::SmallVector<size_t> resultToAbs;
78 mlir::FunctionType cachedFuncType;
79};
80
81/// A single alternative of a variant type.
83} // namespace detail
84
85} // namespace sim
86} // namespace circt
87
88#define GET_TYPEDEF_CLASSES
89#include "circt/Dialect/Sim/SimTypes.h.inc"
90
91#endif // CIRCT_DIALECT_SIM_SIMTYPES_H
::circt::FieldInfo VariantAlternative
A single alternative of a variant type.
Definition SimTypes.h:82
llvm::StringRef stringifyDPIDirectionKeyword(DPIDirection dir)
Return the keyword string for a DPIDirection (e.g. "in", "return").
Definition SimTypes.cpp:28
std::optional< DPIDirection > parseDPIDirectionKeyword(llvm::StringRef keyword)
Parse a keyword string to a DPIDirection. Returns std::nullopt on failure.
bool isCallOperandDir(DPIDirection dir)
True if an argument with this direction is a call operand (input/inout/ref).
Definition SimTypes.cpp:54
static bool operator==(const DPIArgument &a, const DPIArgument &b)
Definition SimTypes.h:44
static llvm::hash_code hash_value(const DPIArgument &arg)
Definition SimTypes.h:47
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
A named and typed field of an aggregate type.
Definition FieldInfo.h:27
A single argument in a DPI function type.
Definition SimTypes.h:38
mlir::StringAttr name
Definition SimTypes.h:39
llvm::SmallVector< DPIArgument > arguments
Definition SimTypes.h:75
DPIFunctionTypeStorage(llvm::ArrayRef< DPIArgument > args)
Definition SimTypes.cpp:73
llvm::SmallVector< size_t > inputToAbs
Definition SimTypes.h:76
static llvm::hash_code hashKey(const KeyTy &key)
Definition SimTypes.h:61
llvm::SmallVector< size_t > resultToAbs
Definition SimTypes.h:77
llvm::ArrayRef< DPIArgument > getArguments() const
Definition SimTypes.h:70
static DPIFunctionTypeStorage * construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key)
Definition SimTypes.cpp:87
mlir::FunctionType getCachedFunctionType() const
Return the cached MLIR FunctionType for the call shape.
Definition SimTypes.h:73
bool operator==(const KeyTy &key) const
Definition SimTypes.h:57
llvm::ArrayRef< DPIArgument > KeyTy
Definition SimTypes.h:55