Skip to content

Commit de4ab25

Browse files
committed
change nthSucc to lengthx
1 parent fa89d73 commit de4ab25

9 files changed

Lines changed: 75 additions & 48 deletions

File tree

compiler/src/dmd/backend/blockopt.d

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ void block_pred(ref BlockOpt bo)
210210
for (block* b = bo.startblock; b; b = b.Bnext) // for each block
211211
{
212212
//printf("b = %p, BC = BC.%s\n", b, bc_str(b.bc));
213-
foreach (bp; ListRange(b.Bsucc))
213+
foreach (bp; BsuccArray(b.Bsucc))
214214
{ /* for each successor to b */
215215
//printf("\tbs = %p\n",list_block(bp));
216-
list_block(bp).Bpred.push(b); // original inserts at the beginning, don't think it matters
216+
bp.Bpred.push(b); // original inserts at the beginning, don't think it matters
217217
}
218218
}
219219
assert(bo.startblock.Bpred.length == 0); /* startblock has no preds */
@@ -233,13 +233,14 @@ void block_clearvisit(ref BlockOpt bo)
233233
/********************************************
234234
* Visit block and each of its predecessors.
235235
*/
236-
236+
@trusted
237237
void block_visit(block* b)
238238
{
239239
b.Bflags |= BFL.visited;
240-
foreach (l; ListRange(b.Bsucc))
240+
foreach (bs; BsuccArray(b.Bsucc))
241+
//foreach (l; ListRange(b.Bsucc))
241242
{
242-
block* bs = list_block(l);
243+
//block* bs = list_block(l);
243244
assert(bs);
244245
if ((bs.Bflags & BFL.visited) == 0) // if not visited
245246
block_visit(bs);
@@ -646,9 +647,10 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo)
646647
{
647648
b.bc = BC.exit;
648649
// Exit block has no successors, so remove them
649-
foreach (bp; ListRange(b.Bsucc))
650+
foreach (bp; BsuccArray(b.Bsucc))
651+
//foreach (bp; ListRange(b.Bsucc))
650652
{
651-
list_block(bp).Bpred.subtract(b);
653+
bp.Bpred.subtract(b);
652654
}
653655
list_free(&b.Bsucc, FPNULL);
654656
debug if (debugc) printf("CHANGE: noreturn becomes BC.exit\n");
@@ -730,11 +732,12 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo)
730732
block* db = b.Bsuccx(i);
731733

732734
/* delete predecessors of successors (!) */
733-
foreach (bl; ListRange(b.Bsucc))
735+
foreach (bl; BsuccArray(b.Bsucc))
736+
//foreach (bl; ListRange(b.Bsucc))
734737
{
735738
if (i--) // but not the db successor
736739
{
737-
bool bx = list_block(bl).Bpred.subtract(b);
740+
bool bx = bl.Bpred.subtract(b);
738741
assert(bx);
739742
}
740743
}
@@ -848,14 +851,16 @@ void compdfo(ref BlockOpt bo, ref Barray!(block*) dfo, block* startblock)
848851
/******************************
849852
* Add b's successors to dfo[], then b
850853
*/
854+
@trusted
851855
void walkDFO(block* b)
852856
{
853857
assert(b);
854858
b.Bflags |= BFL.visited; // executed at least once
855859

856-
foreach (bl; ListRange(b.Bsucc)) // for each successor
860+
foreach (bs; BsuccArray(b.Bsucc))
861+
//foreach (bl; ListRange(b.Bsucc)) // for each successor
857862
{
858-
block* bs = list_block(bl);
863+
//block* bs = list_block(bl);
859864
assert(bs);
860865
if ((bs.Bflags & BFL.visited) == 0) // if not visited
861866
walkDFO(bs);
@@ -914,11 +919,12 @@ private void elimblks(ref GlobalOptimizer go, ref BlockOpt bo)
914919
/* for each marked successor S to b */
915920
/* remove b from S.Bpred. */
916921
/* Presumably all predecessors to b are unmarked also. */
917-
foreach (s; ListRange(b.Bsucc))
922+
foreach (s; BsuccArray(b.Bsucc))
923+
//foreach (s; ListRange(b.Bsucc))
918924
{
919-
assert(list_block(s));
920-
if (list_block(s).Bflags & BFL.visited) /* if it is marked */
921-
list_block(s).Bpred.subtract(b);
925+
//assert(list_block(s));
926+
if (s.Bflags & BFL.visited) /* if it is marked */
927+
s.Bpred.subtract(b);
922928
}
923929
if (b.Balign && b.Bnext && b.Balign > b.Bnext.Balign)
924930
b.Bnext.Balign = b.Balign;

compiler/src/dmd/backend/cc.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,30 @@ nothrow:
332332
@trusted
333333
block* Bsuccx(block* b, int n) { return cast(block*)list_ptr(list_nth(b.Bsucc, n)); }
334334

335+
@trusted
336+
int lengthx(LIST* bl) { return list_nitems((cast(block*)list_ptr(bl)).Bsucc); }
337+
335338
@trusted
336339
inout(block)* list_block(inout list_t lst) { return cast(inout(block)*)list_ptr(lst); }
337340

341+
struct BsuccArray
342+
{
343+
nothrow @nogc @trusted:
344+
345+
this(list_t li)
346+
{
347+
this.li = li;
348+
}
349+
350+
block* front() return { return list_block(li); }
351+
void popFront() { li = li.next; }
352+
bool empty() const { return !li; }
353+
354+
private:
355+
list_t li;
356+
}
357+
358+
338359
/** Basic block control flow operators. **/
339360

340361
enum BC : ubyte

compiler/src/dmd/backend/debugprint.d

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,8 @@ void WRblockarray(block*[] bl)
299299
@trusted
300300
void WRblocklist(list_t bl)
301301
{
302-
foreach (bl2; ListRange(bl))
302+
foreach (b; BsuccArray(bl))
303303
{
304-
block* b = list_block(bl2);
305-
306304
if (b && b.Bweight)
307305
printf("B%d (%p) ",b.Bdfoidx,b);
308306
else

compiler/src/dmd/backend/eh.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void except_fillInEHTable(Symbol* s)
180180
}
181181
i = b.Bscope_index + 1;
182182

183-
int nsucc = b.numSucc();
183+
int nsucc = b.numSucc;
184184

185185
if (config.ehmethod == EHmethod.EH_DM)
186186
{

compiler/src/dmd/backend/gflow.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,9 +1353,9 @@ void flowlv(ref BlockOpt bo)
13531353
{
13541354
/* Bout = union of Bins of all successors to B. */
13551355
bool first = true;
1356-
foreach (bl; ListRange(b.Bsucc))
1356+
foreach (bl; BsuccArray(b.Bsucc))
13571357
{
1358-
const inlv = list_block(bl).Binlv;
1358+
const inlv = bl.Binlv;
13591359
if (first)
13601360
vec_copy(b.Boutlv, inlv);
13611361
else
@@ -1702,9 +1702,9 @@ void flowvbe(ref GlobalOptimizer go, ref BlockOpt bo)
17021702

17031703
/* Bout = & of Bin of all successors */
17041704
bool first = true;
1705-
foreach (bl; ListRange(b.Bsucc))
1705+
foreach (bl; BsuccArray(b.Bsucc))
17061706
{
1707-
const vin = list_block(bl).Bin;
1707+
const vin = bl.Bin;
17081708
if (first)
17091709
vec_copy(b.Bout, vin);
17101710
else

compiler/src/dmd/backend/gloop.d

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ bool blockinit(ref BlockOpt bo)
221221
L1:
222222
foreach (blp; b.Bpred[])
223223
{
224-
foreach (bls; ListRange(blp.Bsucc))
225-
if (list_block(bls) == b)
224+
foreach (bls; BsuccArray(blp.Bsucc))
225+
if (bls == b)
226226
continue L1;
227227
assert(0);
228228
}
@@ -328,6 +328,7 @@ bool dom(ref BlockOpt bo, const block* A, const block* B)
328328
* Find all the loops.
329329
*/
330330

331+
@trusted
331332
private void findloops(ref BlockOpt bo, block*[] dfo, ref Loops loops)
332333
{
333334
freeloop(loops);
@@ -340,9 +341,8 @@ private void findloops(ref BlockOpt bo, block*[] dfo, ref Loops loops)
340341
// loops are found first)
341342
{
342343
assert(b);
343-
foreach (bl; ListRange(b.Bsucc))
344+
foreach (s; BsuccArray(b.Bsucc))
344345
{
345-
block* s = list_block(bl); // each successor s to b
346346
assert(s);
347347
if (dom(bo, s, b)) // if s dominates b
348348
buildloop(bo, loops, s, b); // we found a loop
@@ -455,8 +455,8 @@ L1:
455455
vec_setbit(i,l.Lexit); /* ret blocks are exit blocks */
456456
else
457457
{
458-
foreach (bl; ListRange(bo.dfo[i].Bsucc))
459-
if (!vec_testbit(list_block(bl).Bdfoidx,l.Lloop))
458+
foreach (b; BsuccArray(bo.dfo[i].Bsucc))
459+
if (!vec_testbit(b.Bdfoidx,l.Lloop))
460460
{
461461
vec_setbit(i,l.Lexit);
462462
break;
@@ -610,7 +610,7 @@ static if (1)
610610
foreach (bl; ListRange(bs.Bsucc))
611611
if (list_block(bl) == head)
612612
{
613-
bl.ptr = cast(void*)head2;
613+
bl.ptr = head2;
614614
goto L2;
615615
}
616616
assert(0);
@@ -648,10 +648,9 @@ else
648648
} // for each pred(head)
649649
}
650650
// succ(head2) = succ(head)
651-
foreach (bl; ListRange(head.Bsucc))
651+
foreach (b; BsuccArray(head.Bsucc))
652652
{
653-
block* b = list_block(bl);
654-
list_append(&(head2.Bsucc),b);
653+
head2.appendSucc(b);
655654
b.Bpred.push(head2);
656655
}
657656
if (debugc) printf("1Rotated loop %p\n", &l);
@@ -1579,11 +1578,12 @@ Lnextlis:
15791578
uint i;
15801579
for (i = 0; (i = cast(uint) vec_index(i, l.Lexit)) < bo.dfo.length; ++i) // for each exit block
15811580
{
1582-
foreach (bl; ListRange(bo.dfo[i].Bsucc))
1581+
foreach (s; BsuccArray(bo.dfo[i].Bsucc))
1582+
//foreach (bl; ListRange(bo.dfo[i].Bsucc))
15831583
{
1584-
block* s; // successor to exit block
1584+
//block* s; // successor to exit block
15851585

1586-
s = list_block(bl);
1586+
//s = list_block(bl);
15871587
if (!vec_testbit(s.Bdfoidx,l.Lloop) &&
15881588
(!symbol_isintab(v) ||
15891589
vec_testbit(v.Ssymnum,s.Binlv))) // if v is live on exit
@@ -3119,9 +3119,10 @@ private void elimbasivs(ref GlobalOptimizer go, ref BlockOpt bo, ref Loop l)
31193119
/* Eliminate the basic IV if it is not live on any successor */
31203120
for (uint i = 0; (i = cast(uint) vec_index(i, l.Lexit)) < bo.dfo.length; ++i) // for each exit block
31213121
{
3122-
foreach (bl; ListRange(bo.dfo[i].Bsucc))
3122+
foreach (b; BsuccArray(bo.dfo[i].Bsucc))
3123+
//foreach (bl; ListRange(bo.dfo[i].Bsucc))
31233124
{ /* for each successor */
3124-
block* b = list_block(bl);
3125+
//block* b = list_block(bl);
31253126
if (vec_testbit(b.Bdfoidx,l.Lloop))
31263127
continue; /* inside loop */
31273128
if (vec_testbit(X.Ssymnum,b.Binlv))
@@ -3184,9 +3185,10 @@ private void elimopeqs(ref GlobalOptimizer go, ref BlockOpt bo, ref Loop l)
31843185
uint i;
31853186
for (i = 0; (i = cast(uint) vec_index(i, l.Lexit)) < bo.dfo.length; ++i) // for each exit block
31863187
{
3187-
foreach (bl; ListRange(bo.dfo[i].Bsucc))
3188+
foreach (b; BsuccArray(bo.dfo[i].Bsucc))
3189+
//foreach (bl; ListRange(bo.dfo[i].Bsucc))
31883190
{ // for each successor
3189-
block* b = list_block(bl);
3191+
//block* b = list_block(bl);
31903192
if (vec_testbit(b.Bdfoidx,l.Lloop))
31913193
continue; // inside loop
31923194
if (vec_testbit(X.Ssymnum,b.Binlv))

compiler/src/dmd/backend/gother.d

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,8 @@ private int loopcheck(block* start,block* inc,block* rel)
10661066
{
10671067
if (!(start.Bflags & BFL.visited))
10681068
{ start.Bflags |= BFL.visited; /* guarantee eventual termination */
1069-
foreach (list; ListRange(start.Bsucc))
1069+
foreach (b; BsuccArray(start.Bsucc))
10701070
{
1071-
block* b = cast(block*) list_ptr(list);
10721071
if (b != rel && (b == inc || loopcheck(b,inc,rel)))
10731072
return true;
10741073
}

compiler/src/dmd/backend/x86/cgreg.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,9 @@ void cgreg_spillreg_epilog(block* b,Symbol* s,ref CodeBuilder cdbstore, ref Code
613613
const live = vec_testbit(bi,s.Slvreg) != 0;
614614

615615
// Look at successors to see if we need to load in/out of register
616-
foreach (bl; ListRange(b.Bsucc))
616+
foreach (bl; BsuccArray(b.Bsucc))
617617
{
618-
const bpi = list_block(bl).Bdfoidx;
618+
const bpi = bl.Bdfoidx;
619619
if (!vec_testbit(bpi,s.Srange))
620620
continue;
621621
if (vec_testbit(bpi,s.Slvreg))

compiler/src/dmd/backend/x86/cod5.d

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ else
118118

119119
// See if b is an epilog
120120
mark = 0;
121-
foreach (bl; ListRange(b.Bsucc))
121+
foreach (bl; BsuccArray(b.Bsucc))
122122
{
123-
if (list_block(bl).Bflags & BFL.outsideprolog)
123+
if (bl.Bflags & BFL.outsideprolog)
124124
{
125125
if (mark == 2)
126126
goto L1;
@@ -175,15 +175,16 @@ void cod5_noprol(block* startblock)
175175
* the function prolog.
176176
*/
177177

178+
@trusted
178179
private void pe_add(block* b)
179180
{
180181
if (b.Bflags & BFL.outsideprolog ||
181182
need_prolog(b))
182183
return;
183184

184185
b.Bflags |= BFL.outsideprolog;
185-
foreach (bl; ListRange(b.Bsucc))
186-
pe_add(list_block(bl));
186+
foreach (bl; BsuccArray(b.Bsucc))
187+
pe_add(bl);
187188
}
188189

189190
/**********************************************

0 commit comments

Comments
 (0)