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