P4C
The P4 Compiler
Loading...
Searching...
No Matches
bf-p4c-options.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_BF_P4C_OPTIONS_H_
20#define BACKENDS_TOFINO_BF_P4C_BF_P4C_OPTIONS_H_
21
22#include "frontends/common/applyOptionsPragmas.h"
23#include "frontends/common/options.h"
24#include "lib/cstring.h"
25#include "lib/exename.h"
26#include "logging/bf_error_reporter.h"
27
28class BFN_Options : public CompilerOptions {
29 public:
30 bool allowUnimplemented = false;
31 bool debugInfo = false;
32 bool no_deadcode_elimination = false;
33 bool forced_placement = false;
34 bool use_clot = true;
35 bool no_tagalong = false;
36 float phv_scale_factor = 1;
37 float max_power = 0.0;
38 bool create_graphs = false;
39 bool decaf = false;
40 bool auto_init_metadata = false;
41 bool disable_parser_state_merging = false;
42 bool backward_compatible = false;
43 bool display_power_budget = false;
44 bool disable_power_check = false;
45 bool disable_mpr_config = false;
46 bool force_match_dependency = false;
47 bool infer_payload_offset = false;
48 bool parser_timing_reports = false;
49 bool parser_bandwidth_opt = false;
50 bool egress_intr_md_opt = false;
51 bool disable_direct_exit = false;
52 bool disable_long_branch = false;
53 bool disable_dark_allocation = false;
54 bool disable_split_attached = false;
55 bool disable_table_placement_backfill = false;
56 bool disable_egress_latency_padding = false;
57 bool table_placement_in_order = false;
58 bool table_placement_long_branch_backtrack = false;
59 bool disable_gfm_parity = true;
60 int relax_phv_init = 0;
61 bool quick_phv_alloc = false;
62#ifdef ALT_PHV_ALLOC_DEFAULT
63 bool alt_phv_alloc = ALT_PHV_ALLOC_DEFAULT;
64#else
65 bool alt_phv_alloc = false;
66#endif
67 int traffic_limit = 100;
68 int num_stages_override = 0;
69 bool enable_event_logger = false;
70 bool disable_parse_min_depth_limit = false;
71 bool disable_parse_max_depth_limit = false;
72 bool alt_phv_alloc_meta_init = false;
73#if BAREFOOT_INTERNAL || 1
74 // FIXME -- Cmake does not consistently set BAREFOOT_INTERNAL for all source
75 // files (why?), so having the layout of any class depend on it will result in
76 // different object files disagreeing on the layout, leading to random memory
77 // corruption. So we always include these fields; they're just unused in release
78 // The particular problem seems to be with gtest -- gtest source files are built
79 // with BAREFOOT_INTERNAL unset, whil backend files are built with it set.
80 std::set<cstring> skipped_pipes;
81 bool no_power_check = false;
82 bool stage_allocation = false;
83 bool tof2lab44_workaround = false;
84 bool skip_seo = true; // still skipping by default currently
85#endif
86 bool verbose = false;
87
88 // FIXME: Temporarily allow manual aliasing of POV bits to address POV bit
89 // growth caused by varbit headers. Only a single bit is needed on Tofino 2 if the varbit is
90 // allocated to a CLOT.
91 bool allow_pov_aliasing = false;
92
93 cstring bfRtSchema = ""_cs;
94 bool p4RuntimeForceStdExterns = false;
95 cstring programName;
96 cstring outputDir = nullptr; // output directory, default "programName.device"
97
98 // Default value on v1ModelVersion must be set based on changes to p4c
99 // frontend. Check PR 2706 in p4lang/p4c. This value will need an update
100 // whenever latest version model number changes in the frontend
101 int v1ModelVersion = 20200408;
102
103 BFN_Options();
104
106 std::vector<const char *> *process(int argc, char *const argv[]) override;
107
108 // private:
109 // BFN_Options::process is called twice: once from the main, and once
110 // from applyPragmaOptions to handle pragma command_line.
111 // This variable prevents doing the actions below twice, since the
112 // pragma command line will only invoke the callbacks for the
113 // respective options.
114 bool processed = false;
115 // FIXME: Must be eventually moved to a program specific data structure
116 // which is accessible by Backend as this is currently not set through
117 // command line option but a convenient place to store global program
118 // information
119 // Set pipe ids for program, for a multipipe program all valid pipe ids will be set
120 unsigned pipes = 0;
121 // Set ghost pipe ids for program, for a multipipe program all pipes with
122 // ghost threads will be set
123 unsigned ghost_pipes = 0;
124 unsigned int inclusive_max_errors_before_enforcing_silence_other_than_the_summary = INT_MAX;
125};
126
127// forward declarations so we do not include ir-generated.h
128namespace P4 {
129namespace IR {
130class P4Program; // NOLINT(build/forward_decl)
131class ToplevelBlock; // NOLINT(build/forward_decl)
132} // namespace IR
133} // namespace P4
134
136class BFNContext : public virtual P4CContext {
137 public:
140 static BFNContext &get();
141
143 BFN_Options &options() override;
144
147
149 void clearBackendOptions();
150
170 cstring getOutputDirectory(const cstring &suffix = cstring(), int pipe_id = -1);
171
173 void discoverPipes(const IR::P4Program *, const IR::ToplevelBlock *);
174
176 cstring &getPipeName(int pipe_id) {
177 static cstring empty("");
178 if (_pipes.count(pipe_id)) return _pipes.at(pipe_id);
179 return empty;
180 }
181
183 bool isPipeName(const cstring &name) {
184 for (auto pipe : _pipes) {
185 if (pipe.second == name) return true;
186 }
187 return false;
188 }
189
190 BfErrorReporter &errorReporter() override;
191
192 private:
193 bool isRecognizedDiagnostic(cstring diagnostic) final;
194
197 BFN_Options primaryOptions;
198
200 thread_local static BFN_Options *optionsInstance;
201
204 std::map<int, cstring> _pipes;
205
206 BfErrorReporter bfErrorReporter;
207};
208
209inline BFN_Options &BackendOptions() { return BFNContext::get().options(); }
210
221 public:
222 std::optional<CommandLineOptions> tryToParse(const IR::Annotation *annotation) override;
223
224 private:
225 std::optional<CommandLineOptions> parseCompilerOption(const IR::Annotation *annotation);
226};
227
228#endif /* BACKENDS_TOFINO_BF_P4C_BF_P4C_OPTIONS_H_ */
Definition bf-p4c-options.h:28
std::vector< const char * > * process(int argc, char *const argv[]) override
Process the command line arguments and set options accordingly.
Definition bf-p4c-options.cpp:673
A CompileContext for bf-p4c.
Definition bf-p4c-options.h:136
static BFNContext & get()
Definition bf-p4c-options.cpp:777
BFN_Options & options() override
Definition bf-p4c-options.cpp:781
void setBackendOptions(BFN_Options *options)
Record options created in the Backend.
Definition bf-p4c-options.cpp:783
void clearBackendOptions()
Clear the backend options.
Definition bf-p4c-options.cpp:789
cstring getOutputDirectory(const cstring &suffix=cstring(), int pipe_id=-1)
Definition bf-p4c-options.cpp:795
void discoverPipes(const IR::P4Program *, const IR::ToplevelBlock *)
identify the pipelines in the program and setup the _pipes map
Definition bf-p4c-options.cpp:829
cstring & getPipeName(int pipe_id)
Return the pipeline name or empty if the program has not been parsed.
Definition bf-p4c-options.h:176
Definition bf-p4c-options.h:220
Definition bf_error_reporter.h:28
Definition applyOptionsPragmas.h:78
The namespace encapsulating IR node classes.
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24