File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
python/mlir/dialects/transform Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 77from .._transform_ops_gen import _Dialect
88from ..._mlir_libs ._mlirDialectsTransform import *
99from ..._mlir_libs ._mlirDialectsTransform import AnyOpType , OperationType
10+ from . import interpreter
1011
1112try :
1213 from ...ir import *
@@ -324,6 +325,25 @@ def bodyTarget(self) -> Value:
324325 def bodyExtraArgs (self ) -> BlockArgumentList :
325326 return self .body .arguments [1 :]
326327
328+ def apply (
329+ self ,
330+ payload : Module ,
331+ transform_options : Optional [interpreter .TransformOptions ] = None ,
332+ ) -> Module :
333+ assert self .parent
334+ assert "transform.with_named_sequence" in self .parent .attributes
335+ assert isinstance (
336+ self .parent .attributes ["transform.with_named_sequence" ], UnitAttr
337+ )
338+
339+ interpreter .apply_named_sequence (
340+ payload_root = payload ,
341+ transform_root = self ,
342+ transform_module = self .parent ,
343+ transform_options = transform_options ,
344+ )
345+ return payload # NB: was modified in-place (if any transformation happened)
346+
327347
328348def named_sequence (
329349 sym_name : Union [str , SymbolRefAttr ],
Original file line number Diff line number Diff line change @@ -31,6 +31,20 @@ def print_self():
3131# CHECK: transform.yield
3232
3333
34+ @test_in_context
35+ def print_self_via_apply_method ():
36+ m = ir .Module .parse (
37+ print_root_module .replace ("from interpreter" , "print_self_via_apply_method" )
38+ )
39+ m .body .operations [0 ].apply (m )
40+
41+
42+ # CHECK-LABEL: print_self_via_apply_method
43+ # CHECK: transform.named_sequence @__transform_main
44+ # CHECK: transform.print
45+ # CHECK: transform.yield
46+
47+
3448@test_in_context
3549def print_other ():
3650 transform = ir .Module .parse (
You can’t perform that action at this time.
0 commit comments