2 * Processor architecture specification.
3 * @author Sebastian Hack
30 arch_env_t *arch_env_init(arch_env_t *env, const arch_isa_if_t *isa_if)
32 memset(env, 0, sizeof(*env));
33 env->isa = isa_if->init();
37 arch_env_t *arch_env_add_irn_handler(arch_env_t *env,
38 const arch_irn_handler_t *handler)
40 assert(env->handlers_tos <= ARCH_MAX_HANDLERS);
41 env->handlers[env->handlers_tos++] = handler;
45 static const arch_irn_ops_t *fallback_irn_ops = NULL;
47 int arch_register_class_put(const arch_register_class_t *cls, bitset_t *bs)
51 for(i = 0, n = cls->n_regs; i < n; ++i)
59 * Get the isa responsible for a node.
60 * @param env The arch environment with the isa stack.
61 * @param irn The node to get the responsible isa for.
62 * @return The irn operations given by the responsible isa.
64 static INLINE const arch_irn_ops_t *
65 get_irn_ops(const arch_env_t *env, const ir_node *irn)
69 for(i = env->handlers_tos - 1; i >= 0; --i) {
70 const arch_irn_handler_t *handler = env->handlers[i];
71 const arch_irn_ops_t *ops = handler->get_irn_ops(handler, irn);
77 return fallback_irn_ops;
80 const arch_register_req_t *arch_get_register_req(const arch_env_t *env,
81 arch_register_req_t *req, const ir_node *irn, int pos)
83 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
84 req->type = arch_register_req_type_none;
85 return ops->impl->get_irn_reg_req(ops, req, irn, pos);
88 void arch_set_stack_bias(const arch_env_t *env, ir_node *irn, int bias)
90 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
91 ops->impl->set_stack_bias(ops, irn, bias);
95 int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs)
97 arch_register_req_t local_req;
98 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
99 const arch_register_req_t *req = ops->impl->get_irn_reg_req(ops, &local_req, irn, pos);
101 if(req->type == arch_register_req_type_none) {
102 bitset_clear_all(bs);
106 if(arch_register_req_is(req, limited)) {
107 req->limited(req->limited_env, bs);
108 return bitset_popcnt(bs);
111 arch_register_class_put(req->cls, bs);
112 return req->cls->n_regs;
115 void arch_put_non_ignore_regs(const arch_env_t *env, const arch_register_class_t *cls, bitset_t *bs)
119 for(i = 0; i < cls->n_regs; ++i) {
120 if(!arch_register_type_is(&cls->regs[i], ignore))
125 int arch_is_register_operand(const arch_env_t *env,
126 const ir_node *irn, int pos)
128 arch_register_req_t local_req;
129 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
130 const arch_register_req_t *req = ops->impl->get_irn_reg_req(ops, &local_req, irn, pos);
134 int arch_reg_is_allocatable(const arch_env_t *env, const ir_node *irn,
135 int pos, const arch_register_t *reg)
137 arch_register_req_t req;
139 arch_get_register_req(env, &req, irn, pos);
141 if(req.type == arch_register_req_type_none)
144 if(arch_register_req_is(&req, limited)) {
145 bitset_t *bs = bitset_alloca(req.cls->n_regs);
146 req.limited(req.limited_env, bs);
147 return bitset_is_set(bs, arch_register_get_index(reg));
150 return req.cls == reg->reg_class;
153 const arch_register_class_t *
154 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos)
156 arch_register_req_t local_req;
157 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
158 const arch_register_req_t *req = ops->impl->get_irn_reg_req(ops, &local_req, irn, pos);
159 return req ? req->cls : NULL;
162 extern const arch_register_t *
163 arch_get_irn_register(const arch_env_t *env, const ir_node *irn)
165 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
166 return ops->impl->get_irn_reg(ops, irn);
169 extern void arch_set_irn_register(const arch_env_t *env,
170 ir_node *irn, const arch_register_t *reg)
172 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
173 ops->impl->set_irn_reg(ops, irn, reg);
176 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn)
178 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
179 return ops->impl->classify(ops, irn);
182 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn)
184 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
185 return ops->impl->get_flags(ops, irn);
188 extern const char *arch_irn_flag_str(arch_irn_flags_t fl)
191 #define XXX(x) case arch_irn_flags_ ## x: return #x;
194 XXX(rematerializable);
201 extern char *arch_register_req_format(char *buf, size_t len, const arch_register_req_t *req)
204 snprintf(buf, len, "class: %s", req->cls->name);
206 if(arch_register_req_is(req, limited)) {
208 bitset_t *bs = bitset_alloca(req->cls->n_regs);
209 req->limited(req->limited_env, bs);
210 strncat(buf, " limited:", len);
211 bitset_foreach(bs, elm) {
212 strncat(buf, " ", len);
213 strncat(buf, req->cls->regs[elm].name, len);
217 if(arch_register_req_is(req, should_be_same)) {
218 snprintf(tmp, sizeof(tmp), " same to: %+F", req->other_different);
219 strncat(buf, tmp, len);
222 if(arch_register_req_is(req, should_be_different)) {
223 snprintf(tmp, sizeof(tmp), " different to: %+F", req->other_different);
224 strncat(buf, tmp, len);