From 30becabb47a9ec8b7fa8aadb1fd9b98b6da4634c Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 15 Oct 2024 13:30:02 +0200 Subject: [PATCH] backend: Remove PARSER (#17008) --- compiler/src/dmd/backend/blockopt.d | 135 +++-------------- compiler/src/dmd/backend/cgelem.d | 1 - compiler/src/dmd/backend/dcgcv.d | 2 +- compiler/src/dmd/backend/dout.d | 1 - compiler/src/dmd/backend/dwarfdbginf.d | 2 +- compiler/src/dmd/backend/elem.d | 197 ++----------------------- compiler/src/dmd/backend/global.d | 4 +- compiler/src/dmd/backend/var.d | 1 - 8 files changed, 38 insertions(+), 305 deletions(-) diff --git a/compiler/src/dmd/backend/blockopt.d b/compiler/src/dmd/backend/blockopt.d index 2e514bfda4a4..4cdd793cb132 100644 --- a/compiler/src/dmd/backend/blockopt.d +++ b/compiler/src/dmd/backend/blockopt.d @@ -396,30 +396,6 @@ void block_initvar(Symbol *s) } -/******************* - * Mark end of function. - * flag: - * 0 do a "return" - * 1 do a "return 0" - */ - -@trusted -void block_endfunc(int flag) -{ - bo.curblock.Bsymend = globsym.length; - bo.curblock.Bendscope = bo.curblock; - if (flag) - { - elem *e = el_longt(tstypes[TYint], 0); - block_appendexp(bo.curblock, e); - bo.curblock.BC = BCretexp; // put a return at the end - } - else - bo.curblock.BC = BCret; // put a return at the end - bo.curblock = null; // undefined from now on - bo.block_last = null; -} - /****************************** * Perform branch optimization on basic blocks. */ @@ -552,7 +528,7 @@ void brcombine(ref GlobalOptimizer go) continue; if (b2 == bo.startblock) continue; - if (!PARSER && b2.Belem && !OTleaf(b2.Belem.Eoper)) + if (b2.Belem && !OTleaf(b2.Belem.Eoper)) continue; ubyte bc2 = b2.BC; @@ -563,8 +539,7 @@ void brcombine(ref GlobalOptimizer go) if (b2.Belem) { int op = OPandand; - b.Belem = PARSER ? el_bint(op,tstypes[TYint],b.Belem,b2.Belem) - : el_bin(op,TYint,b.Belem,b2.Belem); + b.Belem = el_bin(op,TYint,b.Belem,b2.Belem); b2.Belem = null; } list_subtract(&(b.Bsucc),b2); @@ -578,20 +553,11 @@ void brcombine(ref GlobalOptimizer go) //|| (bc2 == BCret && b3.BC == BCret) ) { - if (PARSER) - { - type *t = (bc2 == BCretexp) ? b2.Belem.ET : tstypes[TYvoid]; - elem *e = el_bint(OPcolon2,t,b2.Belem,b3.Belem); - b.Belem = el_bint(OPcond,t,b.Belem,e); - } - else - { - if (!OTleaf(b3.Belem.Eoper)) - continue; - tym_t ty = (bc2 == BCretexp) ? b2.Belem.Ety : cast(tym_t) TYvoid; - elem *e = el_bin(OPcolon2,ty,b2.Belem,b3.Belem); - b.Belem = el_bin(OPcond,ty,b.Belem,e); - } + if (!OTleaf(b3.Belem.Eoper)) + continue; + tym_t ty = (bc2 == BCretexp) ? b2.Belem.Ety : cast(tym_t) TYvoid; + elem *e = el_bin(OPcolon2,ty,b2.Belem,b3.Belem); + b.Belem = el_bin(OPcond,ty,b.Belem,e); b.BC = bc2; b.Belem.ET = b2.Belem.ET; b2.Belem = null; @@ -610,36 +576,19 @@ void brcombine(ref GlobalOptimizer go) if (b2.Belem) { elem *e; - if (PARSER) + if (b3.Belem) { - if (b3.Belem) - { - e = el_bint(OPcolon2,b2.Belem.ET, - b2.Belem,b3.Belem); - e = el_bint(OPcond,e.ET,b.Belem,e); - } - else - { - int op = OPandand; - e = el_bint(op,tstypes[TYint],b.Belem,b2.Belem); - } + if (!OTleaf(b3.Belem.Eoper)) + continue; + e = el_bin(OPcolon2,b2.Belem.Ety, + b2.Belem,b3.Belem); + e = el_bin(OPcond,e.Ety,b.Belem,e); + e.ET = b2.Belem.ET; } else { - if (b3.Belem) - { - if (!OTleaf(b3.Belem.Eoper)) - continue; - e = el_bin(OPcolon2,b2.Belem.Ety, - b2.Belem,b3.Belem); - e = el_bin(OPcond,e.Ety,b.Belem,e); - e.ET = b2.Belem.ET; - } - else - { - int op = OPandand; - e = el_bin(op,TYint,b.Belem,b2.Belem); - } + int op = OPandand; + e = el_bin(op,TYint,b.Belem,b2.Belem); } b2.Belem = null; b.Belem = e; @@ -647,8 +596,7 @@ void brcombine(ref GlobalOptimizer go) else if (b3.Belem) { int op = OPoror; - b.Belem = PARSER ? el_bint(op,tstypes[TYint],b.Belem,b3.Belem) - : el_bin(op,TYint,b.Belem,b3.Belem); + b.Belem = el_bin(op,TYint,b.Belem,b3.Belem); } b.BC = BCgoto; b3.Belem = null; @@ -669,51 +617,6 @@ void brcombine(ref GlobalOptimizer go) anychanges++; } } - else if (bc == BCgoto && PARSER) - { - block *b2 = b.nthSucc(0); - if (!list_next(b2.Bpred) && b2.BC != BCasm // if b is only parent - && b2 != bo.startblock - && b2.BC != BCtry - && b2.BC != BC_try - && b.Btry == b2.Btry - ) - { - if (b2.Belem) - { - if (PARSER) - { - block_appendexp(b,b2.Belem); - } - else if (b.Belem) - b.Belem = el_bin(OPcomma,b2.Belem.Ety,b.Belem,b2.Belem); - else - b.Belem = b2.Belem; - b2.Belem = null; - } - list_subtract(&b.Bsucc,b2); - list_subtract(&b2.Bpred,b); - - /* change predecessor of successors of b2 from b2 to b */ - foreach (bl; ListRange(b2.Bsucc)) - { - list_t bp; - for (bp = list_block(bl).Bpred; bp; bp = list_next(bp)) - { - if (list_block(bp) == b2) - bp.ptr = cast(void *)b; - } - } - - b.BC = b2.BC; - b.BS = b2.BS; - b.Bsucc = b2.Bsucc; - b2.Bsucc = null; - b2.BC = BCret; /* a harmless one */ - debug if (debugc) printf("brcombine(): %p goto %p eliminated\n",b,b2); - anychanges++; - } - } } if (anychanges) { go.changes++; @@ -730,7 +633,6 @@ void brcombine(ref GlobalOptimizer go) private void bropt(ref GlobalOptimizer go) { debug if (debugc) printf("bropt()\n"); - assert(!PARSER); for (block *b = bo.startblock; b; b = b.Bnext) // for each block { elem **pn = &(b.Belem); @@ -941,7 +843,6 @@ void compdfo(ref Barray!(block*) dfo, block* startblock) debug if (debugc) printf("compdfo()\n"); debug assert(OPTIMIZER); block_clearvisit(); - debug assert(!PARSER); dfo.setLength(0); /****************************** @@ -1416,7 +1317,7 @@ private elem * bl_delist(list_t el) private void bltailmerge(ref GlobalOptimizer go) { debug if (debugc) printf("bltailmerge()\n"); - assert(!PARSER && OPTIMIZER); + assert(OPTIMIZER); if (!(go.mfoptim & MFtime)) /* if optimized for space */ { /* Split each block into a reversed linked list of elems */ diff --git a/compiler/src/dmd/backend/cgelem.d b/compiler/src/dmd/backend/cgelem.d index 6715722144f9..33bd56ec63b8 100644 --- a/compiler/src/dmd/backend/cgelem.d +++ b/compiler/src/dmd/backend/cgelem.d @@ -6185,7 +6185,6 @@ beg: elem *doptelem(elem *e, Goal goal) { //printf("doptelem(e = %p, goal = x%x)\n", e, goal); - assert(!PARSER); do { again = false; topair = false; diff --git a/compiler/src/dmd/backend/dcgcv.d b/compiler/src/dmd/backend/dcgcv.d index dfb6a547e0fc..b05c1ded9205 100644 --- a/compiler/src/dmd/backend/dcgcv.d +++ b/compiler/src/dmd/backend/dcgcv.d @@ -1792,7 +1792,7 @@ static if (1) case SC.const_: // The only constants are enum members - value = cast(uint)el_tolongt(s.Svalue); + value = cast(uint)el_tolong(s.Svalue); TOWORD(debsym + 2,S_CONST); TOIDX(debsym + 4,typidx); length = 4 + cgcv.sz_idx; diff --git a/compiler/src/dmd/backend/dout.d b/compiler/src/dmd/backend/dout.d index f32b48e2e5a4..d6301c36d1b6 100644 --- a/compiler/src/dmd/backend/dout.d +++ b/compiler/src/dmd/backend/dout.d @@ -969,7 +969,6 @@ private void writefunc2(Symbol *sfunc, ref GlobalOptimizer go) } assert(b != b.Bnext); } - PARSER = 0; if (eecontext.EEelem) { const marksi = globsym.length; diff --git a/compiler/src/dmd/backend/dwarfdbginf.d b/compiler/src/dmd/backend/dwarfdbginf.d index 37585b2c90be..b6a3b6aa8999 100644 --- a/compiler/src/dmd/backend/dwarfdbginf.d +++ b/compiler/src/dmd/backend/dwarfdbginf.d @@ -3014,7 +3014,7 @@ static if (1) foreach (sl2; ListRange(s.Senum.SEenumlist)) { Symbol *sf = cast(Symbol *)list_ptr(sl2); - const value = cast(uint)el_tolongt(sf.Svalue); + const value = cast(uint)el_tolong(sf.Svalue); debug_info.buf.writeuLEB128(membercode); debug_info.buf.writeStringz(getSymName(sf)); // DW_AT_name diff --git a/compiler/src/dmd/backend/elem.d b/compiler/src/dmd/backend/elem.d index deb3e48a7976..9f3468fc178f 100644 --- a/compiler/src/dmd/backend/elem.d +++ b/compiler/src/dmd/backend/elem.d @@ -494,7 +494,6 @@ elem * el_alloctmp(tym_t ty) elem * el_selecte1(elem *e) { elem *e1; - assert(!PARSER); elem_debug(e); assert(!OTleaf(e.Eoper)); e1 = e.E1; @@ -536,14 +535,9 @@ elem * el_selecte2(elem *e) if (e.Esrcpos.Slinnum) e2.Esrcpos = e.Esrcpos; } - if (PARSER) - el_settype(e2,e.ET); - else - { - e2.Ety = e.Ety; - //if (tyaggregate(e.Ety)) - // e2.Enumbytes = e.Enumbytes; - } + e2.Ety = e.Ety; + //if (tyaggregate(e.Ety)) + // e2.Enumbytes = e.Enumbytes; el_free(e); return e2; } @@ -791,28 +785,6 @@ bool el_anydef(const elem *ed, const(elem)* e) * Make a binary operator node. */ -@trusted -elem* el_bint(OPER op,type *t,elem *e1,elem *e2) -{ - elem *e; - /* e2 is null when OPpostinc is built */ - assert(op < OPMAX && OTbinary(op) && e1); - assert(PARSER); - e = el_calloc(); - if (t) - { - e.ET = t; - type_debug(t); - e.ET.Tcount++; - } - e.Eoper = cast(ubyte)op; - elem_debug(e1); - if (e2) - elem_debug(e2); - e.E1 = e1; - e.E2 = e2; - return e; -} @trusted elem* el_bin(OPER op,tym_t ty,elem *e1,elem *e2) @@ -838,28 +810,6 @@ static if (0) /************************ * Make a unary operator node. */ - -@trusted -elem* el_unat(OPER op,type *t,elem *e1) -{ - debug if (!(op < OPMAX && OTunary(op) && e1)) - printf("op = x%x, e1 = %p\n",op,e1); - - assert(op < OPMAX && OTunary(op) && e1); - assert(PARSER); - elem_debug(e1); - elem* e = el_calloc(); - e.Eoper = cast(ubyte)op; - e.E1 = e1; - if (t) - { - type_debug(t); - t.Tcount++; - e.ET = t; - } - return e; -} - @trusted elem* el_una(OPER op,tym_t ty,elem *e1) { @@ -875,25 +825,6 @@ elem* el_una(OPER op,tym_t ty,elem *e1) return e; } -/******************* - * Make a constant node out of integral type. - */ - -@trusted -elem* el_longt(type *t,targ_llong val) -{ - assert(PARSER); - elem* e = el_calloc(); - e.Eoper = OPconst; - e.ET = t; - if (e.ET) - { - type_debug(t); - e.ET.Tcount++; - } - e.Vllong = val; - return e; -} elem* el_long(tym_t t,targ_llong val) { @@ -1111,7 +1042,6 @@ Lnodep: bool ERTOL(const elem *e) { elem_debug(e); - assert(!PARSER); return OTrtol(e.Eoper) && (!OTopeq(e.Eoper) || config.inline8087 || !tyfloating(e.Ety)); } @@ -1351,7 +1281,6 @@ elem *el_convstring(elem *e) Symbol *s; char *p; - assert(!PARSER); elem_debug(e); assert(e.Eoper == OPstring); p = e.Vstring; @@ -1692,45 +1621,6 @@ elem *el_ctor_dtor(elem *ec, elem *ed, out elem* pedtor) return er; } -/************************** - * Insert destructor information into tree. - * edtor pointer to object being destructed - * e code to do the destruction - */ - -elem *el_dtor(elem *edtor,elem *e) -{ - if (edtor) - { - edtor = el_unat(OPdtor,edtor.ET,edtor); - if (e) - e = el_bint(OPcomma,e.ET,edtor,e); - else - e = edtor; - } - return e; -} - -/********************************** - * Create an elem of the constant 0, of the type t. - */ - -@trusted -elem *el_zero(type *t) -{ - assert(PARSER); - - elem* e = el_calloc(); - e.Eoper = OPconst; - e.ET = t; - if (t) - { - type_debug(t); - e.ET.Tcount++; - } - return(e); -} - /******************* * Find and return pointer to parent of e starting at pe. * Return null if can't find it. @@ -1797,14 +1687,7 @@ L1: if (OTunary(op)) { L2: - if (PARSER) - { - n1 = n1.E1; - n2 = n2.E1; - assert(n1 && n2); - goto L1; - } - else if (OPTIMIZER) + if (OPTIMIZER) { if (op == OPstrpar || op == OPstrctor) { if (/*n1.Enumbytes != n2.Enumbytes ||*/ n1.ET != n2.ET) @@ -1827,13 +1710,10 @@ L1: } else if (OTbinary(op)) { - if (!PARSER) + if (op == OPstreq) { - if (op == OPstreq) - { - if (/*n1.Enumbytes != n2.Enumbytes ||*/ n1.ET != n2.ET) - return false; - } + if (/*n1.Enumbytes != n2.Enumbytes ||*/ n1.ET != n2.ET) + return false; } if (el_matchx(n1.E2, n2.E2, gmatch2)) { @@ -1848,7 +1728,6 @@ L1: case OPconst: if (gmatch2 & 1) break; - Lagain: switch (tybasic(tym)) { case TYshort: @@ -1882,12 +1761,6 @@ L1: break; case TYenum: - if (PARSER) - { tym = n1.ET.Tnext.Tty; - goto Lagain; - } - goto case TYuint; - case TYint: case TYuint: if (_tysize[TYint] == SHORTSIZE) @@ -2106,20 +1979,6 @@ bool el_match5(const elem* n1, const elem* n2) } -/****************************** - * Extract long value from constant parser elem. - */ - -@trusted -targ_llong el_tolongt(elem *e) -{ - const parsersave = PARSER; - PARSER = 1; - const result = el_tolong(e); - PARSER = parsersave; - return result; -} - /****************************** * Extract long value from constant elem. */ @@ -2455,32 +2314,15 @@ void elem_print(const elem* e, int nestlevel = 0) if (e.Esrcpos.Sfilename) printf("%s(%u) ", e.Esrcpos.Sfilename, e.Esrcpos.Slinnum); } - if (!PARSER) - { - printf("cnt=%d ",e.Ecount); - if (!OPTIMIZER) - printf("cs=%d ",e.Ecomsub); - } + printf("cnt=%d ",e.Ecount); + if (!OPTIMIZER) + printf("cs=%d ",e.Ecomsub); printf("%s ", oper_str(e.Eoper)); - enum scpp = false; - if (scpp && PARSER) - { + if ((e.Eoper == OPstrpar || e.Eoper == OPstrctor || e.Eoper == OPstreq) || + e.Ety == TYstruct || e.Ety == TYarray) if (e.ET) - { - type_debug(e.ET); - if (tybasic(e.ET.Tty) == TYstruct) - printf("%d ", cast(int)type_size(e.ET)); - printf("%s\n", tym_str(e.ET.Tty)); - } - } - else - { - if ((e.Eoper == OPstrpar || e.Eoper == OPstrctor || e.Eoper == OPstreq) || - e.Ety == TYstruct || e.Ety == TYarray) - if (e.ET) - printf("%d ", cast(int)type_size(e.ET)); - printf("%s ", tym_str(e.Ety)); - } + printf("%d ", cast(int)type_size(e.ET)); + printf("%s ", tym_str(e.Ety)); if (OTunary(e.Eoper)) { if (e.E2) @@ -2491,8 +2333,8 @@ void elem_print(const elem* e, int nestlevel = 0) } else if (OTbinary(e.Eoper)) { - if (!PARSER && e.Eoper == OPstreq && e.ET) - printf("bytes=%d ", cast(int)type_size(e.ET)); + if (e.Eoper == OPstreq && e.ET) + printf("bytes=%d ", cast(int)type_size(e.ET)); printf("%p %p\n",e.E1,e.E2); elem_print(e.E1, nestlevel + 1); elem_print(e.E2, nestlevel + 1); @@ -2533,7 +2375,6 @@ void elem_print_const(const elem* e) { assert(e.Eoper == OPconst); tym_t tym = tybasic(typemask(e)); -case_tym: switch (tym) { case TYbool: case TYchar: @@ -2560,12 +2401,6 @@ case_tym: assert(0); case TYenum: - if (PARSER) - { tym = e.ET.Tnext.Tty; - goto case_tym; - } - goto case TYint; - case TYint: case TYuint: case TYvoid: /* in case (void)(1) */ diff --git a/compiler/src/dmd/backend/global.d b/compiler/src/dmd/backend/global.d index 675da444a8a8..13f440bad953 100644 --- a/compiler/src/dmd/backend/global.d +++ b/compiler/src/dmd/backend/global.d @@ -114,7 +114,7 @@ public import dmd.backend.var : debuga, debugb, debugc, debugd, debuge, debugf, 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.var : OPTIMIZER, globsym, controlc_saw, pointertype, sytab; public import dmd.backend.cg : fregsaved, localgot, tls_get_addr_sym; public import dmd.backend.blockopt : bo; @@ -155,7 +155,7 @@ public import dmd.backend.dout : outthunk, out_readonly, out_readonly_comdat, public import dmd.backend.blockopt : bc_goal, block_calloc, block_init, block_term, block_next, block_next, block_goto, block_goto, block_goto, block_goto, block_ptr, block_pred, block_clearvisit, block_visit, block_compbcount, blocklist_free, block_optimizer_free, - block_free, block_appendexp, block_endfunc, brcombine, blockopt, compdfo; + block_free, block_appendexp, brcombine, blockopt, compdfo; public import dmd.backend.var : regstring; public import dmd.backend.debugprint; diff --git a/compiler/src/dmd/backend/var.d b/compiler/src/dmd/backend/var.d index f6a984acf654..a8e271bad9ca 100644 --- a/compiler/src/dmd/backend/var.d +++ b/compiler/src/dmd/backend/var.d @@ -35,7 +35,6 @@ __gshared: /* Global flags: */ -char PARSER = 0; // indicate we're in the parser char OPTIMIZER = 0; // indicate we're in the optimizer int structalign; /* alignment for members of structures */ char dbcs = 0; // current double byte character set