Mercurial > projects > ddmd
annotate dmd/UnrolledLoopStatement.d @ 168:ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
author | korDen |
---|---|
date | Thu, 30 Sep 2010 12:57:13 +0400 |
parents | fe932c1a9563 |
children | e3afd1303184 |
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 | |
0 | 24 class UnrolledLoopStatement : Statement |
25 { | |
26 Statements statements; | |
27 | |
56 | 28 this(Loc loc, Statements s) |
0 | 29 { |
72 | 30 super(loc); |
56 | 31 statements = s; |
0 | 32 } |
33 | |
72 | 34 override Statement syntaxCopy() |
0 | 35 { |
36 assert(false); | |
37 } | |
38 | |
72 | 39 override Statement semantic(Scope sc) |
0 | 40 { |
72 | 41 //printf("UnrolledLoopStatement.semantic(this = %p, sc = %p)\n", this, sc); |
42 | |
43 sc.noctor++; | |
44 Scope scd = sc.push(); | |
45 scd.sbreak = this; | |
46 scd.scontinue = this; | |
47 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
48 foreach(ref Statement s; statements) |
72 | 49 { |
50 if (s) | |
51 { | |
52 s = s.semantic(scd); | |
53 } | |
54 } | |
55 | |
56 scd.pop(); | |
57 sc.noctor--; | |
56 | 58 return this; |
0 | 59 } |
60 | |
72 | 61 override bool hasBreak() |
0 | 62 { |
63 assert(false); | |
64 } | |
65 | |
72 | 66 override bool hasContinue() |
0 | 67 { |
68 assert(false); | |
69 } | |
70 | |
72 | 71 override bool usesEH() |
0 | 72 { |
73 assert(false); | |
74 } | |
75 | |
72 | 76 override BE blockExit() |
0 | 77 { |
72 | 78 BE result = BEfallthru; |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
79 foreach (s; statements) |
72 | 80 { |
81 if (s) | |
82 { | |
83 int r = s.blockExit(); | |
84 result |= r & ~(BEbreak | BEcontinue); | |
85 } | |
86 } | |
56 | 87 return result; |
0 | 88 } |
89 | |
72 | 90 override bool comeFrom() |
0 | 91 { |
92 assert(false); | |
93 } | |
94 | |
72 | 95 override Expression interpret(InterState istate) |
0 | 96 { |
163 | 97 Expression e = null; |
98 | |
99 version (LOG) { | |
100 printf("UnrolledLoopStatement.interpret()\n"); | |
101 } | |
102 if (istate.start == this) | |
103 istate.start = null; | |
104 if (statements) | |
105 { | |
106 for (size_t i = 0; i < statements.dim; i++) | |
107 { | |
108 Statement s = statements[i]; | |
109 | |
110 e = s.interpret(istate); | |
111 if (e is EXP_CANT_INTERPRET) | |
112 break; | |
113 if (e is EXP_CONTINUE_INTERPRET) | |
114 { | |
115 e = null; | |
116 continue; | |
117 } | |
118 if (e is EXP_BREAK_INTERPRET) | |
119 { | |
120 e = null; | |
121 break; | |
122 } | |
123 if (e) | |
124 break; | |
125 } | |
126 } | |
127 return e; | |
0 | 128 } |
129 | |
72 | 130 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 131 { |
132 assert(false); | |
133 } | |
134 | |
72 | 135 override int inlineCost(InlineCostState* ics) |
0 | 136 { |
123 | 137 int cost = 0; |
138 | |
139 foreach (Statement s; statements) | |
140 { | |
141 if (s) | |
142 { | |
143 cost += s.inlineCost(ics); | |
144 if (cost >= COST_MAX) | |
145 break; | |
146 } | |
147 } | |
148 return cost; | |
0 | 149 } |
150 | |
72 | 151 override Expression doInline(InlineDoState ids) |
0 | 152 { |
153 assert(false); | |
154 } | |
155 | |
72 | 156 override Statement inlineScan(InlineScanState* iss) |
0 | 157 { |
123 | 158 foreach (ref Statement s; statements) |
159 { | |
160 if (s) | |
161 s = s.inlineScan(iss); | |
162 } | |
163 return this; | |
0 | 164 } |
165 | |
72 | 166 override void toIR(IRState* irs) |
0 | 167 { |
72 | 168 Blockx* blx = irs.blx; |
169 | |
170 IRState mystate = IRState(irs, this); | |
171 mystate.breakBlock = block_calloc(blx); | |
172 | |
173 block* bpre = blx.curblock; | |
174 block_next(blx, BCgoto, null); | |
175 | |
176 block* bdo = blx.curblock; | |
177 list_append(&bpre.Bsucc, bdo); | |
178 | |
179 block* bdox; | |
180 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
181 foreach (s; statements) |
72 | 182 { |
183 if (s !is null) | |
184 { | |
185 mystate.contBlock = block_calloc(blx); | |
186 | |
187 s.toIR(&mystate); | |
188 | |
189 bdox = blx.curblock; | |
190 block_next(blx, BCgoto, mystate.contBlock); | |
191 list_append(&bdox.Bsucc, mystate.contBlock); | |
192 } | |
193 } | |
194 | |
195 bdox = blx.curblock; | |
196 block_next(blx, BCgoto, mystate.breakBlock); | |
67 | 197 list_append(&bdox.Bsucc, mystate.breakBlock); |
0 | 198 } |
199 } | |
200 |