2020-06-05 08:52:30 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 whitequark <whitequark@whitequark.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This file is a part of the CXXRTL C API. It should be used together with `cxxrtl_capi.h`.
|
|
|
|
|
|
|
|
#include <backends/cxxrtl/cxxrtl.h>
|
|
|
|
#include <backends/cxxrtl/cxxrtl_capi.h>
|
|
|
|
|
|
|
|
struct _cxxrtl_handle {
|
|
|
|
std::unique_ptr<cxxrtl::module> module;
|
|
|
|
cxxrtl::debug_items objects;
|
|
|
|
};
|
|
|
|
|
2020-06-06 22:45:53 -05:00
|
|
|
// Private function for use by other units of the C API.
|
|
|
|
const cxxrtl::debug_items &cxxrtl_debug_items_from_handle(cxxrtl_handle handle) {
|
|
|
|
return handle->objects;
|
|
|
|
}
|
|
|
|
|
2020-06-05 08:52:30 -05:00
|
|
|
cxxrtl_handle cxxrtl_create(cxxrtl_toplevel design) {
|
2020-12-02 19:58:02 -06:00
|
|
|
return cxxrtl_create_at(design, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
cxxrtl_handle cxxrtl_create_at(cxxrtl_toplevel design, const char *root) {
|
|
|
|
std::string path = root;
|
|
|
|
if (!path.empty()) {
|
|
|
|
// module::debug_info() accepts either an empty path, or a path ending in space to simplify
|
|
|
|
// the logic in generated code. While this is sketchy at best to expose in the C++ API, this
|
|
|
|
// would be a lot worse in the C API, so don't expose it here.
|
|
|
|
assert(path.back() != ' ');
|
|
|
|
path += ' ';
|
|
|
|
}
|
|
|
|
|
2020-06-05 08:52:30 -05:00
|
|
|
cxxrtl_handle handle = new _cxxrtl_handle;
|
|
|
|
handle->module = std::move(design->module);
|
2020-12-02 19:58:02 -06:00
|
|
|
handle->module->debug_info(handle->objects, path);
|
2020-06-05 08:52:30 -05:00
|
|
|
delete design;
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cxxrtl_destroy(cxxrtl_handle handle) {
|
|
|
|
delete handle;
|
|
|
|
}
|
|
|
|
|
2020-12-02 02:25:27 -06:00
|
|
|
void cxxrtl_reset(cxxrtl_handle handle) {
|
|
|
|
handle->module->reset();
|
|
|
|
}
|
|
|
|
|
2020-07-12 18:34:18 -05:00
|
|
|
int cxxrtl_eval(cxxrtl_handle handle) {
|
|
|
|
return handle->module->eval();
|
|
|
|
}
|
|
|
|
|
|
|
|
int cxxrtl_commit(cxxrtl_handle handle) {
|
|
|
|
return handle->module->commit();
|
|
|
|
}
|
|
|
|
|
2020-06-05 08:52:30 -05:00
|
|
|
size_t cxxrtl_step(cxxrtl_handle handle) {
|
|
|
|
return handle->module->step();
|
|
|
|
}
|
|
|
|
|
2020-06-11 08:31:16 -05:00
|
|
|
struct cxxrtl_object *cxxrtl_get_parts(cxxrtl_handle handle, const char *name, size_t *parts) {
|
|
|
|
auto it = handle->objects.table.find(name);
|
|
|
|
if (it == handle->objects.table.end())
|
|
|
|
return nullptr;
|
|
|
|
*parts = it->second.size();
|
|
|
|
return static_cast<cxxrtl_object*>(&it->second[0]);
|
2020-06-05 08:52:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void cxxrtl_enum(cxxrtl_handle handle, void *data,
|
2020-06-11 08:31:16 -05:00
|
|
|
void (*callback)(void *data, const char *name,
|
|
|
|
cxxrtl_object *object, size_t parts)) {
|
|
|
|
for (auto &it : handle->objects.table)
|
|
|
|
callback(data, it.first.c_str(), static_cast<cxxrtl_object*>(&it.second[0]), it.second.size());
|
2020-06-05 08:52:30 -05:00
|
|
|
}
|
cxxrtl: implement debug information outlining.
Aggressive wire localization and inlining is necessary for CXXRTL to
achieve high performance. However, that comes with a cost: reduced
debug information coverage. Previously, as a workaround, the `-Og`
option could have been used to guarantee complete coverage, at a cost
of a significant performance penalty.
This commit introduces debug information outlining. The main eval()
function is compiled with the user-specified optimization settings.
In tandem, an auxiliary debug_eval() function, compiled from the same
netlist, can be used to reconstruct the values of localized/inlined
signals on demand. To the extent that it is possible, debug_eval()
reuses the results of computations performed by eval(), only filling
in the missing values.
Benchmarking a representative design (Minerva SoC SRAM) shows that:
* Switching from `-O4`/`-Og` to `-O6` reduces runtime by ~40%.
* Switching from `-g1` to `-g2`, both used with `-O6`, increases
compile time by ~25%.
* Although `-g2` increases the resident size of generated modules,
this has no effect on runtime.
Because the impact of `-g2` is minimal and the benefits of having
unconditional 100% debug information coverage (and the performance
improvement as well) are major, this commit removes `-Og` and changes
the defaults to `-O6 -g2`.
We'll have our cake and eat it too!
2020-12-13 01:03:16 -06:00
|
|
|
|
|
|
|
void cxxrtl_outline_eval(cxxrtl_outline outline) {
|
|
|
|
outline->eval();
|
|
|
|
}
|
2023-10-09 06:45:12 -05:00
|
|
|
|
|
|
|
int cxxrtl_attr_type(cxxrtl_attr_set attrs_, const char *name) {
|
|
|
|
auto attrs = (cxxrtl::metadata_map*)attrs_;
|
|
|
|
if (!attrs->count(name))
|
|
|
|
return CXXRTL_ATTR_NONE;
|
|
|
|
switch (attrs->at(name).value_type) {
|
|
|
|
case cxxrtl::metadata::UINT:
|
|
|
|
return CXXRTL_ATTR_UNSIGNED_INT;
|
|
|
|
case cxxrtl::metadata::SINT:
|
|
|
|
return CXXRTL_ATTR_SIGNED_INT;
|
|
|
|
case cxxrtl::metadata::STRING:
|
|
|
|
return CXXRTL_ATTR_STRING;
|
|
|
|
case cxxrtl::metadata::DOUBLE:
|
|
|
|
return CXXRTL_ATTR_DOUBLE;
|
|
|
|
default:
|
|
|
|
// Present unsupported attribute type the same way as no attribute at all.
|
|
|
|
return CXXRTL_ATTR_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t cxxrtl_attr_get_unsigned_int(cxxrtl_attr_set attrs_, const char *name) {
|
|
|
|
auto &attrs = *(cxxrtl::metadata_map*)attrs_;
|
|
|
|
assert(attrs.count(name) && attrs.at(name).value_type == cxxrtl::metadata::UINT);
|
|
|
|
return attrs[name].as_uint();
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t cxxrtl_attr_get_signed_int(cxxrtl_attr_set attrs_, const char *name) {
|
|
|
|
auto &attrs = *(cxxrtl::metadata_map*)attrs_;
|
|
|
|
assert(attrs.count(name) && attrs.at(name).value_type == cxxrtl::metadata::SINT);
|
|
|
|
return attrs[name].as_sint();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *cxxrtl_attr_get_string(cxxrtl_attr_set attrs_, const char *name) {
|
|
|
|
auto &attrs = *(cxxrtl::metadata_map*)attrs_;
|
|
|
|
assert(attrs.count(name) && attrs.at(name).value_type == cxxrtl::metadata::STRING);
|
|
|
|
return attrs[name].as_string().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
double cxxrtl_attr_get_double(cxxrtl_attr_set attrs_, const char *name) {
|
|
|
|
auto &attrs = *(cxxrtl::metadata_map*)attrs_;
|
|
|
|
assert(attrs.count(name) && attrs.at(name).value_type == cxxrtl::metadata::DOUBLE);
|
|
|
|
return attrs[name].as_double();
|
|
|
|
}
|