{
this->ht = hash_table_ctor(0, hash_table_pointer_hash,
hash_table_pointer_compare);
- this->mem_ctx = talloc_init("loop state");
+ this->mem_ctx = ralloc_context(NULL);
+ this->loop_found = false;
}
loop_state::~loop_state()
{
hash_table_dtor(this->ht);
+ ralloc_free(this->mem_ctx);
}
loop_state::insert(ir_loop *ir)
{
loop_variable_state *ls = new(this->mem_ctx) loop_variable_state;
+
hash_table_insert(this->ht, ls, ir);
+ this->loop_found = true;
return ls;
}
loop_variable *
loop_variable_state::insert(ir_variable *var)
{
- void *mem_ctx = talloc_parent(this);
- loop_variable *lv = talloc_zero(mem_ctx, loop_variable);
+ void *mem_ctx = ralloc_parent(this);
+ loop_variable *lv = rzalloc(mem_ctx, loop_variable);
lv->var = var;
loop_terminator *
loop_variable_state::insert(ir_if *if_stmt)
{
- void *mem_ctx = talloc_parent(this);
- loop_terminator *t = talloc_zero(mem_ctx, loop_terminator);
+ void *mem_ctx = ralloc_parent(this);
+ loop_terminator *t = rzalloc(mem_ctx, loop_terminator);
t->ir = if_stmt;
this->terminators.push_tail(t);
public:
loop_analysis();
+ virtual ir_visitor_status visit(ir_loop_jump *);
virtual ir_visitor_status visit(ir_dereference_variable *);
virtual ir_visitor_status visit_enter(ir_loop *);
}
+ir_visitor_status
+loop_analysis::visit(ir_loop_jump *ir)
+{
+ (void) ir;
+
+ assert(!this->state.is_empty());
+
+ loop_variable_state *const ls =
+ (loop_variable_state *) this->state.get_head();
+
+ ls->num_loop_jumps++;
+
+ return visit_continue;
+}
+
+
ir_visitor_status
loop_analysis::visit(ir_dereference_variable *ir)
{
/* If we're not somewhere inside a loop, there's nothing to do.
*/
if (this->state.is_empty())
- return visit_continue_with_parent;
+ return visit_continue;
loop_variable_state *const ls =
(loop_variable_state *) this->state.get_head();
ir_rvalue *inc = (op0 == var) ? rhs->operands[1] : rhs->operands[0];
- if (inc->constant_expression_value() == NULL) {
+ if (inc->as_constant() == NULL) {
ir_variable *const inc_var = inc->variable_referenced();
if (inc_var != NULL) {
loop_variable *lv =
}
if ((inc != NULL) && (rhs->operation == ir_binop_sub)) {
- void *mem_ctx = talloc_parent(ir);
+ void *mem_ctx = ralloc_parent(ir);
inc = new(mem_ctx) ir_expression(ir_unop_neg,
inc->type,