Skip to content

Commit 2cf1ede

Browse files
committed
bring up to date with dmd
1 parent 49b084a commit 2cf1ede

9 files changed

Lines changed: 521 additions & 291 deletions

File tree

dm/src/dmc/cgelem.d

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/**
2+
* Local optimizations of elem trees
3+
*
24
* Compiler implementation of the
35
* $(LINK2 http://www.dlang.org, D programming language).
46
*
@@ -787,12 +789,40 @@ private elem * elmemset(elem *e, goal_t goal)
787789
case SHORTSIZE: tym = TYshort; goto L1;
788790
case LONGSIZE: tym = TYlong; goto L1;
789791
case LLONGSIZE: if (_tysize[TYint] == 2)
790-
goto Ldefault;
792+
goto default;
791793
tym = TYllong; goto L1;
794+
795+
case 16: if (REGSIZE == 8 && e1.Eoper == OPrelconst)
796+
goto L1;
797+
goto default;
792798
L1:
793799
{
794800
tym_t ety = e.Ety;
795801
memset(&value, value & 0xFF, value.sizeof);
802+
if (nbytes == 2 * REGSIZE && e1.Eoper == OPrelconst)
803+
{
804+
/* Rewrite as:
805+
* (*e1.0 = value),(*e1.4 = value),(e1)
806+
*/
807+
tym = REGSIZE == 8 ? TYllong : TYint;
808+
809+
auto e1a = el_copytree(e1);
810+
e1a.Eoper = OPvar;
811+
e1a.Ety = tym;
812+
auto ea = el_bin(OPeq,TYint,e1a,el_long(tym,value));
813+
814+
auto e1b = el_copytree(e1);
815+
e1b.Eoper = OPvar;
816+
e1b.Ety = tym;
817+
e1b.EV.Voffset += REGSIZE;
818+
auto eb = el_bin(OPeq,tym,e1b,el_long(tym,value));
819+
820+
e.EV.E1 = null;
821+
el_free(e);
822+
e = el_combine(el_combine(ea, eb), e1);
823+
e = optelem(e, GOALvalue);
824+
return e;
825+
}
796826
evalue.EV.Vullong = value;
797827
evalue.Ety = tym;
798828
e.Eoper = OPeq;
@@ -807,11 +837,10 @@ private elem * elmemset(elem *e, goal_t goal)
807837
e.EV.E2 = el_selecte2(e.EV.E2);
808838
e = el_combine(e, tmp);
809839
e = optelem(e,GOALvalue);
810-
break;
811840
}
841+
break;
812842

813843
default:
814-
Ldefault:
815844
break;
816845
}
817846
}
@@ -3268,7 +3297,7 @@ private elem * elbit(elem *e, goal_t goal)
32683297
e.Eoper = OPu8_16;
32693298
e.EV.E2 = null;
32703299
el_free(e2);
3271-
goto L1;
3300+
return optelem(e,GOALvalue); // optimize result
32723301
}
32733302

32743303
if (w + b == sz) // if field is left-justified
@@ -3282,7 +3311,7 @@ private elem * elbit(elem *e, goal_t goal)
32823311
e.Eoper = OPs8_16;
32833312
e.EV.E2 = null;
32843313
el_free(e2);
3285-
goto L1;
3314+
return optelem(e,GOALvalue); // optimize result
32863315
}
32873316
m = ~cast(targ_ullong)0;
32883317
c = sz - (w + b);
@@ -3297,7 +3326,6 @@ private elem * elbit(elem *e, goal_t goal)
32973326
e.EV.E1 = el_bin(OPshr,tym1,
32983327
el_bin(OPshl,tym1,e.EV.E1,el_long(TYint,c)),
32993328
el_long(TYint,b));
3300-
L1:
33013329
return optelem(e,GOALvalue); // optimize result
33023330
}
33033331

@@ -3684,7 +3712,9 @@ elem * elstruct(elem *e, goal_t goal)
36843712
}
36853713
}
36863714
else if (I32 && targ1 && targ2)
3715+
{
36873716
tym = TYllong;
3717+
}
36883718
assert(tym != TYstruct);
36893719
}
36903720
assert(tym != ~0);
@@ -3772,6 +3802,8 @@ elem * elstruct(elem *e, goal_t goal)
37723802
break;
37733803
}
37743804
}
3805+
//printf("elstruct return\n");
3806+
//elem_print(e);
37753807
return e;
37763808
}
37773809

@@ -4071,13 +4103,6 @@ static if (0)
40714103

40724104
if (e1.Eoper == OPcomma)
40734105
return cgel_lvalue(e);
4074-
version (MARS)
4075-
{
4076-
// No bit fields to deal with
4077-
return e;
4078-
}
4079-
else
4080-
{
40814106
if (e1.Eoper != OPbit)
40824107
return e;
40834108
if (e1.EV.E1.Eoper == OPcomma || OTassign(e1.EV.E1.Eoper))
@@ -4139,7 +4164,6 @@ else
41394164
el_free(e);
41404165
return optelem(eres,GOALvalue);
41414166
}
4142-
}
41434167

41444168
/**********************************
41454169
*/
@@ -4186,8 +4210,7 @@ private elem * elopass(elem *e, goal_t goal)
41864210
{ e = fixconvop(e);
41874211
return optelem(e,GOALvalue);
41884212
}
4189-
version (SCPP) // have bit fields to worry about?
4190-
{
4213+
41914214
goal_t wantres = goal;
41924215
if (e1.Eoper == OPbit)
41934216
{
@@ -4266,7 +4289,7 @@ version (SCPP) // have bit fields to worry about?
42664289
e = optelem(eres,GOALvalue);
42674290
return e;
42684291
}
4269-
}
4292+
42704293
{
42714294
if (e1.Eoper == OPcomma || OTassign(e1.Eoper))
42724295
e = cgel_lvalue(e); // replace (e,v)op=e2 with e,(v op= e2)
@@ -5732,7 +5755,7 @@ private elem * optelem(elem *e, goal_t goal)
57325755
beg:
57335756
//__gshared uint count;
57345757
//printf("count: %u\n", ++count);
5735-
//{ printf("xoptelem: %p ",e); WROP(e.Eoper); printf(" goal x%x\n", goal); }
5758+
//{ printf("xoptelem: %p %s goal x%x\n",e, oper_str(e.Eoper), goal); }
57365759
assert(e);
57375760
elem_debug(e);
57385761
assert(e.Ecount == 0); // no CSEs
@@ -6208,11 +6231,11 @@ beg:
62086231
}
62096232

62106233
// if (debugb)
6211-
// { print("optelem: %p ",e); WROP(op); print("\n"); }
6234+
// { print("optelem: %p %s\n",e, oper_str(op)); }
62126235

62136236
static if (0)
62146237
{
6215-
{ print("xoptelem: %p ",e); WROP(e.Eoper); print("\n"); }
6238+
printf("xoptelem: %p %s\n", e, oper_str(e.Eoper));
62166239
elem_print(e);
62176240
e = (*elxxx[op])(e, goal);
62186241
printf("After:\n");

dm/src/dmc/debugprint.d

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/**
2+
* Pretty print data structures
3+
*
24
* Compiler implementation of the
35
* $(LINK2 http://www.dlang.org, D programming language).
46
*
@@ -133,6 +135,21 @@ void WROP(uint oper)
133135
ferr(" ");
134136
}
135137

138+
/***************************
139+
* Convert OPER to string.
140+
* Params:
141+
* oper = operator number
142+
* Returns:
143+
* pointer to string
144+
*/
145+
146+
@trusted
147+
const(char)* oper_str(uint oper)
148+
{
149+
assert(oper < OPMAX);
150+
return debtab[oper];
151+
}
152+
136153
/*******************************
137154
* Write TYxxxx
138155
*/
@@ -158,6 +175,10 @@ void WRTYxx(tym_t t)
158175
// if (t & mTYtransu)
159176
// printf("mTYtransu|");
160177
//#endif
178+
if (t & mTYxmmgpr)
179+
printf("mTYxmmgpr|");
180+
if (t & mTYgprxmm)
181+
printf("mTYgprxmm|");
161182
t = tybasic(t);
162183
if (t >= TYMAX)
163184
{ printf("TY %x\n",cast(int)t);
@@ -210,7 +231,8 @@ void WReqn(elem *e)
210231
return;
211232
if (OTunary(e.Eoper))
212233
{
213-
WROP(e.Eoper);
234+
ferr(oper_str(e.Eoper));
235+
ferr(" ");
214236
if (OTbinary(e.EV.E1.Eoper))
215237
{ nest++;
216238
ferr("(");
@@ -238,7 +260,8 @@ void WReqn(elem *e)
238260
else
239261
WReqn(e.EV.E1);
240262
ferr(" ");
241-
WROP(e.Eoper);
263+
ferr(oper_str(e.Eoper));
264+
ferr(" ");
242265
if (e.Eoper == OPstreq)
243266
printf("%d", cast(int)type_size(e.ET));
244267
ferr(" ");
@@ -286,12 +309,13 @@ void WReqn(elem *e)
286309
case OPhalt:
287310
case OPdctor:
288311
case OPddtor:
289-
WROP(e.Eoper);
312+
ferr(oper_str(e.Eoper));
313+
ferr(" ");
290314
break;
291315
case OPstrthis:
292316
break;
293317
default:
294-
WROP(e.Eoper);
318+
ferr(oper_str(e.Eoper));
295319
assert(0);
296320
}
297321
}

dm/src/dmc/dexp2.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ err:
13521352

13531353

13541354
/*************************
1355+
* C11 6.5.2.1-2
13551356
* E1[E2] is converted to *(E1 + E2*s1)
13561357
* No error checking is done.
13571358
*/
@@ -2134,7 +2135,9 @@ elem *convertchk(elem *e)
21342135
}
21352136

21362137
/**************************
2138+
* C11 6.3.2.1-3
21372139
* If e is <array of>, convert it to <pointer to>.
2140+
* C11 6.3.2.1-4
21382141
* If e is <function>, convert it to <pointer to><function>.
21392142
*/
21402143

dm/src/dmc/dnwc.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,14 +3360,14 @@ private type * getprototype(const char *fident,type *tret)
33603360
tp2.Tflags &= ~TFfuncparam;
33613361
type_free(pt);
33623362

3363-
/* Convert function to pointer to function */
3363+
// C11 6.7.6.3-8 Convert function to pointer to function
33643364
if (tyfunc(tparam.Tty))
33653365
{ tparam = newpointer(tparam);
33663366
tparam.Tnext.Tcount--;
33673367
tparam.Tcount++;
33683368
}
33693369

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

dm/src/dmc/dvec.d

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,16 @@ __gshared VecGlobal vecGlobal;
179179

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

182+
/****
183+
* Returns:
184+
* number of bits in the vector
185+
*/
182186
@trusted
183187
pure ref inout(vec_base_t) vec_numbits(inout vec_t v) { return v[-1]; }
188+
/****
189+
* Returns:
190+
* number of bytes in the vector
191+
*/
184192
@trusted
185193
pure ref inout(vec_base_t) vec_dim(inout vec_t v) { return v[-2]; }
186194

@@ -312,14 +320,15 @@ void vec_clearbit(size_t b, vec_t v)
312320
*/
313321

314322
@trusted
323+
pure
315324
size_t vec_testbit(size_t b, const vec_t v)
316325
{
317326
if (!v)
318327
return 0;
319328
debug
320329
{
321330
if (!(v && b < vec_numbits(v)))
322-
printf("vec_testbit(v = %p,b = %d): numbits = %d dim = %d\n",
331+
printf("vec_setbit(v = %p,b = %d): numbits = %d dim = %d\n",
323332
v, cast(int) b, cast(int) (v ? vec_numbits(v) : 0), cast(int) (v ? vec_dim(v) : 0));
324333
}
325334
assert(v && b < vec_numbits(v));
@@ -363,6 +372,33 @@ size_t vec_index(size_t b, const vec_t vec)
363372
return vec_numbits(vec);
364373
}
365374

375+
/********************************
376+
* Count number of set bits in vector `v`
377+
* Params:
378+
* v = vector
379+
* Returns:
380+
* number of set bits
381+
*/
382+
@safe
383+
pure
384+
uint vec_numBitsSet(const vec_t vec)
385+
{
386+
uint n = 0;
387+
size_t length = vec_numbits(vec);
388+
for (size_t i = 0; (i = vec_index(i, vec)) < length; ++i)
389+
++n;
390+
return n;
391+
}
392+
393+
uint vec_numBitsSet2(const vec_t vec)
394+
{
395+
uint n = 0;
396+
foreach (i; VecRange(vec))
397+
++n;
398+
return n;
399+
}
400+
401+
366402
/********************************
367403
* Compute v1 &= v2.
368404
*/
@@ -648,3 +684,14 @@ void vec_print(const vec_t v)
648684
}
649685

650686

687+
struct VecRange
688+
{
689+
uint i;
690+
const vec_t v;
691+
692+
@nogc @safe nothrow pure:
693+
this(const vec_t v) { this.v = v; i = vec_index(0, v); }
694+
bool empty() const { return i == vec_numbits(v); }
695+
uint front() const { return i; }
696+
void popFront() { i = vec_index(i + 1, v); }
697+
}

dm/src/dmc/global.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/**
2+
* Declarations for back end
3+
*
24
* Compiler implementation of the
35
* $(LINK2 http://www.dlang.org, D programming language).
46
*
@@ -432,6 +434,7 @@ extern __gshared const(char)*[32] regstring;
432434
void WRclass(int c);
433435
void WRTYxx(tym_t t);
434436
void WROP(uint oper);
437+
@trusted const(char)* oper_str(uint oper);
435438
void WRBC(uint bc);
436439
void WRarglst(list_t a);
437440
void WRblock(block *b);

0 commit comments

Comments
 (0)