-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssa.h
75 lines (70 loc) · 2.43 KB
/
ssa.h
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
#ifndef SSA_H
#define SSA_H
#include "3ac.h"
/**
* Represents a number as in global value numbering. This number contains a list of
* equivalent values (VALUESTRUCTs), the equivalent constant and tag information, and
* the index in the list to prevent unnecesary storage of the index.
**/
typedef struct {
DYNARR* equivs;
union {
long intconst;
double floatconst;
char* strconst;
};
enum {NOCONST, INTCONST, FLOATCONST, STRCONST} hasconst;
int index;
} GVNNUM;
/**
* Represents an instance of a value as in global value numbering, Primarily used
* for GVNPRE, to represent anticipable expressions. Typically p1 (and p2 if binary)
* are the indices of the values of the operands, however in the special case of
* INIT_3 (PARAM_3 is replaced with INIT_3 for simplicity), the value p1 refers to
* the actual regnum of the variable. This is done to allow for operand replacement
* in GVNPRE
**/
typedef struct {
enum opcode_3ac o;
unsigned int p1;
unsigned int p2;
short size1; //bottom 4 bits size, 5th bit sign
short size2; //bottom 4 bits size, 5th bit sign
} VALUESTRUCT;
/**
* Contains all of the equivalence information for a PROGRAM. These are the GVNNUMS,
* the information about which regnums map to which constants, and the information
* about which operations map to which values.
**/
typedef struct {
DYNARR* uniq_vals;//of GVNNUMS
LVHASHTABLE* intconsthash;
FVHASHTABLE* floatconsthash;
QHASHTABLE* strconsthash;
OPHASHTABLE* ophash;
} EQONTAINER;
void ssa(PROGRAM* prog);
void gvn(PROGRAM* prog);
void ssaout(PROGRAM* prog);
BBLOCK* intersect(BBLOCK* n1, BBLOCK* n2);
char fixedintersect(const BBLOCK* fb, BBLOCK* gb);
void annotateuse(PROGRAM* prog);
void killreg(PROGRAM* prog);
//yield the 1 byte VALUESTRUCT type information from the 4 byte ADDRTYPE information
static inline char supersize(ADDRTYPE adt) {
return (adt & 0xf) | (adt & ISSIGNED ? 0x10 : 0) | (adt & ISFLOAT ? 0x20 : 0);
}
//yield the simplest 4 byte ADDRTYPE information that meets the 1 byte VALUESTRUCT informtion
static inline ADDRTYPE downsize(char super) {
return (super & 0xf) | (super & 0x10 ? ISSIGNED : 0) | (super & 0x20 ? ISFLOAT : 0);
}
static inline VALUESTRUCT* ctvalstruct(enum opcode_3ac o, unsigned int p1, unsigned int p2, char size1, char size2) {
VALUESTRUCT* irval = malloc(sizeof(VALUESTRUCT));
irval->o = o;
irval->p1 = p1;
irval->p2 = p2;
irval->size1 = size1;
irval->size2 = size2;
return irval;
}
#endif