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