Skip to content

Commit

Permalink
Don't give warnings about constant folding late in the compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbudiu-vmw committed Nov 18, 2016
1 parent 5f69305 commit 9458e69
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backends/bmv2/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ MidEnd::MidEnd(CompilerOptions& options) {
new P4::RemoveLeftSlices(&refMap, &typeMap),
new P4::TypeChecking(&refMap, &typeMap),
new LowerExpressions(&typeMap),
new P4::ConstantFolding(&refMap, &typeMap),
new P4::ConstantFolding(&refMap, &typeMap, false),
evaluator,
new VisitFunctor([this, evaluator]() { toplevel = evaluator->getToplevelBlock(); })
});
Expand Down
7 changes: 4 additions & 3 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ const IR::Node* DoConstantFolding::shift(const IR::Operation_Binary* e) {

auto tb = left->type->to<IR::Type_Bits>();
if (tb != nullptr) {
if ((unsigned)tb->size < shift)
if (((unsigned)tb->size < shift) && warnings)
::warning("%1%: Shifting %2%-bit value with %3%", e, tb->size, shift);
}

Expand Down Expand Up @@ -710,7 +710,8 @@ const IR::Node* DoConstantFolding::postorder(IR::SelectExpression* expression) {
* Should really implement this in SelectCase pre/postorder and this postorder goes away */
for (auto c : expression->selectCases) {
if (finished) {
::warning("%1%: unreachable case", c);
if (warnings)
::warning("%1%: unreachable case", c);
continue;
}
auto inside = setContains(c->keyset, sel);
Expand All @@ -735,7 +736,7 @@ const IR::Node* DoConstantFolding::postorder(IR::SelectExpression* expression) {
}

if (changes) {
if (cases.size() == 0 && result == expression)
if (cases.size() == 0 && result == expression && warnings)
// TODO: this is the same as verify(false, error.NoMatch),
// but we cannot replace the selectExpression with a method call.
::warning("%1%: no case matches", expression);
Expand Down
9 changes: 5 additions & 4 deletions frontends/common/constantFolding.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DoConstantFolding : public Transform {
const ReferenceMap* refMap; // if null no 'const' values can be resolved
TypeMap* typeMap; // if null we have no types; updated for new constants
bool typesKnown;
bool warnings; // if true emit warnings
// maps expressions and declarations to their constant values
std::map<const IR::Node*, const IR::Expression*> constants;

Expand All @@ -55,8 +56,8 @@ class DoConstantFolding : public Transform {
Result setContains(const IR::Expression* keySet, const IR::Expression* constant) const;

public:
DoConstantFolding(const ReferenceMap* refMap, TypeMap* typeMap) :
refMap(refMap), typeMap(typeMap), typesKnown(typeMap != nullptr) {
DoConstantFolding(const ReferenceMap* refMap, TypeMap* typeMap, bool warnings = true) :
refMap(refMap), typeMap(typeMap), typesKnown(typeMap != nullptr), warnings(warnings) {
visitDagOnce = true; setName("DoConstantFolding");
}

Expand Down Expand Up @@ -92,10 +93,10 @@ class DoConstantFolding : public Transform {

class ConstantFolding : public PassManager {
public:
ConstantFolding(ReferenceMap* refMap, TypeMap* typeMap) {
ConstantFolding(ReferenceMap* refMap, TypeMap* typeMap, bool warnings = true) {
if (typeMap != nullptr)
passes.push_back(new TypeChecking(refMap, typeMap));
passes.push_back(new DoConstantFolding(refMap, typeMap));
passes.push_back(new DoConstantFolding(refMap, typeMap, warnings));
setName("ConstantFolding");
}
};
Expand Down

0 comments on commit 9458e69

Please sign in to comment.