diff --git a/compiler/src/dmd/backend/blockopt.d b/compiler/src/dmd/backend/blockopt.d index 3bc503131ecd..b074bb40a3f3 100644 --- a/compiler/src/dmd/backend/blockopt.d +++ b/compiler/src/dmd/backend/blockopt.d @@ -210,10 +210,10 @@ void block_pred(ref BlockOpt bo) for (block* b = bo.startblock; b; b = b.Bnext) // for each block { //printf("b = %p, BC = BC.%s\n", b, bc_str(b.bc)); - foreach (bp; ListRange(b.Bsucc)) + foreach (bp; BsuccArray(b.Bsucc)) { /* for each successor to b */ //printf("\tbs = %p\n",list_block(bp)); - list_block(bp).Bpred.push(b); // original inserts at the beginning, don't think it matters + bp.Bpred.push(b); // original inserts at the beginning, don't think it matters } } assert(bo.startblock.Bpred.length == 0); /* startblock has no preds */ @@ -233,13 +233,14 @@ void block_clearvisit(ref BlockOpt bo) /******************************************** * Visit block and each of its predecessors. */ - +@trusted void block_visit(block* b) { b.Bflags |= BFL.visited; - foreach (l; ListRange(b.Bsucc)) + foreach (bs; BsuccArray(b.Bsucc)) + //foreach (l; ListRange(b.Bsucc)) { - block* bs = list_block(l); + //block* bs = list_block(l); assert(bs); if ((bs.Bflags & BFL.visited) == 0) // if not visited block_visit(bs); @@ -519,8 +520,8 @@ void brcombine(ref GlobalOptimizer go, ref BlockOpt bo) const bc = b.bc; if (bc == BC.iftrue) { - block* b2 = b.nthSucc(0); - block* b3 = b.nthSucc(1); + block* b2 = b.Bsuccx(0); + block* b3 = b.Bsuccx(1); if (b2.Bpred.length > 1) // if more than one predecessor continue; @@ -533,7 +534,7 @@ void brcombine(ref GlobalOptimizer go, ref BlockOpt bo) const bc2 = b2.bc; if (bc2 == BC.goto_ && - b3 == b2.nthSucc(0)) + b3 == b2.Bsuccx(0)) { b.bc = BC.goto_; if (b2.Belem) @@ -570,9 +571,9 @@ void brcombine(ref GlobalOptimizer go, ref BlockOpt bo) } else if (bc2 == BC.goto_ && b3.bc == BC.goto_ && - b2.nthSucc(0) == b3.nthSucc(0)) + b2.Bsuccx(0) == b3.Bsuccx(0)) { - block* bsucc = b2.nthSucc(0); + block* bsucc = b2.Bsuccx(0); if (b2.Belem) { elem* e; @@ -646,9 +647,10 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) { b.bc = BC.exit; // Exit block has no successors, so remove them - foreach (bp; ListRange(b.Bsucc)) + foreach (bp; BsuccArray(b.Bsucc)) + //foreach (bp; ListRange(b.Bsucc)) { - list_block(bp).Bpred.subtract(b); + bp.Bpred.subtract(b); } list_free(&b.Bsucc, FPNULL); debug if (debugc) printf("CHANGE: noreturn becomes BC.exit\n"); @@ -680,13 +682,13 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) if (iftrue(n)) /* if elem is true */ { // select first succ - db = b.nthSucc(1); + db = b.Bsuccx(1); goto L1; } else if (iffalse(n)) { // select second succ - db = b.nthSucc(0); + db = b.Bsuccx(0); L1: list_subtract(&(b.Bsucc),db); @@ -699,11 +701,11 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) } /* Look for both destinations being the same */ - else if (b.nthSucc(0) == - b.nthSucc(1)) + else if (b.Bsuccx(0) == + b.Bsuccx(1)) { b.bc = BC.goto_; - db = b.nthSucc(0); + db = b.Bsuccx(0); list_subtract(&(b.Bsucc),db); db.Bpred.subtract(b); debug if (debugc) printf("CHANGE: if (e) goto L1; else goto L1;\n"); @@ -727,14 +729,15 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) break; } } - block* db = b.nthSucc(i); + block* db = b.Bsuccx(i); /* delete predecessors of successors (!) */ - foreach (bl; ListRange(b.Bsucc)) + foreach (bl; BsuccArray(b.Bsucc)) + //foreach (bl; ListRange(b.Bsucc)) { if (i--) // but not the db successor { - bool bx = list_block(bl).Bpred.subtract(b); + bool bx = bl.Bpred.subtract(b); assert(bx); } } @@ -776,7 +779,7 @@ private void brrear(ref BlockOpt bo) static if (NTEXCEPTIONS) enum additionalAnd = "b.Btry == bt.Btry && - bt.Btry == bt.nthSucc(0).Btry"; + bt.Btry == bt.Bsuccx(0).Btry"; else enum additionalAnd = "true"; @@ -814,8 +817,8 @@ private void brrear(ref BlockOpt bo) if (b.bc == BC.iftrue || b.bc == BC.iffalse) { - block* bif = b.nthSucc(0); - block* belse = b.nthSucc(1); + block* bif = b.Bsuccx(0); + block* belse = b.Bsuccx(1); if (bif == b.Bnext) { @@ -848,14 +851,16 @@ void compdfo(ref BlockOpt bo, ref Barray!(block*) dfo, block* startblock) /****************************** * Add b's successors to dfo[], then b */ + @trusted void walkDFO(block* b) { assert(b); b.Bflags |= BFL.visited; // executed at least once - foreach (bl; ListRange(b.Bsucc)) // for each successor + foreach (bs; BsuccArray(b.Bsucc)) + //foreach (bl; ListRange(b.Bsucc)) // for each successor { - block* bs = list_block(bl); + //block* bs = list_block(bl); assert(bs); if ((bs.Bflags & BFL.visited) == 0) // if not visited walkDFO(bs); @@ -914,11 +919,12 @@ private void elimblks(ref GlobalOptimizer go, ref BlockOpt bo) /* for each marked successor S to b */ /* remove b from S.Bpred. */ /* Presumably all predecessors to b are unmarked also. */ - foreach (s; ListRange(b.Bsucc)) + foreach (s; BsuccArray(b.Bsucc)) + //foreach (s; ListRange(b.Bsucc)) { - assert(list_block(s)); - if (list_block(s).Bflags & BFL.visited) /* if it is marked */ - list_block(s).Bpred.subtract(b); + //assert(list_block(s)); + if (s.Bflags & BFL.visited) /* if it is marked */ + s.Bpred.subtract(b); } if (b.Balign && b.Bnext && b.Balign > b.Bnext.Balign) b.Bnext.Balign = b.Balign; @@ -1396,11 +1402,12 @@ private void bltailmerge(ref GlobalOptimizer go, ref BlockOpt bo) /* Update the predecessor list of the successor list of bnew, from b to bnew, and removing bn */ - foreach (bl; ListRange(bnew.Bsucc)) + foreach (bl; BsuccArray(bnew.Bsucc)) + //foreach (bl; ListRange(bnew.Bsucc)) { - list_block(bl).Bpred.subtract(b); - list_block(bl).Bpred.subtract(bn); - list_block(bl).Bpred.push(bnew); + bl.Bpred.subtract(b); + bl.Bpred.subtract(bn); + bl.Bpred.push(bnew); } /* The predecessors to bnew are b and bn */ @@ -1441,7 +1448,7 @@ private void bltailmerge(ref GlobalOptimizer go, ref BlockOpt bo) } /********************************** - * Rearrange blocks to minimize jmp's. + * Rearrange blocks to minimize jmps. */ @trusted @@ -1476,18 +1483,20 @@ private void brmin(ref GlobalOptimizer go, ref BlockOpt bo) if (!isExceptionHandler(b.Bnext)) { // Skip the block if one of the successors is already at Bnext. - foreach (bl; ListRange(b.Bsucc)) + foreach (bl; BsuccArray(b.Bsucc)) + //foreach (bl; ListRange(b.Bsucc)) { - if (list_block(bl) == b.Bnext) + if (bl == b.Bnext) continue Lbb; } } // Look for a successor of b for which everyone must jmp to. Lsucc: - foreach (bl; ListRange(b.Bsucc)) + foreach (bs; BsuccArray(b.Bsucc)) + //foreach (bl; ListRange(b.Bsucc)) { - block* bs = list_block(bl); + //block* bs = list_block(bl); // BC.exit should have been optimized by blexit(). // Also ignore exception handlers. @@ -1608,9 +1617,10 @@ private void block_check() break; } - foreach (bl; ListRange(b.Bsucc)) + foreach (bs; BsuccArray(b.Bsucc)) + //foreach (bl; ListRange(b.Bsucc)) { - block* bs = list_block(bl); + //block* bs = list_block(bl); foreach (bls; bs.Bpred[]) { @@ -2093,9 +2103,10 @@ private void blassertsplit(ref GlobalOptimizer go, ref BlockOpt bo) */ b2.Bsucc = b.Bsucc; b.Bsucc = null; - foreach (b2sl; ListRange(b2.Bsucc)) + foreach (b2s; BsuccArray(b2.Bsucc)) + //foreach (b2sl; ListRange(b2.Bsucc)) { - block* b2s = list_block(b2sl); + //block* b2s = list_block(b2sl); foreach (ref b2spl; b2s.Bpred[]) { if (b2spl == b) @@ -2159,9 +2170,10 @@ private void blexit(ref GlobalOptimizer go, ref BlockOpt bo) b.bc = BC.exit; - foreach (bsl; ListRange(b.Bsucc)) + foreach (bs; BsuccArray(b.Bsucc)) + //foreach (bsl; ListRange(b.Bsucc)) { - block* bs = list_block(bsl); + //block* bs = list_block(bsl); bs.Bpred.subtract(b); } list_free(&b.Bsucc, FPNULL); diff --git a/compiler/src/dmd/backend/cc.d b/compiler/src/dmd/backend/cc.d index 0d7f08fcf4b2..b696d751e551 100644 --- a/compiler/src/dmd/backend/cc.d +++ b/compiler/src/dmd/backend/cc.d @@ -325,16 +325,37 @@ nothrow: int numSucc() { return list_nitems(this.Bsucc); } - @trusted - block* nthSucc(int n) { return cast(block*)list_ptr(list_nth(Bsucc, n)); } - @trusted void setNthSucc(int n, block* b) { list_nth(Bsucc, n).ptr = b; } } +@trusted +block* Bsuccx(block* b, int n) { return cast(block*)list_ptr(list_nth(b.Bsucc, n)); } + +@trusted +int lengthx(LIST* bl) { return list_nitems((cast(block*)list_ptr(bl)).Bsucc); } + @trusted inout(block)* list_block(inout list_t lst) { return cast(inout(block)*)list_ptr(lst); } +struct BsuccArray +{ + nothrow @nogc @trusted: + + this(list_t li) + { + this.li = li; + } + + block* front() return { return list_block(li); } + void popFront() { li = li.next; } + bool empty() const { return !li; } + + private: + list_t li; +} + + /** Basic block control flow operators. **/ enum BC : ubyte diff --git a/compiler/src/dmd/backend/cgcs.d b/compiler/src/dmd/backend/cgcs.d index a0f1fa8f2210..309185be29ce 100644 --- a/compiler/src/dmd/backend/cgcs.d +++ b/compiler/src/dmd/backend/cgcs.d @@ -99,8 +99,8 @@ void comsubs2(block* startblock, ref CGCS cgcs, ref GlobalOptimizer go, ref Bloc auto blc = bl; while (bln && bln.Bpred.length == 1 && ((blc.bc == BC.iftrue && - blc.nthSucc(1) == bln) || - (blc.bc == BC.goto_ && blc.nthSucc(0) == bln) + blc.Bsuccx(1) == bln) || + (blc.bc == BC.goto_ && blc.Bsuccx(0) == bln) ) && bln.bc != BC.asm_ // no CSE's extending across ASM blocks ) diff --git a/compiler/src/dmd/backend/debugprint.d b/compiler/src/dmd/backend/debugprint.d index 200a7938361e..7f96bebf3774 100644 --- a/compiler/src/dmd/backend/debugprint.d +++ b/compiler/src/dmd/backend/debugprint.d @@ -299,10 +299,8 @@ void WRblockarray(block*[] bl) @trusted void WRblocklist(list_t bl) { - foreach (bl2; ListRange(bl)) + foreach (b; BsuccArray(bl)) { - block* b = list_block(bl2); - if (b && b.Bweight) printf("B%d (%p) ",b.Bdfoidx,b); else diff --git a/compiler/src/dmd/backend/dwarfeh.d b/compiler/src/dmd/backend/dwarfeh.d index e9e5fec4fd2c..1615725dd963 100644 --- a/compiler/src/dmd/backend/dwarfeh.d +++ b/compiler/src/dmd/backend/dwarfeh.d @@ -119,7 +119,7 @@ static if (0) DwEhTableEntry* d = deh.push(); d.start = cast(uint)b.Boffset; - block* bf = b.nthSucc(1); + block* bf = b.Bsuccx(1); if (bf.bc == BC.jcatch) { d.lpad = cast(uint)bf.Boffset; @@ -138,7 +138,7 @@ static if (0) d.action = offset + 1; } else - d.lpad = cast(uint)bf.nthSucc(0).Boffset; + d.lpad = cast(uint)bf.Bsuccx(0).Boffset; d.prev = index; index = i; bprev = b.Btry; diff --git a/compiler/src/dmd/backend/eh.d b/compiler/src/dmd/backend/eh.d index 64f5c649ceab..aa5f0e532c45 100644 --- a/compiler/src/dmd/backend/eh.d +++ b/compiler/src/dmd/backend/eh.d @@ -180,7 +180,7 @@ void except_fillInEHTable(Symbol* s) } i = b.Bscope_index + 1; - int nsucc = b.numSucc(); + int nsucc = b.numSucc; if (config.ehmethod == EHmethod.EH_DM) { @@ -216,10 +216,10 @@ void except_fillInEHTable(Symbol* s) { assert(nsucc == 2); dtb.dword(0); // no catch offset - block* bhandler = b.nthSucc(1); + block* bhandler = b.Bsuccx(1); assert(bhandler.bc == BC._finally); // To successor of BC._finally block - bhandler = bhandler.nthSucc(0); + bhandler = bhandler.Bsuccx(0); // finally handler address if (config.ehmethod == EHmethod.EH_DM) { @@ -341,7 +341,7 @@ void except_fillInEHTable(Symbol* s) for (int j = 1; j < nsucc; ++j) { - block* bcatch = b.nthSucc(j); + block* bcatch = b.Bsuccx(j); dtb.xoff(bcatch.Bcatchtype,0,TYnptr); diff --git a/compiler/src/dmd/backend/gflow.d b/compiler/src/dmd/backend/gflow.d index c031b4f55c3b..3cda989fb18e 100644 --- a/compiler/src/dmd/backend/gflow.d +++ b/compiler/src/dmd/backend/gflow.d @@ -570,7 +570,7 @@ private void flowaecp(ref GlobalOptimizer go, ref BlockOpt bo) bool first = true; foreach (bp; b.Bpred[]) { - if (bp.bc == BC.iftrue && bp.nthSucc(0) != b) + if (bp.bc == BC.iftrue && bp.Bsuccx(0) != b) { if (first) vec_copy(b.Bin,bp.Bout2); @@ -1353,9 +1353,9 @@ void flowlv(ref BlockOpt bo) { /* Bout = union of Bins of all successors to B. */ bool first = true; - foreach (bl; ListRange(b.Bsucc)) + foreach (bl; BsuccArray(b.Bsucc)) { - const inlv = list_block(bl).Binlv; + const inlv = bl.Binlv; if (first) vec_copy(b.Boutlv, inlv); else @@ -1702,9 +1702,9 @@ void flowvbe(ref GlobalOptimizer go, ref BlockOpt bo) /* Bout = & of Bin of all successors */ bool first = true; - foreach (bl; ListRange(b.Bsucc)) + foreach (bl; BsuccArray(b.Bsucc)) { - const vin = list_block(bl).Bin; + const vin = bl.Bin; if (first) vec_copy(b.Bout, vin); else diff --git a/compiler/src/dmd/backend/gloop.d b/compiler/src/dmd/backend/gloop.d index b4882c684012..e43fe185fa24 100644 --- a/compiler/src/dmd/backend/gloop.d +++ b/compiler/src/dmd/backend/gloop.d @@ -221,8 +221,8 @@ bool blockinit(ref BlockOpt bo) L1: foreach (blp; b.Bpred[]) { - foreach (bls; ListRange(blp.Bsucc)) - if (list_block(bls) == b) + foreach (bls; BsuccArray(blp.Bsucc)) + if (bls == b) continue L1; assert(0); } @@ -328,6 +328,7 @@ bool dom(ref BlockOpt bo, const block* A, const block* B) * Find all the loops. */ +@trusted private void findloops(ref BlockOpt bo, block*[] dfo, ref Loops loops) { freeloop(loops); @@ -340,9 +341,8 @@ private void findloops(ref BlockOpt bo, block*[] dfo, ref Loops loops) // loops are found first) { assert(b); - foreach (bl; ListRange(b.Bsucc)) + foreach (s; BsuccArray(b.Bsucc)) { - block* s = list_block(bl); // each successor s to b assert(s); if (dom(bo, s, b)) // if s dominates b buildloop(bo, loops, s, b); // we found a loop @@ -455,8 +455,8 @@ L1: vec_setbit(i,l.Lexit); /* ret blocks are exit blocks */ else { - foreach (bl; ListRange(bo.dfo[i].Bsucc)) - if (!vec_testbit(list_block(bl).Bdfoidx,l.Lloop)) + foreach (b; BsuccArray(bo.dfo[i].Bsucc)) + if (!vec_testbit(b.Bdfoidx,l.Lloop)) { vec_setbit(i,l.Lexit); break; @@ -610,7 +610,7 @@ static if (1) foreach (bl; ListRange(bs.Bsucc)) if (list_block(bl) == head) { - bl.ptr = cast(void*)head2; + bl.ptr = head2; goto L2; } assert(0); @@ -648,10 +648,9 @@ else } // for each pred(head) } // succ(head2) = succ(head) - foreach (bl; ListRange(head.Bsucc)) + foreach (b; BsuccArray(head.Bsucc)) { - block* b = list_block(bl); - list_append(&(head2.Bsucc),b); + head2.appendSucc(b); b.Bpred.push(head2); } if (debugc) printf("1Rotated loop %p\n", &l); @@ -1579,11 +1578,12 @@ Lnextlis: uint i; for (i = 0; (i = cast(uint) vec_index(i, l.Lexit)) < bo.dfo.length; ++i) // for each exit block { - foreach (bl; ListRange(bo.dfo[i].Bsucc)) + foreach (s; BsuccArray(bo.dfo[i].Bsucc)) + //foreach (bl; ListRange(bo.dfo[i].Bsucc)) { - block* s; // successor to exit block + //block* s; // successor to exit block - s = list_block(bl); + //s = list_block(bl); if (!vec_testbit(s.Bdfoidx,l.Lloop) && (!symbol_isintab(v) || 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) /* Eliminate the basic IV if it is not live on any successor */ for (uint i = 0; (i = cast(uint) vec_index(i, l.Lexit)) < bo.dfo.length; ++i) // for each exit block { - foreach (bl; ListRange(bo.dfo[i].Bsucc)) + foreach (b; BsuccArray(bo.dfo[i].Bsucc)) + //foreach (bl; ListRange(bo.dfo[i].Bsucc)) { /* for each successor */ - block* b = list_block(bl); + //block* b = list_block(bl); if (vec_testbit(b.Bdfoidx,l.Lloop)) continue; /* inside loop */ if (vec_testbit(X.Ssymnum,b.Binlv)) @@ -3184,9 +3185,10 @@ private void elimopeqs(ref GlobalOptimizer go, ref BlockOpt bo, ref Loop l) uint i; for (i = 0; (i = cast(uint) vec_index(i, l.Lexit)) < bo.dfo.length; ++i) // for each exit block { - foreach (bl; ListRange(bo.dfo[i].Bsucc)) + foreach (b; BsuccArray(bo.dfo[i].Bsucc)) + //foreach (bl; ListRange(bo.dfo[i].Bsucc)) { // for each successor - block* b = list_block(bl); + //block* b = list_block(bl); if (vec_testbit(b.Bdfoidx,l.Lloop)) continue; // inside loop if (vec_testbit(X.Ssymnum,b.Binlv)) diff --git a/compiler/src/dmd/backend/gother.d b/compiler/src/dmd/backend/gother.d index 593e4108066e..ce564012d403 100644 --- a/compiler/src/dmd/backend/gother.d +++ b/compiler/src/dmd/backend/gother.d @@ -1066,9 +1066,8 @@ private int loopcheck(block* start,block* inc,block* rel) { if (!(start.Bflags & BFL.visited)) { start.Bflags |= BFL.visited; /* guarantee eventual termination */ - foreach (list; ListRange(start.Bsucc)) + foreach (b; BsuccArray(start.Bsucc)) { - block* b = cast(block*) list_ptr(list); if (b != rel && (b == inc || loopcheck(b,inc,rel))) return true; } diff --git a/compiler/src/dmd/backend/inliner.d b/compiler/src/dmd/backend/inliner.d index 9bf090530a52..50261ef98981 100644 --- a/compiler/src/dmd/backend/inliner.d +++ b/compiler/src/dmd/backend/inliner.d @@ -112,7 +112,7 @@ bool canInlineFunction(Symbol* sfunc) switch (b.bc) { case BC.goto_: - if (b.Bnext != b.nthSucc(0)) + if (b.Bnext != b.Bsuccx(0)) return no(__LINE__); b = b.Bnext; continue; diff --git a/compiler/src/dmd/backend/x86/cgreg.d b/compiler/src/dmd/backend/x86/cgreg.d index e3644d01f7c9..14dd12cf8c75 100644 --- a/compiler/src/dmd/backend/x86/cgreg.d +++ b/compiler/src/dmd/backend/x86/cgreg.d @@ -607,15 +607,15 @@ void cgreg_spillreg_epilog(block* b,Symbol* s,ref CodeBuilder cdbstore, ref Code const bi = b.Bdfoidx; //printf("cgreg_spillreg_epilog(block %d, s = '%s')\n",bi,s.Sident.ptr); //assert(b.bc == BC.goto_); - if (!cgreg_gotoepilog(b.nthSucc(0), s)) + if (!cgreg_gotoepilog(b.Bsuccx(0), s)) return; const live = vec_testbit(bi,s.Slvreg) != 0; // Look at successors to see if we need to load in/out of register - foreach (bl; ListRange(b.Bsucc)) + foreach (bl; BsuccArray(b.Bsucc)) { - const bpi = list_block(bl).Bdfoidx; + const bpi = bl.Bdfoidx; if (!vec_testbit(bpi,s.Srange)) continue; if (vec_testbit(bpi,s.Slvreg)) diff --git a/compiler/src/dmd/backend/x86/cod3.d b/compiler/src/dmd/backend/x86/cod3.d index 51da0e2a8446..f3f27fd00645 100644 --- a/compiler/src/dmd/backend/x86/cod3.d +++ b/compiler/src/dmd/backend/x86/cod3.d @@ -1060,8 +1060,8 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys case BC.iftrue: { bool jcond = true; - block* bs1 = bl.nthSucc(0); - block* bs2 = bl.nthSucc(1); + block* bs1 = bl.Bsuccx(0); + block* bs2 = bl.Bsuccx(1); if (bs1 == bl.Bnext) { // Swap bs1 and bs2 block* btmp; @@ -1117,7 +1117,7 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys } goto case_goto; case BC.goto_: - nextb = bl.nthSucc(0); + nextb = bl.Bsuccx(0); if ((MARS || funcsym_p.Sfunc.Fflags3 & Fnteh) && ehmethod(funcsym_p) != EHmethod.EH_DWARF && @@ -1132,7 +1132,7 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys if (toindex + 1 == fromindex) { // Simply call __finally if (bl.Btry && - bl.Btry.nthSucc(1).bc == BC.jcatch) + bl.Btry.Bsuccx(1).bc == BC.jcatch) { goto L5; // it's a try-catch, not a try-finally } @@ -1155,7 +1155,7 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys { block* bf; //printf("\tbt.Bscope_index = %d, bt.Blast_index = %d\n", bt.Bscope_index, bt.Blast_index); - bf = bt.nthSucc(1); + bf = bt.Bsuccx(1); // Only look at try-finally blocks if (bf.bc == BC.jcatch) continue; @@ -1165,11 +1165,11 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys //printf("\tbf = B%d, nextb = B%d\n", bf.Bdfoidx, nextb.Bdfoidx); if (nextb.bc == BC.goto_ && !nextb.Belem && - bf == nextb.nthSucc(0)) + bf == nextb.Bsuccx(0)) continue; // call __finally - cdb.append(callFinallyBlock(cg, bf.nthSucc(0), retregsx)); + cdb.append(callFinallyBlock(cg, bf.Bsuccx(0), retregsx)); } } } @@ -1197,7 +1197,7 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys cdb.append(cdbstore); cdb.append(cdbload); } - nextb = bl.nthSucc(0); + nextb = bl.Bsuccx(0); goto L5; } @@ -1231,8 +1231,8 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys regm_t retregsx = 0; gencodelem(cdb,bl.Belem,retregsx,true); - // JMP bl.nthSucc(1) - nextb = bl.nthSucc(1); + // JMP bl.Bsuccx(1) + nextb = bl.Bsuccx(1); goto L5; } @@ -1248,10 +1248,10 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys assert(!e); // Generate CALL to finalizer code - cdb.append(callFinallyBlock(cg, bl.nthSucc(0), 0)); + cdb.append(callFinallyBlock(cg, bl.Bsuccx(0), 0)); - // JMP bl.nthSucc(1) - nextb = bl.nthSucc(1); + // JMP bl.Bsuccx(1) + nextb = bl.Bsuccx(1); goto L5; } @@ -1266,8 +1266,8 @@ void outblkexitcode(ref CGstate cg, ref CodeBuilder cdb, block* bl, ref int anys regm_t retregsx = 0; gencodelem(cdb,bl.Belem,retregsx,true); - // JMP bl.nthSucc(0) - nextb = bl.nthSucc(0); + // JMP bl.Bsuccx(0) + nextb = bl.Bsuccx(0); goto L5; } @@ -1291,7 +1291,7 @@ static if (NTEXCEPTIONS) cg.usednteh |= NTEH_except; nteh_setsp(cg, cdb,0x8B); getregsNoSave(cg.allregs); - nextb = bl.nthSucc(0); + nextb = bl.Bsuccx(0); goto L5; } case BC._filter: @@ -1529,7 +1529,7 @@ static if (NTEXCEPTIONS) block* bt = bl; while ((bt = bt.Btry) != null) { - block* bf = bt.nthSucc(1); + block* bf = bt.Bsuccx(1); // Only look at try-finally blocks if (bf.bc == BC.jcatch) { @@ -1547,7 +1547,7 @@ static if (NTEXCEPTIONS) nteh_gensindex(cdb,-1); gensaverestore(cg,retregs,cdbs,cdbr); cdb.append(cdbs); - cdb.genc(0xE8,0,FL.unde,0,FL.block,cast(targ_size_t)bf.nthSucc(0)); + cdb.genc(0xE8,0,FL.unde,0,FL.block,cast(targ_size_t)bf.Bsuccx(0)); cg.regcon.immed.mval = 0; cdb.append(cdbr); } @@ -1560,7 +1560,7 @@ static if (NTEXCEPTIONS) else { // call __finally - cdb.append(callFinallyBlock(cg, bf.nthSucc(0), retregs)); + cdb.append(callFinallyBlock(cg, bf.Bsuccx(0), retregs)); } } } @@ -1582,7 +1582,7 @@ static if (NTEXCEPTIONS) getregs(cdbx, iasm_regs(bl)); // mark destroyed registers code* c = cdbx.finish(); if (bl.Bsucc) - { nextb = bl.nthSucc(0); + { nextb = bl.Bsuccx(0); if (!bl.Bnext) { cdb.append(bl.Bcode); @@ -1593,7 +1593,7 @@ static if (NTEXCEPTIONS) bl.Bnext && !(bl.Bnext.bc == BC.goto_ && !bl.Bnext.Belem && - nextb == bl.Bnext.nthSucc(0))) + nextb == bl.Bnext.Bsuccx(0))) { // See if already have JMP at end of block code* cl = code_last(bl.Bcode); @@ -2068,7 +2068,7 @@ void doswitch(ref CGstate cg, ref CodeBuilder cdb, block* b) reg2 = NOREG; } list_t bl = b.Bsucc; - block* bdefault = b.nthSucc(0); + block* bdefault = b.Bsuccx(0); if (dword && mswsame) { cdb.genc2(0x81,modregrm(3,7,reg2),msw); // CMP reg2,MSW @@ -2149,19 +2149,19 @@ void doswitch(ref CGstate cg, ref CodeBuilder cdb, block* b) cdb.genc2(0x81,modregrm(3,5,reg),cast(targ_size_t)vmin); // SUB reg,vmin if (dword) { cdb.genc2(0x81,modregrm(3,3,reg2),cast(targ_size_t)MSREG(vmin)); // SBB reg2,vmin - genjmp(cdb,JNE,FL.block,b.nthSucc(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.Bsuccx(0)); // JNE default } } else if (dword) { gentstreg(cdb,reg2); // TEST reg2,reg2 - genjmp(cdb,JNE,FL.block,b.nthSucc(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.Bsuccx(0)); // JNE default } if (vmax - vmin != REGMASK) // if there is a maximum { // CMP reg,vmax-vmin cdb.genc2(0x81,modregrm(3,7,reg),cast(targ_size_t)(vmax-vmin)); if (I64 && sz == 8) code_orrex(cdb.last(), REX_W); - genjmp(cdb,JA,FL.block,b.nthSucc(0)); // JA default + genjmp(cdb,JA,FL.block,b.Bsuccx(0)); // JA default } if (I64) { @@ -2216,14 +2216,14 @@ static if (JMPJMPTABLE) ... */ CodeBuilder ctable; ctable.ctor(); - block* bdef = b.nthSucc(0); + block* bdef = b.Bsuccx(0); targ_llong u; for (u = vmin; ; u++) { block* targ = bdef; foreach (n, val; b.Bswitch) { if (val == u) - { targ = b.nthSucc(n + 1); + { targ = b.Bsuccx(n + 1); break; } } @@ -2329,7 +2329,7 @@ else if (dword && mswsame) { /* CMP DX,MSW */ cdb.genc2(0x81,modregrm(3,7,DX),msw); - genjmp(cdb,JNE,FL.block,b.nthSucc(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.Bsuccx(0)); // JNE default } getregs(cdb,mCX|mDI); @@ -2403,7 +2403,7 @@ else cdb.gen1(0xF2); // REPNE cdb.gen1(0xAF); // SCASW } - genjmp(cdb,JNE,FL.block,b.nthSucc(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.Bsuccx(0)); // JNE default const int mod = (disp > 127) ? 2 : 1; // 1 or 2 byte displacement if (csseg) cdb.gen1(SEGCS); // table is in code segment @@ -2468,14 +2468,14 @@ void outjmptab(block* b) assert(*poffset == b.Btableoffset); // should match precomputed value Symbol* gotsym = null; - targ_size_t def = b.nthSucc(0).Boffset; // default address + targ_size_t def = b.Bsuccx(0).Boffset; // default address for (targ_llong u = vmin; ; u++) { targ_size_t targ = def; // default foreach (n; 0 .. ncases) { if (b.Bswitch[n] == u) { - targ = b.nthSucc(cast(int)(n + 1)).Boffset; + targ = b.Bsuccx(cast(int)(n + 1)).Boffset; break; } } diff --git a/compiler/src/dmd/backend/x86/cod5.d b/compiler/src/dmd/backend/x86/cod5.d index eeaba0e5f901..c9ad13ebcf75 100644 --- a/compiler/src/dmd/backend/x86/cod5.d +++ b/compiler/src/dmd/backend/x86/cod5.d @@ -118,9 +118,9 @@ else // See if b is an epilog mark = 0; - foreach (bl; ListRange(b.Bsucc)) + foreach (bl; BsuccArray(b.Bsucc)) { - if (list_block(bl).Bflags & BFL.outsideprolog) + if (bl.Bflags & BFL.outsideprolog) { if (mark == 2) goto L1; @@ -175,6 +175,7 @@ void cod5_noprol(block* startblock) * the function prolog. */ +@trusted private void pe_add(block* b) { if (b.Bflags & BFL.outsideprolog || @@ -182,8 +183,8 @@ private void pe_add(block* b) return; b.Bflags |= BFL.outsideprolog; - foreach (bl; ListRange(b.Bsucc)) - pe_add(list_block(bl)); + foreach (bl; BsuccArray(b.Bsucc)) + pe_add(bl); } /********************************************** diff --git a/compiler/src/dmd/glue/s2ir.d b/compiler/src/dmd/glue/s2ir.d index 048d0840ab39..41dee38b30e4 100644 --- a/compiler/src/dmd/glue/s2ir.d +++ b/compiler/src/dmd/glue/s2ir.d @@ -1351,11 +1351,11 @@ void Statement_toIR(Statement s, ref IRState irs, StmtState* stmtstate) if (b.bc == BC.goto_ && b.numSucc() == 1) { - block* bdest = b.nthSucc(0); + block* bdest = b.Bsuccx(0); if (btry && bdest.Btry != btry) { //printf("test1 b %p b.Btry %p bdest %p bdest.Btry %p\n", b, btry, bdest, bdest.Btry); - block* bfinally = btry.nthSucc(1); + block* bfinally = btry.Bsuccx(1); if (bfinally == finallyblock) { b.appendSucc(finallyblock); @@ -1366,7 +1366,7 @@ void Statement_toIR(Statement s, ref IRState irs, StmtState* stmtstate) // If the goto exits a try block, then the finally block is also a successor if (b.bc == BC.goto_ && b.numSucc() == 2) // if goto exited a tryblock { - block* bdest = b.nthSucc(0); + block* bdest = b.Bsuccx(0); // If the last finally block executed by the goto if (bdest.Btry == tryblock.Btry) @@ -1593,14 +1593,14 @@ void insertFinallyBlockCalls(block* startblock) *x BC._ret * breakblock */ - block* breakblock = b.nthSucc(0); + block* breakblock = b.Bsuccx(0); block* lasttry = breakblock.Btry; block* blast = b; ++flagvalue; for (block* bt = b.Btry; bt != lasttry; bt = bt.Btry) { assert(bt.bc == BC._try); - block* bf = bt.nthSucc(1); + block* bf = bt.Bsuccx(1); if (bf.bc == BC.jcatch) continue; // skip try-catch assert(bf.bc == BC._finally); @@ -1692,13 +1692,13 @@ void insertFinallyBlockGotos(block* startblock) { case BC._try: b.bc = BC.goto_; - list_subtract(&b.Bsucc, b.nthSucc(1)); + list_subtract(&b.Bsucc, b.Bsuccx(1)); break; case BC._finally: b.bc = BC.goto_; - list_subtract(&b.Bsucc, b.nthSucc(2)); - list_subtract(&b.Bsucc, b.nthSucc(0)); + list_subtract(&b.Bsucc, b.Bsuccx(2)); + list_subtract(&b.Bsucc, b.Bsuccx(0)); break; case BC._lpad: