Replace the part of the AST, as being pointed to by `src_sref`, with a specific statement `tgt_stmt`, and maintain the sref tree accordingly. Replace will try to perform copy on write as much as possible when the ScheduleState holds the only copy to the IRModule and
(
self,
src_sref: StmtSRef,
tgt_stmt: SBlock | For | SBlockRealize,
block_sref_reuse: dict[SBlock, SBlock] | None = None,
)
| 197 | ) |
| 198 | |
| 199 | def replace( |
| 200 | self, |
| 201 | src_sref: StmtSRef, |
| 202 | tgt_stmt: SBlock | For | SBlockRealize, |
| 203 | block_sref_reuse: dict[SBlock, SBlock] | None = None, |
| 204 | ) -> None: |
| 205 | """ |
| 206 | Replace the part of the AST, as being pointed to by `src_sref`, |
| 207 | with a specific statement `tgt_stmt`, and maintain the sref tree accordingly. |
| 208 | Replace will try to perform copy on write as much as possible when the ScheduleState holds |
| 209 | the only copy to the IRModule and IR nodes. |
| 210 | |
| 211 | Only 3 types of replacements are allowed: from `src_sref->stmt` to `tgt_stmt`. |
| 212 | 1) SBlock -> SBlock |
| 213 | 2) Loop -> Loop |
| 214 | 3) Loop -> BlockRealize |
| 215 | |
| 216 | Parameters |
| 217 | ---------- |
| 218 | src_sref : StmtSRef |
| 219 | The sref to the statement to be replaced in the TensorIR AST |
| 220 | |
| 221 | tgt_stmt : Union[Block, For, BlockRealize] |
| 222 | The statement to be replaced to |
| 223 | |
| 224 | block_sref_reuse : Optional[Dict[Block, Block]] = None |
| 225 | Maps an old block (to be replaced in the subtree under `src_sref->stmt`) |
| 226 | to a new block (replaced to, in the subtree under `tgt_stmt`), and enforces |
| 227 | reuse of srefs between them (rather than create new srefs) i.e. after being replaced, |
| 228 | the sref that points to the old block will point to the new one |
| 229 | |
| 230 | Note |
| 231 | ---- |
| 232 | The reuse of loop srefs are detected automatically according to the reuse of loop vars. |
| 233 | """ |
| 234 | if block_sref_reuse is None: |
| 235 | block_sref_reuse = {} |
| 236 | _ffi_api.ScheduleStateReplace( # type: ignore # pylint: disable=no-member |
| 237 | self, src_sref, tgt_stmt, block_sref_reuse |
| 238 | ) |
no outgoing calls