Mercurial > projects > ddmd
annotate dmd/UnrolledLoopStatement.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
72 | 1 module dmd.UnrolledLoopStatement; |
2 | |
114 | 3 import dmd.common; |
163 | 4 import dmd.GlobalExpressions; |
72 | 5 import dmd.Expression; |
6 import dmd.Statement; | |
7 import dmd.InterState; | |
8 import dmd.ArrayTypes; | |
9 import dmd.OutBuffer; | |
10 import dmd.Loc; | |
11 import dmd.Scope; | |
12 import dmd.InlineCostState; | |
13 import dmd.InlineDoState; | |
14 import dmd.IRState; | |
15 import dmd.HdrGenState; | |
0 | 16 import dmd.InlineScanState; |
72 | 17 import dmd.BE; |
18 | |
19 import dmd.backend.BC; | |
20 import dmd.backend.Blockx; | |
21 import dmd.backend.block; | |
22 import dmd.backend.Util; | |
23 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 |
0 | 26 class UnrolledLoopStatement : Statement |
27 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 |
0 | 30 Statements statements; |
31 | |
56 | 32 this(Loc loc, Statements s) |
0 | 33 { |
178 | 34 register(); |
72 | 35 super(loc); |
56 | 36 statements = s; |
0 | 37 } |
38 | |
72 | 39 override Statement syntaxCopy() |
0 | 40 { |
41 assert(false); | |
42 } | |
43 | |
72 | 44 override Statement semantic(Scope sc) |
0 | 45 { |
72 | 46 //printf("UnrolledLoopStatement.semantic(this = %p, sc = %p)\n", this, sc); |
47 | |
48 sc.noctor++; | |
49 Scope scd = sc.push(); | |
50 scd.sbreak = this; | |
51 scd.scontinue = this; | |
52 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
53 foreach(ref Statement s; statements) |
72 | 54 { |
55 if (s) | |
56 { | |
57 s = s.semantic(scd); | |
58 } | |
59 } | |
60 | |
61 scd.pop(); | |
62 sc.noctor--; | |
56 | 63 return this; |
0 | 64 } |
65 | |
72 | 66 override bool hasBreak() |
0 | 67 { |
68 assert(false); | |
69 } | |
70 | |
72 | 71 override bool hasContinue() |
0 | 72 { |
73 assert(false); | |
74 } | |
75 | |
72 | 76 override bool usesEH() |
0 | 77 { |
78 assert(false); | |
79 } | |
80 | |
72 | 81 override BE blockExit() |
0 | 82 { |
72 | 83 BE result = BEfallthru; |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
84 foreach (s; statements) |
72 | 85 { |
86 if (s) | |
87 { | |
88 int r = s.blockExit(); | |
89 result |= r & ~(BEbreak | BEcontinue); | |
90 } | |
91 } | |
56 | 92 return result; |
0 | 93 } |
94 | |
72 | 95 override bool comeFrom() |
0 | 96 { |
97 assert(false); | |
98 } | |
99 | |
72 | 100 override Expression interpret(InterState istate) |
0 | 101 { |
163 | 102 Expression e = null; |
103 | |
104 version (LOG) { | |
105 printf("UnrolledLoopStatement.interpret()\n"); | |
106 } | |
107 if (istate.start == this) | |
108 istate.start = null; | |
109 if (statements) | |
110 { | |
111 for (size_t i = 0; i < statements.dim; i++) | |
112 { | |
113 Statement s = statements[i]; | |
114 | |
115 e = s.interpret(istate); | |
116 if (e is EXP_CANT_INTERPRET) | |
117 break; | |
118 if (e is EXP_CONTINUE_INTERPRET) | |
119 { | |
120 e = null; | |
121 continue; | |
122 } | |
123 if (e is EXP_BREAK_INTERPRET) | |
124 { | |
125 e = null; | |
126 break; | |
127 } | |
128 if (e) | |
129 break; | |
130 } | |
131 } | |
132 return e; | |
0 | 133 } |
134 | |
72 | 135 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 136 { |
137 assert(false); | |
138 } | |
139 | |
72 | 140 override int inlineCost(InlineCostState* ics) |
0 | 141 { |
123 | 142 int cost = 0; |
143 | |
144 foreach (Statement s; statements) | |
145 { | |
146 if (s) | |
147 { | |
148 cost += s.inlineCost(ics); | |
149 if (cost >= COST_MAX) | |
150 break; | |
151 } | |
152 } | |
153 return cost; | |
0 | 154 } |
155 | |
72 | 156 override Expression doInline(InlineDoState ids) |
0 | 157 { |
158 assert(false); | |
159 } | |
160 | |
72 | 161 override Statement inlineScan(InlineScanState* iss) |
0 | 162 { |
123 | 163 foreach (ref Statement s; statements) |
164 { | |
165 if (s) | |
166 s = s.inlineScan(iss); | |
167 } | |
168 return this; | |
0 | 169 } |
170 | |
72 | 171 override void toIR(IRState* irs) |
0 | 172 { |
72 | 173 Blockx* blx = irs.blx; |
174 | |
175 IRState mystate = IRState(irs, this); | |
176 mystate.breakBlock = block_calloc(blx); | |
177 | |
178 block* bpre = blx.curblock; | |
179 block_next(blx, BCgoto, null); | |
180 | |
181 block* bdo = blx.curblock; | |
182 list_append(&bpre.Bsucc, bdo); | |
183 | |
184 block* bdox; | |
185 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
186 foreach (s; statements) |
72 | 187 { |
188 if (s !is null) | |
189 { | |
190 mystate.contBlock = block_calloc(blx); | |
191 | |
192 s.toIR(&mystate); | |
193 | |
194 bdox = blx.curblock; | |
195 block_next(blx, BCgoto, mystate.contBlock); | |
196 list_append(&bdox.Bsucc, mystate.contBlock); | |
197 } | |
198 } | |
199 | |
200 bdox = blx.curblock; | |
201 block_next(blx, BCgoto, mystate.breakBlock); | |
67 | 202 list_append(&bdox.Bsucc, mystate.breakBlock); |
0 | 203 } |
204 } | |
205 |