Skip to content

Commit b845c98

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

8 files changed

Lines changed: 48 additions & 29 deletions

File tree

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: 13 additions & 13 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

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)