diff --git a/compiler/src/dmd/backend/blockopt.d b/compiler/src/dmd/backend/blockopt.d index 91da55690df4..3bc503131ecd 100644 --- a/compiler/src/dmd/backend/blockopt.d +++ b/compiler/src/dmd/backend/blockopt.d @@ -519,8 +519,8 @@ void brcombine(ref GlobalOptimizer go, ref BlockOpt bo) const bc = b.bc; if (bc == BC.iftrue) { - block* b2 = b.Bsuccx(0); - block* b3 = b.Bsuccx(1); + block* b2 = b.nthSucc(0); + block* b3 = b.nthSucc(1); if (b2.Bpred.length > 1) // if more than one predecessor continue; @@ -533,7 +533,7 @@ void brcombine(ref GlobalOptimizer go, ref BlockOpt bo) const bc2 = b2.bc; if (bc2 == BC.goto_ && - b3 == b2.Bsuccx(0)) + b3 == b2.nthSucc(0)) { b.bc = BC.goto_; if (b2.Belem) @@ -570,9 +570,9 @@ void brcombine(ref GlobalOptimizer go, ref BlockOpt bo) } else if (bc2 == BC.goto_ && b3.bc == BC.goto_ && - b2.Bsuccx(0) == b3.Bsuccx(0)) + b2.nthSucc(0) == b3.nthSucc(0)) { - block* bsucc = b2.Bsuccx(0); + block* bsucc = b2.nthSucc(0); if (b2.Belem) { elem* e; @@ -680,13 +680,13 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) if (iftrue(n)) /* if elem is true */ { // select first succ - db = b.Bsuccx(1); + db = b.nthSucc(1); goto L1; } else if (iffalse(n)) { // select second succ - db = b.Bsuccx(0); + db = b.nthSucc(0); L1: list_subtract(&(b.Bsucc),db); @@ -699,11 +699,11 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) } /* Look for both destinations being the same */ - else if (b.Bsuccx(0) == - b.Bsuccx(1)) + else if (b.nthSucc(0) == + b.nthSucc(1)) { b.bc = BC.goto_; - db = b.Bsuccx(0); + db = b.nthSucc(0); list_subtract(&(b.Bsucc),db); db.Bpred.subtract(b); debug if (debugc) printf("CHANGE: if (e) goto L1; else goto L1;\n"); @@ -727,7 +727,7 @@ private void bropt(ref GlobalOptimizer go, ref BlockOpt bo) break; } } - block* db = b.Bsuccx(i); + block* db = b.nthSucc(i); /* delete predecessors of successors (!) */ foreach (bl; ListRange(b.Bsucc)) @@ -776,7 +776,7 @@ private void brrear(ref BlockOpt bo) static if (NTEXCEPTIONS) enum additionalAnd = "b.Btry == bt.Btry && - bt.Btry == bt.Bsuccx(0).Btry"; + bt.Btry == bt.nthSucc(0).Btry"; else enum additionalAnd = "true"; @@ -814,8 +814,8 @@ private void brrear(ref BlockOpt bo) if (b.bc == BC.iftrue || b.bc == BC.iffalse) { - block* bif = b.Bsuccx(0); - block* belse = b.Bsuccx(1); + block* bif = b.nthSucc(0); + block* belse = b.nthSucc(1); if (bif == b.Bnext) { diff --git a/compiler/src/dmd/backend/cc.d b/compiler/src/dmd/backend/cc.d index eeadd25176a1..0d7f08fcf4b2 100644 --- a/compiler/src/dmd/backend/cc.d +++ b/compiler/src/dmd/backend/cc.d @@ -325,16 +325,13 @@ 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); } diff --git a/compiler/src/dmd/backend/cgcs.d b/compiler/src/dmd/backend/cgcs.d index 309185be29ce..a0f1fa8f2210 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.Bsuccx(1) == bln) || - (blc.bc == BC.goto_ && blc.Bsuccx(0) == bln) + blc.nthSucc(1) == bln) || + (blc.bc == BC.goto_ && blc.nthSucc(0) == bln) ) && bln.bc != BC.asm_ // no CSE's extending across ASM blocks ) diff --git a/compiler/src/dmd/backend/dwarfeh.d b/compiler/src/dmd/backend/dwarfeh.d index 1615725dd963..e9e5fec4fd2c 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.Bsuccx(1); + block* bf = b.nthSucc(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.Bsuccx(0).Boffset; + d.lpad = cast(uint)bf.nthSucc(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 aa5f0e532c45..64f5c649ceab 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.Bsuccx(1); + block* bhandler = b.nthSucc(1); assert(bhandler.bc == BC._finally); // To successor of BC._finally block - bhandler = bhandler.Bsuccx(0); + bhandler = bhandler.nthSucc(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.Bsuccx(j); + block* bcatch = b.nthSucc(j); dtb.xoff(bcatch.Bcatchtype,0,TYnptr); diff --git a/compiler/src/dmd/backend/gflow.d b/compiler/src/dmd/backend/gflow.d index 978c216b8156..c031b4f55c3b 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.Bsuccx(0) != b) + if (bp.bc == BC.iftrue && bp.nthSucc(0) != b) { if (first) vec_copy(b.Bin,bp.Bout2); diff --git a/compiler/src/dmd/backend/inliner.d b/compiler/src/dmd/backend/inliner.d index 50261ef98981..9bf090530a52 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.Bsuccx(0)) + if (b.Bnext != b.nthSucc(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 b5970971f128..e3644d01f7c9 100644 --- a/compiler/src/dmd/backend/x86/cgreg.d +++ b/compiler/src/dmd/backend/x86/cgreg.d @@ -607,7 +607,7 @@ 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.Bsuccx(0), s)) + if (!cgreg_gotoepilog(b.nthSucc(0), s)) return; const live = vec_testbit(bi,s.Slvreg) != 0; diff --git a/compiler/src/dmd/backend/x86/cod3.d b/compiler/src/dmd/backend/x86/cod3.d index f3f27fd00645..51da0e2a8446 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.Bsuccx(0); - block* bs2 = bl.Bsuccx(1); + block* bs1 = bl.nthSucc(0); + block* bs2 = bl.nthSucc(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.Bsuccx(0); + nextb = bl.nthSucc(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.Bsuccx(1).bc == BC.jcatch) + bl.Btry.nthSucc(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.Bsuccx(1); + bf = bt.nthSucc(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.Bsuccx(0)) + bf == nextb.nthSucc(0)) continue; // call __finally - cdb.append(callFinallyBlock(cg, bf.Bsuccx(0), retregsx)); + cdb.append(callFinallyBlock(cg, bf.nthSucc(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.Bsuccx(0); + nextb = bl.nthSucc(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.Bsuccx(1) - nextb = bl.Bsuccx(1); + // JMP bl.nthSucc(1) + nextb = bl.nthSucc(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.Bsuccx(0), 0)); + cdb.append(callFinallyBlock(cg, bl.nthSucc(0), 0)); - // JMP bl.Bsuccx(1) - nextb = bl.Bsuccx(1); + // JMP bl.nthSucc(1) + nextb = bl.nthSucc(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.Bsuccx(0) - nextb = bl.Bsuccx(0); + // JMP bl.nthSucc(0) + nextb = bl.nthSucc(0); goto L5; } @@ -1291,7 +1291,7 @@ static if (NTEXCEPTIONS) cg.usednteh |= NTEH_except; nteh_setsp(cg, cdb,0x8B); getregsNoSave(cg.allregs); - nextb = bl.Bsuccx(0); + nextb = bl.nthSucc(0); goto L5; } case BC._filter: @@ -1529,7 +1529,7 @@ static if (NTEXCEPTIONS) block* bt = bl; while ((bt = bt.Btry) != null) { - block* bf = bt.Bsuccx(1); + block* bf = bt.nthSucc(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.Bsuccx(0)); + cdb.genc(0xE8,0,FL.unde,0,FL.block,cast(targ_size_t)bf.nthSucc(0)); cg.regcon.immed.mval = 0; cdb.append(cdbr); } @@ -1560,7 +1560,7 @@ static if (NTEXCEPTIONS) else { // call __finally - cdb.append(callFinallyBlock(cg, bf.Bsuccx(0), retregs)); + cdb.append(callFinallyBlock(cg, bf.nthSucc(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.Bsuccx(0); + { nextb = bl.nthSucc(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.Bsuccx(0))) + nextb == bl.Bnext.nthSucc(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.Bsuccx(0); + block* bdefault = b.nthSucc(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.Bsuccx(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.nthSucc(0)); // JNE default } } else if (dword) { gentstreg(cdb,reg2); // TEST reg2,reg2 - genjmp(cdb,JNE,FL.block,b.Bsuccx(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.nthSucc(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.Bsuccx(0)); // JA default + genjmp(cdb,JA,FL.block,b.nthSucc(0)); // JA default } if (I64) { @@ -2216,14 +2216,14 @@ static if (JMPJMPTABLE) ... */ CodeBuilder ctable; ctable.ctor(); - block* bdef = b.Bsuccx(0); + block* bdef = b.nthSucc(0); targ_llong u; for (u = vmin; ; u++) { block* targ = bdef; foreach (n, val; b.Bswitch) { if (val == u) - { targ = b.Bsuccx(n + 1); + { targ = b.nthSucc(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.Bsuccx(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.nthSucc(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.Bsuccx(0)); // JNE default + genjmp(cdb,JNE,FL.block,b.nthSucc(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.Bsuccx(0).Boffset; // default address + targ_size_t def = b.nthSucc(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.Bsuccx(cast(int)(n + 1)).Boffset; + targ = b.nthSucc(cast(int)(n + 1)).Boffset; break; } } diff --git a/compiler/src/dmd/glue/s2ir.d b/compiler/src/dmd/glue/s2ir.d index 41dee38b30e4..048d0840ab39 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.Bsuccx(0); + block* bdest = b.nthSucc(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.Bsuccx(1); + block* bfinally = btry.nthSucc(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.Bsuccx(0); + block* bdest = b.nthSucc(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.Bsuccx(0); + block* breakblock = b.nthSucc(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.Bsuccx(1); + block* bf = bt.nthSucc(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.Bsuccx(1)); + list_subtract(&b.Bsucc, b.nthSucc(1)); break; case BC._finally: b.bc = BC.goto_; - list_subtract(&b.Bsucc, b.Bsuccx(2)); - list_subtract(&b.Bsucc, b.Bsuccx(0)); + list_subtract(&b.Bsucc, b.nthSucc(2)); + list_subtract(&b.Bsucc, b.nthSucc(0)); break; case BC._lpad: