- arm_abi_env_t *env = xmalloc(sizeof(env[0]));
- be_abi_call_flags_t fl = be_abi_call_get_flags(call);
- env->flags = fl.bits;
- env->irg = irg;
- env->arch_env = arch_env;
- env->isa = arch_env->isa;
- return env;
-}
-
-static void arm_abi_dont_save_regs(void *self, pset *s)
-{
- arm_abi_env_t *env = self;
- if (env->flags.try_omit_fp)
- pset_insert_ptr(s, env->isa->bp);
-}
-
-
-
-/**
- * Build the ARM prolog
- */
-static const arch_register_t *arm_abi_prologue(void *self, ir_node **mem, pmap *reg_map) {
- ir_node *keep, *store;
- arm_abi_env_t *env = self;
- ir_graph *irg = env->irg;
- ir_node *block = get_irg_start_block(irg);
- arch_register_class_t *gp = &arm_reg_classes[CLASS_arm_gp];
-
- ir_node *fp = be_abi_reg_map_get(reg_map, env->isa->bp);
- ir_node *ip = be_abi_reg_map_get(reg_map, &arm_gp_regs[REG_R12]);
- ir_node *sp = be_abi_reg_map_get(reg_map, env->isa->sp);
- ir_node *lr = be_abi_reg_map_get(reg_map, &arm_gp_regs[REG_LR]);
- ir_node *pc = be_abi_reg_map_get(reg_map, &arm_gp_regs[REG_PC]);
-
- if (env->flags.try_omit_fp)
- return env->isa->sp;
-
- ip = be_new_Copy(gp, irg, block, sp);
- arch_set_irn_register(env->arch_env, ip, &arm_gp_regs[REG_R12]);
- be_set_constr_single_reg(ip, BE_OUT_POS(0), &arm_gp_regs[REG_R12] );
-
- store = new_rd_arm_StoreStackM4Inc(NULL, irg, block, sp, fp, ip, lr, pc, *mem);
-
- sp = new_r_Proj(irg, block, store, env->isa->sp->reg_class->mode, pn_arm_StoreStackM4Inc_ptr);
- arch_set_irn_register(env->arch_env, sp, env->isa->sp);
- *mem = new_r_Proj(irg, block, store, mode_M, pn_arm_StoreStackM4Inc_M);
-
- keep = be_new_CopyKeep_single(gp, irg, block, ip, sp, get_irn_mode(ip));
- be_node_set_reg_class(keep, 1, gp);
- arch_set_irn_register(env->arch_env, keep, &arm_gp_regs[REG_R12]);
- be_set_constr_single_reg(keep, BE_OUT_POS(0), &arm_gp_regs[REG_R12] );
-
- fp = new_rd_arm_Sub_i(NULL, irg, block, keep, get_irn_mode(fp),
- new_tarval_from_long(4, get_irn_mode(fp)));
- arch_set_irn_register(env->arch_env, fp, env->isa->bp);
-
- be_abi_reg_map_set(reg_map, env->isa->bp, fp);
- be_abi_reg_map_set(reg_map, &arm_gp_regs[REG_R12], keep);
- be_abi_reg_map_set(reg_map, env->isa->sp, sp);
- be_abi_reg_map_set(reg_map, &arm_gp_regs[REG_LR], lr);
- be_abi_reg_map_set(reg_map, &arm_gp_regs[REG_PC], pc);
-
- return env->isa->bp;
-}
-
-/**
- * Builds the ARM epilogue
- */
-static void arm_abi_epilogue(void *self, ir_node *bl, ir_node **mem, pmap *reg_map) {
- arm_abi_env_t *env = self;
- ir_node *curr_sp = be_abi_reg_map_get(reg_map, env->isa->sp);
- ir_node *curr_bp = be_abi_reg_map_get(reg_map, env->isa->bp);
- ir_node *curr_pc = be_abi_reg_map_get(reg_map, &arm_gp_regs[REG_PC]);
- ir_node *curr_lr = be_abi_reg_map_get(reg_map, &arm_gp_regs[REG_LR]);
-
- // TODO: Activate Omit fp in epilogue
- if (env->flags.try_omit_fp) {
- curr_sp = be_new_IncSP(env->isa->sp, env->irg, bl, curr_sp, BE_STACK_FRAME_SIZE_SHRINK);
- add_irn_dep(curr_sp, *mem);
-
- curr_lr = be_new_CopyKeep_single(&arm_reg_classes[CLASS_arm_gp], env->irg, bl, curr_lr, curr_sp, get_irn_mode(curr_lr));
- be_node_set_reg_class(curr_lr, 1, &arm_reg_classes[CLASS_arm_gp]);
- arch_set_irn_register(env->arch_env, curr_lr, &arm_gp_regs[REG_LR]);
- be_set_constr_single_reg(curr_lr, BE_OUT_POS(0), &arm_gp_regs[REG_LR] );
-
- curr_pc = be_new_Copy(&arm_reg_classes[CLASS_arm_gp], env->irg, bl, curr_lr );
- arch_set_irn_register(env->arch_env, curr_pc, &arm_gp_regs[REG_PC]);
- be_set_constr_single_reg(curr_pc, BE_OUT_POS(0), &arm_gp_regs[REG_PC] );
- be_node_set_flags(curr_pc, BE_OUT_POS(0), arch_irn_flags_ignore);
- } else {
- ir_node *sub12_node;
- ir_node *load_node;
- tarval *tv = new_tarval_from_long(12,mode_Iu);
- sub12_node = new_rd_arm_Sub_i(NULL, env->irg, bl, curr_bp, mode_Iu, tv);
- // FIXME
- //set_arm_req_out_all(sub12_node, sub12_req);
- arch_set_irn_register(env->arch_env, sub12_node, env->isa->sp);
- load_node = new_rd_arm_LoadStackM3( NULL, env->irg, bl, sub12_node, *mem );
- // FIXME
- //set_arm_req_out(load_node, &arm_default_req_arm_gp_r11, 0);
- //set_arm_req_out(load_node, &arm_default_req_arm_gp_sp, 1);
- //set_arm_req_out(load_node, &arm_default_req_arm_gp_pc, 2);
- curr_bp = new_r_Proj(env->irg, bl, load_node, env->isa->bp->reg_class->mode, pn_arm_LoadStackM3_res0);
- curr_sp = new_r_Proj(env->irg, bl, load_node, env->isa->sp->reg_class->mode, pn_arm_LoadStackM3_res1);
- curr_pc = new_r_Proj(env->irg, bl, load_node, mode_Iu, pn_arm_LoadStackM3_res2);
- *mem = new_r_Proj(env->irg, bl, load_node, mode_M, pn_arm_LoadStackM3_M);
- arch_set_irn_register(env->arch_env, curr_bp, env->isa->bp);
- arch_set_irn_register(env->arch_env, curr_sp, env->isa->sp);
- arch_set_irn_register(env->arch_env, curr_pc, &arm_gp_regs[REG_PC]);
- }
- be_abi_reg_map_set(reg_map, env->isa->sp, curr_sp);
- be_abi_reg_map_set(reg_map, env->isa->bp, curr_bp);
- be_abi_reg_map_set(reg_map, &arm_gp_regs[REG_LR], curr_lr);
- be_abi_reg_map_set(reg_map, &arm_gp_regs[REG_PC], curr_pc);
-}
-
-static const be_abi_callbacks_t arm_abi_callbacks = {
- arm_abi_init,
- free,
- arm_get_between_type,
- arm_abi_dont_save_regs,
- arm_abi_prologue,
- arm_abi_epilogue,
-};
-
-
-/**
- * Get the ABI restrictions for procedure calls.
- * @param self The this pointer.
- * @param method_type The type of the method (procedure) in question.
- * @param abi The abi object to be modified
- */
-void arm_get_call_abi(const void *self, ir_type *method_type, be_abi_call_t *abi) {
- ir_type *tp;
- ir_mode *mode;
- int i;
- int n = get_method_n_params(method_type);
- be_abi_call_flags_t flags = {
- {
- 0, /* store from left to right */
- 0, /* store arguments sequential */
- 1, /* try to omit the frame pointer */
- 1, /* the function can use any register as frame pointer */
- 1, /* a call can take the callee's address as an immediate */
- 0, /* IRG is a leaf function */
- 0 /* Set to one, if there is already enough room on the stack for call args. */
- }
- };
- (void) self;
-
- /* set stack parameter passing style */
- be_abi_call_set_flags(abi, flags, &arm_abi_callbacks);
-
- for (i = 0; i < n; i++) {
- /* reg = get reg for param i; */
- /* be_abi_call_param_reg(abi, i, reg); */
- if (i < 4)
-
- be_abi_call_param_reg(abi, i, arm_get_RegParam_reg(i));
- else
- be_abi_call_param_stack(abi, i, 4, 0, 0);
- }
-
- /* set return registers */
- n = get_method_n_ress(method_type);
-
- assert(n <= 2 && "more than two results not supported");
-
- /* In case of 64bit returns, we will have two 32bit values */
- if (n == 2) {
- tp = get_method_res_type(method_type, 0);
- mode = get_type_mode(tp);
-
- assert(!mode_is_float(mode) && "two FP results not supported");
-
- tp = get_method_res_type(method_type, 1);
- mode = get_type_mode(tp);
-
- assert(!mode_is_float(mode) && "mixed INT, FP results not supported");
-
- be_abi_call_res_reg(abi, 0, &arm_gp_regs[REG_R0]);
- be_abi_call_res_reg(abi, 1, &arm_gp_regs[REG_R1]);
- } else if (n == 1) {
- const arch_register_t *reg;
-
- tp = get_method_res_type(method_type, 0);
- assert(is_atomic_type(tp));
- mode = get_type_mode(tp);
-
- reg = mode_is_float(mode) ? &arm_fpa_regs[REG_F0] : &arm_gp_regs[REG_R0];
- be_abi_call_res_reg(abi, 0, reg);
- }
-}
-
-static const void *arm_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn) {
- (void) self;
- (void) irn;
- return &arm_irn_ops;
-}
-
-const arch_irn_handler_t arm_irn_handler = {
- arm_get_irn_ops
-};
-
-const arch_irn_handler_t *arm_get_irn_handler(const void *self) {
- (void) self;
- return &arm_irn_handler;
-}
-
-int arm_to_appear_in_schedule(void *block_env, const ir_node *irn) {