3 * File name: ir/ir/irop.c
4 * Purpose: Representation of opcode of intermediate operation.
5 * Author: Christian Schaefer
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
20 # include "irnode_t.h"
24 ir_op *op_Block; ir_op *get_op_Block () { return op_Block; }
26 ir_op *op_Start; ir_op *get_op_Start () { return op_Start; }
27 ir_op *op_End; ir_op *get_op_End () { return op_End; }
28 ir_op *op_Jmp; ir_op *get_op_Jmp () { return op_Jmp; }
29 ir_op *op_Cond; ir_op *get_op_Cond () { return op_Cond; }
30 ir_op *op_Return; ir_op *get_op_Return () { return op_Return; }
31 ir_op *op_Raise; ir_op *get_op_Raise () { return op_Raise; }
33 ir_op *op_Sel; ir_op *get_op_Sel () { return op_Sel; }
34 ir_op *op_InstOf; ir_op *get_op_InstOf () { return op_InstOf; }
36 ir_op *op_Const; ir_op *get_op_Const () { return op_Const; }
37 ir_op *op_SymConst; ir_op *get_op_SymConst () { return op_SymConst; }
39 ir_op *op_Call; ir_op *get_op_Call () { return op_Call; }
40 ir_op *op_Add; ir_op *get_op_Add () { return op_Add; }
41 ir_op *op_Sub; ir_op *get_op_Sub () { return op_Sub; }
42 ir_op *op_Minus; ir_op *get_op_Minus () { return op_Minus; }
43 ir_op *op_Mul; ir_op *get_op_Mul () { return op_Mul; }
44 ir_op *op_Quot; ir_op *get_op_Quot () { return op_Quot; }
45 ir_op *op_DivMod; ir_op *get_op_DivMod () { return op_DivMod; }
46 ir_op *op_Div; ir_op *get_op_Div () { return op_Div; }
47 ir_op *op_Mod; ir_op *get_op_Mod () { return op_Mod; }
48 ir_op *op_Abs; ir_op *get_op_Abs () { return op_Abs; }
49 ir_op *op_And; ir_op *get_op_And () { return op_And; }
50 ir_op *op_Or; ir_op *get_op_Or () { return op_Or; }
51 ir_op *op_Eor; ir_op *get_op_Eor () { return op_Eor; }
52 ir_op *op_Not; ir_op *get_op_Not () { return op_Not; }
53 ir_op *op_Cmp; ir_op *get_op_Cmp () { return op_Cmp; }
54 ir_op *op_Shl; ir_op *get_op_Shl () { return op_Shl; }
55 ir_op *op_Shr; ir_op *get_op_Shr () { return op_Shr; }
56 ir_op *op_Shrs; ir_op *get_op_Shrs () { return op_Shrs; }
57 ir_op *op_Rot; ir_op *get_op_Rot () { return op_Rot; }
58 ir_op *op_Conv; ir_op *get_op_Conv () { return op_Conv; }
59 ir_op *op_Cast; ir_op *get_op_Cast () { return op_Cast; }
61 ir_op *op_Phi; ir_op *get_op_Phi () { return op_Phi; }
63 ir_op *op_Load; ir_op *get_op_Load () { return op_Load; }
64 ir_op *op_Store; ir_op *get_op_Store () { return op_Store; }
65 ir_op *op_Alloc; ir_op *get_op_Alloc () { return op_Alloc; }
66 ir_op *op_Free; ir_op *get_op_Free () { return op_Free; }
67 ir_op *op_Sync; ir_op *get_op_Sync () { return op_Sync; }
69 ir_op *op_Tuple; ir_op *get_op_Tuple () { return op_Tuple; }
70 ir_op *op_Proj; ir_op *get_op_Proj () { return op_Proj; }
71 ir_op *op_Id; ir_op *get_op_Id () { return op_Id; }
72 ir_op *op_Bad; ir_op *get_op_Bad () { return op_Bad; }
73 ir_op *op_Confirm; ir_op *get_op_Confirm () { return op_Confirm; }
75 ir_op *op_Unknown; ir_op *get_op_Unknown () { return op_Unknown; }
76 ir_op *op_Filter; ir_op *get_op_Filter () { return op_Filter; }
77 ir_op *op_Break; ir_op *get_op_Break () { return op_Break; }
78 ir_op *op_CallBegin; ir_op *get_op_CallBegin () { return op_CallBegin; }
79 ir_op *op_EndReg; ir_op *get_op_EndReg () { return op_EndReg; }
80 ir_op *op_EndExcept; ir_op *get_op_EndExcept () { return op_EndExcept; }
82 ir_op *op_FuncCall; ir_op *get_op_FuncCall () { return op_FuncCall; }
86 new_ir_op (opcode code, const char *name, op_pinned p, int labeled, size_t attr_size)
90 res = (ir_op *) xmalloc (sizeof (ir_op));
92 res->name = id_from_str(name, strlen(name));
94 res->attr_size = attr_size;
95 res->labeled = labeled; /* For vcg dumping.
96 Set labeled = 1 if the edges should be
97 enumarated in vcg output, otherwise set
102 void free_ir_op (ir_op *code) {
109 op_Block = new_ir_op (iro_Block, "Block", pinned, 1, sizeof (block_attr));
111 op_Start = new_ir_op (iro_Start, "Start", pinned, 0, sizeof (start_attr));
112 op_End = new_ir_op (iro_End, "End", pinned, 0, 0);
113 op_Jmp = new_ir_op (iro_Jmp, "Jmp", pinned, 0, 0);
114 op_Cond = new_ir_op (iro_Cond, "Cond", pinned, 1, sizeof(cond_attr));
115 op_Return = new_ir_op (iro_Return, "Return", pinned, 1, 0);
116 op_Raise = new_ir_op (iro_Raise, "Raise", pinned, 1, 0);
118 op_Const = new_ir_op (iro_Const, "Const", floats, 0, sizeof (const_attr));
119 op_SymConst = new_ir_op (iro_SymConst, "SymConst", floats, 0, sizeof (symconst_attr));
121 op_Sel = new_ir_op (iro_Sel, "Sel", floats, 1, sizeof (sel_attr));
122 op_InstOf = new_ir_op (iro_InstOf, "InstOf", floats, 1, sizeof (sel_attr));
124 op_Call = new_ir_op (iro_Call, "Call", pinned, 1, sizeof (call_attr));
125 op_Add = new_ir_op (iro_Add, "Add", floats, 0, 0);
126 op_Minus = new_ir_op (iro_Minus, "Minus", floats, 0, 0);
127 op_Sub = new_ir_op (iro_Sub, "Sub", floats, 1, 0);
128 op_Mul = new_ir_op (iro_Mul, "Mul", floats, 0, 0);
129 op_Quot = new_ir_op (iro_Quot, "Quot", pinned, 1, sizeof(struct irnode **));
130 op_DivMod = new_ir_op (iro_DivMod, "DivMod", pinned, 1, sizeof(struct irnode **));
131 op_Div = new_ir_op (iro_Div, "Div", pinned, 1, sizeof(struct irnode **));
132 op_Mod = new_ir_op (iro_Mod, "Mod", pinned, 1, sizeof(struct irnode **));
133 op_Abs = new_ir_op (iro_Abs, "Abs", floats, 0, 0);
134 op_And = new_ir_op (iro_And, "And", floats, 0, 0);
135 op_Or = new_ir_op (iro_Or, "Or", floats, 0, 0);
136 op_Eor = new_ir_op (iro_Eor, "Eor", floats, 0, 0);
137 op_Not = new_ir_op (iro_Not, "Not", floats, 0, 0);
138 op_Cmp = new_ir_op (iro_Cmp, "Cmp", floats, 1, 0);
139 op_Shl = new_ir_op (iro_Shl, "Shl", floats, 1, 0);
140 op_Shr = new_ir_op (iro_Shr, "Shr", floats, 1, 0);
141 op_Shrs = new_ir_op (iro_Shrs, "Shrs", floats, 1, 0);
142 op_Rot = new_ir_op (iro_Rot, "Rot", floats, 1, 0);
143 op_Conv = new_ir_op (iro_Conv, "Conv", floats, 0, 0);
144 op_Cast = new_ir_op (iro_Cast, "Cast", floats, 0, sizeof (cast_attr));
146 op_Phi = new_ir_op (iro_Phi, "Phi", pinned, 1, sizeof (int));
148 op_Load = new_ir_op (iro_Load, "Load", pinned, 1, sizeof(struct irnode **));
149 op_Store = new_ir_op (iro_Store, "Store", pinned, 1, sizeof(struct irnode **));
150 op_Alloc = new_ir_op (iro_Alloc, "Alloc", pinned, 1, sizeof (alloc_attr));
151 op_Free = new_ir_op (iro_Free, "Free", pinned, 1, sizeof (type *));
152 op_Sync = new_ir_op (iro_Sync, "Sync", pinned, 0, 0);
154 op_Proj = new_ir_op (iro_Proj, "Proj", floats, 0, sizeof (long));
155 op_Tuple = new_ir_op (iro_Tuple, "Tuple", floats, 1, 0);
156 op_Id = new_ir_op (iro_Id, "Id", floats, 0, 0);
157 op_Bad = new_ir_op (iro_Bad, "Bad", floats, 0, 0);
158 op_Confirm = new_ir_op (iro_Confirm, "Confirm", floats, 1, sizeof (confirm_attr));
160 op_Unknown = new_ir_op (iro_Unknown, "Unknown", floats, 0, 0);
161 op_Filter = new_ir_op (iro_Filter, "Filter", pinned, 1, sizeof(filter_attr));
162 op_Break = new_ir_op (iro_Break, "Break", pinned, 0, 0);
163 op_CallBegin = new_ir_op (iro_CallBegin, "CallBegin", pinned, 0, sizeof(callbegin_attr));
164 op_EndReg = new_ir_op (iro_EndReg, "EndReg", pinned, 0, sizeof(end_attr));
165 op_EndExcept = new_ir_op (iro_EndExcept, "EndExcept", pinned, 0, sizeof(end_attr));
167 op_FuncCall = new_ir_op (iro_FuncCall, "FuncCall", floats, 1, sizeof (call_attr));
171 /* free memory used by irop module. */
173 free_ir_op (op_Block); op_Block = NULL;
175 free_ir_op (op_Start ); op_Start = NULL;
176 free_ir_op (op_End ); op_End = NULL;
177 free_ir_op (op_Jmp ); op_Jmp = NULL;
178 free_ir_op (op_Cond ); op_Cond = NULL;
179 free_ir_op (op_Return ); op_Return = NULL;
180 free_ir_op (op_Raise ); op_Raise = NULL;
182 free_ir_op (op_Const ); op_Const = NULL;
183 free_ir_op (op_SymConst ); op_SymConst = NULL;
185 free_ir_op (op_Sel ); op_Sel = NULL;
186 free_ir_op (op_InstOf ); op_InstOf = NULL;
188 free_ir_op (op_Call ); op_Call = NULL;
189 free_ir_op (op_Add ); op_Add = NULL;
190 free_ir_op (op_Minus ); op_Minus = NULL;
191 free_ir_op (op_Sub ); op_Sub = NULL;
192 free_ir_op (op_Mul ); op_Mul = NULL;
193 free_ir_op (op_Quot ); op_Quot = NULL;
194 free_ir_op (op_DivMod ); op_DivMod = NULL;
195 free_ir_op (op_Div ); op_Div = NULL;
196 free_ir_op (op_Mod ); op_Mod = NULL;
197 free_ir_op (op_Abs ); op_Abs = NULL;
198 free_ir_op (op_And ); op_And = NULL;
199 free_ir_op (op_Or ); op_Or = NULL;
200 free_ir_op (op_Eor ); op_Eor = NULL;
201 free_ir_op (op_Not ); op_Not = NULL;
202 free_ir_op (op_Cmp ); op_Cmp = NULL;
203 free_ir_op (op_Shl ); op_Shl = NULL;
204 free_ir_op (op_Shr ); op_Shr = NULL;
205 free_ir_op (op_Shrs ); op_Shrs = NULL;
206 free_ir_op (op_Rot ); op_Rot = NULL;
207 free_ir_op (op_Conv ); op_Conv = NULL;
208 free_ir_op (op_Cast ); op_Cast = NULL;
210 free_ir_op (op_Phi ); op_Phi = NULL;
212 free_ir_op (op_Load ); op_Load = NULL;
213 free_ir_op (op_Store ); op_Store = NULL;
214 free_ir_op (op_Alloc ); op_Alloc = NULL;
215 free_ir_op (op_Free ); op_Free = NULL;
216 free_ir_op (op_Sync ); op_Sync = NULL;
218 free_ir_op (op_Proj ); op_Proj = NULL;
219 free_ir_op (op_Tuple ); op_Tuple = NULL;
220 free_ir_op (op_Id ); op_Id = NULL;
221 free_ir_op (op_Bad ); op_Bad = NULL;
222 free_ir_op (op_Confirm ); op_Confirm = NULL;
224 free_ir_op (op_Unknown ); op_Unknown = NULL;
225 free_ir_op (op_Filter ); op_Filter = NULL;
226 free_ir_op (op_Break ); op_Break = NULL;
227 free_ir_op (op_CallBegin); op_CallBegin = NULL;
228 free_ir_op (op_EndReg ); op_EndReg = NULL;
229 free_ir_op (op_EndExcept); op_EndExcept = NULL;
232 /* Returns the string for the opcode. */
233 const char *get_op_name (const ir_op *op) {
234 return get_id_str(op->name);
237 opcode get_op_code (const ir_op *op){
241 ident *get_op_ident(ir_op *op){
245 op_pinned get_op_pinned (const ir_op *op){
249 /* Sets pinned in the opcode. Setting it to floating has no effect
250 for Phi, Block and control flow nodes. */
251 void set_op_pinned(ir_op *op, op_pinned pinned) {
252 if (op == op_Block || op == op_Phi || is_cfopcode(op)) return;
257 /* returns the attribute size of the operator. */
258 int get_op_attr_size (const ir_op *op) {
259 return op->attr_size;
262 int is_cfopcode(const ir_op *op) {
263 return ((op == op_Start)
270 || (op == op_Unknown)
272 || (op == op_CallBegin)
274 || (op == op_EndExcept));
277 /* Returns true if the operation manipulates interprocedural control flow:
278 CallBegin, EndReg, EndExcept */
279 int is_ip_cfopcode(const ir_op *op) {
280 return ((op == op_CallBegin)
282 || (op == op_EndExcept));