commit 4d41a720d00b2571d1918e0e57b107c475961f5f
parent 7b2cd38cc36458375c34b3da23e71f58c8751ea0
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Wed, 9 Mar 2016 11:50:44 -0500
use opdesc[] in isel.c
Diffstat:
| M | lisc/isel.c | | | 70 | ++++++++-------------------------------------------------------------- |
| M | lisc/lisc.h | | | 2 | ++ |
| M | lisc/parse.c | | | 116 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
3 files changed, 68 insertions(+), 120 deletions(-)
diff --git a/lisc/isel.c b/lisc/isel.c
@@ -110,41 +110,7 @@ rslot(Ref r, Fn *fn)
static int
argcls(Ins *i, int n)
{
- switch (i->op) {
- case OStores:
- return n == 0 ? Ks : Kl;
- case OStored:
- return n == 0 ? Kd : Kl;
- case OStoreb:
- case OStoreh:
- case OStorew:
- return n == 0 ? Kw : Kl;
- case OStorel:
- return Kl;
- case OExts:
- return Ks;
- case OTruncd:
- return Kd;
- case OFtosi:
- return KWIDE(i->cls) ? Kl : Kw;
- case OSitof:
- return KWIDE(i->cls) ? Kd : Ks;
- case OCast:
- switch (i->cls) {
- case Kw: return Ks;
- case Kl: return Kd;
- case Ks: return Kw;
- case Kd: return Kl;
- }
- default:
- if (OCmpw <= i->op && i->op <= OCmpd1)
- diag("isel: invalid call to argcls");
- if (isload(i->op))
- return Kl;
- if (isext(i->op))
- return Kw;
- return i->cls;
- }
+ return opdesc[i->op].argcls[n][i->cls];
}
static void
@@ -357,34 +323,14 @@ Emit:
static Ins *
flagi(Ins *i0, Ins *i)
{
- while (i>i0)
- switch ((--i)->op) {
- default:
- if (iscmp(i->op, 0, 0))
- return i;
- if (isext(i->op) || isload(i->op))
- continue;
- return 0;
- case OAdd: /* flag-setting */
- case OSub:
- case OAnd:
- case OOr:
- case OXor:
+ while (i>i0) {
+ i--;
+ if (opdesc[i->op].sflag)
return i;
- case OCopy: /* flag-transparent */
- case OStored:
- case OStores:
- case OStorel:
- case OStorew:
- case OStoreh:
- case OStoreb:
- case OExts:
- case OTruncd:
- case OFtosi:
- case OSitof:
- case OCast:
- ;
- }
+ if (opdesc[i->op].lflag)
+ continue;
+ return 0;
+ }
return 0;
}
diff --git a/lisc/lisc.h b/lisc/lisc.h
@@ -303,6 +303,8 @@ struct OpDesc {
char *name;
int nmem;
char argcls[2][4];
+ uint sflag:1; /* sets flags */
+ uint lflag:1; /* leaves flags */
};
struct Ins {
diff --git a/lisc/parse.c b/lisc/parse.c
@@ -4,73 +4,73 @@
enum {
Kx = -1, /* Invalid operand */
- Km = Kl, /* Memory pointer */
+ Km = Kl, /* Memory pointer (for x64) */
};
OpDesc opdesc[NOp] = {
#define A(a,b,c,d) {[Kw]=K##a, [Kl]=K##b, [Ks]=K##c, [Kd]=K##d}
- /* NAME NM ARGCLS0 ARGCLS1 */
- [OAdd] = { "add", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [OSub] = { "sub", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [ODiv] = { "div", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [ORem] = { "rem", 2, {A(w,l,x,x), A(w,l,x,x)} },
- [OMul] = { "mul", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [OAnd] = { "and", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [OOr] = { "or", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [OXor] = { "xor", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [OStored] = { "stored", 0, {A(d,d,d,d), A(m,m,m,m)} },
- [OStores] = { "stores", 0, {A(s,s,s,s), A(m,m,m,m)} },
- [OStorel] = { "storel", 0, {A(l,l,l,l), A(m,m,m,m)} },
- [OStorew] = { "storew", 0, {A(w,w,w,w), A(m,m,m,m)} },
- [OStoreh] = { "storeh", 0, {A(w,w,w,w), A(m,m,m,m)} },
- [OStoreb] = { "storeb", 0, {A(w,w,w,w), A(m,m,m,m)} },
- [OLoad] = { "load", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OLoadsw] = { "loadsw", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OLoaduw] = { "loaduw", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OLoadsh] = { "loadsh", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OLoaduh] = { "loaduh", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OLoadsb] = { "loadsb", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OLoadub] = { "loadub", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OExtsw] = { "extsw", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OExtuw] = { "extuw", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OExtsh] = { "extsh", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OExtuh] = { "extuh", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OExtsb] = { "extsb", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OExtub] = { "extub", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OExts] = { "exts", 0, {A(w,w,w,w), A(x,x,x,x)} },
- [OTruncd] = { "truncd", 0, {A(d,d,d,d), A(x,x,x,x)} },
- [OFtosi] = { "ftosi", 0, {A(s,d,x,x), A(x,x,x,x)} },
- [OSitof] = { "sitof", 0, {A(x,x,w,l), A(x,x,x,x)} },
- [OCast] = { "cast", 0, {A(s,d,w,l), A(x,x,x,x)} },
- [OCopy] = { "copy", 1, {A(w,l,s,d), A(x,x,x,x)} },
- [ONop] = { "nop", 0, {A(x,x,x,x), A(x,x,x,x)} },
- [OSwap] = { "swap", 2, {A(w,l,s,d), A(w,l,s,d)} },
- [OSign] = { "sign", 0, {A(w,l,x,x), A(x,x,x,x)} },
- [OSAlloc] = { "salloc", 0, {A(x,l,x,x), A(x,x,x,x)} },
- [OXDiv] = { "xdiv", 1, {A(w,l,x,x), A(x,x,x,x)} },
- [OXCmp] = { "xcmp", 1, {A(w,l,s,d), A(w,l,s,d)} },
- [OXTest] = { "xtest", 1, {A(w,l,x,x), A(w,l,x,x)} },
- [OAddr] = { "addr", 0, {A(x,m,x,x), A(x,x,x,x)} },
- [OPar] = { "parn", 0, {A(x,x,x,x), A(x,x,x,x)} },
- [OParc] = { "parc", 0, {A(x,x,x,x), A(x,x,x,x)} },
- [OArg] = { "arg", 0, {A(x,x,x,x), A(x,x,x,x)} },
- [OArgc] = { "argc", 0, {A(x,x,x,x), A(x,x,x,x)} },
- [OCall] = { "call", 0, {A(m,m,m,m), A(x,x,x,x)} },
- [OXSetnp] = { "xsetnp", 0, {A(x,x,x,x), A(x,x,x,x)} },
- [OXSetp] = { "xsetp", 0, {A(x,x,x,x), A(x,x,x,x)}},
- [OAlloc] = { "alloc4", 1, {A(l,l,l,l), A(x,x,x,x)} },
- [OAlloc+1] = { "alloc8", 1, {A(l,l,l,l), A(x,x,x,x)} },
- [OAlloc+2] = { "alloc16", 1, {A(l,l,l,l), A(x,x,x,x)} },
+ /* NAME NM ARGCLS0 ARGCLS1 SF LF */
+ [OAdd] = { "add", 2, {A(w,l,s,d), A(w,l,s,d)}, 1, 0 },
+ [OSub] = { "sub", 2, {A(w,l,s,d), A(w,l,s,d)}, 1, 0 },
+ [ODiv] = { "div", 2, {A(w,l,s,d), A(w,l,s,d)}, 0, 0 },
+ [ORem] = { "rem", 2, {A(w,l,x,x), A(w,l,x,x)}, 0, 0 },
+ [OMul] = { "mul", 2, {A(w,l,s,d), A(w,l,s,d)}, 0, 0 },
+ [OAnd] = { "and", 2, {A(w,l,s,d), A(w,l,s,d)}, 1, 0 },
+ [OOr] = { "or", 2, {A(w,l,s,d), A(w,l,s,d)}, 1, 0 },
+ [OXor] = { "xor", 2, {A(w,l,s,d), A(w,l,s,d)}, 1, 0 },
+ [OStored] = { "stored", 0, {A(d,d,d,d), A(m,m,m,m)}, 0, 1 },
+ [OStores] = { "stores", 0, {A(s,s,s,s), A(m,m,m,m)}, 0, 1 },
+ [OStorel] = { "storel", 0, {A(l,l,l,l), A(m,m,m,m)}, 0, 1 },
+ [OStorew] = { "storew", 0, {A(w,w,w,w), A(m,m,m,m)}, 0, 1 },
+ [OStoreh] = { "storeh", 0, {A(w,w,w,w), A(m,m,m,m)}, 0, 1 },
+ [OStoreb] = { "storeb", 0, {A(w,w,w,w), A(m,m,m,m)}, 0, 1 },
+ [OLoad] = { "load", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OLoadsw] = { "loadsw", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OLoaduw] = { "loaduw", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OLoadsh] = { "loadsh", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OLoaduh] = { "loaduh", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OLoadsb] = { "loadsb", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OLoadub] = { "loadub", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 1 },
+ [OExtsw] = { "extsw", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OExtuw] = { "extuw", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OExtsh] = { "extsh", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OExtuh] = { "extuh", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OExtsb] = { "extsb", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OExtub] = { "extub", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OExts] = { "exts", 0, {A(w,w,w,w), A(x,x,x,x)}, 0, 1 },
+ [OTruncd] = { "truncd", 0, {A(d,d,d,d), A(x,x,x,x)}, 0, 1 },
+ [OFtosi] = { "ftosi", 0, {A(s,d,x,x), A(x,x,x,x)}, 0, 1 },
+ [OSitof] = { "sitof", 0, {A(x,x,w,l), A(x,x,x,x)}, 0, 1 },
+ [OCast] = { "cast", 0, {A(s,d,w,l), A(x,x,x,x)}, 0, 1 },
+ [OCopy] = { "copy", 1, {A(w,l,s,d), A(x,x,x,x)}, 0, 1 },
+ [ONop] = { "nop", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 1 },
+ [OSwap] = { "swap", 2, {A(w,l,s,d), A(w,l,s,d)}, 0, 0 },
+ [OSign] = { "sign", 0, {A(w,l,x,x), A(x,x,x,x)}, 0, 0 },
+ [OSAlloc] = { "salloc", 0, {A(x,l,x,x), A(x,x,x,x)}, 0, 0 },
+ [OXDiv] = { "xdiv", 1, {A(w,l,x,x), A(x,x,x,x)}, 0, 0 },
+ [OXCmp] = { "xcmp", 1, {A(w,l,s,d), A(w,l,s,d)}, 1, 0 },
+ [OXTest] = { "xtest", 1, {A(w,l,x,x), A(w,l,x,x)}, 1, 0 },
+ [OAddr] = { "addr", 0, {A(m,m,x,x), A(x,x,x,x)}, 0, 1 },
+ [OPar] = { "parn", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 0 },
+ [OParc] = { "parc", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 0 },
+ [OArg] = { "arg", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 0 },
+ [OArgc] = { "argc", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 0 },
+ [OCall] = { "call", 0, {A(m,m,m,m), A(x,x,x,x)}, 0, 0 },
+ [OXSetnp] = { "xsetnp", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 0 },
+ [OXSetp] = { "xsetp", 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 0 },
+ [OAlloc] = { "alloc4", 1, {A(l,l,l,l), A(x,x,x,x)}, 0, 0 },
+ [OAlloc+1] = { "alloc8", 1, {A(l,l,l,l), A(x,x,x,x)}, 0, 0 },
+ [OAlloc+2] = { "alloc16", 1, {A(l,l,l,l), A(x,x,x,x)}, 0, 0 },
#define X(c) \
- [OCmpw+IC##c] = { "c" #c "w", 0, {A(w,w,x,x), A(w,w,x,x)} }, \
- [OCmpl+IC##c] = { "c" #c "l", 0, {A(l,l,x,x), A(l,l,x,x)} }, \
- [OXSet+IC##c] = { "xset" #c, 0, {A(x,x,x,x), A(x,x,x,x)} },
+ [OCmpw+IC##c] = { "c" #c "w", 0, {A(w,w,x,x), A(w,w,x,x)}, 1, 0 }, \
+ [OCmpl+IC##c] = { "c" #c "l", 0, {A(l,l,x,x), A(l,l,x,x)}, 1, 0 }, \
+ [OXSet+IC##c] = { "xset" #c, 0, {A(x,x,x,x), A(x,x,x,x)}, 0, 1 },
ICMPS(X)
#undef X
#define X(c) \
- [OCmps+FC##c] = { "c" #c "s", 0, {A(s,s,x,x), A(s,s,x,x)} }, \
- [OCmpd+FC##c] = { "c" #c "d", 0, {A(d,d,x,x), A(d,d,x,x)} },
+ [OCmps+FC##c] = { "c" #c "s", 0, {A(s,s,x,x), A(s,s,x,x)}, 1, 0 }, \
+ [OCmpd+FC##c] = { "c" #c "d", 0, {A(d,d,x,x), A(d,d,x,x)}, 1, 0 },
FCMPS(X)
#undef X