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 std::equal(key.begin(), key.end(), arguments.begin(),
59 arguments.end());
60 }
61
62 static llvm::hash_code hashKey(const KeyTy &key) {
63 return llvm::hash_combine_range(key.begin(), key.end());
64 }
65
67 construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key);
68
69 KeyTy getAsKey() const { return arguments; }
70
71 llvm::ArrayRef<DPIArgument> getArguments() const { return arguments; }
72
73 /// Return the cached MLIR FunctionType for the call shape.
74 mlir::FunctionType getCachedFunctionType() const { return cachedFuncType; }
75
76 llvm::SmallVector<DPIArgument> arguments;
77 llvm::SmallVector<size_t> inputToAbs;
78 llvm::SmallVector<size_t> resultToAbs;
79 mlir::FunctionType cachedFuncType;
80};
81
82/// A single alternative of a variant type.
84} // namespace detail
85
86} // namespace sim
87} // namespace circt
88
89#define GET_TYPEDEF_CLASSES
90#include "circt/Dialect/Sim/SimTypes.h.inc"
91
92#endif // CIRCT_DIALECT_SIM_SIMTYPES_H
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.
Definition hw.py:1
Definition sim.py:1
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:76
llvm::SmallVector< size_t > inputToAbs
Definition SimTypes.h:77
static llvm::hash_code hashKey(const KeyTy &key)
Definition SimTypes.h:62
llvm::SmallVector< size_t > resultToAbs
Definition SimTypes.h:78
llvm::ArrayRef< DPIArgument > getArguments() const
Definition SimTypes.h:71
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:74
bool operator==(const KeyTy &key) const
Definition SimTypes.h:57
llvm::ArrayRef< DPIArgument > KeyTy
Definition SimTypes.h:55