Skip to content

Commit 05542be

Browse files
committed
IR::Ptr fixes for tofino
- do NOT use IR::Ptr for the return value of getWriteDest in parde.def, so that we can have covariant return types. - stateful alu creation use IR::Ptr throughout - fromv1.0 stuff use IR::Ptr is most places - MANY changes 'const auto *' => 'auto' to allow inferring IR::Ptr Signed-off-by: Chris Dodd <cdodd@nvidia.com>
1 parent 7579795 commit 05542be

93 files changed

Lines changed: 530 additions & 521 deletions

File tree

Some content is hidden

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

backends/tofino/bf-p4c/arch/add_t2na_meta.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ void AddT2naMeta::postorder(IR::Type_StructLike *typeStructLike) {
6161
}
6262
} else if (typeStructLikeName == "egress_intrinsic_metadata_t") {
6363
const IR::StructField *lastStructField = nullptr;
64-
for (const auto *structField : typeStructLike->fields) {
64+
for (auto structField : typeStructLike->fields) {
6565
lastStructField = structField;
66-
};
66+
}
6767
if (lastStructField && lastStructField->getAnnotation("padding"_cs)) {
6868
LOG3("AddT2naMeta : " << typeStructLikeName << " already complete");
6969
return;

backends/tofino/bf-p4c/arch/arch.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool Pipeline::equiv(const Pipeline &other) const {
6262
return true;
6363
}
6464

65-
void Pipeline::insertPragmas(const std::vector<const IR::Annotation *> &all_pragmas) {
65+
void Pipeline::insertPragmas(const std::vector<IR::Ptr<IR::Annotation>> &all_pragmas) {
6666
auto applies = [this](const IR::Annotation *p) {
6767
if (p->getExpr().empty() || p->getExpr(0) == nullptr) {
6868
return true;
@@ -77,7 +77,7 @@ void Pipeline::insertPragmas(const std::vector<const IR::Annotation *> &all_prag
7777
}
7878
return true;
7979
};
80-
for (const auto *pragma : all_pragmas) {
80+
for (auto pragma : all_pragmas) {
8181
if (applies(pragma)) {
8282
pragmas.push_back(pragma);
8383
}
@@ -392,7 +392,7 @@ void add_param(ordered_map<cstring, cstring> &tnaParams, const IR::ParameterList
392392
IR::ParameterList *newParams, cstring hdr, size_t index, cstring hdr_type = ""_cs,
393393
IR::Direction dir = IR::Direction::None) {
394394
if (params->parameters.size() > index) {
395-
auto *param = params->parameters.at(index);
395+
auto param = params->parameters.at(index);
396396
tnaParams.emplace(hdr, param->name);
397397
} else {
398398
// add optional parameter to parser and control type
@@ -403,7 +403,7 @@ void add_param(ordered_map<cstring, cstring> &tnaParams, const IR::ParameterList
403403
}
404404

405405
const IR::Node *RestoreParams::postorder(IR::BFN::TnaControl *control) {
406-
auto *params = control->type->getApplyParameters();
406+
auto params = control->type->getApplyParameters();
407407
ordered_map<cstring, cstring> tnaParams;
408408
auto *newParams = new IR::ParameterList();
409409
for (auto p : params->parameters) {
@@ -451,7 +451,7 @@ const IR::Node *RestoreParams::postorder(IR::BFN::TnaControl *control) {
451451
}
452452

453453
const IR::Node *RestoreParams::postorder(IR::BFN::TnaParser *parser) {
454-
auto *params = parser->type->getApplyParameters();
454+
auto params = parser->type->getApplyParameters();
455455
ordered_map<cstring, cstring> tnaParams;
456456

457457
auto *newParams = new IR::ParameterList();
@@ -488,7 +488,7 @@ const IR::Node *RestoreParams::postorder(IR::BFN::TnaParser *parser) {
488488
}
489489

490490
const IR::Node *RestoreParams::postorder(IR::BFN::TnaDeparser *control) {
491-
auto *params = control->type->getApplyParameters();
491+
auto params = control->type->getApplyParameters();
492492
ordered_map<cstring, cstring> tnaParams;
493493
auto *newParams = new IR::ParameterList();
494494
for (auto p : params->parameters) {

backends/tofino/bf-p4c/arch/arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ struct Pipeline {
287287
private:
288288
// Inserts global pragmas into this instance. Filters out all pragmas which are applied
289289
// to a different pipeline.
290-
void insertPragmas(const std::vector<const IR::Annotation *> &all_pragmas);
290+
void insertPragmas(const std::vector<IR::Ptr<IR::Annotation>> &all_pragmas);
291291
};
292292

293293
class ProgramPipelines {

backends/tofino/bf-p4c/arch/bridge_metadata.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct CollectSpecialPrimitives : public Inspector {
5151
void postorder(const IR::ExitStatement *e) override { exit.insert(e); }
5252

5353
void postorder(const IR::MethodCallStatement *node) override {
54-
auto *call = node->methodCall;
54+
auto call = node->methodCall;
5555
auto *pa = call->method->to<IR::PathExpression>();
5656
if (!pa) return;
5757
if (pa->path->name == "bypass_egress")
@@ -112,7 +112,7 @@ struct BridgeIngressToEgress : public Transform {
112112
if (structFields.size() > 0) {
113113
if (LOGGING(3)) {
114114
LOG3("\tNumber of fields to bridge: " << fieldsToBridge.size());
115-
for (auto *f : structFields) LOG3("\t Bridged field: " << f->name);
115+
for (auto f : structFields) LOG3("\t Bridged field: " << f->name);
116116
}
117117
auto bridgedMetaType = new IR::Type_Struct(
118118
"fields", {new IR::Annotation(IR::ID("flexible"), {})}, structFields);
@@ -131,10 +131,10 @@ struct BridgeIngressToEgress : public Transform {
131131
forAllMatching<IR::BFN::TnaControl>(root, [&](const IR::BFN::TnaControl *control) {
132132
if (!metaStructName.isNullOrEmpty()) return;
133133
cstring p4ParamName = control->tnaParams.at("md"_cs);
134-
auto *params = control->type->getApplyParameters();
135-
auto *param = params->getParameter(p4ParamName);
134+
auto params = control->type->getApplyParameters();
135+
auto param = params->getParameter(p4ParamName);
136136
BUG_CHECK(param, "Couldn't find param %1% on control: %2%", p4ParamName, control);
137-
auto *paramType = typeMap->getType(param);
137+
auto paramType = typeMap->getType(param);
138138
BUG_CHECK(paramType, "Couldn't find type for: %1%", param);
139139
BUG_CHECK(paramType->is<IR::Type_StructLike>(),
140140
"User metadata parameter type isn't structlike %2%: %1%", paramType,
@@ -335,7 +335,7 @@ struct BridgeIngressToEgress : public Transform {
335335
}
336336

337337
IR::Node *preorder(IR::MethodCallStatement *node) override {
338-
auto *call = node->methodCall;
338+
auto call = node->methodCall;
339339
auto *pa = call->method->to<IR::PathExpression>();
340340
if (!pa) return node;
341341
if (pa->path->name != "bypass_egress") return node;

backends/tofino/bf-p4c/arch/collect_bridged_fields.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool isMetadata(const LinearPath &path, P4::TypeMap *typeMap) {
5050
return std::all_of(path.components.begin(), path.components.end(),
5151
[&](const IR::Expression *component) {
5252
LOG2("isMetadata? checking component: " << component);
53-
auto *type = typeMap->getType(component);
53+
auto type = typeMap->getType(component);
5454
BUG_CHECK(type, "Couldn't find type for: %1%", component);
5555
LOG3("isMetadata? type is: " << type);
5656
if (component == lastComponent) return isMetadataOrPrimitiveType(type);
@@ -65,7 +65,7 @@ std::optional<cstring> containingTnaParam(const LinearPath &linearPath, const Tn
6565
"Path-like expression tree was rooted in "
6666
"non-path expression: %1%",
6767
linearPath.components[0]);
68-
auto *decl = refMap->getDeclaration(topLevelPath->path);
68+
auto decl = refMap->getDeclaration(topLevelPath->path);
6969
BUG_CHECK(decl,
7070
"No declaration for top level path in path-like "
7171
"expression: %1%",
@@ -96,13 +96,13 @@ void forAllTouchedFields(const LinearPath &linearPath, P4::TypeMap *typeMap, Fun
9696
BUG("Unexpected path-like expression component: %1%", component);
9797
}
9898

99-
auto *lastComponentType = typeMap->getType(components.back());
99+
auto lastComponentType = typeMap->getType(components.back());
100100
BUG_CHECK(lastComponentType, "Couldn't find type for: %1%", components.back());
101101
if (auto *structType = lastComponentType->to<IR::Type_StructLike>()) {
102102
fullPathStr.push_back('.');
103103
cstring fullPath(fullPathStr);
104-
for (auto *field : structType->fields) {
105-
auto *fieldType = typeMap->getType(field);
104+
for (auto field : structType->fields) {
105+
auto fieldType = typeMap->getType(field);
106106
BUG_CHECK(fieldType, "Couldn't find type for: %1%", field);
107107
auto *fieldExpr = new IR::Member(fieldType, components.back(), IR::ID(field->name));
108108
func(fullPath + field->name, fieldType, fieldExpr);
@@ -267,8 +267,8 @@ bool CollectBridgedFields::preorder(const IR::BFN::TnaDeparser *d) {
267267
return false;
268268
}
269269
bool CollectBridgedFields::preorder(const IR::P4Table *tbl) {
270-
if (auto *key = tbl->getKey()) visit(key, "key");
271-
if (auto *actions = tbl->getActionList()) {
270+
if (auto key = tbl->getKey()) visit(key, "key");
271+
if (auto actions = tbl->getActionList()) {
272272
parallel_visit(actions->actionList, "actions");
273273
} else {
274274
BUG("No actions in %s", tbl);

backends/tofino/bf-p4c/arch/fromv1.0/checksum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class InsertParserChecksums : public Inspector {
242242
ExtractToState &extractToState;
243243

244244
void postorder(const IR::MethodCallStatement *statement) override {
245-
auto *call = statement->methodCall;
245+
auto call = statement->methodCall;
246246
CHECK_NULL(call);
247247
auto *method = call->method->to<IR::Member>();
248248
auto *state = findContext<IR::ParserState>();
@@ -398,7 +398,7 @@ class InsertParserChecksums : public Inspector {
398398
}
399399
}
400400

401-
auto *destfieldAdj = destfield;
401+
auto destfieldAdj = destfield;
402402
if (const auto *member = destfield->to<IR::Member>()) {
403403
destfieldAdj = replaceSrcInfo(member, state->srcInfo);
404404
}

backends/tofino/bf-p4c/arch/fromv1.0/egress_packet_length.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PacketLengthEgressUseEval : public Inspector {
5757
bool preorder(const IR::Member *member) {
5858
if (!member->expr->is<IR::PathExpression>() || member->member.name != "pkt_length")
5959
return false;
60-
auto *decl = refMap->getDeclaration(member->expr->to<IR::PathExpression>()->path);
60+
auto decl = refMap->getDeclaration(member->expr->to<IR::PathExpression>()->path);
6161
auto *control = findContext<IR::BFN::TnaControl>();
6262
if (decl && control && decl->getName().name == control->tnaParams.at("eg_intr_md"_cs)) {
6363
egressUsesPacketLength = true;
@@ -100,7 +100,7 @@ class EgressPacketLengthAdjust : public Transform {
100100

101101
// Find extracted mirror header and assign "egress_pkt_len_adjust"
102102
auto *newEgressMirrorParserState = state->clone();
103-
for (auto *component : state->components) {
103+
for (auto component : state->components) {
104104
// Ignore non-extract statements
105105
auto *methodCallStatement = component->to<IR::MethodCallStatement>();
106106
if (!methodCallStatement || methodCallStatement->methodCall->arguments->size() < 1)
@@ -111,7 +111,7 @@ class EgressPacketLengthAdjust : public Transform {
111111
if (!pathExpr || pathExpr->path->name.name != parser->tnaParams.at("pkt"_cs)) continue;
112112

113113
// Extracted mirror header
114-
auto *argument = methodCallStatement->methodCall->arguments->at(0)->expression;
114+
auto argument = methodCallStatement->methodCall->arguments->at(0)->expression;
115115
// Add "egress_pkt_len_adjust" assignment to parse state
116116
auto &compGenMeta = parser->tnaParams.at("__bfp4c_compiler_generated_meta"_cs);
117117
auto *egPktLenAdjust = new IR::Member(new IR::PathExpression(compGenMeta),

backends/tofino/bf-p4c/arch/fromv1.0/lpf.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
P4V1::LpfConverter::LpfConverter() { addConverter("lpf"_cs, this); }
2424

25-
const IR::Type_Extern *P4V1::LpfConverter::convertExternType(P4V1::ProgramStructure *structure,
26-
const IR::Type_Extern *, cstring) {
25+
IR::Ptr<IR::Type_Extern> P4V1::LpfConverter::convertExternType(P4V1::ProgramStructure *structure,
26+
const IR::Type_Extern *, cstring) {
2727
if (use_v1model()) structure->include("tofino/lpf.p4"_cs);
2828
return nullptr;
2929
}
3030

31-
const IR::Declaration_Instance *P4V1::LpfConverter::convertExternInstance(
31+
IR::Ptr<IR::Declaration_Instance> P4V1::LpfConverter::convertExternInstance(
3232
P4V1::ProgramStructure *structure, const IR::Declaration_Instance *ext, cstring name,
3333
IR::IndexedVector<IR::Declaration> *) {
3434
auto *et = ext->type->to<IR::Type_Extern>();
@@ -74,9 +74,9 @@ const IR::Declaration_Instance *P4V1::LpfConverter::convertExternInstance(
7474
}
7575
}
7676

77-
const IR::Statement *P4V1::LpfConverter::convertExternCall(P4V1::ProgramStructure *structure,
78-
const IR::Declaration_Instance *ext,
79-
const IR::Primitive *prim) {
77+
IR::Ptr<IR::Statement> P4V1::LpfConverter::convertExternCall(P4V1::ProgramStructure *structure,
78+
const IR::Declaration_Instance *ext,
79+
const IR::Primitive *prim) {
8080
auto *et = ext->type->to<IR::Type_Extern>();
8181
BUG_CHECK(et && et->name == "lpf", "Extern %s is not lpf type, but %s", ext, ext->type);
8282
ExpressionConverter conv(structure);

backends/tofino/bf-p4c/arch/fromv1.0/lpf.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class LpfConverter : public ExternConverter {
2929
static LpfConverter singleton;
3030

3131
public:
32-
const IR::Type_Extern *convertExternType(P4V1::ProgramStructure *, const IR::Type_Extern *,
33-
cstring) override;
34-
const IR::Declaration_Instance *convertExternInstance(
32+
IR::Ptr<IR::Type_Extern> convertExternType(P4V1::ProgramStructure *, const IR::Type_Extern *,
33+
cstring) override;
34+
IR::Ptr<IR::Declaration_Instance> convertExternInstance(
3535
P4V1::ProgramStructure *, const IR::Declaration_Instance *, cstring,
3636
IR::IndexedVector<IR::Declaration> *) override;
37-
const IR::Statement *convertExternCall(P4V1::ProgramStructure *,
38-
const IR::Declaration_Instance *,
39-
const IR::Primitive *) override;
37+
IR::Ptr<IR::Statement> convertExternCall(P4V1::ProgramStructure *,
38+
const IR::Declaration_Instance *,
39+
const IR::Primitive *) override;
4040
};
4141

4242
} // namespace P4V1

backends/tofino/bf-p4c/arch/fromv1.0/meter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
P4V1::MeterConverter::MeterConverter() { addConverter("meter"_cs, this); }
2525

26-
const IR::Type_Extern *P4V1::MeterConverter::convertExternType(P4V1::ProgramStructure *structure,
27-
const IR::Type_Extern *, cstring) {
26+
IR::Ptr<IR::Type_Extern> P4V1::MeterConverter::convertExternType(P4V1::ProgramStructure *structure,
27+
const IR::Type_Extern *, cstring) {
2828
if (use_v1model()) structure->include("tofino/meter.p4"_cs);
2929
return nullptr;
3030
}
3131

32-
const IR::Declaration_Instance *P4V1::MeterConverter::convertExternInstance(
32+
IR::Ptr<IR::Declaration_Instance> P4V1::MeterConverter::convertExternInstance(
3333
P4V1::ProgramStructure *structure, const IR::Declaration_Instance *ext, cstring name,
3434
IR::IndexedVector<IR::Declaration> *) {
3535
auto *et = ext->type->to<IR::Type_Extern>();
@@ -105,9 +105,9 @@ const IR::Declaration_Instance *P4V1::MeterConverter::convertExternInstance(
105105
}
106106
}
107107

108-
const IR::Statement *P4V1::MeterConverter::convertExternCall(P4V1::ProgramStructure *structure,
109-
const IR::Declaration_Instance *ext,
110-
const IR::Primitive *prim) {
108+
IR::Ptr<IR::Statement> P4V1::MeterConverter::convertExternCall(P4V1::ProgramStructure *structure,
109+
const IR::Declaration_Instance *ext,
110+
const IR::Primitive *prim) {
111111
auto *et = ext->type->to<IR::Type_Extern>();
112112
BUG_CHECK(et && et->name == "meter", "Extern %s is not meter type, but %s", ext, ext->type);
113113
ExpressionConverter conv(structure);

0 commit comments

Comments
 (0)