irop_t.h 3.47 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Matthias Braun's avatar
Matthias Braun committed
6
7
8
/**
 * @file
 * @brief    Representation of opcode of intermediate operation -- private header.
Michael Beck's avatar
Michael Beck committed
9
 * @author   Christian Schaefer, Goetz Lindenmaier, Michael Beck
10
 */
Matthias Braun's avatar
Matthias Braun committed
11
12
#ifndef FIRM_IR_IROP_T_H
#define FIRM_IR_IROP_T_H
Götz Lindenmaier's avatar
Götz Lindenmaier committed
13

Michael Beck's avatar
Michael Beck committed
14
#include "irop.h"
Matthias Braun's avatar
Matthias Braun committed
15
16
17

#include <stdbool.h>

18
#include "irtypes.h"
Michael Beck's avatar
Michael Beck committed
19
#include "tv.h"
Götz Lindenmaier's avatar
Götz Lindenmaier committed
20

21
22
23
24
25
26
27
28
#define get_op_code(op)         get_op_code_(op)
#define get_op_ident(op)        get_op_ident_(op)
#define get_op_pinned(op)       get_op_pinned_(op)
#define set_op_tag(op, tag)     set_op_tag_((op), (tag))
#define get_op_tag(op)          get_op_tag_(op)
#define set_op_attr(op, attr)   set_op_attr_((op), (attr))
#define get_op_attr(op)         get_op_attr_(op)

29
30
31
#define set_generic_function_ptr(op, func) set_generic_function_ptr_((op), (op_func)(func))
#define get_generic_function_ptr(type, op) ((type*)get_generic_function_ptr_((op)))

Michael Beck's avatar
Michael Beck committed
32
/** Initialize the irop module. */
Matthias Braun's avatar
Matthias Braun committed
33
void firm_init_op(void);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
34

Matthias Braun's avatar
Matthias Braun committed
35
36
/** frees memory allocated by irop module */
void firm_finish_op(void);
37

38
39
40
41
/**
 * Returns the attribute size of nodes of this opcode.
 * @note Use not encouraged, internal feature.
 */
42
static inline size_t get_op_attr_size(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
43
{
Michael Beck's avatar
Michael Beck committed
44
	return op->attr_size;
45
46
}

47
48
49
50
/**
 * Returns non-zero if op is a control flow opcode,
 * like Start, End, Jmp, Cond, Return, Raise or Bad.
 */
Matthias Braun's avatar
Matthias Braun committed
51
52
static inline bool is_op_cfopcode(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
53
	return op->flags & irop_flag_cfopcode;
54
55
}

56
57
58
59
60
static inline bool is_op_unknown_jump(const ir_op *op)
{
	return op->flags & irop_flag_unknown_jump;
}

61
/** Returns non-zero if operation is commutative */
Matthias Braun's avatar
Matthias Braun committed
62
63
static inline bool is_op_commutative(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
64
	return op->flags & irop_flag_commutative;
65
66
}

67
/** Returns non-zero if operation is fragile */
Matthias Braun's avatar
Matthias Braun committed
68
69
static inline bool is_op_fragile(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
70
	return op->flags & irop_flag_fragile;
71
72
}

73
/** Returns non-zero if operation is forking control flow */
Matthias Braun's avatar
Matthias Braun committed
74
75
static inline bool is_op_forking(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
76
	return op->flags & irop_flag_forking;
Michael Beck's avatar
Michael Beck committed
77
78
}

79
/** Returns non-zero if operation is a const-like op */
Matthias Braun's avatar
Matthias Braun committed
80
81
static inline bool is_op_constlike(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
82
	return op->flags & irop_flag_constlike;
83
84
}

Matthias Braun's avatar
Matthias Braun committed
85
86
static inline bool is_op_uses_memory(const ir_op *op)
{
87
	return op->flags & irop_flag_uses_memory;
88
89
}

Michael Beck's avatar
Michael Beck committed
90
/** Returns non-zero if operation is a keep-like op */
Matthias Braun's avatar
Matthias Braun committed
91
92
static inline bool is_op_keep(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
93
	return op->flags & irop_flag_keep;
Michael Beck's avatar
Michael Beck committed
94
95
}

96
/** Returns non-zero if operation must always be placed in the start block. */
Matthias Braun's avatar
Matthias Braun committed
97
98
static inline bool is_op_start_block_placed(const ir_op *op)
{
Michael Beck's avatar
Michael Beck committed
99
	return op->flags & irop_flag_start_block;
100
101
}

102
static inline unsigned get_op_code_(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
103
104
{
	return op->code;
Michael Beck's avatar
Michael Beck committed
105
106
}

107
static inline ident *get_op_ident_(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
108
109
{
	return op->name;
Michael Beck's avatar
Michael Beck committed
110
111
}

112
static inline op_pin_state get_op_pinned_(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
113
114
{
	return op->pin_state;
Michael Beck's avatar
Michael Beck committed
115
116
}

117
static inline void set_generic_function_ptr_(ir_op *op, op_func func)
Matthias Braun's avatar
Matthias Braun committed
118
119
{
	op->ops.generic = func;
120
121
}

122
static inline op_func get_generic_function_ptr_(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
123
124
{
	return op->ops.generic;
125
}
Michael Beck's avatar
Michael Beck committed
126

127
static inline ir_op_ops const *get_op_ops(ir_op const *const op)
Matthias Braun's avatar
Matthias Braun committed
128
129
{
	return &op->ops;
Michael Beck's avatar
Michael Beck committed
130
131
}

132
static inline void set_op_tag_(ir_op *op, unsigned tag)
Matthias Braun's avatar
Matthias Braun committed
133
{
Sebastian Hack's avatar
Sebastian Hack committed
134
135
136
	op->tag = tag;
}

137
static inline unsigned get_op_tag_(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
138
{
Sebastian Hack's avatar
Sebastian Hack committed
139
140
141
	return op->tag;
}

142
static inline void set_op_attr_(ir_op *op, void *attr)
Matthias Braun's avatar
Matthias Braun committed
143
{
144
145
146
	op->attr = attr;
}

147
static inline void *get_op_attr_(const ir_op *op)
Matthias Braun's avatar
Matthias Braun committed
148
{
149
150
151
	return op->attr;
}

152
153
154
/** An attr_equals function that always returns 0/false */
int attrs_equal_false(const ir_node *a, const ir_node *b);

Matthias Braun's avatar
Matthias Braun committed
155
#endif