@@ -414,7 +414,8 @@ def finalize_loopvar_type(self, body_var: Var):
414414
415415
416416class Builder :
417- def __init__ (self , ctx : IRContext , loc : Loc , reduction_body : bool = False ):
417+ def __init__ (self , ctx : IRContext , loc : Loc , reduction_body : bool = False ,
418+ scan_body : bool = False ):
418419 self .ir_ctx = ctx
419420 self .is_terminated = False
420421 self ._loc = loc
@@ -423,14 +424,18 @@ def __init__(self, ctx: IRContext, loc: Loc, reduction_body: bool = False):
423424 self ._prev_builder = None
424425 self ._var_map : Dict [str , Var ] = dict ()
425426 self .reduction_body = reduction_body
427+ self .scan_body = scan_body
426428
427429 def add_operation (self , op_class ,
428430 result_ty : Type | None | Tuple [Type | None , ...],
429431 attrs_and_operands ,
430432 result : Var | Sequence [Var ] | None = None ) -> Var | Tuple [Var , ...]:
431- if self .reduction_body and op_class .memory_effect != MemoryEffect .NONE :
432- raise TileSyntaxError ("Operations with memory effects are not supported"
433- " inside reduction body" )
433+ if (self .reduction_body or self .scan_body ) and op_class .memory_effect != MemoryEffect .NONE :
434+ if self .reduction_body :
435+ msg = "Operations with memory effects are not supported inside reduction body"
436+ else :
437+ msg = "Operations with memory effects are not supported inside scan body"
438+ raise TileSyntaxError (msg )
434439
435440 assert not self .is_terminated
436441 force_type = False
@@ -524,11 +529,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
524529
525530
526531@contextmanager
527- def nested_block (loc : Loc , reduction_body : bool = False ):
532+ def nested_block (loc : Loc , reduction_body : bool = False , scan_body : bool = False ):
528533 prev_builder = Builder .get_current ()
529534 block = Block (prev_builder .ir_ctx , loc = loc )
530535 with Builder (prev_builder .ir_ctx , loc ,
531- reduction_body = reduction_body or prev_builder .reduction_body ) as builder :
536+ reduction_body = reduction_body or prev_builder .reduction_body ,
537+ scan_body = scan_body or prev_builder .scan_body ) as builder :
532538 yield block
533539 block .extend (builder .ops )
534540
0 commit comments