Skip to content

Commit 48d3fa5

Browse files
committed
3rd attempt to make Bsucc an array
1 parent 2990bc7 commit 48d3fa5

12 files changed

Lines changed: 75 additions & 28 deletions

File tree

compiler/src/dmd/backend/barray.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ struct Barray(T)
190190
*/
191191
bool equals(ref const Barray rhs)
192192
{
193-
if (array.length != rhs.length)
194-
return false;
193+
if (array.length != rhs.length)
194+
return false;
195195
foreach (i, ref t; array)
196196
{
197197
if (t != rhs.array[i])

compiler/src/dmd/backend/blockopt.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ void block_free(ref BlockOpt bo, block* b)
307307
if (b.Belem)
308308
el_free(b.Belem);
309309
list_free(&b.Bsucc,FPNULL);
310+
b.Bsucca.dtor();
310311
b.Bpred.dtor();
311312
if (OPTIMIZER)
312313
block_optimizer_free(b);

compiler/src/dmd/backend/cc.d

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ nothrow:
205205
block* Bnext; // pointer to next block in list
206206
list_t Bsucc; // linked list of pointers to successors
207207
// of this block
208+
Barray!(block*) Bsucca; // and the successor array copy of Bsucc
208209
Barray!(block*) Bpred; // and the predecessor array
209210
int Bindex; // into created object stack
210211
int Bendindex; // index at end of block
@@ -335,6 +336,44 @@ nothrow:
335336
@trusted
336337
inout(block)* list_block(inout list_t lst) { return cast(inout(block)*)list_ptr(lst); }
337338

339+
// Convert Bsucc to Bsucca
340+
void convertBsuccToBsucca(block *b)
341+
{
342+
for (; b; b = b.Bnext)
343+
{
344+
convertOneBsuccToBsucca(b);
345+
}
346+
}
347+
348+
void convertOneBsuccToBsucca(block *b)
349+
{
350+
int n = list_nitems(b.Bsucc);
351+
b.Bsucca.setLength(n);
352+
int i;
353+
foreach (bp; ListRange(b.Bsucc))
354+
{
355+
b.Bsucca[i] = list_block(bp);
356+
++i;
357+
}
358+
assert(i == b.Bsucca.length);
359+
}
360+
361+
// Verify Bsucc has same contents as Bsucca
362+
void verifyBsuccMatchesBsucca(block *b)
363+
{
364+
for (; b; b = b.Bnext)
365+
{
366+
int n = list_nitems(b.Bsucc);
367+
assert(n == b.Bsucca.length);
368+
int i;
369+
foreach (bp; ListRange(b.Bsucc))
370+
{
371+
assert(b.Bsucca[i] == list_block(bp));
372+
++i;
373+
}
374+
}
375+
}
376+
338377
/** Basic block control flow operators. **/
339378

340379
enum BC : ubyte

compiler/src/dmd/backend/gflow.d

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ void flowlv(ref BlockOpt bo)
13391339
foreach (b; bo.dfo[])
13401340
{
13411341
vec_copy(b.Binlv, b.Bgen); // Binlv = Bgen
1342+
convertOneBsuccToBsucca(b);
13421343
}
13431344

13441345
vec_t tmp = vec_calloc(globsym.length);
@@ -1353,9 +1354,10 @@ void flowlv(ref BlockOpt bo)
13531354
{
13541355
/* Bout = union of Bins of all successors to B. */
13551356
bool first = true;
1356-
foreach (bl; ListRange(b.Bsucc))
1357+
foreach (bl; b.Bsucca[])
1358+
//foreach (bl; ListRange(b.Bsucc))
13571359
{
1358-
const inlv = list_block(bl).Binlv;
1360+
const inlv = bl.Binlv;
13591361
if (first)
13601362
vec_copy(b.Boutlv, inlv);
13611363
else
@@ -1656,6 +1658,7 @@ private void accumlv(vec_t GEN, vec_t KILL, const(elem)* n, const vec_t ambigsym
16561658
@trusted
16571659
void flowvbe(ref GlobalOptimizer go, ref BlockOpt bo)
16581660
{
1661+
if (1) assert(0);
16591662
go.flowxx = VBE;
16601663
aecpgenkill(go, bo); // compute Bgen and Bkill for VBEs
16611664
if (go.exptop <= 1) /* if no candidates for VBEs */

compiler/src/dmd/backend/gother.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,10 @@ 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+
1070+
convertOneBsuccToBsucca(start);
1071+
foreach (b; start.Bsucca[])
10701072
{
1071-
block* b = cast(block*) list_ptr(list);
10721073
if (b != rel && (b == inc || loopcheck(b,inc,rel)))
10731074
return true;
10741075
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void codgen(Symbol* sfunc)
8888
/***********************
8989
* Same as codgen(), but adding in CGstate argument
9090
* Params:
91-
* cg = code generator state
91+
* cg = code generator state
9292
* sfunc = function to generate code for
9393
*/
9494
private @trusted
@@ -98,6 +98,10 @@ void codgenx(ref CGstate cg, Symbol* sfunc)
9898
assert(sfunc == funcsym_p);
9999
assert(cseg == funcsym_p.Sseg);
100100

101+
// Convert Bsucc to Bsucca
102+
convertBsuccToBsucca(bo.startblock);
103+
verifyBsuccMatchesBsucca(bo.startblock);
104+
101105
cgreg_init();
102106
CSE.initialize();
103107

@@ -2131,7 +2135,7 @@ bool cssave(elem* e, regm_t regm, bool opsflag)
21312135
/*if (e.Ecount && e.Ecount == e.Ecomsub)*/
21322136
if (e.Ecount && e.Ecomsub)
21332137
{
2134-
CGstate* cg = &cgstate;
2138+
CGstate* cg = &cgstate;
21352139
if (!opsflag && cg.pass != BackendPass.final_ && (I32 || I64))
21362140
return false;
21372141

@@ -2579,7 +2583,7 @@ private void loadcse(ref CodeBuilder cdb,elem* e,reg_t reg,regm_t regm)
25792583
//printf("CSE[%d] = %p, regm = %s\n", i, cse.e, regm_str(cse.regm));
25802584
if (cse.regm & regm)
25812585
{
2582-
CGstate* cg = &cgstate;
2586+
CGstate* cg = &cgstate;
25832587
cg.reflocal = true;
25842588
cse.flags |= CSEload; /* it was loaded */
25852589
cg.regcon.cse.value[reg] = e;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,15 @@ void cgreg_spillreg_epilog(block* b,Symbol* s,ref CodeBuilder cdbstore, ref Code
607607
const bi = b.Bdfoidx;
608608
//printf("cgreg_spillreg_epilog(block %d, s = '%s')\n",bi,s.Sident.ptr);
609609
//assert(b.bc == BC.goto_);
610-
if (!cgreg_gotoepilog(b.nthSucc(0), s))
610+
if (!cgreg_gotoepilog(b.Bsucca[0], s))
611611
return;
612612

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 (bs; b.Bsucca[])
617617
{
618-
const bpi = list_block(bl).Bdfoidx;
618+
const bpi = bs.Bdfoidx;
619619
if (!vec_testbit(bpi,s.Srange))
620620
continue;
621621
if (vec_testbit(bpi,s.Slvreg))

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,8 +1581,8 @@ static if (NTEXCEPTIONS)
15811581
cg.refparam |= bl.bIasmrefparam;
15821582
getregs(cdbx, iasm_regs(bl)); // mark destroyed registers
15831583
code* c = cdbx.finish();
1584-
if (bl.Bsucc)
1585-
{ nextb = bl.nthSucc(0);
1584+
if (bl.Bsucca.length)
1585+
{ nextb = bl.Bsucca[0];
15861586
if (!bl.Bnext)
15871587
{
15881588
cdb.append(bl.Bcode);
@@ -2067,8 +2067,7 @@ void doswitch(ref CGstate cg, ref CodeBuilder cdb, block* b)
20672067
reg = findreg(retregs); // reg that result is in
20682068
reg2 = NOREG;
20692069
}
2070-
list_t bl = b.Bsucc;
2071-
block* bdefault = b.nthSucc(0);
2070+
block* bdefault = b.Bsucca[0];
20722071
if (dword && mswsame)
20732072
{
20742073
cdb.genc2(0x81,modregrm(3,7,reg2),msw); // CMP reg2,MSW
@@ -2088,8 +2087,7 @@ void doswitch(ref CGstate cg, ref CodeBuilder cdb, block* b)
20882087
foreach (n, val; b.Bswitch)
20892088
{
20902089
casevals[n].val = val;
2091-
bl = list_next(bl);
2092-
casevals[n].target = list_block(bl);
2090+
casevals[n].target = b.Bsucca[1 + n];
20932091

20942092
// See if we need a scratch register
20952093
if (!cg.AArch64 && sreg == NOREG && I64 && sz == 8 && val != cast(int)val)
@@ -2564,11 +2562,9 @@ void outswitab(block* b)
25642562
assert(*poffset == offset);
25652563
}
25662564

2567-
list_t bl = b.Bsucc;
25682565
foreach (n; 0 .. ncases) // send out address table
25692566
{
2570-
bl = list_next(bl);
2571-
objmod.reftocodeseg(seg,*poffset,list_block(bl).Boffset);
2567+
objmod.reftocodeseg(seg,*poffset,b.Bsucca[1 + n].Boffset);
25722568
*poffset += tysize(TYnptr);
25732569
}
25742570
assert(*poffset == offset + ncases * tysize(TYnptr));

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

Lines changed: 4 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; b.Bsucca[])
122122
{
123-
if (list_block(bl).Bflags & BFL.outsideprolog)
123+
if (bl.Bflags & BFL.outsideprolog)
124124
{
125125
if (mark == 2)
126126
goto L1;
@@ -182,8 +182,8 @@ private void pe_add(block* b)
182182
return;
183183

184184
b.Bflags |= BFL.outsideprolog;
185-
foreach (bl; ListRange(b.Bsucc))
186-
pe_add(list_block(bl));
185+
foreach (bl; b.Bsucca[])
186+
pe_add(bl);
187187
}
188188

189189
/**********************************************

compiler/src/dmd/declaration.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,9 @@ extern (C++) final class SymbolDeclaration : Declaration
711711
/***********************************************************
712712
* Generate Identifier for TypeInfo corresponding to `t`
713713
* Params:
714-
* t = type to generate TypeInfo identifier for
714+
* t = type to generate TypeInfo identifier for
715715
* Returns:
716-
* the identifier
716+
* the identifier
717717
*/
718718
private Identifier getTypeInfoIdent(Type t)
719719
{

0 commit comments

Comments
 (0)