Skip to content

Commit a14f9f0

Browse files
author
mbudiu-vmw
committed
make side effects explicit
1 parent db1bf4c commit a14f9f0

File tree

941 files changed

+25651
-23494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

941 files changed

+25651
-23494
lines changed

backends/bmv2/analyzer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ namespace {
9090
// This visitor "converts" IR::Node* into EdgeSets
9191
// Since we cannot return EdgeSets, we place them in the 'after' map.
9292
class CFGBuilder : public Inspector {
93-
CFG* cfg;
94-
const CFG::EdgeSet* current; // predecessors of current node
93+
CFG* cfg;
94+
const CFG::EdgeSet* current; // predecessors of current node
9595
std::map<const IR::Statement*, const CFG::EdgeSet*> after; // successors of each statement
96-
const P4::ReferenceMap* refMap;
97-
const P4::TypeMap* typeMap;
96+
P4::ReferenceMap* refMap;
97+
P4::TypeMap* typeMap;
9898

9999
void setAfter(const IR::Statement* statement, const CFG::EdgeSet* value) {
100100
LOG1("After " << statement << " " << value);
@@ -216,7 +216,7 @@ class CFGBuilder : public Inspector {
216216
}
217217

218218
public:
219-
CFGBuilder(CFG* cfg, const P4::ReferenceMap* refMap, const P4::TypeMap* typeMap) :
219+
CFGBuilder(CFG* cfg, P4::ReferenceMap* refMap, P4::TypeMap* typeMap) :
220220
cfg(cfg), current(nullptr), refMap(refMap), typeMap(typeMap) {}
221221
const CFG::EdgeSet* run(const IR::Statement* startNode, const CFG::EdgeSet* predecessors) {
222222
CHECK_NULL(startNode); CHECK_NULL(predecessors);
@@ -228,7 +228,7 @@ class CFGBuilder : public Inspector {
228228
} // end anonymous namespace
229229

230230
void CFG::build(const IR::P4Control* cc,
231-
const P4::ReferenceMap* refMap, const P4::TypeMap* typeMap) {
231+
P4::ReferenceMap* refMap, P4::TypeMap* typeMap) {
232232
container = cc;
233233
entryPoint = makeNode(cc->name + ".entry");
234234
exitPoint = makeNode(cc->name + ".exit");

backends/bmv2/analyzer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class CFG : public IHasDbPrint {
150150
return result;
151151
}
152152
void build(const IR::P4Control* cc,
153-
const P4::ReferenceMap* refMap, const P4::TypeMap* typeMap);
153+
P4::ReferenceMap* refMap, P4::TypeMap* typeMap);
154154
void setEntry(Node* entry) {
155155
BUG_CHECK(entryPoint == nullptr, "Entry already set");
156156
entryPoint = entry;

backends/bmv2/bmv2stf.py

+2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def do_cli_command(self, cmd):
289289
self.cli_stdin.flush()
290290
self.packetDelay = 1
291291
def do_command(self, cmd):
292+
if self.options.verbose:
293+
print("STF Command:", cmd)
292294
first, cmd = nextWord(cmd)
293295
if first == "":
294296
pass

backends/bmv2/jsonconverter.cpp

+97-21
Large diffs are not rendered by default.

backends/bmv2/midend.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ limitations under the License.
1818
#include "lower.h"
1919
#include "inlining.h"
2020
#include "midend/actionsInlining.h"
21-
#include "midend/uniqueNames.h"
22-
#include "midend/moveDeclarations.h"
2321
#include "midend/removeReturns.h"
2422
#include "midend/moveConstructors.h"
2523
#include "midend/localizeActions.h"
@@ -29,10 +27,9 @@ limitations under the License.
2927
#include "midend/removeLeftSlices.h"
3028
#include "midend/convertEnums.h"
3129
#include "midend/simplifyKey.h"
32-
#include "midend/simplifyExpressions.h"
33-
#include "midend/simplifyParsers.h"
34-
#include "midend/resetHeaders.h"
3530
#include "midend/simplifySelect.h"
31+
#include "frontends/p4/uniqueNames.h"
32+
#include "frontends/p4/simplifyParsers.h"
3633
#include "frontends/p4/strengthReduction.h"
3734
#include "frontends/p4/typeMap.h"
3835
#include "frontends/p4/evaluator/evaluator.h"
@@ -41,6 +38,7 @@ limitations under the License.
4138
#include "frontends/p4/toP4/toP4.h"
4239
#include "frontends/p4/simplify.h"
4340
#include "frontends/p4/unusedDeclarations.h"
41+
#include "frontends/p4/moveDeclarations.h"
4442
#include "frontends/common/constantFolding.h"
4543
#include "frontends/p4/fromv1.0/v1model.h"
4644

@@ -84,14 +82,8 @@ void MidEnd::setup_for_P4_16(CompilerOptions&) {
8482
// we may come through this path even if the program is actually a P4 v1.0 program
8583
auto evaluator = new P4::EvaluatorPass(&refMap, &typeMap);
8684
addPasses({
87-
new P4::SimplifyParsers(&refMap),
8885
new P4::ConvertEnums(&refMap, &typeMap,
8986
new EnumOn32Bits()),
90-
new P4::ResetHeaders(&refMap, &typeMap),
91-
new P4::UniqueNames(&refMap),
92-
new P4::MoveDeclarations(),
93-
new P4::MoveInitializers(),
94-
new P4::SimplifyExpressions(&refMap, &typeMap),
9587
new P4::RemoveReturns(&refMap),
9688
new P4::MoveConstructors(&refMap),
9789
new P4::RemoveAllUnusedDeclarations(&refMap),
@@ -106,11 +98,12 @@ void MidEnd::setup_for_P4_16(CompilerOptions&) {
10698
new P4::Inline(&refMap, &typeMap, evaluator),
10799
new P4::InlineActions(&refMap, &typeMap),
108100
new P4::LocalizeAllActions(&refMap),
101+
new P4::UniqueNames(&refMap),
109102
new P4::UniqueParameters(&refMap),
110103
new P4::ClearTypeMap(&typeMap),
111104
new P4::SimplifyControlFlow(&refMap, &typeMap),
112-
new P4::RemoveParameters(&refMap, &typeMap),
113-
new P4::ClearTypeMap(&typeMap),
105+
new P4::RemoveTableParameters(&refMap, &typeMap),
106+
new P4::RemoveActionParameters(&refMap, &typeMap),
114107
new P4::SimplifyKey(&refMap, &typeMap,
115108
new P4::NonLeftValue(&refMap, &typeMap)),
116109
new P4::ConstantFolding(&refMap, &typeMap),

backends/ebpf/ebpfBackend.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013-present Barefoot Networks, Inc.
2+
Copyright 2013-present Barefoot Networks, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ limitations under the License.
2525
namespace EBPF {
2626

2727
void run_ebpf_backend(const EbpfOptions& options, const IR::ToplevelBlock* toplevel,
28-
P4::ReferenceMap* refMap, const P4::TypeMap* typeMap) {
28+
P4::ReferenceMap* refMap, P4::TypeMap* typeMap) {
2929
if (toplevel == nullptr)
3030
return;
3131

backends/ebpf/ebpfBackend.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013-present Barefoot Networks, Inc.
2+
Copyright 2013-present Barefoot Networks, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ limitations under the License.
2525
namespace EBPF {
2626

2727
void run_ebpf_backend(const EbpfOptions& options, const IR::ToplevelBlock* toplevel,
28-
P4::ReferenceMap* refMap, const P4::TypeMap* typeMap);
28+
P4::ReferenceMap* refMap, P4::TypeMap* typeMap);
2929

3030
} // namespace EBPF
3131

backends/ebpf/ebpfControl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void ControlBodyTranslationVisitor::processApply(const P4::ApplyMethod* method)
107107
BUG_CHECK(table != nullptr, "No table for %1%", method->expr);
108108

109109
P4::ParameterSubstitution binding;
110-
binding.populate(method->getParameters(), method->expr->arguments);
110+
binding.populate(method->getActualParameters(), method->expr->arguments);
111111
cstring actionVariableName = saveAction.at(saveAction.size() - 1);
112112
if (!actionVariableName.isNullOrEmpty()) {
113113
builder->appendFormat("%s %s;\n", table->actionEnumName, actionVariableName);
@@ -118,7 +118,7 @@ void ControlBodyTranslationVisitor::processApply(const P4::ApplyMethod* method)
118118
if (!binding.empty()) {
119119
builder->emitIndent();
120120
builder->appendLine("/* bind parameters */");
121-
for (auto p : *method->getParameters()->getEnumerator()) {
121+
for (auto p : *method->getActualParameters()->getEnumerator()) {
122122
toDereference.emplace(p);
123123
auto etype = EBPFTypeFactory::instance->create(p->type);
124124
builder->emitIndent();

backends/ebpf/ebpfObject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class EBPFProgram : public EBPFObject {
5151
const IR::P4Program* program;
5252
const IR::ToplevelBlock* toplevel;
5353
P4::ReferenceMap* refMap;
54-
const P4::TypeMap* typeMap;
54+
P4::TypeMap* typeMap;
5555
EBPFParser* parser;
5656
EBPFControl* control;
5757
EBPFModel &model;
@@ -70,7 +70,7 @@ class EBPFProgram : public EBPFObject {
7070
bool build(); // return 'true' on success
7171

7272
EBPFProgram(const IR::P4Program* program, P4::ReferenceMap* refMap,
73-
const P4::TypeMap* typeMap, const IR::ToplevelBlock* toplevel) :
73+
P4::TypeMap* typeMap, const IR::ToplevelBlock* toplevel) :
7474
program(program), toplevel(toplevel),
7575
refMap(refMap), typeMap(typeMap),
7676
parser(nullptr), control(nullptr), model(EBPFModel::instance) {

backends/ebpf/midend.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ limitations under the License.
1717
#include "midend.h"
1818
#include "midend/actionsInlining.h"
1919
#include "midend/inlining.h"
20-
#include "midend/moveDeclarations.h"
21-
#include "midend/uniqueNames.h"
2220
#include "midend/removeReturns.h"
2321
#include "midend/moveConstructors.h"
2422
#include "midend/actionSynthesis.h"
2523
#include "midend/localizeActions.h"
2624
#include "midend/removeParameters.h"
2725
#include "midend/local_copyprop.h"
28-
#include "midend/simplifyExpressions.h"
29-
#include "midend/simplifyParsers.h"
30-
#include "midend/resetHeaders.h"
3126
#include "midend/simplifyKey.h"
3227
#include "midend/simplifySelect.h"
28+
#include "frontends/p4/uniqueNames.h"
29+
#include "frontends/p4/moveDeclarations.h"
3330
#include "frontends/p4/typeMap.h"
3431
#include "frontends/p4/evaluator/evaluator.h"
3532
#include "frontends/p4/typeChecking/typeChecker.h"
@@ -39,6 +36,7 @@ limitations under the License.
3936
#include "frontends/p4/unusedDeclarations.h"
4037
#include "frontends/common/constantFolding.h"
4138
#include "frontends/p4/strengthReduction.h"
39+
#include "frontends/p4/simplifyParsers.h"
4240

4341
namespace EBPF {
4442

@@ -51,12 +49,6 @@ const IR::ToplevelBlock* MidEnd::run(EbpfOptions& options, const IR::P4Program*
5149
auto evaluator = new P4::EvaluatorPass(&refMap, &typeMap);
5250

5351
PassManager simplify = {
54-
new P4::SimplifyParsers(&refMap),
55-
new P4::ResetHeaders(&refMap, &typeMap),
56-
new P4::UniqueNames(&refMap),
57-
new P4::MoveDeclarations(),
58-
new P4::MoveInitializers(),
59-
new P4::SimplifyExpressions(&refMap, &typeMap),
6052
new P4::RemoveReturns(&refMap),
6153
new P4::MoveConstructors(&refMap),
6254
new P4::RemoveAllUnusedDeclarations(&refMap),
@@ -81,11 +73,12 @@ const IR::ToplevelBlock* MidEnd::run(EbpfOptions& options, const IR::P4Program*
8173
new P4::Inline(&refMap, &typeMap, evaluator),
8274
new P4::InlineActions(&refMap, &typeMap),
8375
new P4::LocalizeAllActions(&refMap),
76+
new P4::UniqueNames(&refMap),
8477
new P4::UniqueParameters(&refMap),
8578
new P4::ClearTypeMap(&typeMap),
8679
new P4::SimplifyControlFlow(&refMap, &typeMap),
87-
new P4::RemoveParameters(&refMap, &typeMap),
88-
new P4::ClearTypeMap(&typeMap),
80+
new P4::RemoveTableParameters(&refMap, &typeMap),
81+
new P4::RemoveActionParameters(&refMap, &typeMap),
8982
new P4::SimplifyKey(&refMap, &typeMap,
9083
new P4::NonLeftValue(&refMap, &typeMap)),
9184
new P4::RemoveExits(&refMap, &typeMap),

backends/p4test/midend.cpp

+8-15
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
#include "midend.h"
1818
#include "midend/actionsInlining.h"
1919
#include "midend/inlining.h"
20-
#include "midend/moveDeclarations.h"
21-
#include "midend/uniqueNames.h"
2220
#include "midend/removeReturns.h"
2321
#include "midend/removeParameters.h"
2422
#include "midend/moveConstructors.h"
@@ -28,19 +26,18 @@ limitations under the License.
2826
#include "midend/simplifyKey.h"
2927
#include "midend/parserUnroll.h"
3028
#include "midend/specialize.h"
31-
#include "midend/simplifyExpressions.h"
32-
#include "midend/simplifyParsers.h"
33-
#include "midend/resetHeaders.h"
3429
#include "midend/simplifySelect.h"
35-
#include "midend/simplifyDefUse.h"
30+
#include "frontends/p4/simplifyParsers.h"
3631
#include "frontends/p4/typeMap.h"
3732
#include "frontends/p4/evaluator/evaluator.h"
3833
#include "frontends/common/resolveReferences/resolveReferences.h"
3934
#include "frontends/p4/toP4/toP4.h"
4035
#include "frontends/p4/simplify.h"
4136
#include "frontends/p4/unusedDeclarations.h"
37+
#include "frontends/p4/moveDeclarations.h"
4238
#include "frontends/common/constantFolding.h"
4339
#include "frontends/p4/strengthReduction.h"
40+
#include "frontends/p4/uniqueNames.h"
4441

4542
namespace P4Test {
4643

@@ -55,14 +52,9 @@ MidEnd::MidEnd(CompilerOptions& options) {
5552
// TODO: improve copy propagation
5653
// TODO: simplify actions which are too complex
5754
// TODO: lower errors to integers
55+
// TODO: handle bit-slices as out arguments
56+
// TODO: remove control-flow from parsers
5857
addPasses({
59-
new P4::SimplifyParsers(&refMap),
60-
new P4::ResetHeaders(&refMap, &typeMap),
61-
new P4::UniqueNames(&refMap), // Give each local declaration a unique internal name
62-
new P4::MoveDeclarations(), // Move all local declarations to the beginning
63-
new P4::MoveInitializers(),
64-
new P4::SimplifyDefUse(&refMap, &typeMap),
65-
new P4::SimplifyExpressions(&refMap, &typeMap),
6658
new P4::RemoveReturns(&refMap),
6759
new P4::MoveConstructors(&refMap),
6860
new P4::RemoveAllUnusedDeclarations(&refMap),
@@ -80,11 +72,12 @@ MidEnd::MidEnd(CompilerOptions& options) {
8072
// Parser loop unrolling: TODO
8173
// new P4::ParsersUnroll(true, &refMap, &typeMap),
8274
new P4::LocalizeAllActions(&refMap),
75+
new P4::UniqueNames(&refMap),
8376
new P4::UniqueParameters(&refMap),
8477
new P4::ClearTypeMap(&typeMap), // table types have changed
8578
new P4::SimplifyControlFlow(&refMap, &typeMap),
86-
new P4::RemoveParameters(&refMap, &typeMap),
87-
new P4::ClearTypeMap(&typeMap), // table types have changed
79+
new P4::RemoveTableParameters(&refMap, &typeMap),
80+
new P4::RemoveActionParameters(&refMap, &typeMap),
8881
new P4::SimplifyKey(&refMap, &typeMap,
8982
new P4::NonLeftValue(&refMap, &typeMap)),
9083
new P4::RemoveExits(&refMap, &typeMap),

backends/p4test/run-p4-sample.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def check_generated_files(options, tmpdir, expecteddir):
161161
return SUCCESS
162162

163163
def file_name(tmpfolder, base, suffix, ext):
164-
return tmpfolder + "/" + base + suffix + ext
164+
return tmpfolder + "/" + base + "-" + suffix + ext
165165

166166
def process_file(options, argv):
167167
assert isinstance(options, Options)
@@ -179,10 +179,15 @@ def process_file(options, argv):
179179
if not os.path.exists(expected_dirname):
180180
os.makedirs(expected_dirname)
181181

182+
# We rely on the fact that these keys are in alphabetical order.
183+
rename = { "FrontEnd_11_SimplifyControlFlow": "first",
184+
"FrontEnd_20_SimplifyDefUse": "frontend",
185+
"MidEnd_27_Evaluator": "midend" }
186+
182187
if options.verbose:
183188
print("Writing temporary files into ", tmpdir)
184189
ppfile = tmpdir + "/" + basename # after parsing
185-
referenceOutputs = "FrontEnd_12_Simplify,FrontEnd_13_Remove,MidEnd_32_Evaluator"
190+
referenceOutputs = ",".join(rename.keys())
186191
stderr = tmpdir + "/" + basename + "-stderr"
187192

188193
if not os.path.isfile(options.p4filename):
@@ -207,21 +212,12 @@ def process_file(options, argv):
207212

208213
# Canonicalize the generated file names
209214
lastFile = None
210-
firstFile = file_name(tmpdir, base, "-FrontEnd_12_SimplifyControlFlow", ext)
211-
if os.path.isfile(firstFile):
212-
newName = file_name(tmpdir, base, "-first", ext)
213-
os.rename(firstFile, newName)
214-
lastFile = newName
215-
midFile = file_name(tmpdir, base, "-FrontEnd_13_RemoveAllUnusedDeclarations", ext)
216-
if os.path.isfile(midFile):
217-
newName = file_name(tmpdir, base, "-frontend", ext)
218-
os.rename(midFile, newName)
219-
lastFile = newName
220-
endFile = file_name(tmpdir, base, "-MidEnd_32_Evaluator", ext)
221-
if os.path.isfile(endFile):
222-
newName = file_name(tmpdir, base, "-midend", ext)
223-
os.rename(endFile, newName)
224-
lastFile = newName
215+
for k in sorted(rename.keys()):
216+
file = file_name(tmpdir, base, k, ext)
217+
if os.path.isfile(file):
218+
newName = file_name(tmpdir, base, rename[k], ext)
219+
os.rename(file, newName)
220+
lastFile = newName
225221

226222
if (result == SUCCESS):
227223
result = check_generated_files(options, tmpdir, expected_dirname);

frontends/Makefile.am

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ p4_frontend_SOURCES = \
1616
frontends/p4/p4-parse.ypp \
1717
frontends/p4/frontend.h \
1818
frontends/p4/frontend.cpp \
19-
frontends/p4/checkAliasing.h \
20-
frontends/p4/checkAliasing.cpp \
2119
frontends/p4/createBuiltins.h \
2220
frontends/p4/createBuiltins.cpp \
2321
frontends/p4/def_use.h \
@@ -71,7 +69,19 @@ p4_frontend_SOURCES = \
7169
frontends/p4/fromv1.0/converters.h \
7270
frontends/p4/fromv1.0/converters.cpp \
7371
frontends/p4/typeMap.h \
74-
frontends/p4/typeMap.cpp
72+
frontends/p4/typeMap.cpp \
73+
frontends/p4/simplifyDefUse.cpp \
74+
frontends/p4/simplifyDefUse.h \
75+
frontends/p4/sideEffects.cpp \
76+
frontends/p4/sideEffects.h \
77+
frontends/p4/simplifyParsers.cpp \
78+
frontends/p4/simplifyParsers.h \
79+
frontends/p4/uniqueNames.cpp \
80+
frontends/p4/uniqueNames.h \
81+
frontends/p4/resetHeaders.cpp \
82+
frontends/p4/resetHeaders.h \
83+
frontends/p4/moveDeclarations.cpp \
84+
frontends/p4/moveDeclarations.h
7585

7686
common_frontend_SOURCES = \
7787
frontends/common/options.h \

0 commit comments

Comments
 (0)