Skip to content

Commit f2f9481

Browse files
committed
whatever progress
1 parent 6cc1f1d commit f2f9481

File tree

7 files changed

+396
-53
lines changed

7 files changed

+396
-53
lines changed

src/exo/analysis.py

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
from ..core.configs import reverse_config_lookup, Config
77
from .new_analysis_core import *
88
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+
)
1016

1117

1218
def lift_dexpr():
@@ -1662,7 +1668,85 @@ def bds(x, lo, hi):
16621668

16631669

16641670
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
16661750
16671751
p = GetControlPredicates(proc, stmts).result()
16681752
slv = SMTSolver(verbose=False)
@@ -1690,7 +1774,10 @@ def Check_DeleteConfigWrite(proc, stmts):
16901774
# Below are the actual checks
16911775
ir1, d_stmts = LoopIR_to_DataflowIR(proc, stmts).result()
16921776
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])
16941781
cfg_mod = {pt.name: pt for pt in get_point_exprs(WrG)}
16951782
16961783
# consider every global that might be modified
@@ -1701,15 +1788,20 @@ def Check_DeleteConfigWrite(proc, stmts):
17011788
is_read_post = is_elem(pt, RdGp)
17021789
is_overwritten = is_elem(pt, WrGp)
17031790
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))
17071795
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)
17091800
17101801
# if the value of the global might be read,
17111802
# then it must not have been changed.
17121803
safe_write = AImplies(AMay(is_read_post), ADef(is_unchanged))
1804+
print(safe_write)
17131805
if not slv.verify(safe_write):
17141806
slv.pop()
17151807
raise SchedulingError(
@@ -1725,6 +1817,7 @@ def Check_DeleteConfigWrite(proc, stmts):
17251817
17261818
slv.pop()
17271819
return cfg_mod_visible
1820+
"""
17281821

17291822

17301823
# This equivalence check assumes that we can

0 commit comments

Comments
 (0)