CIRCT 21.0.0git
Loading...
Searching...
No Matches
RTGToolModule.cpp
Go to the documentation of this file.
1//===- RTGToolModule.cpp - RTG Tool API nanobind module -------------------===//
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#include "CIRCTModules.h"
10
11#include "circt-c/RtgTool.h"
12
13#include "mlir/Bindings/Python/NanobindAdaptors.h"
14
15#include <nanobind/nanobind.h>
16namespace nb = nanobind;
17
18using namespace circt;
19
20namespace {
21/// Wrapper around an CirctRtgToolOptions.
22class PyRtgToolOptions {
23public:
24 PyRtgToolOptions(unsigned seed, CirctRtgToolOutputFormat outputFormat,
25 bool verifyPasses, bool verbosePassExecution,
26 const std::vector<std::string> &unsupportedInstructions,
27 const std::string &unsupportedInstructionsFile,
28 bool splitOutput, const std::string &outputPath)
29 : options(circtRtgToolOptionsCreateDefault(seed)) {
30 setOutputFormat(outputFormat);
31 setVerifyPasses(verifyPasses);
32 setVerbosePassExecution(verbosePassExecution);
33 setUnsupportedInstructions(unsupportedInstructions);
34 setUnsupportedInstructionsFile(unsupportedInstructionsFile);
35 setSplitOutput(splitOutput);
36 setOutputPath(outputPath);
37 }
38 ~PyRtgToolOptions() { circtRtgToolOptionsDestroy(options); }
39
40 operator CirctRtgToolOptions() const { return options; }
41 CirctRtgToolOptions get() const { return options; }
42
43 void setOutputFormat(CirctRtgToolOutputFormat format) {
45 }
46
47 void setSeed(unsigned seed) { circtRtgToolOptionsSetSeed(options, seed); }
48
49 void setVerifyPasses(bool enable) {
51 }
52
53 void setVerbosePassExecution(bool enable) {
55 }
56
57 void
58 setUnsupportedInstructions(const std::vector<std::string> &instructions) {
60 options, instructions.size(),
61 reinterpret_cast<const void **>(
62 const_cast<std::string *>(instructions.data())));
63 }
64
65 void addUnsupportedInstruction(const std::string &instruction) {
66 circtRtgToolOptionsAddUnsupportedInstruction(options, instruction.c_str());
67 }
68
69 void setUnsupportedInstructionsFile(const std::string &filename) {
71 filename.c_str());
72 }
73
74 void setSplitOutput(bool enable) {
75 circtRtgToolOptionsSetSplitOutput(options, enable);
76 }
77
78 void setOutputPath(const std::string &path) {
79 circtRtgToolOptionsSetOutputPath(options, path.c_str());
80 }
81
82private:
83 CirctRtgToolOptions options;
84};
85} // namespace
86
87/// Populate the rtgtool python module.
89 m.doc() = "RTGTool Python native extension";
90
91 nb::enum_<CirctRtgToolOutputFormat>(m, "OutputFormat")
93 .value("ELABORATED_MLIR", CIRCT_RTGTOOL_OUTPUT_FORMAT_ELABORATED_MLIR)
95
96 nb::class_<PyRtgToolOptions>(m, "Options")
97 .def(nb::init<unsigned, CirctRtgToolOutputFormat, bool, bool,
98 const std::vector<std::string> &, const std::string &, bool,
99 const std::string &>(),
100 nb::arg("seed"),
101 nb::arg("output_format") = CIRCT_RTGTOOL_OUTPUT_FORMAT_ASM,
102 nb::arg("verify_passes") = true,
103 nb::arg("verbose_pass_execution") = false,
104 nb::arg("unsupported_instructions") = std::vector<const char *>(),
105 nb::arg("unsupported_instructions_file") = "",
106 nb::arg("split_output") = false, nb::arg("output_path") = "")
107 .def("set_output_format", &PyRtgToolOptions::setOutputFormat,
108 "Specify the output format of the tool", nb::arg("format"))
109 .def("set_seed", &PyRtgToolOptions::setSeed,
110 "Specify the seed for all RNGs used in the tool", nb::arg("seed"))
111 .def("set_verify_passes", &PyRtgToolOptions::setVerifyPasses,
112 "Specify whether the verifiers should be run after each pass",
113 nb::arg("enable"))
114 .def("set_verbose_pass_execution",
115 &PyRtgToolOptions::setVerbosePassExecution,
116 "Specify whether passes should run in verbose mode",
117 nb::arg("enable"))
118 .def("set_unsupported_instructions",
119 &PyRtgToolOptions::setUnsupportedInstructions,
120 "Set the list of of instructions unsupported by the assembler",
121 nb::arg("instructions"))
122 .def("add_unsupported_instruction",
123 &PyRtgToolOptions::addUnsupportedInstruction,
124 "Add the instruction given by name to the list of instructions not "
125 "supported by the assembler",
126 nb::arg("instruction_name"))
127 .def("set_unsupported_instructions_file",
128 &PyRtgToolOptions::setUnsupportedInstructionsFile,
129 "Register a file containing a comma-separated list of instruction "
130 "names which are not supported by the assembler.",
131 nb::arg("filename"))
132 .def("set_split_output", &PyRtgToolOptions::setSplitOutput,
133 "Determines whether each test should be emitted to a separate file.",
134 nb::arg("filename"))
135 .def("output_path", &PyRtgToolOptions::setOutputPath,
136 "The path of a file to be emitted to or a directory if "
137 "'split_output' is enabled.",
138 nb::arg("filename"));
139
140 m.def("populate_randomizer_pipeline",
141 [](MlirPassManager pm, const PyRtgToolOptions &options) {
142 circtRtgToolRandomizerPipeline(pm, options.get());
143 });
144}
MLIR_CAPI_EXPORTED void circtRtgToolOptionsAddUnsupportedInstruction(CirctRtgToolOptions options, const char *unsupportedInstruction)
Definition RtgTool.cpp:75
@ CIRCT_RTGTOOL_OUTPUT_FORMAT_ASM
Definition RtgTool.h:36
@ CIRCT_RTGTOOL_OUTPUT_FORMAT_ELABORATED_MLIR
Definition RtgTool.h:35
@ CIRCT_RTGTOOL_OUTPUT_FORMAT_MLIR
Definition RtgTool.h:34
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetVerifyPasses(CirctRtgToolOptions options, bool enable)
Definition RtgTool.cpp:55
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetOutputFormat(CirctRtgToolOptions options, CirctRtgToolOutputFormat format)
Definition RtgTool.cpp:33
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetUnsupportedInstructionsFile(CirctRtgToolOptions options, const char *filename)
Definition RtgTool.cpp:81
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetOutputPath(CirctRtgToolOptions options, const char *path)
Definition RtgTool.cpp:91
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetSplitOutput(CirctRtgToolOptions options, bool enable)
Definition RtgTool.cpp:86
MLIR_CAPI_EXPORTED void circtRtgToolOptionsDestroy(CirctRtgToolOptions options)
Definition RtgTool.cpp:29
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetSeed(CirctRtgToolOptions options, unsigned seed)
Definition RtgTool.cpp:51
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetVerbosePassExecution(CirctRtgToolOptions options, bool enable)
Definition RtgTool.cpp:60
MLIR_CAPI_EXPORTED void circtRtgToolRandomizerPipeline(MlirPassManager pm, CirctRtgToolOptions options)
Definition RtgTool.cpp:100
MLIR_CAPI_EXPORTED CirctRtgToolOptions circtRtgToolOptionsCreateDefault(unsigned seed)
Definition RtgTool.cpp:24
MLIR_CAPI_EXPORTED void circtRtgToolOptionsSetUnsupportedInstructions(CirctRtgToolOptions options, unsigned numInstr, const void **unsupportedInstructions)
Definition RtgTool.cpp:65
enum CiretRtgToolOutputFormat CirctRtgToolOutputFormat
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition CalyxOps.cpp:55
void populateDialectRTGToolSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.