Add `@bound` attribute for loops with statically known bounds.
Closed this issue · 1 comments
cgyurgyik commented
Not thinking too hard about this, one way I can see it being done is adding another Optional variable to CFor
and CWhile
called staticBound
that can be used in the Calyx backend. @rachitnigam WDYT?
rachitnigam commented
I was thinking that we just generate the bound
for CFor loops since they always iterate over a finite domain. The computation should be straightforward: For a for (let i = s..e)
, we generate @bound(e - s)
. The one tricky part is that by the time loops get to the calyx backend generator, they've all been turned into CWhile
instead. For now, let's add:
case class CWhile(cond: Expr, pipeline: Boolean, body: Command, bound: Option[Int] = None)
And the LowerForLoops
pass can ensure that loops that started off as CFor
get the right bound. The backend generator can then add @bound(b)
for such loops.