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);
94 entity *arch_get_frame_entity(const arch_env_t *env, ir_node *irn)
96 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
97 return ops->impl->get_frame_entity(ops, irn);
101 int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs)
103 arch_register_req_t local_req;
104 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
105 const arch_register_req_t *req = ops->impl->get_irn_reg_req(ops, &local_req, irn, pos);
107 if(req->type == arch_register_req_type_none) {
108 bitset_clear_all(bs);
112 if(arch_register_req_is(req, limited)) {
113 req->limited(req->limited_env, bs);
114 return bitset_popcnt(bs);
117 arch_register_class_put(req->cls, bs);
118 return req->cls->n_regs;
121 void arch_put_non_ignore_regs(const arch_env_t *env, const arch_register_class_t *cls, bitset_t *bs)
125 for(i = 0; i < cls->n_regs; ++i) {
126 if(!arch_register_type_is(&cls->regs[i], ignore))
131 int arch_is_register_operand(const arch_env_t *env,
132 const ir_node *irn, int pos)
134 arch_register_req_t local_req;
135 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
136 const arch_register_req_t *req = ops->impl->get_irn_reg_req(ops, &local_req, irn, pos);
140 int arch_reg_is_allocatable(const arch_env_t *env, const ir_node *irn,
141 int pos, const arch_register_t *reg)
143 arch_register_req_t req;
145 arch_get_register_req(env, &req, irn, pos);
147 if(req.type == arch_register_req_type_none)
150 if(arch_register_req_is(&req, limited)) {
151 bitset_t *bs = bitset_alloca(req.cls->n_regs);
152 req.limited(req.limited_env, bs);
153 return bitset_is_set(bs, arch_register_get_index(reg));
156 return req.cls == reg->reg_class;
159 const arch_register_class_t *
160 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos)
162 arch_register_req_t local_req;
163 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
164 const arch_register_req_t *req = ops->impl->get_irn_reg_req(ops, &local_req, irn, pos);
165 return req ? req->cls : NULL;
168 extern const arch_register_t *
169 arch_get_irn_register(const arch_env_t *env, const ir_node *irn)
171 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
172 return ops->impl->get_irn_reg(ops, irn);
175 extern void arch_set_irn_register(const arch_env_t *env,
176 ir_node *irn, const arch_register_t *reg)
178 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
179 ops->impl->set_irn_reg(ops, irn, reg);
182 extern arch_irn_class_t arch_irn_classify(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->classify(ops, irn);
188 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn)
190 const arch_irn_ops_t *ops = get_irn_ops(env, irn);
191 return ops->impl->get_flags(ops, irn);
194 extern const char *arch_irn_flag_str(arch_irn_flags_t fl)
197 #define XXX(x) case arch_irn_flags_ ## x: return #x;
200 XXX(rematerializable);
207 extern char *arch_register_req_format(char *buf, size_t len, const arch_register_req_t *req)
210 snprintf(buf, len, "class: %s", req->cls->name);
212 if(arch_register_req_is(req, limited)) {
214 bitset_t *bs = bitset_alloca(req->cls->n_regs);
215 req->limited(req->limited_env, bs);
216 strncat(buf, " limited:", len);
217 bitset_foreach(bs, elm) {
218 strncat(buf, " ", len);
219 strncat(buf, req->cls->regs[elm].name, len);
223 if(arch_register_req_is(req, should_be_same)) {
224 snprintf(tmp, sizeof(tmp), " same to: %+F", req->other_different);
225 strncat(buf, tmp, len);
228 if(arch_register_req_is(req, should_be_different)) {
229 snprintf(tmp, sizeof(tmp), " different to: %+F", req->other_different);
230 strncat(buf, tmp, len);