P4C
The P4 Compiler
Loading...
Searching...
No Matches
gen_prim_json.h
1
19
#ifndef BF_P4C_MAU_GEN_PRIM_JSON_H_
20
#define BF_P4C_MAU_GEN_PRIM_JSON_H_
21
22
#include "backends/tofino/bf-p4c/common/asm_output.h"
23
#include "backends/tofino/bf-p4c/mau/ixbar_expr.h"
24
#include "backends/tofino/bf-p4c/mau/mau_visitor.h"
25
#include "lib/json.h"
26
27
// Generate Primitive Info for actions before instruction adjustment. Once
28
// instruction adjustment is applied it merges/splits instructions and we loose
29
// the initial p4 info on the operands. This info is passed off to the assembler
30
// to plug into respective actions which is then picked up by the model for
31
// logging
32
// Following Primitives are supported:
33
// - ModifyFieldPrimitive
34
// - DirectAluPrimitive
35
// - ExecuteStatefulAluPrimitive
36
// - DropPrimitive
37
// - AddHeaderPrimitive
38
// - RemoveHeaderPrimitive
39
// - ShiftPrimitive
40
// - ExecuteMeterPrimitive
41
//
42
// Primitives info is generated for model logging and is associated with
43
// a 'primitives' node (in context.json) for each action within a table.
44
//
45
// The 'GeneratePrimitiveInfo' pass does the job of generating a
46
// <testname>.prim.json file with all action primitives and is later
47
// merged into the context.json by the assembler. This is separated out
48
// from being generated directly into the assembly file purely to keep
49
// the assembly concise and readable.
50
//
51
// The primitives node requires instruction details like destination
52
// field, source operand info and operation type which requires the
53
// compiler to have done instruction selection and phv allocation.
54
//
55
// This pass should however always be called before any instruction
56
// adjustment (splitting) occurs as the logging only needs to output the
57
// overall instruction execution as specified in the p4 program. This
58
// should also happen before table placement which can cause table
59
// splitting across stages.
60
//
61
// TBD: Compiler while optimizing may split tables across
62
// stages. This could result in multiple scenarios - e.g.
63
// - all split stages have same set of actions
64
// - one split stage has a different set of actions as compared to the others
65
// - one split stage is a no match table and others have a gateway
66
// - one split stage has an indirect resource and others dont
67
// - one split stage has a partial action completed in the other stages
68
//
69
// With current schema the action primitives (used for logging) are
70
// populated per table and are stage agnostic. They assume the actions
71
// are same in each stage.
72
//
73
// Model logging in such cases will be inconsistent/missing since model
74
// logs actions per stage. This will require an update to the schema to
75
// represent the actions node within a stage_table. In addition to
76
// actions, the indirect_resource node may also need to be moved
77
// similarly.
78
//
79
// Overall this is a significant change as the updated schema
80
// must be supported by the driver/model. The schema should also convey
81
// the original p4 action and how it is split across the stages to give
82
// a clear idea during logging.
83
84
using namespace
P4
;
85
86
class
GeneratePrimitiveInfo
:
public
MauInspector
{
87
private
:
88
const
PhvInfo
&phv;
89
Util::JsonObject
&_primNode;
90
Util::JsonArray
*_tables =
nullptr
;
91
bool
preorder(
const
IR::MAU::Table *tbl)
override
;
92
void
add_primitive(
Util::JsonArray
*primitives,
Util::JsonObject
*prim);
93
void
gen_action_json(
const
IR::MAU::Table *tbl,
const
IR::MAU::Action *act,
94
Util::JsonObject
*_action);
95
Util::JsonObject
*add_op_json(
Util::JsonObject
*prim,
const
std::string op,
96
const
std::string type,
cstring
name);
97
void
validate_add_op_json(
Util::JsonObject
*_primitive,
const
std::string op_name,
98
const
IR::Expression *exp);
99
Util::JsonObject
*add_stful_op_json(
Util::JsonObject
*prim,
const
std::string op,
100
const
std::string op_pfx,
const
std::string type,
101
cstring
name);
102
void
add_hash_dist_json(
Util::JsonObject
*_primitive,
const
std::string prim_name,
103
const
std::string dst_type,
const
cstring
dst_name,
104
const
IR::Expression *dst,
const
IR::MAU::HashDist *hd);
105
Visitor::profile_t
init_apply(
const
IR::Node
*root)
override
;
106
void
end_apply()
override
;
107
108
public
:
109
explicit
GeneratePrimitiveInfo
(
const
PhvInfo
&p,
Util::JsonObject
&primNode)
110
: phv(p), _primNode(primNode) {
111
visitDagOnce =
false
;
112
_tables =
new
Util::JsonArray
();
113
}
114
};
115
116
#endif
/* BF_P4C_MAU_GEN_PRIM_JSON_H_ */
GeneratePrimitiveInfo
Definition
gen_prim_json.h:86
MauInspector
Definition
mau_visitor.h:29
P4::IR::Node
Definition
node.h:94
P4::Util::JsonArray
Definition
json.h:115
P4::Util::JsonObject
Definition
json.h:164
P4::Visitor::profile_t
Definition
visitor.h:78
P4::cstring
Definition
cstring.h:85
PhvInfo
Definition
phv_fields.h:1095
P4
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
applyOptionsPragmas.cpp:24
backends
tofino
bf-p4c
mau
gen_prim_json.h
Generated by
1.12.0