Skip to content

Commit

Permalink
bring up to date with dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 6, 2022
1 parent 49b084a commit 2cf1ede
Show file tree
Hide file tree
Showing 9 changed files with 521 additions and 291 deletions.
63 changes: 43 additions & 20 deletions dm/src/dmc/cgelem.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Local optimizations of elem trees
*
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
Expand Down Expand Up @@ -787,12 +789,40 @@ private elem * elmemset(elem *e, goal_t goal)
case SHORTSIZE: tym = TYshort; goto L1;
case LONGSIZE: tym = TYlong; goto L1;
case LLONGSIZE: if (_tysize[TYint] == 2)
goto Ldefault;
goto default;
tym = TYllong; goto L1;

case 16: if (REGSIZE == 8 && e1.Eoper == OPrelconst)
goto L1;
goto default;
L1:
{
tym_t ety = e.Ety;
memset(&value, value & 0xFF, value.sizeof);
if (nbytes == 2 * REGSIZE && e1.Eoper == OPrelconst)
{
/* Rewrite as:
* (*e1.0 = value),(*e1.4 = value),(e1)
*/
tym = REGSIZE == 8 ? TYllong : TYint;

auto e1a = el_copytree(e1);
e1a.Eoper = OPvar;
e1a.Ety = tym;
auto ea = el_bin(OPeq,TYint,e1a,el_long(tym,value));

auto e1b = el_copytree(e1);
e1b.Eoper = OPvar;
e1b.Ety = tym;
e1b.EV.Voffset += REGSIZE;
auto eb = el_bin(OPeq,tym,e1b,el_long(tym,value));

e.EV.E1 = null;
el_free(e);
e = el_combine(el_combine(ea, eb), e1);
e = optelem(e, GOALvalue);
return e;
}
evalue.EV.Vullong = value;
evalue.Ety = tym;
e.Eoper = OPeq;
Expand All @@ -807,11 +837,10 @@ private elem * elmemset(elem *e, goal_t goal)
e.EV.E2 = el_selecte2(e.EV.E2);
e = el_combine(e, tmp);
e = optelem(e,GOALvalue);
break;
}
break;

default:
Ldefault:
break;
}
}
Expand Down Expand Up @@ -3268,7 +3297,7 @@ private elem * elbit(elem *e, goal_t goal)
e.Eoper = OPu8_16;
e.EV.E2 = null;
el_free(e2);
goto L1;
return optelem(e,GOALvalue); // optimize result
}

if (w + b == sz) // if field is left-justified
Expand All @@ -3282,7 +3311,7 @@ private elem * elbit(elem *e, goal_t goal)
e.Eoper = OPs8_16;
e.EV.E2 = null;
el_free(e2);
goto L1;
return optelem(e,GOALvalue); // optimize result
}
m = ~cast(targ_ullong)0;
c = sz - (w + b);
Expand All @@ -3297,7 +3326,6 @@ private elem * elbit(elem *e, goal_t goal)
e.EV.E1 = el_bin(OPshr,tym1,
el_bin(OPshl,tym1,e.EV.E1,el_long(TYint,c)),
el_long(TYint,b));
L1:
return optelem(e,GOALvalue); // optimize result
}

Expand Down Expand Up @@ -3684,7 +3712,9 @@ elem * elstruct(elem *e, goal_t goal)
}
}
else if (I32 && targ1 && targ2)
{
tym = TYllong;
}
assert(tym != TYstruct);
}
assert(tym != ~0);
Expand Down Expand Up @@ -3772,6 +3802,8 @@ elem * elstruct(elem *e, goal_t goal)
break;
}
}
//printf("elstruct return\n");
//elem_print(e);
return e;
}

Expand Down Expand Up @@ -4071,13 +4103,6 @@ static if (0)

if (e1.Eoper == OPcomma)
return cgel_lvalue(e);
version (MARS)
{
// No bit fields to deal with
return e;
}
else
{
if (e1.Eoper != OPbit)
return e;
if (e1.EV.E1.Eoper == OPcomma || OTassign(e1.EV.E1.Eoper))
Expand Down Expand Up @@ -4139,7 +4164,6 @@ else
el_free(e);
return optelem(eres,GOALvalue);
}
}

/**********************************
*/
Expand Down Expand Up @@ -4186,8 +4210,7 @@ private elem * elopass(elem *e, goal_t goal)
{ e = fixconvop(e);
return optelem(e,GOALvalue);
}
version (SCPP) // have bit fields to worry about?
{

goal_t wantres = goal;
if (e1.Eoper == OPbit)
{
Expand Down Expand Up @@ -4266,7 +4289,7 @@ version (SCPP) // have bit fields to worry about?
e = optelem(eres,GOALvalue);
return e;
}
}

{
if (e1.Eoper == OPcomma || OTassign(e1.Eoper))
e = cgel_lvalue(e); // replace (e,v)op=e2 with e,(v op= e2)
Expand Down Expand Up @@ -5732,7 +5755,7 @@ private elem * optelem(elem *e, goal_t goal)
beg:
//__gshared uint count;
//printf("count: %u\n", ++count);
//{ printf("xoptelem: %p ",e); WROP(e.Eoper); printf(" goal x%x\n", goal); }
//{ printf("xoptelem: %p %s goal x%x\n",e, oper_str(e.Eoper), goal); }
assert(e);
elem_debug(e);
assert(e.Ecount == 0); // no CSEs
Expand Down Expand Up @@ -6208,11 +6231,11 @@ beg:
}

// if (debugb)
// { print("optelem: %p ",e); WROP(op); print("\n"); }
// { print("optelem: %p %s\n",e, oper_str(op)); }

static if (0)
{
{ print("xoptelem: %p ",e); WROP(e.Eoper); print("\n"); }
printf("xoptelem: %p %s\n", e, oper_str(e.Eoper));
elem_print(e);
e = (*elxxx[op])(e, goal);
printf("After:\n");
Expand Down
32 changes: 28 additions & 4 deletions dm/src/dmc/debugprint.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Pretty print data structures
*
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
Expand Down Expand Up @@ -133,6 +135,21 @@ void WROP(uint oper)
ferr(" ");
}

/***************************
* Convert OPER to string.
* Params:
* oper = operator number
* Returns:
* pointer to string
*/

@trusted
const(char)* oper_str(uint oper)
{
assert(oper < OPMAX);
return debtab[oper];
}

/*******************************
* Write TYxxxx
*/
Expand All @@ -158,6 +175,10 @@ void WRTYxx(tym_t t)
// if (t & mTYtransu)
// printf("mTYtransu|");
//#endif
if (t & mTYxmmgpr)
printf("mTYxmmgpr|");
if (t & mTYgprxmm)
printf("mTYgprxmm|");
t = tybasic(t);
if (t >= TYMAX)
{ printf("TY %x\n",cast(int)t);
Expand Down Expand Up @@ -210,7 +231,8 @@ void WReqn(elem *e)
return;
if (OTunary(e.Eoper))
{
WROP(e.Eoper);
ferr(oper_str(e.Eoper));
ferr(" ");
if (OTbinary(e.EV.E1.Eoper))
{ nest++;
ferr("(");
Expand Down Expand Up @@ -238,7 +260,8 @@ void WReqn(elem *e)
else
WReqn(e.EV.E1);
ferr(" ");
WROP(e.Eoper);
ferr(oper_str(e.Eoper));
ferr(" ");
if (e.Eoper == OPstreq)
printf("%d", cast(int)type_size(e.ET));
ferr(" ");
Expand Down Expand Up @@ -286,12 +309,13 @@ void WReqn(elem *e)
case OPhalt:
case OPdctor:
case OPddtor:
WROP(e.Eoper);
ferr(oper_str(e.Eoper));
ferr(" ");
break;
case OPstrthis:
break;
default:
WROP(e.Eoper);
ferr(oper_str(e.Eoper));
assert(0);
}
}
Expand Down
3 changes: 3 additions & 0 deletions dm/src/dmc/dexp2.d
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ err:


/*************************
* C11 6.5.2.1-2
* E1[E2] is converted to *(E1 + E2*s1)
* No error checking is done.
*/
Expand Down Expand Up @@ -2134,7 +2135,9 @@ elem *convertchk(elem *e)
}

/**************************
* C11 6.3.2.1-3
* If e is <array of>, convert it to <pointer to>.
* C11 6.3.2.1-4
* If e is <function>, convert it to <pointer to><function>.
*/

Expand Down
4 changes: 2 additions & 2 deletions dm/src/dmc/dnwc.d
Original file line number Diff line number Diff line change
Expand Up @@ -3360,14 +3360,14 @@ private type * getprototype(const char *fident,type *tret)
tp2.Tflags &= ~TFfuncparam;
type_free(pt);

/* Convert function to pointer to function */
// C11 6.7.6.3-8 Convert function to pointer to function
if (tyfunc(tparam.Tty))
{ tparam = newpointer(tparam);
tparam.Tnext.Tcount--;
tparam.Tcount++;
}

/* Convert <array of> to <pointer to> in prototypes */
// C11 6.7.6.3-7 Convert <array of> to <pointer to> in prototypes
else if (tybasic(tparam.Tty) == TYarray)
tparam = topointer(tparam);

Expand Down
49 changes: 48 additions & 1 deletion dm/src/dmc/dvec.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,16 @@ __gshared VecGlobal vecGlobal;

private pure vec_base_t MASK(uint b) { return cast(vec_base_t)1 << (b & VECMASK); }

/****
* Returns:
* number of bits in the vector
*/
@trusted
pure ref inout(vec_base_t) vec_numbits(inout vec_t v) { return v[-1]; }
/****
* Returns:
* number of bytes in the vector
*/
@trusted
pure ref inout(vec_base_t) vec_dim(inout vec_t v) { return v[-2]; }

Expand Down Expand Up @@ -312,14 +320,15 @@ void vec_clearbit(size_t b, vec_t v)
*/

@trusted
pure
size_t vec_testbit(size_t b, const vec_t v)
{
if (!v)
return 0;
debug
{
if (!(v && b < vec_numbits(v)))
printf("vec_testbit(v = %p,b = %d): numbits = %d dim = %d\n",
printf("vec_setbit(v = %p,b = %d): numbits = %d dim = %d\n",
v, cast(int) b, cast(int) (v ? vec_numbits(v) : 0), cast(int) (v ? vec_dim(v) : 0));
}
assert(v && b < vec_numbits(v));
Expand Down Expand Up @@ -363,6 +372,33 @@ size_t vec_index(size_t b, const vec_t vec)
return vec_numbits(vec);
}

/********************************
* Count number of set bits in vector `v`
* Params:
* v = vector
* Returns:
* number of set bits
*/
@safe
pure
uint vec_numBitsSet(const vec_t vec)
{
uint n = 0;
size_t length = vec_numbits(vec);
for (size_t i = 0; (i = vec_index(i, vec)) < length; ++i)
++n;
return n;
}

uint vec_numBitsSet2(const vec_t vec)
{
uint n = 0;
foreach (i; VecRange(vec))
++n;
return n;
}


/********************************
* Compute v1 &= v2.
*/
Expand Down Expand Up @@ -648,3 +684,14 @@ void vec_print(const vec_t v)
}


struct VecRange
{
uint i;
const vec_t v;

@nogc @safe nothrow pure:
this(const vec_t v) { this.v = v; i = vec_index(0, v); }
bool empty() const { return i == vec_numbits(v); }
uint front() const { return i; }
void popFront() { i = vec_index(i + 1, v); }
}
3 changes: 3 additions & 0 deletions dm/src/dmc/global.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Declarations for back end
*
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
Expand Down Expand Up @@ -432,6 +434,7 @@ extern __gshared const(char)*[32] regstring;
void WRclass(int c);
void WRTYxx(tym_t t);
void WROP(uint oper);
@trusted const(char)* oper_str(uint oper);
void WRBC(uint bc);
void WRarglst(list_t a);
void WRblock(block *b);
Expand Down
Loading

2 comments on commit 2cf1ede

@Geod24
Copy link
Contributor

@Geod24 Geod24 commented on 2cf1ede Jan 25, 2022

Choose a reason for hiding this comment

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

This just reverted all the fixes I have been doing to the Makefile so that other people could compile DMC...

@WalterBright
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that. I was just doing a merge and wasn't paying much attention. Please add back your makefile changes.

Please sign in to comment.