stanford-ppl / spatial

Spatial: "Specify Parameterized Accelerators Through Inordinately Abstract Language"
https://spatial.stanford.edu
MIT License
271 stars 33 forks source link

Not Staging Return Value of IfThenElse #271

Open mattfel1 opened 4 years ago

mattfel1 commented 4 years ago

I'm not sure why it isn't staging the if branch's return of raw, or why it at least doesn't crash because the branches return different types (Void and I16). This eventually causes a crash in a post-unrolling TransientCleanup pass. I'm going to just rewrite the app for now, but it should at least have a rule in the sanity check if one branch of the IfThenElse/Switch doesn't return the correct type?

The app has:

      val raw = fifo.deq()
      val data = if (condition) {reg := raw; raw} else reg.value

Which becomes:

                    x21 = IfThenElse(x18,Block(x16),Block(x20)) {
                     - Name: data
                     - Type: Fix[TRUE,_16,_0]
                     - SrcCtx: DownUpSample.scala:106:29
                     - class spatial.metadata.control.ScopeCtrl: ScopeCtrl(x25 (scope: 0, 0))
                     - class spatial.metadata.control.ParentCtrl: ParentCtrl(x25 (stage: -1))
                     - class argon.Effects: (unique=true, reads={x15}, writes={x15})
                     - class argon.Consumers: Consumers(Set(x23, x25))
                     - class spatial.metadata.control.Children: Children(ArrayBuffer())
                     - class spatial.metadata.control.DefiningBlk: DefiningBlk(x25 (block: 0))
                     - class spatial.metadata.access.ReadUses: ReadUses(Set(x16, x20))
                     - class spatial.metadata.control.ControlLevel: ControlLevel(InnerControl)
                     - class argon.ShallowAliases: ShallowAliases(Set(x21))
                     - class argon.DeepAliases: DeepAliases(Set())
                    binds: 
                      block 0: Block(x16) {
                        effects:  (reads={x15}, writes={x15})
                          x19 = RegWrite(x15,x16,Set())
                           - Type: Void
                           - SrcCtx: DownUpSample.scala:106:29
                           - class argon.Effects: (reads={x15}, writes={x15})
                           - class argon.Consumers: Consumers(Set(x21))
                           - class spatial.metadata.control.DefiningBlk: DefiningBlk(x21 (block: 0))
                           - class spatial.metadata.access.ReadUses: ReadUses(Set(x16))
                           - class argon.ShallowAliases: ShallowAliases(Set(x19))
                           - class argon.DeepAliases: DeepAliases(Set())
                      } // End of x21 block #0
                      block 1: Block(x20) {
                        effects:  (unique=true, reads={x15})
                          x20 = RegRead(x15)
                           - Type: Fix[TRUE,_16,_0]
                           - SrcCtx: DownUpSample.scala:106:29
                           - class argon.Effects: (unique=true, reads={x15})
                           - class argon.Consumers: Consumers(Set(x21))
                           - class spatial.metadata.control.DefiningBlk: DefiningBlk(x21 (block: 1))
                           - class spatial.metadata.access.ReadUses: ReadUses(Set(x20))
                           - class argon.ShallowAliases: ShallowAliases(Set(x20))
                           - class argon.DeepAliases: DeepAliases(Set())
                      } // End of x21 block #1
                    } // End of x21