CIRCT 23.0.0git
Loading...
Searching...
No Matches
IRInterface.h
Go to the documentation of this file.
1//===- IRInterface.h - ArcRuntime internal API ----------------------------===//
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// Declares the runtime functions called from the MLIR model.
10//
11// This file defines the runtime's internal API. Changes to the internal API
12// must be reflected in the lowering passes of the MLIR model.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef CIRCT_DIALECT_ARC_RUNTIME_IRINTERFACE_H
17#define CIRCT_DIALECT_ARC_RUNTIME_IRINTERFACE_H
18
19// NOLINTBEGIN(readability-identifier-naming)
20
21#ifndef ARC_IR_EXPORT
22#ifndef ARC_RUNTIME_JIT_BIND
23
24// Marco definition for the shipped version of the library:
25// Symbols have to be visible to allow linking of the precompiled hardware
26// model against the static or dynamic runtime library.
27
28#ifdef _WIN32
29#define ARC_IR_EXPORT extern "C" __declspec(dllexport)
30#else
31#define ARC_IR_EXPORT extern "C" __attribute__((visibility("default")))
32#endif
33
34#else // #ifndef ARC_RUNTIME_JIT_BIND
35
36// Marco definition for the JIT runner version of the library:
37// Symbols are deliberately hidden in the executable's symbol table and
38// instead explicitly bound at runtime. This avoids issues due to linker GC
39// and internalization.
40
41#ifdef _WIN32
42#define ARC_IR_EXPORT extern "C"
43#else
44#define ARC_IR_EXPORT extern "C" __attribute__((visibility("hidden")))
45#endif
46
47#endif // #ifndef ARC_RUNTIME_JIT_BIND
48#endif // #ifndef ARC_IR_EXPORT
49
51
52#include <stdint.h>
53
54// Forward-declare.
55namespace circt {
56namespace arc {
57namespace runtime {
58struct FmtDescriptor;
59} // namespace runtime
60} // namespace arc
61} // namespace circt
62
63/// Allocate and initialize the state for a new instance of the given hardware
64/// model.
65///
66/// This function must allocate an `ArcState` struct with at least
67/// `model->numStateBytes` bytes provided for the `modelState` array.
68/// It must return the pointer to the zero initialized model state which is
69/// required to be 16-byte-aligned.
70///
71/// `args` is a zero terminated string containing implementation specific
72/// options for the new instance or `null`.
73ARC_IR_EXPORT uint8_t *
74arcRuntimeIR_allocInstance(const ArcRuntimeModelInfo *model, const char *args);
75
76/// Destroy and deallocate the state of a model instance.
77///
78/// This function is responsible for releasing all resources that previously
79/// have been allocated by `arcRuntimeIR_allocInstance`.
80ARC_IR_EXPORT void arcRuntimeIR_deleteInstance(uint8_t *modelState);
81
82/// Pre-Eval hook of the runtime library.
83///
84/// Simulation drivers must call this once before every invocation of the
85/// model's `eval` function.
86ARC_IR_EXPORT void arcRuntimeIR_onEval(uint8_t *modelState);
87
88/// Prints a formatted string to stdout.
89///
90/// `fmt` is an array of `FmtDescriptor` objects, ending in a descriptor with
91/// action `Action_End`.
92///
93/// The values to format are passed as variadic arguments.
96
97/// Release the active trace buffer and request an empty new buffer.
98///
99/// Invoked by the model to signal that the currently active trace buffer,
100/// referenced by `modelState->traceBuffer` is ready for processing and
101/// contains `modelState->traceBufferSize` valid uint64_t words.
102///
103/// The runtime must return a pointer to a valid storage of at least
104/// `traceBufferCapacity` x uint64_t size, which will become the new active
105/// trace buffer.
106ARC_IR_EXPORT uint64_t *arcRuntimeIR_swapTraceBuffer(const uint8_t *modelState);
107
108// NOLINTEND(readability-identifier-naming)
109#endif // CIRCT_DIALECT_ARC_RUNTIME_IRINTERFACE_H
ARC_IR_EXPORT uint8_t * arcRuntimeIR_allocInstance(const ArcRuntimeModelInfo *model, const char *args)
Allocate and initialize the state for a new instance of the given hardware model.
ARC_IR_EXPORT void arcRuntimeIR_deleteInstance(uint8_t *modelState)
Destroy and deallocate the state of a model instance.
ARC_IR_EXPORT void arcRuntimeIR_onEval(uint8_t *modelState)
Pre-Eval hook of the runtime library.
#define ARC_IR_EXPORT
Definition IRInterface.h:31
ARC_IR_EXPORT uint64_t * arcRuntimeIR_swapTraceBuffer(const uint8_t *modelState)
Release the active trace buffer and request an empty new buffer.
ARC_IR_EXPORT void arcRuntimeIR_format(const circt::arc::runtime::FmtDescriptor *fmt,...)
Prints a formatted string to stdout.
Definition arc.py:1
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Static information for a compiled hardware model, generated by the MLIR lowering.
Definition Common.h:70
A format descriptor, to be given to arcRuntimeFormat.