Skip to content

Commit 22f197b

Browse files
committed
tmp
1 parent 63ea35a commit 22f197b

File tree

13 files changed

+963
-189
lines changed

13 files changed

+963
-189
lines changed

crates/filament/src/ir_passes/build_domination.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ impl BuildDomination {
4646
// First pass to register all paremeter owners.
4747
for (id, cmd) in cmds.iter().enumerate() {
4848
match cmd {
49-
ir::Command::Let(ir::Let { param, .. }) => {
49+
ir::Command::Exists(ir::Exists { param, .. })
50+
| ir::Command::Let(ir::Let { param, .. }) => {
5051
log::trace!("let-bound param {}", comp.display(*param));
5152
param_map.insert(*param, id);
5253
}
@@ -72,21 +73,27 @@ impl BuildDomination {
7273
// Second pass to add dependencies between parameter owners and users.
7374
for (id, cmd) in cmds.iter().enumerate() {
7475
match cmd {
75-
ir::Command::Let(ir::Let { expr, param }) => {
76-
if let Some(expr) = expr {
77-
for idx in expr.relevant_vars(comp) {
78-
log::trace!(
79-
"param {} is used by {}",
80-
comp.display(idx),
81-
comp.display(*param)
82-
);
83-
if let Some(pid) = param_map.get(&idx) {
84-
// Add a dependency from the let to the parameter owner, if it is defined in this scope
85-
topo.add_dependency(*pid, id);
86-
}
76+
ir::Command::Let(ir::Let {
77+
expr: Some(expr),
78+
param,
79+
})
80+
| ir::Command::Exists(ir::Exists { param, expr }) => {
81+
for idx in expr.relevant_vars(comp) {
82+
log::trace!(
83+
"param {} is used by {}",
84+
comp.display(idx),
85+
comp.display(*param)
86+
);
87+
if let Some(pid) = param_map.get(&idx) {
88+
// Add a dependency from the let to the parameter owner, if it is defined in this scope
89+
topo.add_dependency(*pid, id);
8790
}
8891
}
8992
}
93+
ir::Command::Let(ir::Let { expr: None, .. }) => {
94+
// If the let does not have an expression, it depends on nothing.
95+
// We can ignore it.
96+
}
9097
ir::Command::Instance(inst) => {
9198
for idx in (*inst).relevant_vars(comp) {
9299
log::trace!(
@@ -154,6 +161,11 @@ impl BuildDomination {
154161
fn add_let(&mut self, let_: ir::Let) {
155162
self.plets.last_mut().unwrap().push(let_.into());
156163
}
164+
165+
fn add_exists(&mut self, exists: ir::Exists) {
166+
// We can treat exists as a let binding
167+
self.plets.last_mut().unwrap().push(exists.into());
168+
}
157169
}
158170

159171
impl Visitor for BuildDomination {
@@ -179,6 +191,16 @@ impl Visitor for BuildDomination {
179191
Action::Change(vec![])
180192
}
181193

194+
fn exists(
195+
&mut self,
196+
exists: &mut ir::Exists,
197+
_: &mut VisitorData,
198+
) -> Action {
199+
self.add_exists(exists.clone());
200+
// Remove the exists
201+
Action::Change(vec![])
202+
}
203+
182204
fn start_cmds(&mut self, _: &mut Vec<ir::Command>, _: &mut VisitorData) {
183205
self.start_scope();
184206
}

crates/filament/src/ir_passes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod lower;
1010
mod mono;
1111
mod phantom_check;
1212
mod prop_simplify;
13+
// mod schedule;
1314
mod type_check;
1415

1516
pub use assignment_check::AssignCheck;

crates/filament/src/ir_passes/mono/monodeferred.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ pub struct MonoDeferred<'comp, 'pass: 'comp> {
2424

2525
/// If this component should be scheduled, this stores the scheduling type
2626
pub schedule: Option<u64>,
27-
28-
/// Existential parameter map.
29-
/// These are not interned until [Self::sig_complete_mono] as scheduling
30-
/// may affect the values of existential parameters.
31-
exist_params:
32-
SparseInfoMap<ir::Param, Base<ir::Expr>, Underlying<ir::Param>>,
3327
}
3428

3529
impl<'a, 'pass: 'a> MonoDeferred<'a, 'pass> {
@@ -45,7 +39,6 @@ impl<'a, 'pass: 'a> MonoDeferred<'a, 'pass> {
4539
monosig,
4640
// Set to false if we call `sig_partial_mono` and true once we call `sig_complete_mono`
4741
sig_mono_complete: true,
48-
exist_params: SparseInfoMap::default(),
4942
}
5043
}
5144
}
@@ -105,12 +98,23 @@ impl MonoDeferred<'_, '_> {
10598

10699
// Insert the existential parameters into the monomorphization
107100
// Also extend the binding with existential parameters
108-
for (param, expr) in self.exist_params.iter() {
101+
let exist_params = self
102+
.monosig
103+
.binding
104+
.iter()
105+
.filter(|(p, _)| self.underlying.get(*p).is_existential())
106+
.copied()
107+
.collect_vec();
108+
109+
for (param, expr) in exist_params {
109110
let comp_key = self.monosig.comp_key.clone();
110111
let base_comp = self.monosig.base.comp();
111-
let v = expr.get().as_concrete(base_comp).unwrap();
112+
let v = expr.get().as_concrete(base_comp).unwrap_or_else(
113+
|| unreachable!("Existential parameter {} was bound to non-constant value {}", self.underlying.display(param), base_comp.display(expr.get())),
114+
);
112115

113116
self.pass.inst_info_mut(comp_key).add_exist_val(param, v);
117+
// replace the old binding with this new one
114118
self.monosig.push_binding(param, v);
115119
}
116120

@@ -286,30 +290,20 @@ impl MonoDeferred<'_, '_> {
286290
let ir::Fact { prop, reason, .. } = fact;
287291

288292
let prop = prop.ul();
289-
let (params, _) = self.underlying.relevant_vars(prop);
290293

291-
if !params
292-
.into_iter()
293-
.all(|idx| self.monosig.binding.get(&idx).is_some())
294-
{
295-
// Discards the assertion if it references parameters that can't be resolved (bundle parameters, etc)
296-
// TODO(edmund): Find a better solution to this - we should resolve bundle assertions when bundles are unrolled.
297-
None
298-
} else {
299-
let prop = self.monosig.prop(&self.underlying, prop, self.pass);
300-
let prop = self
301-
.monosig
302-
.base
303-
.resolve_prop(self.monosig.base.get(prop).clone())
304-
.get();
294+
let prop = self.monosig.prop(&self.underlying, prop, self.pass);
295+
// let prop = self
296+
// .monosig
297+
// .base
298+
// .resolve_prop(self.monosig.base.get(prop).clone())
299+
// .get();
305300

306-
let reason = reason.ul();
307-
let reason =
308-
self.monosig.info(&self.underlying, self.pass, reason).get();
301+
let reason = reason.ul();
302+
let reason =
303+
self.monosig.info(&self.underlying, self.pass, reason).get();
309304

310-
// After monomorphization, both assumes and asserts become asserts.
311-
Some(ir::Fact::assert(prop, reason))
312-
}
305+
// After monomorphization, both assumes and asserts become asserts.
306+
Some(ir::Fact::assert(prop.get(), reason))
313307
}
314308

315309
/// Compile the given command and return the generated command if any.
@@ -380,7 +374,7 @@ impl MonoDeferred<'_, '_> {
380374
let e =
381375
self.monosig.expr(&self.underlying, expr.ul(), self.pass);
382376

383-
self.exist_params.push(param.ul(), e);
377+
self.monosig.binding.push(param.ul(), e);
384378
None
385379
}
386380
// XXX(rachit): We completely get rid of facts in the program here.

crates/filament/src/ir_passes/mono/monosig.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,15 @@ impl MonoSig {
258258
}
259259
};
260260
unreachable!(
261-
"{} `{}' should have been resolved in the binding but the binding was: [{}]",
261+
"{} `{}' should have been resolved in the binding but the binding was: [{}], param_map was: {:?}",
262262
msg,
263263
p_rep,
264264
self.binding_rep(ul),
265+
self.param_map
266+
.clone()
267+
.iter()
268+
.map(|(k, v)| (ul.display(k), self.base.display(*v)))
269+
.collect_vec()
265270
)
266271
}
267272
}
@@ -854,6 +859,18 @@ impl MonoSig {
854859

855860
self.base.push_port_attrs(new_port, attrs.clone());
856861

862+
// Add the bundle parameters associated with this port.
863+
// We need to do this here because signature ports can have their
864+
// Bundle idxs referred to in assertions before their data has been monomorphized
865+
let ir::Liveness { idxs, .. } = live;
866+
867+
self.bundle_params(
868+
underlying,
869+
pass,
870+
&idxs.iter().map(|idx| idx.ul()).collect_vec(),
871+
new_port,
872+
);
873+
857874
// Overwrite the value in the port map if any. This is okay because this
858875
// method can be called on local ports defined in iterative scopes.
859876
self.port_map.insert(port_map_k, new_port);
@@ -880,17 +897,16 @@ impl MonoSig {
880897
// Find the new port owner
881898
let mono_owner = self.find_new_portowner(underlying, pass, owner);
882899

883-
let ir::Liveness { idxs, lens, range } = live;
884-
885-
let mono_idxs = self.bundle_params(
886-
underlying,
887-
pass,
888-
&idxs.iter().map(|idx| idx.ul()).collect_vec(),
889-
new_port,
890-
);
900+
let ir::Liveness { lens, range, .. } = live;
891901

892902
let mut mono_liveness = ir::Liveness {
893-
idxs: mono_idxs.iter().map(|idx| idx.get()).collect_vec(),
903+
idxs: self
904+
.bundle_param_map
905+
.get(&new_port)
906+
.unwrap()
907+
.iter()
908+
.map(|idx| idx.get())
909+
.collect_vec(),
894910
lens: vec![], // placeholder
895911
range: range.clone(), // placeholder
896912
};

crates/filament/src/ir_passes/schedule/retime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impl Retime {
8181
});
8282
src_info.events.push(event, "G".into());
8383
src_info.interface_ports.push(event, "write_en".into());
84-
8584
comp.event_args = Box::new([event]);
8685

8786
// Concrete expressions

0 commit comments

Comments
 (0)