-
Notifications
You must be signed in to change notification settings - Fork 444
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
Shorten the Identifer name, including dots(.) in Member expression #3175
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ filegroup( | |
srcs = [ | ||
"frontends/p4-14/ir-v1.def", | ||
"backends/bmv2/bmv2.def", | ||
"backends/dpdk/dpdk.def", | ||
# p4c extensions may set this target to a `filegroup` containing | ||
# additional .def files. | ||
"@com_github_p4lang_p4c_extension//:ir_extensions", | ||
|
@@ -190,13 +191,17 @@ cc_library( | |
"frontends/parsers/p4/p4lexer.cc", | ||
"frontends/parsers/v1/v1lexer.cc", | ||
"ir/ir-generated.cpp", | ||
"backends/dpdk/spec.cpp", | ||
"backends/dpdk/dbprint-dpdk.cpp", | ||
"backends/dpdk/printUtils.cpp", | ||
], | ||
textual_hdrs = glob([ | ||
"ir/**/*.h", | ||
"frontends/**/*.h", | ||
"frontends/**/*.hpp", | ||
"midend/**/*.h", | ||
"control-plane/**/*.h", | ||
"backends/dpdk/*.h", | ||
]) + [ | ||
":p4_parser_yacc", | ||
":v1_parser_yacc", | ||
|
@@ -275,8 +280,71 @@ cc_binary( | |
data = [":p4include"], | ||
) | ||
|
||
# This builds the p4test backend. | ||
# dpdk backend | ||
genrule( | ||
name = "dest_dir_dpdk", | ||
srcs = ["backends/dpdk/control-plane/proto/p4info.proto"], | ||
outs = ["p4/config/dpdk/p4info.proto"], | ||
cmd = "mkdir -p p4/config/dpdk; cp $(SRCS) $(OUTS)", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
proto_library( | ||
name = "p4info_dpdk_proto", | ||
srcs = ["p4/config/dpdk/p4info.proto"], | ||
deps = [ | ||
"@com_google_protobuf//:any_proto", | ||
"@com_google_protobuf//:descriptor_proto", | ||
], | ||
) | ||
|
||
cc_proto_library( | ||
name = "p4info_dpdk_cc_proto", | ||
deps = [":p4info_dpdk_proto"], | ||
) | ||
|
||
cc_library( | ||
name = "p4c_dpdk_lib", | ||
srcs = glob( | ||
["backends/dpdk/*.cpp", "backends/dpdk/control-plane/*.cpp", "backends/bmv2/common/lower.cpp"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: maybe put each file on a separate line for consistency / readability? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below |
||
exclude = ["backends/dpdk/main.cpp", "backends/dpdk/spec.cpp", "backends/dpdk/printUtils.cpp", "backends/dpdk/dbprint-dpdk.cpp"], | ||
), | ||
hdrs = glob(["backends/dpdk/*.h", "backends/dpdk/control-plane/*.h", "backends/bmv2/common/lower.h"]), | ||
deps = [ | ||
":ir_frontend_midend_control_plane", | ||
":lib", | ||
":p4info_dpdk_cc_proto", | ||
], | ||
) | ||
|
||
genrule( | ||
name = "p4c_dpdk_version", | ||
srcs = ["backends/dpdk/version.h.cmake"], | ||
outs = ["backends/dpdk/version.h"], | ||
cmd = "sed 's|@P4C_VERSION@|0.0.0.0|g' $(SRCS) > $(OUTS)", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
cc_binary( | ||
name = "p4c_dpdk", | ||
srcs = [ | ||
"backends/dpdk/main.cpp", | ||
"backends/dpdk/version.h", | ||
], | ||
linkopts = [ | ||
"-lgmp", | ||
"-lgmpxx", | ||
], | ||
deps = [ | ||
":p4c_dpdk_lib", | ||
":ir_frontend_midend_control_plane", | ||
":lib", | ||
], | ||
data = [":p4include"], | ||
) | ||
|
||
|
||
# This builds the p4test backend. | ||
cc_binary( | ||
name = "p4c_backend_p4test", | ||
srcs = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,124 @@ class ValidateTableKeys : public Inspector { | |
int getFieldSizeBits(const IR::Type *field_type); | ||
}; | ||
|
||
// This pass shorten the Identifier length | ||
class ShortenTokenLength : public Transform { | ||
ordered_map<cstring, cstring> newNameMap; | ||
static size_t count; | ||
// Currently Dpdk allows Identifier of 63 char long or less | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just a silly restriction, since I suspect the identifiers do not have a runtime representation. |
||
// including dots(.) for member exp. | ||
// worst case member expression will look like below(for headers) | ||
// 1.30.30 => 63(including dot(.)) | ||
// if id name less than allowedLength keep it same | ||
cstring shortenString(cstring str, size_t allowedLength = 60) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a class which does this, MinimalNameGenerator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This runs post codegen and applied on some dpdk specific types too. |
||
if (str.size() <= allowedLength) | ||
return str; | ||
auto itr = newNameMap.find(str); | ||
if (itr != newNameMap.end()) | ||
return itr->second; | ||
// make sure new string length less or equal allowedLength | ||
cstring newStr = str.substr(0, allowedLength - std::to_string(count).size()); | ||
newStr += std::to_string(count); | ||
count++; | ||
newNameMap.insert(std::pair<cstring, cstring>(str, newStr)); | ||
origNameMap.insert(std::pair<cstring, cstring>(newStr, str)); | ||
return newStr; | ||
} | ||
|
||
public: | ||
static ordered_map<cstring, cstring> origNameMap; | ||
|
||
const IR::Node* preorder(IR::Member *m) override { | ||
if (m->toString().startsWith("m.")) | ||
m->member = shortenString(m->member); | ||
else | ||
m->member = shortenString(m->member, 30); | ||
return m; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkStructType *s) override { | ||
if (s->getAnnotations()->getSingle("__packet_data__")) { | ||
s->name = shortenString(s->name); | ||
IR::IndexedVector<IR::StructField> changedFields; | ||
for (auto field : s->fields) { | ||
IR::StructField *f = new IR::StructField(field->name, field->type); | ||
f->name = shortenString(f->name, 30); | ||
changedFields.push_back(f); | ||
} | ||
return new IR::DpdkStructType(s->srcInfo, s->name, | ||
s->annotations, changedFields); | ||
} else { | ||
s->name = shortenString(s->name); | ||
IR::IndexedVector<IR::StructField> changedFields; | ||
for (auto field : s->fields) { | ||
IR::StructField *f = new IR::StructField(field->name, field->type); | ||
f->name = shortenString(f->name); | ||
changedFields.push_back(f); | ||
} | ||
return new IR::DpdkStructType(s->srcInfo, s->name, | ||
s->annotations, changedFields); | ||
} | ||
return s; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkHeaderType *h) override { | ||
h->name = shortenString(h->name, 30); | ||
IR::IndexedVector<IR::StructField> changedFields; | ||
for (auto field : h->fields) { | ||
IR::StructField *f = new IR::StructField(field->name, field->type); | ||
f->name = shortenString(f->name, 30); | ||
changedFields.push_back(f); | ||
} | ||
return new IR::DpdkHeaderType(h->srcInfo, h->name, | ||
h->annotations, changedFields); | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkExternDeclaration *e) override { | ||
e->name = shortenString(e->name); | ||
return e; | ||
} | ||
|
||
const IR::Node* preorder(IR::Declaration *g) override { | ||
g->name = shortenString(g->name); | ||
return g; | ||
} | ||
|
||
const IR::Node* preorder(IR::Path *p) override { | ||
p->name = shortenString(p->name); | ||
return p; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkAction *a) override { | ||
a->name = shortenString(a->name); | ||
return a; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkTable *t) override { | ||
t->name = shortenString(t->name); | ||
return t; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkLearner *l) override { | ||
l->name = shortenString(l->name); | ||
return l; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkSelector *s) override { | ||
s->name = shortenString(s->name); | ||
return s; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkLearnStatement *ls) override{ | ||
ls->action = shortenString(ls->action); | ||
return ls; | ||
} | ||
|
||
const IR::Node* preorder(IR::DpdkApplyStatement *as) override{ | ||
as->table = shortenString(as->table); | ||
return as; | ||
} | ||
}; | ||
|
||
// Instructions can only appear in actions and apply block of .spec file. | ||
// All these individual passes work on the actions and apply block of .spec file. | ||
class DpdkAsmOptimization : public PassRepeated { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps for the bazel build you want to request a review from @smolkaj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unable to add @smolkaj to reviewer list. may be due to permission issues. Can you please add him?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That mention is enough, he had been notified. If he doesn't reply in a couple of days I will merge it anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, taking a look :)