Skip to content

Commit

Permalink
move allregs to CGstate
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed May 14, 2024
1 parent 9469a2e commit 29bb98a
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 130 deletions.
36 changes: 17 additions & 19 deletions compiler/src/dmd/backend/cgcod.d
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ private Symbol *retsym; // set to symbol that should be placed in
regm_t msavereg; // Mask of registers that we would like to save.
// they are temporaries (set by scodelem())
regm_t mfuncreg; // Mask of registers preserved by a function

regm_t allregs; // ALLREGS optionally including mBP
}

/*********************************
Expand All @@ -131,7 +129,7 @@ void codgen(Symbol *sfunc)

cgreg_init();
CSE.initialize();
allregs = ALLREGS;
cgstate.allregs = ALLREGS;
cgstate.Alloca.initialize();
anyiasm = 0;

Expand Down Expand Up @@ -272,12 +270,12 @@ void codgen(Symbol *sfunc)
}

// See which variables we can put into registers
allregs |= cod3_useBP(); // use EBP as general purpose register
cgstate.allregs |= cod3_useBP(); // use EBP as general purpose register

// If pic code, but EBX was never needed
if (!(allregs & mask(PICREG)) && !gotref)
if (!(cgstate.allregs & mask(PICREG)) && !gotref)
{
allregs |= mask(PICREG); // EBX can now be used
cgstate.allregs |= mask(PICREG); // EBX can now be used
cgreg_assign(retsym);
pass = BackendPass.reg;
}
Expand Down Expand Up @@ -1634,7 +1632,7 @@ static if (0)
}
tym = tybasic(tym);
uint size = _tysize[tym];
outretregs &= mES | allregs | XMMREGS;
outretregs &= mES | cgstate.allregs | XMMREGS;
regm_t retregs = outretregs;
regm_t[] lastRetregs = cgstate.lastRetregs[];

Expand All @@ -1661,12 +1659,12 @@ static if (0)
}
int count = 0;
L1:
//printf("L1: allregs = %s, outretregs = %s\n", regm_str(allregs), regm_str(outretregs));
//printf("L1: allregs = %s, outretregs = %s\n", regm_str(cgstate.allregs), regm_str(outretregs));
assert(++count < 20); /* fail instead of hanging if blocked */
assert(retregs);
reg_t msreg = NOREG, lsreg = NOREG; /* no value assigned yet */
L3:
//printf("L2: allregs = %s, outretregs = %s\n", regm_str(allregs), regm_str(outretregs));
//printf("L2: allregs = %s, outretregs = %s\n", regm_str(cgstate.allregs), regm_str(outretregs));
regm_t r = retregs & ~(msavereg | regcon.cse.mval | regcon.params);
if (!r)
{
Expand Down Expand Up @@ -1816,10 +1814,10 @@ regm_t lpadregs()
{
regm_t used;
if (config.ehmethod == EHmethod.EH_DWARF)
used = allregs & ~mfuncreg;
used = cgstate.allregs & ~mfuncreg;
else
used = (I32 | I64) ? allregs : (ALLREGS | mES);
//printf("lpadregs(): used=%s, allregs=%s, mfuncreg=%s\n", regm_str(used), regm_str(allregs), regm_str(mfuncreg));
used = (I32 | I64) ? cgstate.allregs : (ALLREGS | mES);
//printf("lpadregs(): used=%s, allregs=%s, mfuncreg=%s\n", regm_str(used), regm_str(cgstate.llregs), regm_str(mfuncreg));
return used;
}

Expand Down Expand Up @@ -2039,7 +2037,7 @@ bool evalinregister(elem *e)
sz <= REGSIZE)
{
// Do it only if at least 2 registers are available
regm_t m = allregs & ~regcon.mvar;
regm_t m = cgstate.allregs & ~regcon.mvar;
if (sz == 1)
m &= BYTEREGS;
if (m & (m - 1)) // if more than one register
Expand Down Expand Up @@ -2080,7 +2078,7 @@ regm_t getscratch()
regm_t scratch = 0;
if (pass == BackendPass.final_)
{
scratch = allregs & ~(regcon.mvar | regcon.mpvar | regcon.cse.mval |
scratch = cgstate.allregs & ~(regcon.mvar | regcon.mpvar | regcon.cse.mval |
regcon.immed.mval | regcon.params | mfuncreg);
}
return scratch;
Expand Down Expand Up @@ -2197,8 +2195,8 @@ private void comsub(ref CodeBuilder cdb,elem *e, ref regm_t pretregs)
retregs = pretregs;
if (byte_ && !(retregs & BYTEREGS))
retregs = BYTEREGS;
else if (!(retregs & allregs))
retregs = allregs;
else if (!(retregs & cgstate.allregs))
retregs = cgstate.allregs;
reg = allocreg(cdb,retregs,tym);
code *cr = &cse.csimple;
cr.setReg(reg);
Expand Down Expand Up @@ -2851,7 +2849,7 @@ void scodelem(ref CodeBuilder cdb, elem *e,regm_t *pretregs,regm_t keepmsk,bool
touse = 0; // PUSH/POP pairs are always shorter
else
{
touse = mfuncreg & allregs & ~(msavereg | oldregcon | regcon.cse.mval);
touse = mfuncreg & cgstate.allregs & ~(msavereg | oldregcon | regcon.cse.mval);
/* Don't use registers we'll have to save/restore */
touse &= ~(fregsaved & oldmfuncreg);
/* Don't use registers that have constant values in them, since
Expand Down Expand Up @@ -2966,8 +2964,8 @@ const(char)* regm_str(regm_t rm)
return "ALLREGS";
if (rm == BYTEREGS)
return "BYTEREGS";
if (rm == allregs)
return "allregs";
if (rm == cgstate.allregs)
return "cgstate.allregs";
if (rm == XMMREGS)
return "XMMREGS";
char *p = str[i].ptr;
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 @@ -911,13 +911,13 @@ int cgreg_assign(Symbol *retsym)
continue;

// If BP isn't available, can't assign to it
if (reg == BP && !(allregs & mBP))
if (reg == BP && !(cgstate.allregs & mBP))
continue;

static if (0 && TARGET_LINUX)
{
// Need EBX for static pointer
if (reg == BX && !(allregs & mBX))
if (reg == BX && !(cgstate.allregs & mBX))
continue;
}
/* Don't enregister any parameters to variadicPrologRegs
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/cgsched.d
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void cgsched_block(block* b)
config.target_cpu >= TARGET_Pentium &&
b.BC != BCasm)
{
regm_t scratch = allregs;
regm_t scratch = cgstate.allregs;

scratch &= ~(b.Bregcon.used | b.Bregcon.params | mfuncreg);
scratch &= ~(b.Bregcon.immed.mval | b.Bregcon.cse.mval);
Expand Down
40 changes: 20 additions & 20 deletions compiler/src/dmd/backend/cod1.d
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ void getlvalue(ref CodeBuilder cdb,code *pcs,elem *e,regm_t keepmsk)
/*assert(datafl[f]);*/ /* what if addr of func? */
if (!I16)
{ /* Any register can be an index register */
regm_t idxregs = allregs & ~keepmsk;
regm_t idxregs = cgstate.allregs & ~keepmsk;
assert(idxregs);

/* See if e1.E1 can be a scaled index */
Expand Down Expand Up @@ -1185,7 +1185,7 @@ void getlvalue(ref CodeBuilder cdb,code *pcs,elem *e,regm_t keepmsk)
/* The rest of the cases could be a far pointer */

regm_t idxregs;
idxregs = (I16 ? IDXREGS : allregs) & ~keepmsk; // only these can be index regs
idxregs = (I16 ? IDXREGS : cgstate.allregs) & ~keepmsk; // only these can be index regs
assert(idxregs);
if (!I16 &&
(sz == REGSIZE || (I64 && sz == 4)) &&
Expand Down Expand Up @@ -1283,7 +1283,7 @@ void getlvalue(ref CodeBuilder cdb,code *pcs,elem *e,regm_t keepmsk)
if (ss)
{
scodelem(cdb, e11, &idxregs, keepmsk, true);
idxregs2 = allregs & ~(idxregs | keepmsk);
idxregs2 = cgstate.allregs & ~(idxregs | keepmsk);
cdisscaledindex(cdb, e12, &idxregs2, keepmsk | idxregs);
}

Expand All @@ -1292,7 +1292,7 @@ void getlvalue(ref CodeBuilder cdb,code *pcs,elem *e,regm_t keepmsk)
{
idxregs2 = idxregs;
cdisscaledindex(cdb, e11, &idxregs2, keepmsk);
idxregs = allregs & ~(idxregs2 | keepmsk);
idxregs = cgstate.allregs & ~(idxregs2 | keepmsk);
scodelem(cdb, e12, &idxregs, keepmsk | idxregs2, true);
}
// Look for *(((v1 << scale) + c1) + v2)
Expand All @@ -1304,15 +1304,15 @@ void getlvalue(ref CodeBuilder cdb,code *pcs,elem *e,regm_t keepmsk)
pcs.IEV1.Vuns = e11.E2.Vuns;
idxregs2 = idxregs;
cdisscaledindex(cdb, e11.E1, &idxregs2, keepmsk);
idxregs = allregs & ~(idxregs2 | keepmsk);
idxregs = cgstate.allregs & ~(idxregs2 | keepmsk);
scodelem(cdb, e12, &idxregs, keepmsk | idxregs2, true);
freenode(e11.E2);
freenode(e11);
}
else
{
scodelem(cdb, e11, &idxregs, keepmsk, true);
idxregs2 = allregs & ~(idxregs | keepmsk);
idxregs2 = cgstate.allregs & ~(idxregs | keepmsk);
scodelem(cdb, e12, &idxregs2, keepmsk | idxregs, true);
}
base = findreg(idxregs);
Expand Down Expand Up @@ -1764,7 +1764,7 @@ void tstresult(ref CodeBuilder cdb, regm_t regm, tym_t tym, uint saveflag)
{
if (saveflag)
{
scrregm = allregs & ~regm; // possible scratch regs
scrregm = cgstate.allregs & ~regm; // possible scratch regs
scrreg = allocreg(cdb, scrregm, TYoffset); // allocate scratch reg
genmovreg(cdb, scrreg, reg); // MOV scrreg,msreg
reg = scrreg;
Expand Down Expand Up @@ -3747,7 +3747,7 @@ void cdfunc(ref CodeBuilder cdb, elem* e, regm_t* pretregs)
void cdstrthis(ref CodeBuilder cdb, elem* e, regm_t* pretregs)
{
assert(tysize(e.Ety) == REGSIZE);
const reg = findreg(*pretregs & allregs);
const reg = findreg(*pretregs & cgstate.allregs);
getregs(cdb,mask(reg));
// LEA reg,np[ESP]
uint np = stackpush - e.Vuns; // stack delta to parameter
Expand Down Expand Up @@ -3836,7 +3836,7 @@ private void funccall(ref CodeBuilder cdb, elem* e, uint numpara, uint numalign,
}
if (sytab[s.Sclass] & SCSS) // if function is on stack (!)
{
retregs = allregs & ~keepmsk;
retregs = cgstate.allregs & ~keepmsk;
s.Sflags &= ~GTregcand;
s.Sflags |= SFLread;
cdrelconst(cdbe,e1,&retregs);
Expand Down Expand Up @@ -3926,7 +3926,7 @@ private void funccall(ref CodeBuilder cdb, elem* e, uint numpara, uint numalign,
if ((!OTleaf(e11.Eoper) || e11.Eoper == OPconst) &&
(e11.Eoper != OPind || e11.Ecount))
{
retregs = allregs & ~keepmsk;
retregs = cgstate.allregs & ~keepmsk;
cgstate.stackclean++;
scodelem(cdbe,e11,&retregs,keepmsk,true);
cgstate.stackclean--;
Expand Down Expand Up @@ -4273,7 +4273,7 @@ private void movParams(ref CodeBuilder cdb, elem* e, uint stackalign, uint funca
int i = cast(int)sz;
do
{ int regsize = REGSIZE;
regm_t retregs = (sz == 1) ? BYTEREGS : allregs;
regm_t retregs = (sz == 1) ? BYTEREGS : cgstate.allregs;
reg_t reg;
if (reghasvalue(retregs,*p,reg))
{
Expand Down Expand Up @@ -4305,7 +4305,7 @@ private void movParams(ref CodeBuilder cdb, elem* e, uint stackalign, uint funca
default:
break;
}
regm_t retregs = tybyte(tym) ? BYTEREGS : allregs;
regm_t retregs = tybyte(tym) ? BYTEREGS : cgstate.allregs;
if (tyvector(tym) ||
config.fpxmmregs && tyxmmreg(tym) &&
// If not already in x87 register from function call return
Expand Down Expand Up @@ -4827,7 +4827,7 @@ void pushParams(ref CodeBuilder cdb, elem* e, uint stackalign, tym_t tyf)
for (int i = 0; i < 3; ++i)
{
reg_t reg;
if (reghasvalue(allregs, value, reg))
if (reghasvalue(cgstate.allregs, value, reg))
cdb.gen1(0x50 + reg); // PUSH reg
else
cdb.genc2(0x68,0,value); // PUSH value
Expand Down Expand Up @@ -4898,16 +4898,16 @@ void pushParams(ref CodeBuilder cdb, elem* e, uint stackalign, tym_t tyf)
{
if (I64 && regsize == 8 && value != cast(int)value)
{
reg = regwithvalue(cdb,allregs,value,64);
reg = regwithvalue(cdb,cgstate.allregs,value,64);
goto Preg; // cannot push imm64 unless it is sign extended 32 bit value
}
if (regsize == REGSIZE && reghasvalue(allregs,value,reg))
if (regsize == REGSIZE && reghasvalue(cgstate.allregs,value,reg))
goto Preg;
cdb.genc2((szb == 1) ? 0x6A : 0x68, 0, value); // PUSH value
}
else
{
reg = regwithvalue(cdb, allregs, value, 0);
reg = regwithvalue(cdb, cgstate.allregs, value, 0);
Preg:
genpush(cdb,reg); // PUSH reg
}
Expand Down Expand Up @@ -4938,7 +4938,7 @@ void pushParams(ref CodeBuilder cdb, elem* e, uint stackalign, tym_t tyf)
}
else
{
regm_t regs = allregs;
regm_t regs = cgstate.allregs;
codelem(cdb, e, &regs, false);
genpush(cdb, findregmsw(regs)); // PUSH msreg
genpush(cdb, findreglsw(regs)); // PUSH lsreg
Expand Down Expand Up @@ -4969,7 +4969,7 @@ void pushParams(ref CodeBuilder cdb, elem* e, uint stackalign, tym_t tyf)
}
else
{
regm_t regs = allregs;
regm_t regs = cgstate.allregs;
codelem(cdb, e, &regs, false);
genpush(cdb, findregmsw(regs)); // PUSH msreg
genpush(cdb, findreglsw(regs)); // PUSH lsreg
Expand All @@ -4983,7 +4983,7 @@ void pushParams(ref CodeBuilder cdb, elem* e, uint stackalign, tym_t tyf)
break;
}

regm_t retregs = tybyte(tym) ? BYTEREGS : allregs;
regm_t retregs = tybyte(tym) ? BYTEREGS : cgstate.allregs;
if (tyvector(tym) || (tyxmmreg(tym) && config.fpxmmregs))
{
regm_t retxmm = XMMREGS;
Expand Down Expand Up @@ -5178,7 +5178,7 @@ void loaddata(ref CodeBuilder cdb, elem* e, ref regm_t outretregs)
if (outretregs == mPSW)
{
Symbol *s;
regm = allregs;
regm = cgstate.allregs;
if (e.Eoper == OPconst)
{ /* true: OR SP,SP (SP is never 0) */
/* false: CMP SP,SP (always equal) */
Expand Down
Loading

0 comments on commit 29bb98a

Please sign in to comment.