Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/ddmd/backend/blockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/ddmd/backend/blockopt.c, backend/blockopt.c)
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/ddmd/backend/blockopt.c
*/


Expand Down Expand Up @@ -132,7 +133,7 @@ void block_next(Blockx *bctx,int bc,block *bn)
bctx->curblock->Bflags |= bctx->flags;
}
#else
void block_next(enum BC bc,block *bn)
void block_next(int bc,block *bn)
{
curblock->BC = bc;
curblock->Bsymend = globsym.top;
Expand Down Expand Up @@ -591,12 +592,18 @@ void blockopt(int iter)
} while (go.changes);
#ifdef DEBUG
if (debugw)
{
numberBlocks(startblock);
for (b = startblock; b; b = b->Bnext)
WRblock(b);
}
#endif
}
else
{
#ifdef DEBUG
numberBlocks(startblock);
#endif
/* canonicalize the trees */
for (b = startblock; b; b = b->Bnext)
{
Expand Down Expand Up @@ -630,8 +637,11 @@ void blockopt(int iter)
comsubs(); /* eliminate common subexpressions */
#ifdef DEBUG
if (debugb)
for (b = startblock; b; b = b->Bnext)
WRblock(b);
{
numberBlocks(startblock);
for (b = startblock; b; b = b->Bnext)
WRblock(b);
}
#endif
}
}
Expand All @@ -649,6 +659,7 @@ void brcombine()
int anychanges;

cmes("brcombine()\n");
//numberBlocks(startblock);
//for (b = startblock; b; b = b->Bnext)
//WRblock(b);

Expand Down
1 change: 1 addition & 0 deletions src/ddmd/backend/cc.d
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ struct block
// is executed (optimizer and codegen)

uint Bdfoidx; // index of this block in dfo[]
uint Bnumber; // sequence number of block
union
{
// CPP
Expand Down
1 change: 1 addition & 0 deletions src/ddmd/backend/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ struct block
// is executed (optimizer and codegen)

unsigned Bdfoidx; // index of this block in dfo[]
unsigned Bnumber; // sequence number of block
union
{
// CPP
Expand Down
46 changes: 34 additions & 12 deletions src/ddmd/backend/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/ddmd/backend/debug.c, backend/debug.c)
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/ddmd/backend/debug.c
*/

#if !SPP
Expand Down Expand Up @@ -318,25 +319,34 @@ void WRblock(block *b)
int ncases;

assert(b);
printf("***** block %p ", b);
WRBC(b->BC);
printf("%2d: ", b->Bnumber); WRBC(b->BC);
if (b->Btry)
printf(" Btry=%p",b->Btry);
printf(" Btry=B%d",b->Btry ? b->Btry->Bnumber : 0);
if (b->Bindex)
printf(" Bindex=%d",b->Bindex);
if (b->BC == BC_finally)
printf(" b_ret=%p", b->BS.BI_FINALLY.b_ret);
printf(" b_ret=B%d", b->BS.BI_FINALLY.b_ret ? b->BS.BI_FINALLY.b_ret->Bnumber : 0);
#if MARS
if (b->Bsrcpos.Sfilename)
printf(" %s(%u)", b->Bsrcpos.Sfilename, b->Bsrcpos.Slinnum);
#endif
printf("\n");
if (b->Belem) elem_print(b->Belem);
if (b->Belem)
{
if (0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be false instead of 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I ask is because of #7310

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is never going to be an incorrect argument to if.

elem_print(b->Belem);
else
{
ferr("\t");
WReqn(b->Belem);
printf(";\n");
}
}
if (b->Bpred)
{
printf("\tBpred:");
for (list_t bl = b->Bpred; bl; bl = list_next(bl))
printf(" %p",list_block(bl));
printf(" B%d",list_block(bl)->Bnumber);
printf("\n");
}
list_t bl = b->Bsucc;
Expand All @@ -347,10 +357,10 @@ void WRblock(block *b)
assert(pu);
ncases = *pu;
printf("\tncases = %d\n",ncases);
printf("\tdefault: %p\n",list_block(bl));
printf("\tdefault: B%d\n",list_block(bl) ? list_block(bl)->Bnumber : 0);
while (ncases--)
{ bl = list_next(bl);
printf("\tcase %lld: %p\n",(long long)*++pu,list_block(bl));
printf("\tcase %lld: B%d\n",(long long)*++pu,list_block(bl)->Bnumber);
}
break;
case BCiftrue:
Expand All @@ -371,7 +381,7 @@ void WRblock(block *b)
{
printf("\tBsucc:");
for ( ; bl; bl = list_next(bl))
printf(" %p",list_block(bl));
printf(" B%d",list_block(bl)->Bnumber);
printf("\n");
}
break;
Expand All @@ -385,12 +395,24 @@ void WRblock(block *b)
}
}

void WRfunc()
/*****************************
* Number the blocks starting at 1.
* So much more convenient than pointer values.
*/
void numberBlocks(block *startblock)
{
block *b;
unsigned number = 0;
for (block *b = startblock; b; b = b->Bnext)
b->Bnumber = ++number;
}

void WRfunc()
{
printf("func: '%s'\n",funcsym_p->Sident);
for (b = startblock; b; b = b->Bnext)

numberBlocks(startblock);

for (block *b = startblock; b; b = b->Bnext)
WRblock(b);
}

Expand Down
3 changes: 2 additions & 1 deletion src/ddmd/backend/global.d
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ extern __gshared uint[BCMAX] bc_goal;
block* block_calloc();
void block_init();
void block_term();
void block_next(BC,block *);
void block_next(int,block *);
void block_next(Blockx *bctx,int bc,block *bn);
block *block_goto(Blockx *bctx,BC bc,block *bn);
void block_setlabel(uint lbl);
Expand Down Expand Up @@ -438,6 +438,7 @@ void WRarglst(list_t a);
void WRblock(block *b);
void WRblocklist(list_t bl);
void WReqn(elem *e);
void numberBlocks(block* startblock);
void WRfunc();
void WRdefnod();
void WRFL(FL);
Expand Down
3 changes: 2 additions & 1 deletion src/ddmd/backend/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ extern unsigned bc_goal[BCMAX];
block *block_calloc();
void block_init();
void block_term();
void block_next(BC,block *);
void block_next(int,block *);
void block_next(Blockx *bctx,int bc,block *bn);
block *block_goto(Blockx *bctx,int bc,block *bn);
void block_setlabel(unsigned lbl);
Expand Down Expand Up @@ -425,6 +425,7 @@ void WRarglst(list_t a);
void WRblock(block *b);
void WRblocklist(list_t bl);
void WReqn(elem *e);
void numberBlocks(block* startblock);
void WRfunc();
void WRdefnod();
void WRFL(FL);
Expand Down