P4C
The P4 Compiler
Loading...
Searching...
No Matches
auto_alias.h
1
19
#ifndef BACKENDS_TOFINO_BF_P4C_PHV_TRANSFORMS_AUTO_ALIAS_H_
20
#define BACKENDS_TOFINO_BF_P4C_PHV_TRANSFORMS_AUTO_ALIAS_H_
21
22
#include "bf-p4c/phv/phv_fields.h"
23
#include "bf-p4c/phv/pragma/pa_alias.h"
24
#include "bf-p4c/phv/pragma/pa_no_overlay.h"
25
#include "lib/bitvec.h"
26
27
class
DetermineCandidateHeaders
:
public
Inspector
{
28
private
:
29
const
PhvInfo
&phv;
30
ordered_map<cstring, ordered_set<const IR::MAU::Action *>
> headers;
31
ordered_set<cstring>
headersValidatedInParser;
32
ordered_map<cstring, ordered_set<const IR::MAU::Action *>
> headersValidatedInMAU;
33
ordered_set<cstring>
allHeaders;
34
35
profile_t
init_apply(
const
IR::Node
*root)
override
;
36
bool
preorder(
const
IR::BFN::Extract *extract)
override
;
37
bool
preorder(
const
IR::MAU::Instruction *inst)
override
;
38
void
end_apply()
override
;
39
40
public
:
41
explicit
DetermineCandidateHeaders
(
const
PhvInfo
&p) : phv(p) {}
42
43
const
ordered_set<cstring>
getCandidateHeaders()
const
{
44
ordered_set<cstring>
headerSet;
45
for
(
auto
&kv : headers) headerSet.insert(kv.first);
46
return
headerSet;
47
}
48
49
bool
isCandidateHeader(
cstring
header)
const
{
return
headers.count(header); }
50
51
const
ordered_set<const IR::MAU::Action *>
&getActionsForCandidateHeader(
cstring
header)
const
{
52
static
ordered_set<const IR::MAU::Action *>
actions;
53
if
(!isCandidateHeader(header))
return
actions;
54
return
headers.at(header);
55
}
56
};
57
58
struct
MapDestToInstruction
:
public
Inspector
{
59
ordered_map<const PHV::Field *, ordered_set<const IR::MAU::Instruction *>
> dest_to_inst;
60
61
const
PhvInfo
&phv;
62
63
bool
preorder(
const
IR::MAU::Instruction *inst)
override
{
64
if
(inst->operands.empty())
return
true
;
65
auto
dest = phv.field(inst->operands[0]);
66
if
(!dest)
return
true
;
67
dest_to_inst[dest].insert(inst);
68
return
true
;
69
}
70
71
explicit
MapDestToInstruction
(
const
PhvInfo
&p) : phv(p) {}
72
};
73
74
class
DetermineCandidateFields
:
public
Inspector
{
75
private
:
76
const
PhvInfo
&phv;
77
const
DetermineCandidateHeaders
&headers;
78
PragmaAlias
&pragma;
79
PragmaNoOverlay
&no_overlay;
80
const
MapDestToInstruction
&d2i;
81
82
ordered_set<const PHV::Field *>
initialCandidateSet;
83
ordered_map
<
const
PHV::Field
*,
84
ordered_map<const PHV::Field *, ordered_set<const IR::MAU::Action *>
>>
85
candidateSources;
86
87
inline
void
dropFromCandidateSet(
const
PHV::Field
*field);
88
bool
multipleSourcesFound(
const
PHV::Field
*dest,
const
PHV::Field
*src)
const
;
89
bool
incompatibleConstraints(
const
PHV::Field
*dest,
const
PHV::Field
*src)
const
;
90
91
profile_t
init_apply(
const
IR::Node
*root)
override
;
92
bool
preorder(
const
IR::MAU::Instruction *inst)
override
;
93
void
end_apply()
override
;
94
95
public
:
96
explicit
DetermineCandidateFields
(
const
PhvInfo
&p,
const
DetermineCandidateHeaders
&h,
97
PragmaAlias
&pa,
PragmaNoOverlay
&no_ovrl,
98
const
MapDestToInstruction
&d)
99
: phv(p), headers(h), pragma(pa), no_overlay(no_ovrl), d2i(d) {}
100
};
101
102
class
AutoAlias
:
public
PassManager
{
103
private
:
104
MapDestToInstruction
d2i;
105
106
DetermineCandidateHeaders
headers;
107
DetermineCandidateFields
fields;
108
109
public
:
110
explicit
AutoAlias
(
const
PhvInfo
&phv,
PragmaAlias
&pa,
PragmaNoOverlay
&no_ovrl)
111
: d2i(phv), headers(phv), fields(phv, headers, pa, no_ovrl, d2i) {
112
addPasses({&d2i, &headers, &fields});
113
}
114
};
115
116
#endif
/* BACKENDS_TOFINO_BF_P4C_PHV_TRANSFORMS_AUTO_ALIAS_H_ */
AutoAlias
Definition
auto_alias.h:102
DetermineCandidateFields
Definition
auto_alias.h:74
DetermineCandidateHeaders
Definition
auto_alias.h:27
P4::IR::Node
Definition
node.h:95
P4::Inspector
Definition
visitor.h:400
P4::PassManager
Definition
ir/pass_manager.h:40
P4::Visitor::profile_t
Definition
visitor.h:78
P4::cstring
Definition
cstring.h:85
P4::ordered_map
Definition
ordered_map.h:32
P4::ordered_set
Definition
ordered_set.h:32
PHV::Field
Definition
phv_fields.h:154
PhvInfo
Definition
phv_fields.h:1095
PragmaAlias
Definition
pa_alias.h:38
PragmaNoOverlay
Definition
pa_no_overlay.h:33
MapDestToInstruction
Definition
auto_alias.h:58
backends
tofino
bf-p4c
phv
transforms
auto_alias.h
Generated by
1.12.0