tvm
tvm copied to clipboard
[TVMScript] Support continue and break in tvmscript
Add TIR intrinsics for break and continue semantics. It aims to provide roundtrip support for TVMScript frontend and help users to develop complex algorithms in more pythonic fashion.
Below are some notes:
-
Like
tir.retintroduced by https://github.com/apache/tvm/pull/7084, they are not first-class IR node but only intrinsic calls. -
The change implement the codegen for
candllvm. In llvm target, we check the innermost serial loop scope must exists. -
The change do not check the validity of TIR local function scopes and parallel launch scopes. Thus currently if the
continueandbreakare misused in a parallel for scope, the error might only raised in codegen phase lately. -
We have not implement precise TIR analysis of control flow with loop jumps, thus if there are
ret,break,continuein loops,existing analysis (eg, region lowerbound & upperbound) might not be robust.
cc @Kathryn-cat @spectrometerHBH
@tvm-bot re-run
the issue seems to be pr title
cc @tqchen @Kathryn-cat @spectrometerHBH
The pipeline get passed. Could you help to review? thanks!
would you like to add tests to printer/parser as well?
I think overall LGTM, the llvm codegen seems good, perhaps we can strengthen the test cases for "nested for/while loop" and "mixed break/continue in a loop" to make sure the control flow is correct?
@wrongtest-intellif could we rebase the latest branch? i think this is also a very good feature for other dsl development based on tir
cc @spectrometerHBH @Kathryn-cat Very thanks for the suggestions!
"mixed break/continue in a loop"
- Here is a bundle of ai-gen nested cases to check primfunc behave the same with raw golden python.
- https://gist.github.com/wrongtest-intellif/1c74cc7acbc48e34311cb6efc69eaaab
With break/continue introduced, such loop elimination should be handled carefully
- Add an annotation pass to help existing loop transformations be aware of loop jumps.
LGTM!