Skip to content

Commit 85a7001

Browse files
author
mbudiu-vmw
committed
Two more passes: simplify expressions and move initializers; parserUnroll still commented-out
2 parents ee7b788 + ead3ed3 commit 85a7001

File tree

815 files changed

+4887
-7406
lines changed

Some content is hidden

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

815 files changed

+4887
-7406
lines changed

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $(srcdir)/otherMakefiles.am: $(srcdir)/backends $(srcdir)/extensions $(wildcard
5757
# make is very stupid regarding multiple files generated from the same source
5858
# this pattern ensures that parallel builds continue to work
5959
ir/ir-generated.h: irgenerator $(ir_DEF_FILES)
60-
./irgenerator -t ir/gen-tree-macro.h -i ir/ir-generated.cpp $(ir_DEF_FILES) >$@
60+
./irgenerator -t ir/gen-tree-macro.h -i ir/ir-generated.cpp $(ir_DEF_FILES) >$@ || ( rm $@ && false )
6161
@$(srcdir)/tools/fixup-line-directives $@ >$@.tmp
6262
@mv $@.tmp $@
6363
ir/gen-tree-macro.h: ir/ir-generated.h

backends/bmv2/inlining.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const IR::Node* SimpleControlsInliner::preorder(IR::P4Control* caller) {
3737
workToDo = &toInline->callerToWork[orig];
3838
LOG1("Simple inliner " << caller);
3939
auto stateful = new IR::IndexedVector<IR::Declaration>();
40-
for (auto s : *caller->stateful) {
40+
for (auto s : *caller->controlLocals) {
4141
auto inst = s->to<IR::Declaration_Instance>();
4242
if (inst == nullptr ||
4343
workToDo->declToCallee.find(inst) == workToDo->declToCallee.end()) {
@@ -63,7 +63,7 @@ const IR::Node* SimpleControlsInliner::preorder(IR::P4Control* caller) {
6363
auto clone = callee->getNode()->apply(sp);
6464
if (clone == nullptr)
6565
return caller;
66-
for (auto i : *clone->to<IR::P4Control>()->stateful) {
66+
for (auto i : *clone->to<IR::P4Control>()->controlLocals) {
6767
if (stateful->getDeclaration(i->name) == nullptr)
6868
stateful->push_back(i);
6969
}

backends/bmv2/jsonconverter.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,12 @@ cstring JsonConverter::convertHashAlgorithm(cstring algorithm) const {
999999
cstring result;
10001000
if (algorithm == v1model.algorithm.crc32.name)
10011001
result = "crc32";
1002+
else if (algorithm == v1model.algorithm.crc32_custom.name)
1003+
result = "crc32_custom";
10021004
else if (algorithm == v1model.algorithm.crc16.name)
10031005
result = "crc16";
1006+
else if (algorithm == v1model.algorithm.crc16_custom.name)
1007+
result = "crc16_custom";
10041008
else if (algorithm == v1model.algorithm.random.name)
10051009
result = "random";
10061010
else if (algorithm == v1model.algorithm.identity.name)
@@ -1348,7 +1352,7 @@ Util::IJson* JsonConverter::convertControl(const IR::ControlBlock* block, cstrin
13481352
tables->append(exitTable);
13491353
}
13501354

1351-
for (auto c : *cont->stateful) {
1355+
for (auto c : *cont->controlLocals) {
13521356
if (c->is<IR::Declaration_Constant>() ||
13531357
c->is<IR::Declaration_Variable>() ||
13541358
c->is<IR::P4Action>() ||
@@ -1875,8 +1879,8 @@ Util::IJson* JsonConverter::convertDeparser(const IR::P4Control* ctrl) {
18751879

18761880
Util::IJson* JsonConverter::toJson(const IR::P4Parser* parser) {
18771881
auto result = new Util::JsonObject();
1878-
if (parser->stateful->size() != 0) {
1879-
::error("%1%: Stateful elements not yet supported in parser for this target", parser);
1882+
if (parser->parserLocals->size() != 0) {
1883+
::error("%1%: locals not yet supported in parser for this target", parser);
18801884
return result;
18811885
}
18821886
result->emplace("name", "parser"); // at least in simple_router this name is hardwired

backends/bmv2/midend.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ limitations under the License.
2929
#include "midend/removeLeftSlices.h"
3030
#include "midend/convertEnums.h"
3131
#include "midend/simplifyKey.h"
32+
#include "midend/simplifyExpressions.h"
3233
#include "frontends/p4/strengthReduction.h"
3334
#include "frontends/p4/typeMap.h"
3435
#include "frontends/p4/evaluator/evaluator.h"
@@ -96,6 +97,9 @@ void MidEnd::setup_for_P4_16(CompilerOptions& options) {
9697
new P4::UniqueNames(&refMap, isv1),
9798
// Move all local declarations to the beginning
9899
new P4::MoveDeclarations(),
100+
new P4::MoveInitializers(),
101+
new P4::TypeChecking(&refMap, &typeMap, false, isv1),
102+
new P4::SimplifyExpressions(&refMap, &typeMap),
99103
new P4::ResolveReferences(&refMap, isv1),
100104
new P4::RemoveReturns(&refMap),
101105
// Move some constructor calls into temporaries

backends/bmv2/run-bmv2-test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def main(argv):
717717
else:
718718
options.compilerOptions += argv[1].split();
719719
argv = argv[1:]
720-
elif argv[0][1] == 'T':
720+
elif argv[0][1] == 'D' or argv[0][1] == 'I' or argv[0][1] == 'T':
721721
options.compilerOptions.append(argv[0]);
722722
else:
723723
reportError("Uknown option ", argv[0])

backends/ebpf/ebpfControl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void EBPFControl::emitDeclaration(const IR::Declaration* decl, CodeBuilder* buil
295295
}
296296

297297
void EBPFControl::emit(CodeBuilder* builder) {
298-
for (auto a : *controlBlock->container->stateful)
298+
for (auto a : *controlBlock->container->controlLocals)
299299
emitDeclaration(a, builder);
300300
builder->emitIndent();
301301
ControlBodyTranslationVisitor psi(this, builder);

backends/ebpf/midend.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ limitations under the License.
2525
#include "midend/localizeActions.h"
2626
#include "midend/removeParameters.h"
2727
#include "midend/local_copyprop.h"
28+
#include "midend/simplifyExpressions.h"
2829
#include "frontends/p4/typeMap.h"
2930
#include "frontends/p4/evaluator/evaluator.h"
3031
#include "frontends/p4/typeChecking/typeChecker.h"
@@ -53,6 +54,9 @@ const IR::ToplevelBlock* MidEnd::run(EbpfOptions& options, const IR::P4Program*
5354
new P4::UniqueNames(&refMap, isv1),
5455
// Move all local declarations to the beginning
5556
new P4::MoveDeclarations(),
57+
new P4::MoveInitializers(),
58+
new P4::TypeChecking(&refMap, &typeMap, false, isv1),
59+
new P4::SimplifyExpressions(&refMap, &typeMap),
5660
new P4::ResolveReferences(&refMap, isv1),
5761
new P4::RemoveReturns(&refMap), // necessary for inlining
5862
// Move some constructor calls into temporaries

backends/p4test/midend.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ limitations under the License.
2828
#include "midend/simplifyKey.h"
2929
#include "midend/parserUnroll.h"
3030
#include "midend/specialize.h"
31+
#include "midend/simplifyExpressions.h"
3132
#include "frontends/p4/typeMap.h"
3233
#include "frontends/p4/evaluator/evaluator.h"
3334
#include "frontends/p4/typeChecking/typeChecker.h"
@@ -45,7 +46,6 @@ MidEnd::MidEnd(CompilerOptions& options) {
4546
auto evaluator = new P4::Evaluator(&refMap, &typeMap);
4647
setName("MidEnd");
4748

48-
// TODO: break down expression into simple parts
4949
// TODO: def-use analysis
5050
// TODO: parser inlining
5151
// TODO: parser loop unrolling
@@ -61,6 +61,9 @@ MidEnd::MidEnd(CompilerOptions& options) {
6161
// Move all local declarations to the beginning
6262
new P4::MoveDeclarations(),
6363
new P4::MoveInitializers(),
64+
// Simplify expressions
65+
new P4::TypeChecking(&refMap, &typeMap, false, isv1),
66+
new P4::SimplifyExpressions(&refMap, &typeMap),
6467
new P4::ResolveReferences(&refMap, isv1),
6568
new P4::RemoveReturns(&refMap),
6669
// Move some constructor calls into temporaries
@@ -87,10 +90,8 @@ MidEnd::MidEnd(CompilerOptions& options) {
8790
new P4::RemoveAllUnusedDeclarations(&refMap, isv1),
8891
new P4::SpecializeAll(&refMap, &typeMap, isv1),
8992
new P4::RemoveAllUnusedDeclarations(&refMap, isv1),
90-
// TODO: simplify statements and expressions.
91-
// This is required for the correctness of some of the following passes.
92-
// Parser loop unrolling
93-
new P4::ParserUnroll(true, &refMap, &typeMap, isv1),
93+
// Parser loop unrolling: TODO
94+
// new P4::ParsersUnroll(true, &refMap, &typeMap, isv1),
9495
// Clone an action for each use, so we can specialize the action
9596
// per user (e.g., for each table or direct invocation).
9697
new P4::LocalizeAllActions(&refMap, isv1),

backends/p4test/run-p4-sample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def process_file(options, argv):
182182
if options.verbose:
183183
print("Writing temporary files into ", tmpdir)
184184
ppfile = tmpdir + "/" + basename # after parsing
185-
referenceOutputs = "FrontEnd_13,FrontEnd_14,MidEnd_43_Evaluator"
185+
referenceOutputs = "FrontEnd_13,FrontEnd_14,MidEnd_45_Evaluator"
186186
stderr = tmpdir + "/" + basename + "-stderr"
187187

188188
if not os.path.isfile(options.p4filename):
@@ -217,7 +217,7 @@ def process_file(options, argv):
217217
newName = file_name(tmpdir, base, "-frontend", ext)
218218
os.rename(midFile, newName)
219219
lastFile = newName
220-
endFile = file_name(tmpdir, base, "-MidEnd_43_Evaluator", ext)
220+
endFile = file_name(tmpdir, base, "-MidEnd_45_Evaluator", ext)
221221
if os.path.isfile(endFile):
222222
newName = file_name(tmpdir, base, "-midend", ext)
223223
os.rename(endFile, newName)

configure.ac

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ AC_LANG(C++)
1818

1919
AC_CHECK_FUNCS([clock_gettime])
2020
AC_CHECK_FUNCS([memchr])
21+
AC_CHECK_FUNCS([memrchr])
2122
AC_CHECK_FUNCS([memset])
23+
AC_CHECK_FUNCS([pipe2])
2224
AC_CHECK_FUNCS([select])
2325
AC_CHECK_FUNCS([strchr])
2426
AC_CHECK_FUNCS([strcspn])
@@ -79,7 +81,7 @@ AX_PYTHON_MODULE([re], [fatal], [python])
7981
dnl The following lines are just including all "addconfig.ac" files
8082
dnl found in subdirectories
8183

82-
m4_foreach_w([ac_file],m4_esyscmd([find -name addconfig.ac]),
84+
m4_foreach_w([ac_file],m4_esyscmd([find . -name addconfig.ac]),
8385
[[#]] config from ac_file
8486
[sinclude(]ac_file[)]
8587
[[#]] end of ac_file

docs/README.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,28 @@ Most dependences can be installed using `apt-get install`:
7272

7373
## OS X dependences
7474

75-
Installing dependences on OS X:
75+
Installing on OS X:
7676

77-
- You may need to install brew for useful utilities:
78-
`sudo /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
77+
- Enable XCode's command-line tools:
78+
```
79+
xcode-select --install
80+
```
7981

80-
- `sudo brew install autoconf automake libtool boost`
82+
- Install Homebrew:
83+
```
84+
sudo /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
85+
```
86+
Be sure to add `/usr/local/bin/` to your `$PATH`.
8187

82-
- You can recompile the C++ garbage-collector from sources from `https://github.com/ivmai/bdwgc.git`
88+
- Install dependencies using Homebrew:
89+
```
90+
brew install autoconf automake libtool boost bison pkg-config
91+
```
8392

84-
- You can recompile GMP from sources `https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2` (you will need
85-
to `configure --enable-cxx`)
93+
- Build the C++ garbage-collector (BDW-GC) from `https://github.com/ivmai/bdwgc.git`. Follow the build instructions in the [README](https://github.com/ivmai/bdwgc/blob/master/README.md) file; you will need to `configure --enable-cplus-plus`.
94+
95+
- Build the GNU Multi Precision Arithmetic Library (GMP) from `https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2`.
96+
Follow the instructions in the `INSTALL` file; you will need to `configure --enable-cxx`.
8697

8798
# Development tools
8899

0 commit comments

Comments
 (0)