CIRCT 23.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
12#include "mlir/IR/BuiltinAttributes.h"
13#include "mlir/IR/BuiltinTypes.h"
14#include "mlir/IR/Types.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/SmallVector.h"
17
18namespace circt {
19namespace hw {
20class ModuleType;
21} // namespace hw
22namespace sim {
23
24// Forward-declare the tablegen enum (defined in SimEnums.h.inc).
25enum class DPIDirection : uint32_t;
26
27/// Return the keyword string for a DPIDirection (e.g. "in", "return").
28llvm::StringRef stringifyDPIDirectionKeyword(DPIDirection dir);
29
30/// Parse a keyword string to a DPIDirection. Returns std::nullopt on failure.
31std::optional<DPIDirection> parseDPIDirectionKeyword(llvm::StringRef keyword);
32
33/// True if an argument with this direction is a call operand (input/inout/ref).
34bool isCallOperandDir(DPIDirection dir);
35
36/// A single argument in a DPI function type.
38 mlir::StringAttr name;
39 mlir::Type type;
40 DPIDirection dir;
41};
42
43static inline bool operator==(const DPIArgument &a, const DPIArgument &b) {
44 return a.dir == b.dir && a.name == b.name && a.type == b.type;
45}
46static inline llvm::hash_code hash_value(const DPIArgument &arg) {
47 return llvm::hash_combine(static_cast<uint32_t>(arg.dir), arg.name, arg.type);
48}
49
50namespace detail {
51struct DPIFunctionTypeStorage : public mlir::TypeStorage {
52 DPIFunctionTypeStorage(llvm::ArrayRef<DPIArgument> args);
53
54 using KeyTy = llvm::ArrayRef<DPIArgument>;
55
56 bool operator==(const KeyTy &key) const {
57 return std::equal(key.begin(), key.end(), arguments.begin(),
58 arguments.end());
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} // namespace detail
81
82} // namespace sim
83} // namespace circt
84
85#define GET_TYPEDEF_CLASSES
86#include "circt/Dialect/Sim/SimTypes.h.inc"
87
88#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:27
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:53
static bool operator==(const DPIArgument &a, const DPIArgument &b)
Definition SimTypes.h:43
static llvm::hash_code hash_value(const DPIArgument &arg)
Definition SimTypes.h:46
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition hw.py:1
Definition sim.py:1
A single argument in a DPI function type.
Definition SimTypes.h:37
mlir::StringAttr name
Definition SimTypes.h:38
llvm::SmallVector< DPIArgument > arguments
Definition SimTypes.h:75
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:86
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:56
llvm::ArrayRef< DPIArgument > KeyTy
Definition SimTypes.h:54