summaryrefslogtreecommitdiff
path: root/includes/compiler/IroUtil.h
blob: a75702572bd189202c52a73f6510931f5d82f5cc (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef COMPILER_IROUTIL_H
#define COMPILER_IROUTIL_H

#include "compiler/IrOptimizer.h"
#include "compiler/CInt64.h"
#include "compiler/CParser.h"

#ifdef __MWERKS__
#pragma options align=mac68k
#endif
struct IROList {
    IROLinear *head;
    IROLinear *tail;
};

struct IROListNode {
    IROList list;
    IROListNode *nextList;
};

struct IROElmList {
    void *element;
    IROElmList *next;
};

struct IROAddrRecord {
    IROLinear *linear;
    unsigned short numObjRefs;
    IROElmList *objRefs;
    unsigned short numMisc;
    IROElmList *misc;
    unsigned short numInts;
    IROElmList *ints;
    int x16;
};
#ifdef __MWERKS__
#pragma options align=reset
#endif

extern Object *FunctionName;
extern Boolean IRO_IsLeafFunction;
extern Boolean IRO_FunctionHasReturn;
extern Boolean DisableDueToAsm;
extern Boolean LoopOptimizerRun;

extern Object *IRO_IsVariable(IROLinear *linear);
extern Boolean IRO_IsConstant(IROLinear *linear);
extern Boolean IRO_IsPow2(IROLinear *linear, SInt32 *powvalue);
extern Boolean IRO_IsIntConstant(IROLinear *linear);
extern Boolean IRO_IsFloatConstant(IROLinear *linear);
extern Boolean IRO_IsVector128Constant(IROLinear *linear);
extern Boolean IRO_IsAssignment(IROLinear *linear);
extern Boolean IRO_TypesEqual(Type *a, Type *b);
extern Type *IRO_UnsignedType(Type *type);
extern Type *IRO_SignedType(Type *type);
extern Boolean IRO_is_CPtypeequal(Type *a, Type *b);
extern Boolean IRO_ExprsSame(IROLinear *a, IROLinear *b);
extern CLabel *IRO_NewLabel(void);
extern Boolean IRO_ExprsSameSemantically(IROLinear *a, IROLinear *b);
extern IROLinear *IRO_FindPrecedAfter(IROLinear *a, IROLinear *iter);
extern IROLinear *IRO_FindPreced(IROLinear *a);
extern IROLinear *IRO_FindFirst(IROLinear *linear);
extern void IRO_CutAndPasteAfter(IROLinear *a, IROLinear *b, IROLinear *c);
extern Boolean IRO_IsConstantZero(IROLinear *linear);
extern Boolean IRO_IsConstantOne(IROLinear *linear);
extern Boolean IRO_IsConstantNegativeOne(IROLinear *linear);
extern void IRO_NopOut(IROLinear *linear);
extern void IRO_NopNonSideEffects(IROLinear *linear, SInt32 level);
extern void IRO_BuildList(IROLinear *linear, Boolean isEntry);
typedef void (*IROWalkTreeFunc)(IROLinear *linear, Boolean isEntry);
extern void IRO_WalkTree(IROLinear *linear, IROWalkTreeFunc func);
extern void IRO_WalkTreeToPropagateFlags(IROLinear *linear, IROWalkTreeFunc func);
extern void IRO_WalkInts(IROLinear *a, IROLinear *b, IROWalkTreeFunc func);
extern void IRO_Cut(IROLinear *a, IROLinear *b);
extern void IRO_Paste(IROLinear *a, IROLinear *b, IROLinear *c);
extern void IRO_PasteAfter(IROLinear *a, IROLinear *b, IROLinear *c);
extern void IRO_ClipExpr(IROExpr *expr);
extern void IRO_ClipExprTree(IROLinear *linear);
extern void IRO_MoveExpression(IROExpr *expr, IROLinear *linear);
extern void IRO_InitList(IROList *list);
extern void IRO_AddToList(IROLinear *linear, IROList *list);
extern IROLinear *IRO_FindLabelNode(CLabel *label, IROLinear *linear);
extern void IRO_DuplicateExprRange(IROLinear *start, IROLinear *end, IROList *list);
extern IROLinear *IRO_DuplicateExpr(IROLinear *linear, IROList *list);
extern IROLinear *IRO_TempReference(Object *obj, IROList *list);
extern IROLinear *IRO_LocateFather(IROLinear *linear);
extern IROLinear *IRO_LocateFather_Cut_And_Paste(IROLinear *a, IROLinear *b);
extern IROLinear *IRO_LocateFather_Cut_And_Paste_Without_Nopping(IROLinear *a, IROLinear *b);
extern void IRO_ReplaceReference(IROLinear *a, Object *obj, IROLinear *b);
extern void IRO_ReplaceReferenceWithNode(IROLinear *a, IROLinear *b);
extern VarRecord *IRO_GetTemp(IROExpr *expr);
extern IROLinear *IRO_AssignToTemp(IROExpr *expr);
extern IROLinear *IRO_FindStart(IROLinear *linear);
extern void IRO_DeleteCommaNode(IROLinear *linear, IROExpr *expr);
extern void IRO_RemoveCommaNodeFromIR(void);
extern IROAddrRecord *IRO_InitAddrRecordPointer(IROLinear *linear);
extern IROLinear *IRO_HasSideEffect(IROLinear *linear);
extern IROLinear *IRO_CheckSideEffect(IROLinear *linear);
typedef void (*WalkObjFunc)(Object *obj);
extern void IRO_WalkExcActions(ExceptionAction *action, WalkObjFunc func);
extern Boolean IRO_FunctionCallMightThrowException(IROLinear *linear);
extern IROLinear *IRO_NewIntConst(CInt64 val, Type *type);
extern IROLinear *IRO_NewFloatConst(const Float val, Type *type);
extern Boolean IRO_IsAddressMultiply(IROLinear *linear);
extern void IRO_SetupForUserBreakChecking(void);
extern void IRO_CheckForUserBreak(void);

// TODO is this elsewhere?
CW_INLINE Boolean IRO_IsUnsignedType(Type *type) {
    return is_unsigned(type);
}

// 4B4D40
CW_INLINE CInt64 IRO_MakeULong(UInt32 i) {
    CInt64 val;
    CInt64_SetULong(&val, i);
    return val;
}

// 4BAAA0
CW_INLINE CInt64 IRO_MakeLong(SInt32 i) {
    CInt64 val;
    CInt64_SetLong(&val, i);
    return val;
}

#endif