Add ir_loop to represent loops

This touches a lot of files because everything derived from ir_visitor
has to be updated.  This is the primary disadvantage of the visitor pattern.
This commit is contained in:
Ian Romanick 2010-04-05 16:16:07 -07:00
parent b94e402cff
commit fad607a9be
7 changed files with 82 additions and 0 deletions

38
ir.h
View file

@ -287,6 +287,44 @@ public:
};
/**
* IR instruction representing a high-level loop structure.
*/
class ir_loop : public ir_instruction {
public:
ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL)
{
/* empty */
}
virtual void accept(ir_visitor *v)
{
v->visit(this);
}
/**
* Get an iterator for the instructions of the loop body
*/
exec_list_iterator iterator()
{
return body_instructions.iterator();
}
/** List of instructions that make up the body of the loop. */
exec_list body_instructions;
/**
* \name Loop counter and controls
*/
/*@{*/
ir_rvalue *from;
ir_rvalue *to;
ir_rvalue *increment;
ir_variable *counter;
/*@}*/
};
class ir_assignment : public ir_rvalue {
public:
ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);

View file

@ -74,6 +74,7 @@ public:
virtual void visit(ir_call *);
virtual void visit(ir_return *);
virtual void visit(ir_if *);
virtual void visit(ir_loop *);
/*@}*/
/**
@ -464,3 +465,11 @@ ir_constant_visitor::visit(ir_if *ir)
(void) ir;
value = NULL;
}
void
ir_constant_visitor::visit(ir_loop *ir)
{
(void) ir;
value = NULL;
}

View file

@ -145,3 +145,10 @@ ir_constant_folding_visitor::visit(ir_if *ir)
visit_exec_list(&ir->then_instructions, this);
visit_exec_list(&ir->else_instructions, this);
}
void
ir_constant_folding_visitor::visit(ir_loop *ir)
{
(void) ir;
}

View file

@ -58,5 +58,6 @@ public:
virtual void visit(ir_call *);
virtual void visit(ir_return *);
virtual void visit(ir_if *);
virtual void visit(ir_loop *);
/*@}*/
};

View file

@ -294,3 +294,28 @@ ir_print_visitor::visit(ir_if *ir)
}
printf("))\n");
}
void
ir_print_visitor::visit(ir_loop *ir)
{
printf("(loop (");
if (ir->counter != NULL)
ir->counter->accept(this);
printf(") (");
if (ir->from != NULL)
ir->from->accept(this);
printf(") (");
if (ir->to != NULL)
ir->to->accept(this);
printf(") (");
if (ir->increment != NULL)
ir->increment->accept(this);
printf(") (");
foreach_iter(exec_list_iterator, iter, ir->body_instructions) {
ir_instruction *const inst = (ir_instruction *) iter.get();
inst->accept(this);
}
printf("))\n");
}

View file

@ -65,6 +65,7 @@ public:
virtual void visit(ir_call *);
virtual void visit(ir_return *);
virtual void visit(ir_if *);
virtual void visit(ir_loop *);
/*@}*/
private:

View file

@ -56,6 +56,7 @@ public:
virtual void visit(class ir_call *) = 0;
virtual void visit(class ir_return *) = 0;
virtual void visit(class ir_if *) = 0;
virtual void visit(class ir_loop *) = 0;
/*@}*/
};