From efbdea44fe7757b01af4c6516b18bcfdb64e3054 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sat, 11 May 2024 18:48:26 -0700 Subject: [PATCH] move funcoffset to CGstate (#16475) --- compiler/src/dmd/backend/cgcod.d | 13 ++++++------- compiler/src/dmd/backend/cod3.d | 8 ++++---- compiler/src/dmd/backend/code.d | 1 + compiler/src/dmd/backend/dwarfdbginf.d | 24 ++++++++++++------------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/compiler/src/dmd/backend/cgcod.d b/compiler/src/dmd/backend/cgcod.d index 74edd8347d9e..c4dc9bfd5355 100644 --- a/compiler/src/dmd/backend/cgcod.d +++ b/compiler/src/dmd/backend/cgcod.d @@ -117,7 +117,6 @@ regm_t allregs; // ALLREGS optionally including mBP int dfoidx; /* which block we are in */ -targ_size_t funcoffset; // offset of start of function targ_size_t prolog_allocoffset; // offset past adj of stack allocation targ_size_t startoffset; // size of function entry code targ_size_t retoffset; /* offset from start of func to ret code */ @@ -349,7 +348,7 @@ void codgen(Symbol *sfunc) if (cprolog) pinholeopt(cprolog,null); // optimize - funcoffset = Offset(sfunc.Sseg); + cgstate.funcoffset = Offset(sfunc.Sseg); targ_size_t coffset = Offset(sfunc.Sseg); if (eecontext.EEelem) @@ -383,7 +382,7 @@ void codgen(Symbol *sfunc) pinholeopt(b.Bcode,b); // do pinhole optimization if (b.Bflags & BFL.prolog) // do function prolog { - startoffset = coffset + calcblksize(cprolog) - funcoffset; + startoffset = coffset + calcblksize(cprolog) - cgstate.funcoffset; b.Bcode = cat(cprolog,b.Bcode); } cgsched_block(b); @@ -502,7 +501,7 @@ void codgen(Symbol *sfunc) assert(0); } - sfunc.Ssize = Offset(sfunc.Sseg) - funcoffset; // size of function + sfunc.Ssize = Offset(sfunc.Sseg) - cgstate.funcoffset; // size of function if (configv.vasm) disassemble(disasmBuf[]); // disassemble the code @@ -531,7 +530,7 @@ void codgen(Symbol *sfunc) case BCret: case BCretexp: /* Compute offset to return code from start of function */ - retoffset = b.Boffset + b.Bsize - cgstate.retsize - funcoffset; + retoffset = b.Boffset + b.Bsize - cgstate.retsize - cgstate.funcoffset; /* Add 3 bytes to retoffset in case we have an exception * handler. THIS PROBABLY NEEDS TO BE IN ANOTHER SPOT BUT @@ -542,7 +541,7 @@ void codgen(Symbol *sfunc) break; default: - retoffset = b.Boffset + b.Bsize - funcoffset; + retoffset = b.Boffset + b.Bsize - cgstate.funcoffset; break; } } @@ -552,7 +551,7 @@ void codgen(Symbol *sfunc) */ /* Instead, try offset to cleanup code */ if (retoffset < sfunc.Ssize) - objmod.linnum(sfunc.Sfunc.Fendline,sfunc.Sseg,funcoffset + retoffset); + objmod.linnum(sfunc.Sfunc.Fendline,sfunc.Sseg,cgstate.funcoffset + retoffset); static if (MARS) { diff --git a/compiler/src/dmd/backend/cod3.d b/compiler/src/dmd/backend/cod3.d index 5cc98690f543..ebbd9dca38c7 100644 --- a/compiler/src/dmd/backend/cod3.d +++ b/compiler/src/dmd/backend/cod3.d @@ -7364,13 +7364,13 @@ private void do64bit(ref MiniCodeBuf pbuf, FL fl, ref evc uev,int flags) case FLblock: /* displacement to another block */ ad = uev.Vblock.Boffset - pbuf.getOffset() - 4; - //printf("FLblock: funcoffset = %x, pbuf.getOffset = %x, Boffset = %x, ad = %x\n", funcoffset, pbuf.getOffset(), uev.Vblock.Boffset, ad); + //printf("FLblock: funcoffset = %x, pbuf.getOffset = %x, Boffset = %x, ad = %x\n", cgstate.funcoffset, pbuf.getOffset(), uev.Vblock.Boffset, ad); goto L1; case FLblockoff: pbuf.flush(); assert(uev.Vblock); - //printf("FLblockoff: offset = %x, Boffset = %x, funcoffset = %x\n", pbuf.offset, uev.Vblock.Boffset, funcoffset); + //printf("FLblockoff: offset = %x, Boffset = %x, funcoffset = %x\n", pbuf.offset, uev.Vblock.Boffset, cgstate.funcoffset); pbuf.write64(uev.Vblock.Boffset); objmod.reftocodeseg(pbuf.seg,pbuf.offset,uev.Vblock.Boffset); break; @@ -7544,13 +7544,13 @@ private void do32bit(ref MiniCodeBuf pbuf, FL fl, ref evc uev,int flags, int val case FLblock: /* displacement to another block */ ad = uev.Vblock.Boffset - pbuf.getOffset() - 4; - //printf("FLblock: funcoffset = %x, pbuf.getOffset = %x, Boffset = %x, ad = %x\n", funcoffset, pbuf.getOffset(), uev.Vblock.Boffset, ad); + //printf("FLblock: funcoffset = %x, pbuf.getOffset = %x, Boffset = %x, ad = %x\n", cgstate.funcoffset, pbuf.getOffset(), uev.Vblock.Boffset, ad); goto L1; case FLblockoff: pbuf.flush(); assert(uev.Vblock); - //printf("FLblockoff: offset = %x, Boffset = %x, funcoffset = %x\n", pbuf.offset, uev.Vblock.Boffset, funcoffset); + //printf("FLblockoff: offset = %x, Boffset = %x, funcoffset = %x\n", pbuf.offset, uev.Vblock.Boffset, cgstate.funcoffset); objmod.reftocodeseg(pbuf.seg,pbuf.offset,uev.Vblock.Boffset); pbuf.write32(cast(uint)(uev.Vblock.Boffset)); break; diff --git a/compiler/src/dmd/backend/code.d b/compiler/src/dmd/backend/code.d index a5f9cc726071..f0ca757782f0 100644 --- a/compiler/src/dmd/backend/code.d +++ b/compiler/src/dmd/backend/code.d @@ -176,6 +176,7 @@ struct CGstate regm_t[4] lastRetregs; // used to not allocate the same register over and over again, // to improve instruction scheduling + targ_size_t funcoffset; // offset of start of function targ_size_t retsize; // size of function return code } diff --git a/compiler/src/dmd/backend/dwarfdbginf.d b/compiler/src/dmd/backend/dwarfdbginf.d index cd4fafbbc6cb..78eb958811cd 100644 --- a/compiler/src/dmd/backend/dwarfdbginf.d +++ b/compiler/src/dmd/backend/dwarfdbginf.d @@ -1912,8 +1912,8 @@ static if (1) debug_info.buf.writeuLEB128(sfunc.Sfunc.Fstartline.Scharnum); // DW_AT_decl_column // DW_AT_low_pc and DW_AT_high_pc - dwarf_appreladdr(debug_info.seg, debug_info.buf, seg, funcoffset); - dwarf_appreladdr(debug_info.seg, debug_info.buf, seg, funcoffset + sfunc.Ssize); + dwarf_appreladdr(debug_info.seg, debug_info.buf, seg, cgstate.funcoffset); + dwarf_appreladdr(debug_info.seg, debug_info.buf, seg, cgstate.funcoffset + sfunc.Ssize); // DW_AT_frame_base if (config.objfmt == OBJ_ELF) @@ -2027,14 +2027,14 @@ static if (1) if (sd.SDaranges_offset) // Extend existing entry size - *cast(ulong *)(debug_aranges.buf.buf + sd.SDaranges_offset + _tysize[TYnptr]) = funcoffset + sfunc.Ssize; + *cast(ulong *)(debug_aranges.buf.buf + sd.SDaranges_offset + _tysize[TYnptr]) = cgstate.funcoffset + sfunc.Ssize; else { // Add entry sd.SDaranges_offset = cast(uint)debug_aranges.buf.length(); // address of start of .text segment dwarf_appreladdr(debug_aranges.seg, debug_aranges.buf, seg, 0); // size of .text segment - append_addr(debug_aranges.buf, funcoffset + sfunc.Ssize); + append_addr(debug_aranges.buf, cgstate.funcoffset + sfunc.Ssize); } /* ============= debug_ranges =========================== */ @@ -2043,8 +2043,8 @@ static if (1) * indicate this by adding to the debug_ranges */ // start of function and end of function - dwarf_appreladdr(debug_ranges.seg, debug_ranges.buf, seg, funcoffset); - dwarf_appreladdr(debug_ranges.seg, debug_ranges.buf, seg, funcoffset + sfunc.Ssize); + dwarf_appreladdr(debug_ranges.seg, debug_ranges.buf, seg, cgstate.funcoffset); + dwarf_appreladdr(debug_ranges.seg, debug_ranges.buf, seg, cgstate.funcoffset + sfunc.Ssize); /* ============= debug_loc =========================== */ @@ -2055,22 +2055,22 @@ static if (1) // set the entry for this function in .debug_loc segment // after call - dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, funcoffset + 0); - dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, funcoffset + 1); + dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, cgstate.funcoffset + 0); + dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, cgstate.funcoffset + 1); loc_op = cast(ushort)(((cgstate.Para.size - REGSIZE) << 8) | (DW_OP_breg0 + dwarf_regno(SP))); debug_loc.buf.write32(loc_op << 16 | op_size); // after push EBP - dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, funcoffset + 1); - dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, funcoffset + 3); + dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, cgstate.funcoffset + 1); + dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, cgstate.funcoffset + 3); loc_op = cast(ushort)(((cgstate.Para.size) << 8) | (DW_OP_breg0 + dwarf_regno(SP))); debug_loc.buf.write32(loc_op << 16 | op_size); // after mov EBP, ESP - dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, funcoffset + 3); - dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, funcoffset + sfunc.Ssize); + dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, cgstate.funcoffset + 3); + dwarf_appreladdr(debug_loc.seg, debug_loc.buf, seg, cgstate.funcoffset + sfunc.Ssize); loc_op = cast(ushort)(((cgstate.Para.size) << 8) | (DW_OP_breg0 + dwarf_regno(BP))); debug_loc.buf.write32(loc_op << 16 | op_size);