summaryrefslogtreecommitdiff
path: root/frontends/ast/simplify.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-08-18 00:02:30 +0200
committerClifford Wolf <clifford@clifford.at>2014-08-18 00:02:30 +0200
commitacb435b6cf583b6c18f405a9c92566c4e9fb85e5 (patch)
tree8d301c4a63ee0e54f99e54aaa265f930ef057b3f /frontends/ast/simplify.cc
parentaa7a3ed83f0972bd6da3b272e7bbc9efb1409067 (diff)
Added const folding of AST_CASE to AST simplifier
Diffstat (limited to 'frontends/ast/simplify.cc')
-rw-r--r--frontends/ast/simplify.cc33
1 files changed, 32 insertions, 1 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index 76d1f827..85671213 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -1567,7 +1567,7 @@ skip_dynamic_range_lvalue_expansion:;
}
// perform const folding when activated
- if (const_fold && newNode == NULL)
+ if (const_fold)
{
bool string_op;
std::vector<RTLIL::State> tmp_bits;
@@ -1746,6 +1746,37 @@ skip_dynamic_range_lvalue_expansion:;
newNode->realvalue = -children[0]->asReal(sign_hint);
}
break;
+ case AST_CASE:
+ if (children[0]->type == AST_CONSTANT && children[0]->bits_only_01()) {
+ std::vector<AstNode*> new_children;
+ new_children.push_back(children[0]);
+ for (int i = 1; i < SIZE(children); i++) {
+ AstNode *child = children[i];
+ log_assert(child->type == AST_COND);
+ for (auto v : child->children) {
+ if (v->type == AST_DEFAULT)
+ goto keep_const_cond;
+ if (v->type == AST_BLOCK)
+ continue;
+ if (v->type == AST_CONSTANT && v->bits_only_01()) {
+ if (v->bits == children[0]->bits) {
+ while (i+1 < SIZE(children))
+ delete children[++i];
+ goto keep_const_cond;
+ }
+ continue;
+ }
+ goto keep_const_cond;
+ }
+ if (0)
+ keep_const_cond:
+ new_children.push_back(child);
+ else
+ delete child;
+ }
+ new_children.swap(children);
+ }
+ break;
case AST_TERNARY:
if (children[0]->isConst())
{