Skip to content

Commit

Permalink
backend: Put BlockOpt globals in a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Korpel authored and thewilsonator committed Oct 15, 2024
1 parent b0bcf40 commit 163c73e
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 235 deletions.
144 changes: 73 additions & 71 deletions compiler/src/dmd/backend/blockopt.d

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions compiler/src/dmd/backend/cgcs.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ nothrow:
@trusted
public void comsubs(ref GlobalOptimizer go)
{
debug if (debugx) printf("comsubs(%p)\n",startblock);
debug if (debugx) printf("comsubs(%p)\n",bo.startblock);

comsubs2(startblock, cgcsdata, go);
comsubs2(bo.startblock, cgcsdata, go);

debug if (debugx)
printf("done with comsubs()\n");
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dmd/backend/dout.d
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ void out_regcand(symtab_t *psymtab)
}

bool addressOfParam = false; // haven't taken addr of param yet
for (block *b = startblock; b; b = b.Bnext)
for (block *b = bo.startblock; b; b = b.Bnext)
{
if (b.Belem)
out_regcand_walk(b.Belem, addressOfParam);
Expand Down Expand Up @@ -883,10 +883,10 @@ private void writefunc2(Symbol *sfunc, ref GlobalOptimizer go)
foreach (si; 0 .. nsymbols)
globsym[si] = f.Flocsym[si];

assert(startblock == null);
startblock = sfunc.Sfunc.Fstartblock;
assert(bo.startblock == null);
bo.startblock = sfunc.Sfunc.Fstartblock;
sfunc.Sfunc.Fstartblock = null;
assert(startblock);
assert(bo.startblock);

assert(funcsym_p == null);
funcsym_p = sfunc;
Expand Down Expand Up @@ -951,7 +951,7 @@ private void writefunc2(Symbol *sfunc, ref GlobalOptimizer go)

bool addressOfParam = false; // see if any parameters get their address taken
bool anyasm = false;
for (block *b = startblock; b; b = b.Bnext)
for (block *b = bo.startblock; b; b = b.Bnext)
{
memset(&b._BLU,0,block.sizeof - block._BLU.offsetof);
if (b.Belem)
Expand Down Expand Up @@ -996,7 +996,7 @@ private void writefunc2(Symbol *sfunc, ref GlobalOptimizer go)
{
if (debugb)
{
WRfunc("codegen", funcsym_p, startblock);
WRfunc("codegen", funcsym_p, bo.startblock);
}
}

Expand Down Expand Up @@ -1035,16 +1035,16 @@ private void writefunc2(Symbol *sfunc, ref GlobalOptimizer go)
//printf("codgen()\n");
codgen(sfunc); // generate code
//printf("after codgen for %s Coffset %x\n",sfunc.Sident.ptr,Offset(cseg));
sfunc.Sfunc.Fstartblock = startblock;
sfunc.Sfunc.Fstartblock = bo.startblock;
bool saveForInlining = canInlineFunction(sfunc);
if (saveForInlining)
{
startblock = null;
bo.startblock = null;
}
else
{
sfunc.Sfunc.Fstartblock = null;
blocklist_free(&startblock);
blocklist_free(&bo.startblock);
}

objmod.func_term(sfunc);
Expand Down
28 changes: 14 additions & 14 deletions compiler/src/dmd/backend/eh.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void except_fillInEHTable(Symbol *s)
// First, calculate starting catch offset
int guarddim = 0; // max dimension of guard[]
int ndctors = 0; // number of PSOP.dctor's
foreach (b; BlockRange(startblock))
foreach (b; BlockRange(bo.startblock))
{
if (b.BC == BC_try && b.Bscope_index >= guarddim)
guarddim = b.Bscope_index + 1;
Expand All @@ -164,7 +164,7 @@ void except_fillInEHTable(Symbol *s)

// Generate guard[]
int i = 0;
foreach (b; BlockRange(startblock))
foreach (b; BlockRange(bo.startblock))
{
//printf("b = %p, b.Btry = %p, b.offset = %x\n", b, b.Btry, b.Boffset);
if (b.BC == BC_try)
Expand All @@ -182,7 +182,7 @@ void except_fillInEHTable(Symbol *s)
if (config.ehmethod == EHmethod.EH_DM)
{
//printf("DHandlerInfo: offset = %x", cast(int)(b.Boffset - startblock.Boffset));
dtb.dword(cast(int)(b.Boffset - startblock.Boffset)); // offset to start of block
dtb.dword(cast(int)(b.Boffset - bo.startblock.Boffset)); // offset to start of block

// Compute ending offset
uint endoffset;
Expand All @@ -191,7 +191,7 @@ void except_fillInEHTable(Symbol *s)
//printf("\tbn = %p, bn.Btry = %p, bn.offset = %x\n", bn, bn.Btry, bn.Boffset);
assert(bn);
if (bn.Btry == b.Btry)
{ endoffset = cast(uint)(bn.Boffset - startblock.Boffset);
{ endoffset = cast(uint)(bn.Boffset - bo.startblock.Boffset);
break;
}
}
Expand Down Expand Up @@ -220,8 +220,8 @@ void except_fillInEHTable(Symbol *s)
// finally handler address
if (config.ehmethod == EHmethod.EH_DM)
{
assert(bhandler.Boffset > startblock.Boffset);
dtb.size(bhandler.Boffset - startblock.Boffset); // finally handler offset
assert(bhandler.Boffset > bo.startblock.Boffset);
dtb.size(bhandler.Boffset - bo.startblock.Boffset); // finally handler offset
}
else
dtb.coff(cast(uint)bhandler.Boffset);
Expand All @@ -239,7 +239,7 @@ void except_fillInEHTable(Symbol *s)
Barray!int stack;

int scopeindex = guarddim;
foreach (b; BlockRange(startblock))
foreach (b; BlockRange(bo.startblock))
{
/* Set up stack of scope indices
*/
Expand All @@ -254,7 +254,7 @@ void except_fillInEHTable(Symbol *s)
if (config.ehmethod == EHmethod.EH_WIN32)
nteh_patchindex(c2, scopeindex);
if (config.ehmethod == EHmethod.EH_DM)
dtb.dword(cast(int)(boffset - startblock.Boffset)); // guard offset
dtb.dword(cast(int)(boffset - bo.startblock.Boffset)); // guard offset
// Find corresponding ddtor instruction
int n = 0;
uint eoffset = boffset;
Expand Down Expand Up @@ -290,7 +290,7 @@ void except_fillInEHTable(Symbol *s)
//cf = code_next(cf);
//foffset += calccodsize(cf);
if (config.ehmethod == EHmethod.EH_DM)
dtb.dword(cast(int)(eoffset - startblock.Boffset)); // guard offset
dtb.dword(cast(int)(eoffset - bo.startblock.Boffset)); // guard offset
break;
}
}
Expand All @@ -306,8 +306,8 @@ void except_fillInEHTable(Symbol *s)
dtb.dword(0); // no catch offset
if (config.ehmethod == EHmethod.EH_DM)
{
assert(foffset > startblock.Boffset);
dtb.size(foffset - startblock.Boffset); // finally handler offset
assert(foffset > bo.startblock.Boffset);
dtb.size(foffset - bo.startblock.Boffset); // finally handler offset
}
else
dtb.coff(foffset); // finally handler address
Expand All @@ -328,7 +328,7 @@ void except_fillInEHTable(Symbol *s)
}

// Generate catch[]
foreach (b; BlockRange(startblock))
foreach (b; BlockRange(bo.startblock))
{
if (b.BC == BC_try && b.jcatchvar) // if try-catch
{
Expand All @@ -347,8 +347,8 @@ void except_fillInEHTable(Symbol *s)
// catch handler address
if (config.ehmethod == EHmethod.EH_DM)
{
assert(bcatch.Boffset > startblock.Boffset);
dtb.size(bcatch.Boffset - startblock.Boffset); // catch handler offset
assert(bcatch.Boffset > bo.startblock.Boffset);
dtb.size(bcatch.Boffset - bo.startblock.Boffset); // catch handler offset
}
else
dtb.coff(cast(uint)bcatch.Boffset);
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dmd/backend/gdag.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void builddags(ref GlobalOptimizer go)
vec_t aevec;

debug if (debugc) printf("builddags()\n");
assert(dfo);
assert(bo.dfo);
flowae(go); /* compute available expressions */
if (go.exptop <= 1) /* if no AEs */
return;
Expand Down Expand Up @@ -130,14 +130,14 @@ void builddags(ref GlobalOptimizer go)
/* the code generator can only track register contents */
/* properly across extended basic blocks. */
aevec = vec_calloc(go.exptop);
foreach (i, b; dfo[])
foreach (i, b; bo.dfo[])
{
/* if not first block and (there are more than one */
/* predecessor or the only predecessor is not the */
/* previous block), then zero out the available */
/* expressions. */
if ((i != 0 &&
(list_block(b.Bpred) != dfo[i - 1] ||
(list_block(b.Bpred) != bo.dfo[i - 1] ||
list_next(b.Bpred) != null))
|| b.BC == BCasm
|| b.BC == BC_finally
Expand All @@ -154,7 +154,7 @@ void builddags(ref GlobalOptimizer go)

// Need 2 passes to converge on solution
foreach (j; 0 .. 2)
foreach (b; dfo[])
foreach (b; bo.dfo[])
{
if (b.Belem)
{
Expand Down Expand Up @@ -598,8 +598,8 @@ void boolopt(ref GlobalOptimizer go)
vec_t aevecval;

debug if (debugc) printf("boolopt()\n");
if (!dfo.length)
compdfo(dfo, startblock);
if (!bo.dfo.length)
compdfo(bo.dfo, bo.startblock);
flowae(go); /* compute available expressions */
if (go.exptop <= 1) /* if no AEs */
return;
Expand Down Expand Up @@ -633,14 +633,14 @@ void boolopt(ref GlobalOptimizer go)
}
}

foreach (i, b; dfo[])
foreach (i, b; bo.dfo[])
{
/* if not first block and (there are more than one */
/* predecessor or the only predecessor is not the */
/* previous block), then zero out the available */
/* expressions. */
if ((i != 0 &&
(list_block(b.Bpred) != dfo[i - 1] ||
(list_block(b.Bpred) != bo.dfo[i - 1] ||
list_next(b.Bpred) != null))
|| b.BC == BCasm
|| b.BC == BC_finally
Expand Down
38 changes: 19 additions & 19 deletions compiler/src/dmd/backend/gflow.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ void flowrd(ref GlobalOptimizer go)
/* Bout = (Bin - Bkill) | Bgen */
/* Using Ullman's algorithm: */

foreach (b; dfo[])
foreach (b; bo.dfo[])
vec_copy(b.Boutrd, b.Bgen);

bool anychng;
vec_t tmp = vec_calloc(go.defnod.length);
do
{
anychng = false;
foreach (b; dfo[]) // for each block
foreach (b; bo.dfo[]) // for each block
{
/* Binrd = union of Boutrds of all predecessors of b */
vec_clear(b.Binrd);
Expand Down Expand Up @@ -160,7 +160,7 @@ private void rdgenkill(ref GlobalOptimizer go)
/* Compute number of definition elems. */
uint num_unambig_def = 0;
uint deftop = 0;
foreach (b; dfo[]) // for each block
foreach (b; bo.dfo[]) // for each block
if (b.Belem)
{
deftop += numdefelems(b.Belem, num_unambig_def);
Expand All @@ -183,14 +183,14 @@ private void rdgenkill(ref GlobalOptimizer go)

go.defnod.setLength(deftop);
size_t i = deftop;
foreach_reverse (b; dfo[]) // for each block
foreach_reverse (b; bo.dfo[]) // for each block
if (b.Belem)
asgdefelems(b, b.Belem, go.defnod[], i); // fill in go.defnod[]
assert(i == 0);

initDNunambigVectors(go, go.defnod[]);

foreach (b; dfo[]) // for each block
foreach (b; bo.dfo[]) // for each block
{
/* dump any existing vectors */
vec_free(b.Bgen);
Expand Down Expand Up @@ -552,13 +552,13 @@ private void flowaecp(ref GlobalOptimizer go, int flowxx)
/* Bout = (Bin - Bkill) | Bgen */
/* Using Ullman's algorithm: */

vec_clear(startblock.Bin);
vec_copy(startblock.Bout,startblock.Bgen); /* these never change */
if (startblock.BC == BCiftrue)
vec_copy(startblock.Bout2,startblock.Bgen2); // these never change
vec_clear(bo.startblock.Bin);
vec_copy(bo.startblock.Bout,bo.startblock.Bgen); /* these never change */
if (bo.startblock.BC == BCiftrue)
vec_copy(bo.startblock.Bout2,bo.startblock.Bgen2); // these never change

/* For all blocks except startblock */
foreach (b; dfo[1 .. $])
foreach (b; bo.dfo[1 .. $])
{
vec_set(b.Bin); /* Bin = all expressions */

Expand All @@ -579,7 +579,7 @@ private void flowaecp(ref GlobalOptimizer go, int flowxx)
anychng = false;

// For all blocks except startblock
foreach (b; dfo[1 .. $])
foreach (b; bo.dfo[1 .. $])
{
// Bin = & of Bout of all predecessors
// Bout = (Bin - Bkill) | Bgen
Expand Down Expand Up @@ -782,7 +782,7 @@ private void aecpgenkill(ref GlobalOptimizer go, int flowxx)
go.expblk.setLength(0); // dump any existing one
go.expblk.push(null);

foreach (b; dfo[])
foreach (b; bo.dfo[])
{
if (b.Belem)
{
Expand Down Expand Up @@ -813,7 +813,7 @@ private void aecpgenkill(ref GlobalOptimizer go, int flowxx)
{ dbg_printf("vptrkill "); vec_println(go.vptrkill); }
}

foreach (i, b; dfo[])
foreach (i, b; bo.dfo[])
{
/* dump any existing vectors */
vec_free(b.Bin);
Expand Down Expand Up @@ -1026,7 +1026,7 @@ void genkillae(ref GlobalOptimizer go)
{
flowxx = AE;
assert(go.exptop > 1);
foreach (b; dfo[])
foreach (b; bo.dfo[])
{
assert(b);
vec_clear(b.Bgen);
Expand Down Expand Up @@ -1354,7 +1354,7 @@ void flowlv()
/* Bout = union of Bin of all successors to B. */
/* Using Ullman's algorithm: */

foreach (b; dfo[])
foreach (b; bo.dfo[])
{
vec_copy(b.Binlv, b.Bgen); // Binlv = Bgen
}
Expand All @@ -1367,7 +1367,7 @@ void flowlv()
anychng = false;

/* For each block B in reverse DFO order */
foreach_reverse (b; dfo[])
foreach_reverse (b; bo.dfo[])
{
/* Bout = union of Bins of all successors to B. */
bool first = true;
Expand Down Expand Up @@ -1444,7 +1444,7 @@ private void lvgenkill()
}
}

foreach (b; dfo[])
foreach (b; bo.dfo[])
{
vec_free(b.Bgen);
vec_free(b.Bkill);
Expand Down Expand Up @@ -1690,7 +1690,7 @@ void flowvbe(ref GlobalOptimizer go)
/*printf("defkill = "); vec_println(go.defkill);
printf("starkill = "); vec_println(go.starkill);*/

foreach (b; dfo[])
foreach (b; bo.dfo[])
{
/*printf("block %p\n",b);
printf("Bgen = "); vec_println(b.Bgen);
Expand All @@ -1713,7 +1713,7 @@ void flowvbe(ref GlobalOptimizer go)
anychng = false;

/* for all blocks except return blocks in reverse dfo order */
foreach_reverse (b; dfo[])
foreach_reverse (b; bo.dfo[])
{
if (b.BC == BCret || b.BC == BCretexp || b.BC == BCexit)
continue;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/global.d
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ extern (D) regm_t mask(uint m) { return cast(regm_t)1 << m; }

public import dmd.backend.var : OPTIMIZER, PARSER, globsym, controlc_saw, pointertype, sytab;
public import dmd.backend.cg : fregsaved, localgot, tls_get_addr_sym;
public import dmd.backend.blockopt : startblock, dfo, curblock, block_last;
public import dmd.backend.blockopt : bo;

__gshared Configv configv; // non-ph part of configuration

Expand Down
Loading

0 comments on commit 163c73e

Please sign in to comment.