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

Fix a nullptr access in the DPDK back end. #4712

Merged
merged 2 commits into from
Jun 6, 2024
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
36 changes: 24 additions & 12 deletions backends/dpdk/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ limitations under the License.
#include "midend/eliminateTypedefs.h"
#include "midend/removeComplexExpressions.h"
#include "midend/simplifyKey.h"

namespace DPDK {

void DpdkBackend::convert(const IR::ToplevelBlock *tlb) {
Expand Down Expand Up @@ -129,29 +130,40 @@ void DpdkBackend::convert(const IR::ToplevelBlock *tlb) {
};
simplify.addDebugHook(hook, true);
program = program->apply(simplify);
ordered_set<cstring> used_fields;
if (errorCount() > 0) {
return;
}

dpdk_program = convertToDpdk->getDpdkProgram();
if (!dpdk_program) return;
if (dpdk_program == nullptr) {
return;
}

PassManager postCodeGen;
ordered_map<cstring, cstring> newNameMap;
ordered_set<cstring> usedFields;
if (structure.p4arch == "pna") {
PassManager post_code_gen = {
postCodeGen.addPasses({
new PrependPassRecircId(),
new DirectionToRegRead(),
};
dpdk_program = dpdk_program->apply(post_code_gen)->to<IR::DpdkAsmProgram>();
});
}
ordered_map<cstring, cstring> newNameMap;
PassManager post_code_gen = {
postCodeGen.addPasses({
new EliminateUnusedAction(),
new DpdkAsmOptimization,
new CopyPropagationAndElimination(typeMap),
new CollectUsedMetadataField(used_fields),
new RemoveUnusedMetadataFields(used_fields),
new CollectUsedMetadataField(usedFields),
new RemoveUnusedMetadataFields(usedFields),
new ShortenTokenLength(newNameMap),
new EmitDpdkTableConfig(refMap, typeMap, newNameMap),
};

dpdk_program = dpdk_program->apply(post_code_gen)->to<IR::DpdkAsmProgram>();
});
const auto *optimizedProgram = dpdk_program->apply(postCodeGen);
if (errorCount() > 0) {
return;
}
dpdk_program = optimizedProgram->to<IR::DpdkAsmProgram>();
}

void DpdkBackend::codegen(std::ostream &out) const { dpdk_program->toSpec(out) << std::endl; }

} // namespace DPDK
10 changes: 6 additions & 4 deletions backends/dpdk/dpdkArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,11 @@ cstring CopyMatchKeysToSingleStruct::getTableKeyName(const IR::Expression *e) {
}

const IR::Node *CopyMatchKeysToSingleStruct::preorder(IR::Key *keys) {
// If copyNeeded is false at this point, it means the keys are from same struct.
// Check remaining conditions to see if the copy is needed or not
// TODO: This indirection should not be needed. Instead of using a visitor for IR::KeyElement
// just resolve each key element directly.
metaCopyNeeded = false;
// If any key field is from different structure, put all keys in metadata
LOG3("Visiting " << keys);
bool copyNeeded = false;
Expand Down Expand Up @@ -1645,10 +1650,6 @@ const IR::Node *CopyMatchKeysToSingleStruct::preorder(IR::Key *keys) {
} else {
structure->table_type_map.emplace(table->name.name, InternalTableType::WILDCARD);
}

// If copyNeeded is false at this point, it means the keys are from same struct.
// Check remaining conditions to see if the copy is needed or not
metaCopyNeeded = false;
if (copyNeeded) contiguous = false;

if (!contiguous &&
Expand All @@ -1670,6 +1671,7 @@ const IR::Node *CopyMatchKeysToSingleStruct::preorder(IR::Key *keys) {
}
return keys;
}

const IR::Node *CopyMatchKeysToSingleStruct::postorder(IR::KeyElement *element) {
// If we got here we need to put the key element in metadata.
LOG3("Extracting key element " << element);
Expand Down
2 changes: 1 addition & 1 deletion backends/dpdk/dpdkArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ struct keyInfo {
class CopyMatchKeysToSingleStruct : public P4::KeySideEffect {
IR::IndexedVector<IR::Declaration> decls;
DpdkProgramStructure *structure;
bool metaCopyNeeded;
bool metaCopyNeeded = false;

public:
CopyMatchKeysToSingleStruct(P4::ReferenceMap *refMap, P4::TypeMap *typeMap,
Expand Down
Loading