From fad607a9be59056aecda50176b4d20a8b5319747 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 5 Apr 2010 16:16:07 -0700 Subject: [PATCH] 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. --- ir.h | 38 ++++++++++++++++++++++++++++++++++++++ ir_constant_expression.cpp | 9 +++++++++ ir_constant_folding.cpp | 7 +++++++ ir_constant_folding.h | 1 + ir_print_visitor.cpp | 25 +++++++++++++++++++++++++ ir_print_visitor.h | 1 + ir_visitor.h | 1 + 7 files changed, 82 insertions(+) diff --git a/ir.h b/ir.h index adc14055724..8c533c308a0 100644 --- a/ir.h +++ b/ir.h @@ -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); diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp index e1073cde1ce..a94b0fc9e2a 100644 --- a/ir_constant_expression.cpp +++ b/ir_constant_expression.cpp @@ -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; +} diff --git a/ir_constant_folding.cpp b/ir_constant_folding.cpp index af6674c3f6e..d7efdecc45f 100644 --- a/ir_constant_folding.cpp +++ b/ir_constant_folding.cpp @@ -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; +} diff --git a/ir_constant_folding.h b/ir_constant_folding.h index 9e151ecde66..382f57c7e55 100644 --- a/ir_constant_folding.h +++ b/ir_constant_folding.h @@ -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 *); /*@}*/ }; diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp index 375659d5cff..76524261ecd 100644 --- a/ir_print_visitor.cpp +++ b/ir_print_visitor.cpp @@ -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"); +} diff --git a/ir_print_visitor.h b/ir_print_visitor.h index 76d812e19c1..a6365bec7e2 100644 --- a/ir_print_visitor.h +++ b/ir_print_visitor.h @@ -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: diff --git a/ir_visitor.h b/ir_visitor.h index 521b1c3d805..fab1a75d53f 100644 --- a/ir_visitor.h +++ b/ir_visitor.h @@ -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; /*@}*/ }; -- 2.30.2