Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P4_14 -> P4_16 conversion for externs #162

Merged
merged 2 commits into from
Dec 6, 2016
Merged

Conversation

ChrisDodd
Copy link
Contributor

This is incomplete as it doesn't convert P4_14 style extern attributes into P4_16 style arguments to the extern constructor. Since we don't dump the attributes when producing P4_16 code, it results in the attributes simply being lost, which is bad.

@pierce-m
Copy link

pierce-m commented Dec 5, 2016

Not super familiar with this part of the code...can you explain what exactly is going on here/what changes are going in at a high level?

@mihaibudiu
Copy link
Contributor

P4 v1.1 introduced a specific syntax for extern blocks.
P4_16 has a different syntax.
This pass should convert one to the other - but the conversion is probably lossy according to the comments. To understand this pass one must understand both syntaxes.

@pierce-m
Copy link

pierce-m commented Dec 5, 2016

I see, thanks Mihai.

@ChrisDodd
Copy link
Contributor Author

ChrisDodd commented Dec 5, 2016

This is all code associated with handle extern objects.

The p4-14/typecheck.cpp is p4-14 typechecking, which replaces NamedRef (simple name expressions in the code) with GlobalRef and AttributeRef objects referring to global instances of things (counter and meters as well as externs) and attributes of externs; backends will need these to deal with these objects properly)

Most of the changes are in the P4-14 to P4-16 conversion, where global extern instances from P4-14 are converted to extern instance declarations in the control flows containing the tables and actions that use the extern instance.

I mostly assigned Pierce in case any of this impacts any of the architecture stuff you're currently working on -- when we move this path to use the standard switch architecture rather than the current v1model.p4, much of this code (the from1.0 stuff) will be impacted.

@pierce-m
Copy link

pierce-m commented Dec 5, 2016

Thanks Chris.

@@ -31,6 +31,13 @@ class TypeCheck::Pass1 : public Transform {
if (auto af = findContext<IR::ActionFunction>())
if (auto arg = af->arg(ref->name))
return arg;
if (auto bbox = findContext<IR::Declaration_Instance>()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something I don't understand:

  • p4-14 is compiled just for the v1model.p4
  • the list of externs in v1model.p4 is fixed
    So I don't understand how new extern declarations can appear in P4-14 programs. P4-14 does not support multiple architectures, and our front-end which parses p4-14 is hardwired to assume v1model.p4. So how can one write a p4 program that uses the extern syntax that has attributes if your target does not support any such externs?

return ref; }
if (auto hdr = findContext<IR::Type_StructLike>()) {
if (auto field = hdr->getField(ref->name)) {
/* FIXME -- Should this be converted to something else? */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of FIXME here...
Do we have any input p4 programs that will exercise this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a number of Barefoot internal testcases (using stateful ALU externs) that exercise this code. Unfortunately nothing on the open-source side (yet?)


if (extrn) {
auto parent = findContext<IR::ActionFunction>();
BUG_CHECK(parent != nullptr, "%1%: Extern call not within action", primitive);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ::error instead of BUG?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4-14 syntactically disallow statements (primitive calls in this case) anywhere other than in action bodies, so it should not occur.

validate{ BUG_CHECK(type->is<Type_Name>() ||
type->is<Type_Specialized>(),
type->is<Type_Specialized>() ||
type->is<Type_Extern>(), // P4_14 only?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For P4-16 this can be a Type_Name that refers to a Type_Extern, but not the Type_Extern itself. I don't see any call to a Declaration_Instance constructor in the new code which can use a Type_Extern. Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The P4_14 parser produces DeclarationInstances that refer to Type_Externs.

@@ -22,7 +22,7 @@ header ipv4_t {
bit<16> hdrChecksum;
bit<32> srcAddr;
bit<32> dstAddr;
@length(ihl * 4)
@length(ihl * 4w4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please commit some tests which exercise these paths as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants