Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite1a3657

Browse files
committed
experiments with dynamic recompilation
Introduce `stable` vars. Programs are compiled assuming that stablevars are mostly constant. Programs are specialized to the currentvalues but every read is replaced by a guard that will triggerrecompilation of the program if the var has changed.The tricky part is recompiling the program on the fly, becausewhen we detect a var change, we are already in the middle ofexecuting compiled code. This is solved by storing the uncompiledcontinuation as static constant. Additional care must be taken todeal with the free vars of the continuation, which may pointto local vars of the running compiled code. We thus generateinstructions in the original code to pass these vars tothe dynamic compile call.There are considerable degrees of freedom regarding when tocompile, what compiled code to store/throw away etc. The testcases explore just one design.
1 parent09eb856 commite1a3657

File tree

3 files changed

+485
-0
lines changed

3 files changed

+485
-0
lines changed

‎test-out/epfl/test13-stable1.check‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
free vars: List(Sym(1), Sym(2))
2+
/*****************************************
3+
Emitting Generated Code
4+
*******************************************/
5+
class staged$0(px3:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px4:Object,px6:scala.virtualization.lms.epfl.test13.SCell[Int]) extends ((Int)=>(Int)) {
6+
def apply(x0:Int): Int = {
7+
val x1 = x0 + 1
8+
val x2 = x0 * 2
9+
val x3 = px3 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable1$1$$anon$1
10+
val x4 = px4 // static data: <function1>
11+
val x5 = {import x3._;
12+
val s1 = infix_lhs(findDefinition(Sym(1)).get).head;
13+
val s2 = infix_lhs(findDefinition(Sym(2)).get).head;
14+
reset;x3.nVars=3;compile{(x:Rep[Int]) =>
15+
createDefinition(s1,StaticData(x1));
16+
createDefinition(s2,StaticData(x2));
17+
val r = x4.asInstanceOf[Rep[Int]=>Rep[Int]](x)
18+
println(globalDefs); r}}//List(Sym(1), Sym(2))
19+
val x6 = px6 // static data: SCell(stable)
20+
val x7 = x6.value
21+
val x8 = x5(x7)
22+
x8
23+
}
24+
}
25+
/*****************************************
26+
End of Generated Code
27+
*******************************************/
28+
29+
compilation: ok
30+
List(TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(4),NumericPlus(Sym(1),Sym(2))), TP(Sym(5),NumericTimes(Sym(3),Sym(4))))
31+
/*****************************************
32+
Emitting Generated Code
33+
*******************************************/
34+
class staged$1(px1:Int,px2:Int) extends ((Int)=>(Int)) {
35+
def apply(x3:Int): Int = {
36+
val x1 = px1 // static data: 10
37+
val x2 = px2 // static data: 18
38+
val x4 = x1 + x2
39+
val x5 = x3 * x4
40+
x5
41+
}
42+
}
43+
/*****************************************
44+
End of Generated Code
45+
*******************************************/
46+
47+
compilation: ok
48+
28
49+
List(TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(4),NumericPlus(Sym(1),Sym(2))), TP(Sym(5),NumericTimes(Sym(3),Sym(4))))
50+
/*****************************************
51+
Emitting Generated Code
52+
*******************************************/
53+
class staged$2(px1:Int,px2:Int) extends ((Int)=>(Int)) {
54+
def apply(x3:Int): Int = {
55+
val x1 = px1 // static data: 10
56+
val x2 = px2 // static data: 18
57+
val x4 = x1 + x2
58+
val x5 = x3 * x4
59+
x5
60+
}
61+
}
62+
/*****************************************
63+
End of Generated Code
64+
*******************************************/
65+
66+
compilation: ok
67+
140
68+
List(TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(4),NumericPlus(Sym(1),Sym(2))), TP(Sym(5),NumericTimes(Sym(3),Sym(4))))
69+
/*****************************************
70+
Emitting Generated Code
71+
*******************************************/
72+
class staged$3(px1:Int,px2:Int) extends ((Int)=>(Int)) {
73+
def apply(x3:Int): Int = {
74+
val x1 = px1 // static data: 10
75+
val x2 = px2 // static data: 18
76+
val x4 = x1 + x2
77+
val x5 = x3 * x4
78+
x5
79+
}
80+
}
81+
/*****************************************
82+
End of Generated Code
83+
*******************************************/
84+
85+
compilation: ok
86+
56

‎test-out/epfl/test13-stable2.check‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
call with arg 9
2+
(re) compiling
3+
free vars: List(Sym(1), Sym(2))
4+
read value SCell(stable) sym Sym(3)
5+
compiled Sym(12)
6+
/*****************************************
7+
Emitting Generated Code
8+
*******************************************/
9+
class staged$0(px3:scala.virtualization.lms.epfl.test13.SCell[Int],px8:scala.virtualization.lms.epfl.test13.SCell[scala.Function1[Int, Int]],px10:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px11:Object) extends ((Int)=>(Int)) {
10+
def apply(x0:Int): Int = {
11+
val x3 = px3 // static data: SCell(stable)
12+
val x4 = x3.value
13+
val x5 = x4 == 1
14+
val x15 = if (x5) {
15+
val x1 = x0 + 1
16+
val x2 = x0 * 2
17+
val x6 = x1 + x2
18+
val x7 = 1 * x6
19+
x7
20+
} else {
21+
val x8 = px8 // static data: SCell(code)
22+
val x9 = x8.set(null)
23+
val x1 = x0 + 1
24+
val x2 = x0 * 2
25+
val x10 = px10 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable2$1$$anon$2
26+
val x11 = px11 // static data: <function1>
27+
val x12 = {import x10._;
28+
val s4 = infix_lhs(findDefinition(Sym(4)).get).head;
29+
val s1 = infix_lhs(findDefinition(Sym(1)).get).head;
30+
val s2 = infix_lhs(findDefinition(Sym(2)).get).head;
31+
reset;x10.nVars=5;compile{(x:Rep[Int]) =>
32+
createDefinition(s4,StaticData(x4));
33+
createDefinition(s1,StaticData(x1));
34+
createDefinition(s2,StaticData(x2));
35+
val r = x11.asInstanceOf[Rep[Int]=>Rep[Int]](x)
36+
println(globalDefs); r}}//List(Sym(4), Sym(1), Sym(2))
37+
val x13 = x12(x4)
38+
x13
39+
}
40+
x15
41+
}
42+
}
43+
/*****************************************
44+
End of Generated Code
45+
*******************************************/
46+
47+
compilation: ok
48+
28
49+
call with arg 9
50+
List(TP(Sym(4),StaticData(5)), TP(Sym(1),StaticData(10)), TP(Sym(2),StaticData(18)), TP(Sym(6),NumericPlus(Sym(1),Sym(2))), TP(Sym(7),NumericTimes(Sym(4),Sym(6))))
51+
/*****************************************
52+
Emitting Generated Code
53+
*******************************************/
54+
class staged$1(px4:Int,px1:Int,px2:Int) extends ((Int)=>(Int)) {
55+
def apply(x5:Int): Int = {
56+
val x4 = px4 // static data: 5
57+
val x1 = px1 // static data: 10
58+
val x2 = px2 // static data: 18
59+
val x6 = x1 + x2
60+
val x7 = x4 * x6
61+
x7
62+
}
63+
}
64+
/*****************************************
65+
End of Generated Code
66+
*******************************************/
67+
68+
compilation: ok
69+
140
70+
call with arg 9
71+
(re) compiling
72+
free vars: List(Sym(9), Sym(10))
73+
read value SCell(stable) sym Sym(11)
74+
compiled Sym(20)
75+
/*****************************************
76+
Emitting Generated Code
77+
*******************************************/
78+
class staged$2(px11:scala.virtualization.lms.epfl.test13.SCell[Int],px16:scala.virtualization.lms.epfl.test13.SCell[scala.Function1[Int, Int]],px18:scala.virtualization.lms.common.Compile with scala.virtualization.lms.common.StaticDataExp,px19:Object) extends ((Int)=>(Int)) {
79+
def apply(x8:Int): Int = {
80+
val x11 = px11 // static data: SCell(stable)
81+
val x12 = x11.value
82+
val x13 = x12 == 2
83+
val x23 = if (x13) {
84+
val x9 = x8 + 1
85+
val x10 = x8 * 2
86+
val x14 = x9 + x10
87+
val x15 = 2 * x14
88+
x15
89+
} else {
90+
val x16 = px16 // static data: SCell(code)
91+
val x17 = x16.set(null)
92+
val x9 = x8 + 1
93+
val x10 = x8 * 2
94+
val x18 = px18 // static data: IR:scala.virtualization.lms.epfl.test13.TestStable$$anonfun$testStable2$1$$anon$2
95+
val x19 = px19 // static data: <function1>
96+
val x20 = {import x18._;
97+
val s12 = infix_lhs(findDefinition(Sym(12)).get).head;
98+
val s9 = infix_lhs(findDefinition(Sym(9)).get).head;
99+
val s10 = infix_lhs(findDefinition(Sym(10)).get).head;
100+
reset;x18.nVars=13;compile{(x:Rep[Int]) =>
101+
createDefinition(s12,StaticData(x12));
102+
createDefinition(s9,StaticData(x9));
103+
createDefinition(s10,StaticData(x10));
104+
val r = x19.asInstanceOf[Rep[Int]=>Rep[Int]](x)
105+
println(globalDefs); r}}//List(Sym(12), Sym(9), Sym(10))
106+
val x21 = x20(x12)
107+
x21
108+
}
109+
x23
110+
}
111+
}
112+
/*****************************************
113+
End of Generated Code
114+
*******************************************/
115+
116+
compilation: ok
117+
56

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp