void ConstantConditionEliminator::visit(Conditional &cond)
{
- ExpressionEvaluator eval;
- cond.condition->visit(eval);
- if(eval.is_result_valid())
- {
- Block &block = (eval.get_result() ? cond.body : cond.else_body);
- current_block->body.splice(insert_point, block.body);
- nodes_to_remove.insert(&cond);
- return;
- }
+ if(Literal *literal = dynamic_cast<Literal *>(cond.condition.get()))
+ if(literal->value.check_type<bool>())
+ {
+ Block &block = (literal->value.value<bool>() ? cond.body : cond.else_body);
+ current_block->body.splice(insert_point, block.body);
+ nodes_to_remove.insert(&cond);
+ return;
+ }
TraversingVisitor::visit(cond);
}
}
-UnusedVariableRemover::VariableInfo::VariableInfo():
- local(false),
- output(false),
- conditionally_assigned(false),
- referenced(false),
- interface_block(0)
-{ }
-
-
bool UnusedTypeRemover::apply(Stage &stage)
{
stage.content.visit(*this);
}
+UnusedVariableRemover::VariableInfo::VariableInfo():
+ local(false),
+ output(false),
+ conditionally_assigned(false),
+ referenced(false),
+ interface_block(0)
+{ }
+
+
UnusedVariableRemover::UnusedVariableRemover():
stage(0),
interface_block(0),
}
if(output)
{
- if(!i->second.assignments.empty() && i->second.interface_block)
+ if((i->second.referenced || !i->second.assignments.empty()) && i->second.interface_block)
used_interface_blocks.insert(i->second.interface_block);
continue;
}