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

make DumpPipe from Tofino available to all #5184

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ OPTION (ENABLE_IWYU "Enable checking includes with IWYU" OFF)
# Support a legacy option. TODO: Remove?
OPTION (ENABLE_UNIFIED_COMPILATION "Enable CMAKE_UNITY_BUILD" OFF)

# Enable DumpPipe pass output
OPTION(ENABLE_DUMP_PIPE "Enable DumpPipe pass output" ON)

set (P4C_DRIVER_NAME "p4c" CACHE STRING "Customize the name of the driver script")

set(MAX_LOGGING_LEVEL 10 CACHE STRING "Control the maximum logging level for -T logs")
Expand Down Expand Up @@ -189,6 +192,11 @@ if (BUILD_AUTO_VAR_INIT_PATTERN)
add_cxx_compiler_option ("-ftrivial-auto-var-init=pattern")
endif ()

# Enable DumpPipe pass output
if (ENABLE_DUMP_PIPE)
add_definitions("-DENABLE_DUMP_PIPE=1")
endif ()

# Required tools and libraries.
find_package (PythonInterp 3 REQUIRED)
find_package (FLEX 2.0 REQUIRED)
Expand Down
7 changes: 5 additions & 2 deletions backends/p4test/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.
#include "frontends/p4/typeChecking/typeChecker.h"
#include "frontends/p4/typeMap.h"
#include "frontends/p4/unusedDeclarations.h"
#include "ir/dump.h"
#include "midend/actionSynthesis.h"
#include "midend/compileTimeOps.h"
#include "midend/complexComparison.h"
Expand Down Expand Up @@ -87,7 +88,8 @@ MidEnd::MidEnd(P4TestOptions &options, std::ostream *outStream) {
auto defUse = new P4::ComputeDefUse;

addPasses(
{options.ndebug ? new P4::RemoveAssertAssume(&typeMap) : nullptr,
{new P4::DumpPipe("MidEnd start"),
options.ndebug ? new P4::RemoveAssertAssume(&typeMap) : nullptr,
new P4::RemoveMiss(&typeMap),
new P4::EliminateNewtype(&typeMap),
new P4::EliminateInvalidHeaders(&typeMap),
Expand Down Expand Up @@ -171,7 +173,8 @@ MidEnd::MidEnd(P4TestOptions &options, std::ostream *outStream) {
[this, evaluator]() { toplevel = evaluator->getToplevelBlock(); },
new P4::FlattenHeaderUnion(&refMap, &typeMap, options.loopsUnrolling),
new P4::SimplifyControlFlow(&typeMap, true),
new P4::MidEndLast()});
new P4::MidEndLast(),
new P4::DumpPipe("MidEnd end")});
if (options.listMidendPasses) {
listPasses(*outStream, cstring::newline);
*outStream << std::endl;
Expand Down
1 change: 0 additions & 1 deletion backends/tofino/bf-p4c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ set (BF_P4C_BACKEND_COMMON_SRCS
common/check_field_corruption.cpp
common/check_for_unimplemented_features.cpp
common/check_uninitialized_read.cpp
common/dump_pipe.cpp
common/pragma/collect_global_pragma.cpp
common/elim_unused.cpp
common/empty_tableseq.cpp
Expand Down
15 changes: 8 additions & 7 deletions backends/tofino/bf-p4c/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
#include "backends/tofino/bf-p4c/phv/split_padding.h"
#include "backends/tofino/bf-p4c/phv/utils/slice_alloc.h"
#include "backends/tofino/bf-p4c/phv/v2/metadata_initialization.h"
#include "ir/dump.h"
#include "ir/pass_manager.h"
#include "lib/indent.h"

Expand Down Expand Up @@ -212,7 +213,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
: nullptr;

addPasses({
new DumpPipe("Initial table graph"),
new P4::DumpPipe("Initial table graph"),
flexibleLogging,
LOGGING(4) ? new DumpParser("begin_backend") : nullptr,
new AdjustByteCountSetup,
Expand Down Expand Up @@ -258,7 +259,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
new CollectPhvInfo(phv),
new GatherReductionOrReqs(deps.red_info),
new InstructionSelection(options, phv, deps.red_info),
new DumpPipe("After InstructionSelection"),
new P4::DumpPipe("After InstructionSelection"),
new FindDependencyGraph(phv, deps, &options, "program_graph"_cs,
"After Instruction Selection"_cs),
options.decaf ? &decaf : nullptr,
Expand All @@ -274,7 +275,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
new AutoAlias(phv, *pragmaAlias, *noOverlay),
new Alias(phv, *pragmaAlias),
new CollectPhvInfo(phv),
new DumpPipe("After Alias"),
new P4::DumpPipe("After Alias"),
// This is the backtracking point from table placement to PHV allocation. Based on a
// container conflict-free PHV allocation, we generate a number of no-pack conflicts between
// fields (these are fields written in different nonmutually exclusive actions in the same
Expand All @@ -283,7 +284,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
// metadata packing.
&mau_backtracker,
new ResolveSizeOfOperator(),
new DumpPipe("After ResolveSizeOfOperator"),
new P4::DumpPipe("After ResolveSizeOfOperator"),
// Run after bridged metadata packing as bridged packing updates the parser state.
new CollectPhvInfo(phv),
new ParserCopyProp(phv),
Expand Down Expand Up @@ -352,7 +353,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
// with table info
// Trivial PHV alloc => table alloc ==================> PHV alloc ===> redo table.
new AddInitsInMAU(phv, mauInitFields, false),
new DumpPipe("Before phv_analysis"),
new P4::DumpPipe("Before phv_analysis"),
new DumpTableFlowGraph(phv),
options.alt_phv_alloc
? new PassManager({
Expand Down Expand Up @@ -444,7 +445,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
// tables to be split across stages.
new GeneratePrimitiveInfo(phv, primNode),
&table_alloc,
new DumpPipe("After TableAlloc"),
new P4::DumpPipe("After TableAlloc"),
&table_summary,
// Rerun defuse analysis here so that table placements are used to correctly calculate live
// ranges output in the assembly.
Expand All @@ -461,7 +462,7 @@ Backend::Backend(const BFN_Options &o, int pipe_id)
: nullptr,
new InstructionAdjustment(phv, deps.red_info),
&nextTblProp, // Must be run after all modifications to the table graph have finished!
new DumpPipe("Final table graph"),
new P4::DumpPipe("Final table graph"),
new CheckFieldCorruption(defuse, phv, PHV_Analysis->get_pragmas()),
new AdjustExtract(phv),
phvLoggingDefUseInfo,
Expand Down
46 changes: 0 additions & 46 deletions backends/tofino/bf-p4c/common/dump_pipe.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions backends/tofino/bf-p4c/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@

using namespace P4;

struct DumpPipe : public Inspector {
const char *heading;
DumpPipe() : heading(nullptr) {}
explicit DumpPipe(const char *h) : heading(h) {}
#if BAREFOOT_INTERNAL
bool preorder(const IR::Node *pipe) override;
#endif // BAREFOOT_INTERNAL
};

/// Used to end the compiler after a fatal error is raised. Usually, this just trows an exception
/// \ref Util::CompilationError. In internal builds when a program contains "expect error" and all
/// the errors are expected (including the fatal one) then this function just exits (calls
Expand Down
54 changes: 33 additions & 21 deletions backends/tofino/bf-p4c/mau/mau_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "backends/tofino/bf-p4c/mau/table_placement.h"
#include "backends/tofino/bf-p4c/mau/table_seqdeps.h"
#include "backends/tofino/bf-p4c/phv/mau_backtracker.h"
#include "ir/dump.h"

int TableAllocPass::table_placement_round = 1;

Expand All @@ -39,27 +40,38 @@ TableAllocPass::TableAllocPass(const BFN_Options &options, PhvInfo &phv, Depende
: Logging::PassManager("table_placement_"_cs), att_info(phv), options(options) {
lc = LayoutChoices::create(phv, deps.red_info, att_info);
siaa = new SharedIndirectAttachedAnalysis(mutex, ignore, action_mutex, *lc);
addPasses(
{new GatewayOpt(phv), // must be before TableLayout? or just TablePlacement?
new TableLayout(phv, *lc, att_info), // catches IXBar::realign backtracks
new AssignActionHandle(phv), new MeterALU::Format(phv, *lc),
new TableFindSeqDependencies(phv), new FindDependencyGraph(phv, deps),
new SpreadGatewayAcrossSeq(phv), new CheckTableNameDuplicate,
new TableFindSeqDependencies(phv), new CheckTableNameDuplicate,
new FindDependencyGraph(phv, deps, &options, ""_cs, "Before Table Placement"_cs, &summary),
new DumpJsonGraph(deps, jsonGraph, "Before Table Placement"_cs, false), &ignore, &mutex,
&action_mutex, siaa, new DumpPipe("Before TablePlacement"),
new TablePlacement(options, deps, mutex, phv, *lc, *siaa, att_info, summary,
mau_backtracker),
new DumpPipe("After TablePlacement"),
new FindDependencyGraph(phv, deps, &options, ""_cs, "After Table Placement"_cs, &summary),
new TableDependencyGraphSummary(deps), new CheckTableNameDuplicate,
new TableFindSeqDependencies(phv), // not needed?
new AssignCounterLRTValues(), new CheckTableNameDuplicate, new AdjustIXBarExpression,
// RemoveNoopGateway can be removed after MultipleApply2 is in
new PassIf(
[&options] { return !Device::hasLongBranches() || options.disable_long_branch; },
{new RemoveNoopGateway})});
addPasses({
new GatewayOpt(phv), // must be before TableLayout? or just TablePlacement?
new TableLayout(phv, *lc, att_info), // catches IXBar::realign backtracks
new AssignActionHandle(phv),
new MeterALU::Format(phv, *lc),
new TableFindSeqDependencies(phv),
new FindDependencyGraph(phv, deps),
new SpreadGatewayAcrossSeq(phv),
new CheckTableNameDuplicate,
new TableFindSeqDependencies(phv),
new CheckTableNameDuplicate,
new FindDependencyGraph(phv, deps, &options, ""_cs, "Before Table Placement"_cs, &summary),
new DumpJsonGraph(deps, jsonGraph, "Before Table Placement"_cs, false),
&ignore,
&mutex,
&action_mutex,
siaa,
new P4::DumpPipe("Before TablePlacement"),
new TablePlacement(options, deps, mutex, phv, *lc, *siaa, att_info, summary,
mau_backtracker),
new P4::DumpPipe("After TablePlacement"),
new FindDependencyGraph(phv, deps, &options, ""_cs, "After Table Placement"_cs, &summary),
new TableDependencyGraphSummary(deps),
new CheckTableNameDuplicate,
new TableFindSeqDependencies(phv), // not needed?
new AssignCounterLRTValues(),
new CheckTableNameDuplicate,
new AdjustIXBarExpression,
// RemoveNoopGateway can be removed after MultipleApply2 is in
new PassIf([&options] { return !Device::hasLongBranches() || options.disable_long_branch; },
{new RemoveNoopGateway}),
});

setName("Table Alloc");
}
17 changes: 14 additions & 3 deletions backends/tofino/bf-p4c/phv/v2/metadata_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "metadata_initialization.h"

#include "ir/dump.h"

namespace {

/** A helper class that maps phv::Field to a IR::Expression.
Expand Down Expand Up @@ -794,7 +796,16 @@ PHV::v2::MetadataInitialization::MetadataInitialization(MauBacktracker &backtrac
collect_pov_protected_field->pov_protected_fields);
auto *apply_init_insert =
new ApplyMetadataInitialization(*gen_init_plans, *field_to_expr, *table_write_info);
addPasses({new DumpPipe("before v2 metadata initialization"), collect_pov_protected_field,
pa_no_init, mutex, tfg_builder, field_to_expr, table_write_info, gen_init_plans,
apply_init_insert, new DumpPipe("after v2 metadata initialization")});
addPasses({
new P4::DumpPipe("before v2 metadata initialization"),
collect_pov_protected_field,
pa_no_init,
mutex,
tfg_builder,
field_to_expr,
table_write_info,
gen_init_plans,
apply_init_insert,
new P4::DumpPipe("after v2 metadata initialization"),
});
}
2 changes: 1 addition & 1 deletion backends/tofino/scripts/package_p4c_for_tofino.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
fi

install_prefix=/usr/local
barefoot_internal="-DENABLE_BAREFOOT_INTERNAL=OFF"
barefoot_internal="-DENABLE_BAREFOOT_INTERNAL=OFF -DENABLE_DUMP_PIPE=OFF"
enable_cb="-DENABLE_CLOUDBREAK=OFF"
enable_fr="-DENABLE_FLATROCK=OFF"
pgo=false
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/scripts/package_sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ else
fi

install_prefix=/usr/local
barefoot_internal="-DENABLE_BAREFOOT_INTERNAL=OFF"
barefoot_internal="-DENABLE_BAREFOOT_INTERNAL=OFF -DENABLE_DUMP_PIPE=OFF"
pgo=false
lto=false

Expand Down
22 changes: 22 additions & 0 deletions ir/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
#include "ir/node.h"
#include "ir/visitor.h"
#include "lib/cstring.h"
#include "lib/gc.h"
#include "lib/indent.h"
#include "lib/source_file.h"

Expand Down Expand Up @@ -138,4 +139,25 @@ std::string dumpToString(const IR::Node *n) {
return str.str();
}

bool DumpPipe::preorder(const IR::Node *pipe) {
#if ENABLE_DUMP_PIPE
if (LOGGING(1)) {
if (heading) {
LOG1("-------------------------------------------------");
LOG1(heading);
LOG1("-------------------------------------------------");
size_t maxMem = 0;
size_t memUsed = gc_mem_inuse(&maxMem) / (1024 * 1024);
maxMem = maxMem / (1024 * 1024);
LOG1("*** mem in use = " << memUsed << "MB, heap size = " << maxMem << "MB");
}
if (LOGGING(2))
dump(Log::Detail::fileLogOutput(__FILE__), pipe);
else
LOG1(*pipe);
}
#endif // ENABLE_DUMP_PIPE
return false;
}

} // namespace P4
7 changes: 7 additions & 0 deletions ir/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ inline std::ostream &operator<<(std::ostream &out, const Dump &d) {
return out;
}

struct DumpPipe : public Inspector {
const char *heading;
DumpPipe() : heading(nullptr) {}
explicit DumpPipe(const char *h) : heading(h) {}
bool preorder(const IR::Node *pipe) override;
};

} // namespace P4

#endif /* IR_DUMP_H_ */
Loading