summaryrefslogtreecommitdiff
path: root/includes/compiler/IroFlowgraph.h
blob: 90e696c5407ca71529e0e9f71f312c0f31757620 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef COMPILER_IROFLOWGRAPH_H
#define COMPILER_IROFLOWGRAPH_H

#include "compiler/IrOptimizer.h"
#include "compiler/BitVector.h"
#include "compiler/CError.h"
#include "compiler/CompilerTools.h"

#ifdef __MWERKS__
#pragma options align=mac68k
#endif

struct IRONode {
    UInt16 index;
    UInt16 numsucc;
    UInt16 *succ;
    UInt16 numpred;
    UInt16 *pred;
    IROLinear *first;
    IROLinear *last;
    BitVector *x16; // In
    BitVector *x1A; // Out
    BitVector *x1E; // Gen
    BitVector *x22; // Kill
    UInt32 x26;
    BitVector *x2A; // AA
    BitVector *dom;
    IRONode *nextnode;
    Boolean x36;
    Boolean x37;
    Boolean mustreach;
    Boolean x39;
    UInt16 loopdepth;
    Boolean x3C;
    struct ObjectSet *addressed;
    Boolean mustreach1;
};

typedef struct IRONodes {
    UInt16 *indices;
    UInt16 num;
    UInt16 base;
} IRONodes;

#ifdef __MWERKS__
#pragma options align=reset
#endif

extern UInt16 IRO_NumNodes;
extern IRONode *IRO_FirstNode;
extern IRONode *IRO_LastNode;
extern IRONode *IRO_EndNode;
extern IRONode **IRO_NodeTable;
extern BitVector *IRO_VarKills;
extern BitVector *IRO_Avail;
extern BitVector *IRO_FuncKills;
extern BitVector *IRO_ExprKills;

extern void IRO_ComputeSuccPred(void);
extern void IRO_ComputeDom(void);
extern void IRO_BuildFlowgraph(IROLinear *linear);
extern IRONode *IRO_NewFlowGraphNode(void);
extern IRONode *IRO_MergeFlowGraphNodes(IRONode *a, IRONode *b);

CW_INLINE void IROFlowgraph_sub_4C2140(IRONodes *nodes) {
    nodes->indices = oalloc(sizeof(UInt16) * IRO_NumNodes);
    nodes->num = 0;
    nodes->base = 0;
}

CW_INLINE void IROFlowgraph_sub_4C20E0(IRONodes *nodes) {
}

CW_INLINE UInt16 IROFlowgraph_sub_4C2040(IRONodes *nodes) {
    return nodes->num;
}

CW_INLINE UInt16 IROFlowgraph_sub_4C2100(IRONodes *nodes) {
    UInt16 result = -1;
    if (nodes->num) {
        result = nodes->indices[nodes->base];
        nodes->base = (nodes->base + 1) % IRO_NumNodes;
        nodes->num--;
    }
    return result;
}

CW_INLINE void IROFlowgraph_sub_4C3880(IRONodes *nodes, UInt16 index) {
    if (nodes->num < IRO_NumNodes) {
        nodes->indices[(nodes->base + nodes->num) % IRO_NumNodes] = index;
        nodes->num++;
    } else {
        CError_FATAL(93);
    }
}

#endif