├── version.sbt ├── .sbtopts ├── project ├── build.properties └── plugin.sbt ├── test-out └── epfl │ ├── test4-patmat1.check │ ├── test4-matchertriv1.check │ ├── test4-matchertriv2.check │ ├── test4-matchertriv3.check │ ├── test5-noargfun.check │ ├── test13-interpret1.check │ ├── test5-tuplefun.check │ ├── test4-fac1.check │ ├── test5-twoargsfun.check │ ├── test10-worklist22.check │ ├── test5-schedfun.check │ ├── test10-worklist2.check │ ├── test5-twoargsrecfun.check │ ├── test10-transformrec1.check │ ├── test3-match2.check │ ├── test10-bwd1.check │ ├── test2-power3-dot.check │ ├── test8-speculative1b.check │ ├── test4-fac4.check │ ├── test8-speculative1.check │ ├── test3-match1.check │ ├── test9-cps2.check │ ├── test12-mkstring.check │ ├── test9-cps1.check │ ├── test2-power2-dot.check │ ├── test4-fac3.check │ ├── test9-csp1.check │ ├── test4-fac2.check │ ├── test9-struct6.check │ ├── test7-codemotion4.check │ ├── test7-liveness2.check │ ├── test9-csp2.check │ ├── test9-struct5.check │ ├── test7-codemotion5.check │ ├── test4-fac1-dot.check │ ├── test2-power1-dot.check │ ├── test8-speculative1c.check │ ├── test7-codemotion1.check │ ├── test8-speculative1d.check │ ├── test9-struct1.check │ ├── test7-liveness1.check │ ├── test8-mutation7.check │ ├── test8-speculative4.check │ ├── test14-cgen1.check │ ├── test10-transform1.check │ ├── test7-codemotion6.check │ ├── test4-fac5.check │ ├── test4-fac6.check │ ├── test12-map-flatmap-filter.check │ ├── test7-fusion3.check │ ├── test7-lambdalift1.check │ ├── test2-fft2.check │ ├── test7-codemotion2.check │ ├── test10-misc1.check │ ├── test7-codemotion7.check │ ├── test3-match2-dot.check │ ├── test14-cgen2.check │ ├── test5-funretfun.check │ ├── test14-dataop1.check │ ├── test10-transformrec2.check │ ├── test8-mutation1b.check │ ├── test12-array-seq-creation.check │ ├── test14-queries1.check │ ├── test11-stencil0.check │ ├── test4-ack1.check │ ├── test11-stencil2a.check │ ├── test8-mutation4c.check │ ├── test3-match1-dot.check │ ├── test5-conditional.html.check │ ├── test9-amb1b.check │ ├── test2-fft3.check │ ├── test7-fusion1.check │ ├── test8-mutation3b.check │ ├── test8-speculative5.check │ ├── test8-mutation3.check │ ├── test7-codemotion3.check │ ├── test6-vectors.check │ ├── test4-fac3-dot.check │ ├── test10-effects1.check │ ├── test8-mutation5.check │ ├── test8-mutation1.check │ ├── test11-hmm1.check │ ├── test8-speculative3.check │ ├── test8-speculative3b.check │ ├── test10-effects4.check │ ├── test8-mutation2.check │ ├── test14-dataop2.check │ ├── test11-hmm2.check │ ├── test11-stencil3a.check │ ├── test10-transformrec3.check │ ├── test14-queries2.check │ ├── test10-effects3.check │ ├── test4-fac4-dot.check │ ├── test8-mutation4.check │ ├── test5-functionsrecursive.check │ ├── test9-struct2.check │ ├── test5-functions.check │ ├── test12-concat.check │ ├── test10-worklist21.check │ ├── test4-counter1.check │ ├── test8-mutation4b.check │ ├── test5-conditional.check │ ├── test2-fft1.check │ ├── test10-effects2.check │ ├── test4-fac2-dot.check │ ├── test10-misc2.check │ ├── test14-queries3.check │ ├── test2-sort1.check │ ├── test10-worklist23.check │ ├── test14-queries4.check │ ├── test9-struct4.check │ ├── test14-cgen3.check │ ├── test9-amb1a.check │ ├── test8-mutation6.check │ ├── test2-power.check │ ├── test9-struct3.check │ ├── test9-struct2b.check │ ├── test10-transform2.check │ ├── test13-unstage1.check │ ├── test10-worklist3.check │ ├── test13-stable1.check │ ├── test7-fusion4.check │ ├── test10-worklist1.check │ ├── test2-fft2-dot.check │ ├── test4-matchernew1.check │ ├── test4-matchernew1b.check │ └── test7-fusion21.check ├── src ├── internal │ ├── Exceptions.scala │ ├── FatTraversal.scala │ ├── Utils.scala │ ├── Config.scala │ ├── FatScheduling.scala │ ├── FatCodegen.scala │ ├── GraphVizExport.scala │ ├── FatExpressions.scala │ └── AccModel.scala ├── common │ ├── ExportGraph.scala │ ├── Compile.scala │ ├── DSLOps.scala │ ├── FractionalOps.scala │ ├── SynchronizedArrayBufferOps.scala │ ├── ImplicitOps.scala │ ├── ExceptionOps.scala │ ├── Unchecked.scala │ └── LivenessOpt.scala └── util │ ├── ClosureCompare.scala │ └── GraphUtil.scala ├── .gitignore ├── test-src └── epfl │ ├── test2-fft │ ├── DisableOpts.scala │ └── TestSort.scala │ ├── test10-transform │ └── TestWIP.scalax │ ├── test1-arith │ ├── Trig.scala │ ├── Arrays.scala │ └── Relat.scala │ ├── test12-collections │ ├── TestArrayOps.scala │ └── TestList.scala │ ├── test4-functions │ ├── FooBar.scala │ ├── FunctionsGraphViz.scala │ ├── TestAckermann.scala │ └── TestPatMat.scala │ ├── FileDiffSuite.scala │ ├── test3-parsers │ ├── ExtractorsGraphViz.scala │ ├── Functions.scala │ └── Parsers.scala │ └── test5-js │ └── JSCompile.scala ├── .travis.yml ├── publish.sbt ├── README.md └── LICENSE /version.sbt: -------------------------------------------------------------------------------- 1 | version in ThisBuild := "1.1.0-SNAPSHOT" 2 | -------------------------------------------------------------------------------- /.sbtopts: -------------------------------------------------------------------------------- 1 | -J-Xms4G 2 | -J-Xmx4G 3 | -J-Xss2M 4 | -J-XX:+UseParallelGC -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | #Project properties 2 | sbt.version=0.13.15 3 | -------------------------------------------------------------------------------- /test-out/epfl/test4-patmat1.check: -------------------------------------------------------------------------------- 1 | NOTE: doesn't work yet :-( 2 | bar 3 | -------------------------------------------------------------------------------- /test-out/epfl/test4-matchertriv1.check: -------------------------------------------------------------------------------- 1 | found at List(W, A, A, A, A, B, Q) 2 | found at List(Q) 3 | -------------------------------------------------------------------------------- /test-out/epfl/test4-matchertriv2.check: -------------------------------------------------------------------------------- 1 | found at List(W, A, A, A, A, B, Q) 2 | found at List(Q) 3 | -------------------------------------------------------------------------------- /test-out/epfl/test4-matchertriv3.check: -------------------------------------------------------------------------------- 1 | found at List(W, A, A, A, A, B, Q) 2 | found at List(Q) 3 | -------------------------------------------------------------------------------- /test-out/epfl/test5-noargfun.check: -------------------------------------------------------------------------------- 1 | function main(x0) { 2 | var x1 = function() { 3 | return x0 4 | } 5 | var x2 = x1() 6 | return x2 7 | } 8 | -------------------------------------------------------------------------------- /src/internal/Exceptions.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | class GenerationFailedException(msg: String) extends Exception(msg) -------------------------------------------------------------------------------- /test-out/epfl/test13-interpret1.check: -------------------------------------------------------------------------------- 1 | spec-add-int: AddN(LookupN(n),ConstN(-1)) 2 | spec-add-int: AddN(LookupN(x),AppN(LookupN(a),LookupN(n))) 3 | 65280 4 | -------------------------------------------------------------------------------- /test-out/epfl/test5-tuplefun.check: -------------------------------------------------------------------------------- 1 | function main(x0) { 2 | var x3 = function(x1,x2) { 3 | return {_1:x1,_2:x2} 4 | } 5 | var x5 = x3(1.0,x0) 6 | return x5 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib_managed 2 | *.iml 3 | .idea/ 4 | .DS_Store 5 | local.properties 6 | project/boot 7 | project/build/target 8 | target/ 9 | test-out/ 10 | !test-out/**/*.check 11 | data/ -------------------------------------------------------------------------------- /test-out/epfl/test4-fac1.check: -------------------------------------------------------------------------------- 1 | TP(Sym(1),Lambda()) 2 | TP(Sym(2),Apply(Sym(1),Sym(0))) 3 | TP(Sym(3),Lambda()) 4 | TP(Sym(4),Apply(Sym(3),Sym(0))) 5 | TP(Sym(5),OrElse(List(Sym(2), Sym(4)))) 6 | Sym(5) 7 | -------------------------------------------------------------------------------- /src/common/ExportGraph.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import internal.GraphVizExport 5 | 6 | trait ExportGraph extends GraphVizExport { 7 | import IR._ 8 | 9 | def exportGraph(file: String, landscape: Boolean = false)(x: Exp[Any]) = 10 | emitDepGraph(x, file, landscape) 11 | 12 | } -------------------------------------------------------------------------------- /test-out/epfl/test5-twoargsfun.check: -------------------------------------------------------------------------------- 1 | function main(x0) { 2 | var x6 = function(x1,x2) { 3 | var x3 = x1 4 | var x4 = x2 5 | var x5 = {__structName:Tuple2DoubleDouble,_1:x4,_2:x3} 6 | return x5 7 | } 8 | var x8 = x6(x0,x0) 9 | var x9 = x8._1 10 | var x10 = x8._2 11 | var x11 = x6(x9,x10) 12 | return x11 13 | } 14 | -------------------------------------------------------------------------------- /src/common/Compile.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import internal.ScalaCompile 5 | 6 | trait Compile extends Base { 7 | 8 | def compile[A,B](f: Rep[A] => Rep[B])(implicit mA: Typ[A], mB: Typ[B]): A=>B 9 | 10 | } 11 | 12 | trait CompileScala extends Compile with BaseExp with ScalaCompile { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /test-out/epfl/test10-worklist22.check: -------------------------------------------------------------------------------- 1 | ### first 2 | register replacement for Sym(1) 3 | --- code --- 4 | val x1 = VectorZeros(Const(100)) 5 | val x3 = println(x1) 6 | 7 | ### next 8 | install replacement for Sym(1) 9 | --- code --- 10 | val x6 = LoopArray(100) { x5 => 11 | 0 12 | } 13 | val x7 = new VectorInt(x6,100) 14 | val x8 = println(x7) 15 | -------------------------------------------------------------------------------- /test-out/epfl/test5-schedfun.check: -------------------------------------------------------------------------------- 1 | function Test(x0) { 2 | var x1 = function(x2) { 3 | var x3 = function(x4) { 4 | var x5 = x4==0 5 | var x9 6 | if (x5) { 7 | x9=x2 8 | } else { 9 | var x6 = x4-1.0 10 | var x7 = x3(x6) 11 | x9=x7 12 | } 13 | return x9 14 | } 15 | var x11 = x3(x2) 16 | return x11 17 | } 18 | var x13 = x1(x0) 19 | return x13 20 | } 21 | -------------------------------------------------------------------------------- /test-out/epfl/test10-worklist2.check: -------------------------------------------------------------------------------- 1 | ### first 2 | register replacement for Sym(1) 3 | --- code --- 4 | val x1 = VectorZeros(Const(100)) 5 | val x3 = println(x1) 6 | 7 | ### next 8 | install replacement for Sym(1) 9 | --- code --- 10 | val x6 = LoopArray(100) { x5 => 11 | 0.0 12 | } 13 | val x7 = new VectorDouble(x6,100) 14 | val x8 = println(x7) 15 | -------------------------------------------------------------------------------- /test-out/epfl/test5-twoargsrecfun.check: -------------------------------------------------------------------------------- 1 | function main(x0) { 2 | var x1 = function(x2,x3) { 3 | var x4 = x2 4 | var x6 = x4==0 5 | var x12 6 | if (x6) { 7 | var x5 = x3 8 | x12=x5 9 | } else { 10 | var x7 = x4-1.0 11 | var x5 = x3 12 | var x8 = x4*x5 13 | var x10 = x1(x7,x8) 14 | x12=x10 15 | } 16 | return x12 17 | } 18 | var x15 = x1(x0,1.0) 19 | return x15 20 | } 21 | -------------------------------------------------------------------------------- /test-out/epfl/test10-transformrec1.check: -------------------------------------------------------------------------------- 1 | -- before transformation 2 | val x1 = {x2: (Double) => 3 | val x3 = x2 + 1.0 4 | x3 5 | } 6 | val x4 = x1(x0) 7 | -- after null transformation 8 | val x1 = {x2: (Double) => 9 | val x3 = x2 + 1.0 10 | x3 11 | } 12 | val x4 = x1(x0) 13 | -- after transformation 14 | val x5 = /*2*/{x2: (Double) => 15 | val x3 = x2 + 1.0 16 | x3 17 | } 18 | val x7 = x5(x0) 19 | -- done 20 | -------------------------------------------------------------------------------- /test-out/epfl/test3-match2.check: -------------------------------------------------------------------------------- 1 | TP(Sym(1),Lambda()) 2 | TP(Sym(2),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) 3 | TP(Sym(3),Test(Sym(2),7)) 4 | TP(Sym(4),Reify(Const(yes),List(Sym(2), Sym(3)))) 5 | TP(Sym(5),Lambda()) 6 | TP(Sym(6),Reify(Const(maybe),List(Sym(2)))) 7 | TP(Sym(7),Lambda()) 8 | TP(Sym(8),OrElse(List(Sym(4), Sym(6), Pure(Const(no))))) 9 | Pure(Sym(8)) 10 | -------------------------------------------------------------------------------- /test-out/epfl/test10-bwd1.check: -------------------------------------------------------------------------------- 1 | ===== first round 2 | { 3 | Sym(1) = WaitBwd(List(io),) 4 | Sym(2) = WaitBwd(List(),) 5 | Sym(5) = WaitBwd(List(io, io),) 6 | Const(8) 7 | } 8 | ===== second round 9 | { 10 | Sym(5) = if (Sym(2)) 11 | { 12 | Sym(3) = Print(Const(x)) 13 | Const(1) 14 | } 15 | else 16 | { 17 | Sym(4) = Print(Const(x)) 18 | Const(1) 19 | } 20 | Sym(1) = Print(Const(t)) 21 | Const(8) 22 | } 23 | -------------------------------------------------------------------------------- /test-src/epfl/test2-fft/DisableOpts.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test2 4 | 5 | import internal._ 6 | 7 | trait DisableCSE extends Expressions { 8 | override def findDefinition[T: Typ](d: Def[T]) = None 9 | } 10 | 11 | 12 | trait DisableDCE extends GraphTraversal { 13 | import IR._ 14 | override def buildScheduleForResult(start: Any, sort: Boolean = true): List[Stm] = 15 | globalDefs 16 | } 17 | 18 | -------------------------------------------------------------------------------- /test-out/epfl/test2-power3-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(2)" [ 3 | label="Sym(2) \n Plus(Sym(0),Sym(1))" 4 | shape=box 5 | ] 6 | "Sym(0)" -> "Sym(2)" 7 | "Sym(1)" -> "Sym(2)" 8 | "Sym(3)" [ 9 | label="Sym(3) \n Times(Sym(2),Sym(2))" 10 | shape=box 11 | ] 12 | "Sym(2)" -> "Sym(3)" 13 | "Sym(2)" -> "Sym(3)" 14 | "Sym(4)" [ 15 | label="Sym(4) \n Times(Sym(3),Sym(3))" 16 | shape=box 17 | ] 18 | "Sym(3)" -> "Sym(4)" 19 | "Sym(3)" -> "Sym(4)" 20 | } 21 | -------------------------------------------------------------------------------- /project/plugin.sbt: -------------------------------------------------------------------------------- 1 | resolvers += Classpaths.sbtPluginReleases 2 | 3 | // test coverage 4 | 5 | addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.0.1") 6 | 7 | addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.0.0.BETA1") 8 | 9 | // release process 10 | 11 | addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.0") 12 | 13 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") 14 | 15 | addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.5.0") -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative1b.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x3 = println(5) 7 | x3 8 | } 9 | } 10 | /***************************************** 11 | End of Generated Code 12 | *******************************************/ 13 | compilation: ok 14 | 5 15 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac4.check: -------------------------------------------------------------------------------- 1 | TP(Sym(3),Equal(Sym(2),Const(0))) 2 | TP(Sym(4),Lambda()) 3 | TP(Sym(5),Minus(Sym(2),Const(1.0))) 4 | TP(Sym(6),Apply(Sym(1),Sym(5))) 5 | TP(Sym(7),Times(Sym(2),Sym(6))) 6 | TP(Sym(8),IfThenElse(Sym(3),Block(Const(1.0)),Block(Sym(7)))) 7 | TP(Sym(1),DefineFun(Block(Sym(8)))) 8 | TP(Sym(9),Apply(Sym(1),Sym(0))) 9 | TP(Sym(10),Times(Const(2.0),Sym(0))) 10 | TP(Sym(11),Apply(Sym(1),Sym(10))) 11 | TP(Sym(12),Plus(Sym(9),Sym(11))) 12 | Sym(12) 13 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x2 = println(7) 7 | val x3 = println(7) 8 | x3 9 | } 10 | } 11 | /***************************************** 12 | End of Generated Code 13 | *******************************************/ 14 | compilation: ok 15 | 7 16 | 7 17 | -------------------------------------------------------------------------------- /test-out/epfl/test3-match1.check: -------------------------------------------------------------------------------- 1 | TP(Sym(1),Lambda()) 2 | TP(Sym(2),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) 3 | TP(Sym(3),Test(Sym(2),7)) 4 | TP(Sym(4),Reify(Const(yes),List(Sym(2), Sym(3)))) 5 | TP(Sym(5),Lambda()) 6 | TP(Sym(6),Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))) 7 | TP(Sym(7),Reify(Const(maybe),List(Sym(6)))) 8 | TP(Sym(8),Lambda()) 9 | TP(Sym(9),OrElse(List(Sym(4), Sym(7), Pure(Const(no))))) 10 | Pure(Sym(9)) 11 | -------------------------------------------------------------------------------- /test-out/epfl/test9-cps2.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Boolean)=>(Unit)) { 5 | def apply(x0:Boolean): Unit = { 6 | val x5 = if (x0) { 7 | val x1 = println(7) 8 | x1 9 | } else { 10 | val x3 = println(9) 11 | x3 12 | } 13 | x5 14 | } 15 | } 16 | /***************************************** 17 | End of Generated Code 18 | *******************************************/ 19 | -------------------------------------------------------------------------------- /test-out/epfl/test12-mkstring.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class MkString extends ((scala.collection.immutable.List[Int])=>(java.lang.String)) { 5 | def apply(x0:scala.collection.immutable.List[Int]): java.lang.String = { 6 | val x1 = x0.mkString 7 | x1 8 | } 9 | } 10 | /***************************************** 11 | End of Generated Code 12 | *******************************************/ 13 | -------------------------------------------------------------------------------- /src/internal/FatTraversal.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | import util.GraphUtil 5 | import java.io.{File, PrintWriter} 6 | 7 | 8 | trait FatBlockTraversal extends NestedBlockTraversal with FatScheduling { 9 | val IR: Expressions with Effects with FatExpressions 10 | import IR._ 11 | 12 | 13 | 14 | override def focusFatBlock[A](result: List[Block[Any]])(body: => A): A = { 15 | super.focusFatBlock(result) { 16 | innerScope = fattenAll(innerScope) 17 | body 18 | } 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /test-out/epfl/test9-cps1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Boolean)=>(Unit)) { 5 | def apply(x0:Boolean): Unit = { 6 | val x5 = if (x0) { 7 | val x1 = println("is true") 8 | x1 9 | } else { 10 | val x3 = println("is false") 11 | x3 12 | } 13 | x5 14 | } 15 | } 16 | /***************************************** 17 | End of Generated Code 18 | *******************************************/ 19 | -------------------------------------------------------------------------------- /src/internal/Utils.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | // TODO: add logging, etc. 5 | trait Utils extends Config { 6 | def __ = throw new RuntimeException("unsupported embedded dsl operation") 7 | 8 | def printdbg(x: =>Any) { if (verbosity >= 2) System.err.println(x) } 9 | def printlog(x: =>Any) { if (verbosity >= 1) System.err.println(x) } 10 | def printerr(x: =>Any) { System.err.println(x); hadErrors = true } 11 | 12 | def printsrc(x: =>Any) { if (sourceinfo >= 1) System.err.println(x) } 13 | 14 | var hadErrors = false 15 | } -------------------------------------------------------------------------------- /test-out/epfl/test2-power2-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(2)" [ 3 | label="Sym(2) \n Plus(Sym(0),Sym(1))" 4 | shape=box 5 | ] 6 | "Sym(0)" -> "Sym(2)" 7 | "Sym(1)" -> "Sym(2)" 8 | "Sym(3)" [ 9 | label="Sym(3) \n Times(Sym(2),Sym(2))" 10 | shape=box 11 | ] 12 | "Sym(2)" -> "Sym(3)" 13 | "Sym(2)" -> "Sym(3)" 14 | "Sym(4)" [ 15 | label="Sym(4) \n Times(Sym(2),Sym(3))" 16 | shape=box 17 | ] 18 | "Sym(2)" -> "Sym(4)" 19 | "Sym(3)" -> "Sym(4)" 20 | "Sym(5)" [ 21 | label="Sym(5) \n Times(Sym(2),Sym(4))" 22 | shape=box 23 | ] 24 | "Sym(2)" -> "Sym(5)" 25 | "Sym(4)" -> "Sym(5)" 26 | } 27 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac3.check: -------------------------------------------------------------------------------- 1 | -- hit recursion: class scala.lms.epfl.test3.MatchingExtractorsExp$$anonfun$liftAlt$1$1 Sym(5) <- Sym(0) 2 | TP(Sym(1),Lambda()) 3 | TP(Sym(2),Test(Sym(0),0.0)) 4 | TP(Sym(3),Reify(Const(1.0),List(Sym(2)))) 5 | TP(Sym(4),Lambda()) 6 | TP(Sym(5),Minus(Sym(0),Const(1.0))) 7 | TP(Sym(6),Test(Sym(5),0.0)) 8 | TP(Sym(7),Reify(Const(1.0),List(Sym(6)))) 9 | TP(Sym(8),Apply(Sym(-2),Sym(5))) 10 | TP(Sym(9),OrElse(List(Sym(7), Sym(8)))) 11 | TP(Sym(10),Times(Sym(0),Sym(9))) 12 | TP(Sym(11),OrElse(List(Sym(3), Pure(Sym(10))))) 13 | Sym(11) 14 | -------------------------------------------------------------------------------- /test-out/epfl/test9-csp1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test(px1:scala.Function1[Int, Unit]) extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = px1 // static data: 7 | val x2 = x1(x0) 8 | x2 9 | } 10 | } 11 | /***************************************** 12 | End of Generated Code 13 | *******************************************/ 14 | -- running program 15 | compilation: ok 16 | this is external non-DSL code: 42 17 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac2.check: -------------------------------------------------------------------------------- 1 | TP(Sym(3),Test(Sym(2),0.0)) 2 | TP(Sym(4),Reify(Const(1.0),List(Sym(3)))) 3 | TP(Sym(1),DefineFun(Block(Sym(4)))) 4 | TP(Sym(5),Lambda()) 5 | TP(Sym(6),Apply(Sym(1),Sym(0))) 6 | TP(Sym(9),Minus(Sym(8),Const(1.0))) 7 | TP(Sym(10),Apply(Sym(1),Sym(9))) 8 | TP(Sym(11),Lambda()) 9 | TP(Sym(12),Apply(Sym(7),Sym(9))) 10 | TP(Sym(13),OrElse(List(Sym(10), Sym(12)))) 11 | TP(Sym(14),Times(Sym(8),Sym(13))) 12 | TP(Sym(7),DefineFun(Block(Pure(Sym(14))))) 13 | TP(Sym(15),Apply(Sym(7),Sym(0))) 14 | TP(Sym(16),OrElse(List(Sym(6), Sym(15)))) 15 | Sym(16) 16 | -------------------------------------------------------------------------------- /test-out/epfl/test9-struct6.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = new Anon189207751(1.0,2.0) 7 | val x2 = println(x1) 8 | val x3 = new Anon189207751(3.0,4.0) 9 | val x4 = println(x3) 10 | x4 11 | } 12 | } 13 | /***************************************** 14 | End of Generated Code 15 | *******************************************/ 16 | 17 | case class Anon189207751(re: Double, im: Double) 18 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion4.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Double, Unit])) { 5 | def apply(x0:Unit): scala.Function1[Double, Unit] = { 6 | val x7 = {x1: (Double) => 7 | val x5 = if (true) { 8 | val x2 = x1 + 1.0 9 | val x3 = println(x2) 10 | () 11 | } else { 12 | () 13 | } 14 | x5: Unit 15 | } 16 | x7 17 | } 18 | } 19 | /***************************************** 20 | End of Generated Code 21 | *******************************************/ 22 | -------------------------------------------------------------------------------- /test-out/epfl/test7-liveness2.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(Unit)) { 5 | def apply(x0:Unit): Unit = { 6 | val x1 = new Array[Int](100) 7 | val x2 = x1 8 | x2(7) = 42 9 | val x3 = x2.clone() 10 | x3(2) = 42 11 | val x4 = x2 12 | x4(4) = 42 13 | val x5 = x3 14 | arrayPlus(x5,x3,x4) 15 | // kill: x4 16 | val x6 = println(x5) 17 | // kill: x5 18 | x6 19 | } 20 | } 21 | /***************************************** 22 | End of Generated Code 23 | *******************************************/ 24 | -------------------------------------------------------------------------------- /test-out/epfl/test9-csp2.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test(px1:scala.collection.mutable.ArrayBuffer[Int]) extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = px1 // static data: ArrayBuffer() 7 | val x2 = x1 += x0 8 | val x3 = x1 += x0 9 | val x4 = println("done") 10 | x4 11 | } 12 | } 13 | /***************************************** 14 | End of Generated Code 15 | *******************************************/ 16 | -- running program 17 | compilation: ok 18 | done 19 | accumulated: 21,21 20 | -------------------------------------------------------------------------------- /test-out/epfl/test9-struct5.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = new Anon189214509(1.0,2.0) 7 | val x2 = println(x1) 8 | val x3 = new Anon189207751(3.0,4.0) 9 | val x4 = println(x3) 10 | x4 11 | } 12 | } 13 | /***************************************** 14 | End of Generated Code 15 | *******************************************/ 16 | 17 | case class Anon189214509(x: Double, y: Double) 18 | 19 | case class Anon189207751(re: Double, im: Double) 20 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion5.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Double, Unit])) { 5 | def apply(x0:Unit): scala.Function1[Double, Unit] = { 6 | val x8 = if (true) { 7 | val x2 = 7.0 + 9.0 8 | val x5 = {x1: (Double) => 9 | val x3 = println(x2) 10 | x3: Unit 11 | } 12 | x5 13 | } else { 14 | val x7 = {x6: (Double) => 15 | (): Unit 16 | } 17 | x7 18 | } 19 | x8 20 | } 21 | } 22 | /***************************************** 23 | End of Generated Code 24 | *******************************************/ 25 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac1-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(1)" [ 3 | label="Sym(1) \n Lambda()" 4 | shape=box 5 | ] 6 | "Sym(2)" [ 7 | label="Sym(2) \n Apply(Sym(1),Sym(0))" 8 | shape=box 9 | color=blue 10 | style=filled 11 | ] 12 | "Sym(1)" -> "Sym(2)" 13 | "Sym(0)" -> "Sym(2)" 14 | "Sym(3)" [ 15 | label="Sym(3) \n Lambda()" 16 | shape=box 17 | ] 18 | "Sym(4)" [ 19 | label="Sym(4) \n Apply(Sym(3),Sym(0))" 20 | shape=box 21 | color=blue 22 | style=filled 23 | ] 24 | "Sym(3)" -> "Sym(4)" 25 | "Sym(0)" -> "Sym(4)" 26 | "Sym(5)" [ 27 | label="Sym(5) \n OrElse(List(Sym(2), Sym(4)))" 28 | shape=box 29 | ] 30 | "Sym(2)" -> "Sym(5)" 31 | "Sym(4)" -> "Sym(5)" 32 | } 33 | -------------------------------------------------------------------------------- /test-out/epfl/test2-power1-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(2)" [ 3 | label="Sym(2) \n Plus(Sym(0),Sym(1))" 4 | shape=box 5 | ] 6 | "Sym(0)" -> "Sym(2)" 7 | "Sym(1)" -> "Sym(2)" 8 | "Sym(3)" [ 9 | label="Sym(3) \n Times(Sym(2),Const(1.0))" 10 | shape=box 11 | ] 12 | "Sym(2)" -> "Sym(3)" 13 | "Sym(4)" [ 14 | label="Sym(4) \n Times(Sym(2),Sym(3))" 15 | shape=box 16 | ] 17 | "Sym(2)" -> "Sym(4)" 18 | "Sym(3)" -> "Sym(4)" 19 | "Sym(5)" [ 20 | label="Sym(5) \n Times(Sym(2),Sym(4))" 21 | shape=box 22 | ] 23 | "Sym(2)" -> "Sym(5)" 24 | "Sym(4)" -> "Sym(5)" 25 | "Sym(6)" [ 26 | label="Sym(6) \n Times(Sym(2),Sym(5))" 27 | shape=box 28 | ] 29 | "Sym(2)" -> "Sym(6)" 30 | "Sym(5)" -> "Sym(6)" 31 | } 32 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative1c.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x1: Int = 7 7 | val x2 = 7 > x0 8 | // TODO: use vars instead of tuples to return multiple values 9 | val (x10,x8) = if (x2) { 10 | x1 = 5 11 | ((),()) 12 | } else { 13 | val x5 = println("no") 14 | ((),()) 15 | } 16 | val x12 = x1 17 | val x13 = println(x12) 18 | x13 19 | } 20 | } 21 | /***************************************** 22 | End of Generated Code 23 | *******************************************/ 24 | compilation: ok 25 | no 26 | 7 27 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Double, scala.Function1[Double, Double]])) { 5 | def apply(x0:Unit): scala.Function1[Double, scala.Function1[Double, Double]] = { 6 | val x4 = 4.0 * 3.0 7 | val x7 = {x2: (Double) => 8 | val x3 = println("yo") 9 | val x5 = x2 + x4 10 | x5: Double 11 | } 12 | val x8 = {x1: (Double) => 13 | x7: scala.Function1[Double, Double] 14 | } 15 | x8 16 | } 17 | } 18 | /***************************************** 19 | End of Generated Code 20 | *******************************************/ 21 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative1d.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x1: Int = 7 7 | val x3 = 7 > x0 8 | // TODO: use vars instead of tuples to return multiple values 9 | val (x15,x11) = if (x3) { 10 | x1 = 5 11 | ((),()) 12 | } else { 13 | val x7 = println("no") 14 | ((),()) 15 | } 16 | val x17 = x1 17 | val x18 = println(x17) 18 | x18 19 | } 20 | } 21 | /***************************************** 22 | End of Generated Code 23 | *******************************************/ 24 | compilation: ok 25 | no 26 | 7 27 | -------------------------------------------------------------------------------- /test-out/epfl/test9-struct1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x2: Int = x0 7 | var x3: Double = 0.0 8 | val x5 = x2 9 | val x6 = x3 10 | val x9 = x5 + 0.0 11 | x2 = x9 12 | val x10 = x6 + x0 13 | x3 = x10 14 | val x14 = x2 15 | val x15 = x3 16 | val x16 = new Anon189207751(x14,x15) 17 | val x17 = println(x16) 18 | x17 19 | } 20 | } 21 | /***************************************** 22 | End of Generated Code 23 | *******************************************/ 24 | 25 | case class Anon189207751(re: Int, im: Double) 26 | -------------------------------------------------------------------------------- /test-out/epfl/test7-liveness1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(Unit)) { 5 | def apply(x0:Unit): Unit = { 6 | val x1 = new Array[Int](100) 7 | val x2 = x1.clone() 8 | x2(7) = 42 9 | // kill: x1 10 | val x3 = x2.clone() 11 | x3(2) = 42 12 | val x4 = x2.clone() 13 | x4(4) = 42 14 | // kill: x2 15 | val x5 = new Array[Int](x3.length) 16 | arrayPlus(x5,x3,x4) 17 | // kill: x3, x4 18 | val x6 = println(x5) 19 | // kill: x5 20 | x6 21 | } 22 | } 23 | /***************************************** 24 | End of Generated Code 25 | *******************************************/ 26 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation7.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x1: Double = 0.0 7 | val x9 = while ({val x2 = x1 8 | val x3 = x2 < x0 9 | x3}) { 10 | val x5 = x1 11 | val x6 = x5 + 1.0 12 | x1 = x6 13 | () 14 | } 15 | val x10 = x1 16 | val x11 = x10 < x0 17 | val x14 = if (x11) { 18 | x1 = 8.0 19 | () 20 | } else { 21 | () 22 | } 23 | val x15 = x1 24 | val x16 = println(x15) 25 | x16 26 | } 27 | } 28 | /***************************************** 29 | End of Generated Code 30 | *******************************************/ 31 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative4.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | while ({ // List(Sym(18)) 7 | // dummy placeholder for previous iteration: List(Sym(11)) = Sym(3) / List() 8 | false 9 | }) { 10 | // dummy placeholder for previous iteration: List(Sym(13)) = Sym(2) / List() 11 | val x14 = println("booooring!") 12 | } 13 | val x19 = println("done") 14 | x19 15 | } 16 | } 17 | /***************************************** 18 | End of Generated Code 19 | *******************************************/ 20 | compilation: ok 21 | done 22 | -------------------------------------------------------------------------------- /test-out/epfl/test14-cgen1.check: -------------------------------------------------------------------------------- 1 | /* FILE: main.c */ 2 | int32_t main(int32_t); 3 | /***************************************** 4 | Emitting C Generated Code 5 | *******************************************/ 6 | #include 7 | #include 8 | #include 9 | #include 10 | int32_t main(int32_t x0) { 11 | int32_t x1 = 0; 12 | for (;;) { 13 | int32_t x2 = x1; 14 | bool x3 = x2 < 10; 15 | if (!x3) break; 16 | int32_t x5 = x1; 17 | printf(string("Hello, world! %d\n").c_str(),x5); 18 | int32_t x7 = x5 + 1; 19 | x1 = x7; 20 | } 21 | return 0; 22 | } 23 | /***************************************** 24 | End of C Generated Code 25 | *******************************************/ 26 | -------------------------------------------------------------------------------- /test-out/epfl/test10-transform1.check: -------------------------------------------------------------------------------- 1 | -- full graph 2 | TP(Sym(1),VectorZeros(Const(100))) 3 | TP(Sym(2),VectorPlus(Sym(1),Sym(1))) 4 | TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 5 | TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 6 | TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))) 7 | -- before transformation 8 | val x1 = VectorZeros(Const(100)) 9 | val x2 = VectorPlus(Sym(1),Sym(1)) 10 | val x3 = VectorPlus(Sym(1),Sym(2)) 11 | val x4 = println(x3) 12 | -- after transformation 13 | val x1 = VectorZeros(Const(100)) 14 | val x2 = VectorPlus(Sym(1),Sym(1)) 15 | val x3 = VectorPlus(Sym(1),Sym(2)) 16 | val x6 = println(x3) 17 | -- done 18 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion6.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Boolean, Unit])) { 5 | def apply(x0:Unit): scala.Function1[Boolean, Unit] = { 6 | val x4 = if (true) { 7 | val x1 = 7.0 + 9.0 8 | val x2 = println(x1) 9 | x2 10 | } else { 11 | () 12 | } 13 | val x8 = {x5: (Boolean) => 14 | val x6 = println(x4) 15 | x6: Unit 16 | } 17 | x8 18 | } 19 | } 20 | /***************************************** 21 | End of Generated Code 22 | *******************************************/ 23 | // NOTE: generated code is not ideal yet (x1=7+9 should be moved inside conditional). see source for discussion. 24 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac5.check: -------------------------------------------------------------------------------- 1 | 2 | 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | class Fac extends ((Double)=>(Double)) { 7 | def apply(x0:Double): Double = { 8 | var x1 = null.asInstanceOf[scala.Function1[Double, Double]] 9 | x1 = {x2: (Double) => 10 | val x3 = x2 == 0 11 | val x8 = if (x3) { 12 | 1.0 13 | } else { 14 | val x5 = x2-1.0 15 | val x6 = x1(x5) 16 | val x7 = x2*x6 17 | x7 18 | } 19 | x8 20 | } 21 | val x9 = x1(x0) 22 | val x10 = 2.0*x0 23 | val x11 = x1(x10) 24 | val x12 = x9+x11 25 | x12 26 | } 27 | } 28 | /***************************************** 29 | End of Generated Code 30 | *******************************************/ 31 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac6.check: -------------------------------------------------------------------------------- 1 | 2 | 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | class Fac extends ((Double)=>(Double)) { 7 | def apply(x0:Double): Double = { 8 | var x1 = null.asInstanceOf[scala.Function1[Double, Double]] 9 | x1 = {x2: (Double) => 10 | val x3 = x2 == 0 11 | val x8 = if (x3) { 12 | 1.0 13 | } else { 14 | val x4 = x2-1.0 15 | val x5 = x1(x4) 16 | val x6 = x2*x5 17 | x6 18 | } 19 | x8: Double 20 | } 21 | val x10 = x1(x0) 22 | val x11 = 2.0*x0 23 | val x12 = x1(x11) 24 | val x13 = x10+x12 25 | x13 26 | } 27 | } 28 | /***************************************** 29 | End of Generated Code 30 | *******************************************/ 31 | -------------------------------------------------------------------------------- /test-out/epfl/test12-map-flatmap-filter.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class MapFlatMapAndFilter extends ((scala.collection.immutable.List[Int])=>(scala.collection.immutable.List[Int])) { 5 | def apply(x0:scala.collection.immutable.List[Int]): scala.collection.immutable.List[Int] = { 6 | val x2 = List(1,2,3) 7 | val x5 = x2.filter { x3 => 8 | val x4 = x3 < 3 9 | 10 | x4 11 | } 12 | val x9 = x0.flatMap { x1 => 13 | val x8 = x5.map { x6 => 14 | val x7 = x1 * x6 15 | 16 | x7 17 | } 18 | 19 | x8 20 | } 21 | x9 22 | } 23 | } 24 | /***************************************** 25 | End of Generated Code 26 | *******************************************/ 27 | -------------------------------------------------------------------------------- /test-out/epfl/test7-fusion3.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(Unit)) { 5 | def apply(x0:Unit): Unit = { 6 | var x2 = new Array[Int](100) 7 | for (x1 <- 0 until 100) { 8 | x2(x1) = x1 9 | } 10 | var x6 = new ArrayBuilder[Int] 11 | for (x3 <- 0 until 100) { 12 | val x4 = x2.apply(x3) 13 | val x5 = x4 > 50 14 | if (x5) x6 += x4 15 | } 16 | val x7 = x6.length 17 | var x10: Int = 0 18 | for (x8 <- 0 until x7) { 19 | val x9 = x6.apply(x8) 20 | x10 += x9 21 | } 22 | val x11 = println(x10) 23 | x11 24 | } 25 | } 26 | /***************************************** 27 | End of Generated Code 28 | *******************************************/ 29 | -------------------------------------------------------------------------------- /test-out/epfl/test7-lambdalift1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Double, scala.Function1[Double, Double]])) { 5 | def apply(x0:Unit): scala.Function1[Double, scala.Function1[Double, Double]] = { 6 | val x4 = 4.0 * 3.0 7 | val x7 = new Anonfun_x7(x4) 8 | val x8 = new Anonfun_x8(x7) 9 | x8 10 | } 11 | } 12 | /***************************************** 13 | End of Generated Code 14 | *******************************************/ 15 | class Anonfun_x8(x7) { 16 | def apply(x1) = { 17 | x7 18 | } 19 | } 20 | 21 | class Anonfun_x7(x4) { 22 | def apply(x2) = { 23 | val x3 = println("yo") 24 | val x5 = x2 + x4 25 | x5 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /test-out/epfl/test2-fft2.check: -------------------------------------------------------------------------------- 1 | TP(Sym(8),Plus(Sym(0),Sym(4))) 2 | TP(Sym(9),Plus(Sym(1),Sym(5))) 3 | TP(Sym(10),Minus(Sym(0),Sym(4))) 4 | TP(Sym(11),Minus(Sym(1),Sym(5))) 5 | TP(Sym(12),Plus(Sym(2),Sym(6))) 6 | TP(Sym(13),Plus(Sym(3),Sym(7))) 7 | TP(Sym(14),Minus(Sym(2),Sym(6))) 8 | TP(Sym(15),Minus(Sym(3),Sym(7))) 9 | TP(Sym(16),Plus(Sym(8),Sym(12))) 10 | TP(Sym(17),Plus(Sym(9),Sym(13))) 11 | TP(Sym(18),Minus(Sym(8),Sym(12))) 12 | TP(Sym(19),Minus(Sym(9),Sym(13))) 13 | TP(Sym(20),Minus(Const(0.0),Sym(15))) 14 | TP(Sym(21),Minus(Const(0.0),Sym(14))) 15 | TP(Sym(22),Plus(Sym(10),Sym(15))) 16 | TP(Sym(23),Minus(Sym(11),Sym(14))) 17 | TP(Sym(24),Minus(Sym(10),Sym(15))) 18 | TP(Sym(25),Plus(Sym(11),Sym(14))) 19 | List(Complex(Sym(16),Sym(17)), Complex(Sym(22),Sym(23)), Complex(Sym(18),Sym(19)), Complex(Sym(24),Sym(25))) 20 | -------------------------------------------------------------------------------- /test-src/epfl/test10-transform/TestWIP.scalax: -------------------------------------------------------------------------------- 1 | // add modular abstract interpretations (example: int ranges) 2 | 3 | def createDefinition(sym, def) = { 4 | val (sym1, def1) = rewriteUntilConverged(sym, def) 5 | globalDefs ::= (sym1,def1) 6 | } 7 | 8 | def rewriteUntilConverged = ... 9 | 10 | 11 | trait AbsIntDomain { 12 | val IR 13 | type Fact[T] 14 | val table: Map[Sym[_], Fact[_]] 15 | def unapply() 16 | def update(sym,def): Fact 17 | } 18 | 19 | 20 | trait MyAbstractInterpretation { self => 21 | 22 | object MyAbsIntDomain extends AbsIntDomain { 23 | val IR = self 24 | 25 | def update(sym,def) = evalAbs(sym,def) 26 | } 27 | 28 | 29 | def evalAbs(sym,def) = def match { 30 | case Foo(MyAbsIntDomain(x),MyAbsIntDomain(y)) => foo(x,y) 31 | } 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion2.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Boolean, scala.Function1[Double, Double]])) { 5 | def apply(x0:Unit): scala.Function1[Boolean, scala.Function1[Double, Double]] = { 6 | val x3 = {x1: (Double) => 7 | val x2 = 2.0 * x1 8 | x2: Double 9 | } 10 | val x8 = {x6: (Double) => 11 | val x7 = x6 + 1.0 12 | x7: Double 13 | } 14 | val x11 = {x4: (Boolean) => 15 | val x5 = println("yo") 16 | val x9 = if (x4) { 17 | x3 18 | } else { 19 | x8 20 | } 21 | x9: scala.Function1[Double, Double] 22 | } 23 | x11 24 | } 25 | } 26 | /***************************************** 27 | End of Generated Code 28 | *******************************************/ 29 | -------------------------------------------------------------------------------- /test-out/epfl/test10-misc1.check: -------------------------------------------------------------------------------- 1 | -- full graph 2 | TP(Sym(1),VectorZeros(Const(100))) 3 | TP(Sym(2),VectorPlus(Sym(1),Sym(1))) 4 | TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 5 | TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 6 | TP(Sym(5),Reify(Sym(4),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))) 7 | -- before transformation 8 | val x1 = VectorZeros(Const(100)) 9 | val x2 = VectorPlus(Sym(1),Sym(1)) 10 | val x3 = VectorPlus(Sym(1),Sym(2)) 11 | val x4 = println(x3) 12 | replacing TP(Sym(2),VectorPlus(Sym(1),Sym(1))) 13 | replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 14 | -- after transformation 15 | val x1 = VectorZeros(Const(100)) 16 | val x2 = VectorPlus(Sym(1),Sym(1)) 17 | val x3 = VectorPlus(Sym(2),Sym(1)) 18 | val x4 = println(x3) 19 | -- done 20 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion7.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Double, scala.Function1[Double, Double]])) { 5 | def apply(x0:Unit): scala.Function1[Double, scala.Function1[Double, Double]] = { 6 | val x8 = {x7: (Double) => 7 | x7: Double 8 | } 9 | val x10 = {x1: (Double) => 10 | val x2 = x1 < 100.0 11 | val x9 = if (x2) { 12 | val x3 = x1 + 9.0 13 | val x6 = {x4: (Double) => 14 | val x5 = x3 + x4 15 | x5: Double 16 | } 17 | x6 18 | } else { 19 | x8 20 | } 21 | x9: scala.Function1[Double, Double] 22 | } 23 | x10 24 | } 25 | } 26 | /***************************************** 27 | End of Generated Code 28 | *******************************************/ 29 | // was a Delite issue (Scratchpad in optiml-beta). 30 | -------------------------------------------------------------------------------- /test-out/epfl/test3-match2-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(2)" [ 3 | label="Sym(2) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" 4 | shape=box 5 | color=red 6 | ] 7 | "Sym(0)" -> "Sym(2)" 8 | "Sym(3)" [ 9 | label="Sym(3) \n Test(Sym(2),7)" 10 | shape=box 11 | color=red 12 | ] 13 | "Sym(2)" -> "Sym(3)" 14 | "Sym(4)" [ 15 | label="Sym(4) \n Reify(Const(yes),List(Sym(2), Sym(3)))" 16 | shape=box 17 | ] 18 | "Sym(2)" -> "Sym(4)" [color=red] 19 | "Sym(3)" -> "Sym(4)" [color=red] 20 | "Sym(6)" [ 21 | label="Sym(6) \n Reify(Const(maybe),List(Sym(2)))" 22 | shape=box 23 | ] 24 | "Sym(2)" -> "Sym(6)" [color=red] 25 | "Sym(8)" [ 26 | label="Sym(8) \n OrElse(List(Sym(4), Sym(6), Pure(Const(no))))" 27 | shape=box 28 | ] 29 | "Sym(4)" -> "Sym(8)" 30 | "Sym(6)" -> "Sym(8)" 31 | "Sym(9)" [ 32 | label="Sym(9) \n Result(Pure(Sym(8)))" 33 | shape=box 34 | ] 35 | "Sym(8)" -> "Sym(9)" 36 | } 37 | -------------------------------------------------------------------------------- /src/internal/Config.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | trait Config { 5 | val verbosity = System.getProperty("lms.verbosity","0").toInt 6 | val sourceinfo = System.getProperty("lms.sourceinfo","0").toInt 7 | val addControlDeps = System.getProperty("lms.controldeps","true").toBoolean 8 | 9 | val scalaExplicitTypes = System.getProperty("lms.scala.explicitTypes","false").toBoolean 10 | 11 | // memory management type for C++ target (refcnt or gc) 12 | val cppMemMgr = System.getProperty("lms.cpp.memmgr","malloc") 13 | 14 | // explicit return type of lambda functions (allows recursive functions but is less generic) 15 | val cppExplicitFunRet = System.getProperty("lms.cpp.explicitFunRet","true") 16 | 17 | // auto return value of if-else expressions (allows type deduction on if-then-else expressions) 18 | val cppIfElseAutoRet = System.getProperty("lms.cpp.ifElseAutoRet","false") 19 | } 20 | -------------------------------------------------------------------------------- /test-out/epfl/test14-cgen2.check: -------------------------------------------------------------------------------- 1 | /* FILE: main.c */ 2 | int32_t main(int32_t); 3 | /***************************************** 4 | Emitting C Generated Code 5 | *******************************************/ 6 | #include 7 | #include 8 | #include 9 | #include 10 | int32_t main(int32_t x0) { 11 | function x1 = [&](int32_t x2,int32_t x3) { 12 | int32_t x4 = x2; 13 | bool x6 = x4 == 0; 14 | int32_t x12; 15 | if (x6) { 16 | x12 = 1; 17 | } else { 18 | int32_t x5 = x3; 19 | int32_t x7 = x4 - 1; 20 | int32_t x9 = x1(x7,x5); 21 | int32_t x10 = x4 * x9; 22 | x12 = x10; 23 | } 24 | return x12; 25 | }; 26 | int32_t x15 = x1(4,0); 27 | printf(string("Hello, world! %d\n").c_str(),x15); 28 | return 0; 29 | } 30 | /***************************************** 31 | End of C Generated Code 32 | *******************************************/ 33 | -------------------------------------------------------------------------------- /test-out/epfl/test5-funretfun.check: -------------------------------------------------------------------------------- 1 | -- begin 2 | /***************************************** 3 | Emitting Generated Code 4 | *******************************************/ 5 | class Test extends ((Double)=>(scala.Function1[Int, Any])) { 6 | def apply(x0:Double): scala.Function1[Int, Any] = { 7 | val x5 = {x2: (Any) => 8 | val x3 = println("foo") 9 | x2: Any 10 | } 11 | val x9 = {x1: (Int) => 12 | val x6 = x5(x0) 13 | val x7 = x5(x6) 14 | x7: Any 15 | } 16 | x9 17 | } 18 | } 19 | /***************************************** 20 | End of Generated Code 21 | *******************************************/ 22 | function main(x0) { 23 | var x5 = function(x2) { 24 | var x3 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("foo")) 25 | return x2 26 | } 27 | var x9 = function(x1) { 28 | var x6 = x5(x0) 29 | var x7 = x5(x6) 30 | return x7 31 | } 32 | return x9 33 | } 34 | -- end 35 | -------------------------------------------------------------------------------- /test-out/epfl/test14-dataop1.check: -------------------------------------------------------------------------------- 1 | /* FILE: main.c */ 2 | int32_t main(int32_t); 3 | /***************************************** 4 | Emitting C Generated Code 5 | *******************************************/ 6 | #include 7 | #include 8 | #include 9 | #include 10 | int32_t main(int32_t x0) { 11 | int32_t x5 = 0; 12 | int* *x1 = mmap('table_field1.dat') // XX TODO ; 13 | int32_t x4 = x1->length; 14 | int* *x2 = mmap('table_field2.dat') // XX TODO ; 15 | for (;;) { 16 | int32_t x6 = x5; 17 | bool x7 = x6 < x4; 18 | if (x7) { 19 | x5 += 1; 20 | } else { 21 | } 22 | if (!x7) break; 23 | int32_t x12 = x5; 24 | int32_t x14 = x2[x12]; 25 | int32_t x13 = x1[x12]; 26 | int32_t x16 = 2 * x13; 27 | printf(string("foo: %d, bar: %d\n").c_str(),x14,x16); 28 | } 29 | return 0; 30 | } 31 | /***************************************** 32 | End of C Generated Code 33 | *******************************************/ 34 | -------------------------------------------------------------------------------- /test-src/epfl/test1-arith/Trig.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test1 4 | 5 | import common._ 6 | 7 | trait Trig extends Base { 8 | 9 | //todo removed 10 | //implicit def unit(x: Double): Rep[Double] 11 | 12 | def sin(x: Rep[Double]): Rep[Double] 13 | def cos(x: Rep[Double]): Rep[Double] 14 | 15 | } 16 | 17 | trait TrigExp extends Trig with BaseExp { 18 | implicit def doubleTyp: Typ[Double] 19 | 20 | case class Sin(x: Exp[Double]) extends Def[Double] 21 | case class Cos(x: Exp[Double]) extends Def[Double] 22 | 23 | def sin(x: Exp[Double]) = Sin(x) 24 | def cos(x: Exp[Double]) = Cos(x) 25 | } 26 | 27 | trait TrigExpOpt extends TrigExp { 28 | 29 | override def sin(x: Exp[Double]) = x match { 30 | case Const(x) => unit(math.sin(x)) 31 | case _ => super.sin(x) 32 | } 33 | 34 | override def cos(x: Exp[Double]) = x match { 35 | case Const(x) => unit(math.cos(x)) 36 | case _ => super.cos(x) 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /test-out/epfl/test10-transformrec2.check: -------------------------------------------------------------------------------- 1 | -- before transformation 2 | var x1 = null.asInstanceOf[scala.Function1[Double, Double]] 3 | x1 = {x2: (Double) => 4 | val x3 = x2 == 0 5 | val x7 = if (x3) { 6 | 1.0 7 | } else { 8 | val x4 = x2 - 1.0 9 | val x5 = x1(x4) 10 | val x6 = x2 * x5 11 | x6 12 | } 13 | x7 14 | } 15 | val x8 = x1(x0) 16 | -- after null transformation 17 | var x9 = null.asInstanceOf[scala.Function1[Double, Double]] 18 | x9 = {x2: (Double) => 19 | val x3 = x2 == 0 20 | val x12 = if (x3) { 21 | 1.0 22 | } else { 23 | val x4 = x2 - 1.0 24 | val x10 = x9(x4) 25 | val x11 = x2 * x10 26 | x11 27 | } 28 | x12 29 | } 30 | val x14 = x9(x0) 31 | -- after transformation 32 | var x15 = null.asInstanceOf[scala.Function1[Double, Double]] 33 | x15 = /*2*/{x2: (Double) => 34 | val x3 = x2 == 0 35 | val x18 = if (x3) { 36 | 1.0 37 | } else { 38 | val x4 = x2 - 1.0 39 | val x16 = x15(x4) 40 | val x17 = x2 * x16 41 | x17 42 | } 43 | x18 44 | } 45 | val x20 = x15(x0) 46 | -- done 47 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation1b.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(11)=Reflect(ArrayIndex(Sym(9),Const(50)),Summary(false,false,false,false,false,false,List(Sym(9)),List(Sym(9)),List(),List()),List(Sym(9), Sym(10))) 2 | depends on Sym(9) 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | class Test extends ((Int)=>(Unit)) { 7 | def apply(x0:Int): Unit = { 8 | val x2 = LoopArray(100) { x1 => 9 | 0 10 | } 11 | val x3 = x2.clone // mutable 12 | val x5 = LoopArray(100) { x4 => 13 | 0 14 | } 15 | val x6 = x5.clone // mutable 16 | val x7 = x0 > 7 17 | val x8 = if (x7) { 18 | x3 19 | } else { 20 | x6 21 | } 22 | val x9 = x8.clone // mutable 23 | val x10 = x9.update(40, 40) 24 | val x11 = x9.apply(50) 25 | val x12 = println(x11) 26 | x12 27 | } 28 | } 29 | /***************************************** 30 | End of Generated Code 31 | *******************************************/ 32 | -------------------------------------------------------------------------------- /test-out/epfl/test12-array-seq-creation.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class IntArrayCreation extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = Array[Int](1,2,3) 7 | val x2 = x1(0) 8 | val x3 = println(x2) 9 | x3 10 | } 11 | } 12 | /***************************************** 13 | End of Generated Code 14 | *******************************************/ 15 | /***************************************** 16 | Emitting Generated Code 17 | *******************************************/ 18 | class CharArrayCreation extends ((Int)=>(Unit)) { 19 | def apply(x5:Int): Unit = { 20 | val x6 = Array[Char]('a','b','c') 21 | val x7 = x6(0) 22 | val x8 = println(x7) 23 | x8 24 | } 25 | } 26 | /***************************************** 27 | End of Generated Code 28 | *******************************************/ 29 | -------------------------------------------------------------------------------- /test-out/epfl/test14-queries1.check: -------------------------------------------------------------------------------- 1 | db 2 | {people:List({name:Alex,age:60}, {name:Bert,age:55}, {name:Cora,age:33}, {name:Drew,age:31}, {name:Edna,age:21}, {name:Fred,age:60}),couples:List({her:Alex,him:Bert}, {her:Cora,him:Drew})} 3 | List({name:Alex,diff:5}, {name:Cora,diff:2}) 4 | List({name:Cora}, {name:Drew}) 5 | List({name:Cora}, {name:Drew}) 6 | List({name:Alex}, {name:Fred}) 7 | List({name:Cora}, {name:Drew}, {name:Edna}) 8 | List({name:Cora}, {name:Drew}) 9 | List({name:Cora}, {name:Drew}) 10 | List({dpt:Quality}, {dpt:Research}) 11 | List({dpt:Product,employees:List({emp:Alex,tasks:List(build)}, {emp:Bert,tasks:List(build)})}, {dpt:Quality,employees:List()}, {dpt:Research,employees:List({emp:Cora,tasks:List(abstract, build, design)}, {emp:Drew,tasks:List(abstract, design)}, {emp:Edna,tasks:List(abstract, call, design)})}, {dpt:Sales,employees:List({emp:Fred,tasks:List(call)})}) 12 | List({dpt:Quality}, {dpt:Research}) 13 | List(2, 4) 14 | List(0, 1, 2, 4) 15 | List(2) 16 | List(6) 17 | -------------------------------------------------------------------------------- /test-out/epfl/test11-stencil0.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class staged$0 extends ((Array[Double])=>(Array[Double])) { 5 | def apply(x0:Array[Double]): Array[Double] = { 6 | val x1 = new Array[Double](20) 7 | var x3 : Int = 0 8 | val x14 = while (x3 < 20) { 9 | val x4 = x3.doubleValue() 10 | val x5 = 2.0 * x4 11 | val x6 = x5 + 3.0 12 | val x7 = x3 + 1 13 | val x8 = x7.doubleValue() 14 | val x9 = 2.0 * x8 15 | val x10 = x9 + 3.0 16 | val x11 = x6 + x10 17 | val x12 = x1(x3) = x11 18 | 19 | x3 = x3 + 1 20 | } 21 | x1 22 | } 23 | } 24 | /***************************************** 25 | End of Generated Code 26 | *******************************************/ 27 | 28 | compilation: ok 29 | 8.0 30 | 12.0 31 | 16.0 32 | 20.0 33 | 24.0 34 | 28.0 35 | 32.0 36 | 36.0 37 | 40.0 38 | 44.0 39 | 48.0 40 | 52.0 41 | 56.0 42 | 60.0 43 | 64.0 44 | 68.0 45 | 72.0 46 | 76.0 47 | 80.0 48 | 84.0 49 | -------------------------------------------------------------------------------- /test-out/epfl/test4-ack1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Ack extends ((Int)=>(Int)) { 5 | def apply(x0:Int): Int = { 6 | var x4 = null.asInstanceOf[scala.Function1[Int, Int]] 7 | var x1 = null.asInstanceOf[scala.Function1[Int, Int]] 8 | val x7 = {x8: (Int) => 9 | val x9 = x8 + 1 10 | x9 11 | } 12 | val x10 = x7(1) 13 | x4 = {x5: (Int) => 14 | val x6 = x5 == 0 15 | val x14 = if (x6) { 16 | x10 17 | } else { 18 | val x11 = x5 - 1 19 | val x12 = x4(x11) 20 | val x13 = x7(x12) 21 | x13 22 | } 23 | x14 24 | } 25 | val x15 = x4(1) 26 | x1 = {x2: (Int) => 27 | val x3 = x2 == 0 28 | val x19 = if (x3) { 29 | x15 30 | } else { 31 | val x16 = x2 - 1 32 | val x17 = x1(x16) 33 | val x18 = x4(x17) 34 | x18 35 | } 36 | x19 37 | } 38 | val x20 = x1(x0) 39 | x20 40 | } 41 | } 42 | /***************************************** 43 | End of Generated Code 44 | *******************************************/ 45 | -------------------------------------------------------------------------------- /test-out/epfl/test11-stencil2a.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class staged$0 extends ((Array[Double])=>(Array[Double])) { 5 | def apply(x0:Array[Double]): Array[Double] = { 6 | val x1 = x0.length 7 | val x2 = new Array[Double](x1) 8 | val x3 = x1 - 1 9 | var x5 : Int = 1 10 | val x17 = while (x5 < x3) { 11 | val x6 = x0(x5) 12 | val x7 = x5 + 1 13 | val x8 = x0(x7) 14 | val x9 = x6 * x8 15 | val x10 = x6 - x9 16 | val x11 = x5 - 1 17 | val x12 = x0(x11) 18 | val x13 = x12 * x6 19 | val x14 = x10 + x13 20 | val x15 = x2(x5) = x14 21 | 22 | x5 = x5 + 1 23 | } 24 | x2 25 | } 26 | } 27 | /***************************************** 28 | End of Generated Code 29 | *******************************************/ 30 | 31 | compilation: ok 32 | 0.0 33 | 0.8800000000000001 34 | 0.96 35 | 1.0400000000000003 36 | 1.12 37 | 1.1999999999999993 38 | 1.2799999999999998 39 | 1.3600000000000003 40 | 1.4400000000000006 41 | 0.0 42 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation4c.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(5)=Reflect(ArrayClone(Sym(3)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List()) 2 | depends on Sym(3) 3 | promoting to effect: Sym(9)=Reflect(ArrayIndex(Sym(8),Const(5)),Summary(false,false,false,false,false,false,List(Sym(8)),List(Sym(8)),List(),List()),List(Sym(8))) 4 | depends on Sym(8) 5 | /***************************************** 6 | Emitting Generated Code 7 | *******************************************/ 8 | class Test extends ((Int)=>(Unit)) { 9 | def apply(x0:Int): Unit = { 10 | val x2 = LoopArray(100) { x1 => 11 | 0 12 | } 13 | val x3 = x2.clone // mutable 14 | val x7 = LoopArray(10) { x4 => 15 | val x5 = x3.clone 16 | x5 17 | } 18 | val x8 = x7.clone // mutable 19 | val x9 = x8.apply(5) 20 | val x10 = x9.apply(50) 21 | val x11 = println(x10) 22 | x11 23 | } 24 | } 25 | /***************************************** 26 | End of Generated Code 27 | *******************************************/ 28 | -------------------------------------------------------------------------------- /test-out/epfl/test3-match1-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(2)" [ 3 | label="Sym(2) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" 4 | shape=box 5 | color=red 6 | ] 7 | "Sym(0)" -> "Sym(2)" 8 | "Sym(3)" [ 9 | label="Sym(3) \n Test(Sym(2),7)" 10 | shape=box 11 | color=red 12 | ] 13 | "Sym(2)" -> "Sym(3)" 14 | "Sym(4)" [ 15 | label="Sym(4) \n Reify(Const(yes),List(Sym(2), Sym(3)))" 16 | shape=box 17 | ] 18 | "Sym(2)" -> "Sym(4)" [color=red] 19 | "Sym(3)" -> "Sym(4)" [color=red] 20 | "Sym(6)" [ 21 | label="Sym(6) \n Deconstruct(class scala.lms.epfl.test3.MatchProg$Success,Sym(0))" 22 | shape=box 23 | color=red 24 | ] 25 | "Sym(0)" -> "Sym(6)" 26 | "Sym(7)" [ 27 | label="Sym(7) \n Reify(Const(maybe),List(Sym(6)))" 28 | shape=box 29 | ] 30 | "Sym(6)" -> "Sym(7)" [color=red] 31 | "Sym(9)" [ 32 | label="Sym(9) \n OrElse(List(Sym(4), Sym(7), Pure(Const(no))))" 33 | shape=box 34 | ] 35 | "Sym(4)" -> "Sym(9)" 36 | "Sym(7)" -> "Sym(9)" 37 | "Sym(10)" [ 38 | label="Sym(10) \n Result(Pure(Sym(9)))" 39 | shape=box 40 | ] 41 | "Sym(9)" -> "Sym(10)" 42 | } 43 | -------------------------------------------------------------------------------- /test-out/epfl/test5-conditional.html.check: -------------------------------------------------------------------------------- 1 | Scala2JS 22 | 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Use Docker-based container (instead of OpenVZ) 2 | sudo: false 3 | 4 | language: scala 5 | 6 | scala: 7 | - 2.11.2 8 | 9 | cache: 10 | directories: 11 | - $HOME/.ivy2/cache 12 | - $HOME/.sbt/boot 13 | 14 | # Q: should we use sbt ++$TRAVIS_SCALA_VERSION test? 15 | 16 | script: 17 | - sbt clean coverage test && sbt coverageAggregate 18 | # Tricks to avoid unnecessary cache updates 19 | - find $HOME/.sbt -name "*.lock" | xargs rm 20 | - find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm 21 | 22 | after_success: 23 | - sbt coveralls 24 | - "[[ $TRAVIS_PULL_REQUEST == 'false' && $TRAVIS_BRANCH == 'develop'* ]] && sbt publish" 25 | 26 | env: 27 | global: 28 | - secure: X+7udElsP9vnDvz8zM+0rESZQE5rCin4Iw7S0ZqaIgZth1RM+vdmFpOtV7j/YeBtJnpL1s7z9xWpnAf1PzCESp8JrApvHmxyzXC5yRYki0tf8bb9jWJmkNP8ZRAiwe1uSLwhtGGST6kMjuIBjbTlCoizhqu7/abvwZNUYn37Afs= 29 | - secure: huTySCqcSt7gBI3I8GTWZDW9wh9aMxqQWl4AwV+jewh0s4jIn++oHUJ5HmKMBOXkkcrA3fxaaI0iwAodBJ/A5nH0Ge1tx0mW1JSYikDbkMNKNvooy0R6qZziACjrJ+7ooxnP/g2g3MrSskGkkZVX7vsH6cgk5Ai4z6FBhXv0DQA= 30 | -------------------------------------------------------------------------------- /test-out/epfl/test9-amb1b.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = println("found:") 7 | val x2 = println(1) 8 | val x3 = println(1) 9 | val x4 = println("found:") 10 | val x5 = println(2) 11 | val x6 = println(2) 12 | val x7 = x0 == 1 13 | val x12 = if (x7) { 14 | val x8 = println("found:") 15 | val x9 = println(x0) 16 | val x10 = println(1) 17 | x10 18 | } else { 19 | () 20 | } 21 | val x13 = x0 == 2 22 | val x18 = if (x13) { 23 | val x14 = println("found:") 24 | val x15 = println(x0) 25 | val x16 = println(2) 26 | x16 27 | } else { 28 | () 29 | } 30 | val x19 = x0 == 3 31 | val x24 = if (x19) { 32 | val x20 = println("found:") 33 | val x21 = println(x0) 34 | val x22 = println(3) 35 | x22 36 | } else { 37 | () 38 | } 39 | () 40 | } 41 | } 42 | /***************************************** 43 | End of Generated Code 44 | *******************************************/ 45 | -------------------------------------------------------------------------------- /src/internal/FatScheduling.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | import util.GraphUtil 5 | import scala.collection.mutable.HashMap 6 | 7 | trait FatScheduling extends Scheduling { 8 | val IR: FatExpressions 9 | import IR._ 10 | 11 | def fatten(e: Stm): Stm = e 12 | 13 | def fattenAll(e: List[Stm]): List[Stm] = e.map(fatten) 14 | 15 | 16 | // ------------------- these are needed by loop fusion. they should live elsewhere. 17 | def unapplySimpleIndex(e: Def[Any]): Option[(Exp[Any], Exp[Int])] = None 18 | def unapplySimpleDomain(e: Def[Int]): Option[Exp[Any]] = None 19 | def unapplySimpleCollect(e: Def[Any]): Option[Exp[Any]] = None 20 | def unapplySimpleCollectIf(e: Def[Any]): Option[(Exp[Any],List[Exp[Boolean]])] = unapplySimpleCollect(e).map((_,Nil)) 21 | 22 | // FIXME: should be Def[A] => Def[A], not Def[Any] 23 | def applyAddCondition(e: Def[Any], c: List[Exp[Boolean]]): Def[Any] = sys.error("not implemented") 24 | 25 | def shouldApplyFusion(currentScope: List[Stm])(result: List[Exp[Any]]): Boolean = true 26 | 27 | // ------------------- 28 | 29 | 30 | } -------------------------------------------------------------------------------- /test-out/epfl/test2-fft3.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class FFT4 extends ((Array[Double])=>(Array[Double])) { 5 | def apply(x0:Array[Double]): Array[Double] = { 6 | val x1 = x0.apply(0) 7 | val x5 = x0.apply(4) 8 | val x9 = x1+x5 9 | val x3 = x0.apply(2) 10 | val x7 = x0.apply(6) 11 | val x13 = x3+x7 12 | val x17 = x9+x13 13 | val x2 = x0.apply(1) 14 | val x6 = x0.apply(5) 15 | val x10 = x2+x6 16 | val x4 = x0.apply(3) 17 | val x8 = x0.apply(7) 18 | val x14 = x4+x8 19 | val x18 = x10+x14 20 | val x19 = x9-x13 21 | val x20 = x10-x14 22 | val x11 = x1-x5 23 | val x16 = x4-x8 24 | val x23 = x11+x16 25 | val x12 = x2-x6 26 | val x15 = x3-x7 27 | val x24 = x12-x15 28 | val x25 = x11-x16 29 | val x26 = x12+x15 30 | val x27 = Array[Double](x17,x18,x23,x24,x19,x20,x25,x26) 31 | x27 32 | } 33 | } 34 | /***************************************** 35 | End of Generated Code 36 | *******************************************/ 37 | compilation: ok 38 | 6.0,0.0,-1.0,1.0,0.0,0.0,-1.0,-1.0 39 | -------------------------------------------------------------------------------- /test-out/epfl/test7-fusion1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(Unit)) { 5 | def apply(x0:Unit): Unit = { 6 | val x2 = LoopArray(100) { x1 => 7 | 1.0 8 | } 9 | val x5 = LoopArray(100) { x3 => 10 | val x4 = 2.0 * x3 11 | x4 12 | } 13 | val x10 = LoopArray(100) { x6 => 14 | val x7 = x2.apply(x6) 15 | val x8 = x5.apply(x6) 16 | val x9 = x7 + x8 17 | x9 18 | } 19 | val x13 = LoopReduce(100) { x11 => 20 | val x12 = x10.apply(x11) 21 | x12 22 | } 23 | val x14 = x13 / 100 24 | val x26 = println(x14) 25 | val x18 = LoopReduce(100) { x15 => 26 | val x16 = x10.apply(x15) 27 | val x17 = x16 * x16 28 | x17 29 | } 30 | val x19 = x18 / 100 31 | val x22 = LoopReduce(100) { x20 => 32 | val x21 = x10.apply(x20) 33 | x21 34 | } 35 | val x23 = x22 / 100 36 | val x24 = x23 * x23 37 | val x25 = x19 - x24 38 | val x27 = println(x25) 39 | x27 40 | } 41 | } 42 | /***************************************** 43 | End of Generated Code 44 | *******************************************/ 45 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation3b.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(7)=Reflect(ArrayLen(Sym(6)),Summary(false,false,false,false,false,false,List(Sym(6)),List(Sym(6)),List(),List()),List(Sym(6))) 2 | depends on Sym(6) 3 | promoting to effect: Sym(13)=Reflect(ArrayClone(Sym(6)),Summary(false,false,false,false,false,false,List(Sym(6)),List(Sym(6)),List(),List()),List(Sym(12))) 4 | depends on Sym(6) 5 | /***************************************** 6 | Emitting Generated Code 7 | *******************************************/ 8 | class Test extends ((Int)=>(Unit)) { 9 | def apply(x0:Int): Unit = { 10 | val x2 = LoopArray(100) { x1 => 11 | 0 12 | } 13 | var x3: Array[Int] = x2 14 | val x5 = LoopArray(100) { x4 => 15 | 0 16 | } 17 | val x6 = x5.clone // mutable 18 | val x7 = x6.length 19 | var x9 : Int = 0 20 | val x16 = while (x9 < x7) { 21 | val x10 = x3 22 | val x12 = x6.update(x9, 8) 23 | val x13 = x6.clone 24 | x3 = x13 25 | 26 | x9 = x9 + 1 27 | } 28 | x16 29 | } 30 | } 31 | /***************************************** 32 | End of Generated Code 33 | *******************************************/ 34 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative5.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x34 = null.asInstanceOf[Unit] 7 | var x38 = null.asInstanceOf[Unit] 8 | var x2: Double = 0.0 9 | while ({ // List(Sym(34), Sym(38)) 10 | // dummy placeholder for previous iteration: List(Sym(21), Sym(20)) = Sym(4) / List(Sym(2), Sym(34)) 11 | val x22 = x2 12 | val x23 = x22 < 10.0 13 | x23 14 | }) { 15 | // dummy placeholder for previous iteration: List(Sym(25), Sym(26)) = Sym(3) / List(Sym(2), Sym(34)) 16 | val x29 = x2 += 1.0 17 | val x27 = println("test") 18 | val x28 = println(7.0) 19 | } 20 | val x39 = println(7.0) 21 | x39 22 | } 23 | } 24 | /***************************************** 25 | End of Generated Code 26 | *******************************************/ 27 | compilation: ok 28 | test 29 | 7.0 30 | test 31 | 7.0 32 | test 33 | 7.0 34 | test 35 | 7.0 36 | test 37 | 7.0 38 | test 39 | 7.0 40 | test 41 | 7.0 42 | test 43 | 7.0 44 | test 45 | 7.0 46 | test 47 | 7.0 48 | 7.0 49 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation3.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(7)=Reflect(ArrayLen(Sym(6)),Summary(false,false,false,false,false,false,List(Sym(6)),List(Sym(6)),List(),List()),List(Sym(6))) 2 | depends on Sym(6) 3 | error: illegal sharing of mutable objects Sym(6) 4 | at Sym(13)=Reflect(Assign(Variable(Sym(3)),Sym(6)),Summary(false,false,false,false,false,false,List(Sym(3), Sym(6)),List(Sym(3), Sym(6)),List(Sym(3)),List(Sym(3))),List(Sym(10), Sym(12))) 5 | /***************************************** 6 | Emitting Generated Code 7 | *******************************************/ 8 | class Test extends ((Int)=>(Unit)) { 9 | def apply(x0:Int): Unit = { 10 | val x2 = LoopArray(100) { x1 => 11 | 0 12 | } 13 | var x3: Array[Int] = x2 14 | val x5 = LoopArray(100) { x4 => 15 | 0 16 | } 17 | val x6 = x5.clone // mutable 18 | val x7 = x6.length 19 | var x9 : Int = 0 20 | val x15 = while (x9 < x7) { 21 | val x10 = x3 22 | val x12 = x6.update(x9, 8) 23 | x3 = x6 24 | 25 | x9 = x9 + 1 26 | } 27 | x15 28 | } 29 | } 30 | /***************************************** 31 | End of Generated Code 32 | *******************************************/ 33 | -------------------------------------------------------------------------------- /test-out/epfl/test7-codemotion3.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Unit)=>(scala.Function1[Boolean, scala.Function1[Double, Double]])) { 5 | def apply(x0:Unit): scala.Function1[Boolean, scala.Function1[Double, Double]] = { 6 | val x7 = if (true) { 7 | val x3 = {x1: (Double) => 8 | val x2 = 2.0 * x1 9 | x2: Double 10 | } 11 | x3 12 | } else { 13 | val x6 = {x4: (Double) => 14 | val x5 = 4.0 * x4 15 | x5: Double 16 | } 17 | x6 18 | } 19 | val x19 = if (false) { 20 | val x15 = {x13: (Double) => 21 | val x14 = x13 + 1.0 22 | x14: Double 23 | } 24 | x15 25 | } else { 26 | val x18 = {x16: (Double) => 27 | val x17 = x16 + 2.0 28 | x17: Double 29 | } 30 | x18 31 | } 32 | val x23 = {x8: (Boolean) => 33 | val x9 = println("yo") 34 | val x21 = if (x8) { 35 | val x10 = println("then") 36 | x7 37 | } else { 38 | val x12 = println("else") 39 | x19 40 | } 41 | x21: scala.Function1[Double, Double] 42 | } 43 | x23 44 | } 45 | } 46 | /***************************************** 47 | End of Generated Code 48 | *******************************************/ 49 | -------------------------------------------------------------------------------- /src/util/ClosureCompare.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package util 3 | 4 | import java.io._ 5 | 6 | trait ClosureCompare extends Externalizable { 7 | 8 | // the whole thing must be serializable, since embedded closures 9 | // might refer to the context. 10 | 11 | def writeExternal(out: ObjectOutput) { 12 | // println("in write object") 13 | } 14 | def readExternal(in: ObjectInput) { 15 | throw new NotSerializableException("this is just a mock-up!") 16 | } 17 | 18 | def canonicalize(f: Function[_,_]) = { 19 | val s = new java.io.ByteArrayOutputStream() 20 | val o = new java.io.ObjectOutputStream(s) 21 | o.writeObject(f) 22 | s.toString("ASCII") 23 | } 24 | 25 | def sameFunction(f: Function[_,_], g: Function[_,_]): Boolean = { 26 | 27 | def ser(f: Function[_,_]) = f.isInstanceOf[java.io.Serializable] 28 | 29 | if (f.getClass != g.getClass) 30 | return false 31 | 32 | if (ser(f) && ser(g)) { 33 | canonicalize(f) == canonicalize(g) 34 | } else { 35 | println("serizalizable(f): " + f.getClass + ": " + ser(f)) 36 | println("serizalizable(g): " + g.getClass + ": " + ser(g)) 37 | false 38 | } 39 | } 40 | 41 | 42 | } -------------------------------------------------------------------------------- /test-src/epfl/test12-collections/TestArrayOps.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test12 4 | 5 | import common._ 6 | import java.io.PrintWriter 7 | 8 | class TestArrayOps extends FileDiffSuite { 9 | 10 | val prefix = home + "test-out/epfl/test12-" 11 | 12 | def testIntArrayCreation() { 13 | withOutFile(prefix+"array-seq-creation") { 14 | val prog = new LiftArrays with ArrayOps with MiscOps with ArrayOpsExp with SeqOpsExp with StringOpsExp with MiscOpsExp { 15 | def f(i : Rep[Int]): Rep[Unit] = { 16 | val a = Array(unit(1), unit(2), unit(3)) 17 | println(a(unit(0))) 18 | } 19 | 20 | def g(i : Rep[Int]): Rep[Unit] = { 21 | val a = Array(unit('a'), unit('b'), unit('c')) 22 | println(a(unit(0))) 23 | } 24 | } 25 | 26 | val codegen = new ScalaGenArrayOps with ScalaGenMiscOps { val IR: prog.type = prog } 27 | import prog.{intTyp,unitTyp} 28 | codegen.emitSource(prog.f, "IntArrayCreation", new PrintWriter(System.out)) 29 | codegen.emitSource(prog.g, "CharArrayCreation", new PrintWriter(System.out)) 30 | } 31 | assertFileEqualsCheck(prefix+"array-seq-creation") 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /test-out/epfl/test6-vectors.check: -------------------------------------------------------------------------------- 1 | -- begin 2 | /***************************************** 3 | Emitting Generated Code 4 | *******************************************/ 5 | class Test extends ((Unit)=>(Array[Double])) { 6 | def apply(x0:Unit): Array[Double] = { 7 | val x1 = scala.lms.epfl.test6.VectorOps.random(7) 8 | val x3 = scala.lms.epfl.test6.VectorOps.random(7) 9 | val x4 = (x1,x3) 10 | val x5 = scala.lms.epfl.test6.VectorOps.plus(x4) 11 | x5 12 | } 13 | } 14 | /***************************************** 15 | End of Generated Code 16 | *******************************************/ 17 | compilation: ok 18 | 0.0,0.0,0.0,0.0,0.0,0.0,0.0 19 | /***************************************** 20 | Emitting Generated Code 21 | *******************************************/ 22 | class Test extends ((Int)=>(java.lang.String)) { 23 | def apply(x0:Int): java.lang.String = { 24 | val x1 = "hi yo ".toString + x0.toString 25 | val x2 = x1.toString + " done".toString 26 | x2 27 | } 28 | } 29 | /***************************************** 30 | End of Generated Code 31 | *******************************************/ 32 | compilation: ok 33 | hi yo 0 done 34 | -- end 35 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac3-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(2)" [ 3 | label="Sym(2) \n Test(Sym(0),0.0)" 4 | shape=box 5 | color=red 6 | ] 7 | "Sym(0)" -> "Sym(2)" 8 | "Sym(3)" [ 9 | label="Sym(3) \n Reify(Const(1.0),List(Sym(2)))" 10 | shape=box 11 | ] 12 | "Sym(2)" -> "Sym(3)" [color=red] 13 | "Sym(5)" [ 14 | label="Sym(5) \n Minus(Sym(0),Const(1.0))" 15 | shape=box 16 | ] 17 | "Sym(0)" -> "Sym(5)" 18 | "Sym(6)" [ 19 | label="Sym(6) \n Test(Sym(5),0.0)" 20 | shape=box 21 | color=red 22 | ] 23 | "Sym(5)" -> "Sym(6)" 24 | "Sym(7)" [ 25 | label="Sym(7) \n Reify(Const(1.0),List(Sym(6)))" 26 | shape=box 27 | ] 28 | "Sym(6)" -> "Sym(7)" [color=red] 29 | "Sym(8)" [ 30 | label="Sym(8) \n Apply(Sym(-2),Sym(5))" 31 | shape=box 32 | color=blue 33 | style=filled 34 | ] 35 | "Sym(-2)" -> "Sym(8)" 36 | "Sym(5)" -> "Sym(8)" 37 | "Sym(9)" [ 38 | label="Sym(9) \n OrElse(List(Sym(7), Sym(8)))" 39 | shape=box 40 | ] 41 | "Sym(7)" -> "Sym(9)" 42 | "Sym(8)" -> "Sym(9)" 43 | "Sym(10)" [ 44 | label="Sym(10) \n Times(Sym(0),Sym(9))" 45 | shape=box 46 | ] 47 | "Sym(0)" -> "Sym(10)" 48 | "Sym(9)" -> "Sym(10)" 49 | "Sym(11)" [ 50 | label="Sym(11) \n OrElse(List(Sym(3), Pure(Sym(10))))" 51 | shape=box 52 | ] 53 | "Sym(3)" -> "Sym(11)" 54 | "Sym(10)" -> "Sym(11)" 55 | } 56 | -------------------------------------------------------------------------------- /test-out/epfl/test10-effects1.check: -------------------------------------------------------------------------------- 1 | killing: List(Sym(1))/List(Sym(1), Sym(2)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) 2 | **fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(3),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2)))), TP(Sym(5),Mutate(Sym(2),Sym(3))), TP(Sym(6),VectorApply(Sym(5),Const(0))), TP(Sym(7),Reflect(Print(Sym(6)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(8),Reify(Sym(7),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(7))))) 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | class Test extends ((Int)=>(Unit)) { 7 | def apply(x0:Int): Unit = { 8 | val x1 = VectorZeros(Const(100)) 9 | val x2 = VectorLiteral(List(Sym(1))) 10 | // begin multi 11 | // soft deps: x1,x2 12 | val x3 = VectorUpdate(Sym(1),Const(5),Const(7.0)) 13 | val x5 = x2 // mutated by x3 14 | // end multi 15 | val x6 = VectorApply(Sym(5),Const(0)) 16 | val x7 = println(x6) 17 | x7 18 | } 19 | } 20 | /***************************************** 21 | End of Generated Code 22 | *******************************************/ 23 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation5.check: -------------------------------------------------------------------------------- 1 | error: illegal sharing of mutable objects Sym(8) 2 | at Sym(10)=Reflect(ArrayUpdate(Sym(5),Const(5),Sym(8)),Summary(false,false,false,false,false,false,List(Sym(5), Sym(8)),List(Sym(5), Sym(8)),List(Sym(5)),List(Sym(5))),List(Sym(5), Sym(8), Sym(9))) 3 | promoting to effect: Sym(12)=Reflect(ArrayIndex(Sym(5),Const(5)),Summary(false,false,false,false,false,false,List(Sym(5)),List(Sym(5)),List(),List()),List(Sym(5), Sym(9), Sym(10))) 4 | depends on Sym(5) 5 | /***************************************** 6 | Emitting Generated Code 7 | *******************************************/ 8 | class Test extends ((Int)=>(Unit)) { 9 | def apply(x0:Int): Unit = { 10 | val x2 = LoopArray(100) { x1 => 11 | 0 12 | } 13 | val x4 = LoopArray(10) { x3 => 14 | x2 15 | } 16 | val x5 = x4.clone // mutable 17 | val x7 = LoopArray(20) { x6 => 18 | 0 19 | } 20 | val x8 = x7.clone // mutable 21 | val x9 = x5.update(4, x2) 22 | val x10 = x5.update(5, x8) 23 | val x11 = x8.update(50, 50) 24 | val x12 = x5.apply(5) 25 | val x13 = x12.apply(50) 26 | val x14 = println(x13) 27 | x14 28 | } 29 | } 30 | /***************************************** 31 | End of Generated Code 32 | *******************************************/ 33 | -------------------------------------------------------------------------------- /src/internal/FatCodegen.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | import util.GraphUtil 5 | import java.io.{File, PrintWriter} 6 | 7 | trait GenericFatCodegen extends GenericNestedCodegen with FatBlockTraversal { 8 | val IR: Expressions with Effects with FatExpressions 9 | import IR._ 10 | 11 | 12 | override def traverseStm(stm: Stm) = stm match { 13 | case TTP(lhs, mhs, rhs) => emitFatNode(lhs, rhs) 14 | case _ => super.traverseStm(stm) 15 | } 16 | 17 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { // TODO: get rid of. used by SimplifyTranform 18 | case Forward(x) => emitValDef(sym, quote(x)) 19 | case _ => super.emitNode(sym, rhs) 20 | } 21 | 22 | def emitFatNode(sym: List[Sym[Any]], rhs: FatDef): Unit = rhs match { 23 | case _ => sys.error("don't know how to generate code for: "+rhs) 24 | } 25 | 26 | // DELITE SPECIFIC METHOD -- used for kernel activation records 27 | def emitFatNodeKernelExtra(sym: List[Sym[Any]], rhs: FatDef): Unit = { } 28 | def emitNodeKernelExtra(sym: List[Sym[Any]], rhs: Def[Any]): Unit = { } 29 | 30 | def emitFatBlock(rhs: List[Block[Any]]): Unit = { 31 | emitBlock(Block(Combine(rhs.map(getBlockResultFull)))) // TODO: find another way 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation1.check: -------------------------------------------------------------------------------- 1 | error: write to non-mutable Sym(8) -> Some(TP(Sym(8),IfThenElse(Sym(7),Block(Sym(3)),Block(Sym(6))))) 2 | at Sym(9)=Reflect(ArrayUpdate(Sym(8),Const(40),Const(40)),Summary(false,false,false,false,false,false,List(Sym(3), Sym(6)),List(Sym(3), Sym(6)),List(Sym(8)),List(Sym(8))),List(Sym(3), Sym(6))) 3 | promoting to effect: Sym(10)=Reflect(ArrayIndex(Sym(8),Const(50)),Summary(false,false,false,false,false,false,List(Sym(3), Sym(6)),List(Sym(3), Sym(6)),List(),List()),List(Sym(3), Sym(6))) 4 | depends on Sym(3) 5 | depends on Sym(6) 6 | /***************************************** 7 | Emitting Generated Code 8 | *******************************************/ 9 | class Test extends ((Int)=>(Unit)) { 10 | def apply(x0:Int): Unit = { 11 | val x2 = LoopArray(100) { x1 => 12 | 0 13 | } 14 | val x3 = x2.clone // mutable 15 | val x5 = LoopArray(100) { x4 => 16 | 0 17 | } 18 | val x6 = x5.clone // mutable 19 | val x7 = x0 > 7 20 | val x8 = if (x7) { 21 | x3 22 | } else { 23 | x6 24 | } 25 | val x9 = x8.update(40, 40) 26 | val x10 = x8.apply(50) 27 | val x11 = println(x10) 28 | x11 29 | } 30 | } 31 | /***************************************** 32 | End of Generated Code 33 | *******************************************/ 34 | -------------------------------------------------------------------------------- /test-out/epfl/test11-hmm1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test(px20:Array[Int]) extends ((Array[Int])=>(Array[Int])) { 5 | def apply(x0:Array[Int]): Array[Int] = { 6 | val x1 = new Array[Int](5) 7 | val x2 = x1(0) 8 | val x3 = x0(0) 9 | val x4 = x2 + x3 10 | val x5 = x1(0) = x4 11 | val x6 = x0(3) 12 | val x7 = x4 + x6 13 | val x8 = x1(0) = x7 14 | val x9 = x1(1) 15 | val x10 = x0(2) 16 | val x11 = x9 + x10 17 | val x12 = x1(1) = x11 18 | val x13 = x1(2) 19 | val x14 = x0(1) 20 | val x15 = x13 + x14 21 | val x16 = x1(2) = x15 22 | val x20 = px20 // static data: Array(0,0,1,1,1) 23 | var x18 : Int = 0 24 | val x27 = while (x18 < 5) { 25 | val x19 = x1(3) 26 | val x21 = x20(x18) 27 | val x22 = x0(x18) 28 | val x23 = x21 * x22 29 | val x24 = x19 + x23 30 | val x25 = x1(3) = x24 31 | 32 | x18 = x18 + 1 33 | } 34 | val x28 = x1(4) 35 | val x29 = x28 + x10 36 | val x30 = x1(4) = x29 37 | val x31 = x0(4) 38 | val x32 = x29 + x31 39 | val x33 = x1(4) = x32 40 | x1 41 | } 42 | } 43 | /***************************************** 44 | End of Generated Code 45 | *******************************************/ 46 | compilation: ok 47 | 1 48 | 5 49 | 1 50 | 7 51 | 9 52 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative3.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x46 = null.asInstanceOf[Unit] 7 | var x50 = null.asInstanceOf[Unit] 8 | var x2: Double = 0.0 9 | while ({ // List(Sym(46), Sym(50)) 10 | // dummy placeholder for previous iteration: List(Sym(28), Sym(27)) = Sym(4) / List(Sym(2), Sym(46)) 11 | val x29 = x2 12 | val x30 = x29 < 10.0 13 | x30 14 | }) { 15 | // dummy placeholder for previous iteration: List(Sym(33), Sym(32)) = Sym(3) / List(Sym(2), Sym(46)) 16 | val x35 = x2 17 | val x34 = println(7) 18 | val x36 = println(x35) 19 | val x40 = println(2) 20 | val x38 = x35 + 1.0 21 | x2 = x38 22 | } 23 | val x51 = println(7) 24 | val x52 = x2 25 | val x53 = println(x52) 26 | x53 27 | } 28 | } 29 | /***************************************** 30 | End of Generated Code 31 | *******************************************/ 32 | compilation: ok 33 | 7 34 | 0.0 35 | 2 36 | 7 37 | 1.0 38 | 2 39 | 7 40 | 2.0 41 | 2 42 | 7 43 | 3.0 44 | 2 45 | 7 46 | 4.0 47 | 2 48 | 7 49 | 5.0 50 | 2 51 | 7 52 | 6.0 53 | 2 54 | 7 55 | 7.0 56 | 2 57 | 7 58 | 8.0 59 | 2 60 | 7 61 | 9.0 62 | 2 63 | 7 64 | 10.0 65 | -------------------------------------------------------------------------------- /test-out/epfl/test8-speculative3b.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | var x58 = null.asInstanceOf[Unit] 7 | var x66 = null.asInstanceOf[Unit] 8 | var x3: Double = 0.0 9 | while ({ // List(Sym(58), Sym(66)) 10 | // dummy placeholder for previous iteration: List(Sym(37), Sym(35)) = Sym(5) / List(Sym(3), Sym(58)) 11 | val x38 = x3 12 | val x39 = x38 < 10.0 13 | x39 14 | }) { 15 | // dummy placeholder for previous iteration: List(Sym(41), Sym(43)) = Sym(4) / List(Sym(3), Sym(58)) 16 | val x45 = x3 17 | val x48 = x45 + 1.0 18 | x3 = x48 19 | val x44 = println(7) 20 | val x46 = println(x45) 21 | val x50 = println(2) 22 | } 23 | val x67 = println(7) 24 | val x68 = x3 25 | val x69 = println(x68) 26 | x69 27 | } 28 | } 29 | /***************************************** 30 | End of Generated Code 31 | *******************************************/ 32 | compilation: ok 33 | 7 34 | 0.0 35 | 2 36 | 7 37 | 1.0 38 | 2 39 | 7 40 | 2.0 41 | 2 42 | 7 43 | 3.0 44 | 2 45 | 7 46 | 4.0 47 | 2 48 | 7 49 | 5.0 50 | 2 51 | 7 52 | 6.0 53 | 2 54 | 7 55 | 7.0 56 | 2 57 | 7 58 | 8.0 59 | 2 60 | 7 61 | 9.0 62 | 2 63 | 7 64 | 10.0 65 | -------------------------------------------------------------------------------- /test-src/epfl/test4-functions/FooBar.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test4 4 | 5 | // unused code -- just a sanity check to make sure it compiles 6 | 7 | trait FooA { 8 | type Rep[T] = Option[T] 9 | 10 | def decons[A](x: Rep[scala.::[A]]): Some[(Rep[A], Rep[List[A]])] 11 | 12 | object Foo { 13 | def unapply[A](x: Rep[scala.::[A]]): Some[(Rep[A], Rep[List[A]])] = decons[A](x) 14 | } 15 | 16 | def foo(xs: Rep[List[Int]]): Unit = xs match { 17 | case Foo(a,b) => foo(b) 18 | case _ => 19 | } 20 | } 21 | 22 | 23 | trait FooB { 24 | 25 | sealed abstract class Exp[+T] 26 | 27 | case class Sym[T]() extends Exp[T] 28 | case class Const[T]() extends Exp[T] 29 | 30 | def lookup[A](x: Sym[A]): Option[Const[A]] 31 | 32 | object Lookup { 33 | def unapply[U](x: Sym[U]): Option[Const[U]] = lookup(x) 34 | } 35 | 36 | object IsSym { 37 | def unapply[U](x: Exp[U]): Option[Sym[U]] = x match { 38 | //2.10 M% case s @ Sym() => Some(s) 39 | case s: Sym[U] => Some(s) 40 | case _ => None 41 | } 42 | } 43 | 44 | def eval[A](term: Exp[A]): Const[A] = term match { 45 | case IsSym(Lookup(c)) => c 46 | // case Lookup(c) => c 47 | //2.10 M5 case c @ Const() => c 48 | case c: Const[A] => c 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /test-out/epfl/test10-effects4.check: -------------------------------------------------------------------------------- 1 | cse: Sym(3) -> Sym(2) 2 | killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) 3 | **fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),VectorLiteral(List(Sym(1)))), TP(Sym(4),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3)))), TP(Sym(6),Mutate(Sym(2),Sym(4))), TP(Sym(8),VectorApply(Sym(6),Const(0))), TP(Sym(10),Reflect(Print(Sym(8)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10))))) 4 | /***************************************** 5 | Emitting Generated Code 6 | *******************************************/ 7 | class Test extends ((Int)=>(Unit)) { 8 | def apply(x0:Int): Unit = { 9 | val x1 = VectorZeros(Const(100)) 10 | val x2 = VectorLiteral(List(Sym(1))) 11 | // begin multi 12 | // soft deps: x1,x2,x3 13 | val x4 = VectorUpdate(Sym(1),Const(5),Const(7.0)) 14 | val x6 = x2 // mutated by x4 15 | // end multi 16 | val x8 = VectorApply(Sym(6),Const(0)) 17 | val x10 = println(x8) 18 | x10 19 | } 20 | } 21 | /***************************************** 22 | End of Generated Code 23 | *******************************************/ 24 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation2.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(9)=Reflect(ArrayIndex(Sym(8),Const(10)),Summary(false,false,false,false,false,false,List(Sym(3), Sym(6)),List(Sym(3), Sym(6)),List(),List()),List(Sym(3), Sym(6))) 2 | depends on Sym(3) 3 | depends on Sym(6) 4 | promoting to effect: Sym(12)=Reflect(ArrayIndex(Sym(8),Const(10)),Summary(false,false,false,false,false,false,List(Sym(3), Sym(6)),List(Sym(3), Sym(6)),List(),List()),List(Sym(3), Sym(6), Sym(10), Sym(11))) 5 | depends on Sym(3) 6 | depends on Sym(6) 7 | /***************************************** 8 | Emitting Generated Code 9 | *******************************************/ 10 | class Test extends ((Int)=>(Unit)) { 11 | def apply(x0:Int): Unit = { 12 | val x2 = LoopArray(100) { x1 => 13 | 0 14 | } 15 | val x3 = x2.clone // mutable 16 | val x5 = LoopArray(100) { x4 => 17 | 0 18 | } 19 | val x6 = x5.clone // mutable 20 | val x7 = x0 > 7 21 | val x8 = if (x7) { 22 | x3 23 | } else { 24 | x6 25 | } 26 | val x9 = x8.apply(10) 27 | val x10 = x3.update(10, 10) 28 | val x11 = x6.update(10, 20) 29 | val x12 = x8.apply(10) 30 | val x13 = x12 - x9 31 | val x14 = println(x13) 32 | x14 33 | } 34 | } 35 | /***************************************** 36 | End of Generated Code 37 | *******************************************/ 38 | -------------------------------------------------------------------------------- /test-out/epfl/test14-dataop2.check: -------------------------------------------------------------------------------- 1 | /* FILE: main.c */ 2 | int32_t main(int32_t); 3 | /***************************************** 4 | Emitting C Generated Code 5 | *******************************************/ 6 | #include 7 | #include 8 | #include 9 | #include 10 | int32_t main(int32_t x0) { 11 | int32_t x3 = 0; 12 | int* *x1 = mmap('table.dat') // XX TODO ; 13 | int32_t x2 = x1->length; 14 | for (;;) { 15 | int32_t x4 = x3; 16 | bool x5 = x4 < x2; 17 | if (x5) { 18 | x3 += 3; 19 | } else { 20 | } 21 | bool x9 = x5; 22 | for (;;) { 23 | bool x10 = x9; 24 | bool x20; 25 | if (x10) { 26 | int32_t x11 = x3; 27 | int32_t x13 = x11 + 1; 28 | int32_t x14 = x1[x13]; 29 | bool x17 = x14 > 0; 30 | bool x18 = !x17; 31 | x20 = x18; 32 | } else { 33 | x20 = false; 34 | } 35 | if (!x20) break; 36 | int32_t x22 = x3; 37 | bool x23 = x22 < x2; 38 | if (x23) { 39 | x3 += 3; 40 | } else { 41 | } 42 | x9 = x23; 43 | } 44 | bool x30 = x9; 45 | if (!x30) break; 46 | int32_t x32 = x3; 47 | int32_t x34 = x32 + 1; 48 | int32_t x35 = x1[x34]; 49 | int32_t x33 = x1[x32]; 50 | int32_t x38 = 2 * x33; 51 | printf(string("foo: %d, bar: %d\n").c_str(),x35,x38); 52 | } 53 | return 0; 54 | } 55 | /***************************************** 56 | End of C Generated Code 57 | *******************************************/ 58 | -------------------------------------------------------------------------------- /test-out/epfl/test11-hmm2.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test(px26:Array[Int]) extends ((Array[Int])=>(Array[Int])) { 5 | def apply(x0:Array[Int]): Array[Int] = { 6 | val x1 = new Array[Int](5) 7 | val x2 = x1(0) 8 | val x4 = x0(0) 9 | val x5 = x2 + x4 10 | val x6 = x1(0) = x5 11 | val x9 = x0(3) 12 | val x10 = x5 + x9 13 | val x11 = x1(0) = x10 14 | val x13 = x1(1) 15 | val x15 = x1(1) = x13 16 | val x8 = x0(2) 17 | val x16 = x13 + x8 18 | val x17 = x1(1) = x16 19 | val x18 = x1(2) 20 | val x20 = x1(2) = x18 21 | val x7 = x0(1) 22 | val x21 = x18 + x7 23 | val x22 = x1(2) = x21 24 | val x26 = px26 // static data: Array(0,0,1,1,1) 25 | var x24 : Int = 0 26 | val x33 = while (x24 < 5) { 27 | val x25 = x1(3) 28 | val x27 = x26(x24) 29 | val x28 = x0(x24) 30 | val x29 = x27 * x28 31 | val x30 = x25 + x29 32 | val x31 = x1(3) = x30 33 | 34 | x24 = x24 + 1 35 | } 36 | val x34 = x1(4) 37 | val x36 = x1(4) = x34 38 | val x37 = x34 + x8 39 | val x38 = x1(4) = x37 40 | val x12 = x0(4) 41 | val x39 = x37 + x12 42 | val x40 = x1(4) = x39 43 | x1 44 | } 45 | } 46 | /***************************************** 47 | End of Generated Code 48 | *******************************************/ 49 | compilation: ok 50 | 1 51 | 5 52 | 1 53 | 7 54 | 9 55 | -------------------------------------------------------------------------------- /test-out/epfl/test11-stencil3a.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class staged$0 extends ((Array[Double])=>(Array[Double])) { 5 | def apply(x0:Array[Double]): Array[Double] = { 6 | val x1 = x0.length 7 | val x2 = new Array[Double](x1) 8 | val x3 = x1 - 2 9 | var x5 : Int = 2 10 | val x31 = while (x5 < x3) { 11 | val x6 = x0(x5) 12 | val x7 = x5 + 1 13 | val x8 = x0(x7) 14 | val x9 = x6 * x8 15 | val x10 = x6 - x9 16 | val x11 = x5 - 1 17 | val x12 = x0(x11) 18 | val x13 = x12 * x6 19 | val x14 = x10 + x13 20 | val x15 = x5 + 2 21 | val x16 = x0(x15) 22 | val x17 = x8 * x16 23 | val x18 = x8 - x17 24 | val x19 = x18 + x9 25 | val x20 = x14 * x19 26 | val x21 = x14 - x20 27 | val x22 = x12 - x13 28 | val x23 = x5 - 2 29 | val x24 = x0(x23) 30 | val x25 = x24 * x12 31 | val x26 = x22 + x25 32 | val x27 = x26 * x14 33 | val x28 = x21 + x27 34 | val x29 = x2(x5) = x28 35 | 36 | x5 = x5 + 1 37 | } 38 | x2 39 | } 40 | } 41 | /***************************************** 42 | End of Generated Code 43 | *******************************************/ 44 | 45 | compilation: ok 46 | 0.0 47 | 0.0 48 | 0.8063999999999999 49 | 0.8735999999999999 50 | 0.9408000000000012 51 | 1.0079999999999998 52 | 1.0751999999999986 53 | 1.1423999999999992 54 | 0.0 55 | 0.0 56 | -------------------------------------------------------------------------------- /test-out/epfl/test10-transformrec3.check: -------------------------------------------------------------------------------- 1 | -- before transformation 2 | var x1 = null.asInstanceOf[scala.Function1[Double, Double]] 3 | var x4 = null.asInstanceOf[scala.Function1[Double, Double]] 4 | x4 = {x5: (Double) => 5 | val x6 = x5 - 1.0 6 | val x7 = x1(x6) 7 | x7 8 | } 9 | x1 = {x2: (Double) => 10 | val x3 = x2 == 0 11 | val x10 = if (x3) { 12 | 1.0 13 | } else { 14 | val x8 = x4(x2) 15 | val x9 = x2 * x8 16 | x9 17 | } 18 | x10 19 | } 20 | val x11 = x1(x0) 21 | -- after null transformation 22 | var x12 = null.asInstanceOf[scala.Function1[Double, Double]] 23 | var x13 = null.asInstanceOf[scala.Function1[Double, Double]] 24 | x13 = {x5: (Double) => 25 | val x6 = x5 - 1.0 26 | val x14 = x12(x6) 27 | x14 28 | } 29 | x12 = {x2: (Double) => 30 | val x3 = x2 == 0 31 | val x18 = if (x3) { 32 | 1.0 33 | } else { 34 | val x16 = x13(x2) 35 | val x17 = x2 * x16 36 | x17 37 | } 38 | x18 39 | } 40 | val x20 = x12(x0) 41 | -- after transformation 42 | var x21 = null.asInstanceOf[scala.Function1[Double, Double]] 43 | var x22 = null.asInstanceOf[scala.Function1[Double, Double]] 44 | x22 = /*2*/{x5: (Double) => 45 | val x6 = x5 - 1.0 46 | val x23 = x21(x6) 47 | x23 48 | } 49 | x21 = /*2*/{x2: (Double) => 50 | val x3 = x2 == 0 51 | val x27 = if (x3) { 52 | 1.0 53 | } else { 54 | val x25 = x22(x2) 55 | val x26 = x2 * x25 56 | x26 57 | } 58 | x27 59 | } 60 | val x29 = x21(x0) 61 | -- done 62 | -------------------------------------------------------------------------------- /publish.sbt: -------------------------------------------------------------------------------- 1 | // --- maven publishing --- 2 | 3 | publishMavenStyle := true 4 | 5 | publishArtifact in Test := false 6 | 7 | pomIncludeRepository := { _ => false } 8 | 9 | publishTo := { 10 | val nexus = "https://oss.sonatype.org/" 11 | val repo = if (version.value.trim.endsWith("SNAPSHOT")) 12 | "snapshots" at nexus + "content/repositories/snapshots" 13 | else 14 | "releases" at nexus + "service/local/staging/deploy/maven2" 15 | Some(repo) 16 | } 17 | 18 | // do not publish docs for snapshot releases 19 | publishArtifact in (Compile, packageDoc) := !version.value.trim.endsWith("SNAPSHOT") 20 | 21 | // `sbt release` should publish signed artifacts 22 | releasePublishArtifactsAction := PgpKeys.publishSigned.value 23 | 24 | pomExtra in Global := { 25 | 26 | 27 | tiarkrompf 28 | Tiark Rompf 29 | https://github.com/tiarkrompf 30 | 31 | 32 | } 33 | 34 | 35 | // --- sonatype settings --- 36 | 37 | sonatypeProfileName := "org.scala-lang" 38 | 39 | credentials ++= (for { 40 | username <- Option(System.getenv().get("SONATYPE_USER")) 41 | password <- Option(System.getenv().get("SONATYPE_PASS")) 42 | } yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq 43 | 44 | // NOTE: sonatypeRelease must be run explicitly, after `sbt release` -------------------------------------------------------------------------------- /test-out/epfl/test14-queries2.check: -------------------------------------------------------------------------------- 1 | nVars=1000 2 | nVars=2000 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | import scala.lms.epfl.test14.Schema 7 | class staged$0 extends ((Unit)=>(Unit)) { 8 | def apply(x0:Unit): Unit = { 9 | val x2580 = println("rangeFromNames(\"Edna\",\"Bert\"):") 10 | val x641 = Schema.db.people.flatMap { x112 => 11 | val x640 = Schema.db.people.flatMap { x445 => 12 | val x639 = Schema.db.people.flatMap { x620 => 13 | val x113 = x112.name 14 | val x114 = x113 == "Edna" 15 | val x448 = x445.name 16 | val x449 = x448 == "Bert" 17 | val x117 = x112.age 18 | val x624 = x620.age 19 | val x625 = x117 <= x624 20 | val x452 = x445.age 21 | val x626 = x624 < x452 22 | val x627 = x625 && x626 23 | val x634 = x449 && x627 24 | val x637 = x114 && x634 25 | val x638 = if (x637) { 26 | val x630 = x620.name 27 | val x631 = new Schema.Record { val name = x630 } 28 | val x632 = List(x631) 29 | x632 30 | } else { 31 | val x34 = List() 32 | x34 33 | } 34 | x638 35 | } 36 | x639 37 | } 38 | x640 39 | } 40 | val x2581 = println(x641) 41 | x2581 42 | } 43 | } 44 | /***************************************** 45 | End of Generated Code 46 | *******************************************/ 47 | 48 | compilation: ok 49 | rangeFromNames("Edna","Bert"): 50 | List({name:Cora}, {name:Drew}, {name:Edna}) 51 | -------------------------------------------------------------------------------- /test-out/epfl/test10-effects3.check: -------------------------------------------------------------------------------- 1 | cse: Sym(2) -> Sym(1) 2 | killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3), Sym(4)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) 3 | **fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(2),Copy(Sym(1))), TP(Sym(3),VectorLiteral(List(Sym(2)))), TP(Sym(4),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(10),Reflect(Print(Sym(3)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(4)))), TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(9), Sym(10))))) 4 | /***************************************** 5 | Emitting Generated Code 6 | *******************************************/ 7 | class Test extends ((Int)=>(Unit)) { 8 | def apply(x0:Int): Unit = { 9 | val x1 = VectorZeros(Const(100)) 10 | val x2 = x1.clone 11 | val x3 = VectorLiteral(List(Sym(2))) 12 | val x4 = println(x3) 13 | // begin multi 14 | // soft deps: x1,x2,x3,x4 15 | val x5 = VectorUpdate(Sym(1),Const(5),Const(7.0)) 16 | val x9 = x4 // mutated by x5 17 | // end multi 18 | val x10 = println(x3) 19 | x10 20 | } 21 | } 22 | /***************************************** 23 | End of Generated Code 24 | *******************************************/ 25 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac4-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(3)" [ 3 | label="Sym(3) \n Equal(Sym(2),Const(0))" 4 | shape=box 5 | ] 6 | "Sym(2)" -> "Sym(3)" 7 | "Sym(5)" [ 8 | label="Sym(5) \n Minus(Sym(2),Const(1.0))" 9 | shape=box 10 | ] 11 | "Sym(2)" -> "Sym(5)" 12 | "Sym(6)" [ 13 | label="Sym(6) \n Apply(Sym(1),Sym(5))" 14 | shape=box 15 | color=blue 16 | style=filled 17 | ] 18 | "Sym(1)" -> "Sym(6)" 19 | "Sym(5)" -> "Sym(6)" 20 | "Sym(7)" [ 21 | label="Sym(7) \n Times(Sym(2),Sym(6))" 22 | shape=box 23 | ] 24 | "Sym(2)" -> "Sym(7)" 25 | "Sym(6)" -> "Sym(7)" 26 | "Sym(8)" [ 27 | label="Sym(8) \n IfThenElse(Sym(3),Block(Const(1.0)),Block(Sym(7)))" 28 | shape=box 29 | ] 30 | "Sym(3)" -> "Sym(8)" 31 | "Sym(7)" -> "Sym(8)" 32 | "Sym(1)" [ 33 | label="Sym(1) \n DefineFun(Block(Sym(8)))" 34 | shape=box 35 | color=green 36 | style=filled 37 | ] 38 | "Sym(8)" -> "Sym(1)" 39 | "Sym(9)" [ 40 | label="Sym(9) \n Apply(Sym(1),Sym(0))" 41 | shape=box 42 | color=blue 43 | style=filled 44 | ] 45 | "Sym(1)" -> "Sym(9)" 46 | "Sym(0)" -> "Sym(9)" 47 | "Sym(10)" [ 48 | label="Sym(10) \n Times(Const(2.0),Sym(0))" 49 | shape=box 50 | ] 51 | "Sym(0)" -> "Sym(10)" 52 | "Sym(11)" [ 53 | label="Sym(11) \n Apply(Sym(1),Sym(10))" 54 | shape=box 55 | color=blue 56 | style=filled 57 | ] 58 | "Sym(1)" -> "Sym(11)" 59 | "Sym(10)" -> "Sym(11)" 60 | "Sym(12)" [ 61 | label="Sym(12) \n Plus(Sym(9),Sym(11))" 62 | shape=box 63 | ] 64 | "Sym(9)" -> "Sym(12)" 65 | "Sym(11)" -> "Sym(12)" 66 | } 67 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation4.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(5)=Reflect(SimpleLoop(Const(10),Sym(4),ArrayElem(Block(Sym(3)))),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 2 | depends on Sym(3) 3 | error: illegal sharing of mutable objects Sym(3) 4 | at Sym(6)=Reflect(ArrayMutable(Sym(5)),Summary(false,false,false,false,true,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 5 | promoting to effect: Sym(7)=Reflect(ArrayIndex(Sym(6),Const(5)),Summary(false,false,false,false,false,false,List(Sym(6), Sym(3)),List(Sym(6), Sym(3)),List(),List()),List(Sym(3), Sym(6))) 6 | depends on Sym(6) 7 | depends on Sym(3) 8 | promoting to effect: Sym(8)=Reflect(ArrayIndex(Sym(7),Const(50)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 9 | depends on Sym(3) 10 | /***************************************** 11 | Emitting Generated Code 12 | *******************************************/ 13 | class Test extends ((Int)=>(Unit)) { 14 | def apply(x0:Int): Unit = { 15 | val x2 = LoopArray(100) { x1 => 16 | 0 17 | } 18 | val x3 = x2.clone // mutable 19 | val x5 = LoopArray(10) { x4 => 20 | x3 21 | } 22 | val x6 = x5.clone // mutable 23 | val x7 = x6.apply(5) 24 | val x8 = x7.apply(50) 25 | val x9 = println(x8) 26 | x9 27 | } 28 | } 29 | /***************************************** 30 | End of Generated Code 31 | *******************************************/ 32 | -------------------------------------------------------------------------------- /test-out/epfl/test5-functionsrecursive.check: -------------------------------------------------------------------------------- 1 | -- begin 2 | /***************************************** 3 | Emitting Generated Code 4 | *******************************************/ 5 | class Test extends ((Double)=>(Any)) { 6 | def apply(x0:Double): Any = { 7 | var x9 = null.asInstanceOf[scala.Function1[Any, Any]] 8 | x9 = {x10: (Any) => 9 | val x11 = println("bar") 10 | val x12 = x9(x10) 11 | x12: Any 12 | } 13 | val x1 = {x2: (Any) => 14 | val x3 = println("foo") 15 | x2: Any 16 | } 17 | val x14 = x1(x0) 18 | val x15 = x1(x14) 19 | val x16 = x9(x15) 20 | val x5 = {x6: (Any) => 21 | val x7 = println("baz") 22 | 1: Int 23 | } 24 | val x17 = x5(x16) 25 | x17 26 | } 27 | } 28 | /***************************************** 29 | End of Generated Code 30 | *******************************************/ 31 | function main(x0) { 32 | var x9 = function(x10) { 33 | var x11 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("bar")) 34 | var x12 = x9(x10) 35 | return x12 36 | } 37 | var x1 = function(x2) { 38 | var x3 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("foo")) 39 | return x2 40 | } 41 | var x14 = x1(x0) 42 | var x15 = x1(x14) 43 | var x16 = x9(x15) 44 | var x5 = function(x6) { 45 | var x7 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("baz")) 46 | return 1 47 | } 48 | var x17 = x5(x16) 49 | return x17 50 | } 51 | -- end 52 | -------------------------------------------------------------------------------- /test-src/epfl/test4-functions/FunctionsGraphViz.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test4 4 | 5 | import internal.GraphVizExport 6 | 7 | import test2._ 8 | import test3._ 9 | 10 | trait FunctionsGraphViz extends GraphVizExport { 11 | val IR: FunctionsExternalDef0 12 | import IR._ 13 | 14 | override def emitNode(sym: Sym[Any], rhs: Def[Any])(implicit stream: java.io.PrintWriter) = rhs match { 15 | /* 16 | case Result(x) => 17 | super.emitNode(sym, rhs) 18 | stream.println("shape=point") 19 | case Test(x, y) => 20 | super.emitNode(sym, rhs) 21 | stream.println("color=red") 22 | */ 23 | case DefineFun(x) => 24 | super.emitNode(sym, rhs) 25 | stream.println("color=green") 26 | stream.println("style=filled") 27 | case Apply(x, y) => 28 | super.emitNode(sym, rhs) 29 | stream.println("color=blue") 30 | stream.println("style=filled") 31 | case _ => 32 | super.emitNode(sym, rhs) 33 | // stream.println("shape=point") 34 | } 35 | 36 | /* 37 | override def emitDeps(sym: Sym[Any], rhs: Def[Any], deps: List[Sym[Any]], stream: java.io.PrintWriter) = rhs match { 38 | case AndAlso(x, effects) => 39 | super.emitDeps(sym, rhs, deps -- effects.asInstanceOf[List[Sym[Any]]]) // TODO: cast 40 | for (dep <- effects) { 41 | stream.println("\"" + dep + "\" -> \"" + sym + "\"" + " [color=red]") 42 | } 43 | case _ => 44 | super.emitDeps(sym, rhs, deps) 45 | } 46 | */ 47 | 48 | } 49 | -------------------------------------------------------------------------------- /test-src/epfl/test1-arith/Arrays.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test1 4 | 5 | import common._ 6 | 7 | import java.io.PrintWriter 8 | 9 | 10 | trait Arrays extends Base { 11 | 12 | class ArrayOps[T:Typ](x: Rep[Array[T]]) { 13 | def apply(i: Int) = arrayApply(x, i) 14 | } 15 | implicit def array2arrayOps[T:Typ](x: Rep[Array[T]]) = new ArrayOps(x) 16 | 17 | def arrayApply[T:Typ](x: Rep[Array[T]], i:Int): Rep[T] 18 | //def arrayUpdate(x: Rep[Double]): Rep[Unit] 19 | def makeArray[T:Typ](x: List[Rep[T]]): Rep[Array[T]] 20 | } 21 | 22 | trait ArraysExp extends Arrays with BaseExp { 23 | implicit def arrayTyp[T:Typ]: Typ[Array[T]] = typ[T].arrayTyp 24 | 25 | case class ArrayApply[T:Typ](x:Rep[Array[T]], i:Int) extends Def[T] 26 | //case class ArrayUpdate[T](x:Rep[Array[T]], i:Int) extends Def[T] 27 | case class MakeArray[T:Typ](x:List[Rep[T]]) extends Def[Array[T]] { 28 | def m = typ[T] 29 | } 30 | 31 | def arrayApply[T:Typ](x: Rep[Array[T]], i:Int) = ArrayApply(x, i) 32 | //def arrayUpdate(x: Rep[Double]) = ArrayUpdate(x) 33 | def makeArray[T:Typ](x: List[Rep[T]]) = MakeArray(x) 34 | } 35 | 36 | trait ScalaGenArrays extends ScalaGenBase { 37 | val IR: ArraysExp 38 | import IR._ 39 | 40 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 41 | case ArrayApply(x,i) => emitValDef(sym, src"$x.apply(${i.toString})") 42 | case a @ MakeArray(x) => emitValDef(sym, src"Array[${a.m}]($x)") 43 | case _ => super.emitNode(sym, rhs) 44 | } 45 | } -------------------------------------------------------------------------------- /test-out/epfl/test9-struct2.check: -------------------------------------------------------------------------------- 1 | REMARK: this makes only sense with fat codegen (computation duplicated and some structs not removed otherwise) 2 | promoting to effect: Sym(21)=Reflect(IfThenElse(Sym(16),Block(Sym(6)),Block(Sym(20))),Summary(false,false,false,false,false,false,List(Sym(13), Sym(14)),List(),List(),List()),List(Sym(13), Sym(14))) 3 | depends on Sym(13) 4 | depends on Sym(14) 5 | /***************************************** 6 | Emitting Generated Code 7 | *******************************************/ 8 | class Test extends ((Int)=>(Unit)) { 9 | def apply(x0:Int): Unit = { 10 | val x10 = LoopArray(100) { x7 => 11 | val x8 = 0.0 - x7 12 | x8 13 | } 14 | var x13: Array[Double] = x10 15 | val x11 = LoopArray(100) { x7 => 16 | x7 17 | } 18 | var x14: Array[Int] = x11 19 | val x4 = LoopArray(100) { x1 => 20 | x1 21 | } 22 | val x5 = LoopArray(100) { x1 => 23 | val x2 = 0.0 - x1 24 | x2 25 | } 26 | val x16 = x0 > 7 27 | val x21 = if (x16) { 28 | val x6 = new ArrayOfAnon189207751(x4,x5) 29 | x6 30 | } else { 31 | val x17 = x13 32 | val x18 = x14 33 | val x19 = new ArrayOfAnon189207751(x17,x18) 34 | x19 35 | } 36 | x13 = x4 37 | x14 = x5 38 | val x24 = x13 39 | val x25 = x14 40 | val x26 = new ArrayOfAnon189207751(x24,x25) 41 | val x27 = println(x26) 42 | val x28 = println(x21) 43 | x28 44 | } 45 | } 46 | /***************************************** 47 | End of Generated Code 48 | *******************************************/ 49 | 50 | case class ArrayOfAnon189207751(re: Array[Double], im: Array[Int]) 51 | -------------------------------------------------------------------------------- /src/internal/GraphVizExport.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | import java.io.{PrintWriter, FileOutputStream} 5 | 6 | trait GraphVizExport extends GraphTraversal { 7 | val IR: Expressions 8 | import IR._ 9 | 10 | def quote(x: Any) = "\""+x+"\"" 11 | 12 | def emitNode(sym: Sym[Any], rhs: Def[Any])(implicit stream: PrintWriter) = { 13 | stream.println("label=" + quote(sym + " \\n " + rhs)) 14 | stream.println("shape=box") 15 | } 16 | 17 | def emitDeps(sym: Sym[Any], rhs: Def[Any], deps: List[Sym[Any]])(implicit stream: PrintWriter) = { 18 | for (dep <- deps) { 19 | stream.println("\"" + dep + "\" -> \"" + sym + "\"") 20 | } 21 | } 22 | 23 | def emitDepGraph(start: Exp[Any], file: String, landscape: Boolean = false): Unit = 24 | emitDepGraph(start, new java.io.PrintWriter(new java.io.FileOutputStream(file)), landscape) 25 | 26 | def emitDepGraph(start: Exp[Any], stream: PrintWriter, landscape: Boolean): Unit = { 27 | 28 | stream.println("digraph G {") 29 | 30 | val deflist = buildScheduleForResult(start,false) 31 | 32 | if (landscape) 33 | stream.println("rankdir=LR") 34 | 35 | for (TP(sym, rhs) <- deflist) { 36 | 37 | val deps = syms(rhs) 38 | 39 | stream.println(quote(sym) + " [") 40 | 41 | // all 42 | 43 | emitNode(sym, rhs)(stream) 44 | 45 | stream.println("]") 46 | 47 | emitDeps(sym, rhs, deps)(stream) 48 | 49 | } 50 | 51 | stream.println("}") 52 | stream.close() 53 | } 54 | 55 | 56 | 57 | } -------------------------------------------------------------------------------- /test-out/epfl/test5-functions.check: -------------------------------------------------------------------------------- 1 | -- begin 2 | /***************************************** 3 | Emitting Generated Code 4 | *******************************************/ 5 | class Test extends ((Double)=>(Any)) { 6 | def apply(x0:Double): Any = { 7 | val x4 = {x1: (Any) => 8 | val x2 = println("foo") 9 | x1: Any 10 | } 11 | val x5 = x4(x0) 12 | val x6 = x4(x5) 13 | x6 14 | } 15 | } 16 | /***************************************** 17 | End of Generated Code 18 | *******************************************/ 19 | /***************************************** 20 | Emitting Generated Code 21 | *******************************************/ 22 | class Test2 extends ((Double)=>(scala.Function1[Double, Double])) { 23 | def apply(x8:Double): scala.Function1[Double, Double] = { 24 | val x12 = {x9: (Double) => 25 | val x10 = x9 == x8 26 | val x11 = if (x10) { 27 | 2.0 28 | } else { 29 | x9 30 | } 31 | x11: Double 32 | } 33 | x12 34 | } 35 | } 36 | /***************************************** 37 | End of Generated Code 38 | *******************************************/ 39 | function main(x0) { 40 | var x4 = function(x1) { 41 | var x2 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("foo")) 42 | return x1 43 | } 44 | var x5 = x4(x0) 45 | var x6 = x4(x5) 46 | return x6 47 | } 48 | function main2(x8) { 49 | var x12 = function(x9) { 50 | var x10 = x9==x8 51 | var x11 52 | if (x10) { 53 | x11=2.0 54 | } else { 55 | x11=x9 56 | } 57 | return x11 58 | } 59 | return x12 60 | } 61 | -- end 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/TiarkRompf/virtualization-lms-core.svg?branch=develop)](https://travis-ci.org/TiarkRompf/virtualization-lms-core) 2 | [![Maven Central](https://img.shields.io/maven-central/v/org.scala-lang.lms/lms-core_2.11.svg)](https://maven-badges.herokuapp.com/maven-central/org.scala-lang.lms/lms-core_2.11) 3 | 4 | Lightweight Modular Staging (LMS) is a runtime code generation approach. 5 | This framework, LMS-Core, provides a library of core components for building 6 | high performance code generators and embedded compilers in Scala. 7 | 8 | Closely related projects are [Delite](https://github.com/stanford-ppl/Delite/), 9 | a framework for heterogeneous parallel domain specific languages (DSLs), 10 | and [Scala-Virtualized](https://github.com/tiarkrompf/scala-virtualized/), 11 | a set of minimal extensions to the Scala compiler to make embedding DSLs 12 | more seamless. 13 | 14 | ### Background: 15 | 16 | - [LMS website](http://scala-lms.github.io) 17 | 18 | - [LMS paper](http://infoscience.epfl.ch/record/150347/files/gpce63-rompf.pdf) 19 | 20 | - [Delite website](http://stanford-ppl.github.com/Delite/) 21 | 22 | - [Scala-Virtualized wiki](https://github.com/TiarkRompf/scala-virtualized/wiki) 23 | 24 | 25 | ### How to build: 26 | 27 | 1. Install the [SBT](http://www.scala-sbt.org/) build tool. 28 | 29 | 2. Run `sbt test` to run the test suite. 30 | 31 | 3. Run `sbt publish-local` to install LMS-Core for use in other projects. 32 | 33 | 34 | ### License: 35 | 36 | Copyright 2010-2016, EPFL and collaborators. Licensed under the revised BSD License. 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2014, EPFL 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /test-out/epfl/test12-concat.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Concat extends ((scala.collection.immutable.List[Int])=>(scala.collection.immutable.List[Int])) { 5 | def apply(x0:scala.collection.immutable.List[Int]): scala.collection.immutable.List[Int] = { 6 | val x1 = List(1,2,3) 7 | val x2 = x0 ::: x1 8 | x2 9 | } 10 | } 11 | /***************************************** 12 | End of Generated Code 13 | *******************************************/ 14 | /***************************************** 15 | Emitting Generated Code 16 | *******************************************/ 17 | class ConcatEmptyLeft extends ((scala.collection.immutable.List[Int])=>(scala.collection.immutable.List[Int])) { 18 | def apply(x3:scala.collection.immutable.List[Int]): scala.collection.immutable.List[Int] = { 19 | x3 20 | } 21 | } 22 | /***************************************** 23 | End of Generated Code 24 | *******************************************/ 25 | /***************************************** 26 | Emitting Generated Code 27 | *******************************************/ 28 | class ConcatEmptyRight extends ((scala.collection.immutable.List[Int])=>(scala.collection.immutable.List[Int])) { 29 | def apply(x5:scala.collection.immutable.List[Int]): scala.collection.immutable.List[Int] = { 30 | x5 31 | } 32 | } 33 | /***************************************** 34 | End of Generated Code 35 | *******************************************/ 36 | -------------------------------------------------------------------------------- /src/internal/FatExpressions.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package internal 3 | 4 | trait FatExpressions extends Expressions { 5 | 6 | abstract class FatDef 7 | 8 | //case class ThinDef(rhs: Def[Any]) extends FatDef 9 | 10 | case class TTP(val lhs: List[Sym[Any]], val mhs: List[Def[Any]], val rhs: FatDef) extends Stm 11 | 12 | override def infix_lhs(stm: Stm): List[Sym[Any]] = stm match { 13 | case TTP(lhs, mhs, rhs) => lhs 14 | case _ => super.infix_lhs(stm) 15 | } 16 | 17 | override def infix_rhs(stm: Stm): Any = stm match { 18 | case TTP(lhs, mhs, rhs) => rhs 19 | case _ => super.infix_rhs(stm) 20 | } 21 | 22 | override def infix_defines[A](stm: Stm, sym: Sym[A]): Option[Def[A]] = stm match { 23 | case TTP(lhs, mhs, rhs) => lhs.indexOf(sym) match { case idx if idx >= 0 => Some(mhs(idx).asInstanceOf[Def[A]]) case _ => None } 24 | case _ => super.infix_defines(stm, sym) 25 | } 26 | 27 | override def infix_defines[A: Typ](stm: Stm, rhs: Def[A]): Option[Sym[A]] = stm match { 28 | case TTP(lhs, mhs, rhs) => mhs.indexOf(rhs) match { 29 | case idx if idx >= 0 => 30 | val sym = lhs(idx) 31 | if (sym.tp <:< typ[A]) 32 | Some(sym.asInstanceOf[Sym[A]]) 33 | else 34 | None 35 | case _ => None 36 | } 37 | case _ => super.infix_defines(stm, rhs) 38 | } 39 | 40 | 41 | 42 | case class Combine(a: List[Exp[Any]]) extends Exp[Any]()(ManifestTyp(manifest[Any])) //TODO: get rid of. used by emitFatBlock 43 | 44 | case class Forward[A](x: Exp[A]) extends Def[A] // TODO: get rid of. used by SimplifyTransform 45 | 46 | } 47 | -------------------------------------------------------------------------------- /test-out/epfl/test10-worklist21.check: -------------------------------------------------------------------------------- 1 | ### first 2 | register replacement for Sym(1) 3 | register replacement for Sym(2) 4 | register replacement for Sym(3) 5 | --- code --- 6 | val x1 = VectorZeros(Const(100)) 7 | val x2 = VectorPlus(Sym(1),Sym(1)) 8 | val x3 = VectorPlus(Sym(1),Sym(2)) 9 | val x4 = println(x3) 10 | 11 | ### next 12 | install replacement for Sym(1) 13 | install replacement for Sym(2) 14 | register replacement for Sym(9) 15 | register replacement for Sym(11) 16 | install replacement for Sym(3) 17 | register replacement for Sym(16) 18 | register replacement for Sym(17) 19 | --- code --- 20 | val x7 = LoopArray(100) { x6 => 21 | 0 22 | } 23 | val x8 = new VectorInt(x7,100) 24 | val x9 = VectorLength(Sym(8)) 25 | val x13 = LoopArray(x9) { x10 => 26 | val x11 = VectorApply(Sym(8),Sym(10)) 27 | val x12 = x11 + x11 28 | x12 29 | } 30 | val x14 = new VectorDouble(x13,x9) 31 | val x19 = LoopArray(x9) { x15 => 32 | val x16 = VectorApply(Sym(8),Sym(15)) 33 | val x17 = VectorApply(Sym(14),Sym(15)) 34 | val x18 = x16 + x17 35 | x18 36 | } 37 | val x20 = new VectorDouble(x19,x9) 38 | val x21 = println(x20) 39 | 40 | ### next 41 | install replacement for Sym(9) 42 | install replacement for Sym(11) 43 | install replacement for Sym(16) 44 | install replacement for Sym(17) 45 | --- code --- 46 | val x24 = LoopArray(100) { x23 => 47 | 0 48 | } 49 | val x29 = LoopArray(100) { x26 => 50 | val x27 = x24.apply(x26) 51 | val x28 = x27 + x27 52 | x28 53 | } 54 | val x35 = LoopArray(100) { x31 => 55 | val x32 = x24.apply(x31) 56 | val x33 = x29.apply(x31) 57 | val x34 = x32 + x33 58 | x34 59 | } 60 | val x36 = new VectorDouble(x35,100) 61 | val x37 = println(x36) 62 | -------------------------------------------------------------------------------- /test-src/epfl/FileDiffSuite.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | 4 | import java.io.{PrintStream,File,FileInputStream,FileOutputStream,ByteArrayOutputStream} 5 | import org.scalatest._ 6 | 7 | 8 | trait FileDiffSuite extends Suite { 9 | val home = sys.env.get("LMS_HOME").map(_ + "/").getOrElse("") 10 | 11 | def withOutFile(name: String)(func: => Unit): Unit = { 12 | val file = new File(name) 13 | file.getParentFile.mkdirs() 14 | withOutput(new PrintStream(new FileOutputStream(file)))(func) 15 | } 16 | def captureOutput(func: => Unit): String = { 17 | val bstream = new ByteArrayOutputStream 18 | withOutput(new PrintStream(bstream))(func) 19 | bstream.toString 20 | } 21 | def withOutput(out: PrintStream)(func: => Unit): Unit = { 22 | val oldStdOut = System.out 23 | val oldStdErr = System.err 24 | try { 25 | System.setOut(out) 26 | System.setErr(out) 27 | Console.withOut(out)(Console.withErr(out)(func)) 28 | } finally { 29 | out.flush() 30 | out.close() 31 | System.setOut(oldStdOut) 32 | System.setErr(oldStdErr) 33 | } 34 | } 35 | 36 | def readFile(name: String): String = { 37 | val source = scala.io.Source.fromFile(name) 38 | val lines = source.getLines.mkString("\n") 39 | source.close() 40 | lines 41 | } 42 | def assertFileEqualsCheck(name: String): Unit = { 43 | assert(readFile(name) == readFile(name+".check"), name) // TODO: diff output 44 | new File(name) delete () 45 | } 46 | def withOutFileChecked(name: String)(func: => Unit): Unit = { 47 | withOutFile(name)(func) 48 | assertFileEqualsCheck(name) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test-out/epfl/test4-counter1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { 5 | def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { 6 | var x1 = null.asInstanceOf[scala.Function1[Double, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 7 | x1 = {x2: (Double) => 8 | val x3 = List(x2) 9 | val x4 = {x5: (Char) => 10 | val x6 = x2 // x5 11 | val x7 = x6 + 1.0 12 | val x8 = x1(x7) 13 | x8 14 | } 15 | val x9 = scala.lms.epfl.test4.Automaton(x3,x4) 16 | x9 17 | } 18 | val x10 = x1(0.0) 19 | x10 20 | } 21 | } 22 | /***************************************** 23 | End of Generated Code 24 | *******************************************/ 25 | compilation: ok 26 | idx: 0 27 | out: List(0.0) 28 | char: X 29 | idx: 1 30 | out: List(1.0) 31 | char: A 32 | idx: 2 33 | out: List(2.0) 34 | char: B 35 | idx: 3 36 | out: List(3.0) 37 | char: Z 38 | idx: 4 39 | out: List(4.0) 40 | char: A 41 | idx: 5 42 | out: List(5.0) 43 | char: A 44 | idx: 6 45 | out: List(6.0) 46 | char: B 47 | idx: 7 48 | out: List(7.0) 49 | char: W 50 | idx: 8 51 | out: List(8.0) 52 | char: A 53 | idx: 9 54 | out: List(9.0) 55 | char: A 56 | idx: 10 57 | out: List(10.0) 58 | char: A 59 | idx: 11 60 | out: List(11.0) 61 | char: A 62 | idx: 12 63 | out: List(12.0) 64 | char: B 65 | idx: 13 66 | out: List(13.0) 67 | char: Q 68 | idx: 14 69 | out: List(14.0) 70 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation4b.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(5)=Reflect(SimpleLoop(Const(10),Sym(4),ArrayElem(Block(Sym(3)))),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 2 | depends on Sym(3) 3 | promoting to effect: Sym(6)=Reflect(ArrayClone(Sym(5)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 4 | depends on Sym(3) 5 | error: illegal sharing of mutable objects Sym(3) 6 | at Sym(7)=Reflect(ArrayMutable(Sym(6)),Summary(false,false,false,false,true,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 7 | promoting to effect: Sym(8)=Reflect(ArrayIndex(Sym(7),Const(5)),Summary(false,false,false,false,false,false,List(Sym(7), Sym(3)),List(Sym(7), Sym(3)),List(),List()),List(Sym(3), Sym(7))) 8 | depends on Sym(7) 9 | depends on Sym(3) 10 | promoting to effect: Sym(9)=Reflect(ArrayIndex(Sym(8),Const(50)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 11 | depends on Sym(3) 12 | /***************************************** 13 | Emitting Generated Code 14 | *******************************************/ 15 | class Test extends ((Int)=>(Unit)) { 16 | def apply(x0:Int): Unit = { 17 | val x2 = LoopArray(100) { x1 => 18 | 0 19 | } 20 | val x3 = x2.clone // mutable 21 | val x5 = LoopArray(10) { x4 => 22 | x3 23 | } 24 | val x6 = x5.clone 25 | val x7 = x6.clone // mutable 26 | val x8 = x7.apply(5) 27 | val x9 = x8.apply(50) 28 | val x10 = println(x9) 29 | x10 30 | } 31 | } 32 | /***************************************** 33 | End of Generated Code 34 | *******************************************/ 35 | -------------------------------------------------------------------------------- /src/common/DSLOps.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | 6 | import scala.lms.internal.{GenericNestedCodegen, GenerationFailedException} 7 | 8 | //TODO: is this used at all? should it be merge with DeliteOps? 9 | 10 | //TODO rename this to something more meaningful 11 | 12 | trait DSLOpsExp extends EffectExp { 13 | // representation must be reified! this places the burden on the caller, but allows the caller to avoid the 14 | // use of function values (which can be uglier). 15 | class DSLOp[A](val representation: Block[A]) extends Def[A] 16 | } 17 | 18 | trait BaseGenDSLOps extends GenericNestedCodegen { 19 | val IR: DSLOpsExp 20 | import IR._ 21 | } 22 | 23 | trait ScalaGenDSLOps extends ScalaGenEffect with BaseGenDSLOps { 24 | val IR: DSLOpsExp 25 | import IR._ 26 | 27 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 28 | case op: DSLOp[_] => 29 | val b = op.representation 30 | gen"""val $sym = { 31 | |${nestedBlock(b)} 32 | |$b 33 | |}""" 34 | 35 | case _ => super.emitNode(sym, rhs) 36 | } 37 | 38 | } 39 | 40 | trait CLikeGenDSLOps extends BaseGenDSLOps with CLikeGenBase { 41 | val IR: DSLOpsExp 42 | import IR._ 43 | 44 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 45 | case op: DSLOp[_] => throw new GenerationFailedException("CLikeGenDSLOps: DSLOp is not supported") 46 | case _ => super.emitNode(sym, rhs) 47 | } 48 | } 49 | 50 | trait CudaGenDSLOps extends CudaGenEffect with CLikeGenDSLOps 51 | trait OpenCLGenDSLOps extends OpenCLGenEffect with CLikeGenDSLOps 52 | trait CGenDSLOps extends CGenEffect with CLikeGenDSLOps 53 | 54 | -------------------------------------------------------------------------------- /test-out/epfl/test5-conditional.check: -------------------------------------------------------------------------------- 1 | -- begin 2 | /***************************************** 3 | Emitting Generated Code 4 | *******************************************/ 5 | class Test extends ((Double)=>(Double)) { 6 | def apply(x0:Double): Double = { 7 | val x1 = println("yoyo") 8 | val x2 = x0 == x0 9 | val x6 = x0 + 4.0 10 | val x9 = if (x2) { 11 | val x3 = println("yoyo") 12 | val x4 = println("xxx") 13 | val x5 = println("yoyo") 14 | x6 15 | } else { 16 | val x8 = x0 + 6.0 17 | x8 18 | } 19 | val x10 = println("yyy") 20 | val x11 = println("yoyo") 21 | val x12 = x9 + x6 22 | x12 23 | } 24 | } 25 | /***************************************** 26 | End of Generated Code 27 | *******************************************/ 28 | compilation: ok 29 | yoyo 30 | yoyo 31 | xxx 32 | yoyo 33 | yyy 34 | yoyo 35 | 22.0 36 | function main(x0) { 37 | var x1 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) 38 | var x2 = x0==x0 39 | var x6 = x0+4.0 40 | var x9 41 | if (x2) { 42 | var x3 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) 43 | var x4 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("xxx")) 44 | var x5 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) 45 | x9=x6 46 | } else { 47 | var x8 = x0+6.0 48 | x9=x8 49 | } 50 | var x10 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yyy")) 51 | var x11 = document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode("yoyo")) 52 | var x12 = x9+x6 53 | return x12 54 | } 55 | -- end 56 | -------------------------------------------------------------------------------- /test-out/epfl/test2-fft1.check: -------------------------------------------------------------------------------- 1 | TP(Sym(8),Times(Const(1.0),Sym(4))) 2 | TP(Sym(9),Times(Const(-0.0),Sym(5))) 3 | TP(Sym(10),Minus(Sym(8),Sym(9))) 4 | TP(Sym(11),Times(Const(1.0),Sym(5))) 5 | TP(Sym(12),Times(Const(-0.0),Sym(4))) 6 | TP(Sym(13),Plus(Sym(11),Sym(12))) 7 | TP(Sym(14),Plus(Sym(0),Sym(10))) 8 | TP(Sym(15),Plus(Sym(1),Sym(13))) 9 | TP(Sym(16),Minus(Sym(0),Sym(10))) 10 | TP(Sym(17),Minus(Sym(1),Sym(13))) 11 | TP(Sym(18),Times(Const(1.0),Sym(6))) 12 | TP(Sym(19),Times(Const(-0.0),Sym(7))) 13 | TP(Sym(20),Minus(Sym(18),Sym(19))) 14 | TP(Sym(21),Times(Const(1.0),Sym(7))) 15 | TP(Sym(22),Times(Const(-0.0),Sym(6))) 16 | TP(Sym(23),Plus(Sym(21),Sym(22))) 17 | TP(Sym(24),Plus(Sym(2),Sym(20))) 18 | TP(Sym(25),Plus(Sym(3),Sym(23))) 19 | TP(Sym(26),Minus(Sym(2),Sym(20))) 20 | TP(Sym(27),Minus(Sym(3),Sym(23))) 21 | TP(Sym(28),Times(Const(1.0),Sym(24))) 22 | TP(Sym(29),Times(Const(-0.0),Sym(25))) 23 | TP(Sym(30),Minus(Sym(28),Sym(29))) 24 | TP(Sym(31),Times(Const(1.0),Sym(25))) 25 | TP(Sym(32),Times(Const(-0.0),Sym(24))) 26 | TP(Sym(33),Plus(Sym(31),Sym(32))) 27 | TP(Sym(34),Plus(Sym(14),Sym(30))) 28 | TP(Sym(35),Plus(Sym(15),Sym(33))) 29 | TP(Sym(36),Minus(Sym(14),Sym(30))) 30 | TP(Sym(37),Minus(Sym(15),Sym(33))) 31 | TP(Sym(38),Times(Const(6.123233995736766E-17),Sym(26))) 32 | TP(Sym(39),Times(Const(-1.0),Sym(27))) 33 | TP(Sym(40),Minus(Sym(38),Sym(39))) 34 | TP(Sym(41),Times(Const(6.123233995736766E-17),Sym(27))) 35 | TP(Sym(42),Times(Const(-1.0),Sym(26))) 36 | TP(Sym(43),Plus(Sym(41),Sym(42))) 37 | TP(Sym(44),Plus(Sym(16),Sym(40))) 38 | TP(Sym(45),Plus(Sym(17),Sym(43))) 39 | TP(Sym(46),Minus(Sym(16),Sym(40))) 40 | TP(Sym(47),Minus(Sym(17),Sym(43))) 41 | List(Complex(Sym(34),Sym(35)), Complex(Sym(44),Sym(45)), Complex(Sym(36),Sym(37)), Complex(Sym(46),Sym(47))) 42 | -------------------------------------------------------------------------------- /test-out/epfl/test10-effects2.check: -------------------------------------------------------------------------------- 1 | cse: Sym(2) -> Sym(1) 2 | killing: List(Sym(1))/List(Sym(1), Sym(2), Sym(3), Sym(4)) by VectorUpdate(Sym(1),Const(5),Const(7.0)) 3 | **fatten List(TP(Sym(1),VectorZeros(Const(100))), TP(Sym(3),VectorLiteral(List(Sym(1)))), TP(Sym(5),ReflectSoft(VectorUpdate(Sym(1),Const(5),Const(7.0)),List(Sym(1), Sym(2), Sym(3), Sym(4)))), TP(Sym(8),Mutate(Sym(3),Sym(5))), TP(Sym(10),VectorApply(Sym(8),Const(0))), TP(Sym(12),Reflect(Print(Sym(10)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())), TP(Sym(2),Copy(Sym(1))), TP(Sym(4),VectorLiteral(List(Sym(2)))), TP(Sym(9),Mutate(Sym(4),Sym(5))), TP(Sym(11),VectorApply(Sym(9),Const(0))), TP(Sym(13),Reflect(Print(Sym(11)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12)))), TP(Sym(14),Reify(Sym(13),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(12), Sym(13))))) 4 | /***************************************** 5 | Emitting Generated Code 6 | *******************************************/ 7 | class Test extends ((Int)=>(Unit)) { 8 | def apply(x0:Int): Unit = { 9 | val x1 = VectorZeros(Const(100)) 10 | val x3 = VectorLiteral(List(Sym(1))) 11 | val x2 = x1.clone 12 | val x4 = VectorLiteral(List(Sym(2))) 13 | // begin multi 14 | // soft deps: x1,x2,x3,x4 15 | val x5 = VectorUpdate(Sym(1),Const(5),Const(7.0)) 16 | val x8 = x3 // mutated by x5 17 | val x9 = x4 // mutated by x5 18 | // end multi 19 | val x10 = VectorApply(Sym(8),Const(0)) 20 | val x12 = println(x10) 21 | val x11 = VectorApply(Sym(9),Const(0)) 22 | val x13 = println(x11) 23 | x13 24 | } 25 | } 26 | /***************************************** 27 | End of Generated Code 28 | *******************************************/ 29 | -------------------------------------------------------------------------------- /test-out/epfl/test4-fac2-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | "Sym(3)" [ 3 | label="Sym(3) \n Test(Sym(2),0.0)" 4 | shape=box 5 | color=red 6 | ] 7 | "Sym(2)" -> "Sym(3)" 8 | "Sym(4)" [ 9 | label="Sym(4) \n Reify(Const(1.0),List(Sym(3)))" 10 | shape=box 11 | ] 12 | "Sym(3)" -> "Sym(4)" [color=red] 13 | "Sym(1)" [ 14 | label="Sym(1) \n DefineFun(Block(Sym(4)))" 15 | shape=box 16 | color=green 17 | style=filled 18 | ] 19 | "Sym(4)" -> "Sym(1)" 20 | "Sym(6)" [ 21 | label="Sym(6) \n Apply(Sym(1),Sym(0))" 22 | shape=box 23 | color=blue 24 | style=filled 25 | ] 26 | "Sym(1)" -> "Sym(6)" 27 | "Sym(0)" -> "Sym(6)" 28 | "Sym(9)" [ 29 | label="Sym(9) \n Minus(Sym(8),Const(1.0))" 30 | shape=box 31 | ] 32 | "Sym(8)" -> "Sym(9)" 33 | "Sym(10)" [ 34 | label="Sym(10) \n Apply(Sym(1),Sym(9))" 35 | shape=box 36 | color=blue 37 | style=filled 38 | ] 39 | "Sym(1)" -> "Sym(10)" 40 | "Sym(9)" -> "Sym(10)" 41 | "Sym(12)" [ 42 | label="Sym(12) \n Apply(Sym(7),Sym(9))" 43 | shape=box 44 | color=blue 45 | style=filled 46 | ] 47 | "Sym(7)" -> "Sym(12)" 48 | "Sym(9)" -> "Sym(12)" 49 | "Sym(13)" [ 50 | label="Sym(13) \n OrElse(List(Sym(10), Sym(12)))" 51 | shape=box 52 | ] 53 | "Sym(10)" -> "Sym(13)" 54 | "Sym(12)" -> "Sym(13)" 55 | "Sym(14)" [ 56 | label="Sym(14) \n Times(Sym(8),Sym(13))" 57 | shape=box 58 | ] 59 | "Sym(8)" -> "Sym(14)" 60 | "Sym(13)" -> "Sym(14)" 61 | "Sym(7)" [ 62 | label="Sym(7) \n DefineFun(Block(Pure(Sym(14))))" 63 | shape=box 64 | color=green 65 | style=filled 66 | ] 67 | "Sym(14)" -> "Sym(7)" 68 | "Sym(15)" [ 69 | label="Sym(15) \n Apply(Sym(7),Sym(0))" 70 | shape=box 71 | color=blue 72 | style=filled 73 | ] 74 | "Sym(7)" -> "Sym(15)" 75 | "Sym(0)" -> "Sym(15)" 76 | "Sym(16)" [ 77 | label="Sym(16) \n OrElse(List(Sym(6), Sym(15)))" 78 | shape=box 79 | ] 80 | "Sym(6)" -> "Sym(16)" 81 | "Sym(15)" -> "Sym(16)" 82 | } 83 | -------------------------------------------------------------------------------- /test-out/epfl/test10-misc2.check: -------------------------------------------------------------------------------- 1 | -- full graph 2 | TP(Sym(1),VectorZeros(Const(100))) 3 | TP(Sym(2),VectorZeros(Const(50))) 4 | TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 5 | TP(Sym(4),Equal(Sym(0),Const(0))) 6 | TP(Sym(5),VectorLength(Sym(3))) 7 | TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 8 | TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) 9 | TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 10 | TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) 11 | TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 12 | TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) 13 | -- before transformation 14 | val x4 = x0 == 0 15 | val x10 = if (x4) { 16 | val x1 = VectorZeros(Const(100)) 17 | val x2 = VectorZeros(Const(50)) 18 | val x3 = VectorPlus(Sym(1),Sym(2)) 19 | val x5 = VectorLength(Sym(3)) 20 | val x6 = println(x5) 21 | x6 22 | } else { 23 | val x1 = VectorZeros(Const(100)) 24 | val x2 = VectorZeros(Const(50)) 25 | val x3 = VectorPlus(Sym(1),Sym(2)) 26 | val x5 = VectorLength(Sym(3)) 27 | val x8 = println(x5) 28 | x8 29 | } 30 | encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 31 | replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 32 | error: java.lang.AssertionError: assertion failed: already defined: List(TP(Sym(3),VectorPlus(Sym(2),Sym(1)))) for List(TP(Sym(3),VectorPlus(Sym(1),Sym(2)))) 33 | -- done 34 | -------------------------------------------------------------------------------- /test-out/epfl/test14-queries3.check: -------------------------------------------------------------------------------- 1 | nVars=1000 2 | nVars=2000 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | import scala.lms.epfl.test14.Schema 7 | class staged$0 extends ((Unit)=>(Unit)) { 8 | def apply(x0:Unit): Unit = { 9 | val x2580 = println("expertise(\"abstract\"):") 10 | val x824 = Schema.org.departments.flatMap { x756 => 11 | val x816 = Schema.org.employees.flatMap { x787 => 12 | val x758 = x756.dpt 13 | val x788 = x787.dpt 14 | val x789 = x758 == x788 15 | val x809 = Schema.org.tasks.flatMap { x800 => 16 | val x791 = x787.emp 17 | val x801 = x800.emp 18 | val x802 = x791 == x801 19 | val x803 = x800.tsk 20 | val x804 = x803 == "abstract" 21 | val x805 = x802 && x804 22 | val x808 = if (x805) { 23 | val x685 = new Schema.Record { val ignore = () } 24 | val x712 = List(x685) 25 | x712 26 | } else { 27 | val x34 = List() 28 | x34 29 | } 30 | x808 31 | } 32 | val x810 = x809.isEmpty 33 | val x812 = x789 && x810 34 | val x815 = if (x812) { 35 | val x685 = new Schema.Record { val ignore = () } 36 | val x712 = List(x685) 37 | x712 38 | } else { 39 | val x34 = List() 40 | x34 41 | } 42 | x815 43 | } 44 | val x817 = x816.isEmpty 45 | val x823 = if (x817) { 46 | val x758 = x756.dpt 47 | val x821 = new Schema.Record { val dpt = x758 } 48 | val x822 = List(x821) 49 | x822 50 | } else { 51 | val x34 = List() 52 | x34 53 | } 54 | x823 55 | } 56 | val x2581 = println(x824) 57 | x2581 58 | } 59 | } 60 | /***************************************** 61 | End of Generated Code 62 | *******************************************/ 63 | 64 | warning: there were 9 feature warnings; re-run with -feature for details 65 | one warning found 66 | compilation: ok 67 | expertise("abstract"): 68 | List({dpt:Quality}, {dpt:Research}) 69 | -------------------------------------------------------------------------------- /test-src/epfl/test1-arith/Relat.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test1 4 | 5 | import common._ 6 | 7 | trait Relat extends Base { 8 | 9 | 10 | /* 11 | implicit def doubleRepRelat(x: Rep[Double]) = new { 12 | def >(y: Rep[Double]) = greater(x,y) 13 | def <(y: Rep[Double]) = less(x,y) 14 | def >=(y: Rep[Double]) = greaterEqual(x,y) 15 | def <=(y: Rep[Double]) = lessEqual(x,y) 16 | def ==(y: Rep[Double]) = equal(x,y) 17 | def !=(y: Rep[Double]) = notEqual(x,y) 18 | } 19 | */ 20 | 21 | def min(x: Rep[Double], y: Rep[Double]): Rep[Double] 22 | def max(x: Rep[Double], y: Rep[Double]): Rep[Double] 23 | 24 | /* 25 | def greater(x: Rep[Double], y: Rep[Double]): Rep[Double] 26 | def less(x: Rep[Double], y: Rep[Double]): Rep[Double] 27 | def greaterEqual(x: Rep[Double], y: Rep[Double]): Rep[Double] 28 | def lessEqual(x: Rep[Double], y: Rep[Double]): Rep[Double] 29 | def equal(x: Rep[Double], y: Rep[Double]): Rep[Double] 30 | def notEqual(x: Rep[Double], y: Rep[Double]): Rep[Double] 31 | */ 32 | } 33 | 34 | trait RelatExp extends Relat with BaseExp { 35 | implicit def doubleTyp: Typ[Double] = manifestTyp 36 | 37 | case class Min(x: Rep[Double], y: Rep[Double]) extends Def[Double] 38 | case class Max(x: Rep[Double], y: Rep[Double]) extends Def[Double] 39 | 40 | def min(x: Rep[Double], y: Rep[Double]) = Min(x,y) 41 | def max(x: Rep[Double], y: Rep[Double]) = Max(x,y) 42 | } 43 | 44 | trait RelatExpOpt extends RelatExp with LiftAll { 45 | 46 | override def min(x: Rep[Double], y: Rep[Double]) = (x,y) match { 47 | case (Const(x), Const(y)) => math.min(x,y) 48 | case _ => super.min(x,y) 49 | } 50 | override def max(x: Rep[Double], y: Rep[Double]) = (x,y) match { 51 | case (Const(x), Const(y)) => math.max(x,y) 52 | case _ => super.max(x,y) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test-out/epfl/test2-sort1.check: -------------------------------------------------------------------------------- 1 | TP(Sym(8),Min(Sym(0),Sym(1))) 2 | TP(Sym(9),Max(Sym(0),Sym(1))) 3 | TP(Sym(10),Min(Sym(2),Sym(3))) 4 | TP(Sym(11),Max(Sym(2),Sym(3))) 5 | TP(Sym(12),Min(Sym(8),Sym(10))) 6 | TP(Sym(13),Max(Sym(8),Sym(10))) 7 | TP(Sym(14),Min(Sym(9),Sym(11))) 8 | TP(Sym(15),Max(Sym(9),Sym(11))) 9 | TP(Sym(16),Min(Sym(12),Sym(14))) 10 | TP(Sym(17),Max(Sym(12),Sym(14))) 11 | TP(Sym(18),Min(Sym(13),Sym(15))) 12 | TP(Sym(19),Max(Sym(13),Sym(15))) 13 | TP(Sym(20),Min(Sym(4),Sym(5))) 14 | TP(Sym(21),Max(Sym(4),Sym(5))) 15 | TP(Sym(22),Min(Sym(6),Sym(7))) 16 | TP(Sym(23),Max(Sym(6),Sym(7))) 17 | TP(Sym(24),Min(Sym(20),Sym(22))) 18 | TP(Sym(25),Max(Sym(20),Sym(22))) 19 | TP(Sym(26),Min(Sym(21),Sym(23))) 20 | TP(Sym(27),Max(Sym(21),Sym(23))) 21 | TP(Sym(28),Min(Sym(24),Sym(26))) 22 | TP(Sym(29),Max(Sym(24),Sym(26))) 23 | TP(Sym(30),Min(Sym(25),Sym(27))) 24 | TP(Sym(31),Max(Sym(25),Sym(27))) 25 | TP(Sym(32),Min(Sym(16),Sym(28))) 26 | TP(Sym(33),Max(Sym(16),Sym(28))) 27 | TP(Sym(34),Min(Sym(18),Sym(30))) 28 | TP(Sym(35),Max(Sym(18),Sym(30))) 29 | TP(Sym(36),Min(Sym(32),Sym(34))) 30 | TP(Sym(37),Max(Sym(32),Sym(34))) 31 | TP(Sym(38),Min(Sym(33),Sym(35))) 32 | TP(Sym(39),Max(Sym(33),Sym(35))) 33 | TP(Sym(40),Min(Sym(17),Sym(29))) 34 | TP(Sym(41),Max(Sym(17),Sym(29))) 35 | TP(Sym(42),Min(Sym(19),Sym(31))) 36 | TP(Sym(43),Max(Sym(19),Sym(31))) 37 | TP(Sym(44),Min(Sym(40),Sym(42))) 38 | TP(Sym(45),Max(Sym(40),Sym(42))) 39 | TP(Sym(46),Min(Sym(41),Sym(43))) 40 | TP(Sym(47),Max(Sym(41),Sym(43))) 41 | TP(Sym(48),Min(Sym(36),Sym(44))) 42 | TP(Sym(49),Max(Sym(36),Sym(44))) 43 | TP(Sym(50),Min(Sym(37),Sym(45))) 44 | TP(Sym(51),Max(Sym(37),Sym(45))) 45 | TP(Sym(52),Min(Sym(38),Sym(46))) 46 | TP(Sym(53),Max(Sym(38),Sym(46))) 47 | TP(Sym(54),Min(Sym(39),Sym(47))) 48 | TP(Sym(55),Max(Sym(39),Sym(47))) 49 | List(Sym(48), Sym(49), Sym(50), Sym(51), Sym(52), Sym(53), Sym(54), Sym(55)) 50 | -------------------------------------------------------------------------------- /test-out/epfl/test10-worklist23.check: -------------------------------------------------------------------------------- 1 | ### first 2 | register replacement for Sym(1) 3 | register replacement for Sym(2) 4 | register replacement for Sym(5) 5 | --- code --- 6 | val x1 = VectorZeros(Const(100)) 7 | val x3 = x0 > 0 8 | val x4 = if (x3) { 9 | x1 10 | } else { 11 | val x2 = VectorZeros(Const(50)) 12 | x2 13 | } 14 | val x5 = VectorPlus(Sym(4),Sym(1)) 15 | val x6 = println(x5) 16 | 17 | ### next 18 | install replacement for Sym(1) 19 | install replacement for Sym(2) 20 | install replacement for Sym(5) 21 | register replacement for Sym(18) 22 | register replacement for Sym(20) 23 | register replacement for Sym(21) 24 | --- code --- 25 | val x3 = x0 > 0 26 | val x9 = LoopArray(100) { x8 => 27 | 0 28 | } 29 | // TODO: use vars instead of tuples to return multiple values 30 | val (x15,x16) = if (x3) { 31 | (x9,100) 32 | } else { 33 | val x12 = LoopArray(50) { x11 => 34 | 0 35 | } 36 | (x12,50) 37 | } 38 | val x17 = new VectorDouble(x15,x16) 39 | val x18 = VectorLength(Sym(17)) 40 | val x10 = new VectorInt(x9,100) 41 | val x23 = LoopArray(x18) { x19 => 42 | val x20 = VectorApply(Sym(17),Sym(19)) 43 | val x21 = VectorApply(Sym(10),Sym(19)) 44 | val x22 = x20 + x21 45 | x22 46 | } 47 | val x24 = new VectorDouble(x23,x18) 48 | val x25 = println(x24) 49 | 50 | ### next 51 | install replacement for Sym(18) 52 | install replacement for Sym(20) 53 | install replacement for Sym(21) 54 | --- code --- 55 | val x3 = x0 > 0 56 | val x28 = LoopArray(100) { x27 => 57 | 0 58 | } 59 | // TODO: use vars instead of tuples to return multiple values 60 | val (x16,x31) = if (x3) { 61 | (100,x28) 62 | } else { 63 | val x30 = LoopArray(50) { x29 => 64 | 0 65 | } 66 | (50,x30) 67 | } 68 | val x38 = LoopArray(x16) { x34 => 69 | val x35 = x31.apply(x34) 70 | val x36 = x28.apply(x34) 71 | val x37 = x35 + x36 72 | x37 73 | } 74 | val x39 = new VectorDouble(x38,x16) 75 | val x40 = println(x39) 76 | -------------------------------------------------------------------------------- /test-out/epfl/test14-queries4.check: -------------------------------------------------------------------------------- 1 | nVars=1000 2 | nVars=2000 3 | /***************************************** 4 | Emitting Generated Code 5 | *******************************************/ 6 | import scala.lms.epfl.test14.Schema 7 | class staged$0 extends ((Unit)=>(Unit)) { 8 | def apply(x0:Unit): Unit = { 9 | val x2580 = println("expertise2(\"abstract\"):") 10 | val x1177 = Schema.org.departments.flatMap { x1018 => 11 | val x1169 = Schema.org.employees.flatMap { x1111 => 12 | val x1020 = x1018.dpt 13 | val x1112 = x1111.dpt 14 | val x1113 = x1020 == x1112 15 | val x1161 = Schema.org.tasks.flatMap { x1148 => 16 | val x1116 = x1111.emp 17 | val x1149 = x1148.emp 18 | val x1150 = x1116 == x1149 19 | val x1153 = x1148.tsk 20 | val x1156 = x1153 == "abstract" 21 | val x1158 = x1150 && x1156 22 | val x1160 = if (x1158) { 23 | val x685 = new Schema.Record { val ignore = () } 24 | val x712 = List(x685) 25 | x712 26 | } else { 27 | val x34 = List() 28 | x34 29 | } 30 | x1160 31 | } 32 | val x1162 = x1161.isEmpty 33 | val x1166 = x1113 && x1162 34 | val x1168 = if (x1166) { 35 | val x685 = new Schema.Record { val ignore = () } 36 | val x712 = List(x685) 37 | x712 38 | } else { 39 | val x34 = List() 40 | x34 41 | } 42 | x1168 43 | } 44 | val x1170 = x1169.isEmpty 45 | val x1176 = if (x1170) { 46 | val x1020 = x1018.dpt 47 | val x1174 = new Schema.Record { val dpt = x1020 } 48 | val x1175 = List(x1174) 49 | x1175 50 | } else { 51 | val x34 = List() 52 | x34 53 | } 54 | x1176 55 | } 56 | val x2581 = println(x1177) 57 | x2581 58 | } 59 | } 60 | /***************************************** 61 | End of Generated Code 62 | *******************************************/ 63 | 64 | warning: there were 9 feature warnings; re-run with -feature for details 65 | one warning found 66 | compilation: ok 67 | expertise2("abstract"): 68 | List({dpt:Quality}, {dpt:Research}) 69 | -------------------------------------------------------------------------------- /test-out/epfl/test9-struct4.check: -------------------------------------------------------------------------------- 1 | wtableneg: List() 2 | partitions: List(TTP(List(Sym(4), Sym(5)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(2))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayElem(Block(Sym(2))))))) 3 | considering TP(Sym(19),ArrayIndex(Sym(5),Sym(17))) 4 | try once more ... 5 | wtableneg: List() 6 | partitions: List(TTP(List(Sym(4), Sym(5)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(2))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayElem(Block(Sym(2))))))) 7 | no changes, we're done 8 | wtableneg: List() 9 | partitions: List(TTP(List(Sym(23)),List(SimpleLoop(Const(100),Sym(17),ArrayElem(Block(Sym(21))))),SimpleFatLoop(Const(100),Sym(17),List(ArrayElem(Block(Sym(21))))))) 10 | no changes, we're done 11 | /***************************************** 12 | Emitting Generated Code 13 | *******************************************/ 14 | class Test extends ((Int)=>(Unit)) { 15 | def apply(x0:Int): Unit = { 16 | var x4 = new Array[Int](100) 17 | var x5 = new Array[Double](100) 18 | for (x1 <- 0 until 100) { 19 | val x2 = 0.0 - x1 20 | x4(x1) = x1 21 | x5(x1) = x2 22 | } 23 | var x13: Array[Int] = x4 24 | var x14: Array[Double] = x5 25 | val x16 = x0 > 7 26 | val x26 = if (x16) { 27 | var x23 = new Array[Double](100) 28 | for (x17 <- 0 until 100) { 29 | val x19 = x5.apply(x17) 30 | val x21 = 0.0 - x19 31 | x23(x17) = x21 32 | } 33 | x23 34 | } else { 35 | x5 36 | } 37 | val x27 = new ArrayOfAnon189207751(x4,x26) 38 | val x28 = println(x27) 39 | x28 40 | } 41 | } 42 | /***************************************** 43 | End of Generated Code 44 | *******************************************/ 45 | 46 | case class ArrayOfAnon189207751(re: Array[Int], im: Array[Double]) 47 | -------------------------------------------------------------------------------- /test-out/epfl/test14-cgen3.check: -------------------------------------------------------------------------------- 1 | /* FILE: test2.c */ 2 | int32_t test2(int32_t); 3 | int32_t test1(int32_t); 4 | int32_t main(int32_t); 5 | /***************************************** 6 | Emitting C Generated Code 7 | *******************************************/ 8 | #include 9 | #include 10 | #include 11 | #include 12 | int32_t test2(int32_t x0) { 13 | printf(string("Hello, world: test2\n").c_str()); 14 | return x0; 15 | } 16 | /***************************************** 17 | End of C Generated Code 18 | *******************************************/ 19 | /* FILE: test1.c */ 20 | int32_t test2(int32_t); 21 | int32_t test1(int32_t); 22 | int32_t main(int32_t); 23 | /***************************************** 24 | Emitting C Generated Code 25 | *******************************************/ 26 | #include 27 | #include 28 | #include 29 | #include 30 | int32_t test1(int32_t x3) { 31 | printf(string("Hello, world: test1\n").c_str()); 32 | int32_t x5 = test2(x3); 33 | return x5; 34 | } 35 | /***************************************** 36 | End of C Generated Code 37 | *******************************************/ 38 | /* FILE: main.c */ 39 | int32_t test2(int32_t); 40 | int32_t test1(int32_t); 41 | int32_t main(int32_t); 42 | /***************************************** 43 | Emitting C Generated Code 44 | *******************************************/ 45 | #include 46 | #include 47 | #include 48 | #include 49 | int32_t main(int32_t x7) { 50 | printf(string("Hello, world: main\n").c_str()); 51 | int32_t x9 = test1(x7); 52 | return x9; 53 | } 54 | /***************************************** 55 | End of C Generated Code 56 | *******************************************/ 57 | -------------------------------------------------------------------------------- /test-out/epfl/test9-amb1a.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Test extends ((Int)=>(Unit)) { 5 | def apply(x0:Int): Unit = { 6 | val x1 = 1 == 1 7 | val x6 = if (x1) { 8 | val x2 = println("found:") 9 | val x3 = println(1) 10 | val x4 = println(1) 11 | x4 12 | } else { 13 | () 14 | } 15 | val x7 = 1 == 2 16 | val x12 = if (x7) { 17 | val x8 = println("found:") 18 | val x9 = println(1) 19 | val x10 = println(2) 20 | x10 21 | } else { 22 | () 23 | } 24 | val x13 = 1 == 3 25 | val x18 = if (x13) { 26 | val x14 = println("found:") 27 | val x15 = println(1) 28 | val x16 = println(3) 29 | x16 30 | } else { 31 | () 32 | } 33 | val x19 = 2 == 1 34 | val x24 = if (x19) { 35 | val x20 = println("found:") 36 | val x21 = println(2) 37 | val x22 = println(1) 38 | x22 39 | } else { 40 | () 41 | } 42 | val x25 = 2 == 2 43 | val x30 = if (x25) { 44 | val x26 = println("found:") 45 | val x27 = println(2) 46 | val x28 = println(2) 47 | x28 48 | } else { 49 | () 50 | } 51 | val x31 = 2 == 3 52 | val x36 = if (x31) { 53 | val x32 = println("found:") 54 | val x33 = println(2) 55 | val x34 = println(3) 56 | x34 57 | } else { 58 | () 59 | } 60 | val x37 = x0 == 1 61 | val x42 = if (x37) { 62 | val x38 = println("found:") 63 | val x39 = println(x0) 64 | val x40 = println(1) 65 | x40 66 | } else { 67 | () 68 | } 69 | val x43 = x0 == 2 70 | val x48 = if (x43) { 71 | val x44 = println("found:") 72 | val x45 = println(x0) 73 | val x46 = println(2) 74 | x46 75 | } else { 76 | () 77 | } 78 | val x49 = x0 == 3 79 | val x54 = if (x49) { 80 | val x50 = println("found:") 81 | val x51 = println(x0) 82 | val x52 = println(3) 83 | x52 84 | } else { 85 | () 86 | } 87 | () 88 | } 89 | } 90 | /***************************************** 91 | End of Generated Code 92 | *******************************************/ 93 | -------------------------------------------------------------------------------- /test-out/epfl/test8-mutation6.check: -------------------------------------------------------------------------------- 1 | promoting to effect: Sym(5)=Reflect(SimpleLoop(Const(10),Sym(4),ArrayElem(Block(Sym(3)))),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 2 | depends on Sym(3) 3 | promoting to effect: Sym(12)=Reflect(ArrayIndex(Sym(11),Const(5)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 4 | depends on Sym(3) 5 | promoting to effect: Sym(13)=Reflect(ArrayIndex(Sym(12),Const(50)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3))) 6 | depends on Sym(3) 7 | promoting to effect: Sym(15)=Reflect(ArrayIndex(Sym(11),Const(5)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3), Sym(14))) 8 | depends on Sym(3) 9 | promoting to effect: Sym(16)=Reflect(ArrayIndex(Sym(15),Const(50)),Summary(false,false,false,false,false,false,List(Sym(3)),List(Sym(3)),List(),List()),List(Sym(3), Sym(14))) 10 | depends on Sym(3) 11 | /***************************************** 12 | Emitting Generated Code 13 | *******************************************/ 14 | class Test extends ((Int)=>(Unit)) { 15 | def apply(x0:Int): Unit = { 16 | val x2 = LoopArray(100) { x1 => 17 | 0 18 | } 19 | val x3 = x2.clone // mutable 20 | val x5 = LoopArray(10) { x4 => 21 | x3 22 | } 23 | val x10 = x0 > 7 24 | val x11 = if (x10) { 25 | x5 26 | } else { 27 | val x8 = LoopArray(100) { x7 => 28 | 0 29 | } 30 | val x9 = LoopArray(10) { x6 => 31 | x8 32 | } 33 | x9 34 | } 35 | val x12 = x11.apply(5) 36 | val x13 = x12.apply(50) 37 | val x14 = x3.update(50, 50) 38 | val x15 = x11.apply(5) 39 | val x16 = x15.apply(50) 40 | val x17 = x16 - x13 41 | val x18 = println(x17) 42 | x18 43 | } 44 | } 45 | /***************************************** 46 | End of Generated Code 47 | *******************************************/ 48 | -------------------------------------------------------------------------------- /test-out/epfl/test2-power.check: -------------------------------------------------------------------------------- 1 | ((x0+x1)*((x0+x1)*((x0+x1)*((x0+x1)*1.0)))) 2 | ((((x0+x1)*1.0)*((x0+x1)*1.0))*(((x0+x1)*1.0)*((x0+x1)*1.0))) 3 | TP(Sym(2),Plus(Sym(0),Sym(1))) 4 | TP(Sym(3),Times(Sym(2),Const(1.0))) 5 | TP(Sym(4),Times(Sym(2),Sym(3))) 6 | TP(Sym(5),Times(Sym(2),Sym(4))) 7 | TP(Sym(6),Times(Sym(2),Sym(5))) 8 | Sym(6) 9 | TP(Sym(2),Plus(Sym(0),Sym(1))) 10 | TP(Sym(3),Times(Sym(2),Sym(2))) 11 | TP(Sym(4),Times(Sym(2),Sym(3))) 12 | TP(Sym(5),Times(Sym(2),Sym(4))) 13 | Sym(5) 14 | /***************************************** 15 | Emitting Generated Code 16 | *******************************************/ 17 | class Power2 extends ((Double)=>(Double)) { 18 | def apply(x0:Double): Double = { 19 | val x1 = x0+x0 20 | val x2 = x1*x1 21 | val x3 = x1*x2 22 | val x4 = x1*x3 23 | x4 24 | } 25 | } 26 | /***************************************** 27 | End of Generated Code 28 | *******************************************/ 29 | TP(Sym(2),Plus(Sym(0),Sym(1))) 30 | TP(Sym(3),Times(Sym(2),Sym(2))) 31 | TP(Sym(4),Times(Sym(3),Sym(3))) 32 | Sym(4) 33 | /***************************************** 34 | Emitting Generated Code 35 | *******************************************/ 36 | class Power3 extends ((Double)=>(Double)) { 37 | def apply(x0:Double): Double = { 38 | val x1 = x0+x0 39 | val x2 = x1*x1 40 | val x3 = x2*x2 41 | x3 42 | } 43 | } 44 | /***************************************** 45 | End of Generated Code 46 | *******************************************/ 47 | /***************************************** 48 | Emitting Generated Code 49 | *******************************************/ 50 | class Power4 extends ((Double)=>(Double)) { 51 | def apply(x0:Double): Double = { 52 | val x1 = x0*x0 53 | val x2 = x0*x1 54 | val x3 = x0*x2 55 | x3 56 | } 57 | } 58 | /***************************************** 59 | End of Generated Code 60 | *******************************************/ 61 | compilation: ok 62 | 16.0 63 | -------------------------------------------------------------------------------- /test-out/epfl/test9-struct3.check: -------------------------------------------------------------------------------- 1 | wtableneg: List() 2 | partitions: List(TTP(List(Sym(4), Sym(5), Sym(13)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(2)))), SimpleLoop(Const(100),Sym(7),ArrayElem(Block(Sym(11))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayElem(Block(Sym(2))), ArrayElem(Block(Sym(11))))))) 3 | considering TP(Sym(9),ArrayIndex(Sym(5),Sym(7))) 4 | replace TP(Sym(9),ArrayIndex(Sym(5),Sym(7))) at 1 within TTP(List(Sym(4), Sym(5), Sym(13)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(2)))), SimpleLoop(Const(100),Sym(7),ArrayElem(Block(Sym(11))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayElem(Block(Sym(2))), ArrayElem(Block(Sym(11)))))) 5 | warning: mirroring of Sym(11)=DoubleMinus(Const(0.0),Sym(9)) type Double returned Sym(1) type Int (not a subtype) 6 | try once more ... 7 | wtableneg: List() 8 | partitions: List(TTP(List(Sym(4), Sym(17)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayElem(Block(Sym(1))))))) 9 | no changes, we're done 10 | super.focusExactScopeFat with result changed from List(Sym(16)) to List(Sym(20)) 11 | /***************************************** 12 | Emitting Generated Code 13 | *******************************************/ 14 | class Test extends ((Int)=>(Unit)) { 15 | def apply(x0:Int): Unit = { 16 | var x4 = new Array[Int](100) 17 | var x17 = new Array[Int](100) 18 | for (x1 <- 0 until 100) { 19 | x4(x1) = x1 20 | x17(x1) = x1 21 | } 22 | val x18 = new ArrayOfAnon189207751(x4,x17) 23 | val x19 = println(x18) 24 | val x15 = x19 25 | x15 26 | } 27 | } 28 | /***************************************** 29 | End of Generated Code 30 | *******************************************/ 31 | 32 | case class ArrayOfAnon189207751(re: Array[Int], im: Array[Double]) 33 | -------------------------------------------------------------------------------- /test-out/epfl/test9-struct2b.check: -------------------------------------------------------------------------------- 1 | wtableneg: List() 2 | partitions: List(TTP(List(Sym(10), Sym(11), Sym(4), Sym(5)),List(SimpleLoop(Const(100),Sym(7),ArrayElem(Block(Sym(8)))), SimpleLoop(Const(100),Sym(7),ArrayElem(Block(Sym(7)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(2))))),SimpleFatLoop(Const(100),Sym(7),List(ArrayElem(Block(Sym(8))), ArrayElem(Block(Sym(7))), ArrayElem(Block(Sym(1))), ArrayElem(Block(Sym(2))))))) 3 | try once more ... 4 | wtableneg: List() 5 | partitions: List(TTP(List(Sym(10), Sym(11)),List(SimpleLoop(Const(100),Sym(7),ArrayElem(Block(Sym(8)))), SimpleLoop(Const(100),Sym(7),ArrayElem(Block(Sym(7))))),SimpleFatLoop(Const(100),Sym(7),List(ArrayElem(Block(Sym(8))), ArrayElem(Block(Sym(7))))))) 6 | no changes, we're done 7 | super.focusExactScopeFat with result changed from List(Sym(37)) to List(Sym(48)) 8 | /***************************************** 9 | Emitting Generated Code 10 | *******************************************/ 11 | class Test extends ((Int)=>(Unit)) { 12 | def apply(x0:Int): Unit = { 13 | var x10 = new Array[Double](100) 14 | var x11 = new Array[Int](100) 15 | for (x7 <- 0 until 100) { 16 | val x8 = 0.0 - x7 17 | x10(x7) = x8 18 | x11(x7) = x7 19 | } 20 | var x13: Array[Double] = x10 21 | var x14: Array[Int] = x11 22 | val x16 = x0 > 7 23 | // TODO: use vars instead of tuples to return multiple values 24 | val (x26,x38,x39) = if (x16) { 25 | val x17 = println("foobar true") 26 | ((),x11,x10) 27 | } else { 28 | val x20 = x13 29 | val x21 = x14 30 | val x19 = println("foobar false") 31 | ((),x20,x21) 32 | } 33 | x13 = x11 34 | x14 = x10 35 | val x42 = x13 36 | val x43 = x14 37 | val x44 = new ArrayOfAnon189207751(x42,x43) 38 | val x45 = println(x44) 39 | val x46 = new ArrayOfAnon189207751(x38,x39) 40 | val x47 = println(x46) 41 | val x36 = x47 42 | x36 43 | } 44 | } 45 | /***************************************** 46 | End of Generated Code 47 | *******************************************/ 48 | 49 | case class ArrayOfAnon189207751(re: Array[Int], im: Array[Double]) 50 | -------------------------------------------------------------------------------- /test-out/epfl/test10-transform2.check: -------------------------------------------------------------------------------- 1 | -- full graph 2 | TP(Sym(1),VectorZeros(Const(100))) 3 | TP(Sym(2),VectorZeros(Const(50))) 4 | TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 5 | TP(Sym(4),Equal(Sym(0),Const(0))) 6 | TP(Sym(5),VectorLength(Sym(3))) 7 | TP(Sym(6),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 8 | TP(Sym(7),Reify(Sym(6),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(6)))) 9 | TP(Sym(8),Reflect(Print(Sym(5)),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 10 | TP(Sym(9),Reify(Sym(8),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(8)))) 11 | TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 12 | TP(Sym(11),Reify(Sym(10),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List(Sym(10)))) 13 | -- before transformation 14 | val x4 = x0 == 0 15 | val x10 = if (x4) { 16 | val x1 = VectorZeros(Const(100)) 17 | val x2 = VectorZeros(Const(50)) 18 | val x3 = VectorPlus(Sym(1),Sym(2)) 19 | val x5 = VectorLength(Sym(3)) 20 | val x6 = println(x5) 21 | x6 22 | } else { 23 | val x1 = VectorZeros(Const(100)) 24 | val x2 = VectorZeros(Const(50)) 25 | val x3 = VectorPlus(Sym(1),Sym(2)) 26 | val x5 = VectorLength(Sym(3)) 27 | val x8 = println(x5) 28 | x8 29 | } 30 | encountering if then else TP(Sym(10),Reflect(IfThenElse(Sym(4),Block(Sym(7)),Block(Sym(9))),Summary(true,true,false,false,false,false,List(),List(),List(),List()),List())) 31 | replacing TP(Sym(3),VectorPlus(Sym(1),Sym(2))) 32 | -- after transformation 33 | val x4 = x0 == 0 34 | val x18 = if (x4) { 35 | val x1 = VectorZeros(Const(100)) 36 | val x2 = VectorZeros(Const(50)) 37 | val x12 = VectorPlus(Sym(2),Sym(1)) 38 | val x13 = VectorLength(Sym(12)) 39 | val x14 = println(x13) 40 | x14 41 | } else { 42 | val x1 = VectorZeros(Const(100)) 43 | val x2 = VectorZeros(Const(50)) 44 | val x3 = VectorPlus(Sym(1),Sym(2)) 45 | val x5 = VectorLength(Sym(3)) 46 | val x16 = println(x5) 47 | x16 48 | } 49 | -- done 50 | -------------------------------------------------------------------------------- /test-src/epfl/test2-fft/TestSort.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test2 4 | 5 | import common._ 6 | import test1._ 7 | 8 | trait MergeSort { this: Relat => 9 | 10 | def splitOddEven[T](xs: List[T]): (List[T], List[T]) = (xs: @unchecked) match { 11 | case o :: e :: xt => 12 | val (os, es) = splitOddEven(xt) 13 | ((o :: os), (e :: es)) 14 | case Nil => (xs, xs) 15 | // cases? 16 | } 17 | 18 | def mergeOddEven[T](odd: List[T], even: List[T]): List[T] = ((odd, even): @unchecked) match { 19 | case (Nil, Nil) => 20 | Nil 21 | case ((o :: os), (e :: es)) => 22 | o :: (e :: mergeOddEven(os, es)) 23 | // cases? 24 | } 25 | 26 | def merge(xs: List[Rep[Double]]): List[Rep[Double]] = (xs: @unchecked) match { 27 | case o :: e :: Nil => 28 | min(o, e) :: max(o, e) :: Nil 29 | case _ => 30 | val (odd0, even0) = splitOddEven(xs) 31 | val (odd1, even1) = (merge(odd0), merge(even0)) 32 | val (odd2, even2) = odd1 zip even1 map { 33 | case (x, y) => 34 | (min(x,y), max(x,y)) 35 | } unzip; 36 | mergeOddEven(odd2, even2) 37 | } 38 | 39 | def sort(xs: List[Rep[Double]]): List[Rep[Double]] = xs match { 40 | case (x :: Nil) => 41 | xs 42 | case _ => 43 | val N = xs.length // should assert it's power of two 44 | 45 | val (left0, right0) = xs.splitAt(N/2) 46 | 47 | val (left1, right1) = (sort(left0), sort(right0)) 48 | 49 | merge(left1 ::: right1) 50 | } 51 | 52 | } 53 | 54 | 55 | class TestSort extends FileDiffSuite { 56 | 57 | val prefix = home + "test-out/epfl/test2-" 58 | 59 | def testSort = { 60 | withOutFile(prefix+"sort1") { 61 | val o = new MergeSort with RelatExpOpt with FlatResult 62 | import o._ 63 | 64 | val r = sort(List.tabulate(8)(_ => fresh)) 65 | println(globalDefs.mkString("\n")) 66 | println(r) 67 | 68 | val p = new ExportGraph { val IR: o.type = o } 69 | p.emitDepGraph(result(r), prefix+"sort1-dot", true) 70 | } 71 | assertFileEqualsCheck(prefix+"sort1") 72 | assertFileEqualsCheck(prefix+"sort1-dot") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test-src/epfl/test4-functions/TestAckermann.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test4 4 | 5 | import common._ 6 | //import internal.GraphVizExport 7 | import test1._ 8 | import test2._ 9 | import test3._ 10 | 11 | 12 | trait AckProg { this: LiftPrimitives with PrimitiveOps with Functions with Equal with IfThenElse => 13 | 14 | class LambdaOps[A:Typ,B:Typ](f: Rep[A=>B]) { 15 | def apply(x:Rep[A]): Rep[B] = doApply(f, x) 16 | } 17 | implicit def lam[A:Typ,B:Typ](f: Rep[A] => Rep[B]): Rep[A=>B] = doLambda(f) 18 | //implicit def toLambdaOps[A,B](f: Rep[A=>B]) = new LambdaOps(f) 19 | 20 | 21 | def ack(m: Double): Rep[Int=>Int] = lam { n => 22 | if (m == 0) n+1 else 23 | if (n == 0) ack(m-1)(1) else 24 | ack(m-1)(ack(m)(n-1)) 25 | } 26 | 27 | /* Example due to Neil Jones, via Oleg on LtU (http://lambda-the-ultimate.org/node/4039#comment-61431) 28 | 29 | ack(2,n) should specialize to: 30 | 31 | ack_2(n) = if n=0 then ack_1(1) else ack_1(ack_2(n-1)) 32 | ack_1(n) = if n=0 then ack_0(1) else ack_0(ack_1(n-1)) 33 | ack_0(n) = n+1 34 | 35 | this actually "just works" 36 | 37 | */ 38 | 39 | } 40 | 41 | 42 | 43 | class TestAck extends FileDiffSuite { 44 | 45 | val prefix = home + "test-out/epfl/test4-" 46 | 47 | def testAck1 = { 48 | withOutFile(prefix+"ack1") { 49 | object AckProgExp extends AckProg 50 | with EqualExp with IfThenElseExp with LiftPrimitives with PrimitiveOpsExpOpt 51 | with FunctionsExternalDef1 52 | import AckProgExp._ 53 | 54 | val f = (x:Rep[Int]) => ack(2)(x) 55 | //val r = ack(2)(fresh) 56 | //println(globalDefs.mkString("\n")) 57 | //println(r) 58 | //val p = new ExtractorsGraphViz with FunctionsGraphViz { val IR: AckProgExp.type = AckProgExp } 59 | //p.emitDepGraph(r, prefix+"ack1-dot") 60 | val p = new ScalaGenPrimitiveOps with ScalaGenEqual with 61 | ScalaGenIfThenElse with ScalaGenFunctionsExternal { val IR: AckProgExp.type = AckProgExp } 62 | p.emitSource(f, "Ack", new java.io.PrintWriter(System.out)) 63 | } 64 | assertFileEqualsCheck(prefix+"ack1") 65 | //assertFileEqualsCheck(prefix+"ack1-dot") 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/common/FractionalOps.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | import scala.reflect.SourceContext 6 | 7 | trait FractionalOps extends ImplicitOps { 8 | def infix_/[A,T](lhs: Rep[T], rhs: Rep[A])(implicit c: A => T, f: Fractional[T], mA: Typ[A], mT: Typ[T], pos: SourceContext) = fractional_divide(lhs,implicit_convert[A,T](rhs)) 9 | 10 | def fractional_divide[T:Fractional:Typ](lhs: Rep[T], rhs: Rep[T])(implicit pos: SourceContext): Rep[T] 11 | } 12 | 13 | trait FractionalOpsExp extends FractionalOps with ImplicitOpsExp with EffectExp { 14 | 15 | case class FractionalDivide[T](lhs: Exp[T], rhs: Exp[T])(implicit val f: Fractional[T], val mT: Typ[T]) extends Def[T] 16 | 17 | def fractional_divide[T:Fractional:Typ](lhs: Exp[T], rhs: Exp[T])(implicit pos: SourceContext) : Rep[T] = FractionalDivide(lhs, rhs) 18 | 19 | override def mirror[A:Typ](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { 20 | case e@FractionalDivide(a,b) => fractional_divide(f(a),f(b))(e.f.asInstanceOf[Fractional[A]],mtype(e.mT),pos) 21 | case Reflect(e@FractionalDivide(a,b), u, es) => reflectMirrored(Reflect(FractionalDivide(f(a),f(b))(e.f.asInstanceOf[Fractional[A]],mtype(e.mT)), mapOver(f,u), f(es)))(mtyp1[A], pos) 22 | case _ => super.mirror(e,f) 23 | }).asInstanceOf[Exp[A]] 24 | } 25 | 26 | trait ScalaGenFractionalOps extends ScalaGenBase { 27 | val IR: FractionalOpsExp 28 | import IR._ 29 | 30 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 31 | case FractionalDivide(a,b) => emitValDef(sym, src"$a / $b") 32 | case _ => super.emitNode(sym, rhs) 33 | } 34 | } 35 | 36 | trait CLikeGenFractionalOps extends CLikeGenBase { 37 | val IR: FractionalOpsExp 38 | import IR._ 39 | 40 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { 41 | rhs match { 42 | case FractionalDivide(a,b) => 43 | emitValDef(sym, src"$a / $b") 44 | case _ => super.emitNode(sym, rhs) 45 | } 46 | } 47 | } 48 | 49 | trait CudaGenFractionalOps extends CudaGenBase with CLikeGenFractionalOps 50 | trait OpenCLGenFractionalOps extends OpenCLGenBase with CLikeGenFractionalOps 51 | trait CGenFractionalOps extends CGenBase with CLikeGenFractionalOps 52 | -------------------------------------------------------------------------------- /src/common/SynchronizedArrayBufferOps.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | import scala.lms.internal.GenericNestedCodegen 6 | import collection.mutable.ArrayBuffer 7 | import scala.reflect.SourceContext 8 | 9 | trait SynchronizedArrayBufferOps extends ArrayBufferOps { 10 | 11 | /* 12 | object SynchronizedArrayBuffer { 13 | def apply[A:Typ](xs: Rep[A]*)(implicit pos: SourceContext) = arraybuffer_new(xs) 14 | } 15 | */ 16 | 17 | } 18 | 19 | trait SynchronizedArrayBufferOpsExp extends SynchronizedArrayBufferOps with ArrayBufferOpsExp { 20 | case class SyncArrayBufferNew[A:Typ](xs: Seq[Exp[A]]) extends Def[ArrayBuffer[A]] { 21 | def mA = typ[A] 22 | } 23 | 24 | // all array buffers are synchronized (nackward compat). TODO: separate constructor 25 | 26 | override def arraybuffer_new[A:Typ](xs: Seq[Exp[A]])(implicit pos: SourceContext) = reflectMutable(SyncArrayBufferNew(xs)) 27 | } 28 | 29 | trait BaseGenSynchronizedArrayBufferOps extends BaseGenArrayBufferOps { 30 | val IR: SynchronizedArrayBufferOpsExp 31 | import IR._ 32 | } 33 | 34 | trait ScalaGenSynchronizedArrayBufferOps extends BaseGenSynchronizedArrayBufferOps with ScalaGenArrayBufferOps { 35 | val IR: SynchronizedArrayBufferOpsExp 36 | import IR._ 37 | 38 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 39 | case a@SyncArrayBufferNew(xs) => emitValDef(sym, src"(new scala.collection.mutable.ArrayBuffer[${a.mA}] with scala.collection.mutable.SynchronizedBuffer[${a.mA}]) ++= List(${(xs map {quote}).mkString(",")})") 40 | case _ => super.emitNode(sym, rhs) 41 | } 42 | } 43 | 44 | trait CLikeGenSynchronizedArrayBufferOps extends BaseGenSynchronizedArrayBufferOps with CLikeGenArrayBufferOps { 45 | val IR: SynchronizedArrayBufferOpsExp 46 | import IR._ 47 | 48 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { 49 | rhs match { 50 | case _ => super.emitNode(sym, rhs) 51 | } 52 | } 53 | } 54 | 55 | trait CudaGenSynchronizedArrayBufferOps extends CudaGenEffect with CLikeGenSynchronizedArrayBufferOps 56 | trait OpenCLGenSynchronizedArrayBufferOps extends OpenCLGenEffect with CLikeGenSynchronizedArrayBufferOps 57 | trait CGenSynchronizedArrayBufferOps extends CGenEffect with CLikeGenSynchronizedArrayBufferOps 58 | 59 | -------------------------------------------------------------------------------- /src/common/ImplicitOps.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | import scala.reflect.SourceContext 6 | 7 | trait ImplicitOps extends Base { 8 | /** 9 | * Implicit conversion from Rep[X] to Rep[Y] 10 | * 11 | * As long as a conversion is in scope, it will be invoked in the generated scala code. 12 | * Code-gen for other platforms should implement the conversions. 13 | **/ 14 | def implicit_convert[X,Y](x: Rep[X])(implicit c: X => Y, mX: Typ[X], mY: Typ[Y], pos: SourceContext) : Rep[Y] // = x.asInstanceOf[Rep[Y] 15 | } 16 | 17 | trait ImplicitOpsExp extends ImplicitOps with BaseExp { 18 | case class ImplicitConvert[X,Y](x: Exp[X])(implicit val mX: Typ[X], val mY: Typ[Y]) extends Def[Y] 19 | 20 | def implicit_convert[X,Y](x: Exp[X])(implicit c: X => Y, mX: Typ[X], mY: Typ[Y], pos: SourceContext) : Rep[Y] = { 21 | if (mX == mY) x.asInstanceOf[Rep[Y]] else ImplicitConvert[X,Y](x) 22 | } 23 | 24 | override def mirror[A:Typ](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { 25 | case im@ImplicitConvert(x) => toAtom(ImplicitConvert(f(x))(im.mX,im.mY))(mtyp1[A],pos) 26 | case _ => super.mirror(e,f) 27 | }).asInstanceOf[Exp[A]] 28 | 29 | } 30 | 31 | trait ScalaGenImplicitOps extends ScalaGenBase { 32 | val IR: ImplicitOpsExp 33 | import IR._ 34 | 35 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 36 | // TODO: this valDef is redundant; we really just want the conversion to be a no-op in the generated code. 37 | // TODO: but we still need to link the defs together 38 | case ImplicitConvert(x) => emitValDef(sym, quote(x)) 39 | case _ => super.emitNode(sym, rhs) 40 | } 41 | } 42 | 43 | trait CLikeGenImplicitOps extends CLikeGenBase { 44 | val IR: ImplicitOpsExp 45 | import IR._ 46 | 47 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = { 48 | rhs match { 49 | case im@ImplicitConvert(x) => 50 | gen"${im.mY} $sym = (${im.mY})$x;" 51 | case _ => super.emitNode(sym, rhs) 52 | } 53 | } 54 | } 55 | 56 | trait CudaGenImplicitOps extends CudaGenBase with CLikeGenImplicitOps 57 | trait OpenCLGenImplicitOps extends OpenCLGenBase with CLikeGenImplicitOps 58 | trait CGenImplicitOps extends CGenBase with CLikeGenImplicitOps 59 | -------------------------------------------------------------------------------- /src/util/GraphUtil.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package util 3 | 4 | import java.util.{ArrayDeque, HashMap} 5 | 6 | 7 | object GraphUtil { 8 | 9 | class Ref[T](init: T) { 10 | var value: T = init 11 | } 12 | 13 | /* test cases 14 | 15 | stronglyConnectedComponents[String](List("A"), { case "A" => List("B") case "B" => List("C") case "C" => List("A","D") case "D" => Nil}) 16 | List(List(A, B, C), List(D)) 17 | 18 | stronglyConnectedComponents[String](List("A","B","C"), { case "A" => List("B") case "B" => List("C") case "C" => List("A","D") case "D" => Nil}) 19 | */ 20 | 21 | /** 22 | Returns the strongly connected components 23 | of the graph rooted at the first argument, 24 | whose edges are given by the function argument. 25 | 26 | The scc are returned in topological order. 27 | Tarjan's algorithm (linear). 28 | */ 29 | def stronglyConnectedComponents[T](start: List[T], succ: T=>List[T]): List[List[T]] = { 30 | 31 | val id: Ref[Int] = new Ref(0) 32 | val stack = new ArrayDeque[T] 33 | val mark = new HashMap[T,Int] 34 | 35 | val res = new Ref[List[List[T]]](Nil) 36 | for (node <- start) 37 | visit(node,succ,id,stack,mark,res) 38 | 39 | res.value 40 | } 41 | 42 | def visit[T](node: T, succ: T=>List[T], id: Ref[Int], stack: ArrayDeque[T], 43 | mark: HashMap[T,Int], res: Ref[List[List[T]]]): Int = { 44 | 45 | 46 | if (mark.containsKey(node)) 47 | mark.get(node) 48 | else { 49 | id.value = id.value + 1 50 | 51 | mark.put(node, id.value) 52 | stack.addFirst(node) 53 | // println("push " + node) 54 | 55 | var min: Int = id.value 56 | for (child <- succ(node)) { 57 | val m = visit(child, succ, id, stack, mark, res) 58 | 59 | if (m < min) 60 | min = m 61 | } 62 | 63 | if (min == mark.get(node)) { 64 | var scc: List[T] = Nil 65 | var loop: Boolean = true 66 | do { 67 | val element = stack.removeFirst() 68 | // println("appending " + element) 69 | scc ::= element 70 | mark.put(element, Integer.MAX_VALUE) 71 | loop = element != node 72 | } while (loop) 73 | res.value ::= scc 74 | } 75 | min 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/internal/AccModel.scala: -------------------------------------------------------------------------------- 1 | package scala.lms.internal 2 | 3 | trait AbstractHostTransfer { 4 | this: GenericCodegen => 5 | 6 | val IR: Expressions 7 | import IR._ 8 | 9 | def emitSend(tp: Typ[_], peer: Targets.Value): (String,String) 10 | def emitRecv(tp: Typ[_], peer: Targets.Value): (String,String) 11 | def emitSendView(tp: Typ[_], peer: Targets.Value): (String,String) 12 | def emitRecvView(tp: Typ[_], peer: Targets.Value): (String,String) 13 | def emitSendUpdate(tp: Typ[_], peer: Targets.Value): (String,String) 14 | def emitRecvUpdate(tp: Typ[_], peer: Targets.Value): (String,String) 15 | 16 | def isListType(tp: Typ[_]): Boolean = { 17 | tp.runtimeClass == classOf[List[_]] 18 | } 19 | } 20 | 21 | trait AbstractDeviceTransfer { 22 | this: GenericCodegen => 23 | 24 | val IR: Expressions 25 | import IR._ 26 | 27 | def emitSendSlave(tp: Typ[_]) : (String,String) 28 | def emitRecvSlave(tp: Typ[_]) : (String,String) 29 | //def emitSendViewSlave(tp: Typ[_]) : (String,String) 30 | //def emitRecvViewSlave(tp: Typ[_]) : (String,String) 31 | def emitSendUpdateSlave(tp: Typ[_]) : (String,String) 32 | def emitRecvUpdateSlave(tp: Typ[_]) : (String,String) 33 | 34 | //def allocOutput(newSym: Sym[_], sym: Sym[_], reset: Boolean = false) : Unit 35 | } 36 | 37 | object Targets extends Enumeration { 38 | 39 | //TODO: Get rid of JVM target, or make an hierarchy 40 | val JVM = Value("jvm") 41 | val Scala = Value("scala") 42 | val Cpp = Value("cpp") 43 | val Cuda = Value("cuda") 44 | val OpenCL = Value("opencl") 45 | 46 | def apply(s: String): Value = s.toLowerCase() match { 47 | case "jvm" => JVM 48 | case "scala" => Scala 49 | case "cpp" => Cpp 50 | case "cuda" => Cuda 51 | case "opencl" => OpenCL 52 | case _ => throw new IllegalArgumentException("unsupported target: " + s) 53 | } 54 | 55 | def getHostTarget(target: Value): Targets.Value = { 56 | target match { 57 | case Targets.Scala => Targets.Scala 58 | case Targets.Cpp => Targets.Cpp 59 | case Targets.Cuda => Targets.Cpp 60 | case Targets.OpenCL => Targets.Cpp 61 | case _ => throw new IllegalArgumentException("Cannot find a host target for target " + target) 62 | } 63 | } 64 | 65 | implicit def targettostring(target: Targets.Value): String = target.toString 66 | } 67 | -------------------------------------------------------------------------------- /src/common/ExceptionOps.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | import internal._ 6 | import scala.reflect.SourceContext 7 | 8 | trait ExceptionOps extends Variables { 9 | // TODO: support virtualization of try-catch-finally blocks 10 | // for now, we only allow fatal errors (the exception will never be caught in generated code) 11 | 12 | def fatal(m: Rep[String]) = throw_exception(m) 13 | 14 | def throw_exception(m: Rep[String]): Rep[Unit] 15 | } 16 | 17 | trait ExceptionOpsExp extends ExceptionOps with EffectExp with StringOpsExp { 18 | case class ThrowException(m: Rep[String]) extends Def[Unit] 19 | 20 | def throw_exception(m: Exp[String]) = reflectEffect(ThrowException(m), Global()) 21 | 22 | override def mirror[A:Typ](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { 23 | case Reflect(ThrowException(s), u, es) => reflectMirrored(Reflect(ThrowException(f(s)), mapOver(f,u), f(es)))(mtyp1[A], pos) 24 | case _ => super.mirror(e,f) 25 | }).asInstanceOf[Exp[A]] 26 | } 27 | 28 | trait ScalaGenExceptionOps extends ScalaGenBase { 29 | val IR: ExceptionOpsExp 30 | import IR._ 31 | 32 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 33 | case ThrowException(m) => emitValDef(sym, src"throw new Exception($m)") 34 | case _ => super.emitNode(sym, rhs) 35 | } 36 | } 37 | 38 | trait CLikeGenExceptionOps extends CLikeGenBase { 39 | val IR: ExceptionOpsExp 40 | import IR._ 41 | 42 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 43 | case ThrowException(m) => 44 | stream.println("printf(" + quote(m) + ".c_str());") 45 | stream.println("assert(false);") 46 | case _ => super.emitNode(sym, rhs) 47 | } 48 | } 49 | 50 | trait CGenExceptionOps extends CGenBase with CLikeGenExceptionOps 51 | trait CudaGenExceptionOps extends CudaGenBase with CLikeGenExceptionOps { 52 | val IR: ExceptionOpsExp 53 | import IR._ 54 | 55 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 56 | case ThrowException(m) => 57 | stream.println("printf(" + quote(m) + ");") 58 | stream.println("assert(false);") 59 | case _ => super.emitNode(sym, rhs) 60 | } 61 | } 62 | //OpenCL does not support printf within a kernel 63 | //trait OpenCLGenExceptionOps extends OpenCLGenBase with CLikeGenExceptionOps 64 | -------------------------------------------------------------------------------- /test-out/epfl/test13-unstage1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class staged$0(px4:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Unit, Int]]) extends ((Int)=>(Int)) { 5 | def apply(x0:Int): Int = { 6 | val x1 = x0 + 1 7 | val x2 = x0 * 2 8 | val x3 = x1 + x2 9 | val x4 = px4 // static data: 10 | val x5 = x4.apply(List(x3, x1, x2))// compile dynamic: fv = List(Sym(3), Sym(1), Sym(2)) 11 | val x6 = x5.apply(()) 12 | x6 13 | } 14 | } 15 | /***************************************** 16 | End of Generated Code 17 | *******************************************/ 18 | 19 | compilation: ok 20 | /***************************************** 21 | Emitting Generated Code 22 | *******************************************/ 23 | class staged$1(px1:Int,px2:Int) extends ((Unit)=>(Int)) { 24 | def apply(x4:Unit): Int = { 25 | val x1 = px1 // static data: 10 26 | val x2 = px2 // static data: 18 27 | val x5 = x1 + x2 28 | val x6 = 28 * x5 29 | x6 30 | } 31 | } 32 | /***************************************** 33 | End of Generated Code 34 | *******************************************/ 35 | 36 | compilation: ok 37 | 784 38 | /***************************************** 39 | Emitting Generated Code 40 | *******************************************/ 41 | class staged$2(px1:Int,px2:Int) extends ((Unit)=>(Int)) { 42 | def apply(x4:Unit): Int = { 43 | val x1 = px1 // static data: 4 44 | val x2 = px2 // static data: 6 45 | val x5 = x1 + x2 46 | val x6 = 10 * x5 47 | x6 48 | } 49 | } 50 | /***************************************** 51 | End of Generated Code 52 | *******************************************/ 53 | 54 | compilation: ok 55 | 100 56 | /***************************************** 57 | Emitting Generated Code 58 | *******************************************/ 59 | class staged$3(px1:Int,px2:Int) extends ((Unit)=>(Int)) { 60 | def apply(x4:Unit): Int = { 61 | val x1 = px1 // static data: 2 62 | val x2 = px2 // static data: 2 63 | val x5 = x1 + x2 64 | val x6 = 4 * x5 65 | x6 66 | } 67 | } 68 | /***************************************** 69 | End of Generated Code 70 | *******************************************/ 71 | 72 | compilation: ok 73 | 16 74 | -------------------------------------------------------------------------------- /test-out/epfl/test10-worklist3.check: -------------------------------------------------------------------------------- 1 | ### first 2 | register replacement for Sym(1) 3 | register replacement for Sym(2) 4 | discarding, already have a replacement for Sym(1) 5 | register replacement for Sym(5) 6 | --- code --- 7 | val x1 = VectorZeros(Const(100)) 8 | val x3 = x0 > 0 9 | val x4 = if (x3) { 10 | x1 11 | } else { 12 | val x2 = VectorZeros(Const(50)) 13 | x2 14 | } 15 | val x5 = VectorPlus(Sym(4),Sym(1)) 16 | val x6 = println(x5) 17 | 18 | ### next 19 | install replacement for Sym(1) 20 | install replacement for Sym(2) 21 | install replacement for Sym(5) 22 | toAtom transform FieldApply(Sym(4),length) List(Sym(4)) -> List(Sym(17)) 23 | toAtom transform VectorApply(Sym(4),Sym(18)) List(Sym(4), Sym(18)) -> List(Sym(17), Sym(18)) 24 | register replacement for Sym(19) 25 | discarding, already have a replacement for Sym(19) 26 | toAtom transform VectorApply(Sym(1),Sym(18)) List(Sym(1), Sym(18)) -> List(Sym(10), Sym(18)) 27 | register replacement for Sym(20) 28 | discarding, already have a replacement for Sym(20) 29 | --- code --- 30 | val x3 = x0 > 0 31 | val x9 = LoopArray(100) { x8 => 32 | 0.0 33 | } 34 | // TODO: use vars instead of tuples to return multiple values 35 | val (x16,x15) = if (x3) { 36 | (100,x9) 37 | } else { 38 | val x12 = LoopArray(50) { x11 => 39 | 0.0 40 | } 41 | (50,x12) 42 | } 43 | val x17 = new VectorDouble(x15,x16) 44 | val x10 = new VectorDouble(x9,100) 45 | val x22 = LoopArray(x16) { x18 => 46 | val x19 = VectorApply(Sym(17),Sym(18)) 47 | val x20 = VectorApply(Sym(10),Sym(18)) 48 | val x21 = x19 + x20 49 | x21 50 | } 51 | val x23 = new VectorDouble(x22,x16) 52 | val x24 = println(x23) 53 | 54 | ### next 55 | install replacement for Sym(19) 56 | toAtom transform ArrayIndex(Sym(15),Sym(18)) List(Sym(15), Sym(18)) -> List(Sym(30), Sym(33)) 57 | install replacement for Sym(20) 58 | toAtom transform ArrayIndex(Sym(9),Sym(18)) List(Sym(9), Sym(18)) -> List(Sym(27), Sym(33)) 59 | --- code --- 60 | val x3 = x0 > 0 61 | val x27 = LoopArray(100) { x26 => 62 | 0.0 63 | } 64 | // TODO: use vars instead of tuples to return multiple values 65 | val (x16,x30) = if (x3) { 66 | (100,x27) 67 | } else { 68 | val x29 = LoopArray(50) { x28 => 69 | 0.0 70 | } 71 | (50,x29) 72 | } 73 | val x37 = LoopArray(x16) { x33 => 74 | val x34 = x30.apply(x33) 75 | val x35 = x27.apply(x33) 76 | val x36 = x34 + x35 77 | x36 78 | } 79 | val x38 = new VectorDouble(x37,x16) 80 | val x39 = println(x38) 81 | -------------------------------------------------------------------------------- /test-src/epfl/test3-parsers/ExtractorsGraphViz.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test3 4 | 5 | import common._ 6 | import internal.GraphVizExport 7 | 8 | import test1._ 9 | import test2._ 10 | 11 | 12 | trait ExtractorsGraphViz extends GraphVizExport { 13 | val IR: MatchingExtractorsExp 14 | import IR._ 15 | 16 | override def emitNode(sym: Sym[Any], rhs: Def[Any])(implicit stream: java.io.PrintWriter) = rhs match { 17 | /* 18 | case Result(x) => 19 | super.emitNode(sym, rhs) 20 | stream.println("shape=point") 21 | */ 22 | case Test(x, y) => 23 | super.emitNode(sym, rhs) 24 | stream.println("color=red") 25 | case Deconstruct(x, y) => 26 | super.emitNode(sym, rhs) 27 | stream.println("color=red") 28 | // case OrElse(_) => 29 | // super.emitNode(sym, rhs) 30 | // stream.println("color=red") 31 | case _ => 32 | super.emitNode(sym, rhs) 33 | } 34 | 35 | override def emitDeps(sym: Sym[Any], rhs: Def[Any], deps: List[Sym[Any]])(implicit stream: java.io.PrintWriter) = rhs match { 36 | 37 | case Reify(x, effects) => 38 | super.emitDeps(sym, rhs, deps filterNot (effects.contains(_))) // TODO: use diff, but might have duplicates 39 | for (dep <- effects) { 40 | stream.println("\"" + dep + "\" -> \"" + sym + "\"" + " [color=red]") 41 | } 42 | /* 43 | case OrElse(alts) => 44 | val effects = alts flatMap { case Reify(p, es) => es } 45 | super.emitDeps(sym, rhs, deps filterNot (effects.contains(_))) // TODO: use diff, but might have duplicates 46 | for (dep <- effects) { 47 | stream.println("\"" + dep + "\" -> \"" + sym + "\"" + " [color=red]") 48 | } 49 | */ 50 | 51 | /* 52 | case Bind(x, effects) => 53 | super.emitDeps(sym, rhs, deps filterNot (_ == effects)) // TODO: use diff, but might have duplicates 54 | for (dep <- List(effects)) { 55 | stream.println("\"" + dep + "\" -> \"" + sym + "\"" + " [color=red]") 56 | } 57 | */ 58 | 59 | /* 60 | case AndAlso(x, effects) => 61 | super.emitDeps(sym, rhs, deps filterNot (effects.contains(_))) // TODO: use diff, but might have duplicates 62 | for (dep <- effects) { 63 | stream.println("\"" + dep + "\" -> \"" + sym + "\"" + " [color=red]") 64 | } 65 | */ 66 | 67 | case _ => 68 | super.emitDeps(sym, rhs, deps) 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /test-out/epfl/test13-stable1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class staged$0(px3:scala.Function1[scala.collection.immutable.List[Any], scala.Function1[Int, Int]],px5:scala.lms.epfl.test13.RCell[Int]) extends ((Int)=>(Int)) { 5 | def apply(x0:Int): Int = { 6 | val x1 = x0 + 1 7 | val x2 = x0 * 2 8 | val x3 = px3 // static data: 9 | val x4 = x3.apply(List(x1, x2))// compile dynamic: fv = List(Sym(1), Sym(2)) 10 | val x5 = px5 // static data: RCell(stable) 11 | val x6 = x5.value 12 | val x7 = x4(x6) 13 | x7 14 | } 15 | } 16 | /***************************************** 17 | End of Generated Code 18 | *******************************************/ 19 | 20 | compilation: ok 21 | /***************************************** 22 | Emitting Generated Code 23 | *******************************************/ 24 | class staged$1(px1:Int,px2:Int) extends ((Int)=>(Int)) { 25 | def apply(x3:Int): Int = { 26 | val x1 = px1 // static data: 10 27 | val x2 = px2 // static data: 18 28 | val x4 = x1 + x2 29 | val x5 = x3 * x4 30 | x5 31 | } 32 | } 33 | /***************************************** 34 | End of Generated Code 35 | *******************************************/ 36 | 37 | compilation: ok 38 | 28 39 | /***************************************** 40 | Emitting Generated Code 41 | *******************************************/ 42 | class staged$2(px1:Int,px2:Int) extends ((Int)=>(Int)) { 43 | def apply(x3:Int): Int = { 44 | val x1 = px1 // static data: 10 45 | val x2 = px2 // static data: 18 46 | val x4 = x1 + x2 47 | val x5 = x3 * x4 48 | x5 49 | } 50 | } 51 | /***************************************** 52 | End of Generated Code 53 | *******************************************/ 54 | 55 | compilation: ok 56 | 140 57 | /***************************************** 58 | Emitting Generated Code 59 | *******************************************/ 60 | class staged$3(px1:Int,px2:Int) extends ((Int)=>(Int)) { 61 | def apply(x3:Int): Int = { 62 | val x1 = px1 // static data: 10 63 | val x2 = px2 // static data: 18 64 | val x4 = x1 + x2 65 | val x5 = x3 * x4 66 | x5 67 | } 68 | } 69 | /***************************************** 70 | End of Generated Code 71 | *******************************************/ 72 | 73 | compilation: ok 74 | 56 75 | -------------------------------------------------------------------------------- /test-src/epfl/test3-parsers/Functions.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test3 4 | 5 | import common._ 6 | import test1._ 7 | import test2._ 8 | 9 | import scala.reflect.SourceContext 10 | 11 | 12 | 13 | trait FunctionsExp extends Functions with BaseExp { // shadow trait with same name in core package 14 | implicit def funTyp[A:Typ,B:Typ]: Typ[A => B] = { 15 | implicit val ManifestTyp(mA) = typ[A] 16 | implicit val ManifestTyp(mB) = typ[B] 17 | manifestTyp 18 | } 19 | implicit def fun2Typ[A1:Typ,A2:Typ,B:Typ]: Typ[(A1,A2)=>B] = { 20 | implicit val ManifestTyp(mA1) = typ[A1] 21 | implicit val ManifestTyp(mA2) = typ[A2] 22 | implicit val ManifestTyp(mB) = typ[B] 23 | manifestTyp 24 | } 25 | // FIXME: there might be a conflict since this pulls in internal.Effects which is different from test1.Effects 26 | case class Lambda[A:Typ,B:Typ](fun: Exp[A] => Exp[B]) extends Def[A => B] 27 | case class Lambda2[A1:Typ,A2:Typ,B:Typ](fun: (Exp[A1],Exp[A2]) => Exp[B]) extends Def[(A1,A2) => B] 28 | case class Apply[A:Typ,B:Typ](fun: Exp[A => B], arg: Exp[A]) extends Def[B] { 29 | def mA = typ[A] 30 | def mB = typ[B] 31 | } 32 | case class Apply2[A1:Typ,A2:Typ,B:Typ](fun: Exp[(A1,A2) => B], arg1: Exp[A1], arg2: Exp[A2]) extends Def[B] { 33 | def mA1 = typ[A1] 34 | def mA2 = typ[A2] 35 | def mB = typ[B] 36 | } 37 | 38 | def doLambda[A:Typ,B:Typ](fun: Exp[A] => Exp[B])(implicit pos: SourceContext): Exp[A => B] = Lambda(fun) 39 | def doLambda2[A1:Typ,A2:Typ,B:Typ](fun: (Exp[A1],Exp[A2]) => Exp[B])(implicit pos: SourceContext) : Exp[(A1,A2) => B] = Lambda2(fun) 40 | def doApply[A:Typ,B:Typ](fun: Exp[A => B], arg: Exp[A])(implicit pos: SourceContext): Exp[B] = Apply(fun, arg) 41 | def doApply2[A1:Typ,A2:Typ,B:Typ](fun: Exp[(A1,A2) => B], arg1: Exp[A1], arg2: Exp[A2])(implicit pos: SourceContext): Exp[B] = Apply2(fun, arg1, arg2) 42 | } 43 | 44 | trait FunctionsExpUnfoldAll extends FunctionsExp { 45 | 46 | override def doApply[A:Typ,B:Typ](fun: Exp[A => B], arg: Exp[A])(implicit pos: SourceContext): Exp[B] = fun match { 47 | case Def(Lambda(fun)) => fun(arg) 48 | case _ => super.doApply(fun, arg) 49 | } 50 | override def doApply2[A1:Typ,A2:Typ,B:Typ](fun: Exp[(A1,A2) => B], arg1: Exp[A1], arg2: Exp[A2])(implicit pos: SourceContext): Exp[B] = fun match { 51 | case Def(Lambda2(fun)) => fun(arg1, arg2) 52 | case _ => super.doApply2(fun, arg1, arg2) 53 | } 54 | 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/common/Unchecked.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | import internal._ 6 | import scala.reflect.SourceContext 7 | 8 | trait UncheckedOps extends Base { 9 | 10 | def unchecked[T:Typ](s: Any*): Rep[T] 11 | def uncheckedPure[T:Typ](s: Any*): Rep[T] 12 | 13 | implicit class richQuote(c: StringContext) { 14 | class QuoteOps(args: Thunk[Rep[Any]]*) { 15 | def as[T:Typ]: Rep[T] = { 16 | //reflect(c.s(args map (a => reify(a.eval())):_*)) 17 | def merge(a: List[Any], b: List[Any]): List[Any] = a match { 18 | case Nil => Nil 19 | case x::xs => x::merge(b,a) 20 | } 21 | unchecked[T](merge(c.parts.toList, args.toList.map(_.eval())):_*) 22 | } 23 | } 24 | def raw(args: Thunk[Rep[Any]]*) = new QuoteOps(args:_*) 25 | } 26 | 27 | // args: =>Code* is not allowed so we make thunks explicit 28 | case class Thunk[+A](eval: () => A) 29 | implicit def toThunk[A](x: =>A) = new Thunk(() => x) 30 | 31 | } 32 | 33 | trait UncheckedOpsExp extends EffectExp { 34 | 35 | // TODO: use reifyEffects 36 | 37 | case class Unchecked[T](s: List[Any]) extends Def[T] 38 | def unchecked[T:Typ](s: Any*): Rep[T] = reflectEffect[T](Unchecked(s.toList)) 39 | def uncheckedPure[T:Typ](s: Any*): Rep[T] = toAtom[T](Unchecked(s.toList)) 40 | 41 | override def mirror[A:Typ](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match { 42 | //case Reflect(ThrowException(s), u, es) => reflectMirrored(Reflect(ThrowException(f(s)), mapOver(f,u), f(es)))(mtyp1[A]) 43 | // TODO mirror Unchecked and Reflect(Unchecked) 44 | case _ => super.mirror(e,f) 45 | }).asInstanceOf[Exp[A]] 46 | } 47 | 48 | trait ScalaGenUncheckedOps extends ScalaGenBase { 49 | val IR: UncheckedOpsExp 50 | import IR._ 51 | 52 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 53 | case Unchecked(xs) => 54 | emitValDef(sym, xs map ((x:Any)=> x match { case x: Exp[_] => quote(x) case x => x.toString }) mkString "") 55 | case _ => super.emitNode(sym, rhs) 56 | } 57 | } 58 | 59 | trait CGenUncheckedOps extends CGenBase { 60 | val IR: UncheckedOpsExp 61 | import IR._ 62 | 63 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 64 | case Unchecked(xs) => 65 | emitValDef(sym, xs map ((x:Any)=> x match { case x: Exp[_] => quote(x) case x => x.toString }) mkString "") 66 | case _ => super.emitNode(sym, rhs) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test-src/epfl/test4-functions/TestPatMat.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test4 4 | 5 | import common._ 6 | import internal.GraphVizExport 7 | import test1._ 8 | import test2._ 9 | import test3._ 10 | 11 | 12 | trait Intf { 13 | type Rep[+T] 14 | type M[+T] = Rep[Maybe[T]] 15 | 16 | val __match: Matcher 17 | abstract class Matcher { 18 | // runs the matcher on the given input 19 | def runOrElse[T, U](in: Rep[T])(matcher: Rep[T] => M[U]): Rep[U] 20 | 21 | def zero: M[Nothing] 22 | def one[T](x: Rep[T]): M[T] 23 | def guard[T](cond: Rep[Boolean], then: => Rep[T]): M[T] 24 | def isSuccess[T, U](x: Rep[T])(f: Rep[T] => M[U]): Rep[Boolean] // used for isDefinedAt 25 | } 26 | 27 | abstract class Maybe[+A] { 28 | def flatMap[B](f: Rep[A] => M[B]): M[B] 29 | def orElse[B >: A](alternative: => M[B]): M[B] 30 | } 31 | 32 | implicit def proxyMaybe[A](m: M[A]): Maybe[A] 33 | implicit def repInt(x: Int): Rep[Int] 34 | implicit def repBoolean(x: Boolean): Rep[Boolean] 35 | implicit def repString(x: String): Rep[String] 36 | } 37 | 38 | trait Impl extends Intf { 39 | type Rep[+T] = String 40 | 41 | object __match extends Matcher { 42 | def runOrElse[T, U](in: Rep[T])(matcher: Rep[T] => M[U]): Rep[U] = 43 | ("runOrElse("+ in +", ?" + matcher("?") + ")") 44 | def zero: M[Nothing] = "zero" 45 | def one[T](x: Rep[T]): M[T] = "one("+x.toString+")" 46 | def guard[T](cond: Rep[Boolean], then: => Rep[T]): M[T] = 47 | "guard("+cond+","+then+")" 48 | def isSuccess[T, U](x: Rep[T])(f: Rep[T] => M[U]): Rep[Boolean] = 49 | ("isSuccess("+x+", ?" + f("?") + ")") 50 | } 51 | 52 | implicit def proxyMaybe[A](m: M[A]): Maybe[A] = new Maybe[A] { 53 | def flatMap[B](f: Rep[A] => M[B]): M[B] = m + ".flatMap(? =>"+ f("?") +")" 54 | def orElse[B >: A](alternative: => M[B]): M[B] = m + ".orElse("+ alternative +")" 55 | } 56 | 57 | def repInt(x: Int): Rep[Int] = x.toString 58 | def repBoolean(x: Boolean): Rep[Boolean] = x.toString 59 | def repString(x: String): Rep[String] = x 60 | } 61 | 62 | 63 | 64 | class TestPatMat extends FileDiffSuite { 65 | 66 | val prefix = home + "test-out/epfl/test4-" 67 | 68 | def testPatMat1 = { 69 | withOutFile(prefix+"patmat1") { 70 | trait Prog extends Intf { 71 | println("NOTE: doesn't work yet :-(") 72 | def test = repInt(7) match { case 5 => "foo" case _ => "bar" } 73 | println(test) 74 | } 75 | new Prog with Impl 76 | } 77 | assertFileEqualsCheck(prefix+"patmat1") 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /test-out/epfl/test7-fusion4.check: -------------------------------------------------------------------------------- 1 | fusion of List((Sym(2),Sym(10))) prevented by TP(Sym(4),ArrayIndex(Sym(2),Sym(3))) which is required by body of List(Sym(10)) 2 | wtableneg: List((Sym(2),Sym(10))) 3 | partitions: List(TTP(List(Sym(10)),List(SimpleLoop(Sym(7),Sym(8),ReduceElem(Block(Sym(9))))),SimpleFatLoop(Sym(7),Sym(8),List(ReduceElem(Block(Sym(9)))))), TTP(List(Sym(2), Sym(6)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(3),ArrayIfElem(Sym(5),Block(Sym(4))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayIfElem(Sym(5),Block(Sym(4))))))) 4 | considering TP(Sym(4),ArrayIndex(Sym(2),Sym(3))) 5 | replace TP(Sym(4),ArrayIndex(Sym(2),Sym(3))) at 0 within TTP(List(Sym(2), Sym(6)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Sym(1)))), SimpleLoop(Const(100),Sym(3),ArrayIfElem(Sym(5),Block(Sym(4))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Sym(1))), ArrayIfElem(Sym(5),Block(Sym(4)))))) 6 | considering TP(Sym(9),ArrayIndex(Sym(6),Sym(8))) 7 | try once more ... 8 | wtableneg: List() 9 | partitions: List(TTP(List(Sym(14), Sym(17)),List(SimpleLoop(Const(100),Sym(1),ArrayIfElem(Sym(13),Block(Sym(1)))), SimpleLoop(Sym(15),Sym(8),ReduceElem(Block(Sym(16))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayIfElem(Sym(13),Block(Sym(1))), ReduceElem(Block(Sym(16))))))) 10 | considering TP(Sym(16),ArrayIndex(Sym(14),Sym(8))) 11 | replace TP(Sym(16),ArrayIndex(Sym(14),Sym(8))) at 0 within TTP(List(Sym(14), Sym(17)),List(SimpleLoop(Const(100),Sym(1),ArrayIfElem(Sym(13),Block(Sym(1)))), SimpleLoop(Sym(15),Sym(8),ReduceElem(Block(Sym(16))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayIfElem(Sym(13),Block(Sym(1))), ReduceElem(Block(Sym(16)))))) 12 | try once more ... 13 | wtableneg: List() 14 | partitions: List(TTP(List(Sym(23)),List(SimpleLoop(Const(100),Sym(1),ReduceIfElem(Sym(13),Block(Sym(1))))),SimpleFatLoop(Const(100),Sym(1),List(ReduceIfElem(Sym(13),Block(Sym(1))))))) 15 | no changes, we're done 16 | super.focusExactScopeFat with result changed from List(Sym(12)) to List(Sym(25)) 17 | /***************************************** 18 | Emitting Generated Code 19 | *******************************************/ 20 | class Test extends ((Unit)=>(Unit)) { 21 | def apply(x0:Unit): Unit = { 22 | var x23: Int = 0 23 | for (x1 <- 0 until 100) { 24 | val x13 = x1 > 50 25 | if (x13) x23 += x1 26 | } 27 | val x24 = println(x23) 28 | val x11 = x24 29 | x11 30 | } 31 | } 32 | /***************************************** 33 | End of Generated Code 34 | *******************************************/ 35 | -------------------------------------------------------------------------------- /src/common/LivenessOpt.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package common 3 | 4 | import java.io.PrintWriter 5 | import scala.lms.internal.NestedBlockTraversal 6 | 7 | import scala.collection.mutable 8 | 9 | trait LivenessOpt extends NestedBlockTraversal { 10 | import IR._ 11 | 12 | def calculateLivenessTransform(used: mutable.HashSet[Sym[Any]], t: Stm): List[Stm] = t match { 13 | case TP(sym, Reify(x, u, es)) if used(sym) => 14 | used ++= syms(x) // ignore effect dependencies! 15 | used ++= u.mayWrite // writes to external data 16 | List(t) 17 | case TP(sym, rhs@Reflect(_, u, es)) if used(sym) || 18 | mayWrite(u, used.toList) || maySimple(u) => 19 | used ++= syms(rhs) 20 | List(t) 21 | /* case TP(sym, rhs) if used(sym) => 22 | used ++= syms(rhs) 23 | //printlog("** add used at " + t + ": " + syms(rhs)) 24 | List(t)*/ 25 | case e => 26 | if (e.lhs exists used) { 27 | used ++= syms(e.rhs) 28 | List(t) 29 | } else { 30 | printlog("dropping " + e) 31 | Nil 32 | } 33 | } 34 | 35 | 36 | override def focusBlock[A](result: Block[Any])(body: => A): A = { 37 | super.focusBlock(result) { 38 | 39 | printlog("gathering liveness info for block " + result) 40 | 41 | val used = new mutable.HashSet[Sym[Any]] 42 | used ++= syms(result) 43 | 44 | val newInnerScope = innerScope.reverse.flatMap(calculateLivenessTransform(used,_).reverse) 45 | 46 | innerScope = newInnerScope.reverse 47 | 48 | body 49 | } 50 | } 51 | 52 | } 53 | 54 | 55 | trait DefUseAnalysis extends NestedBlockTraversal { 56 | import IR._ 57 | 58 | var defUseMap: Map[Exp[Any], Set[Exp[Any]]] = _ 59 | 60 | override def focusBlock[A](result: Block[Any])(body: => A): A = { 61 | super.focusBlock(result) { 62 | val saveDefUseMap = defUseMap 63 | 64 | printlog("gathering def-use info for block " + result) 65 | 66 | var pairs = List[(Exp[Any],Exp[Any])]() 67 | 68 | for (TP(sym, rhs) <- innerScope) { 69 | for (use <- syms(rhs)) { 70 | pairs = (use, sym) :: pairs 71 | } 72 | } 73 | 74 | if (saveDefUseMap ne null) { 75 | defUseMap = pairs.groupBy(_._1).map(p => (p._1, p._2.map(_._2).toSet)) 76 | for ((k,vs) <- saveDefUseMap) { 77 | defUseMap += (k -> (saveDefUseMap(k) ++ defUseMap.getOrElse(k, Set()))) 78 | } 79 | } else 80 | defUseMap = pairs.groupBy(_._1).map(p => (p._1, p._2.map(_._2).toSet)) 81 | 82 | body 83 | } 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /test-out/epfl/test10-worklist1.check: -------------------------------------------------------------------------------- 1 | ### first 2 | register replacement for Sym(1) 3 | discarding, already have a replacement for Sym(1) 4 | register replacement for Sym(2) 5 | register replacement for Sym(3) 6 | --- code --- 7 | val x1 = VectorZeros(Const(100)) 8 | val x2 = VectorPlus(Sym(1),Sym(1)) 9 | val x3 = VectorPlus(Sym(1),Sym(2)) 10 | val x4 = println(x3) 11 | 12 | ### next 13 | install replacement for Sym(1) 14 | install replacement for Sym(2) 15 | toAtom transform FieldApply(Sym(1),length) List(Sym(1)) -> List(Sym(8)) 16 | toAtom transform VectorApply(Sym(1),Sym(9)) List(Sym(1), Sym(9)) -> List(Sym(8), Sym(9)) 17 | register replacement for Sym(10) 18 | discarding, already have a replacement for Sym(10) 19 | toAtom transform VectorApply(Sym(1),Sym(9)) List(Sym(1), Sym(9)) -> List(Sym(8), Sym(9)) 20 | discarding, already have a replacement for Sym(10) 21 | discarding, already have a replacement for Sym(10) 22 | install replacement for Sym(3) 23 | toAtom transform FieldApply(Sym(1),length) List(Sym(1)) -> List(Sym(8)) 24 | toAtom transform VectorApply(Sym(1),Sym(14)) List(Sym(1), Sym(14)) -> List(Sym(8), Sym(14)) 25 | register replacement for Sym(15) 26 | discarding, already have a replacement for Sym(15) 27 | toAtom transform VectorApply(Sym(2),Sym(14)) List(Sym(2), Sym(14)) -> List(Sym(13), Sym(14)) 28 | register replacement for Sym(16) 29 | discarding, already have a replacement for Sym(16) 30 | --- code --- 31 | val x7 = LoopArray(100) { x6 => 32 | 0.0 33 | } 34 | val x8 = new VectorDouble(x7,100) 35 | val x12 = LoopArray(100) { x9 => 36 | val x10 = VectorApply(Sym(8),Sym(9)) 37 | val x11 = x10 + x10 38 | x11 39 | } 40 | val x13 = new VectorDouble(x12,100) 41 | val x18 = LoopArray(100) { x14 => 42 | val x15 = VectorApply(Sym(8),Sym(14)) 43 | val x16 = VectorApply(Sym(13),Sym(14)) 44 | val x17 = x15 + x16 45 | x17 46 | } 47 | val x19 = new VectorDouble(x18,100) 48 | val x20 = println(x19) 49 | 50 | ### next 51 | install replacement for Sym(10) 52 | toAtom transform ArrayIndex(Sym(7),Sym(9)) List(Sym(7), Sym(9)) -> List(Sym(23), Sym(25)) 53 | install replacement for Sym(15) 54 | toAtom transform ArrayIndex(Sym(7),Sym(14)) List(Sym(7), Sym(14)) -> List(Sym(23), Sym(30)) 55 | install replacement for Sym(16) 56 | toAtom transform ArrayIndex(Sym(12),Sym(14)) List(Sym(12), Sym(14)) -> List(Sym(28), Sym(30)) 57 | --- code --- 58 | val x23 = LoopArray(100) { x22 => 59 | 0.0 60 | } 61 | val x28 = LoopArray(100) { x25 => 62 | val x26 = x23.apply(x25) 63 | val x27 = x26 + x26 64 | x27 65 | } 66 | val x34 = LoopArray(100) { x30 => 67 | val x31 = x23.apply(x30) 68 | val x32 = x28.apply(x30) 69 | val x33 = x31 + x32 70 | x33 71 | } 72 | val x35 = new VectorDouble(x34,100) 73 | val x36 = println(x35) 74 | -------------------------------------------------------------------------------- /test-out/epfl/test2-fft2-dot.check: -------------------------------------------------------------------------------- 1 | digraph G { 2 | rankdir=LR 3 | "Sym(8)" [ 4 | label="Sym(8) \n Plus(Sym(0),Sym(4))" 5 | shape=box 6 | ] 7 | "Sym(0)" -> "Sym(8)" 8 | "Sym(4)" -> "Sym(8)" 9 | "Sym(12)" [ 10 | label="Sym(12) \n Plus(Sym(2),Sym(6))" 11 | shape=box 12 | ] 13 | "Sym(2)" -> "Sym(12)" 14 | "Sym(6)" -> "Sym(12)" 15 | "Sym(16)" [ 16 | label="Sym(16) \n Plus(Sym(8),Sym(12))" 17 | shape=box 18 | ] 19 | "Sym(8)" -> "Sym(16)" 20 | "Sym(12)" -> "Sym(16)" 21 | "Sym(9)" [ 22 | label="Sym(9) \n Plus(Sym(1),Sym(5))" 23 | shape=box 24 | ] 25 | "Sym(1)" -> "Sym(9)" 26 | "Sym(5)" -> "Sym(9)" 27 | "Sym(13)" [ 28 | label="Sym(13) \n Plus(Sym(3),Sym(7))" 29 | shape=box 30 | ] 31 | "Sym(3)" -> "Sym(13)" 32 | "Sym(7)" -> "Sym(13)" 33 | "Sym(17)" [ 34 | label="Sym(17) \n Plus(Sym(9),Sym(13))" 35 | shape=box 36 | ] 37 | "Sym(9)" -> "Sym(17)" 38 | "Sym(13)" -> "Sym(17)" 39 | "Sym(18)" [ 40 | label="Sym(18) \n Minus(Sym(8),Sym(12))" 41 | shape=box 42 | ] 43 | "Sym(8)" -> "Sym(18)" 44 | "Sym(12)" -> "Sym(18)" 45 | "Sym(19)" [ 46 | label="Sym(19) \n Minus(Sym(9),Sym(13))" 47 | shape=box 48 | ] 49 | "Sym(9)" -> "Sym(19)" 50 | "Sym(13)" -> "Sym(19)" 51 | "Sym(10)" [ 52 | label="Sym(10) \n Minus(Sym(0),Sym(4))" 53 | shape=box 54 | ] 55 | "Sym(0)" -> "Sym(10)" 56 | "Sym(4)" -> "Sym(10)" 57 | "Sym(15)" [ 58 | label="Sym(15) \n Minus(Sym(3),Sym(7))" 59 | shape=box 60 | ] 61 | "Sym(3)" -> "Sym(15)" 62 | "Sym(7)" -> "Sym(15)" 63 | "Sym(22)" [ 64 | label="Sym(22) \n Plus(Sym(10),Sym(15))" 65 | shape=box 66 | ] 67 | "Sym(10)" -> "Sym(22)" 68 | "Sym(15)" -> "Sym(22)" 69 | "Sym(11)" [ 70 | label="Sym(11) \n Minus(Sym(1),Sym(5))" 71 | shape=box 72 | ] 73 | "Sym(1)" -> "Sym(11)" 74 | "Sym(5)" -> "Sym(11)" 75 | "Sym(14)" [ 76 | label="Sym(14) \n Minus(Sym(2),Sym(6))" 77 | shape=box 78 | ] 79 | "Sym(2)" -> "Sym(14)" 80 | "Sym(6)" -> "Sym(14)" 81 | "Sym(23)" [ 82 | label="Sym(23) \n Minus(Sym(11),Sym(14))" 83 | shape=box 84 | ] 85 | "Sym(11)" -> "Sym(23)" 86 | "Sym(14)" -> "Sym(23)" 87 | "Sym(24)" [ 88 | label="Sym(24) \n Minus(Sym(10),Sym(15))" 89 | shape=box 90 | ] 91 | "Sym(10)" -> "Sym(24)" 92 | "Sym(15)" -> "Sym(24)" 93 | "Sym(25)" [ 94 | label="Sym(25) \n Plus(Sym(11),Sym(14))" 95 | shape=box 96 | ] 97 | "Sym(11)" -> "Sym(25)" 98 | "Sym(14)" -> "Sym(25)" 99 | "Sym(26)" [ 100 | label="Sym(26) \n Result(List(Complex(Sym(16),Sym(17)), Complex(Sym(22),Sym(23)), Complex(Sym(18),Sym(19)), Complex(Sym(24),Sym(25))))" 101 | shape=box 102 | ] 103 | "Sym(16)" -> "Sym(26)" 104 | "Sym(17)" -> "Sym(26)" 105 | "Sym(22)" -> "Sym(26)" 106 | "Sym(23)" -> "Sym(26)" 107 | "Sym(18)" -> "Sym(26)" 108 | "Sym(19)" -> "Sym(26)" 109 | "Sym(24)" -> "Sym(26)" 110 | "Sym(25)" -> "Sym(26)" 111 | } 112 | -------------------------------------------------------------------------------- /test-src/epfl/test12-collections/TestList.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test12 4 | 5 | import common._ 6 | import java.io.PrintWriter 7 | 8 | class TestList extends FileDiffSuite { 9 | 10 | trait MapFlatMapAndFilter { this: ListOps with NumericOps with PrimitiveOps with OrderingOps => 11 | def test(xs: Rep[List[Int]]): Rep[List[Int]] = { 12 | for { 13 | x <- xs 14 | y <- List(unit(1), unit(2), unit(3)) 15 | if y < unit(3) 16 | } yield x * y 17 | } 18 | } 19 | 20 | trait Concat { this: ListOps => 21 | def test(xs: Rep[List[Int]]): Rep[List[Int]] = 22 | xs ++ List(unit(1), unit(2), unit(3)) 23 | 24 | def emptyLeft(xs: Rep[List[Int]]): Rep[List[Int]] = 25 | List[Int]() ++ xs // VIRT 2.11: need type annotation 26 | 27 | def emptyRight(xs: Rep[List[Int]]): Rep[List[Int]] = 28 | xs ++ List[Int]() 29 | } 30 | 31 | trait MkString { this: ListOps => 32 | def test(xs: Rep[List[Int]]): Rep[String] = 33 | xs.mkString 34 | } 35 | 36 | val prefix = home + "test-out/epfl/test12-" 37 | 38 | def testMapFlatMapAndFilter() { 39 | withOutFile(prefix+"map-flatmap-filter") { 40 | val prog = new MapFlatMapAndFilter with ListOpsExp with SeqOpsExp with ArrayOpsExp with NumericOpsExp with PrimitiveOpsExp with OrderingOpsExp 41 | val codegen = new ScalaGenEffect with ScalaGenListOps with ScalaGenNumericOps with ScalaGenPrimitiveOps with ScalaGenOrderingOps { val IR: prog.type = prog } 42 | import prog.{intTyp,unitTyp,listTyp} 43 | codegen.emitSource(prog.test, "MapFlatMapAndFilter", new PrintWriter(System.out)) 44 | } 45 | assertFileEqualsCheck(prefix+"map-flatmap-filter") 46 | } 47 | 48 | def testConcat() { 49 | withOutFile(prefix+"concat") { 50 | val prog = new Concat with ListOpsExpOpt with SeqOpsExp with ArrayOpsExp with PrimitiveOpsExp 51 | val codegen = new ScalaGenEffect with ScalaGenListOps { val IR: prog.type = prog } 52 | import prog.{intTyp,unitTyp,listTyp} 53 | codegen.emitSource(prog.test, "Concat", new PrintWriter(System.out)) 54 | codegen.emitSource(prog.emptyLeft, "ConcatEmptyLeft", new PrintWriter(System.out)) 55 | codegen.emitSource(prog.emptyRight, "ConcatEmptyRight", new PrintWriter(System.out)) 56 | } 57 | assertFileEqualsCheck(prefix+"concat") 58 | } 59 | 60 | def testMkString() { 61 | withOutFile(prefix+"mkstring") { 62 | val prog = new MkString with ListOpsExp with SeqOpsExp with PrimitiveOpsExp 63 | val codegen = new ScalaGenEffect with ScalaGenListOps { val IR: prog.type = prog } 64 | import prog.{intTyp,unitTyp,listTyp,stringTyp} 65 | codegen.emitSource(prog.test, "MkString", new PrintWriter(System.out)) 66 | } 67 | assertFileEqualsCheck(prefix+"mkstring") 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /test-out/epfl/test4-matchernew1.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { 5 | def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { 6 | var x10 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 7 | var x1 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 8 | var x17 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 9 | var x4 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 10 | var x13 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 11 | var x7 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 12 | var x11 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 13 | x1 = {x2: (Char) => 14 | val x3 = x2 == 'A' 15 | val x18 = if (x3) { 16 | x17 17 | } else { 18 | x10 19 | } 20 | x18 21 | } 22 | x10 = scala.lms.epfl.test4.Automaton(List(),x1) 23 | x11 = x10.copy(out = "found"::x10.out) 24 | x7 = {x8: (Char) => 25 | val x9 = x8 == 'B' 26 | val x15 = if (x9) { 27 | x11 28 | } else { 29 | val x12 = x8 == 'A' 30 | val x14 = if (x12) { 31 | x13 32 | } else { 33 | x10 34 | } 35 | x14 36 | } 37 | x15 38 | } 39 | x13 = scala.lms.epfl.test4.Automaton(List(),x7) 40 | x4 = {x5: (Char) => 41 | val x6 = x5 == 'A' 42 | val x16 = if (x6) { 43 | x13 44 | } else { 45 | x10 46 | } 47 | x16 48 | } 49 | x17 = scala.lms.epfl.test4.Automaton(List(),x4) 50 | x10 51 | } 52 | } 53 | /***************************************** 54 | End of Generated Code 55 | *******************************************/ 56 | compilation: ok 57 | idx: 0 58 | out: List() 59 | char: X 60 | idx: 1 61 | out: List() 62 | char: A 63 | idx: 2 64 | out: List() 65 | char: B 66 | idx: 3 67 | out: List() 68 | char: Z 69 | idx: 4 70 | out: List() 71 | char: A 72 | idx: 5 73 | out: List() 74 | char: A 75 | idx: 6 76 | out: List() 77 | char: B 78 | idx: 7 79 | out: List(found) 80 | char: W 81 | idx: 8 82 | out: List() 83 | char: A 84 | idx: 9 85 | out: List() 86 | char: A 87 | idx: 10 88 | out: List() 89 | char: A 90 | idx: 11 91 | out: List() 92 | char: A 93 | idx: 12 94 | out: List() 95 | char: B 96 | idx: 13 97 | out: List(found) 98 | char: Q 99 | idx: 14 100 | out: List() 101 | -------------------------------------------------------------------------------- /test-out/epfl/test4-matchernew1b.check: -------------------------------------------------------------------------------- 1 | /***************************************** 2 | Emitting Generated Code 3 | *******************************************/ 4 | class Match extends ((Unit)=>(scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]])) { 5 | def apply(x0:Unit): scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]] = { 6 | var x12 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 7 | var x1 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 8 | var x17 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 9 | var x4 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 10 | var x10 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 11 | var x7 = null.asInstanceOf[scala.Function1[Char, scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]]] 12 | var x13 = null.asInstanceOf[scala.lms.epfl.test4.Automaton[Char, scala.collection.immutable.List[Any]]] 13 | x1 = {x2: (Char) => 14 | val x3 = x2 == 'A' 15 | val x18 = if (x3) { 16 | x17 17 | } else { 18 | x12 19 | } 20 | x18 21 | } 22 | x12 = scala.lms.epfl.test4.Automaton(List(),x1) 23 | x13 = x12.copy(out = "found"::x12.out) 24 | x7 = {x8: (Char) => 25 | val x9 = x8 == 'A' 26 | val x15 = if (x9) { 27 | x10 28 | } else { 29 | val x11 = x8 == 'B' 30 | val x14 = if (x11) { 31 | x13 32 | } else { 33 | x12 34 | } 35 | x14 36 | } 37 | x15 38 | } 39 | x10 = scala.lms.epfl.test4.Automaton(List(),x7) 40 | x4 = {x5: (Char) => 41 | val x6 = x5 == 'A' 42 | val x16 = if (x6) { 43 | x10 44 | } else { 45 | x12 46 | } 47 | x16 48 | } 49 | x17 = scala.lms.epfl.test4.Automaton(List(),x4) 50 | x12 51 | } 52 | } 53 | /***************************************** 54 | End of Generated Code 55 | *******************************************/ 56 | compilation: ok 57 | idx: 0 58 | out: List() 59 | char: X 60 | idx: 1 61 | out: List() 62 | char: A 63 | idx: 2 64 | out: List() 65 | char: B 66 | idx: 3 67 | out: List() 68 | char: Z 69 | idx: 4 70 | out: List() 71 | char: A 72 | idx: 5 73 | out: List() 74 | char: A 75 | idx: 6 76 | out: List() 77 | char: B 78 | idx: 7 79 | out: List(found) 80 | char: W 81 | idx: 8 82 | out: List() 83 | char: A 84 | idx: 9 85 | out: List() 86 | char: A 87 | idx: 10 88 | out: List() 89 | char: A 90 | idx: 11 91 | out: List() 92 | char: A 93 | idx: 12 94 | out: List() 95 | char: B 96 | idx: 13 97 | out: List(found) 98 | char: Q 99 | idx: 14 100 | out: List() 101 | -------------------------------------------------------------------------------- /test-src/epfl/test5-js/JSCompile.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test5 4 | 5 | import common._ 6 | import internal._ 7 | import test1._ 8 | 9 | import java.io.PrintWriter 10 | 11 | trait JSCodegen extends GenericCodegen { 12 | import IR._ 13 | 14 | def emitHTMLPage[B](f: () => Exp[B], stream: PrintWriter)(implicit mB: Typ[B]): Unit = { 15 | stream.println("Scala2JS") 23 | stream.println("") 24 | stream.flush 25 | } 26 | 27 | def emitSource[A : Typ](args: List[Sym[_]], body: Block[A], methName: String, out: PrintWriter) = { 28 | withStream(out) { 29 | stream.println("function "+methName+"("+args.map(quote).mkString(", ")+") {") 30 | 31 | emitBlock(body) 32 | stream.println("return "+quote(getBlockResult(body))) 33 | 34 | stream.println("}") 35 | } 36 | Nil 37 | } 38 | def emitValDef(sym: Sym[Any], rhs: String): Unit = { 39 | stream.println("var " + quote(sym) + " = " + rhs) 40 | } 41 | } 42 | 43 | trait JSNestedCodegen extends GenericNestedCodegen with JSCodegen { 44 | import IR._ 45 | 46 | } 47 | 48 | trait JSGenBase extends JSCodegen { 49 | val IR: BaseExp 50 | } 51 | 52 | trait JSGenEffect extends JSNestedCodegen with JSGenBase { 53 | val IR: EffectExp 54 | } 55 | 56 | 57 | trait JSGenIfThenElse extends BaseGenIfThenElse with JSGenEffect { // it's more or less generic... 58 | val IR: IfThenElseExp 59 | import IR._ 60 | 61 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 62 | case IfThenElse(c,a,b) => 63 | stream.println("var " + quote(sym)) 64 | stream.println("if (" + quote(c) + ") {") 65 | emitBlock(a) 66 | stream.println(quote(sym) + "=" + quote(getBlockResult(a))) 67 | stream.println("} else {") 68 | emitBlock(b) 69 | stream.println(quote(sym) + "=" + quote(getBlockResult(b))) 70 | stream.println("}") 71 | case _ => super.emitNode(sym, rhs) 72 | } 73 | } 74 | 75 | trait JSGenPrimitiveOps extends JSGenBase { // TODO: define a generic one 76 | val IR: PrimitiveOpsExp 77 | import IR._ 78 | 79 | override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match { 80 | case DoublePlus(a,b) => emitValDef(sym, "" + quote(a) + "+" + quote(b)) 81 | case DoubleMinus(a,b) => emitValDef(sym, "" + quote(a) + "-" + quote(b)) 82 | case DoubleTimes(a,b) => emitValDef(sym, "" + quote(a) + "*" + quote(b)) 83 | case DoubleDivide(a,b) => emitValDef(sym, "" + quote(a) + "/" + quote(b)) 84 | case _ => super.emitNode(sym, rhs) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /test-out/epfl/test7-fusion21.check: -------------------------------------------------------------------------------- 1 | fusion of List((Sym(2),Sym(7))) prevented by TP(Sym(6),ArrayIndex(Sym(2),Const(0))) which is required by body of List(Sym(7)) 2 | fusion of List((Sym(4),Sym(10))) prevented by TP(Sym(9),ArrayIndex(Sym(4),Const(0))) which is required by body of List(Sym(10)) 3 | wtableneg: List((Sym(2),Sym(7)), (Sym(4),Sym(10))) 4 | partitions: List(TTP(List(Sym(10)),List(SimpleLoop(Const(100),Sym(8),ArrayElem(Block(Sym(9))))),SimpleFatLoop(Const(100),Sym(8),List(ArrayElem(Block(Sym(9)))))), TTP(List(Sym(4), Sym(7)),List(SimpleLoop(Const(50),Sym(3),ArrayElem(Block(Const(3.0)))), SimpleLoop(Const(50),Sym(5),ArrayElem(Block(Sym(6))))),SimpleFatLoop(Const(50),Sym(3),List(ArrayElem(Block(Const(3.0))), ArrayElem(Block(Sym(6)))))), TTP(List(Sym(2)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Const(9.0))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Const(9.0))))))) 5 | considering TP(Sym(6),ArrayIndex(Sym(2),Const(0))) 6 | considering TP(Sym(9),ArrayIndex(Sym(4),Const(0))) 7 | try once more ... 8 | fusion of List((Sym(2),Sym(4)), (Sym(2),Sym(7))) prevented by TP(Sym(6),ArrayIndex(Sym(2),Const(0))) which is required by body of List(Sym(4), Sym(7)) 9 | fusion of List((Sym(2),Sym(10))) prevented by TP(Sym(6),ArrayIndex(Sym(2),Const(0))) which is required by body of List(Sym(10)) 10 | fusion of List((Sym(4),Sym(10))) prevented by TP(Sym(9),ArrayIndex(Sym(4),Const(0))) which is required by body of List(Sym(10)) 11 | wtableneg: List((Sym(2),Sym(4)), (Sym(2),Sym(7)), (Sym(2),Sym(10)), (Sym(4),Sym(10))) 12 | partitions: List(TTP(List(Sym(10)),List(SimpleLoop(Const(100),Sym(8),ArrayElem(Block(Sym(9))))),SimpleFatLoop(Const(100),Sym(8),List(ArrayElem(Block(Sym(9)))))), TTP(List(Sym(4), Sym(7)),List(SimpleLoop(Const(50),Sym(3),ArrayElem(Block(Const(3.0)))), SimpleLoop(Const(50),Sym(5),ArrayElem(Block(Sym(6))))),SimpleFatLoop(Const(50),Sym(3),List(ArrayElem(Block(Const(3.0))), ArrayElem(Block(Sym(6)))))), TTP(List(Sym(2)),List(SimpleLoop(Const(100),Sym(1),ArrayElem(Block(Const(9.0))))),SimpleFatLoop(Const(100),Sym(1),List(ArrayElem(Block(Const(9.0))))))) 13 | no changes, we're done 14 | /***************************************** 15 | Emitting Generated Code 16 | *******************************************/ 17 | class Test extends ((Unit)=>(Unit)) { 18 | def apply(x0:Unit): Unit = { 19 | var x2 = new Array[Double](100) 20 | for (x1 <- 0 until 100) { 21 | x2(x1) = 9.0 22 | } 23 | val x6 = x2.apply(0) 24 | var x4 = new Array[Double](50) 25 | var x7 = new Array[Double](50) 26 | for (x3 <- 0 until 50) { 27 | x4(x3) = 3.0 28 | x7(x3) = x6 29 | } 30 | val x11 = println(x4) 31 | val x12 = println(x7) 32 | val x13 = println(x2) 33 | val x9 = x4.apply(0) 34 | var x10 = new Array[Double](100) 35 | for (x8 <- 0 until 100) { 36 | x10(x8) = x9 37 | } 38 | val x14 = println(x10) 39 | x14 40 | } 41 | } 42 | /***************************************** 43 | End of Generated Code 44 | *******************************************/ 45 | -------------------------------------------------------------------------------- /test-src/epfl/test3-parsers/Parsers.scala: -------------------------------------------------------------------------------- 1 | package scala.lms 2 | package epfl 3 | package test3 4 | 5 | trait Parsers { this: Matching with Extractors => 6 | 7 | type Elem 8 | type Input = List[Elem] 9 | // Don't declare as implicit val in children, it gives problems with initialization order! 10 | implicit val mE: Typ[Elem] 11 | 12 | abstract class Parser { 13 | def apply(in: Rep[Input]): Rep[ParseResult] 14 | } 15 | 16 | abstract class ParseResult extends Product with Serializable // instances are case classes 17 | 18 | case class Success(rest: Input) extends ParseResult 19 | case class Failure() extends ParseResult 20 | 21 | implicit def inputTyp: Typ[Input] 22 | implicit def resultTyp: Typ[ParseResult] 23 | implicit def successTyp: Typ[Success] 24 | implicit def failureTyp: Typ[Failure] 25 | 26 | implicit def listTyp[T:Typ]: Typ[List[T]] 27 | implicit def consTyp[T:Typ]: Typ[::[T]] 28 | 29 | object SuccessR { 30 | def apply(x: Rep[Input]): Rep[Success] = construct(classOf[Success], Success.apply, x) 31 | def unapply(x: Rep[Success]): Option[Rep[Input]] = deconstruct(classOf[Success], Success.unapply, x) 32 | } 33 | 34 | object FailureR { 35 | def apply(): Rep[Failure] = construct(classOf[Failure], (_: Unit) => Failure.apply(), unit(())) 36 | def unapply(x: Rep[Failure]): Boolean = deconstruct(classOf[Failure], { x:Failure => if (Failure.unapply(x)) Some(()) else None }, x).isDefined 37 | } // TODO: not so nice... 38 | 39 | object :!: { 40 | def apply[A:Typ](x: Rep[A], xs: Rep[List[A]]) = construct(classOf[::[A]], (::.apply[A] _).tupled, tuple(x, xs)) 41 | // def unapply[A](x: Rep[::[A]]) = deconstruct2(classOf[::[A]], ::.unapply[A], x) // doesn't work: hd is private in :: ! 42 | def unapply[A:Typ](x: Rep[List[A]]): Option[(Rep[A], Rep[List[A]])] = 43 | deconstruct2(classOf[::[A]].asInstanceOf[Class[List[A]]], (x: List[A]) => Some(x.head, x.tail), x) 44 | } 45 | 46 | 47 | def acceptElem(elem: Elem) = { 48 | new Parser { 49 | def apply(in: Rep[Input]) = in switch { 50 | case ((x: Rep[Elem]) :!: (rest: Rep[Input])) if x guard elem => // need types to make it compile 51 | SuccessR(rest) 52 | } orElse { 53 | case _ => FailureR() 54 | } end 55 | } 56 | } 57 | 58 | def seq(a: Parser, b: Parser) = { 59 | new Parser { 60 | def apply(in: Rep[Input]) = a(in) switch { 61 | case SuccessR(rest) => b(rest) 62 | } orElse { 63 | case _ => FailureR() 64 | } end 65 | } 66 | } 67 | 68 | def alt(a: Parser, b: Parser) = { 69 | new Parser { 70 | def apply(in: Rep[Input]) = a(in) switch { 71 | case s @ SuccessR(rest) => s 72 | } orElse { 73 | case _ => b(in) 74 | } end 75 | } 76 | } 77 | 78 | // def acceptElem(elem: Elem) = acceptIf(_ == elem) 79 | def acceptElems(elems: List[Elem]) = { 80 | elems.map(acceptElem).reduceLeft(seq) 81 | } 82 | 83 | } --------------------------------------------------------------------------------