1313 IntegerType ,
1414 BoolAttr ,
1515)
16- from .._tune_transform_ops_gen import TuneSelectOp
16+ from .._tune_transform_ops_gen import *
1717
1818from collections .abc import Sequence
19- from typing import Union
19+ from typing import Union , Optional
2020
2121
2222def select (
23- selected : Type , # transform.any_param or transform.param<...>
23+ result : Type , # transform.any_param or transform.param<...>
2424 name : Union [str , Attribute ],
2525 options : Union [ArrayAttr , Sequence [Union [Attribute , str , int , bool ]]],
2626 loc = None ,
@@ -44,9 +44,60 @@ def select(
4444 options = ArrayAttr .get (option_attrs )
4545
4646 return TuneSelectOp (
47- selected = selected ,
47+ result = result ,
48+ name = name ,
49+ options = options ,
50+ loc = loc ,
51+ ip = ip ,
52+ )
53+
54+
55+ def pick (
56+ result : Type , # transform.any_param or transform.param<...>
57+ name : Union [str , Attribute ],
58+ options : Union [ArrayAttr , Sequence [Union [Attribute , str , int , bool ]]],
59+ * ,
60+ selected : Optional [Union [Attribute , str , int , bool ]] = None ,
61+ loc = None ,
62+ ip = None ,
63+ ) -> TunePickOp :
64+ if isinstance (name , str ):
65+ name = SymbolRefAttr .get ([name ])
66+
67+ if not isinstance (options , ArrayAttr ):
68+ option_attrs = []
69+ for option in options :
70+ if isinstance (option , str ):
71+ option_attrs .append (StringAttr .get (option ))
72+ elif isinstance (option , int ):
73+ int_type = IntegerType .get_signless (64 )
74+ option_attrs .append (IntegerAttr .get (int_type , option ))
75+ elif isinstance (option , bool ):
76+ option_attrs .append (BoolAttr .get (option ))
77+ elif isinstance (option , Attribute ):
78+ option_attrs .append (option )
79+ else :
80+ assert False
81+ options = ArrayAttr .get (option_attrs )
82+
83+
84+ if selected is None :
85+ pass
86+ elif isinstance (selected , str ):
87+ selected = StringAttr .get (selected )
88+ elif isinstance (selected , int ):
89+ int_type = IntegerType .get_signless (64 )
90+ selected = IntegerAttr .get (int_type , selected )
91+ elif isinstance (selected , bool ):
92+ selected = BoolAttr .get (selected )
93+ elif not isinstance (selected , Attribute ):
94+ assert False
95+
96+ return TunePickOp (
97+ result = result ,
4898 name = name ,
4999 options = options ,
100+ selected = selected ,
50101 loc = loc ,
51102 ip = ip ,
52103 )
0 commit comments