Taichi: Support `continue` in loops

Created on 5 Apr 2020  路  4Comments  路  Source: taichi-dev/taichi

Concisely describe the proposed feature
It would be good to support continue in loops. E.g.,

@ti.kernel
def test():
     for i in x:
        if x[i] < 0:       
            continue # skip the rest of this loop body
        x[i] -= 1

Note that there are a few different cases: parallel range/struct for loops, serial range for loops, and while loops. However, the semantics is the same: jump to the end of the loop body so that the next iteration can start after this instruction.

Describe the solution you'd like (if any)

  • Add FrontendContinueStmt and ContinueStmt
  • Modify Python frontend
  • Modify lower_ast, ir_printer etc.
  • Implement the statement in each backend
feature request welcome contribution

Most helpful comment

Taking this. I haven't been able to work on IR for a while, and need to catch up..

All 4 comments

In the parallel case, is this the same as just returning from that struct_for/range_for task?

Right, just a jump to the loop body (if you are using SSA + CFG as in LLVM), or simply a return (in the parallel loop_body_function)/continue in serial loops in source-2-source.

Taking this. I haven't been able to work on IR for a while, and need to catch up..

Closed by #716

Was this page helpful?
0 / 5 - 0 ratings