Liveness funcionando
[pspdecompiler.git] / dataflow.c
blob3ea7517d8b904d4cbc9f3bdb0f71e989ac28851a
2 #include "code.h"
3 #include "utils.h"
5 static
6 void mark_variable (struct variable *var, enum variabletype type, int num)
8 element useel, phiel;
9 struct value *val;
11 var->info = num;
12 var->type = type;
13 useel = list_head (var->uses);
14 while (useel) {
15 struct operation *use = element_getvalue (useel);
16 if (use->type == OP_PHI) {
17 phiel = list_head (use->operands);
18 while (phiel) {
19 struct value *val = element_getvalue (phiel);
20 if (val->val.variable->type == VARIABLE_UNK) {
21 mark_variable (val->val.variable, type, num);
23 phiel = element_next (phiel);
25 val = list_headvalue (use->results);
26 if (val->val.variable->type == VARIABLE_UNK)
27 mark_variable (val->val.variable, type, num);
29 useel = element_next (useel);
32 if (var->def->type == OP_PHI) {
33 phiel = list_head (var->def->operands);
34 while (phiel) {
35 struct value *val = element_getvalue (phiel);
36 if (val->val.variable->type == VARIABLE_UNK) {
37 mark_variable (val->val.variable, type, num);
39 phiel = element_next (phiel);
44 void extract_variables (struct subroutine *sub)
46 element varel;
47 int count = 0;
49 varel = list_head (sub->variables);
50 while (varel) {
51 struct variable *var = element_getvalue (varel);
52 if (var->type == VARIABLE_UNK) {
53 if (var->def->type == OP_START) {
54 mark_variable (var, VARIABLE_ARGUMENT, var->name.val.intval);
55 } else if (var->def->type == OP_CALL && var->name.val.intval != 2 &&
56 var->name.val.intval != 3) {
57 var->type = VARIABLE_INVALID;
58 } else {
59 int istemp = FALSE;
61 if (list_size (var->uses) <= 1) {
62 struct operation *op = list_headvalue (var->uses);
63 if (op) {
64 if (op->type != OP_PHI)
65 istemp = TRUE;
66 } else {
67 istemp = TRUE;
71 if (var->def->type == OP_MOVE || var->def->type == OP_INSTRUCTION) {
72 if (var->def->type == OP_INSTRUCTION) {
73 if (var->def->info.iop.loc->insn->flags & (INSN_LOAD | INSN_STORE | INSN_BRANCH))
74 istemp = FALSE;
76 } else {
77 istemp = FALSE;
80 if (istemp) {
81 var->def->deferred = TRUE;
82 var->type = VARIABLE_TEMP;
83 var->info = 0;
84 } else {
85 mark_variable (var, VARIABLE_LOCAL, ++count);
89 varel = element_next (varel);