Skip to content

Commit b88b850

Browse files
mbudiu-vmwChrisDodd
mbudiu-vmw
authored andcommitted
Fixes for issues #355, #356; removed table parameters from the language and the associated tests
1 parent b21247a commit b88b850

File tree

1,053 files changed

+7699
-8544
lines changed

Some content is hidden

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

1,053 files changed

+7699
-8544
lines changed

backends/bmv2/jsonconverter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ class ExpressionConverter : public Inspector {
370370
BUG("%1%: unhandled case", expression);
371371
}
372372

373+
#if 0
373374
void postorder(const IR::Shr* expression) override {
374375
// special handling for shift of a lookahead
375376
auto l = get(expression->left);
@@ -403,13 +404,15 @@ class ExpressionConverter : public Inspector {
403404
}
404405
binary(expression);
405406
}
407+
#endif
406408

407409
void postorder(const IR::Cast* expression) override {
408410
// nothing to do for casts - the ArithmeticFixup pass should have handled them already
409411
auto j = get(expression->expr);
410412
map.emplace(expression, j);
411413
}
412414

415+
#if 0
413416
void postorder(const IR::Slice* expression) override {
414417
// Special case for parser select: look for
415418
// packet.lookahead<T>()[h:l]. Convert to lookahead(l, h - l).
@@ -433,6 +436,7 @@ class ExpressionConverter : public Inspector {
433436
}
434437
BUG("%1%: unhandled case", expression);
435438
}
439+
#endif
436440

437441
void postorder(const IR::Constant* expression) override {
438442
auto result = new Util::JsonObject();

backends/bmv2/midend.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ limitations under the License.
5050
#include "midend/compileTimeOps.h"
5151
#include "midend/predication.h"
5252
#include "midend/expandLookahead.h"
53+
#include "midend/tableHit.h"
5354

5455
namespace BMV2 {
5556

5657
#if 0
58+
// This code is now obsolete, it probably should be removed
5759
void MidEnd::setup_for_P4_14(CompilerOptions&) {
5860
auto evaluator = new P4::EvaluatorPass(&refMap, &typeMap);
5961
// Inlining is simpler for P4 v1.0/1.1 programs, so we have a
@@ -143,10 +145,9 @@ MidEnd::MidEnd(CompilerOptions& options) {
143145
new P4::Inline(&refMap, &typeMap, evaluator),
144146
new P4::InlineActions(&refMap, &typeMap),
145147
new P4::LocalizeAllActions(&refMap),
146-
new P4::UniqueNames(&refMap),
148+
new P4::UniqueNames(&refMap), // needed again after inlining
147149
new P4::UniqueParameters(&refMap, &typeMap),
148150
new P4::SimplifyControlFlow(&refMap, &typeMap),
149-
new P4::RemoveTableParameters(&refMap, &typeMap),
150151
new P4::RemoveActionParameters(&refMap, &typeMap),
151152
new P4::SimplifyKey(&refMap, &typeMap,
152153
new P4::NonLeftValue(&refMap, &typeMap)),
@@ -169,6 +170,7 @@ MidEnd::MidEnd(CompilerOptions& options) {
169170
"meters", "size", "support_timeout" }),
170171
new P4::SimplifyControlFlow(&refMap, &typeMap),
171172
new P4::CompileTimeOperations(),
173+
new P4::TableHit(&refMap, &typeMap),
172174
new P4::SynthesizeActions(&refMap, &typeMap, new SkipControls(v1controls)),
173175
new P4::MoveActionsToTables(&refMap, &typeMap),
174176
// Proper back-end

backends/ebpf/midend.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ const IR::ToplevelBlock* MidEnd::run(EbpfOptions& options, const IR::P4Program*
9595
new P4::Inline(&refMap, &typeMap, evaluator),
9696
new P4::InlineActions(&refMap, &typeMap),
9797
new P4::LocalizeAllActions(&refMap),
98-
new P4::UniqueNames(&refMap),
98+
new P4::UniqueNames(&refMap), // needed again after inlining
9999
new P4::UniqueParameters(&refMap, &typeMap),
100100
new P4::ClearTypeMap(&typeMap),
101101
new P4::SimplifyControlFlow(&refMap, &typeMap),
102-
new P4::RemoveTableParameters(&refMap, &typeMap),
103102
new P4::RemoveActionParameters(&refMap, &typeMap),
104103
new P4::SimplifyKey(&refMap, &typeMap,
105104
new P4::NonLeftValue(&refMap, &typeMap)),

backends/p4test/midend.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ MidEnd::MidEnd(CompilerOptions& options) {
111111
new P4::UniqueNames(&refMap),
112112
new P4::UniqueParameters(&refMap, &typeMap),
113113
new P4::SimplifyControlFlow(&refMap, &typeMap),
114-
new P4::RemoveTableParameters(&refMap, &typeMap),
115114
new P4::RemoveActionParameters(&refMap, &typeMap),
116115
new P4::SimplifyKey(&refMap, &typeMap,
117116
new P4::NonLeftValue(&refMap, &typeMap)),

backends/p4test/run-p4-sample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def process_file(options, argv):
169169

170170
# We rely on the fact that these keys are in alphabetical order.
171171
rename = { "FrontEnd_11_SimplifyControlFlow": "first",
172-
"FrontEnd_26_FrontEndLast": "frontend",
172+
"FrontEnd_28_FrontEndLast": "frontend",
173173
"MidEnd_35_Evaluator": "midend" }
174174

175175
if options.verbose:

frontends/common/resolveReferences/resolveReferences.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,9 @@ void ResolveReferences::postorder(const IR::Function* function) {
334334

335335
bool ResolveReferences::preorder(const IR::P4Table* t) {
336336
refMap->usedName(t->name.name);
337-
addToContext(t->parameters);
338337
return true;
339338
}
340339

341-
void ResolveReferences::postorder(const IR::P4Table* t) {
342-
removeFromContext(t->parameters);
343-
}
344-
345340
bool ResolveReferences::preorder(const IR::TableProperties *p) {
346341
addToContext(p);
347342
return true;

frontends/common/resolveReferences/resolveReferences.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class ResolveReferences : public Inspector {
113113
DECLARE(P4Action)
114114
DECLARE(Function)
115115
DECLARE(TableProperties)
116-
DECLARE(P4Table)
117116
DECLARE(Type_Method)
118117
DECLARE(ParserState)
119118
DECLARE(Type_Extern)
@@ -124,6 +123,7 @@ class ResolveReferences : public Inspector {
124123
DECLARE(Property)
125124
#undef DECLARE
126125

126+
bool preorder(const IR::P4Table* table) override;
127127
bool preorder(const IR::Declaration_MatchKind* d) override;
128128
bool preorder(const IR::Declaration* d) override
129129
{ refMap->usedName(d->getName().name); return true; }

frontends/p4/def_use.cpp

+25-21
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,22 @@ void ComputeWriteSet::enterScope(const IR::ParameterList* parameters,
357357
auto startPoints = new ProgramPoints(entryPoint);
358358
auto uninit = new ProgramPoints(ProgramPoint::beforeStart);
359359

360-
for (auto p : *parameters->parameters) {
361-
StorageLocation* loc = definitions->storageMap->getOrAdd(p);
362-
if (loc == nullptr)
363-
continue;
364-
if (p->direction == IR::Direction::In ||
365-
p->direction == IR::Direction::InOut ||
366-
p->direction == IR::Direction::None)
367-
defs->set(loc, startPoints);
368-
else if (p->direction == IR::Direction::Out)
369-
defs->set(loc, uninit);
370-
auto valid = loc->getValidBits();
371-
defs->set(valid, startPoints);
372-
auto lastIndex = loc->getLastIndexField();
373-
defs->set(lastIndex, startPoints);
360+
if (parameters != nullptr) {
361+
for (auto p : *parameters->parameters) {
362+
StorageLocation* loc = definitions->storageMap->getOrAdd(p);
363+
if (loc == nullptr)
364+
continue;
365+
if (p->direction == IR::Direction::In ||
366+
p->direction == IR::Direction::InOut ||
367+
p->direction == IR::Direction::None)
368+
defs->set(loc, startPoints);
369+
else if (p->direction == IR::Direction::Out)
370+
defs->set(loc, uninit);
371+
auto valid = loc->getValidBits();
372+
defs->set(valid, startPoints);
373+
auto lastIndex = loc->getLastIndexField();
374+
defs->set(lastIndex, startPoints);
375+
}
374376
}
375377
if (locals != nullptr) {
376378
for (auto d : *locals) {
@@ -394,11 +396,13 @@ void ComputeWriteSet::enterScope(const IR::ParameterList* parameters,
394396
void ComputeWriteSet::exitScope(const IR::ParameterList* parameters,
395397
const IR::IndexedVector<IR::Declaration>* locals) {
396398
currentDefinitions = currentDefinitions->clone();
397-
for (auto p : *parameters->parameters) {
398-
StorageLocation* loc = definitions->storageMap->getStorage(p);
399-
if (loc == nullptr)
400-
continue;
401-
currentDefinitions->remove(loc);
399+
if (parameters != nullptr) {
400+
for (auto p : *parameters->parameters) {
401+
StorageLocation* loc = definitions->storageMap->getStorage(p);
402+
if (loc == nullptr)
403+
continue;
404+
currentDefinitions->remove(loc);
405+
}
402406
}
403407
if (locals != nullptr) {
404408
for (auto d : *locals) {
@@ -876,7 +880,7 @@ bool ComputeWriteSet::preorder(const IR::Function* function) {
876880
bool ComputeWriteSet::preorder(const IR::P4Table* table) {
877881
LOG1("CWS Visiting " << dbp(table));
878882
ProgramPoint pt(callingContext, table);
879-
enterScope(table->parameters, nullptr, pt, false);
883+
enterScope(nullptr, nullptr, pt, false);
880884

881885
// non-deterministic call of one of the actions in the table
882886
auto after = new Definitions();
@@ -889,7 +893,7 @@ bool ComputeWriteSet::preorder(const IR::P4Table* table) {
889893
visit(ale->expression);
890894
after = after->join(currentDefinitions);
891895
}
892-
exitScope(table->parameters, nullptr);
896+
exitScope(nullptr, nullptr);
893897
currentDefinitions = after;
894898
return false;
895899
}

frontends/p4/fromv1.0/converters.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const IR::Node* ExpressionConverter::postorder(IR::ActionArg* arg) {
7979

8080
const IR::Node* ExpressionConverter::postorder(IR::Primitive* primitive) {
8181
if (primitive->name == "current") {
82-
// current(a, b) => packet.lookahead<bit<a+b>>()[a+b-1,a]
82+
// current(a, b) => packet.lookahead<bit<a+b>>()[b-1,0]
8383
BUG_CHECK(primitive->operands.size() == 2, "Expected 2 operands for %1%", primitive);
8484
auto a = primitive->operands.at(0);
8585
auto b = primitive->operands.at(1);
@@ -103,8 +103,8 @@ const IR::Node* ExpressionConverter::postorder(IR::Primitive* primitive) {
103103
auto lookahead = new IR::MethodCallExpression(
104104
Util::SourceInfo(), method, typeargs, new IR::Vector<IR::Expression>());
105105
auto result = new IR::Slice(primitive->srcInfo, lookahead,
106-
new IR::Constant(aval + bval - 1),
107-
new IR::Constant(aval));
106+
new IR::Constant(bval - 1),
107+
new IR::Constant(0));
108108
result->type = IR::Type_Bits::get(bval);
109109
return result;
110110
} else if (primitive->name == "valid") {

frontends/p4/fromv1.0/programStructure.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,7 @@ const IR::P4Table*
628628
ProgramStructure::convertTable(const IR::V1Table* table, cstring newName,
629629
IR::IndexedVector<IR::Declaration>* stateful) {
630630
ExpressionConverter conv(this);
631-
632-
auto params = new IR::ParameterList();
633631
auto propvec = new IR::IndexedVector<IR::Property>(*table->properties.properties);
634-
635632
auto actVect = new IR::IndexedVector<IR::ActionListElement>();
636633
auto actionList = new IR::ActionList(Util::SourceInfo(), actVect);
637634

@@ -818,7 +815,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName,
818815

819816
auto props = new IR::TableProperties(Util::SourceInfo(), propvec);
820817
auto annos = addNameAnnotation(table->name, table->annotations);
821-
auto result = new IR::P4Table(table->srcInfo, newName, annos, params, props);
818+
auto result = new IR::P4Table(table->srcInfo, newName, annos, props);
822819
return result;
823820
}
824821

frontends/p4/frontend.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P
117117
new SimplifyControlFlow(&refMap, &typeMap),
118118
new MoveDeclarations(), // Move all local declarations to the beginning
119119
new SimplifyDefUse(&refMap, &typeMap),
120+
new UniqueParameters(&refMap, &typeMap),
120121
new SimplifyControlFlow(&refMap, &typeMap),
121122
new SpecializeAll(&refMap, &typeMap),
122123
new RemoveParserControlFlow(&refMap, &typeMap),

frontends/p4/p4-parse.ypp

+1-6
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,8 @@ statementOrDeclaration
753753
/************************* TABLE *********************************/
754754

755755
tableDeclaration
756-
: optAnnotations TABLE name '(' parameterList ')' '{' tablePropertyList '}'
756+
: optAnnotations TABLE name '{' tablePropertyList '}'
757757
{ $$ = new IR::P4Table(@3, *$3, $1,
758-
new IR::ParameterList(@5, $5),
759-
new IR::TableProperties(@8, $8)); }
760-
| optAnnotations TABLE name '{' tablePropertyList '}'
761-
{ $$ = new IR::P4Table(@3, *$3, $1,
762-
new IR::ParameterList(),
763758
new IR::TableProperties(@5, $5)); }
764759
;
765760

0 commit comments

Comments
 (0)