Skip to content

Commit 435e759

Browse files
author
Alexey Romanov
committed
Add the optimized version of CastingOpsExp
1 parent aca267c commit 435e759

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/common/CastingOps.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ trait CastingOpsExp extends CastingOps with BaseExp with EffectExp {
3737
}).asInstanceOf[Exp[A]]
3838
}
3939

40+
trait CastingOpsExpOpt extends CastingOpsExp {
41+
this: ImplicitOps =>
42+
43+
override def rep_isinstanceof[A,B](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) =
44+
if (mA <:< mB) unit(true) else super.rep_isinstanceof(lhs, mA, mB)
45+
override def rep_asinstanceof[A,B:Manifest](lhs: Exp[A], mA: Manifest[A], mB: Manifest[B])(implicit pos: SourceContext) : Exp[B] =
46+
if (mA == mB) lhs.asInstanceOf[Exp[B]] else super.rep_asinstanceof(lhs, mA, mB)
47+
}
48+
4049
trait ScalaGenCastingOps extends ScalaGenBase {
4150
val IR: CastingOpsExp
4251
import IR._

test-src/epfl/test13-dynamic-jit/TestInterpret.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class TestInterpret extends FileDiffSuite {
523523
trait Impl extends DSL with VectorExp with ArithExp with OrderingOpsExpOpt with BooleanOpsExp
524524
with EqualExpOpt with IfThenElseFatExp with LoopsFatExp with WhileExp
525525
with RangeOpsExp with PrintExp with FatExpressions with CompileScala
526-
with NumericOpsExp with PrimitiveOpsExp with ArrayOpsExp with HashMapOpsExp with CastingOpsExp with StaticDataExp
526+
with NumericOpsExp with PrimitiveOpsExp with ArrayOpsExp with HashMapOpsExp with CastingOpsExpOpt with StaticDataExp
527527
with InterpretStagedExp { self =>
528528
override val verbosity = 1
529529
dumpGeneratedCode = true

test-src/epfl/test13-dynamic-jit/TestStable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class TestStable extends FileDiffSuite {
208208
trait Impl extends DSL with VectorExp with ArithExp with OrderingOpsExpOpt with BooleanOpsExp
209209
with EqualExpOpt with IfThenElseFatExp with LoopsFatExp with WhileExp
210210
with RangeOpsExp with PrintExp with FatExpressions with CompileScala
211-
with PrimitiveOpsExp with ArrayOpsExp with HashMapOpsExp with CastingOpsExp with StaticDataExp
211+
with PrimitiveOpsExp with ArrayOpsExp with HashMapOpsExp with CastingOpsExpOpt with StaticDataExp
212212
with StableVarsExp { self =>
213213
override val verbosity = 1
214214
dumpGeneratedCode = true

0 commit comments

Comments
 (0)