6
6
from ..core .configs import reverse_config_lookup , Config
7
7
from .new_analysis_core import *
8
8
from ..core .proc_eqv import get_repr_proc
9
- from .dataflow import LoopIR_to_DataflowIR , ScalarPropagation , D
9
+ from .dataflow import (
10
+ LoopIR_to_DataflowIR ,
11
+ ScalarPropagation ,
12
+ D ,
13
+ adom_to_aexpr ,
14
+ DataflowIR ,
15
+ )
10
16
11
17
12
18
def lift_dexpr ():
@@ -1662,7 +1668,85 @@ def bds(x, lo, hi):
1662
1668
1663
1669
1664
1670
def Check_DeleteConfigWrite (proc , stmts ):
1665
- assert len (stmts ) == 1
1671
+ assert len (stmts ) == 2
1672
+
1673
+ p = GetControlPredicates (proc , stmts ).result ()
1674
+ slv = SMTSolver (verbose = False )
1675
+ slv .push ()
1676
+ slv .assume (AMay (p ))
1677
+
1678
+ # Remain the existing pre-checking
1679
+ ap = PostEnv (proc , stmts ).get_posteffs ()
1680
+ a = [E .Guard (AMay (p ), stmts_effs (stmts ))]
1681
+
1682
+ # extract effects
1683
+ WrA , Mod = getsets ([ES .WRITE_ALL , ES .MODIFY ], a )
1684
+ WrAp , RdAp = getsets ([ES .WRITE_ALL , ES .READ_ALL ], ap )
1685
+ print (WrA )
1686
+ print (RdAp )
1687
+
1688
+ # check that `stmts` does not modify any non-global data
1689
+ # only_mod_glob = ADef(is_empty(LDiff(Mod, WrG)))
1690
+ # is_ok = slv.verify(only_mod_glob)
1691
+ # if not is_ok:
1692
+ # slv.pop()
1693
+ # raise SchedulingError(
1694
+ # f"Cannot delete or insert statements at {stmts[0].srcinfo} "
1695
+ # f"because they may modify non-configuration data"
1696
+ # )
1697
+
1698
+ # Below are the actual checks
1699
+ ir1 , d_stmts = LoopIR_to_DataflowIR (proc , stmts ).result ()
1700
+ ScalarPropagation (ir1 )
1701
+ print (ir1 )
1702
+ if isinstance (d_stmts [0 ][0 ], DataflowIR .For ):
1703
+ prev_nm = d_stmts [0 ][- 1 ].lhs
1704
+ post_nm = d_stmts [1 ][- 1 ].lhs
1705
+ else :
1706
+ prev_nm = d_stmts [0 ][0 ].lhs
1707
+ post_nm = d_stmts [1 ][0 ].lhs
1708
+ prev_val = adom_to_aexpr (prev_nm , ir1 .body .ctxt [prev_nm ])
1709
+ post_val = adom_to_aexpr (post_nm , ir1 .body .ctxt [post_nm ])
1710
+ cfg_mod = {pt .name : pt for pt in get_point_exprs (WrA )}
1711
+
1712
+ # consider every global that might be modified
1713
+ cfg_mod_visible = set ()
1714
+ for _ , pt in cfg_mod .items ():
1715
+ pt_e = A .Var (pt .name , T .R , null_srcinfo ())
1716
+ is_written = is_elem (pt , WrA )
1717
+ is_read_post = is_elem (pt , RdAp )
1718
+ is_overwritten = is_elem (pt , WrAp )
1719
+
1720
+ prev_k = A .Var (prev_nm , T .int , null_srcinfo ())
1721
+ post_k = A .Var (post_nm , T .int , null_srcinfo ())
1722
+
1723
+ is_unchanged = AImplies (AAnd (prev_val , post_val ), AEq (prev_k , post_k ))
1724
+ print (is_unchanged )
1725
+
1726
+ # if the value of the global might be read,
1727
+ # then it must not have been changed.
1728
+ safe_write = AImplies (AMay (is_read_post ), ADef (is_unchanged ))
1729
+ print (safe_write )
1730
+ if not slv .verify (is_unchanged ):
1731
+ slv .pop ()
1732
+ raise SchedulingError (
1733
+ f"Cannot change configuration value of { pt .name } "
1734
+ f"at { stmts [0 ].srcinfo } ; the new (and different) "
1735
+ f"values might be read later in this procedure"
1736
+ )
1737
+ # the write is invisible if its definitely unchanged or definitely
1738
+ # overwritten
1739
+ invisible = ADef (AOr (is_unchanged , is_overwritten ))
1740
+ if not slv .verify (invisible ):
1741
+ cfg_mod_visible .add (pt .name )
1742
+
1743
+ slv .pop ()
1744
+ return cfg_mod_visible
1745
+
1746
+
1747
+ """
1748
+ def Check_DeleteConfigWrite(proc, stmts):
1749
+ assert len(stmts) == 2
1666
1750
1667
1751
p = GetControlPredicates(proc, stmts).result()
1668
1752
slv = SMTSolver(verbose=False)
@@ -1690,7 +1774,10 @@ def Check_DeleteConfigWrite(proc, stmts):
1690
1774
# Below are the actual checks
1691
1775
ir1, d_stmts = LoopIR_to_DataflowIR(proc, stmts).result()
1692
1776
ScalarPropagation(ir1)
1693
- config1_vals , config2_vals = GetValues (ir1 , d_stmts ).result ()
1777
+ prev_nm = d_stmts[0][0].lhs
1778
+ post_nm = d_stmts[1][0].lhs
1779
+ prev_val = adom_to_aexpr(prev_nm, ir1.body.ctxt[prev_nm])
1780
+ post_val = adom_to_aexpr(post_nm, ir1.body.ctxt[post_nm])
1694
1781
cfg_mod = {pt.name: pt for pt in get_point_exprs(WrG)}
1695
1782
1696
1783
# consider every global that might be modified
@@ -1701,15 +1788,20 @@ def Check_DeleteConfigWrite(proc, stmts):
1701
1788
is_read_post = is_elem(pt, RdGp)
1702
1789
is_overwritten = is_elem(pt, WrGp)
1703
1790
1704
- akey = A .Var (pt .name .copy (), T .int , null_srcinfo ()) # type and srcinfo not sure
1705
- aval1 = lift_dexpr (config1_vals [pt .name ], key = akey )
1706
- aval2 = lift_dexpr (config2_vals [pt .name ], key = akey )
1791
+ prev_k = A.Var(prev_nm, T.int, null_srcinfo())
1792
+ post_k = A.Var(post_nm, T.int, null_srcinfo())
1793
+ print(repr(prev_k))
1794
+ print(repr(post_k))
1707
1795
1708
- is_unchanged = AAnd (AImplies (aval1 , aval2 ), AImplies (aval2 , aval1 ))
1796
+ # FIXME: Change this! wrong
1797
+ is_unchanged = AImplies(AAnd(prev_val, post_val), AEq(prev_k, post_k))
1798
+ print(pt_e)
1799
+ print(is_unchanged)
1709
1800
1710
1801
# if the value of the global might be read,
1711
1802
# then it must not have been changed.
1712
1803
safe_write = AImplies(AMay(is_read_post), ADef(is_unchanged))
1804
+ print(safe_write)
1713
1805
if not slv.verify(safe_write):
1714
1806
slv.pop()
1715
1807
raise SchedulingError(
@@ -1725,6 +1817,7 @@ def Check_DeleteConfigWrite(proc, stmts):
1725
1817
1726
1818
slv.pop()
1727
1819
return cfg_mod_visible
1820
+ """
1728
1821
1729
1822
1730
1823
# This equivalence check assumes that we can
0 commit comments