2015-06-29 06:56:11 -04:00
|
|
|
#include <assert.h>
|
2015-07-30 21:32:43 -04:00
|
|
|
#include <inttypes.h>
|
2015-06-11 08:49:34 -04:00
|
|
|
#include <stdio.h>
|
2015-07-03 12:16:39 -04:00
|
|
|
#include <stdlib.h>
|
2015-07-15 18:01:38 -04:00
|
|
|
#include <string.h>
|
2015-06-11 08:49:34 -04:00
|
|
|
|
2015-07-03 12:16:39 -04:00
|
|
|
typedef unsigned int uint;
|
2015-10-22 16:40:52 -04:00
|
|
|
typedef unsigned short ushort;
|
2015-09-25 12:14:50 -04:00
|
|
|
typedef unsigned long ulong;
|
2015-07-17 17:02:09 -04:00
|
|
|
|
|
|
|
typedef struct Bits Bits;
|
|
|
|
typedef struct Ref Ref;
|
|
|
|
typedef struct OpDesc OpDesc;
|
|
|
|
typedef struct Ins Ins;
|
|
|
|
typedef struct Phi Phi;
|
|
|
|
typedef struct Blk Blk;
|
2015-11-13 13:12:22 -05:00
|
|
|
typedef struct Use Use;
|
2015-08-03 13:17:44 -04:00
|
|
|
typedef struct Tmp Tmp;
|
|
|
|
typedef struct Con Con;
|
2015-10-23 11:28:45 -04:00
|
|
|
typedef struct Addr Mem;
|
2015-07-17 17:02:09 -04:00
|
|
|
typedef struct Fn Fn;
|
2015-09-08 16:16:08 -04:00
|
|
|
typedef struct Typ Typ;
|
2015-10-07 22:26:13 -04:00
|
|
|
typedef struct Dat Dat;
|
2015-07-02 16:06:29 -04:00
|
|
|
|
2015-08-13 16:10:54 -04:00
|
|
|
enum Reg {
|
2015-08-01 21:05:18 -04:00
|
|
|
RXX,
|
|
|
|
|
|
|
|
RAX, /* caller-save */
|
2015-07-19 07:03:38 -04:00
|
|
|
RCX,
|
|
|
|
RDX,
|
|
|
|
RSI,
|
|
|
|
RDI,
|
|
|
|
R8,
|
|
|
|
R9,
|
|
|
|
R10,
|
|
|
|
R11,
|
2015-08-01 18:17:06 -04:00
|
|
|
|
|
|
|
RBX, /* callee-save */
|
2015-07-19 07:03:38 -04:00
|
|
|
R12,
|
|
|
|
R13,
|
|
|
|
R14,
|
|
|
|
R15,
|
2015-08-01 18:17:06 -04:00
|
|
|
|
2015-07-27 14:34:22 -04:00
|
|
|
RBP, /* reserved */
|
2015-08-01 18:17:06 -04:00
|
|
|
RSP,
|
|
|
|
|
2015-11-27 11:25:23 -05:00
|
|
|
XMM0, /* sse */
|
|
|
|
XMM1,
|
|
|
|
XMM2,
|
|
|
|
XMM3,
|
|
|
|
XMM4,
|
|
|
|
XMM5,
|
|
|
|
XMM6,
|
|
|
|
XMM7,
|
|
|
|
XMM8,
|
|
|
|
XMM9,
|
|
|
|
XMM10,
|
|
|
|
XMM11,
|
|
|
|
XMM12,
|
|
|
|
XMM13,
|
|
|
|
XMM14,
|
|
|
|
XMM15,
|
|
|
|
|
2015-08-13 16:10:54 -04:00
|
|
|
Tmp0, /* first non-reg temporary */
|
|
|
|
|
2016-02-04 14:00:26 -05:00
|
|
|
NIReg = R12 - RAX + 1,
|
2016-02-15 15:34:34 -05:00
|
|
|
NFReg = XMM14 - XMM0 + 1,
|
2015-11-30 12:53:30 -05:00
|
|
|
NISave = 9,
|
2016-02-15 15:34:34 -05:00
|
|
|
NFSave = NFReg,
|
2015-11-30 12:53:30 -05:00
|
|
|
NRSave = NISave + NFSave,
|
2015-09-20 17:46:17 -04:00
|
|
|
NRClob = 5,
|
2015-07-19 07:03:38 -04:00
|
|
|
};
|
|
|
|
|
2015-06-11 08:49:34 -04:00
|
|
|
enum {
|
2015-07-02 16:06:29 -04:00
|
|
|
NString = 32,
|
2015-07-14 06:46:48 -04:00
|
|
|
NPred = 15,
|
|
|
|
NBlk = 128,
|
|
|
|
NIns = 256,
|
2015-08-19 10:47:27 -04:00
|
|
|
NAlign = 3,
|
2015-09-07 21:59:45 -04:00
|
|
|
NSeg = 32,
|
2015-09-10 22:55:03 -04:00
|
|
|
NTyp = 128,
|
2015-07-15 18:01:38 -04:00
|
|
|
|
|
|
|
BITS = 4,
|
2015-07-23 18:09:03 -04:00
|
|
|
NBit = 64,
|
2015-06-11 08:49:34 -04:00
|
|
|
};
|
|
|
|
|
2015-07-15 18:01:38 -04:00
|
|
|
struct Bits {
|
2015-09-20 17:46:17 -04:00
|
|
|
ulong t[BITS];
|
2015-07-15 18:01:38 -04:00
|
|
|
};
|
|
|
|
|
2015-09-25 12:14:50 -04:00
|
|
|
#define BIT(n) (1ul << (n))
|
2015-11-09 21:34:59 -05:00
|
|
|
#define BZERO(b) ((b) = (Bits){{0}})
|
2015-07-15 18:01:38 -04:00
|
|
|
#define BGET(b, n) (1&((b).t[n/NBit]>>(n%NBit)))
|
2015-09-20 17:46:17 -04:00
|
|
|
#define BSET(b, n) ((b).t[n/NBit] |= BIT(n%NBit))
|
|
|
|
#define BCLR(b, n) ((b).t[n/NBit] &= ~BIT(n%NBit))
|
2015-07-15 12:41:51 -04:00
|
|
|
|
|
|
|
struct Ref {
|
2015-07-24 09:31:48 -04:00
|
|
|
uint16_t type:2;
|
|
|
|
uint16_t val:14;
|
2015-07-15 12:41:51 -04:00
|
|
|
};
|
|
|
|
|
2015-10-20 13:04:07 -04:00
|
|
|
enum Alt {
|
|
|
|
AType,
|
|
|
|
ACall,
|
2015-10-23 13:50:26 -04:00
|
|
|
AMem,
|
2015-10-20 13:04:07 -04:00
|
|
|
|
|
|
|
AShift = 12,
|
|
|
|
AMask = (1<<AShift) - 1
|
|
|
|
};
|
|
|
|
|
2015-07-02 16:06:29 -04:00
|
|
|
enum {
|
2015-08-03 13:17:44 -04:00
|
|
|
RTmp,
|
|
|
|
RCon,
|
2015-10-23 13:50:26 -04:00
|
|
|
RSlot,
|
2015-09-14 23:36:26 -04:00
|
|
|
RAlt,
|
2015-10-20 13:04:07 -04:00
|
|
|
|
|
|
|
RAType = RAlt + AType,
|
|
|
|
RACall = RAlt + ACall,
|
2015-10-23 13:50:26 -04:00
|
|
|
RAMem = RAlt + AMem,
|
2015-10-20 13:04:07 -04:00
|
|
|
|
2015-07-24 09:31:48 -04:00
|
|
|
NRef = (1<<14) - 1
|
2015-07-02 16:06:29 -04:00
|
|
|
};
|
|
|
|
|
2015-07-17 16:54:01 -04:00
|
|
|
#define R (Ref){0, 0}
|
2015-08-03 13:17:44 -04:00
|
|
|
#define TMP(x) (Ref){RTmp, x}
|
|
|
|
#define CON(x) (Ref){RCon, x}
|
2015-08-07 14:27:20 -04:00
|
|
|
#define CON_Z CON(0) /* reserved zero constant */
|
2015-10-23 13:50:26 -04:00
|
|
|
#define SLOT(x) (Ref){RSlot, x}
|
2015-10-20 13:04:07 -04:00
|
|
|
#define TYPE(x) (Ref){RAlt, (x)|(AType<<AShift)}
|
|
|
|
#define CALL(x) (Ref){RAlt, (x)|(ACall<<AShift)}
|
2015-10-23 13:50:26 -04:00
|
|
|
#define MEM(x) (assert(x<(1<<(AShift-1)) && "too many mems"), \
|
|
|
|
(Ref){RAlt, (x)|(AMem<<AShift)})
|
2015-06-11 08:49:34 -04:00
|
|
|
|
2015-07-17 16:54:01 -04:00
|
|
|
static inline int req(Ref a, Ref b)
|
2016-02-03 16:00:45 -05:00
|
|
|
{
|
|
|
|
return a.type == b.type && a.val == b.val;
|
|
|
|
}
|
|
|
|
|
2015-07-17 16:54:01 -04:00
|
|
|
static inline int rtype(Ref r)
|
2015-10-20 13:04:07 -04:00
|
|
|
{
|
|
|
|
if (req(r, R))
|
|
|
|
return -1;
|
|
|
|
if (r.type == RAlt)
|
|
|
|
return RAlt + (r.val >> AShift);
|
|
|
|
return r.type;
|
|
|
|
}
|
2016-02-03 16:00:45 -05:00
|
|
|
|
2015-08-24 12:39:55 -04:00
|
|
|
static inline int isreg(Ref r)
|
2016-02-03 16:00:45 -05:00
|
|
|
{
|
|
|
|
return rtype(r) == RTmp && r.val < Tmp0;
|
|
|
|
}
|
2015-07-17 16:54:01 -04:00
|
|
|
|
2016-02-11 16:10:08 -05:00
|
|
|
enum ICmp {
|
|
|
|
#define ICMPS(X) \
|
|
|
|
X(ule) \
|
|
|
|
X(ult) \
|
|
|
|
X(sle) \
|
|
|
|
X(slt) \
|
|
|
|
X(sgt) \
|
|
|
|
X(sge) \
|
|
|
|
X(ugt) \
|
|
|
|
X(uge) \
|
|
|
|
X(eq) \
|
|
|
|
X(ne) /* make sure icmpop() below works! */
|
|
|
|
|
|
|
|
#define X(c) IC##c,
|
|
|
|
ICMPS(X)
|
2015-10-19 17:28:21 -04:00
|
|
|
#undef X
|
2016-02-11 16:10:08 -05:00
|
|
|
NICmp,
|
2015-08-05 11:37:10 -04:00
|
|
|
|
2016-02-11 16:10:08 -05:00
|
|
|
ICXnp = NICmp, /* x64 specific */
|
|
|
|
ICXp,
|
|
|
|
NXICmp
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int icmpop(int c)
|
|
|
|
{
|
|
|
|
return c >= ICeq ? c : ICuge - c;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum FCmp {
|
|
|
|
#define FCMPS(X) \
|
|
|
|
X(le) \
|
|
|
|
X(lt) \
|
|
|
|
X(gt) \
|
|
|
|
X(ge) \
|
|
|
|
X(ne) \
|
|
|
|
X(eq) \
|
|
|
|
X(o) \
|
|
|
|
X(uo)
|
|
|
|
|
|
|
|
#define X(c) FC##c,
|
|
|
|
FCMPS(X)
|
|
|
|
#undef X
|
|
|
|
NFCmp
|
2016-02-03 16:00:45 -05:00
|
|
|
};
|
|
|
|
|
2015-11-30 11:44:37 -05:00
|
|
|
enum Class {
|
|
|
|
Kw,
|
|
|
|
Kl,
|
|
|
|
Ks,
|
|
|
|
Kd
|
|
|
|
};
|
|
|
|
|
2015-11-30 12:53:30 -05:00
|
|
|
#define KWIDE(k) ((k)&1)
|
|
|
|
#define KBASE(k) ((k)>>1)
|
|
|
|
|
2015-08-13 16:10:54 -04:00
|
|
|
enum Op {
|
2015-08-05 11:37:10 -04:00
|
|
|
OXXX,
|
2015-08-08 18:32:03 -04:00
|
|
|
|
2015-08-09 17:55:05 -04:00
|
|
|
/* public instructions */
|
2015-07-02 16:06:29 -04:00
|
|
|
OAdd,
|
2015-06-11 08:49:34 -04:00
|
|
|
OSub,
|
2015-06-29 06:56:11 -04:00
|
|
|
ODiv,
|
2015-07-18 16:41:02 -04:00
|
|
|
ORem,
|
2015-08-16 14:19:54 -04:00
|
|
|
OMul,
|
2015-08-12 15:25:53 -04:00
|
|
|
OAnd,
|
2016-02-11 16:10:08 -05:00
|
|
|
OCmpw,
|
|
|
|
OCmpw1 = OCmpw + NICmp-1,
|
|
|
|
OCmpl,
|
|
|
|
OCmpl1 = OCmpl + NICmp-1,
|
|
|
|
OCmps,
|
|
|
|
OCmps1 = OCmps + NFCmp-1,
|
|
|
|
OCmpd,
|
|
|
|
OCmpd1 = OCmpd + NFCmp-1,
|
2015-12-08 13:39:17 -05:00
|
|
|
|
2015-11-30 11:44:37 -05:00
|
|
|
OStored,
|
|
|
|
OStores,
|
2015-08-11 16:26:12 -04:00
|
|
|
OStorel,
|
|
|
|
OStorew,
|
2015-11-30 10:18:03 -05:00
|
|
|
OStoreh,
|
2015-08-08 17:53:48 -04:00
|
|
|
OStoreb,
|
2016-02-18 19:40:40 -05:00
|
|
|
#define isstore(o) (OStored <= o && o <= OStoreb)
|
|
|
|
OLoadsw, /* needs to match OExt (mem.c) */
|
2015-12-08 13:39:17 -05:00
|
|
|
OLoaduw,
|
|
|
|
OLoadsh,
|
|
|
|
OLoaduh,
|
|
|
|
OLoadsb,
|
|
|
|
OLoadub,
|
2016-02-18 19:40:40 -05:00
|
|
|
OLoad,
|
|
|
|
#define isload(o) (OLoadsw <= o && o <= OLoad)
|
2015-12-27 14:13:00 -05:00
|
|
|
OExtsw,
|
|
|
|
OExtuw,
|
|
|
|
OExtsh,
|
|
|
|
OExtuh,
|
|
|
|
OExtsb,
|
|
|
|
OExtub,
|
2016-02-18 19:40:40 -05:00
|
|
|
#define isext(o) (OExtsw <= o && o <= OExtub)
|
2015-12-08 13:39:17 -05:00
|
|
|
|
2015-08-12 15:25:53 -04:00
|
|
|
OAlloc,
|
2015-08-19 10:47:27 -04:00
|
|
|
OAlloc1 = OAlloc + NAlign-1,
|
2015-12-08 13:39:17 -05:00
|
|
|
|
2015-08-16 11:34:52 -04:00
|
|
|
OCopy,
|
2015-08-08 18:32:03 -04:00
|
|
|
NPubOp,
|
|
|
|
|
2015-09-09 18:33:00 -04:00
|
|
|
/* function instructions */
|
2015-09-17 19:29:49 -04:00
|
|
|
OPar = NPubOp,
|
|
|
|
OParc,
|
|
|
|
OArg,
|
2015-09-09 18:33:00 -04:00
|
|
|
OArgc,
|
|
|
|
OCall,
|
|
|
|
|
2015-08-08 18:32:03 -04:00
|
|
|
/* reserved instructions */
|
2015-09-09 18:33:00 -04:00
|
|
|
ONop,
|
2015-08-16 11:34:52 -04:00
|
|
|
OAddr,
|
2015-07-27 14:34:22 -04:00
|
|
|
OSwap,
|
2015-08-01 18:17:06 -04:00
|
|
|
OSign,
|
2015-09-10 22:55:03 -04:00
|
|
|
OSAlloc,
|
|
|
|
OXPush,
|
2015-08-01 15:49:02 -04:00
|
|
|
OXDiv,
|
2015-08-24 12:39:55 -04:00
|
|
|
OXCmp,
|
2015-08-05 11:37:10 -04:00
|
|
|
OXSet,
|
2016-02-12 10:27:05 -05:00
|
|
|
OXSetnp = OXSet + ICXnp,
|
|
|
|
OXSetp = OXSet + ICXp,
|
2015-08-24 12:39:55 -04:00
|
|
|
OXTest,
|
2015-08-08 18:32:03 -04:00
|
|
|
NOp
|
2015-06-11 08:49:34 -04:00
|
|
|
};
|
|
|
|
|
2015-08-13 16:10:54 -04:00
|
|
|
enum Jmp {
|
2015-07-02 16:06:29 -04:00
|
|
|
JXXX,
|
2015-09-22 16:52:48 -04:00
|
|
|
JRet0,
|
|
|
|
JRetw,
|
|
|
|
JRetl,
|
2016-02-23 10:54:56 -05:00
|
|
|
JRets,
|
|
|
|
JRetd,
|
2015-09-22 16:52:48 -04:00
|
|
|
JRetc,
|
2015-06-11 08:49:34 -04:00
|
|
|
JJmp,
|
2015-08-07 16:01:07 -04:00
|
|
|
JJnz,
|
2015-08-07 14:27:20 -04:00
|
|
|
JXJc,
|
2016-02-12 10:27:05 -05:00
|
|
|
JXJnp = JXJc + ICXnp,
|
|
|
|
JXJp = JXJc + ICXp,
|
2015-08-09 17:55:05 -04:00
|
|
|
NJmp
|
2015-06-11 08:49:34 -04:00
|
|
|
};
|
|
|
|
|
2015-07-15 18:01:38 -04:00
|
|
|
struct OpDesc {
|
|
|
|
char *name;
|
2015-08-08 18:06:47 -04:00
|
|
|
int nmem;
|
2015-07-15 18:01:38 -04:00
|
|
|
};
|
|
|
|
|
2015-06-11 08:49:34 -04:00
|
|
|
struct Ins {
|
2015-11-30 11:44:37 -05:00
|
|
|
ushort op:14;
|
2015-07-02 16:06:29 -04:00
|
|
|
Ref to;
|
2015-07-15 13:23:37 -04:00
|
|
|
Ref arg[2];
|
2015-11-30 11:44:37 -05:00
|
|
|
ushort cls:2;
|
2015-06-11 08:49:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Phi {
|
2015-07-02 16:06:29 -04:00
|
|
|
Ref to;
|
2015-07-14 06:46:48 -04:00
|
|
|
Ref arg[NPred];
|
|
|
|
Blk *blk[NPred];
|
|
|
|
uint narg;
|
2015-11-30 11:44:37 -05:00
|
|
|
int cls;
|
2015-07-14 06:46:48 -04:00
|
|
|
Phi *link;
|
2015-06-11 08:49:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Blk {
|
2015-07-14 06:46:48 -04:00
|
|
|
Phi *phi;
|
|
|
|
Ins *ins;
|
|
|
|
uint nins;
|
2015-06-11 08:49:34 -04:00
|
|
|
struct {
|
2015-07-02 16:06:29 -04:00
|
|
|
short type;
|
2015-06-11 08:49:34 -04:00
|
|
|
Ref arg;
|
|
|
|
} jmp;
|
2015-07-02 16:06:29 -04:00
|
|
|
Blk *s1;
|
|
|
|
Blk *s2;
|
2015-07-10 12:37:41 -04:00
|
|
|
Blk *link;
|
2015-07-02 16:06:29 -04:00
|
|
|
|
2015-07-22 03:00:03 -04:00
|
|
|
int id;
|
|
|
|
int visit;
|
2015-11-09 17:35:20 -05:00
|
|
|
|
|
|
|
Blk *idom;
|
|
|
|
Blk *dom, *dlink;
|
|
|
|
Blk **fron;
|
|
|
|
int nfron;
|
|
|
|
|
2015-07-14 06:46:48 -04:00
|
|
|
Blk **pred;
|
|
|
|
uint npred;
|
2015-07-21 17:08:48 -04:00
|
|
|
Bits in, out, gen;
|
2015-11-30 12:53:30 -05:00
|
|
|
int nlive[2];
|
2015-07-20 17:53:58 -04:00
|
|
|
int loop;
|
2015-07-10 16:17:55 -04:00
|
|
|
char name[NString];
|
2015-06-29 06:56:11 -04:00
|
|
|
};
|
|
|
|
|
2015-11-13 13:12:22 -05:00
|
|
|
struct Use {
|
|
|
|
enum {
|
|
|
|
UXXX,
|
|
|
|
UPhi,
|
|
|
|
UIns,
|
|
|
|
UJmp,
|
|
|
|
} type;
|
|
|
|
int bid;
|
|
|
|
union {
|
2015-11-13 15:22:58 -05:00
|
|
|
Ins *ins;
|
|
|
|
Phi *phi;
|
2015-11-13 13:12:22 -05:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2015-08-03 13:17:44 -04:00
|
|
|
struct Tmp {
|
2015-07-02 16:06:29 -04:00
|
|
|
char name[NString];
|
2015-11-13 13:12:22 -05:00
|
|
|
Use *use;
|
2015-07-20 05:20:20 -04:00
|
|
|
uint ndef, nuse;
|
2015-07-23 18:09:03 -04:00
|
|
|
uint cost;
|
2015-10-20 16:19:00 -04:00
|
|
|
short slot;
|
2015-11-30 12:53:30 -05:00
|
|
|
short cls;
|
2015-11-03 16:47:47 -05:00
|
|
|
struct {
|
|
|
|
int r;
|
|
|
|
ulong m;
|
|
|
|
} hint;
|
2015-09-25 13:02:39 -04:00
|
|
|
int phi;
|
2015-11-10 17:12:51 -05:00
|
|
|
int visit;
|
2015-06-29 06:56:11 -04:00
|
|
|
};
|
|
|
|
|
2015-08-03 13:17:44 -04:00
|
|
|
struct Con {
|
2015-07-30 21:32:43 -04:00
|
|
|
enum {
|
|
|
|
CUndef,
|
2015-12-08 10:36:22 -05:00
|
|
|
CBits,
|
2015-07-30 21:32:43 -04:00
|
|
|
CAddr,
|
|
|
|
} type;
|
|
|
|
char label[NString];
|
2015-12-08 10:36:22 -05:00
|
|
|
union {
|
|
|
|
int64_t i;
|
2016-02-12 14:20:12 -05:00
|
|
|
double d;
|
|
|
|
float s;
|
2015-12-08 10:36:22 -05:00
|
|
|
} bits;
|
2016-02-15 14:22:22 -05:00
|
|
|
char flt; /* for printing, see parse.c */
|
2015-07-30 21:32:43 -04:00
|
|
|
};
|
|
|
|
|
2015-10-23 11:28:45 -04:00
|
|
|
typedef struct Addr Addr;
|
|
|
|
|
|
|
|
struct Addr { /* x64 addressing */
|
|
|
|
Con offset;
|
|
|
|
Ref base;
|
|
|
|
Ref index;
|
|
|
|
int scale;
|
|
|
|
};
|
|
|
|
|
2015-06-29 06:56:11 -04:00
|
|
|
struct Fn {
|
2015-07-02 16:06:29 -04:00
|
|
|
Blk *start;
|
2015-08-03 13:17:44 -04:00
|
|
|
Tmp *tmp;
|
|
|
|
Con *con;
|
2015-10-23 11:28:45 -04:00
|
|
|
Mem *mem;
|
2015-08-03 13:17:44 -04:00
|
|
|
int ntmp;
|
|
|
|
int ncon;
|
2015-10-23 11:28:45 -04:00
|
|
|
int nmem;
|
2015-07-10 13:55:47 -04:00
|
|
|
int nblk;
|
2015-09-25 11:33:50 -04:00
|
|
|
int retty;
|
2015-07-10 13:55:47 -04:00
|
|
|
Blk **rpo;
|
2015-09-20 17:46:17 -04:00
|
|
|
ulong reg;
|
2015-09-29 22:25:49 -04:00
|
|
|
int slot;
|
2015-09-07 21:59:45 -04:00
|
|
|
char name[NString];
|
|
|
|
};
|
|
|
|
|
2015-09-08 16:16:08 -04:00
|
|
|
struct Typ {
|
2015-09-07 23:06:13 -04:00
|
|
|
char name[NString];
|
2015-09-07 21:59:45 -04:00
|
|
|
int dark;
|
2015-09-07 23:08:27 -04:00
|
|
|
uint size;
|
2015-09-07 21:59:45 -04:00
|
|
|
int align;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint flt:1;
|
|
|
|
uint len:31;
|
2015-09-10 22:55:03 -04:00
|
|
|
} seg[NSeg+1];
|
2015-06-11 08:49:34 -04:00
|
|
|
};
|
2015-06-29 06:56:11 -04:00
|
|
|
|
2015-10-07 22:26:13 -04:00
|
|
|
struct Dat {
|
|
|
|
enum {
|
2015-10-08 14:49:00 -04:00
|
|
|
DStart,
|
|
|
|
DEnd,
|
2015-10-07 22:26:13 -04:00
|
|
|
DName,
|
|
|
|
DAlign,
|
|
|
|
DA,
|
|
|
|
DB,
|
|
|
|
DH,
|
|
|
|
DW,
|
|
|
|
DL
|
|
|
|
} type;
|
|
|
|
union {
|
|
|
|
int64_t num;
|
2016-02-12 14:20:12 -05:00
|
|
|
double fltd;
|
|
|
|
float flts;
|
2015-10-07 22:26:13 -04:00
|
|
|
char *str;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2015-06-29 06:56:11 -04:00
|
|
|
|
2015-07-22 04:50:52 -04:00
|
|
|
/* main.c */
|
|
|
|
extern char debug['Z'+1];
|
2015-08-03 13:17:44 -04:00
|
|
|
void dumpts(Bits *, Tmp *, FILE *);
|
2015-07-22 04:50:52 -04:00
|
|
|
|
2015-10-05 17:23:54 -04:00
|
|
|
/* util.c */
|
2015-09-10 22:55:03 -04:00
|
|
|
extern Typ typ[NTyp];
|
2015-10-05 17:23:54 -04:00
|
|
|
extern Ins insb[NIns], *curi;
|
2015-07-19 07:03:38 -04:00
|
|
|
void diag(char *);
|
2015-10-08 14:05:13 -04:00
|
|
|
void *emalloc(size_t);
|
2015-07-10 11:41:11 -04:00
|
|
|
void *alloc(size_t);
|
2015-10-06 22:51:51 -04:00
|
|
|
void freeall(void);
|
2015-10-13 17:20:44 -04:00
|
|
|
Blk *bnew(void);
|
2015-10-05 17:23:54 -04:00
|
|
|
void emit(int, int, Ref, Ref, Ref);
|
|
|
|
void emiti(Ins);
|
|
|
|
int bcnt(Bits *);
|
2015-10-06 13:22:46 -04:00
|
|
|
void idup(Ins **, Ins *, ulong);
|
2015-10-06 13:15:52 -04:00
|
|
|
Ins *icpy(Ins *, Ins *, ulong);
|
2015-10-13 17:20:44 -04:00
|
|
|
void *vnew(ulong, size_t);
|
2015-10-06 20:42:54 -04:00
|
|
|
void vgrow(void *, ulong);
|
2015-11-03 16:47:47 -05:00
|
|
|
int phicls(int, Tmp *);
|
2015-10-06 20:42:54 -04:00
|
|
|
Ref newtmp(char *, Fn *);
|
|
|
|
Ref getcon(int64_t, Fn *);
|
2015-10-22 11:48:55 -04:00
|
|
|
void addcon(Con *, Con *);
|
2015-10-05 17:23:54 -04:00
|
|
|
|
|
|
|
/* parse.c */
|
|
|
|
extern OpDesc opdesc[NOp];
|
2015-10-08 22:02:32 -04:00
|
|
|
void parse(FILE *, void (Dat *), void (Fn *));
|
2015-07-15 02:55:10 -04:00
|
|
|
void printfn(Fn *, FILE *);
|
2015-11-13 15:22:58 -05:00
|
|
|
void printref(Ref, Fn *, FILE *);
|
2015-07-10 11:41:11 -04:00
|
|
|
|
2015-11-19 21:38:23 -05:00
|
|
|
/* mem.c */
|
|
|
|
void memopt(Fn *);
|
|
|
|
|
2015-07-10 11:41:11 -04:00
|
|
|
/* ssa.c */
|
2015-11-11 21:21:54 -05:00
|
|
|
void filluse(Fn *);
|
2015-07-10 11:41:11 -04:00
|
|
|
void fillpreds(Fn *);
|
2015-07-10 13:55:47 -04:00
|
|
|
void fillrpo(Fn *);
|
2015-11-09 17:35:20 -05:00
|
|
|
void ssa(Fn *);
|
2015-07-15 18:01:38 -04:00
|
|
|
|
2015-11-13 15:22:58 -05:00
|
|
|
/* copy.c */
|
|
|
|
void copy(Fn *);
|
|
|
|
|
2015-07-15 18:01:38 -04:00
|
|
|
/* live.c */
|
2015-09-26 16:33:29 -04:00
|
|
|
Bits liveon(Blk *, Blk *);
|
2015-07-15 18:01:38 -04:00
|
|
|
void filllive(Fn *);
|
2015-07-20 17:53:58 -04:00
|
|
|
|
|
|
|
/* isel.c */
|
2016-02-11 16:10:08 -05:00
|
|
|
extern int rsave[/* NRSave */];
|
|
|
|
extern int rclob[/* NRClob */];
|
2015-11-30 12:53:30 -05:00
|
|
|
ulong calldef(Ins, int[2]);
|
|
|
|
ulong calluse(Ins, int[2]);
|
2015-07-20 17:53:58 -04:00
|
|
|
void isel(Fn *);
|
|
|
|
|
|
|
|
/* spill.c */
|
|
|
|
void fillcost(Fn *);
|
|
|
|
void spill(Fn *);
|
2015-07-26 17:21:58 -04:00
|
|
|
|
|
|
|
/* rega.c */
|
|
|
|
void rega(Fn *);
|
2015-07-28 22:40:50 -04:00
|
|
|
|
|
|
|
/* emit.c */
|
|
|
|
void emitfn(Fn *, FILE *);
|
2015-10-07 22:26:13 -04:00
|
|
|
void emitdat(Dat *, FILE *);
|
2016-02-15 14:22:22 -05:00
|
|
|
int stashfp(int64_t, int);
|
|
|
|
void emitfin(FILE *);
|