summaryrefslogtreecommitdiff
path: root/mi/mi.h
blob: 5e9441cafb099dcb23f0fba6698b846b5d46a5e1 (plain)
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
typedef struct Cfg Cfg;
typedef struct Bb Bb;
typedef struct Reaching Reaching;
typedef struct Dtree Dtree;

struct Cfg {
	Node *fn;
	Bb **bb;
	Bb *start;
	Bb *end;
	size_t nbb;

	/* for building bb */
	int nextbbid;
	Htab *lblmap; /* label => Bb mapping */
	Node **fixjmp;
	size_t nfixjmp;
	Bb **fixblk;
	size_t nfixblk;
};

struct Bb {
	int id;
	char **lbls;
	size_t nlbls;
	Node **nl;
	size_t nnl;
	Bitset *pred;
	Bitset *succ;
};

struct Reaching {
	Bitset **in;
	Bitset **out;
	size_t **defs;
	size_t *ndefs;
	size_t nbb;
};

struct Dtree {
	int id;
	Srcloc loc;

	/* values for matching */
	Node *lbl;
	Node *load;
	size_t nconstructors;
	char accept;
	char emitted;

	/* the decision tree step */
	Node **pat;
	size_t npat;
	Dtree **next;
	size_t nnext;
	Dtree *any;

	size_t refcnt;
};

/* dataflow analysis */
Reaching *reaching(Cfg *cfg);
void reachingfree(Reaching *r);

Node *assignee(Node *n);

/* Takes a reduced block, and returns a flow graph. */
Cfg *mkcfg(Node *fn, Node **nl, size_t nn);
void dumpcfg(Cfg *c, FILE *fd);
void check(Cfg *cfg);

/* pattern matching */
void genmatch(Node *m, Node *val, Node ***out, size_t *nout);
void genonematch(Node *pat, Node *val, Node *iftrue, Node *iffalse, Node ***out, size_t *nout, Node ***cap, size_t *ncap);

/* tree flattening */
Node *flattenfn(Node *dcl);
int isconstfn(Node *n);