Mercurial > projects > ddmd
annotate dmd/UnrolledLoopStatement.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | 9e39c7de8438 |
children | fe932c1a9563 |
rev | line source |
---|---|
72 | 1 module dmd.UnrolledLoopStatement; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Statement; | |
6 import dmd.InterState; | |
7 import dmd.ArrayTypes; | |
8 import dmd.OutBuffer; | |
9 import dmd.Loc; | |
10 import dmd.Scope; | |
11 import dmd.InlineCostState; | |
12 import dmd.InlineDoState; | |
13 import dmd.IRState; | |
14 import dmd.HdrGenState; | |
0 | 15 import dmd.InlineScanState; |
72 | 16 import dmd.BE; |
17 | |
18 import dmd.backend.BC; | |
19 import dmd.backend.Blockx; | |
20 import dmd.backend.block; | |
21 import dmd.backend.Util; | |
22 | |
0 | 23 class UnrolledLoopStatement : Statement |
24 { | |
25 Statements statements; | |
26 | |
56 | 27 this(Loc loc, Statements s) |
0 | 28 { |
72 | 29 super(loc); |
56 | 30 statements = s; |
0 | 31 } |
32 | |
72 | 33 override Statement syntaxCopy() |
0 | 34 { |
35 assert(false); | |
36 } | |
37 | |
72 | 38 override Statement semantic(Scope sc) |
0 | 39 { |
72 | 40 //printf("UnrolledLoopStatement.semantic(this = %p, sc = %p)\n", this, sc); |
41 | |
42 sc.noctor++; | |
43 Scope scd = sc.push(); | |
44 scd.sbreak = this; | |
45 scd.scontinue = this; | |
46 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
47 foreach(ref Statement s; statements) |
72 | 48 { |
49 if (s) | |
50 { | |
51 s = s.semantic(scd); | |
52 } | |
53 } | |
54 | |
55 scd.pop(); | |
56 sc.noctor--; | |
56 | 57 return this; |
0 | 58 } |
59 | |
72 | 60 override bool hasBreak() |
0 | 61 { |
62 assert(false); | |
63 } | |
64 | |
72 | 65 override bool hasContinue() |
0 | 66 { |
67 assert(false); | |
68 } | |
69 | |
72 | 70 override bool usesEH() |
0 | 71 { |
72 assert(false); | |
73 } | |
74 | |
72 | 75 override BE blockExit() |
0 | 76 { |
72 | 77 BE result = BEfallthru; |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
78 foreach (s; statements) |
72 | 79 { |
80 if (s) | |
81 { | |
82 int r = s.blockExit(); | |
83 result |= r & ~(BEbreak | BEcontinue); | |
84 } | |
85 } | |
56 | 86 return result; |
0 | 87 } |
88 | |
72 | 89 override bool comeFrom() |
0 | 90 { |
91 assert(false); | |
92 } | |
93 | |
72 | 94 override Expression interpret(InterState istate) |
0 | 95 { |
96 assert(false); | |
97 } | |
98 | |
72 | 99 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 100 { |
101 assert(false); | |
102 } | |
103 | |
72 | 104 override int inlineCost(InlineCostState* ics) |
0 | 105 { |
123 | 106 int cost = 0; |
107 | |
108 foreach (Statement s; statements) | |
109 { | |
110 if (s) | |
111 { | |
112 cost += s.inlineCost(ics); | |
113 if (cost >= COST_MAX) | |
114 break; | |
115 } | |
116 } | |
117 return cost; | |
0 | 118 } |
119 | |
72 | 120 override Expression doInline(InlineDoState ids) |
0 | 121 { |
122 assert(false); | |
123 } | |
124 | |
72 | 125 override Statement inlineScan(InlineScanState* iss) |
0 | 126 { |
123 | 127 foreach (ref Statement s; statements) |
128 { | |
129 if (s) | |
130 s = s.inlineScan(iss); | |
131 } | |
132 return this; | |
0 | 133 } |
134 | |
72 | 135 override void toIR(IRState* irs) |
0 | 136 { |
72 | 137 Blockx* blx = irs.blx; |
138 | |
139 IRState mystate = IRState(irs, this); | |
140 mystate.breakBlock = block_calloc(blx); | |
141 | |
142 block* bpre = blx.curblock; | |
143 block_next(blx, BCgoto, null); | |
144 | |
145 block* bdo = blx.curblock; | |
146 list_append(&bpre.Bsucc, bdo); | |
147 | |
148 block* bdox; | |
149 | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
150 foreach (s; statements) |
72 | 151 { |
152 if (s !is null) | |
153 { | |
154 mystate.contBlock = block_calloc(blx); | |
155 | |
156 s.toIR(&mystate); | |
157 | |
158 bdox = blx.curblock; | |
159 block_next(blx, BCgoto, mystate.contBlock); | |
160 list_append(&bdox.Bsucc, mystate.contBlock); | |
161 } | |
162 } | |
163 | |
164 bdox = blx.curblock; | |
165 block_next(blx, BCgoto, mystate.breakBlock); | |
67 | 166 list_append(&bdox.Bsucc, mystate.breakBlock); |
0 | 167 } |
168 } | |
169 |