P4C
The P4 Compiler
Loading...
Searching...
No Matches
resources_parser.h
1
18
19#ifndef _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_PARSER_H_
20#define _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_PARSER_H_
21
22#include "backends/tofino/bf-p4c/device.h"
23#include "backends/tofino/bf-p4c/logging/resources_schema.h"
24#include "backends/tofino/bf-p4c/parde/parde_visitor.h"
25#include "ir/ir.h"
26
27using Logging::Resources_Schema_Logger;
28
29namespace BFN {
30
35class ParserResourcesLogging : public ParserInspector {
36 public:
37 using ElementUsage = Resources_Schema_Logger::ElementUsage;
38 using ParserResources = Resources_Schema_Logger::ParserResources;
39 using ParserResourceUsage = Resources_Schema_Logger::ParserResourceUsage;
40 using Phase0ResourceUsage = Resources_Schema_Logger::Phase0ResourceUsage;
41
42 using ParserStateTransition = Resources_Schema_Logger::ParserStateTransitionResourceUsage;
43
44 using ClotExtracts = ParserStateTransition::Clot_Extracts;
45 using StateExtracts = ParserStateTransition::Extracts;
46 using StateMatchesOn = ParserStateTransition::MatchesOn;
47 using StateSavesTo = ParserStateTransition::SavesTo;
48
49 private:
50 struct ParserLogData {
51 ParserResourceUsage *usage = nullptr;
52 Phase0ResourceUsage *phase0 = nullptr;
53 };
54
55 bool collected = false;
56 ParserResources *parserLogger = nullptr;
57
58 std::map<cstring, ParserLogData> parsers;
59
60 std::map<cstring, int> stateIds;
61 std::map<const IR::BFN::LoweredParserMatch *, int> tcamIds[2];
62 int nextTcamId[2] = {0}; // Next TCAM ID value array
63
65 bool preorder(const IR::BFN::LoweredParserState *state) override;
66 bool preorder(const IR::BFN::LoweredParser *parser) override;
67 void end_apply() override { collected = true; }
68
69 std::vector<ParserStateTransition *> logStateTransitionsByMatch(
70 const std::string &nextStateName, const IR::BFN::LoweredParserState *prevState,
71 const IR::BFN::LoweredParserMatch *match);
72
73 int getTcamId(const IR::BFN::LoweredParserMatch *match, gress_t gress);
74
75 int getStateId(const std::string &state);
76
77 void logStateExtracts(const IR::BFN::LoweredParserMatch *match,
78 std::vector<StateExtracts *> &result);
79
80 void logStateMatches(const IR::BFN::LoweredParserState *prevState,
81 const IR::BFN::LoweredParserMatch *match,
82 std::vector<StateMatchesOn *> &result);
83
84 void logStateSaves(const IR::BFN::LoweredParserMatch *match,
85 std::vector<StateSavesTo *> &result);
86
87 public:
88 ParserResourcesLogging() {
89 const int tcamRowsInit = Device::pardeSpec().numTcamRows() - 1;
90 nextTcamId[0] = tcamRowsInit;
91 nextTcamId[1] = tcamRowsInit;
92 }
93
94 const ParserResources *getLogger();
95};
96
97} // namespace BFN
98
99#endif /* _BACKENDS_TOFINO_BF_P4C_LOGGING_RESOURCES_PARSER_H_ */
Definition parde_visitor.h:66
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21