11 DECLARE_PTR_LIST(pseudo_ptr_list
, pseudo_t
);
14 struct instruction
*insn
;
18 DECLARE_ALLOCATOR(pseudo_user
);
19 DECLARE_PTR_LIST(pseudo_user_list
, struct pseudo_user
);
33 enum pseudo_type type
;
34 struct pseudo_user_list
*users
;
38 struct instruction
*def
;
43 extern struct pseudo void_pseudo
;
45 #define VOID (&void_pseudo)
48 struct basic_block
*target
;
52 struct asm_constraint
{
54 const char *constraint
;
55 const struct ident
*ident
;
58 DECLARE_PTR_LIST(asm_constraint_list
, struct asm_constraint
);
61 struct asm_constraint_list
*inputs
;
62 struct asm_constraint_list
*outputs
;
63 struct asm_constraint_list
*clobbers
;
69 struct basic_block
*bb
;
73 pseudo_t cond
; /* for branch and switch */
76 struct /* entrypoint */ {
77 struct pseudo_list
*arg_list
;
80 struct basic_block
*bb_true
, *bb_false
;
83 struct multijmp_list
*multijmp_list
;
85 struct /* phi_node */ {
86 struct pseudo_list
*phi_list
;
88 struct /* phi source */ {
90 struct instruction_list
*phi_users
;
94 struct symbol
*orig_type
; /* casts */
95 unsigned int offset
; /* memops */
97 struct /* binops and sel */ {
98 pseudo_t src1
, src2
, src3
;
104 struct /* multijump */ {
107 struct /* setval */ {
108 pseudo_t symbol
; /* Subtle: same offset as "src" !! */
109 struct expression
*val
;
113 struct pseudo_list
*arguments
;
115 struct /* context */ {
118 struct expression
*context_expr
;
122 struct asm_rules
*asm_rules
;
135 OP_RET
= OP_TERMINATOR
,
141 OP_TERMINATOR_END
= OP_UNWIND
,
159 OP_BINARY_END
= OP_OR_BOOL
,
161 /* Binary comparison */
163 OP_SET_EQ
= OP_BINCMP
,
173 OP_BINCMP_END
= OP_SET_AE
,
179 /* Select - three input values */
210 /* Sparse tagging (line numbers, context, whatever) */
214 /* Needed to translate SSA back to normal form */
218 struct basic_block_list
;
219 struct instruction_list
;
223 unsigned long generation
;
225 struct entrypoint
*ep
;
226 struct basic_block_list
*parents
; /* sources */
227 struct basic_block_list
*children
; /* destinations */
228 struct instruction_list
*insns
; /* Linear list of instructions */
229 struct pseudo_list
*needs
, *defines
;
232 static inline int is_branch_goto(struct instruction
*br
)
234 return br
&& br
->opcode
==OP_BR
&& (!br
->bb_true
|| !br
->bb_false
);
237 static inline void add_bb(struct basic_block_list
**list
, struct basic_block
*bb
)
239 add_ptr_list(list
, bb
);
242 static inline void add_instruction(struct instruction_list
**list
, struct instruction
*insn
)
244 add_ptr_list(list
, insn
);
247 static inline void add_multijmp(struct multijmp_list
**list
, struct multijmp
*multijmp
)
249 add_ptr_list(list
, multijmp
);
252 static inline pseudo_t
*add_pseudo(struct pseudo_list
**list
, pseudo_t pseudo
)
254 return add_ptr_list(list
, pseudo
);
257 static inline int remove_pseudo(struct pseudo_list
**list
, pseudo_t pseudo
)
259 return delete_ptr_list_entry((struct ptr_list
**)list
, pseudo
, 0) != 0;
262 static inline int bb_terminated(struct basic_block
*bb
)
264 struct instruction
*insn
;
267 insn
= last_instruction(bb
->insns
);
268 return insn
&& insn
->opcode
>= OP_TERMINATOR
269 && insn
->opcode
<= OP_TERMINATOR_END
;
272 static inline int bb_reachable(struct basic_block
*bb
)
277 static inline void add_pseudo_ptr(pseudo_t
*ptr
, struct pseudo_ptr_list
**list
)
279 add_ptr_list(list
, ptr
);
282 static inline void add_pseudo_user_ptr(struct pseudo_user
*user
, struct pseudo_user_list
**list
)
284 add_ptr_list(list
, user
);
287 static inline int has_use_list(pseudo_t p
)
289 return (p
&& p
->type
!= PSEUDO_VOID
&& p
->type
!= PSEUDO_VAL
);
292 static inline struct pseudo_user
*alloc_pseudo_user(struct instruction
*insn
, pseudo_t
*pp
)
294 struct pseudo_user
*user
= __alloc_pseudo_user(0);
300 static inline void use_pseudo(struct instruction
*insn
, pseudo_t p
, pseudo_t
*pp
)
304 add_pseudo_user_ptr(alloc_pseudo_user(insn
, pp
), &p
->users
);
307 static inline void remove_bb_from_list(struct basic_block_list
**list
, struct basic_block
*entry
, int count
)
309 delete_ptr_list_entry((struct ptr_list
**)list
, entry
, count
);
312 static inline void replace_bb_in_list(struct basic_block_list
**list
,
313 struct basic_block
*old
, struct basic_block
*new, int count
)
315 replace_ptr_list_entry((struct ptr_list
**)list
, old
, new, count
);
320 struct symbol_list
*syms
;
321 struct pseudo_list
*accesses
;
322 struct basic_block_list
*bbs
;
323 struct basic_block
*active
;
324 struct instruction
*entry
;
327 extern void insert_select(struct basic_block
*bb
, struct instruction
*br
, struct instruction
*phi
, pseudo_t
true, pseudo_t
false);
328 extern void insert_branch(struct basic_block
*bb
, struct instruction
*br
, struct basic_block
*target
);
330 pseudo_t
alloc_phi(struct basic_block
*source
, pseudo_t pseudo
, int size
);
331 pseudo_t
alloc_pseudo(struct instruction
*def
);
332 pseudo_t
value_pseudo(long long val
);
334 struct entrypoint
*linearize_symbol(struct symbol
*sym
);
335 int unssa(struct entrypoint
*ep
);
336 void show_entry(struct entrypoint
*ep
);
337 const char *show_pseudo(pseudo_t pseudo
);
338 void show_bb(struct basic_block
*bb
);
339 const char *show_instruction(struct instruction
*insn
);
341 #endif /* LINEARIZE_H */