File tree 4 files changed +28
-4
lines changed
4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class SkipControls : public P4::ActionSynthesisPolicy {
82
82
83
83
public:
84
84
explicit SkipControls (const std::set<cstring> *skip) : skip(skip) { CHECK_NULL (skip); }
85
- bool convert (const IR::P4Control* control) const {
85
+ bool convert (const Visitor::Context *, const IR::P4Control* control) override {
86
86
if (skip->find (control->name ) != skip->end ())
87
87
return false ;
88
88
return true ;
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class SkipControls : public P4::ActionSynthesisPolicy {
58
58
59
59
public:
60
60
explicit SkipControls (const std::set<cstring> *skip) : skip(skip) { CHECK_NULL (skip); }
61
- bool convert (const IR::P4Control* control) const override {
61
+ bool convert (const Visitor::Context *, const IR::P4Control* control) override {
62
62
if (skip->find (control->name ) != skip->end ())
63
63
return false ;
64
64
return true ;
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ bool DoSynthesizeActions::mustMove(const IR::AssignmentStatement *assign) {
113
113
const IR::Node* DoSynthesizeActions::preorder (IR::P4Control* control) {
114
114
actions.clear ();
115
115
changes = false ;
116
- if (policy != nullptr && !policy->convert (control))
116
+ if (policy != nullptr && !policy->convert (getContext (), control))
117
117
prune (); // skip this one
118
118
return control;
119
119
}
@@ -132,10 +132,20 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) {
132
132
for (auto c : statement->components ) {
133
133
if (c->is <IR::AssignmentStatement>()) {
134
134
if (mustMove (c->to <IR::AssignmentStatement>())) {
135
+ if (policy && !actbody->components .empty () &&
136
+ !policy->can_combine (getContext (), actbody, c)) {
137
+ auto action = createAction (actbody);
138
+ left->push_back (action);
139
+ actbody = new IR::BlockStatement; }
135
140
actbody->push_back (c);
136
141
continue ; }
137
142
} else if (c->is <IR::MethodCallStatement>()) {
138
143
if (mustMove (c->to <IR::MethodCallStatement>())) {
144
+ if (policy && !actbody->components .empty () &&
145
+ !policy->can_combine (getContext (), actbody, c)) {
146
+ auto action = createAction (actbody);
147
+ left->push_back (action);
148
+ actbody = new IR::BlockStatement; }
139
149
actbody->push_back (c);
140
150
continue ;
141
151
}
Original file line number Diff line number Diff line change @@ -34,7 +34,21 @@ class ActionSynthesisPolicy {
34
34
If the policy returns true the control block is processed,
35
35
otherwise it is left unchanged.
36
36
*/
37
- virtual bool convert (const IR::P4Control* control) const = 0;
37
+ virtual bool convert (const Visitor::Context *ctxt, const IR::P4Control* control) = 0;
38
+
39
+ /* *
40
+ Called for each statement that may be put into an action when there are preceeding
41
+ statements already put into an action --
42
+ @param ctxt context of the code being processsed (control and parents)
43
+ @param blk previous statement(s) being put into an action
44
+ @param stmt statement to be added to the block for a single action
45
+ @returns
46
+ true statement should be added to the same action
47
+ false statement should start a new action
48
+ */
49
+ virtual bool can_combine (const Visitor::Context *, const IR::BlockStatement *,
50
+ const IR::StatOrDecl *) {
51
+ return true ; }
38
52
};
39
53
40
54
/* *
You can’t perform that action at this time.
0 commit comments