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