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 for issue #496 #500

Merged
merged 3 commits into from
Apr 22, 2017
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
2 changes: 1 addition & 1 deletion backends/p4test/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ MidEnd::MidEnd(CompilerOptions& options) {
new P4::RemoveAllUnusedDeclarations(&refMap),
new P4::ClearTypeMap(&typeMap),
evaluator,
new VisitFunctor([v1controls, evaluator](const IR::Node *root) -> const IR::Node * {
new VisitFunctor([v1controls, evaluator](const IR::Node *root) -> const IR::Node * {
auto toplevel = evaluator->getToplevelBlock();
auto main = toplevel->getMain();
if (main == nullptr)
Expand Down
10 changes: 10 additions & 0 deletions frontends/p4/unusedDeclarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ const IR::Node* RemoveUnusedDeclarations::preorder(IR::Declaration_Instance* dec
if (!refMap->isUsed(getOriginal<IR::Declaration_Instance>())) {
if (giveWarning(getOriginal()))
::warning("%1%: unused instance", decl);
// We won't delete extern instances; these may be useful even if not references.
auto type = decl->type;
if (type->is<IR::Type_Specialized>())
type = type->to<IR::Type_Specialized>()->baseType;
if (type->is<IR::Type_Name>())
type = refMap->getDeclaration(type->to<IR::Type_Name>()->path, true)->to<IR::Type>();
if (!type->is<IR::Type_Extern>())
return process(decl);
prune();
return decl;
}
// don't scan the initializer: we don't want to delete virtual methods
prune();
Expand Down
12 changes: 6 additions & 6 deletions frontends/p4/unusedDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace P4 {

class RemoveUnusedDeclarations : public Transform {
const ReferenceMap* refMap;
// If non-null give warnings about unused declarations
/// If non-null give warnings about unused declarations
std::set<const IR::Node*>* warned;
const IR::Node* process(const IR::IDeclaration* decl);

Expand All @@ -38,8 +38,8 @@ class RemoveUnusedDeclarations : public Transform {
using Transform::preorder;
using Transform::init_apply;

// True if we should report a warning; the node is
// added to warned in this case
/// True if we should report a warning; the node is
/// added to warned in this case
bool giveWarning(const IR::Node* node);

Visitor::profile_t init_apply(const IR::Node *root) override;
Expand All @@ -52,7 +52,7 @@ class RemoveUnusedDeclarations : public Transform {

const IR::Node* preorder(IR::Declaration_Instance* decl) override;

// Do not delete the following even if unused
// The following kinds of nodes are not deleted even if they are unreferenced
const IR::Node* preorder(IR::Type_Error* type) override
{ prune(); return type; }
const IR::Node* preorder(IR::Declaration_MatchKind* decl) override
Expand All @@ -63,14 +63,14 @@ class RemoveUnusedDeclarations : public Transform {
{ prune(); return type; }
const IR::Node* preorder(IR::Type_Method* type) override
{ prune(); return type; }
const IR::Node* preorder(IR::Parameter* param) override { return param; } // never dead

const IR::Node* preorder(IR::Declaration_Variable* decl) override;
const IR::Node* preorder(IR::Parameter* param) override { return param; } // never dead
const IR::Node* preorder(IR::Declaration* decl) override { return process(decl); }
const IR::Node* preorder(IR::Type_Declaration* decl) override { return process(decl); }
};

// Iterates RemoveUnusedDeclarations until convergence.
/// Iterates RemoveUnusedDeclarations until convergence.
class RemoveAllUnusedDeclarations : public PassManager {
public:
explicit RemoveAllUnusedDeclarations(ReferenceMap* refMap, bool warn = false) {
Expand Down
Loading