From: Ian Romanick Date: Mon, 5 Apr 2010 23:28:15 +0000 (-0700) Subject: Add ir_loop_jump to represent 'break' and 'continue' in loops X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f8e31e00b1078dc28187a43a1ab8949e154e7533;p=mesa.git Add ir_loop_jump to represent 'break' and 'continue' in loops --- diff --git a/ir.h b/ir.h index 8c533c308a0..4266dbc17aa 100644 --- a/ir.h +++ b/ir.h @@ -532,6 +532,51 @@ public: private: ir_rvalue *value; }; + + +/** + * Jump instructions used inside loops + * + * These include \c break and \c continue. The \c break within a loop is + * different from the \c break within a switch-statement. + * + * \sa ir_switch_jump + */ +class ir_loop_jump : public ir_jump { +public: + enum jump_mode { + jump_break, + jump_continue + }; + + ir_loop_jump(ir_loop *loop, jump_mode mode) + : loop(loop), mode(mode) + { + /* empty */ + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + bool is_break() const + { + return mode == jump_break; + } + + bool is_continue() const + { + return mode == jump_continue; + } + +private: + /** Loop containing this break instruction. */ + ir_loop *loop; + + /** Mode selector for the jump instruction. */ + enum jump_mode mode; +}; /*@}*/ diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp index a94b0fc9e2a..7e1bb030f57 100644 --- a/ir_constant_expression.cpp +++ b/ir_constant_expression.cpp @@ -75,6 +75,7 @@ public: virtual void visit(ir_return *); virtual void visit(ir_if *); virtual void visit(ir_loop *); + virtual void visit(ir_loop_jump *); /*@}*/ /** @@ -473,3 +474,11 @@ ir_constant_visitor::visit(ir_loop *ir) (void) ir; value = NULL; } + + +void +ir_constant_visitor::visit(ir_loop_jump *ir) +{ + (void) ir; + value = NULL; +} diff --git a/ir_constant_folding.cpp b/ir_constant_folding.cpp index d7efdecc45f..e43f6f0ea4c 100644 --- a/ir_constant_folding.cpp +++ b/ir_constant_folding.cpp @@ -152,3 +152,10 @@ ir_constant_folding_visitor::visit(ir_loop *ir) { (void) ir; } + + +void +ir_constant_folding_visitor::visit(ir_loop_jump *ir) +{ + (void) ir; +} diff --git a/ir_constant_folding.h b/ir_constant_folding.h index 382f57c7e55..843b3ad0b77 100644 --- a/ir_constant_folding.h +++ b/ir_constant_folding.h @@ -59,5 +59,6 @@ public: virtual void visit(ir_return *); virtual void visit(ir_if *); virtual void visit(ir_loop *); + virtual void visit(ir_loop_jump *); /*@}*/ }; diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp index 76524261ecd..996beaf2908 100644 --- a/ir_print_visitor.cpp +++ b/ir_print_visitor.cpp @@ -319,3 +319,10 @@ ir_print_visitor::visit(ir_loop *ir) } printf("))\n"); } + + +void +ir_print_visitor::visit(ir_loop_jump *ir) +{ + printf("%s", ir->is_break() ? "break" : "continue"); +} diff --git a/ir_print_visitor.h b/ir_print_visitor.h index a6365bec7e2..82ebbac81f0 100644 --- a/ir_print_visitor.h +++ b/ir_print_visitor.h @@ -66,6 +66,7 @@ public: virtual void visit(ir_return *); virtual void visit(ir_if *); virtual void visit(ir_loop *); + virtual void visit(ir_loop_jump *); /*@}*/ private: diff --git a/ir_visitor.h b/ir_visitor.h index fab1a75d53f..323720e93ed 100644 --- a/ir_visitor.h +++ b/ir_visitor.h @@ -57,6 +57,7 @@ public: virtual void visit(class ir_return *) = 0; virtual void visit(class ir_if *) = 0; virtual void visit(class ir_loop *) = 0; + virtual void visit(class ir_loop_jump *) = 0; /*@}*/ };