1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned char uchar;
enum {
R = 0, /* invalid reference */
NReg = 32,
Tmp0 = NReg+1,
NString = 32,
NPred = 15,
NBlk = 128,
NIns = 256,
};
typedef struct Ins Ins;
typedef struct Phi Phi;
typedef struct Blk Blk;
typedef struct Sym Sym;
typedef struct Fn Fn;
typedef ushort Ref;
enum {
RSym = 0,
RConst = 1,
RMask = 1,
RShift = 1,
NRefs = ((ushort)-1)>>RShift,
};
#define SYM(x) (((x)<<RShift) | RSym)
#define CONST(x) (((x)<<RShift) | RConst)
enum {
OXXX,
OAdd,
OSub,
ODiv,
OMod,
OCopy,
/* reserved instructions */
OX86Div,
};
enum {
JXXX,
JRet,
JJmp,
JJez,
};
struct Ins {
short op;
Ref to;
Ref l;
Ref r;
};
struct Phi {
Ref to;
Ref arg[NPred];
Blk *blk[NPred];
uint narg;
Phi *link;
};
struct Blk {
Phi *phi;
Ins *ins;
uint nins;
struct {
short type;
Ref arg;
} jmp;
Blk *s1;
Blk *s2;
Blk *link;
Blk **pred;
uint npred;
char name[NString];
int id;
};
struct Sym {
enum {
SUndef,
SReg,
STmp,
} type;
char name[NString];
Blk *blk;
int pos;
};
struct Fn {
Blk *start;
Sym *sym;
int ntmp;
int nblk;
Blk **rpo;
};
/* parse.c */
void *alloc(size_t);
Fn *parsefn(FILE *);
/* ssa.c */
void fillpreds(Fn *);
void fillrpo(Fn *);
void ssafix(Fn *, int);
|