Skip to content

Commit 3a8694c

Browse files
committed
Merge remote-tracking branch 'up/main' into remove-ubuntu-20.04-from-ci
2 parents 7ba0593 + 6ad7c9a commit 3a8694c

File tree

136 files changed

+2224
-306
lines changed

Some content is hidden

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

136 files changed

+2224
-306
lines changed

.github/workflows/ci-ubuntu-18-nightly-p4tc-stf.yml .github/workflows/ci-ubuntu-p4tc-stf.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "test-p4c-ubuntu-18.04"
1+
name: "test-p4tc-ubuntu"
22

33
on:
44
schedule:
@@ -11,10 +11,10 @@ on:
1111

1212
jobs:
1313
# Run p4tc stf tests
14-
test-ubuntu18-p4tc-stf:
14+
test-ubuntu-p4tc-stf:
1515
# Only run on pull requests with the "p4tc" label.
1616
if: ${{ github.event_name == 'schedule' || contains(github.event.pull_request.labels.*.name, 'p4tc') }}
17-
runs-on: ubuntu-20.04
17+
runs-on: ubuntu-22.04
1818
env:
1919
CTEST_PARALLEL_LEVEL: 4
2020
IMAGE_TYPE: test
@@ -33,11 +33,11 @@ jobs:
3333
key: test-${{ matrix.unity }}-${{ runner.os }}-gcc
3434
max-size: 1000M
3535

36-
- name: Build (Ubuntu 20.04, GCC)
36+
- name: Build (Ubuntu 22.04, GCC)
3737
run: |
3838
tools/ci-build.sh
3939
40-
- name: Run tests (Ubuntu 20.04)
40+
- name: Run tests (Ubuntu 22.04)
4141
# Need to use sudo for the eBPF kernel tests.
4242
run: sudo -E ctest --output-on-failure --schedule-random -R "p4tc_samples_stf|p4tc_cleanup|p4tc_setup"
4343
working-directory: ./build

backends/bmv2/pna_nic/midend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ PnaNicMidEnd::PnaNicMidEnd(CompilerOptions &options, std::ostream *outStream)
147147
new P4::ValidateTableProperties({"pna_implementation"_cs, "pna_direct_counter"_cs,
148148
"pna_direct_meter"_cs, "pna_idle_timeout"_cs,
149149
"size"_cs}),
150-
new P4::SimplifyControlFlow(&typeMap),
150+
new P4::SimplifyControlFlow(&typeMap, true),
151151
new P4::CompileTimeOperations(),
152152
new P4::TableHit(&typeMap),
153153
new P4::EliminateSwitch(&typeMap),

backends/bmv2/pna_nic/pnaNic.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ void PnaNicBackend::convert(const IR::ToplevelBlock *tlb) {
8686
new SkipControls(&structure.non_pipeline_controls)),
8787
new P4::MoveActionsToTables(refMap, typeMap),
8888
new P4::TypeChecking(refMap, typeMap),
89-
new P4::SimplifyControlFlow(typeMap),
89+
new P4::SimplifyControlFlow(typeMap, true),
9090
new LowerExpressions(typeMap),
9191
new PassRepeated({new P4::ConstantFolding(typeMap), new P4::StrengthReduction(typeMap)}),
9292
new P4::TypeChecking(refMap, typeMap),
9393
new P4::RemoveComplexExpressions(typeMap,
9494
new ProcessControls(&structure.pipeline_controls)),
95-
new P4::SimplifyControlFlow(typeMap),
95+
new P4::SimplifyControlFlow(typeMap, true),
9696
new P4::RemoveAllUnusedDeclarations(P4::RemoveUnusedPolicy()),
9797
// Converts the DAG into a TREE (at least for expressions)
9898
// This is important later for conversion to JSON.

backends/bmv2/psa_switch/midend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ PsaSwitchMidEnd::PsaSwitchMidEnd(CompilerOptions &options, std::ostream *outStre
155155
"psa_idle_timeout"_cs,
156156
"size"_cs,
157157
}),
158-
new P4::SimplifyControlFlow(&typeMap),
158+
new P4::SimplifyControlFlow(&typeMap, true),
159159
new P4::CompileTimeOperations(),
160160
new P4::TableHit(&typeMap),
161161
new P4::EliminateSwitch(&typeMap),

backends/bmv2/psa_switch/psaSwitch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void PsaSwitchBackend::convert(const IR::ToplevelBlock *tlb) {
100100
new SkipControls(&structure.non_pipeline_controls)),
101101
new P4::MoveActionsToTables(refMap, typeMap),
102102
new P4::TypeChecking(refMap, typeMap),
103-
new P4::SimplifyControlFlow(typeMap),
103+
new P4::SimplifyControlFlow(typeMap, true),
104104
new LowerExpressions(typeMap),
105105
new PassRepeated({
106106
new P4::ConstantFolding(typeMap),
@@ -109,7 +109,7 @@ void PsaSwitchBackend::convert(const IR::ToplevelBlock *tlb) {
109109
new P4::TypeChecking(refMap, typeMap),
110110
new P4::RemoveComplexExpressions(typeMap,
111111
new ProcessControls(&structure.pipeline_controls)),
112-
new P4::SimplifyControlFlow(typeMap),
112+
new P4::SimplifyControlFlow(typeMap, true),
113113
new P4::RemoveAllUnusedDeclarations(P4::RemoveUnusedPolicy()),
114114
// Converts the DAG into a TREE (at least for expressions)
115115
// This is important later for conversion to JSON.

backends/bmv2/simple_switch/midend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ SimpleSwitchMidEnd::SimpleSwitchMidEnd(CompilerOptions &options, std::ostream *o
121121
"meters"_cs,
122122
"support_timeout"_cs,
123123
}),
124-
new P4::SimplifyControlFlow(&typeMap),
124+
new P4::SimplifyControlFlow(&typeMap, true),
125125
new P4::EliminateTypedef(&typeMap),
126126
new P4::CompileTimeOperations(),
127127
new P4::TableHit(&typeMap),

backends/bmv2/simple_switch/simpleSwitch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1176,12 +1176,12 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) {
11761176
new SkipControls(&structure->non_pipeline_controls)),
11771177
new P4::MoveActionsToTables(refMap, typeMap),
11781178
new P4::TypeChecking(nullptr, typeMap),
1179-
new P4::SimplifyControlFlow(typeMap),
1179+
new P4::SimplifyControlFlow(typeMap, true),
11801180
new LowerExpressions(typeMap),
11811181
new P4::ConstantFolding(typeMap, false),
11821182
new P4::TypeChecking(nullptr, typeMap),
11831183
new RemoveComplexExpressions(typeMap, new ProcessControls(&structure->pipeline_controls)),
1184-
new P4::SimplifyControlFlow(typeMap),
1184+
new P4::SimplifyControlFlow(typeMap, true),
11851185
new P4::RemoveAllUnusedDeclarations(P4::RemoveUnusedPolicy()),
11861186
new P4::FlattenLogMsg(typeMap),
11871187
// Converts the DAG into a TREE (at least for expressions)

backends/dpdk/midend.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options, std::ostream *outStream) {
204204
new P4::HSIndexSimplifier(&typeMap),
205205
new P4::ParsersUnroll(true, &refMap, &typeMap),
206206
new P4::FlattenHeaderUnion(&refMap, &typeMap),
207-
new P4::SimplifyControlFlow(&typeMap),
207+
new P4::SimplifyControlFlow(&typeMap, true),
208208
new P4::ReplaceSelectRange(),
209209
new P4::MoveDeclarations(), // more may have been introduced
210210
new P4::ConstantFolding(&typeMap),
@@ -215,7 +215,7 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options, std::ostream *outStream) {
215215
}),
216216
new P4::MoveDeclarations(),
217217
validateTableProperties(options.arch),
218-
new P4::SimplifyControlFlow(&typeMap),
218+
new P4::SimplifyControlFlow(&typeMap, true),
219219
new P4::SimplifySwitch(&typeMap),
220220
new P4::CompileTimeOperations(),
221221
new P4::TableHit(&typeMap),

backends/ebpf/midend.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program *
8484
new P4::RemoveMiss(&typeMap),
8585
new P4::EliminateInvalidHeaders(&typeMap),
8686
new P4::EliminateNewtype(&typeMap),
87-
new P4::SimplifyControlFlow(&typeMap),
87+
new P4::SimplifyControlFlow(&typeMap, true),
8888
new P4::SimplifyKey(
8989
&typeMap, new P4::OrPolicy(new P4::IsValid(&typeMap), new P4::IsLikeLeftValue())),
9090
new P4::RemoveExits(&typeMap),
@@ -104,7 +104,7 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program *
104104
new P4::RemoveSelectBooleans(&typeMap),
105105
new P4::SingleArgumentSelect(&typeMap),
106106
new P4::ConstantFolding(&typeMap),
107-
new P4::SimplifyControlFlow(&typeMap),
107+
new P4::SimplifyControlFlow(&typeMap, true),
108108
new P4::TableHit(&typeMap),
109109
new P4::RemoveLeftSlices(&typeMap),
110110
new EBPF::Lower(&refMap, &typeMap),

backends/p4test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set (P4TEST_SRCS
2222
midend.cpp
2323
)
2424
set (P4TEST_HDRS
25+
p4test.h
2526
midend.h
2627
)
2728

backends/p4test/midend.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ limitations under the License.
3333
#include "midend/complexComparison.h"
3434
#include "midend/copyStructures.h"
3535
#include "midend/def_use.h"
36+
#include "midend/eliminateActionRun.h"
3637
#include "midend/eliminateInvalidHeaders.h"
3738
#include "midend/eliminateNewtype.h"
3839
#include "midend/eliminateSerEnums.h"
@@ -76,7 +77,7 @@ class SkipControls : public P4::ActionSynthesisPolicy {
7677
}
7778
};
7879

79-
MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) {
80+
MidEnd::MidEnd(P4TestOptions &options, std::ostream *outStream) {
8081
bool isv1 = options.langVersion == CompilerOptions::FrontendVersion::P4_14;
8182
refMap.setIsV1(isv1);
8283
auto evaluator = new P4::EvaluatorPass(&refMap, &typeMap);
@@ -122,10 +123,11 @@ MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) {
122123
}),
123124
new P4::StrengthReduction(&typeMap),
124125
new P4::MoveDeclarations(), // more may have been introduced
125-
new P4::SimplifyControlFlow(&typeMap),
126+
new P4::SimplifyControlFlow(&typeMap, true),
126127
new P4::CompileTimeOperations(),
127128
new P4::TableHit(&typeMap),
128-
new P4::EliminateSwitch(&typeMap),
129+
!options.preferSwitch ? new P4::EliminateSwitch(&typeMap) : nullptr,
130+
options.preferSwitch ? new P4::ElimActionRun() : nullptr,
129131
new P4::ResolveReferences(&refMap),
130132
new P4::TypeChecking(&refMap, &typeMap, true), // update types before ComputeDefUse
131133
new PassRepeated({
@@ -167,7 +169,7 @@ MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) {
167169
evaluator,
168170
[this, evaluator]() { toplevel = evaluator->getToplevelBlock(); },
169171
new P4::FlattenHeaderUnion(&refMap, &typeMap, options.loopsUnrolling),
170-
new P4::SimplifyControlFlow(&typeMap),
172+
new P4::SimplifyControlFlow(&typeMap, true),
171173
new P4::MidEndLast()});
172174
if (options.listMidendPasses) {
173175
listPasses(*outStream, cstring::newline);

backends/p4test/midend.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
#include "frontends/common/options.h"
2121
#include "frontends/p4/evaluator/evaluator.h"
2222
#include "ir/ir.h"
23+
#include "p4test.h"
2324

2425
namespace P4::P4Test {
2526

@@ -32,7 +33,7 @@ class MidEnd : public PassManager {
3233
IR::ToplevelBlock *toplevel = nullptr;
3334

3435
void addDebugHook(DebugHook hook) { hooks.push_back(hook); }
35-
explicit MidEnd(CompilerOptions &options, std::ostream *outStream = nullptr);
36+
explicit MidEnd(P4TestOptions &options, std::ostream *outStream = nullptr);
3637
IR::ToplevelBlock *process(const IR::P4Program *&program) {
3738
addDebugHooks(hooks, true);
3839
program = program->apply(*this);

backends/p4test/p4test.cpp

+52-51
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
#include "p4test.h"
18+
1719
#include <fstream> // IWYU pragma: keep
1820
#include <iostream>
1921

@@ -35,57 +37,56 @@ limitations under the License.
3537
#include "lib/nullstream.h"
3638
#include "midend.h"
3739

38-
using namespace P4;
39-
40-
class P4TestOptions : public CompilerOptions {
41-
public:
42-
bool parseOnly = false;
43-
bool validateOnly = false;
44-
bool loadIRFromJson = false;
45-
P4TestOptions() {
46-
registerOption(
47-
"--listMidendPasses", nullptr,
48-
[this](const char *) {
49-
listMidendPasses = true;
50-
loadIRFromJson = false;
51-
P4Test::MidEnd MidEnd(*this, outStream);
52-
exit(0);
53-
return false;
54-
},
55-
"[p4test] Lists exact name of all midend passes.\n");
56-
registerOption(
57-
"--parse-only", nullptr,
58-
[this](const char *) {
59-
parseOnly = true;
60-
return true;
61-
},
62-
"only parse the P4 input, without any further processing");
63-
registerOption(
64-
"--validate", nullptr,
65-
[this](const char *) {
66-
validateOnly = true;
67-
return true;
68-
},
69-
"Validate the P4 input, running just the front-end");
70-
registerOption(
71-
"--fromJSON", "file",
72-
[this](const char *arg) {
73-
loadIRFromJson = true;
74-
file = arg;
75-
return true;
76-
},
77-
"read previously dumped json instead of P4 source code");
78-
registerOption(
79-
"--turn-off-logn", nullptr,
80-
[](const char *) {
81-
::P4::Log::Detail::enableLoggingGlobally = false;
82-
return true;
83-
},
84-
"Turn off LOGN() statements in the compiler.\n"
85-
"Use '@__debug' annotation to enable LOGN on "
86-
"the annotated P4 object within the source code.\n");
87-
}
88-
};
40+
P4TestOptions::P4TestOptions() {
41+
registerOption(
42+
"--listMidendPasses", nullptr,
43+
[this](const char *) {
44+
listMidendPasses = true;
45+
loadIRFromJson = false;
46+
P4Test::MidEnd MidEnd(*this, outStream);
47+
exit(0);
48+
return false;
49+
},
50+
"[p4test] Lists exact name of all midend passes.\n");
51+
registerOption(
52+
"--parse-only", nullptr,
53+
[this](const char *) {
54+
parseOnly = true;
55+
return true;
56+
},
57+
"only parse the P4 input, without any further processing");
58+
registerOption(
59+
"--validate", nullptr,
60+
[this](const char *) {
61+
validateOnly = true;
62+
return true;
63+
},
64+
"Validate the P4 input, running just the front-end");
65+
registerOption(
66+
"--fromJSON", "file",
67+
[this](const char *arg) {
68+
loadIRFromJson = true;
69+
file = arg;
70+
return true;
71+
},
72+
"read previously dumped json instead of P4 source code");
73+
registerOption(
74+
"--turn-off-logn", nullptr,
75+
[](const char *) {
76+
::P4::Log::Detail::enableLoggingGlobally = false;
77+
return true;
78+
},
79+
"Turn off LOGN() statements in the compiler.\n"
80+
"Use '@__debug' annotation to enable LOGN on "
81+
"the annotated P4 object within the source code.\n");
82+
registerOption(
83+
"--preferSwitch", nullptr,
84+
[this](const char *) {
85+
preferSwitch = true;
86+
return true;
87+
},
88+
"use passes that use general switch instead of action_run");
89+
}
8990

9091
class P4TestPragmas : public P4::P4COptionPragmaParser {
9192
std::optional<IOptionPragmaParser::CommandLineOptions> tryToParse(

backends/p4test/p4test.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2013-present Barefoot Networks, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef BACKENDS_P4TEST_P4TEST_H_
18+
#define BACKENDS_P4TEST_P4TEST_H_
19+
20+
#include "frontends/common/options.h"
21+
22+
using namespace P4;
23+
24+
class P4TestOptions : public CompilerOptions {
25+
public:
26+
bool parseOnly = false;
27+
bool validateOnly = false;
28+
bool loadIRFromJson = false;
29+
bool preferSwitch = false;
30+
P4TestOptions();
31+
};
32+
33+
#endif /* BACKENDS_P4TEST_P4TEST_H_ */

backends/p4tools/common/compiler/midend.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void MidEnd::addDefaultPasses() {
108108
mkConvertKeys(),
109109
mkConvertEnums(),
110110
new P4::ConstantFolding(&typeMap),
111-
new P4::SimplifyControlFlow(&typeMap),
111+
new P4::SimplifyControlFlow(&typeMap, true),
112112
// Eliminate extraneous cases in select statements.
113113
new P4::SimplifySelectCases(&typeMap, false),
114114
// Expand lookahead assignments into sequences of field assignments.
@@ -145,7 +145,7 @@ void MidEnd::addDefaultPasses() {
145145
}),
146146
new P4::ConstantFolding(&typeMap),
147147
new P4::MoveDeclarations(),
148-
new P4::SimplifyControlFlow(&typeMap),
148+
new P4::SimplifyControlFlow(&typeMap, true),
149149
// Replace any slices in the left side of assignments and convert them to casts.
150150
new P4::RemoveLeftSlices(&typeMap),
151151
// Remove loops from parsers by unrolling them as far as the stack indices allow.
@@ -155,7 +155,7 @@ void MidEnd::addDefaultPasses() {
155155
// Convert tuples into structs.
156156
new P4::EliminateTuples(&typeMap),
157157
new P4::ConstantFolding(&typeMap),
158-
new P4::SimplifyControlFlow(&typeMap),
158+
new P4::SimplifyControlFlow(&typeMap, true),
159159
// Perform a last round of type-checking before passes which do not type-check begin.
160160
new P4::TypeChecking(&refMap, &typeMap, true),
161161
});

0 commit comments

Comments
 (0)