@@ -362,40 +362,10 @@ def build_visitor(self, op, ip):
362
362
self .build_op_handle (op , ip )
363
363
elif isinstance (op , ast .LoopHandle ):
364
364
self .build_loop_handle (op , ip )
365
- elif isinstance (op , ast .ReuseAtOp ):
366
- self .build_reuse_at_op (op , ip )
367
- elif isinstance (op , ast .PartitionOp ):
368
- self .build_partition_op (op , ip )
369
- elif isinstance (op , ast .ReplaceOp ):
370
- self .build_replace_op (op , ip )
371
- elif isinstance (op , ast .ReshapeOp ):
372
- self .build_reshape_op (op , ip )
373
- elif isinstance (op , ast .ReformOp ):
374
- self .build_reform_op (op , ip )
375
- elif isinstance (op , ast .BufferAtOp ):
376
- self .build_buffer_at_op (op , ip )
377
365
elif isinstance (op , ast .InterKernelToOp ):
378
366
self .build_inter_kernel_to_op (op , ip )
379
367
elif isinstance (op , ast .OutlineOp ):
380
368
self .build_outline_op (op , ip )
381
- elif isinstance (op , ast .ReorderOp ):
382
- self .build_reorder_op (op , ip )
383
- elif isinstance (op , ast .SplitOp ):
384
- self .build_split_op (op , ip )
385
- elif isinstance (op , ast .TileOp ):
386
- self .build_tile_op (op , ip )
387
- elif isinstance (op , ast .PipelineOp ):
388
- self .build_pipeline_op (op , ip )
389
- elif isinstance (op , ast .UnrollOp ):
390
- self .build_unroll_op (op , ip )
391
- elif isinstance (op , ast .ParallelOp ):
392
- self .build_parallel_op (op , ip )
393
- elif isinstance (op , ast .FuseOp ):
394
- self .build_fuse_op (op , ip )
395
- elif isinstance (op , ast .ComputeAtOp ):
396
- self .build_compute_at_op (op , ip )
397
- elif isinstance (op , ast .SystolicOp ):
398
- self .build_systolic_op (op , ip )
399
369
else :
400
370
raise HCLNotImplementedError (
401
371
f"{ type (op )} 's build visitor is not implemented yet."
@@ -469,6 +439,7 @@ def build_func_op(self, op: ast.FuncOp, ip):
469
439
# as the same argument object may be refered in multiple functions
470
440
# we need to make sure that the result is not reused
471
441
for arg in op .args :
442
+ arg .prev_result = arg .result
472
443
arg .result = None
473
444
474
445
def build_call_op (self , op : ast .CallOp , ip ):
@@ -1610,75 +1581,6 @@ def build_loop_handle(self, op: ast.LoopHandle, ip):
1610
1581
op .ir_op = hdl_op
1611
1582
op .result = hdl_op .result
1612
1583
1613
- def build_partition_op (self , op : ast .PartitionOp , ip ):
1614
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1615
- i32 = IntegerType .get_signless (32 )
1616
- ui32 = IntegerType .get_unsigned (32 )
1617
- partition_type = IntegerAttr .get (i32 , op .kind )
1618
- dim = IntegerAttr .get (ui32 , op .dim )
1619
- factor = IntegerAttr .get (ui32 , op .factor )
1620
- self .build_visitor (op .tensor , ip )
1621
- partition_op = hcl_d .PartitionOp (
1622
- op .tensor .result ,
1623
- partition_kind = partition_type ,
1624
- dim = dim ,
1625
- factor = factor ,
1626
- ip = ip ,
1627
- loc = loc ,
1628
- )
1629
- op .ir_op = partition_op
1630
-
1631
- def build_replace_op (self , op : ast .ReplaceOp , ip ):
1632
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1633
- self .build_visitor (op .target , ip )
1634
- self .build_visitor (op .src , ip )
1635
- replace_op = hcl_d .ReplaceOp (op .target .result , op .src .result , ip = ip , loc = loc )
1636
- op .ir_op = replace_op
1637
-
1638
- def build_reshape_op (self , op : ast .ReshapeOp , ip ):
1639
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1640
- self .build_visitor (op .tensor , ip )
1641
- eletype = hcl_dtype_to_mlir (op .tensor .dtype )
1642
- memref_type = MemRefType .get (op .shape , eletype , loc = loc )
1643
- reshape_op = hcl_d .ReshapeOp (memref_type , op .tensor .result , ip = ip , loc = loc )
1644
- op .ir_op = reshape_op
1645
-
1646
- def build_reform_op (self , op : ast .ReformOp , ip ):
1647
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1648
- self .build_visitor (op .target , ip )
1649
- if op .layout == "nhwc" :
1650
- attr = AffineMap .get_permutation ([0 , 2 , 3 , 1 ])
1651
- else :
1652
- raise RuntimeError ("Not supported layout" )
1653
- memref_type = MemRefType .get (op .target .shape , op .target .ir_op .dtype )
1654
- reform_op = hcl_d .ReformOp (memref_type , op .target .result , ip = ip , loc = loc )
1655
- reform_op .attributes ["layout" ] = AffineMapAttr .get (attr )
1656
- op .ir_op = reform_op
1657
-
1658
- def build_reuse_at_op (self , op : ast .ReuseAtOp , ip ):
1659
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1660
- self .build_visitor (op .target , ip )
1661
- self .build_visitor (op .axis , ip )
1662
- f32 = F32Type .get ()
1663
- memref_type = MemRefType .get ((1 ,), f32 , loc = loc )
1664
- reuse_at_op = hcl_d .ReuseAtOp (
1665
- memref_type , op .target .result , op .axis .result , ip = ip , loc = loc
1666
- )
1667
- op .ir_op = reuse_at_op
1668
- op .result = reuse_at_op .result
1669
-
1670
- def build_buffer_at_op (self , op : ast .BufferAtOp , ip ):
1671
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1672
- self .build_visitor (op .target , ip )
1673
- self .build_visitor (op .axis , ip )
1674
- f32 = F32Type .get ()
1675
- memref_type = MemRefType .get ((1 ,), f32 , loc = loc )
1676
- buffer_at_op = hcl_d .BufferAtOp (
1677
- memref_type , op .target .result , op .axis .result , ip = ip , loc = loc
1678
- )
1679
- op .ir_op = buffer_at_op
1680
- op .result = buffer_at_op .result
1681
-
1682
1584
def build_inter_kernel_to_op (self , op : ast .InterKernelToOp , ip ):
1683
1585
loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1684
1586
self .build_visitor (op .tensor , ip )
@@ -1704,79 +1606,3 @@ def build_outline_op(self, op: ast.OutlineOp, ip):
1704
1606
if op .axis is not None :
1705
1607
outline_op .attributes ["axis" ] = StringAttr .get (op .axis )
1706
1608
op .ir_op = outline_op
1707
-
1708
- def build_reorder_op (self , op : ast .ReorderOp , ip ):
1709
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1710
- for arg in op .args :
1711
- self .build_visitor (arg , ip )
1712
- arg_results = [arg .result for arg in op .args ]
1713
- reorder_op = hcl_d .ReorderOp (arg_results , ip = ip , loc = loc )
1714
- op .ir_op = reorder_op
1715
-
1716
- def build_split_op (self , op : ast .SplitOp , ip ):
1717
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1718
- self .build_visitor (op .parent , ip )
1719
- i32 = IntegerType .get_unsigned (32 )
1720
- factor = IntegerAttr .get (i32 , op .factor )
1721
- split_op = hcl_d .SplitOp (op .parent .result , factor , ip = ip , loc = loc )
1722
- op .ir_op = split_op
1723
- for result_loop_hdl , hdl_result in zip (op .results , split_op .results ):
1724
- result_loop_hdl .result = hdl_result
1725
-
1726
- def build_tile_op (self , op : ast .TileOp , ip ):
1727
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1728
- i32 = IntegerType .get_unsigned (32 )
1729
- x_factor = IntegerAttr .get (i32 , op .x_factor )
1730
- y_factor = IntegerAttr .get (i32 , op .y_factor )
1731
- self .build_visitor (op .x_parent , ip )
1732
- self .build_visitor (op .y_parent , ip )
1733
- tile_op = hcl_d .TileOp (
1734
- op .x_parent .result , op .y_parent .result , x_factor , y_factor , ip = ip , loc = loc
1735
- )
1736
- op .ir_op = tile_op
1737
- for result_loop_hdl , hdl_result in zip (op .results , tile_op .results ):
1738
- result_loop_hdl .result = hdl_result
1739
-
1740
- def build_pipeline_op (self , op : ast .PipelineOp , ip ):
1741
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1742
- self .build_visitor (op .target , ip )
1743
- i32 = IntegerType .get_unsigned (32 )
1744
- ii = IntegerAttr .get (i32 , op .ii )
1745
- pipeline_op = hcl_d .PipelineOp (op .target .result , ii = ii , ip = ip , loc = loc )
1746
- op .ir_op = pipeline_op
1747
-
1748
- def build_unroll_op (self , op : ast .UnrollOp , ip ):
1749
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1750
- self .build_visitor (op .target , ip )
1751
- i32 = IntegerType .get_unsigned (32 )
1752
- factor = IntegerAttr .get (i32 , op .factor )
1753
- unroll_op = hcl_d .UnrollOp (op .target .result , factor = factor , ip = ip , loc = loc )
1754
- op .ir_op = unroll_op
1755
-
1756
- def build_parallel_op (self , op : ast .ParallelOp , ip ):
1757
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1758
- self .build_visitor (op .target , ip )
1759
- parallel_op = hcl_d .ParallelOp (op .target .result , ip = ip , loc = loc )
1760
- op .ir_op = parallel_op
1761
-
1762
- def build_fuse_op (self , op : ast .FuseOp , ip ):
1763
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1764
- for arg in op .arg_list :
1765
- self .build_visitor (arg , ip )
1766
- arg_results = [arg .result for arg in op .arg_list ]
1767
- fuse_op = hcl_d .FuseOp (arg_results , ip = ip , loc = loc )
1768
- op .ir_op = fuse_op
1769
- op .result = fuse_op .result
1770
-
1771
- def build_compute_at_op (self , op : ast .ComputeAtOp , ip ):
1772
- loc = Location .file (op .loc .filename , op .loc .lineno , 0 )
1773
- self .build_visitor (op .stage , ip )
1774
- self .build_visitor (op .parent , ip )
1775
- self .build_visitor (op .axis , ip )
1776
- compute_at_op = hcl_d .ComputeAtOp (
1777
- op .stage .result , op .parent .result , op .axis .result , ip = ip , loc = loc
1778
- )
1779
- op .ir_op = compute_at_op
1780
-
1781
- def build_systolic_op (self , op : ast .SystolicOp , ip ):
1782
- op .target .ir_op .attributes ["systolic" ] = UnitAttr .get ()
0 commit comments