From bf2aa7bbaa1bfaa75485673c78d9a329fa060a70 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Tue, 4 Mar 2025 18:16:15 -0800 Subject: [PATCH] Mark inline locations with annotation. (#5150) Signed-off-by: Anton Korobeynikov --- backends/bmv2/pna_nic/midend.cpp | 2 +- backends/bmv2/pna_nic/pnaNic.cpp | 4 +-- backends/bmv2/psa_switch/midend.cpp | 2 +- backends/bmv2/psa_switch/psaSwitch.cpp | 4 +-- backends/bmv2/simple_switch/midend.cpp | 2 +- backends/bmv2/simple_switch/simpleSwitch.cpp | 4 +-- backends/dpdk/midend.cpp | 4 +-- backends/ebpf/midend.cpp | 4 +-- backends/p4test/midend.cpp | 4 +-- backends/p4tools/common/compiler/midend.cpp | 6 ++-- backends/tc/midend.cpp | 4 +-- backends/tofino/bf-p4c/midend/elim_cast.h | 2 +- .../bf-p4c/midend/simplifyIfStatement.h | 2 +- backends/ubpf/midend.cpp | 4 +-- frontends/p4/actionsInlining.cpp | 33 ++++++++++--------- frontends/p4/frontend.cpp | 10 +++--- frontends/p4/frontend.h | 4 +++ frontends/p4/functionsInlining.cpp | 17 ++++++---- frontends/p4/parserControlFlow.h | 2 +- frontends/p4/simplify.cpp | 4 ++- frontends/p4/simplify.h | 9 +++-- ir/annotations.cpp | 1 + ir/base.def | 1 + midend/parserUnroll.h | 2 +- test/gtest/midend_pass.cpp | 2 +- .../fabric_20190420/fabric-frontend.p4 | 30 ++++++++--------- .../inline-function2-frontend.p4 | 2 +- .../omec/up4-frontend.p4 | 16 ++++----- .../pins/pins_fabric-frontend.p4 | 18 +++++----- .../pins/pins_fabric-midend.p4 | 18 +++++----- .../pins/pins_middleblock-first.p4 | 2 +- .../pins/pins_middleblock-frontend.p4 | 18 +++++----- .../pins/pins_middleblock-midend.p4 | 18 +++++----- .../pins/pins_middleblock.p4 | 2 +- .../xor_test-frontend.p4 | 4 +-- .../p4_16_samples_outputs/xor_test-midend.p4 | 4 +-- 36 files changed, 141 insertions(+), 124 deletions(-) diff --git a/backends/bmv2/pna_nic/midend.cpp b/backends/bmv2/pna_nic/midend.cpp index 5617a509be0..3a682c609ed 100644 --- a/backends/bmv2/pna_nic/midend.cpp +++ b/backends/bmv2/pna_nic/midend.cpp @@ -147,7 +147,7 @@ PnaNicMidEnd::PnaNicMidEnd(CompilerOptions &options, std::ostream *outStream) new P4::ValidateTableProperties({"pna_implementation"_cs, "pna_direct_counter"_cs, "pna_direct_meter"_cs, "pna_idle_timeout"_cs, "size"_cs}), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::CompileTimeOperations(), new P4::TableHit(&typeMap), new P4::EliminateSwitch(&typeMap), diff --git a/backends/bmv2/pna_nic/pnaNic.cpp b/backends/bmv2/pna_nic/pnaNic.cpp index 33b5e70dbf5..c4da9998c37 100644 --- a/backends/bmv2/pna_nic/pnaNic.cpp +++ b/backends/bmv2/pna_nic/pnaNic.cpp @@ -86,13 +86,13 @@ void PnaNicBackend::convert(const IR::ToplevelBlock *tlb) { new SkipControls(&structure.non_pipeline_controls)), new P4::MoveActionsToTables(refMap, typeMap), new P4::TypeChecking(refMap, typeMap), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new LowerExpressions(typeMap), new PassRepeated({new P4::ConstantFolding(typeMap), new P4::StrengthReduction(typeMap)}), new P4::TypeChecking(refMap, typeMap), new P4::RemoveComplexExpressions(typeMap, new ProcessControls(&structure.pipeline_controls)), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new P4::RemoveAllUnusedDeclarations(P4::RemoveUnusedPolicy()), // Converts the DAG into a TREE (at least for expressions) // This is important later for conversion to JSON. diff --git a/backends/bmv2/psa_switch/midend.cpp b/backends/bmv2/psa_switch/midend.cpp index 643fd878295..cbbf86893d5 100644 --- a/backends/bmv2/psa_switch/midend.cpp +++ b/backends/bmv2/psa_switch/midend.cpp @@ -155,7 +155,7 @@ PsaSwitchMidEnd::PsaSwitchMidEnd(CompilerOptions &options, std::ostream *outStre "psa_idle_timeout"_cs, "size"_cs, }), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::CompileTimeOperations(), new P4::TableHit(&typeMap), new P4::EliminateSwitch(&typeMap), diff --git a/backends/bmv2/psa_switch/psaSwitch.cpp b/backends/bmv2/psa_switch/psaSwitch.cpp index 4e8775c5fb8..adb311823f0 100644 --- a/backends/bmv2/psa_switch/psaSwitch.cpp +++ b/backends/bmv2/psa_switch/psaSwitch.cpp @@ -100,7 +100,7 @@ void PsaSwitchBackend::convert(const IR::ToplevelBlock *tlb) { new SkipControls(&structure.non_pipeline_controls)), new P4::MoveActionsToTables(refMap, typeMap), new P4::TypeChecking(refMap, typeMap), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new LowerExpressions(typeMap), new PassRepeated({ new P4::ConstantFolding(typeMap), @@ -109,7 +109,7 @@ void PsaSwitchBackend::convert(const IR::ToplevelBlock *tlb) { new P4::TypeChecking(refMap, typeMap), new P4::RemoveComplexExpressions(typeMap, new ProcessControls(&structure.pipeline_controls)), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new P4::RemoveAllUnusedDeclarations(P4::RemoveUnusedPolicy()), // Converts the DAG into a TREE (at least for expressions) // This is important later for conversion to JSON. diff --git a/backends/bmv2/simple_switch/midend.cpp b/backends/bmv2/simple_switch/midend.cpp index 0b09c609fcd..c3673e2f190 100644 --- a/backends/bmv2/simple_switch/midend.cpp +++ b/backends/bmv2/simple_switch/midend.cpp @@ -121,7 +121,7 @@ SimpleSwitchMidEnd::SimpleSwitchMidEnd(CompilerOptions &options, std::ostream *o "meters"_cs, "support_timeout"_cs, }), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::EliminateTypedef(&typeMap), new P4::CompileTimeOperations(), new P4::TableHit(&typeMap), diff --git a/backends/bmv2/simple_switch/simpleSwitch.cpp b/backends/bmv2/simple_switch/simpleSwitch.cpp index a2e9699161e..94076711c64 100644 --- a/backends/bmv2/simple_switch/simpleSwitch.cpp +++ b/backends/bmv2/simple_switch/simpleSwitch.cpp @@ -1176,12 +1176,12 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { new SkipControls(&structure->non_pipeline_controls)), new P4::MoveActionsToTables(refMap, typeMap), new P4::TypeChecking(nullptr, typeMap), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new LowerExpressions(typeMap), new P4::ConstantFolding(typeMap, false), new P4::TypeChecking(nullptr, typeMap), new RemoveComplexExpressions(typeMap, new ProcessControls(&structure->pipeline_controls)), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new P4::RemoveAllUnusedDeclarations(P4::RemoveUnusedPolicy()), new P4::FlattenLogMsg(typeMap), // Converts the DAG into a TREE (at least for expressions) diff --git a/backends/dpdk/midend.cpp b/backends/dpdk/midend.cpp index 89cfd232f48..456fc8d4769 100644 --- a/backends/dpdk/midend.cpp +++ b/backends/dpdk/midend.cpp @@ -204,7 +204,7 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options, std::ostream *outStream) { new P4::HSIndexSimplifier(&typeMap), new P4::ParsersUnroll(true, &refMap, &typeMap), new P4::FlattenHeaderUnion(&refMap, &typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::ReplaceSelectRange(), new P4::MoveDeclarations(), // more may have been introduced new P4::ConstantFolding(&typeMap), @@ -215,7 +215,7 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options, std::ostream *outStream) { }), new P4::MoveDeclarations(), validateTableProperties(options.arch), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::SimplifySwitch(&typeMap), new P4::CompileTimeOperations(), new P4::TableHit(&typeMap), diff --git a/backends/ebpf/midend.cpp b/backends/ebpf/midend.cpp index e0c124ee40a..1ff9c87f0f8 100644 --- a/backends/ebpf/midend.cpp +++ b/backends/ebpf/midend.cpp @@ -84,7 +84,7 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program * new P4::RemoveMiss(&typeMap), new P4::EliminateInvalidHeaders(&typeMap), new P4::EliminateNewtype(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::SimplifyKey( &typeMap, new P4::OrPolicy(new P4::IsValid(&typeMap), new P4::IsLikeLeftValue())), new P4::RemoveExits(&typeMap), @@ -104,7 +104,7 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program * new P4::RemoveSelectBooleans(&typeMap), new P4::SingleArgumentSelect(&typeMap), new P4::ConstantFolding(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::TableHit(&typeMap), new P4::RemoveLeftSlices(&typeMap), new EBPF::Lower(&refMap, &typeMap), diff --git a/backends/p4test/midend.cpp b/backends/p4test/midend.cpp index 4c1da8b857e..a32b6f64139 100644 --- a/backends/p4test/midend.cpp +++ b/backends/p4test/midend.cpp @@ -122,7 +122,7 @@ MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) { }), new P4::StrengthReduction(&typeMap), new P4::MoveDeclarations(), // more may have been introduced - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::CompileTimeOperations(), new P4::TableHit(&typeMap), new P4::EliminateSwitch(&typeMap), @@ -167,7 +167,7 @@ MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) { evaluator, [this, evaluator]() { toplevel = evaluator->getToplevelBlock(); }, new P4::FlattenHeaderUnion(&refMap, &typeMap, options.loopsUnrolling), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::MidEndLast()}); if (options.listMidendPasses) { listPasses(*outStream, cstring::newline); diff --git a/backends/p4tools/common/compiler/midend.cpp b/backends/p4tools/common/compiler/midend.cpp index 6d58f28ca76..a74b0542b56 100644 --- a/backends/p4tools/common/compiler/midend.cpp +++ b/backends/p4tools/common/compiler/midend.cpp @@ -108,7 +108,7 @@ void MidEnd::addDefaultPasses() { mkConvertKeys(), mkConvertEnums(), new P4::ConstantFolding(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), // Eliminate extraneous cases in select statements. new P4::SimplifySelectCases(&typeMap, false), // Expand lookahead assignments into sequences of field assignments. @@ -145,7 +145,7 @@ void MidEnd::addDefaultPasses() { }), new P4::ConstantFolding(&typeMap), new P4::MoveDeclarations(), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), // Replace any slices in the left side of assignments and convert them to casts. new P4::RemoveLeftSlices(&typeMap), // Remove loops from parsers by unrolling them as far as the stack indices allow. @@ -155,7 +155,7 @@ void MidEnd::addDefaultPasses() { // Convert tuples into structs. new P4::EliminateTuples(&typeMap), new P4::ConstantFolding(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), // Perform a last round of type-checking before passes which do not type-check begin. new P4::TypeChecking(&refMap, &typeMap, true), }); diff --git a/backends/tc/midend.cpp b/backends/tc/midend.cpp index f941660c9ee..c29a72b0a9a 100644 --- a/backends/tc/midend.cpp +++ b/backends/tc/midend.cpp @@ -31,7 +31,7 @@ const IR::ToplevelBlock *MidEnd::run(TCOptions &options, const IR::P4Program *pr new P4::EliminateInvalidHeaders(&typeMap), new P4::EliminateNewtype(&typeMap), new P4::EliminateSerEnums(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::SimplifyKey(&typeMap, new P4::OrPolicy(new P4::IsValid(&typeMap), new P4::IsLikeLeftValue())), new P4::RemoveExits(&typeMap), @@ -56,7 +56,7 @@ const IR::ToplevelBlock *MidEnd::run(TCOptions &options, const IR::P4Program *pr new P4::RemoveSelectBooleans(&typeMap), new P4::SingleArgumentSelect(&typeMap), new P4::ConstantFolding(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::TableHit(&typeMap), new P4::RemoveLeftSlices(&typeMap), new EBPF::Lower(&refMap, &typeMap), diff --git a/backends/tofino/bf-p4c/midend/elim_cast.h b/backends/tofino/bf-p4c/midend/elim_cast.h index 349eb3a006e..f9395ebcee5 100644 --- a/backends/tofino/bf-p4c/midend/elim_cast.h +++ b/backends/tofino/bf-p4c/midend/elim_cast.h @@ -243,7 +243,7 @@ class ElimCasts : public PassManager { new RewriteConcatToSlices(), new P4::ClearTypeMap(typeMap), new BFN::TypeChecking(refMap, typeMap, true), - new P4::SimplifyControlFlow(typeMap), + new P4::SimplifyControlFlow(typeMap, true), new P4::ClearTypeMap(typeMap), new BFN::TypeChecking(refMap, typeMap, true), }); diff --git a/backends/tofino/bf-p4c/midend/simplifyIfStatement.h b/backends/tofino/bf-p4c/midend/simplifyIfStatement.h index e28ba350796..a2c4a763af3 100644 --- a/backends/tofino/bf-p4c/midend/simplifyIfStatement.h +++ b/backends/tofino/bf-p4c/midend/simplifyIfStatement.h @@ -70,7 +70,7 @@ class SimplifyIfStatement : public PassManager { public: SimplifyIfStatement(ReferenceMap *refMap, TypeMap *typeMap) { passes.push_back(new ElimCallExprInIfCond(refMap, typeMap)); - passes.push_back(new SimplifyControlFlow(typeMap)); + passes.push_back(new SimplifyControlFlow(typeMap, true)); } }; diff --git a/backends/ubpf/midend.cpp b/backends/ubpf/midend.cpp index ec7e3605351..0f59fc1c891 100644 --- a/backends/ubpf/midend.cpp +++ b/backends/ubpf/midend.cpp @@ -80,7 +80,7 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program * new P4::ClearTypeMap(&typeMap), new P4::EliminateNewtype(&typeMap), new P4::EliminateInvalidHeaders(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::SimplifyKey( &typeMap, new P4::OrPolicy(new P4::IsValid(&typeMap), new P4::IsLikeLeftValue())), new P4::ConstantFolding(&typeMap), @@ -100,7 +100,7 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program * new P4::RemoveSelectBooleans(&typeMap), new P4::SingleArgumentSelect(&typeMap), new P4::ConstantFolding(&typeMap), - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::TableHit(&typeMap), new P4::RemoveLeftSlices(&typeMap), new EBPF::Lower(&refMap, &typeMap), diff --git a/frontends/p4/actionsInlining.cpp b/frontends/p4/actionsInlining.cpp index 73b3c064035..d19150b5af7 100644 --- a/frontends/p4/actionsInlining.cpp +++ b/frontends/p4/actionsInlining.cpp @@ -92,11 +92,10 @@ const IR::Node *ActionsInliner::preorder(IR::MethodCallStatement *statement) { cstring newName = nameGen->newName(param->name.name.string_view()); paramRename.emplace(param, newName); if (param->direction == IR::Direction::In || param->direction == IR::Direction::InOut) { - const auto *vardecl = new IR::Declaration_Variable(newName, param->annotations, - param->type, argument->expression); + const auto *vardecl = new IR::Declaration_Variable( + argument->srcInfo, newName, param->annotations, param->type, argument->expression); body.push_back(vardecl); - subst.add(param, new IR::Argument(argument->srcInfo, argument->name, - new IR::PathExpression(newName))); + subst.add(param, new IR::Argument(argument->name, new IR::PathExpression(newName))); } else if (param->direction == IR::Direction::None) { // This works because there can be no side-effects in the evaluation of this // argument. @@ -108,10 +107,9 @@ const IR::Node *ActionsInliner::preorder(IR::MethodCallStatement *statement) { subst.add(param, argument); } else if (param->direction == IR::Direction::Out) { // uninitialized variable - const auto *vardecl = - new IR::Declaration_Variable(newName, param->annotations, param->type); - subst.add(param, new IR::Argument(argument->srcInfo, argument->name, - new IR::PathExpression(newName))); + const auto *vardecl = new IR::Declaration_Variable(argument->srcInfo, newName, + param->annotations, param->type); + subst.add(param, new IR::Argument(argument->name, new IR::PathExpression(newName))); body.push_back(vardecl); } } @@ -136,17 +134,22 @@ const IR::Node *ActionsInliner::preorder(IR::MethodCallStatement *statement) { if (param->direction == IR::Direction::InOut || param->direction == IR::Direction::Out) { cstring newName = ::P4::get(paramRename, param); auto right = new IR::PathExpression(newName); - auto copyout = new IR::AssignmentStatement(left->expression, right); + // FIXME: Technically, location should be just after the call + auto copyout = new IR::AssignmentStatement(statement->srcInfo, left->expression, right); body.push_back(copyout); } } - auto annotations = callee->annotations.where([&](const IR::Annotation *a) { - return !(a->name == IR::Annotation::nameAnnotation || - (a->name == IR::Annotation::noWarnAnnotation && a->getSingleString() == "unused")); - }); - auto result = new IR::BlockStatement(statement->srcInfo, - {annotations->begin(), annotations->end()}, body); + IR::Vector annotations = + callee->annotations.where([&](const IR::Annotation *a) { + return !( + a->name == IR::Annotation::nameAnnotation || + (a->name == IR::Annotation::noWarnAnnotation && a->getSingleString() == "unused")); + }); + annotations.push_back(new IR::Annotation(statement->srcInfo, + IR::Annotation::inlinedFromAnnotation, + {new IR::StringLiteral(callee->name.originalName)})); + auto result = new IR::BlockStatement(statement->srcInfo, annotations, body); LOG2("Replacing " << orig << " with " << result); return result; } diff --git a/frontends/p4/frontend.cpp b/frontends/p4/frontend.cpp index bbeaa5bd515..f3539ef7bd7 100644 --- a/frontends/p4/frontend.cpp +++ b/frontends/p4/frontend.cpp @@ -207,7 +207,7 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P new Reassociation(), new UselessCasts(&typeMap), }), - new SimplifyControlFlow(&typeMap), + new SimplifyControlFlow(&typeMap, policy->foldInlinedFrom()), new SwitchAddDefault, new FrontEndDump(), // used for testing the program at this point new RemoveAllUnusedDeclarations(*policy, true), @@ -218,12 +218,12 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P new MoveInitializers(), new SideEffectOrdering(&typeMap, policy->skipSideEffectOrdering()), policy->removeOpAssign() ? new RemoveOpAssign() : nullptr, - new SimplifyControlFlow(&typeMap), + new SimplifyControlFlow(&typeMap, policy->foldInlinedFrom()), new SimplifySwitch(&typeMap), new MoveDeclarations(), // Move all local declarations to the beginning new SimplifyDefUse(&typeMap), new UniqueParameters(&typeMap), - new SimplifyControlFlow(&typeMap), + new SimplifyControlFlow(&typeMap, policy->foldInlinedFrom()), new SpecializeAll(&typeMap, policy), new RemoveParserControlFlow(&typeMap), new RemoveReturns(), @@ -259,14 +259,14 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P // Check for constants only after inlining new CheckConstants(&typeMap), new ConstantFolding(&typeMap, constantFoldingPolicy), - new SimplifyControlFlow(&typeMap), + new SimplifyControlFlow(&typeMap, policy->foldInlinedFrom()), // more ifs may have been added to parsers new RemoveParserControlFlow(&typeMap), new UniqueNames(), // needed again after inlining new MoveDeclarations(), // needed again after inlining new SimplifyDefUse(&typeMap), new RemoveAllUnusedDeclarations(*policy), - new SimplifyControlFlow(&typeMap), + new SimplifyControlFlow(&typeMap, policy->foldInlinedFrom()), }); } passes.addPasses({ diff --git a/frontends/p4/frontend.h b/frontends/p4/frontend.h index 8b1ddf257e7..790ece24103 100644 --- a/frontends/p4/frontend.h +++ b/frontends/p4/frontend.h @@ -53,6 +53,10 @@ class FrontEndPolicy : public RemoveUnusedPolicy { // TODO: This should probably not be allowed to be skipped at all. virtual bool skipSideEffectOrdering() const { return false; } + /// Indicates whether control flow should fold blocks marked with @inlinedFrom annotation + /// @returns Defaults to true + virtual bool foldInlinedFrom() const { return true; } + /// Indicates whether to enable the `a - constant` to `a + (-constant)` in StrengthReduction. /// @returns Defaults to true. virtual bool enableSubConstToAddTransform() const { return true; } diff --git a/frontends/p4/functionsInlining.cpp b/frontends/p4/functionsInlining.cpp index 525f569e11a..be049d3fdb5 100644 --- a/frontends/p4/functionsInlining.cpp +++ b/frontends/p4/functionsInlining.cpp @@ -276,13 +276,13 @@ const IR::Statement *FunctionsInliner::inlineBefore(const IR::Node *calleeNode, subst.add(param, argument); } else if (param->direction == IR::Direction::In || param->direction == IR::Direction::InOut) { - auto vardecl = new IR::Declaration_Variable(newName, param->annotations, param->type); + auto vardecl = new IR::Declaration_Variable(argument->srcInfo, newName, + param->annotations, param->type); body.push_back(vardecl); auto copyin = new IR::AssignmentStatement(new IR::PathExpression(newName), argument->expression); body.push_back(copyin); - subst.add(param, new IR::Argument(argument->srcInfo, argument->name, - new IR::PathExpression(newName))); + subst.add(param, new IR::Argument(argument->name, new IR::PathExpression(newName))); if (param->direction == IR::Direction::InOut) needCopyout.emplace_back(newName, argument); } else if (param->direction == IR::Direction::None) { @@ -291,9 +291,9 @@ const IR::Statement *FunctionsInliner::inlineBefore(const IR::Node *calleeNode, subst.add(param, argument); } else if (param->direction == IR::Direction::Out) { // uninitialized variable - auto vardecl = new IR::Declaration_Variable(newName, param->annotations, param->type); - subst.add(param, new IR::Argument(argument->srcInfo, argument->name, - new IR::PathExpression(newName))); + auto vardecl = new IR::Declaration_Variable(argument->srcInfo, newName, + param->annotations, param->type); + subst.add(param, new IR::Argument(argument->name, new IR::PathExpression(newName))); body.push_back(vardecl); needCopyout.emplace_back(newName, argument); } @@ -344,7 +344,10 @@ const IR::Statement *FunctionsInliner::inlineBefore(const IR::Node *calleeNode, // ignore the returned value. } - auto result = new IR::BlockStatement(statement->srcInfo, body); + IR::Vector annotations( + {new IR::Annotation(statement->srcInfo, IR::Annotation::inlinedFromAnnotation, + {new IR::StringLiteral(callee->name.originalName)})}); + auto result = new IR::BlockStatement(statement->srcInfo, annotations, body); LOG2("Replacing " << dbp(statement) << " with " << dbp(result)); return result; } diff --git a/frontends/p4/parserControlFlow.h b/frontends/p4/parserControlFlow.h index b749c35252d..a1958c6b987 100644 --- a/frontends/p4/parserControlFlow.h +++ b/frontends/p4/parserControlFlow.h @@ -90,7 +90,7 @@ class RemoveParserControlFlow : public PassRepeated { public: explicit RemoveParserControlFlow(TypeMap *typeMap) : PassRepeated({}) { passes.emplace_back(new DoRemoveParserControlFlow()); - passes.emplace_back(new SimplifyControlFlow(typeMap)); + passes.emplace_back(new SimplifyControlFlow(typeMap, false)); setName("RemoveParserControlFlow"); } }; diff --git a/frontends/p4/simplify.cpp b/frontends/p4/simplify.cpp index f03034d29e6..f2713c9c312 100644 --- a/frontends/p4/simplify.cpp +++ b/frontends/p4/simplify.cpp @@ -23,7 +23,9 @@ namespace P4 { const IR::Node *DoSimplifyControlFlow::postorder(IR::BlockStatement *statement) { LOG3("Visiting " << dbp(getOriginal())); - if (statement->hasAnnotations()) return statement; + if (statement->hasAnnotations() && + !(foldInlinedFrom && statement->hasOnlyAnnotation(IR::Annotation::inlinedFromAnnotation))) + return statement; auto parent = getContext()->node; CHECK_NULL(parent); if (parent->is() || parent->is() || parent->is() || diff --git a/frontends/p4/simplify.h b/frontends/p4/simplify.h index 620f3261f2d..c6d36dccb4f 100644 --- a/frontends/p4/simplify.h +++ b/frontends/p4/simplify.h @@ -50,9 +50,11 @@ namespace P4 { */ class DoSimplifyControlFlow : public Transform, public ResolutionContext { TypeMap *typeMap; + bool foldInlinedFrom; public: - explicit DoSimplifyControlFlow(TypeMap *typeMap) : typeMap(typeMap) { + explicit DoSimplifyControlFlow(TypeMap *typeMap, bool foldInlinedFrom) + : typeMap(typeMap), foldInlinedFrom(foldInlinedFrom) { CHECK_NULL(typeMap); setName("DoSimplifyControlFlow"); // We may want to replace the same statement with different things @@ -69,10 +71,11 @@ class DoSimplifyControlFlow : public Transform, public ResolutionContext { /// steps enable further simplification. class SimplifyControlFlow : public PassRepeated { public: - explicit SimplifyControlFlow(TypeMap *typeMap, TypeChecking *typeChecking = nullptr) { + explicit SimplifyControlFlow(TypeMap *typeMap, bool foldInlinedFrom, + TypeChecking *typeChecking = nullptr) { if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap); passes.push_back(typeChecking); - passes.push_back(new DoSimplifyControlFlow(typeMap)); + passes.push_back(new DoSimplifyControlFlow(typeMap, foldInlinedFrom)); setName("SimplifyControlFlow"); } }; diff --git a/ir/annotations.cpp b/ir/annotations.cpp index 2401dbdba5a..9dc6a186ae1 100644 --- a/ir/annotations.cpp +++ b/ir/annotations.cpp @@ -38,6 +38,7 @@ const cstring IR::Annotation::matchAnnotation = "match"_cs; const cstring IR::Annotation::fieldListAnnotation = "field_list"_cs; const cstring IR::Annotation::debugLoggingAnnotation = "__debug"_cs; const cstring IR::Annotation::disableOptimizationAnnotation = "disable_optimization"_cs; +const cstring IR::Annotation::inlinedFromAnnotation = "inlinedFrom"_cs; namespace Annotations { void addIfNew(Vector &annotations, cstring name, const Expression *expr, diff --git a/ir/base.def b/ir/base.def index 4ddcade848b..07c768d3250 100644 --- a/ir/base.def +++ b/ir/base.def @@ -290,6 +290,7 @@ class Annotation { static const cstring fieldListAnnotation; /// Used for recirculate, etc. static const cstring debugLoggingAnnotation; /// Used by compiler implementer to limit debug log to the annotated IR context. static const cstring disableOptimizationAnnotation; /// annotation to disable certain optimization + static const cstring inlinedFromAnnotation; /// annotation to mark block of inlined function toString{ return absl::StrCat("@", name); } validate{ diff --git a/midend/parserUnroll.h b/midend/parserUnroll.h index a76772ad9a6..38630a951ab 100644 --- a/midend/parserUnroll.h +++ b/midend/parserUnroll.h @@ -298,7 +298,7 @@ class ParsersUnroll : public PassManager { public: ParsersUnroll(bool unroll, ReferenceMap *refMap, TypeMap *typeMap) { // remove block statements - passes.push_back(new SimplifyControlFlow(typeMap)); + passes.push_back(new SimplifyControlFlow(typeMap, false)); passes.push_back(new TypeChecking(refMap, typeMap)); passes.push_back(new RewriteAllParsers(refMap, typeMap, unroll)); setName("ParsersUnroll"); diff --git a/test/gtest/midend_pass.cpp b/test/gtest/midend_pass.cpp index d6752ee7ae0..72495868662 100644 --- a/test/gtest/midend_pass.cpp +++ b/test/gtest/midend_pass.cpp @@ -99,7 +99,7 @@ MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) { new P4::ConstantFolding(&typeMap), new P4::StrengthReduction(&typeMap), new P4::MoveDeclarations(), // more may have been introduced - new P4::SimplifyControlFlow(&typeMap), + new P4::SimplifyControlFlow(&typeMap, true), new P4::CompileTimeOperations(), new P4::TableHit(&typeMap), new P4::EliminateSwitch(&typeMap), diff --git a/testdata/p4_16_samples_outputs/fabric_20190420/fabric-frontend.p4 b/testdata/p4_16_samples_outputs/fabric_20190420/fabric-frontend.p4 index 2b2fb43c3a5..416f89e4b55 100644 --- a/testdata/p4_16_samples_outputs/fabric_20190420/fabric-frontend.p4 +++ b/testdata/p4_16_samples_outputs/fabric_20190420/fabric-frontend.p4 @@ -401,7 +401,7 @@ control FabricIngress(inout parsed_headers_t hdr, inout fabric_metadata_t fabric } @name("FabricIngress.forwarding.bridging_counter") direct_counter(CounterType.packets_and_bytes) forwarding_bridging_counter; @name("FabricIngress.forwarding.set_next_id_bridging") action forwarding_set_next_id_bridging_0(@name("next_id") next_id_t next_id_0) { - @hidden { + @hidden @inlinedFrom("forwarding_set_next_id") { fabric_metadata.next_id = next_id_0; } forwarding_bridging_counter.count(); @@ -422,7 +422,7 @@ control FabricIngress(inout parsed_headers_t hdr, inout fabric_metadata_t fabric @name("FabricIngress.forwarding.mpls_counter") direct_counter(CounterType.packets_and_bytes) forwarding_mpls_counter; @name("FabricIngress.forwarding.pop_mpls_and_next") action forwarding_pop_mpls_and_next_0(@name("next_id") next_id_t next_id_6) { fabric_metadata.mpls_label = 20w0; - @hidden { + @hidden @inlinedFrom("forwarding_set_next_id") { fabric_metadata.next_id = next_id_6; } forwarding_mpls_counter.count(); @@ -441,7 +441,7 @@ control FabricIngress(inout parsed_headers_t hdr, inout fabric_metadata_t fabric } @name("FabricIngress.forwarding.routing_v4_counter") direct_counter(CounterType.packets_and_bytes) forwarding_routing_v4_counter; @name("FabricIngress.forwarding.set_next_id_routing_v4") action forwarding_set_next_id_routing_v4_0(@name("next_id") next_id_t next_id_7) { - @hidden { + @hidden @inlinedFrom("forwarding_set_next_id") { fabric_metadata.next_id = next_id_7; } forwarding_routing_v4_counter.count(); @@ -529,7 +529,7 @@ control FabricIngress(inout parsed_headers_t hdr, inout fabric_metadata_t fabric } @name("FabricIngress.next.xconnect_counter") direct_counter(CounterType.packets_and_bytes) next_xconnect_counter; @name("FabricIngress.next.output_xconnect") action next_output_xconnect_0(@name("port_num") port_num_t port_num) { - @hidden { + @hidden @inlinedFrom("next_output") { standard_metadata.egress_spec = port_num; } next_xconnect_counter.count(); @@ -555,38 +555,38 @@ control FabricIngress(inout parsed_headers_t hdr, inout fabric_metadata_t fabric @max_group_size(16) @name("FabricIngress.next.hashed_selector") action_selector(HashAlgorithm.crc16, 32w1024, 32w16) next_hashed_selector; @name("FabricIngress.next.hashed_counter") direct_counter(CounterType.packets_and_bytes) next_hashed_counter; @name("FabricIngress.next.output_hashed") action next_output_hashed_0(@name("port_num") port_num_t port_num_0) { - @hidden { + @hidden @inlinedFrom("next_output") { standard_metadata.egress_spec = port_num_0; } next_hashed_counter.count(); } @name("FabricIngress.next.routing_hashed") action next_routing_hashed_0(@name("port_num") port_num_t port_num_1, @name("smac") mac_addr_t smac, @name("dmac") mac_addr_t dmac) { - @hidden { - @hidden { + @hidden @inlinedFrom("next_routing") { + @hidden @inlinedFrom("next_rewrite_smac") { hdr.ethernet.src_addr = smac; } - @hidden { + @hidden @inlinedFrom("next_rewrite_dmac") { hdr.ethernet.dst_addr = dmac; } - @hidden { + @hidden @inlinedFrom("next_output") { standard_metadata.egress_spec = port_num_1; } } next_hashed_counter.count(); } @name("FabricIngress.next.mpls_routing_hashed") action next_mpls_routing_hashed_0(@name("port_num") port_num_t port_num_2, @name("smac") mac_addr_t smac_0, @name("dmac") mac_addr_t dmac_0, @name("label") mpls_label_t label_0) { - @hidden { - @hidden { + @hidden @inlinedFrom("next_mpls_routing") { + @hidden @inlinedFrom("next_set_mpls_label") { fabric_metadata.mpls_label = label_0; } - @hidden { - @hidden { + @hidden @inlinedFrom("next_routing") { + @hidden @inlinedFrom("next_rewrite_smac") { hdr.ethernet.src_addr = smac_0; } - @hidden { + @hidden @inlinedFrom("next_rewrite_dmac") { hdr.ethernet.dst_addr = dmac_0; } - @hidden { + @hidden @inlinedFrom("next_output") { standard_metadata.egress_spec = port_num_2; } } diff --git a/testdata/p4_16_samples_outputs/inline-function2-frontend.p4 b/testdata/p4_16_samples_outputs/inline-function2-frontend.p4 index 4d92af853f5..9752cb82598 100644 --- a/testdata/p4_16_samples_outputs/inline-function2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/inline-function2-frontend.p4 @@ -19,7 +19,7 @@ control p(inout bit<1> bt) { y2_0 = tmp; if (y2_0 == 1w1) { y0 = 1w0; - } else { + } else @inlinedFrom("foo") { a_2 = bt; retval_1 = a_2 + 1w1; if (retval_1 != 1w1) { diff --git a/testdata/p4_16_samples_outputs/omec/up4-frontend.p4 b/testdata/p4_16_samples_outputs/omec/up4-frontend.p4 index c8876a1f3c6..f296216b88a 100644 --- a/testdata/p4_16_samples_outputs/omec/up4-frontend.p4 +++ b/testdata/p4_16_samples_outputs/omec/up4-frontend.p4 @@ -470,7 +470,7 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta const default_action = do_drop_1(); } @name("PreQosPipe.uplink_term_fwd") action uplink_term_fwd(@name("ctr_idx") counter_index_t ctr_idx_0, @name("tc") TrafficClass tc_2, @name("app_meter_idx") app_meter_idx_t app_meter_idx) { - @hidden { + @hidden @inlinedFrom("common_term") { local_meta.ctr_idx = ctr_idx_0; local_meta.terminations_hit = true; } @@ -478,14 +478,14 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta local_meta.tc = tc_2; } @name("PreQosPipe.uplink_term_drop") action uplink_term_drop(@name("ctr_idx") counter_index_t ctr_idx_5) { - @hidden { + @hidden @inlinedFrom("common_term") { local_meta.ctr_idx = ctr_idx_5; local_meta.terminations_hit = true; } local_meta.needs_dropping = true; } @name("PreQosPipe.downlink_term_fwd") action downlink_term_fwd(@name("ctr_idx") counter_index_t ctr_idx_6, @name("teid") teid_t teid_1, @name("qfi") qfi_t qfi_1, @name("tc") TrafficClass tc_3, @name("app_meter_idx") app_meter_idx_t app_meter_idx_2) { - @hidden { + @hidden @inlinedFrom("common_term") { local_meta.ctr_idx = ctr_idx_6; local_meta.terminations_hit = true; } @@ -495,7 +495,7 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta local_meta.tc = tc_3; } @name("PreQosPipe.downlink_term_drop") action downlink_term_drop(@name("ctr_idx") counter_index_t ctr_idx_7) { - @hidden { + @hidden @inlinedFrom("common_term") { local_meta.ctr_idx = ctr_idx_7; local_meta.terminations_hit = true; } @@ -557,7 +557,7 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta default_action = NoAction_2(); } @name("PreQosPipe.do_gtpu_tunnel") action do_gtpu_tunnel() { - @hidden { + @hidden @inlinedFrom("_udp_encap") { hdr.inner_udp = hdr.udp; hdr.udp.setInvalid(); hdr.inner_tcp = hdr.tcp; @@ -585,7 +585,7 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta hdr.ipv4.dst_addr = local_meta.tunnel_out_dst_ipv4_addr; hdr.ipv4.checksum = 16w0; } - @hidden { + @hidden @inlinedFrom("_gtpu_encap") { hdr.gtpu.setValid(); hdr.gtpu.version = 3w0x1; hdr.gtpu.pt = 1w0x1; @@ -599,7 +599,7 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta } } @name("PreQosPipe.do_gtpu_tunnel_with_psc") action do_gtpu_tunnel_with_psc() { - @hidden { + @hidden @inlinedFrom("_udp_encap") { hdr.inner_udp = hdr.udp; hdr.udp.setInvalid(); hdr.inner_tcp = hdr.tcp; @@ -627,7 +627,7 @@ control PreQosPipe(inout parsed_headers_t hdr, inout local_metadata_t local_meta hdr.ipv4.dst_addr = local_meta.tunnel_out_dst_ipv4_addr; hdr.ipv4.checksum = 16w0; } - @hidden { + @hidden @inlinedFrom("_gtpu_encap") { hdr.gtpu.setValid(); hdr.gtpu.version = 3w0x1; hdr.gtpu.pt = 1w0x1; diff --git a/testdata/p4_16_samples_outputs/pins/pins_fabric-frontend.p4 b/testdata/p4_16_samples_outputs/pins/pins_fabric-frontend.p4 index f6d4553dd26..1d2353385a0 100644 --- a/testdata/p4_16_samples_outputs/pins/pins_fabric-frontend.p4 +++ b/testdata/p4_16_samples_outputs/pins/pins_fabric-frontend.p4 @@ -647,14 +647,14 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.wcmp_group_id_value = wcmp_group_id_2; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_0(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") wcmp_group_id_t wcmp_group_id_3, @name("route_metadata") route_metadata_t route_metadata_3) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata.wcmp_group_id_valid = true; local_metadata.wcmp_group_id_value = wcmp_group_id_3; } local_metadata.route_metadata = route_metadata_3; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_1(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") wcmp_group_id_t wcmp_group_id_4, @name("route_metadata") route_metadata_t route_metadata_4) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata.wcmp_group_id_valid = true; local_metadata.wcmp_group_id_value = wcmp_group_id_4; } @@ -758,7 +758,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.marked_to_copy = true; } @id(0x01000102) @sai_action(SAI_PACKET_ACTION_TRAP , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_DROP , SAI_PACKET_COLOR_RED) @name("ingress.acl_ingress.acl_trap") action acl_ingress_acl_trap_0(@sai_action_param(QOS_QUEUE) @id(1) @name("qos_queue") qos_queue_t qos_queue_3) { - @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) { + @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) @inlinedFrom("acl_ingress_acl_copy") { acl_ingress_acl_ingress_counter.count(); acl_ingress_acl_ingress_meter.read(local_metadata.color); local_metadata.marked_to_copy = true; @@ -968,7 +968,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, @id(0x01000002) @name("ingress.routing_resolution.set_port_and_src_mac") action routing_resolution_set_port_and_src_mac_0(@id(1) @name("port") port_id_t port_3, @id(2) @format(MAC_ADDRESS) @name("src_mac") ethernet_addr_t src_mac_5) { @id(0x0100001B) @unsupported @action_restriction(" // Disallow reserved VLAN IDs with implementation-defined semantics. - vlan_id != 0 && vlan_id != 4095") { + vlan_id != 0 && vlan_id != 4095") @inlinedFrom("routing_resolution_set_port_and_src_mac_and_vlan_id") { standard_metadata.egress_spec = (bit<9>)port_3; local_metadata.packet_rewrites.src_mac = src_mac_5; local_metadata.packet_rewrites.vlan_id = 12w0xfff; @@ -997,7 +997,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.enable_vlan_rewrite = !(bool)disable_vlan_rewrite; } @id(0x01000014) @name("ingress.routing_resolution.set_ip_nexthop") action routing_resolution_set_ip_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") router_interface_id_t router_interface_id_4, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") ipv6_addr_t neighbor_id_3) { - @id(0x01000017) { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_4; routing_resolution_neighbor_id_valid = true; @@ -1009,8 +1009,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, } } @id(0x01000003) @deprecated("Use set_ip_nexthop instead.") @name("ingress.routing_resolution.set_nexthop") action routing_resolution_set_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") router_interface_id_t router_interface_id_5, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") ipv6_addr_t neighbor_id_4) { - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_5; routing_resolution_neighbor_id_valid = true; @@ -1044,8 +1044,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.tunnel_encap_src_ipv6 = encap_src_ip; local_metadata.tunnel_encap_dst_ipv6 = encap_dst_ip; local_metadata.apply_tunnel_encap_at_egress = true; - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_6; routing_resolution_neighbor_id_valid = true; diff --git a/testdata/p4_16_samples_outputs/pins/pins_fabric-midend.p4 b/testdata/p4_16_samples_outputs/pins/pins_fabric-midend.p4 index ad18c6b7f6b..12e68e67211 100644 --- a/testdata/p4_16_samples_outputs/pins/pins_fabric-midend.p4 +++ b/testdata/p4_16_samples_outputs/pins/pins_fabric-midend.p4 @@ -646,14 +646,14 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._wcmp_group_id_value38 = wcmp_group_id_2; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_0(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") bit<12> wcmp_group_id_3, @name("route_metadata") bit<6> route_metadata_3) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata._wcmp_group_id_valid37 = true; local_metadata._wcmp_group_id_value38 = wcmp_group_id_3; } local_metadata._route_metadata34 = route_metadata_3; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_1(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") bit<12> wcmp_group_id_4, @name("route_metadata") bit<6> route_metadata_4) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata._wcmp_group_id_valid37 = true; local_metadata._wcmp_group_id_value38 = wcmp_group_id_4; } @@ -757,7 +757,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._marked_to_copy18 = true; } @id(0x01000102) @sai_action(SAI_PACKET_ACTION_TRAP , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_DROP , SAI_PACKET_COLOR_RED) @name("ingress.acl_ingress.acl_trap") action acl_ingress_acl_trap_0(@sai_action_param(QOS_QUEUE) @id(1) @name("qos_queue") bit<8> qos_queue_3) { - @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) { + @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) @inlinedFrom("acl_ingress_acl_copy") { acl_ingress_acl_ingress_counter.count(); acl_ingress_acl_ingress_meter.read(local_metadata._color32); local_metadata._marked_to_copy18 = true; @@ -967,7 +967,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, @id(0x01000002) @name("ingress.routing_resolution.set_port_and_src_mac") action routing_resolution_set_port_and_src_mac_0(@id(1) @name("port") bit<9> port_3, @id(2) @format(MAC_ADDRESS) @name("src_mac") bit<48> src_mac_5) { @id(0x0100001B) @unsupported @action_restriction(" // Disallow reserved VLAN IDs with implementation-defined semantics. - vlan_id != 0 && vlan_id != 4095") { + vlan_id != 0 && vlan_id != 4095") @inlinedFrom("routing_resolution_set_port_and_src_mac_and_vlan_id") { standard_metadata.egress_spec = (bit<9>)port_3; local_metadata._packet_rewrites_src_mac8 = src_mac_5; local_metadata._packet_rewrites_vlan_id10 = 12w0xfff; @@ -996,7 +996,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._enable_vlan_rewrite7 = !(bool)disable_vlan_rewrite; } @id(0x01000014) @name("ingress.routing_resolution.set_ip_nexthop") action routing_resolution_set_ip_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") bit<10> router_interface_id_4, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") bit<128> neighbor_id_3) { - @id(0x01000017) { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_4; routing_resolution_neighbor_id_valid = true; @@ -1008,8 +1008,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, } } @id(0x01000003) @deprecated("Use set_ip_nexthop instead.") @name("ingress.routing_resolution.set_nexthop") action routing_resolution_set_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") bit<10> router_interface_id_5, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") bit<128> neighbor_id_4) { - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_5; routing_resolution_neighbor_id_valid = true; @@ -1043,8 +1043,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._tunnel_encap_src_ipv616 = encap_src_ip; local_metadata._tunnel_encap_dst_ipv617 = encap_dst_ip; local_metadata._apply_tunnel_encap_at_egress15 = true; - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_6; routing_resolution_neighbor_id_valid = true; diff --git a/testdata/p4_16_samples_outputs/pins/pins_middleblock-first.p4 b/testdata/p4_16_samples_outputs/pins/pins_middleblock-first.p4 index c2ce74b395b..baa4fd1b0e2 100644 --- a/testdata/p4_16_samples_outputs/pins/pins_middleblock-first.p4 +++ b/testdata/p4_16_samples_outputs/pins/pins_middleblock-first.p4 @@ -1259,7 +1259,7 @@ control acl_ingress(in headers_t headers, inout local_metadata_t local_metadata, is_ipv6::mask != 0 -> (is_ipv6 == 1); // Only allow icmp_type matches for ICMP packets icmpv6_type::mask != 0 -> ip_protocol == 58; -# 369 " .. / .. / .. / .. / pins - infra / sai_p4 / instantiations / google / acl_ingress . p4 " + # 369 " .. / .. / .. / .. / pins - infra / sai_p4 / instantiations / google / acl_ingress . p4 " ") @name("acl_ingress_qos_table") table acl_ingress_qos_table_0 { key = { headers.ipv4.isValid() || headers.ipv6.isValid(): optional @id(1) @name("is_ip") @sai_field(SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE / IP); diff --git a/testdata/p4_16_samples_outputs/pins/pins_middleblock-frontend.p4 b/testdata/p4_16_samples_outputs/pins/pins_middleblock-frontend.p4 index 66f962fb00f..4db02ca5b11 100644 --- a/testdata/p4_16_samples_outputs/pins/pins_middleblock-frontend.p4 +++ b/testdata/p4_16_samples_outputs/pins/pins_middleblock-frontend.p4 @@ -640,14 +640,14 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.wcmp_group_id_value = wcmp_group_id_2; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_0(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") wcmp_group_id_t wcmp_group_id_3, @name("route_metadata") route_metadata_t route_metadata_3) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata.wcmp_group_id_valid = true; local_metadata.wcmp_group_id_value = wcmp_group_id_3; } local_metadata.route_metadata = route_metadata_3; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_1(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") wcmp_group_id_t wcmp_group_id_4, @name("route_metadata") route_metadata_t route_metadata_4) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata.wcmp_group_id_valid = true; local_metadata.wcmp_group_id_value = wcmp_group_id_4; } @@ -751,7 +751,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.marked_to_copy = true; } @id(0x01000102) @sai_action(SAI_PACKET_ACTION_TRAP , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_DROP , SAI_PACKET_COLOR_RED) @name("ingress.acl_ingress.acl_trap") action acl_ingress_acl_trap_0(@sai_action_param(QOS_QUEUE) @id(1) @name("qos_queue") qos_queue_t qos_queue_2) { - @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) { + @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) @inlinedFrom("acl_ingress_acl_copy") { acl_ingress_acl_ingress_counter.count(); acl_ingress_acl_ingress_meter.read(local_metadata.color); local_metadata.marked_to_copy = true; @@ -966,7 +966,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, @id(0x01000002) @name("ingress.routing_resolution.set_port_and_src_mac") action routing_resolution_set_port_and_src_mac_0(@id(1) @name("port") port_id_t port_3, @id(2) @format(MAC_ADDRESS) @name("src_mac") ethernet_addr_t src_mac_5) { @id(0x0100001B) @unsupported @action_restriction(" // Disallow reserved VLAN IDs with implementation-defined semantics. - vlan_id != 0 && vlan_id != 4095") { + vlan_id != 0 && vlan_id != 4095") @inlinedFrom("routing_resolution_set_port_and_src_mac_and_vlan_id") { standard_metadata.egress_spec = (bit<9>)port_3; local_metadata.packet_rewrites.src_mac = src_mac_5; local_metadata.packet_rewrites.vlan_id = 12w0xfff; @@ -995,7 +995,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.enable_vlan_rewrite = !(bool)disable_vlan_rewrite; } @id(0x01000014) @name("ingress.routing_resolution.set_ip_nexthop") action routing_resolution_set_ip_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") router_interface_id_t router_interface_id_4, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") ipv6_addr_t neighbor_id_3) { - @id(0x01000017) { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_4; routing_resolution_neighbor_id_valid = true; @@ -1007,8 +1007,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, } } @id(0x01000003) @deprecated("Use set_ip_nexthop instead.") @name("ingress.routing_resolution.set_nexthop") action routing_resolution_set_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") router_interface_id_t router_interface_id_5, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") ipv6_addr_t neighbor_id_4) { - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_5; routing_resolution_neighbor_id_valid = true; @@ -1042,8 +1042,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata.tunnel_encap_src_ipv6 = encap_src_ip; local_metadata.tunnel_encap_dst_ipv6 = encap_dst_ip; local_metadata.apply_tunnel_encap_at_egress = true; - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_6; routing_resolution_neighbor_id_valid = true; diff --git a/testdata/p4_16_samples_outputs/pins/pins_middleblock-midend.p4 b/testdata/p4_16_samples_outputs/pins/pins_middleblock-midend.p4 index 10d236ba4d0..0fd3cad4541 100644 --- a/testdata/p4_16_samples_outputs/pins/pins_middleblock-midend.p4 +++ b/testdata/p4_16_samples_outputs/pins/pins_middleblock-midend.p4 @@ -640,14 +640,14 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._wcmp_group_id_value38 = wcmp_group_id_2; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_0(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") bit<12> wcmp_group_id_3, @name("route_metadata") bit<6> route_metadata_3) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata._wcmp_group_id_valid37 = true; local_metadata._wcmp_group_id_value38 = wcmp_group_id_3; } local_metadata._route_metadata34 = route_metadata_3; } @id(0x01000011) @name("ingress.routing_lookup.set_wcmp_group_id_and_metadata") action routing_lookup_set_wcmp_group_id_and_metadata_1(@id(1) @refers_to(wcmp_group_table , wcmp_group_id) @name("wcmp_group_id") bit<12> wcmp_group_id_4, @name("route_metadata") bit<6> route_metadata_4) { - @id(0x01000004) { + @id(0x01000004) @inlinedFrom("routing_lookup_set_wcmp_group_id") { local_metadata._wcmp_group_id_valid37 = true; local_metadata._wcmp_group_id_value38 = wcmp_group_id_4; } @@ -751,7 +751,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._marked_to_copy18 = true; } @id(0x01000102) @sai_action(SAI_PACKET_ACTION_TRAP , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_DROP , SAI_PACKET_COLOR_RED) @name("ingress.acl_ingress.acl_trap") action acl_ingress_acl_trap_0(@sai_action_param(QOS_QUEUE) @id(1) @name("qos_queue") bit<8> qos_queue_2) { - @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) { + @id(0x01000101) @sai_action(SAI_PACKET_ACTION_COPY , SAI_PACKET_COLOR_GREEN) @sai_action(SAI_PACKET_ACTION_FORWARD , SAI_PACKET_COLOR_RED) @inlinedFrom("acl_ingress_acl_copy") { acl_ingress_acl_ingress_counter.count(); acl_ingress_acl_ingress_meter.read(local_metadata._color32); local_metadata._marked_to_copy18 = true; @@ -966,7 +966,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, @id(0x01000002) @name("ingress.routing_resolution.set_port_and_src_mac") action routing_resolution_set_port_and_src_mac_0(@id(1) @name("port") bit<9> port_3, @id(2) @format(MAC_ADDRESS) @name("src_mac") bit<48> src_mac_5) { @id(0x0100001B) @unsupported @action_restriction(" // Disallow reserved VLAN IDs with implementation-defined semantics. - vlan_id != 0 && vlan_id != 4095") { + vlan_id != 0 && vlan_id != 4095") @inlinedFrom("routing_resolution_set_port_and_src_mac_and_vlan_id") { standard_metadata.egress_spec = (bit<9>)port_3; local_metadata._packet_rewrites_src_mac8 = src_mac_5; local_metadata._packet_rewrites_vlan_id10 = 12w0xfff; @@ -995,7 +995,7 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._enable_vlan_rewrite7 = !(bool)disable_vlan_rewrite; } @id(0x01000014) @name("ingress.routing_resolution.set_ip_nexthop") action routing_resolution_set_ip_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") bit<10> router_interface_id_4, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") bit<128> neighbor_id_3) { - @id(0x01000017) { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_4; routing_resolution_neighbor_id_valid = true; @@ -1007,8 +1007,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, } } @id(0x01000003) @deprecated("Use set_ip_nexthop instead.") @name("ingress.routing_resolution.set_nexthop") action routing_resolution_set_nexthop_0(@id(1) @refers_to(router_interface_table , router_interface_id) @refers_to(neighbor_table , router_interface_id) @name("router_interface_id") bit<10> router_interface_id_5, @id(2) @format(IPV6_ADDRESS) @refers_to(neighbor_table , neighbor_id) @name("neighbor_id") bit<128> neighbor_id_4) { - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_5; routing_resolution_neighbor_id_valid = true; @@ -1042,8 +1042,8 @@ control ingress(inout headers_t headers, inout local_metadata_t local_metadata, local_metadata._tunnel_encap_src_ipv616 = encap_src_ip; local_metadata._tunnel_encap_dst_ipv617 = encap_dst_ip; local_metadata._apply_tunnel_encap_at_egress15 = true; - @id(0x01000014) { - @id(0x01000017) { + @id(0x01000014) @inlinedFrom("routing_resolution_set_ip_nexthop") { + @id(0x01000017) @inlinedFrom("routing_resolution_set_ip_nexthop_and_disable_rewrites") { routing_resolution_router_interface_id_valid = true; routing_resolution_router_interface_id_value = router_interface_id_6; routing_resolution_neighbor_id_valid = true; diff --git a/testdata/p4_16_samples_outputs/pins/pins_middleblock.p4 b/testdata/p4_16_samples_outputs/pins/pins_middleblock.p4 index cc8fe4e435f..d6c9fb8b9ef 100644 --- a/testdata/p4_16_samples_outputs/pins/pins_middleblock.p4 +++ b/testdata/p4_16_samples_outputs/pins/pins_middleblock.p4 @@ -1237,7 +1237,7 @@ control acl_ingress(in headers_t headers, inout local_metadata_t local_metadata, is_ipv6::mask != 0 -> (is_ipv6 == 1); // Only allow icmp_type matches for ICMP packets icmpv6_type::mask != 0 -> ip_protocol == 58; -# 369 " .. / .. / .. / .. / pins - infra / sai_p4 / instantiations / google / acl_ingress . p4 " + # 369 " .. / .. / .. / .. / pins - infra / sai_p4 / instantiations / google / acl_ingress . p4 " ") table acl_ingress_qos_table { key = { headers.ipv4.isValid() || headers.ipv6.isValid(): optional @id(1) @name("is_ip") @sai_field(SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE / IP); diff --git a/testdata/p4_16_samples_outputs/xor_test-frontend.p4 b/testdata/p4_16_samples_outputs/xor_test-frontend.p4 index 62fade80cb6..d65674b1211 100644 --- a/testdata/p4_16_samples_outputs/xor_test-frontend.p4 +++ b/testdata/p4_16_samples_outputs/xor_test-frontend.p4 @@ -67,12 +67,12 @@ control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadat } @name("MyIngress.forward_and_do_something") action forward_and_do_something(@name("port") egressSpec_t port) { standard_metadata.egress_spec = port; - if (hdr.ipv4.isValid()) { + if (hdr.ipv4.isValid()) @inlinedFrom("srcAddr") { meta.before1 = hdr.ipv4.srcAddr; hdr.ipv4.srcAddr = hdr.ipv4.srcAddr ^ 32w0x12345678; meta.after1 = hdr.ipv4.srcAddr; } - if (hdr.ethernet.isValid()) { + if (hdr.ethernet.isValid()) @inlinedFrom("dstAddr") { if (hdr.ethernet.isValid()) { hdr.ipv4.protocol = hdr.ipv4.protocol ^ 8w1; } diff --git a/testdata/p4_16_samples_outputs/xor_test-midend.p4 b/testdata/p4_16_samples_outputs/xor_test-midend.p4 index 3e1bf99c1f7..c45f1d726e9 100644 --- a/testdata/p4_16_samples_outputs/xor_test-midend.p4 +++ b/testdata/p4_16_samples_outputs/xor_test-midend.p4 @@ -69,12 +69,12 @@ control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadat } @name("MyIngress.forward_and_do_something") action forward_and_do_something(@name("port") bit<9> port) { standard_metadata.egress_spec = port; - if (hdr.ipv4.isValid()) { + if (hdr.ipv4.isValid()) @inlinedFrom("srcAddr") { meta.before1 = hdr.ipv4.srcAddr; hdr.ipv4.srcAddr = hdr.ipv4.srcAddr ^ 32w0x12345678; meta.after1 = hdr.ipv4.srcAddr; } - if (hdr.ethernet.isValid()) { + if (hdr.ethernet.isValid()) @inlinedFrom("dstAddr") { if (hdr.ethernet.isValid()) { hdr.ipv4.protocol = hdr.ipv4.protocol ^ 8w1; }