Skip to content

Commit dfa46f3

Browse files
authored
merge flowxx into GlobalOptimizer (dlang#22952)
1 parent 0fa4fdc commit dfa46f3

2 files changed

Lines changed: 28 additions & 40 deletions

File tree

compiler/src/dmd/backend/gflow.d

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,6 @@ void* util_realloc(void* p, size_t n, size_t size)
6262
return q;
6363
}
6464

65-
66-
67-
/* Since many routines are nearly identical, we can combine them with */
68-
/* this flag: */
69-
70-
private enum
71-
{
72-
AE = 1,
73-
CP,
74-
VBE
75-
}
76-
77-
78-
private __gshared
79-
{
80-
int flowxx; // one of the above values
81-
}
82-
83-
8465
/***************** REACHING DEFINITIONS *********************/
8566

8667
/************************************
@@ -512,8 +493,8 @@ private void accumrd(ref GlobalOptimizer go, vec_t GEN,vec_t KILL,elem* n,uint d
512493
@trusted
513494
void flowae(ref GlobalOptimizer go, ref BlockOpt bo)
514495
{
515-
flowxx = AE;
516-
flowaecp(go, bo, AE);
496+
go.flowxx = AE;
497+
flowaecp(go, bo);
517498
}
518499

519500
/**************************** COPY PROPAGATION ************************/
@@ -530,21 +511,19 @@ void flowae(ref GlobalOptimizer go, ref BlockOpt bo)
530511
@trusted
531512
void flowcp(ref GlobalOptimizer go, ref BlockOpt bo)
532513
{
533-
flowxx = CP;
534-
flowaecp(go, bo, CP);
514+
go.flowxx = CP;
515+
flowaecp(go, bo);
535516
}
536517

537518
/*****************************************
538519
* Common flow analysis routines for Available Expressions and
539520
* Copy Propagation.
540-
* Input:
541-
* flowxx
542521
*/
543522

544523
@trusted
545-
private void flowaecp(ref GlobalOptimizer go, ref BlockOpt bo, int flowxx)
524+
private void flowaecp(ref GlobalOptimizer go, ref BlockOpt bo)
546525
{
547-
aecpgenkill(go, bo, flowxx); // Compute Bgen and Bkill for AEs or CPs
526+
aecpgenkill(go, bo); // Compute Bgen and Bkill for AEs or CPs
548527
if (go.exptop <= 1) /* if no expressions */
549528
return;
550529

@@ -672,7 +651,7 @@ private void flowaecp(ref GlobalOptimizer go, ref BlockOpt bo, int flowxx)
672651
*/
673652

674653
@trusted
675-
private void aecpgenkill(ref GlobalOptimizer go, ref BlockOpt bo, int flowxx)
654+
private void aecpgenkill(ref GlobalOptimizer go, ref BlockOpt bo)
676655
{
677656
block* this_block;
678657

@@ -743,7 +722,7 @@ private void aecpgenkill(ref GlobalOptimizer go, ref BlockOpt bo, int flowxx)
743722
ae = asgaeelems(n.E1);
744723
// Disallow starred references to avoid problems with VBE's
745724
// being hoisted before tests of an invalid pointer.
746-
if (flowxx == VBE && op == OPind)
725+
if (go.flowxx == VBE && op == OPind)
747726
{
748727
n.Eexp = 0;
749728
return false;
@@ -766,7 +745,7 @@ private void aecpgenkill(ref GlobalOptimizer go, ref BlockOpt bo, int flowxx)
766745
{
767746
n.Eexp = cast(uint)go.expnod.length; // remember index into go.expnod[]
768747
go.expnod.push(n);
769-
if (flowxx == VBE)
748+
if (go.flowxx == VBE)
770749
go.expblk.push(this_block);
771750
return true;
772751
}
@@ -787,7 +766,7 @@ private void aecpgenkill(ref GlobalOptimizer go, ref BlockOpt bo, int flowxx)
787766
{
788767
if (b.Belem)
789768
{
790-
if (flowxx == CP)
769+
if (go.flowxx == CP)
791770
asgcpelems(b.Belem);
792771
else
793772
{
@@ -924,7 +903,7 @@ private void defstarkill(ref GlobalOptimizer go)
924903
{
925904
const exptop = go.exptop;
926905
vec_recycle(go.defkill, exptop);
927-
if (flowxx == CP)
906+
if (go.flowxx == CP)
928907
{
929908
vec_recycle(go.starkill, 0);
930909
vec_recycle(go.vptrkill, 0);
@@ -940,7 +919,7 @@ private void defstarkill(ref GlobalOptimizer go)
940919

941920
auto defkill = go.defkill;
942921

943-
if (flowxx == CP)
922+
if (go.flowxx == CP)
944923
{
945924
foreach (i, n; go.expnod[1 .. exptop])
946925
{
@@ -1025,7 +1004,7 @@ private void defstarkill(ref GlobalOptimizer go)
10251004
@trusted
10261005
void genkillae(ref GlobalOptimizer go, ref BlockOpt bo)
10271006
{
1028-
flowxx = AE;
1007+
go.flowxx = AE;
10291008
assert(go.exptop > 1);
10301009
foreach (b; bo.dfo[])
10311010
{
@@ -1058,7 +1037,7 @@ private void aecpelem(ref GlobalOptimizer go, out vec_t gen, out vec_t kill, ele
10581037
kill = vec_calloc(exptop);
10591038
if (n)
10601039
{
1061-
if (flowxx == VBE)
1040+
if (go.flowxx == VBE)
10621041
accumvbe(go, gen,kill,n);
10631042
else
10641043
accumaecp(go, gen,kill,n);
@@ -1103,7 +1082,7 @@ private void accumaecpx(ref GlobalOptimizer go, elem* n)
11031082
case OPvar:
11041083
case OPconst:
11051084
case OPrelconst:
1106-
if ((flowxx == AE) && n.Eexp)
1085+
if ((go.flowxx == AE) && n.Eexp)
11071086
{ uint b;
11081087
debug assert(go.expnod[n.Eexp] == n);
11091088
b = n.Eexp;
@@ -1180,7 +1159,7 @@ private void accumaecpx(ref GlobalOptimizer go, elem* n)
11801159

11811160
case OPvp_fp:
11821161
case OPcvp_fp: // if vptr access
1183-
if ((flowxx == AE) && n.Eexp)
1162+
if ((go.flowxx == AE) && n.Eexp)
11841163
vec_orass(KILL,go.vptrkill); // kill all other vptr accesses
11851164
break;
11861165

@@ -1216,7 +1195,7 @@ private void accumaecpx(ref GlobalOptimizer go, elem* n)
12161195

12171196
/* Do copy propagation stuff first */
12181197

1219-
if (flowxx == CP)
1198+
if (go.flowxx == CP)
12201199
{
12211200
if (!OTdef(op)) /* if not def elem */
12221201
return;
@@ -1675,8 +1654,8 @@ private void accumlv(vec_t GEN, vec_t KILL, const(elem)* n, const vec_t ambigsym
16751654
@trusted
16761655
void flowvbe(ref GlobalOptimizer go, ref BlockOpt bo)
16771656
{
1678-
flowxx = VBE;
1679-
aecpgenkill(go, bo, VBE); // compute Bgen and Bkill for VBEs
1657+
go.flowxx = VBE;
1658+
aecpgenkill(go, bo); // compute Bgen and Bkill for VBEs
16801659
if (go.exptop <= 1) /* if no candidates for VBEs */
16811660
return;
16821661

compiler/src/dmd/backend/goh.d

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,22 @@ struct DefNode
7070
vec_t DNunambig; // vector of unambiguous definitions
7171
}
7272

73+
// which kind of flow analysisis being done
74+
enum
75+
{
76+
AE = 1,
77+
CP,
78+
VBE
79+
}
80+
7381
/* Global Optimizer variables
7482
*/
7583
struct GlobalOptimizer
7684
{
7785
bool AArch64; // AArch64 is the target
7886
mftype mfoptim;
7987
uint changes; // # of optimizations performed
88+
int flowxx; // AE, CP or VBE
8089

8190
Barray!DefNode defnod; // array of definition elems
8291
uint unambigtop; // number of unambiguous defininitions ( <= deftop )

0 commit comments

Comments
 (0)