Skip to content

Commit

Permalink
move pass to CGstate
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed May 15, 2024
1 parent 6501c91 commit 4b8318b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
28 changes: 13 additions & 15 deletions compiler/src/dmd/backend/cgcod.d
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ uint usednteh; // if !=0, then used NT exception handling

/* Register contents */
con_t regcon;

BackendPass pass;
}

/*********************************
Expand Down Expand Up @@ -121,13 +119,13 @@ void codgen(Symbol *sfunc)
* pass can generate opportunities for enregistering more variables,
* loop until no more registers are free'd up.
*/
pass = BackendPass.initial;
cgstate.pass = BackendPass.initial;
while (1)
{
debug
if (debugr)
printf("------------------ PASS%s -----------------\n",
(pass == BackendPass.initial) ? "init".ptr : ((pass == BackendPass.reg) ? "reg".ptr : "final".ptr));
(cgstate.pass == BackendPass.initial) ? "init".ptr : ((cgstate.pass == BackendPass.reg) ? "reg".ptr : "final".ptr));

cgstate.lastRetregs[] = 0;

Expand Down Expand Up @@ -229,14 +227,14 @@ void codgen(Symbol *sfunc)
}
else
{
pass = BackendPass.final_;
cgstate.pass = BackendPass.final_;
for (block* b = startblock; b; b = b.Bnext)
blcodgen(b); // generate the code for each block
}
regcon.immed.mval = 0;
assert(!regcon.cse.mops); // should have all been used

if (pass == BackendPass.final_ || // the final pass, so exit
if (cgstate.pass == BackendPass.final_ || // the final pass, so exit
anyiasm) // possible LEA or LES opcodes
{
break;
Expand All @@ -250,12 +248,12 @@ void codgen(Symbol *sfunc)
{
cgstate.allregs |= mask(PICREG); // EBX can now be used
cgreg_assign(cgstate.retsym);
pass = BackendPass.reg;
cgstate.pass = BackendPass.reg;
}
else if (cgreg_assign(cgstate.retsym)) // if we found some registers
pass = BackendPass.reg;
cgstate.pass = BackendPass.reg;
else
pass = BackendPass.final_;
cgstate.pass = BackendPass.final_;

/* free up generated code for next pass
*/
Expand Down Expand Up @@ -1596,7 +1594,7 @@ reg_t allocreg(ref CodeBuilder cdb,ref regm_t outretregs,tym_t tym ,int line,con

static if (0)
{
if (pass == BackendPass.final_)
if (cgstate.pass == BackendPass.final_)
{
printf("allocreg %s,%d: regcon.mvar %s regcon.cse.mval %s msavereg %s outretregs %s tym %s\n",
file,line,regm_str(regcon.mvar),regm_str(regcon.cse.mval),
Expand Down Expand Up @@ -1662,7 +1660,7 @@ L3:
if (!regcon.indexregs && r & ~mLSW)
r &= ~mLSW;

if (pass == BackendPass.final_ && r & ~lastRetregs[0] && !I16)
if (cgstate.pass == BackendPass.final_ && r & ~lastRetregs[0] && !I16)
{ // Try not to always allocate the same register,
// to schedule better

Expand Down Expand Up @@ -1945,7 +1943,7 @@ bool cssave(elem *e, regm_t regm, bool opsflag)
/*if (e.Ecount && e.Ecount == e.Ecomsub)*/
if (e.Ecount && e.Ecomsub)
{
if (!opsflag && pass != BackendPass.final_ && (I32 || I64))
if (!opsflag && cgstate.pass != BackendPass.final_ && (I32 || I64))
return false;

//printf("cssave(e = %p, regm = %s, opsflag = x%x)\n", e, regm_str(regm), opsflag);
Expand Down Expand Up @@ -2006,7 +2004,7 @@ bool evalinregister(elem *e)
/* to be generated */
{
if ((I32 || I64) &&
//pass == BackendPass.final_ && // bug 8987
//cgstate.pass == BackendPass.final_ && // bug 8987
sz <= REGSIZE)
{
// Do it only if at least 2 registers are available
Expand Down Expand Up @@ -2049,7 +2047,7 @@ bool evalinregister(elem *e)
regm_t getscratch()
{
regm_t scratch = 0;
if (pass == BackendPass.final_)
if (cgstate.pass == BackendPass.final_)
{
scratch = cgstate.allregs & ~(regcon.mvar | regcon.mpvar | regcon.cse.mval |
regcon.immed.mval | regcon.params | cgstate.mfuncreg);
Expand Down Expand Up @@ -2217,7 +2215,7 @@ private void comsub(ref CodeBuilder cdb,elem *e, ref regm_t pretregs)

debug
{
printf("couldn't find cse e = %p, pass = %d\n",e,pass);
printf("couldn't find cse e = %p, pass = %d\n",e,cgstate.pass);
elem_print(e);
}
assert(0); /* should have found it */
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/backend/cgreg.d
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ private void cgreg_map(Symbol *s, reg_t regmsw, reg_t reglsw)
@trusted
void cgreg_unregister(regm_t conflict)
{
if (pass == BackendPass.final_)
pass = BackendPass.reg; // have to codegen at least one more time
if (cgstate.pass == BackendPass.final_)
cgstate.pass = BackendPass.reg; // have to codegen at least one more time
foreach (s; globsym[])
{
if (s.Sfl == FLreg && s.Sregm & conflict)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/cgxmm.d
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ static if (0)
case SHUFPD: case SHUFPS:
if (n == 3)
{
if (pass == BackendPass.final_)
if (cgstate.pass == BackendPass.final_)
error(e.Esrcpos.Sfilename, e.Esrcpos.Slinnum, e.Esrcpos.Scharnum, "missing 4th parameter to `__simd()`");
cs.IFL2 = FLconst;
cs.IEV2.Vsize_t = 0;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/cod2.d
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ void cdshift(ref CodeBuilder cdb,elem *e,regm_t *pretregs)
goto L1;
}

if (pass != BackendPass.final_ && (!forregs || forregs & (mSI | mDI)))
if (cgstate.pass != BackendPass.final_ && (!forregs || forregs & (mSI | mDI)))
{
// e1 might get into SI or DI in a later pass,
// so don't put CX into a register
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/backend/code.d
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ struct CGstate
regm_t mfuncreg; // mask of registers preserved by function
regm_t msavereg; // Mask of registers that we would like to save.
// they are temporaries (set by scodelem())
BackendPass pass;
}

public import dmd.backend.nteh;
Expand Down

0 comments on commit 4b8318b

Please sign in to comment.