Skip to content

Commit

Permalink
move BPoff 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 4b8318b commit a0a1160
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
7 changes: 3 additions & 4 deletions compiler/src/dmd/backend/cgcod.d
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import dmd.backend.dwarfdbginf : dwarf_except_gentables;

__gshared
{
int BPoff; // offset from BP
int EBPtoESP; // add to EBP offset to get ESP offset

REGSAVE regsave;
Expand Down Expand Up @@ -611,7 +610,7 @@ void prolog(ref CodeBuilder cdb)
EBPtoESP = -REGSIZE;
cgstate.hasframe = false;
bool pushds = false;
BPoff = 0;
cgstate.BPoff = 0;
bool pushalloc = false;
tym_t tyf = funcsym_p.ty();
tym_t tym = tybasic(tyf);
Expand Down Expand Up @@ -944,7 +943,7 @@ else
assert(I32 || I64);
prolog_frameadj2(cdbx, tyf, xlocalsize, &pushalloc);
version (FRAMEPTR) { } else
BPoff += REGSIZE;
cgstate.BPoff += REGSIZE;
}
else
assert((localsize | cgstate.Alloca.size) == 0 || (usednteh & NTEHjmonitor));
Expand Down Expand Up @@ -1006,7 +1005,7 @@ Lcont:
/* Alignment checks
*/
//assert(cgstate.Auto.alignment <= STACKALIGN);
//assert(((cgstate.Auto.size + cgstate.Para.size + BPoff) & (cgstate.Auto.alignment - 1)) == 0);
//assert(((cgstate.Auto.size + cgstate.Para.size + cgstate.BPoff) & (cgstate.Auto.alignment - 1)) == 0);
}

/************************************
Expand Down
58 changes: 29 additions & 29 deletions compiler/src/dmd/backend/cod3.d
Original file line number Diff line number Diff line change
Expand Up @@ -3368,7 +3368,7 @@ void prolog_16bit_windows_farfunc(ref CodeBuilder cdb, tym_t* tyf, bool* pushds)
{
cdb.gen1(0x1E); // PUSH DS
*pushds = true;
BPoff = -REGSIZE;
cgstate.BPoff = -REGSIZE;
}
if (wflags & (WFds | WFss | WFdgroup))
cdb.gen2(0x8E,modregrm(3,3,AX)); // MOV DS,AX
Expand Down Expand Up @@ -3570,8 +3570,8 @@ void prolog_setupalloca(ref CodeBuilder cdb)
// Set up magic parameter for alloca()
// MOV -REGSIZE[BP],localsize - BPoff
cdb.genc(0xC7,modregrm(2,0,BPRM),
FLconst,cgstate.Alloca.offset + BPoff,
FLconst,localsize - BPoff);
FLconst,cgstate.Alloca.offset + cgstate.BPoff,
FLconst,localsize - cgstate.BPoff);
if (I64)
code_orrex(cdb.last(), REX_W);
}
Expand All @@ -3596,7 +3596,7 @@ void prolog_saveregs(ref CodeBuilder cdb, regm_t topush, int cfa_offset)
// Save to preallocated section in the stack frame
int xmmtopush = popcnt(topush & XMMREGS); // XMM regs take 16 bytes
int gptopush = popcnt(topush) - xmmtopush; // general purpose registers to save
targ_size_t xmmoffset = cgstate.pushoff + BPoff;
targ_size_t xmmoffset = cgstate.pushoff + cgstate.BPoff;
if (!cgstate.hasframe || cgstate.enforcealign)
xmmoffset += EBPtoESP;
targ_size_t gpoffset = xmmoffset + xmmtopush * 16;
Expand Down Expand Up @@ -3699,7 +3699,7 @@ private void epilog_restoreregs(ref CodeBuilder cdb, regm_t topop)
// Save to preallocated section in the stack frame
int xmmtopop = popcnt(topop & XMMREGS); // XMM regs take 16 bytes
int gptopop = popcnt(topop) - xmmtopop; // general purpose registers to save
targ_size_t xmmoffset = cgstate.pushoff + BPoff;
targ_size_t xmmoffset = cgstate.pushoff + cgstate.BPoff;
if (!cgstate.hasframe || cgstate.enforcealign)
xmmoffset += EBPtoESP;
targ_size_t gpoffset = xmmoffset + xmmtopop * 16;
Expand Down Expand Up @@ -3819,7 +3819,7 @@ void prolog_genvarargs(ref CodeBuilder cdb, Symbol* sv)

/* Save registers into the voff area on the stack
*/
targ_size_t voff = cgstate.Auto.size + BPoff + sv.Soffset; // EBP offset of start of sv
targ_size_t voff = cgstate.Auto.size + cgstate.BPoff + sv.Soffset; // EBP offset of start of sv
const int vregnum = 6;
const uint vsize = vregnum * 8 + 8 * 16;

Expand Down Expand Up @@ -4076,7 +4076,7 @@ void prolog_loadparams(ref CodeBuilder cdb, tym_t tyf, bool pushalloc)
continue;
}

targ_size_t offset = cgstate.Fast.size + BPoff;
targ_size_t offset = cgstate.Fast.size + cgstate.BPoff;
if (s.Sclass == SC.shadowreg)
offset = cgstate.Para.size;
offset += s.Soffset;
Expand Down Expand Up @@ -4109,7 +4109,7 @@ void prolog_loadparams(ref CodeBuilder cdb, tym_t tyf, bool pushalloc)
else
{
//printf("%s Fast.size = %d, BPoff = %d, Soffset = %d, sz = %d\n",
// s.Sident, (int)cgstate.Fast.size, (int)BPoff, (int)s.Soffset, (int)sz);
// s.Sident, (int)cgstate.Fast.size, (int)cgstate.BPoff, (int)s.Soffset, (int)sz);
if (I64 && sz > 4)
code_orrex(cdb.last(), REX_W);
}
Expand Down Expand Up @@ -5093,18 +5093,18 @@ void cod3_adjSymOffsets()
break;

case SC.fastpar:
//printf("\tfastpar %s %p Soffset %x Fast.size %x BPoff %x\n", s.Sident, s, cast(int)s.Soffset, cast(int)cgstate.Fast.size, cast(int)BPoff);
s.Soffset += cgstate.Fast.size + BPoff;
//printf("\tfastpar %s %p Soffset %x Fast.size %x BPoff %x\n", s.Sident, s, cast(int)s.Soffset, cast(int)cgstate.Fast.size, cast(int)cgstate.BPoff);
s.Soffset += cgstate.Fast.size + cgstate.BPoff;
break;

case SC.auto_:
case SC.register:
if (s.Sfl == FLfast)
s.Soffset += cgstate.Fast.size + BPoff;
s.Soffset += cgstate.Fast.size + cgstate.BPoff;
else
//printf("s = '%s', Soffset = x%x, Auto.size = x%x, BPoff = x%x EBPtoESP = x%x\n", s.Sident, cast(int)s.Soffset, cast(int)cgstate.Auto.size, cast(int)BPoff, cast(int)EBPtoESP);
//printf("s = '%s', Soffset = x%x, Auto.size = x%x, BPoff = x%x EBPtoESP = x%x\n", s.Sident, cast(int)s.Soffset, cast(int)cgstate.Auto.size, cast(int)cgstate.BPoff, cast(int)EBPtoESP);
// if (!(funcsym_p.Sfunc.Fflags3 & Fnested))
s.Soffset += cgstate.Auto.size + BPoff;
s.Soffset += cgstate.Auto.size + cgstate.BPoff;
break;

case SC.bprel:
Expand Down Expand Up @@ -5333,7 +5333,7 @@ void assignaddrc(code *c)
goto do2;
}
else
{ c.IEV1.Vpointer += s.Soffset + soff + BPoff;
{ c.IEV1.Vpointer += s.Soffset + soff + cgstate.BPoff;
if (s.Sflags & SFLunambig)
c.Iflags |= CFunambig;
L2:
Expand Down Expand Up @@ -5361,22 +5361,22 @@ void assignaddrc(code *c)

case FLpara:
//printf("s = %s, Soffset = %d, Para.size = %d, BPoff = %d, EBPtoESP = %d, Vpointer = %d\n",
//s.Sident.ptr, cast(int)s.Soffset, cast(int)Para.size, cast(int)BPoff,
//s.Sident.ptr, cast(int)s.Soffset, cast(int)Para.size, cast(int)cgstate.BPoff,
//cast(int)EBPtoESP, cast(int)c.IEV1.Vpointer);
soff = cgstate.Para.size - BPoff; // cancel out add of BPoff
soff = cgstate.Para.size - cgstate.BPoff; // cancel out add of BPoff
goto L1;

case FLfltreg:
c.IEV1.Vpointer += cgstate.Foff + BPoff;
c.IEV1.Vpointer += cgstate.Foff + cgstate.BPoff;
c.Iflags |= CFunambig;
goto L2;

case FLallocatmp:
c.IEV1.Vpointer += cgstate.Alloca.offset + BPoff;
c.IEV1.Vpointer += cgstate.Alloca.offset + cgstate.BPoff;
goto L2;

case FLfuncarg:
c.IEV1.Vpointer += cgstate.funcarg.offset + BPoff;
c.IEV1.Vpointer += cgstate.funcarg.offset + cgstate.BPoff;
goto L2;

case FLbprel:
Expand All @@ -5390,19 +5390,19 @@ void assignaddrc(code *c)
c.Iop = NOP;
continue;
}
c.IEV1.Vpointer = CSE.offset(sn) + cgstate.CSoff + BPoff;
c.IEV1.Vpointer = CSE.offset(sn) + cgstate.CSoff + cgstate.BPoff;
c.Iflags |= CFunambig;
goto L2;

case FLregsave:
sn = c.IEV1.Vuns;
c.IEV1.Vpointer = sn + regsave.off + BPoff;
c.IEV1.Vpointer = sn + regsave.off + cgstate.BPoff;
c.Iflags |= CFunambig;
goto L2;

case FLndp:
assert(c.IEV1.Vuns < global87.save.length);
c.IEV1.Vpointer = c.IEV1.Vuns * tysize(TYldouble) + cgstate.NDPoff + BPoff;
c.IEV1.Vpointer = c.IEV1.Vuns * tysize(TYldouble) + cgstate.NDPoff + cgstate.BPoff;
c.Iflags |= CFunambig;
goto L2;

Expand Down Expand Up @@ -5478,11 +5478,11 @@ void assignaddrc(code *c)
/* NOTREACHED */

case FLfast:
c.IEV2.Vpointer += s.Soffset + cgstate.Fast.size + BPoff;
c.IEV2.Vpointer += s.Soffset + cgstate.Fast.size + cgstate.BPoff;
break;

case FLauto:
c.IEV2.Vpointer += s.Soffset + cgstate.Auto.size + BPoff;
c.IEV2.Vpointer += s.Soffset + cgstate.Auto.size + cgstate.BPoff;
L3:
if (!cgstate.hasframe || (cgstate.enforcealign && c.IFL2 != FLpara))
/* Convert to ESP relative address instead of EBP */
Expand All @@ -5494,15 +5494,15 @@ void assignaddrc(code *c)
goto L3;

case FLfltreg:
c.IEV2.Vpointer += cgstate.Foff + BPoff;
c.IEV2.Vpointer += cgstate.Foff + cgstate.BPoff;
goto L3;

case FLallocatmp:
c.IEV2.Vpointer += cgstate.Alloca.offset + BPoff;
c.IEV2.Vpointer += cgstate.Alloca.offset + cgstate.BPoff;
goto L3;

case FLfuncarg:
c.IEV2.Vpointer += cgstate.funcarg.offset + BPoff;
c.IEV2.Vpointer += cgstate.funcarg.offset + cgstate.BPoff;
goto L3;

case FLbprel:
Expand Down Expand Up @@ -5552,11 +5552,11 @@ targ_size_t cod3_bpoffset(Symbol *s)
break;

case FLfast:
offset += cgstate.Fast.size + BPoff;
offset += cgstate.Fast.size + cgstate.BPoff;
break;

case FLauto:
offset += cgstate.Auto.size + BPoff;
offset += cgstate.Auto.size + cgstate.BPoff;
break;

default:
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dmd/backend/code.d
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ struct CGstate
bool hasframe; // true if this function has a stack frame
bool enforcealign; // enforced stack alignment

int stackclean; // if != 0, then clean the stack after function call
int stackclean; // if != 0, then clean the stack after function call

int BPoff; // offset from BP

targ_size_t spoff;
targ_size_t Foff; // BP offset of floating register
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dmd/backend/cv8.d
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ void cv8_outsym(Symbol *s)
s.Sfl = FLreg;
goto case_register;
}
base = cast(uint)(cgstate.Para.size - BPoff); // cancel out add of BPoff
base = cast(uint)(cgstate.Para.size - cgstate.BPoff); // cancel out add of BPoff
goto L1;

case SC.auto_:
Expand All @@ -719,7 +719,7 @@ static if (1)
buf.reserve(cast(uint)(2 + 2 + 4 + 4 + 2 + len + 1));
buf.write16n(cast(uint)(2 + 4 + 4 + 2 + len + 1));
buf.write16n(0x1111);
buf.write32(cast(uint)(s.Soffset + base + BPoff));
buf.write32(cast(uint)(s.Soffset + base + cgstate.BPoff));
buf.write32(typidx);
buf.write16n(I64 ? 334 : 22); // relative to RBP/EBP
cv8_writename(buf, id, len);
Expand All @@ -731,15 +731,15 @@ else
buf.reserve(2 + 2 + 4 + 4 + len + 1);
buf.write16n( 2 + 4 + 4 + len + 1);
buf.write16n(S_BPREL_V3);
buf.write32(s.Soffset + base + BPoff);
buf.write32(s.Soffset + base + cgstate.BPoff);
buf.write32(typidx);
cv8_writename(buf, id, len);
buf.writeByte(0);
}
break;

case SC.bprel:
base = -BPoff;
base = -cgstate.BPoff;
goto L1;

case SC.fastpar:
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dmd/backend/dcgcv.d
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ private void cv4_outsym(Symbol *s)
s.Sfl = FLreg;
goto case_register;
}
base = cgstate.Para.size - BPoff; // cancel out add of BPoff
base = cgstate.Para.size - cgstate.BPoff; // cancel out add of BPoff
goto L1;

case SC.auto_:
Expand All @@ -1650,11 +1650,11 @@ private void cv4_outsym(Symbol *s)
goto Lret;
TOWORD(debsym + 2,I32 ? S_BPREL32 : S_BPREL16);
if (config.fulltypes == CV4)
{ TOOFFSET(debsym + 4,s.Soffset + base + BPoff);
{ TOOFFSET(debsym + 4,s.Soffset + base + cgstate.BPoff);
TOIDX(debsym + 4 + _tysize[TYint],typidx);
}
else
{ TOOFFSET(debsym + 4 + cgcv.sz_idx,s.Soffset + base + BPoff);
{ TOOFFSET(debsym + 4 + cgcv.sz_idx,s.Soffset + base + cgstate.BPoff);
TOIDX(debsym + 4,typidx);
}
length = 2 + 2 + _tysize[TYint] + cgcv.sz_idx;
Expand All @@ -1663,7 +1663,7 @@ private void cv4_outsym(Symbol *s)
break;

case SC.bprel:
base = -BPoff;
base = -cgstate.BPoff;
goto L1;

case SC.fastpar:
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dmd/backend/dwarfdbginf.d
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ static if (1)
// sa.Sident.ptr, sa.Sscope.Sident.ptr, closptr_off, memb_off);

debug_info.buf.writeByte(DW_OP_fbreg);
debug_info.buf.writesLEB128(cast(uint)(cgstate.Auto.size + BPoff - cgstate.Para.size + closptr_off)); // closure pointer offset from frame base
debug_info.buf.writesLEB128(cast(uint)(cgstate.Auto.size + cgstate.BPoff - cgstate.Para.size + closptr_off)); // closure pointer offset from frame base
debug_info.buf.writeByte(DW_OP_deref);
debug_info.buf.writeByte(DW_OP_plus_uconst);
debug_info.buf.writeuLEB128(cast(uint)memb_off); // closure variable offset
Expand All @@ -1999,11 +1999,11 @@ static if (1)
sa.Sclass == SC.parameter)
debug_info.buf.writesLEB128(cast(int)sa.Soffset);
else if (sa.Sclass == SC.fastpar)
debug_info.buf.writesLEB128(cast(int)(cgstate.Fast.size + BPoff - cgstate.Para.size + sa.Soffset));
debug_info.buf.writesLEB128(cast(int)(cgstate.Fast.size + cgstate.BPoff - cgstate.Para.size + sa.Soffset));
else if (sa.Sclass == SC.bprel)
debug_info.buf.writesLEB128(cast(int)(-cgstate.Para.size + sa.Soffset));
else
debug_info.buf.writesLEB128(cast(int)(cgstate.Auto.size + BPoff - cgstate.Para.size + sa.Soffset));
debug_info.buf.writesLEB128(cast(int)(cgstate.Auto.size + cgstate.BPoff - cgstate.Para.size + sa.Soffset));
}
debug_info.buf.buf[soffset] = cast(ubyte)(debug_info.buf.length() - soffset - 1);
break;
Expand Down

0 comments on commit a0a1160

Please sign in to comment.