Lines Matching refs:ctx

31 #define DASM_M_GROW(ctx, t, p, sz, need) \  argument
42 #define DASM_M_FREE(ctx, p, sz) ir_mem_free(p) argument
71 static const ir_proto_t *ir_call_proto(const ir_ctx *ctx, ir_insn *insn) in ir_call_proto() argument
74 const ir_insn *func = &ctx->ir_base[insn->op2]; in ir_call_proto()
78 return (const ir_proto_t *)ir_get_str(ctx, func->proto); in ir_call_proto()
81 } else if (ctx->ir_base[insn->op2].op == IR_PROTO) { in ir_call_proto()
82 return (const ir_proto_t *)ir_get_str(ctx, ctx->ir_base[insn->op2].op2); in ir_call_proto()
91 bool ir_is_fastcall(const ir_ctx *ctx, const ir_insn *insn) in ir_is_fastcall() argument
95 const ir_insn *func = &ctx->ir_base[insn->op2]; in ir_is_fastcall()
99 const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, func->proto); in ir_is_fastcall()
104 } else if (ctx->ir_base[insn->op2].op == IR_PROTO) { in ir_is_fastcall()
105 const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, ctx->ir_base[insn->op2].op2); in ir_is_fastcall()
114 bool ir_is_fastcall(const ir_ctx *ctx, const ir_insn *insn) in ir_is_fastcall() argument
120 bool ir_is_vararg(const ir_ctx *ctx, ir_insn *insn) in ir_is_vararg() argument
122 const ir_proto_t *proto = ir_call_proto(ctx, insn); in ir_is_vararg()
130 IR_ALWAYS_INLINE uint32_t ir_rule(const ir_ctx *ctx, ir_ref ref) in ir_rule() argument
133 return ctx->rules[ref]; in ir_rule()
136 IR_ALWAYS_INLINE bool ir_in_same_block(ir_ctx *ctx, ir_ref ref) in ir_in_same_block() argument
138 return ref > ctx->bb_start; in ir_in_same_block()
142 static ir_reg ir_get_param_reg(const ir_ctx *ctx, ir_ref ref) in ir_get_param_reg() argument
144 ir_use_list *use_list = &ctx->use_lists[1]; in ir_get_param_reg()
156 if (sizeof(void*) == 4 && (ctx->flags & IR_FASTCALL_FUNC)) { in ir_get_param_reg()
164 for (i = 0, p = &ctx->use_edges[use_list->refs]; i < use_list->count; i++, p++) { in ir_get_param_reg()
166 insn = &ctx->ir_base[use]; in ir_get_param_reg()
201 static int ir_get_args_regs(const ir_ctx *ctx, const ir_insn *insn, int8_t *regs) in ir_get_args_regs() argument
214 if (sizeof(void*) == 4 && ir_is_fastcall(ctx, insn)) { in ir_get_args_regs()
225 type = ctx->ir_base[ir_insn_op(insn, j)].type; in ir_get_args_regs()
256 static bool ir_is_same_mem_var(const ir_ctx *ctx, ir_ref r1, int32_t offset) in ir_is_same_mem_var() argument
265 IR_ASSERT(ctx->vregs[r1]); in ir_is_same_mem_var()
266 ival1 = ctx->live_intervals[ctx->vregs[r1]]; in ir_is_same_mem_var()
308 static void* ir_sym_addr(ir_ctx *ctx, const ir_insn *addr_insn) in ir_sym_addr() argument
310 const char *name = ir_get_str(ctx, addr_insn->val.name); in ir_sym_addr()
311 void *addr = (ctx->loader && ctx->loader->resolve_sym_name) ? in ir_sym_addr()
312 ctx->loader->resolve_sym_name(ctx->loader, name, 0) : in ir_sym_addr()
319 static void* ir_sym_val(ir_ctx *ctx, const ir_insn *addr_insn) in ir_sym_val() argument
321 const char *name = ir_get_str(ctx, addr_insn->val.name); in ir_sym_val()
322 void *addr = (ctx->loader && ctx->loader->resolve_sym_name) ? in ir_sym_val()
323 ctx->loader->resolve_sym_name(ctx->loader, name, addr_insn->op == IR_FUNC) : in ir_sym_val()
330 static void *ir_call_addr(ir_ctx *ctx, ir_insn *insn, ir_insn *addr_insn) in ir_call_addr() argument
336 addr = ir_sym_val(ctx, addr_insn); in ir_call_addr()
344 static void *ir_jmp_addr(ir_ctx *ctx, ir_insn *insn, ir_insn *addr_insn) in ir_jmp_addr() argument
346 void *addr = ir_call_addr(ctx, insn, addr_insn); in ir_jmp_addr()
349 if (ctx->ir_base[insn->op1].op == IR_SNAPSHOT) { in ir_jmp_addr()
350 addr = IR_SNAPSHOT_HANDLER(ctx, insn->op1, &ctx->ir_base[insn->op1], addr); in ir_jmp_addr()
356 static int8_t ir_get_fused_reg(ir_ctx *ctx, ir_ref root, ir_ref ref_and_op) in ir_get_fused_reg() argument
358 if (ctx->fused_regs) { in ir_get_fused_reg()
365 val = ir_strtab_find(ctx->fused_regs, key, 8); in ir_get_fused_reg()
370 return ((int8_t*)ctx->regs)[ref_and_op]; in ir_get_fused_reg()
396 static void ir_emit_osr_entry_loads(ir_ctx *ctx, int b, ir_block *bb);
397 static int ir_parallel_copy(ir_ctx *ctx, ir_copy *copies, int count, ir_reg tmp_reg, ir_reg tmp_fp_…
398 static void ir_emit_dessa_moves(ir_ctx *ctx, int b, ir_block *bb);
407 static int ir_const_label(ir_ctx *ctx, ir_ref ref) in ir_const_label() argument
409 ir_common_backend_data *data = ctx->data; in ir_const_label()
410 int label = ctx->cfg_blocks_count - ref; in ir_const_label()
425 static IR_NEVER_INLINE void ir_emit_osr_entry_loads(ir_ctx *ctx, int b, ir_block *bb) in ir_emit_osr_entry_loads() argument
427 ir_list *list = (ir_list*)ctx->osr_entry_loads; in ir_emit_osr_entry_loads()
431 IR_ASSERT(ctx->binding); in ir_emit_osr_entry_loads()
449 IR_ASSERT(ref >= 0 && ctx->vregs[ref] && ctx->live_intervals[ctx->vregs[ref]]); in ir_emit_osr_entry_loads()
450 if (!(ctx->live_intervals[ctx->vregs[ref]]->flags & IR_LIVE_INTERVAL_SPILLED)) { in ir_emit_osr_entry_loads()
452 ir_reg reg = ctx->live_intervals[ctx->vregs[ref]]->reg; in ir_emit_osr_entry_loads()
453 ir_type type = ctx->ir_base[ref].type; in ir_emit_osr_entry_loads()
454 int32_t offset = -ir_binding_find(ctx, ref); in ir_emit_osr_entry_loads()
457 ir_emit_load_mem(ctx, type, reg, IR_MEM_BO(ctx->spill_base, offset)); in ir_emit_osr_entry_loads()
459 IR_ASSERT(ctx->live_intervals[ctx->vregs[ref]]->flags & IR_LIVE_INTERVAL_SPILL_SPECIAL); in ir_emit_osr_entry_loads()
473 static int ir_parallel_copy(ir_ctx *ctx, ir_copy *copies, int count, ir_reg tmp_reg, ir_reg tmp_fp_… in ir_parallel_copy() argument
487 ir_emit_mov(ctx, type, to, from); in ir_parallel_copy()
489 ir_emit_fp_mov(ctx, type, to, from); in ir_parallel_copy()
521 ir_emit_mov(ctx, type, to, from); in ir_parallel_copy()
523 ir_emit_fp_mov(ctx, type, to, from); in ir_parallel_copy()
542 ir_emit_mov_ext(ctx, type, to, r); in ir_parallel_copy()
544 ir_emit_fp_mov(ctx, type, to, r); in ir_parallel_copy()
572 ir_emit_swap(ctx, type, to, from); in ir_parallel_copy()
581 ir_emit_mov(ctx, type, tmp_reg, to); in ir_parallel_copy()
586 ir_emit_swap_fp(ctx, type, to, from); in ir_parallel_copy()
595 ir_emit_fp_mov(ctx, type, tmp_fp_reg, to); in ir_parallel_copy()
605 ir_emit_mov_ext(ctx, type, to, r); in ir_parallel_copy()
607 ir_emit_fp_mov(ctx, type, to, r); in ir_parallel_copy()
622 static void ir_emit_dessa_move(ir_ctx *ctx, ir_type type, ir_ref to, ir_ref from, ir_reg tmp_reg, i… in ir_emit_dessa_move() argument
629 if (-from < ctx->consts_count) { in ir_emit_dessa_move()
631 ir_emit_load(ctx, type, to, from); in ir_emit_dessa_move()
634 ir_load_local_addr(ctx, to, -from - ctx->consts_count); in ir_emit_dessa_move()
638 ir_emit_mov(ctx, type, to, from); in ir_emit_dessa_move()
640 ir_emit_fp_mov(ctx, type, to, from); in ir_emit_dessa_move()
643 mem_from = ir_vreg_spill_slot(ctx, from - IR_REG_NUM); in ir_emit_dessa_move()
644 ir_emit_load_mem(ctx, type, to, mem_from); in ir_emit_dessa_move()
647 mem_to = ir_vreg_spill_slot(ctx, to - IR_REG_NUM); in ir_emit_dessa_move()
649 if (-from < ctx->consts_count) { in ir_emit_dessa_move()
653 && !IR_IS_SYM_CONST(ctx->ir_base[from].op) in ir_emit_dessa_move()
654 && (ir_type_size[type] != 8 || IR_IS_SIGNED_32BIT(ctx->ir_base[from].val.i64))) { in ir_emit_dessa_move()
655 ir_emit_store_mem_imm(ctx, type, mem_to, ctx->ir_base[from].val.i32); in ir_emit_dessa_move()
661 ir_emit_load(ctx, type, tmp, from); in ir_emit_dessa_move()
662 ir_emit_store_mem(ctx, type, mem_to, tmp); in ir_emit_dessa_move()
667 ir_load_local_addr(ctx, tmp_reg, -from - ctx->consts_count); in ir_emit_dessa_move()
668 ir_emit_store_mem(ctx, type, mem_to, tmp_reg); in ir_emit_dessa_move()
671 ir_emit_store_mem(ctx, type, mem_to, from); in ir_emit_dessa_move()
673 mem_from = ir_vreg_spill_slot(ctx, from - IR_REG_NUM); in ir_emit_dessa_move()
677 ir_emit_load_mem(ctx, type, tmp, mem_from); in ir_emit_dessa_move()
678 ir_emit_store_mem(ctx, type, mem_to, tmp); in ir_emit_dessa_move()
683 IR_ALWAYS_INLINE void ir_dessa_resolve_cycle(ir_ctx *ctx, int32_t *pred, int32_t *loc, int8_t *type… in ir_dessa_resolve_cycle() argument
704 ir_emit_swap(ctx, type, to, from); in ir_dessa_resolve_cycle()
716 ir_emit_mov(ctx, type, tmp_reg, to); in ir_dessa_resolve_cycle()
718 ir_emit_load_mem_int(ctx, type, tmp_reg, ir_vreg_spill_slot(ctx, to - IR_REG_NUM)); in ir_dessa_resolve_cycle()
724 ir_emit_swap_fp(ctx, type, to, from); in ir_dessa_resolve_cycle()
736 ir_emit_fp_mov(ctx, type, tmp_fp_reg, to); in ir_dessa_resolve_cycle()
738 ir_emit_load_mem_fp(ctx, type, tmp_fp_reg, ir_vreg_spill_slot(ctx, to - IR_REG_NUM)); in ir_dessa_resolve_cycle()
757 ir_emit_store_mem(ctx, type, tmp_spill_slot, tmp); in ir_dessa_resolve_cycle()
759 ir_emit_dessa_move(ctx, type, to, r, tmp_reg, tmp_fp_reg); in ir_dessa_resolve_cycle()
761 ir_emit_dessa_move(ctx, type, to, r, IR_REG_NONE, IR_REG_NONE); in ir_dessa_resolve_cycle()
773 ir_emit_load_mem(ctx, type, IR_IS_TYPE_INT(type) ? tmp_reg : tmp_fp_reg, tmp_spill_slot); in ir_dessa_resolve_cycle()
775 ir_emit_dessa_move(ctx, type, to, loc[from], IR_REG_NONE, IR_REG_NONE); in ir_dessa_resolve_cycle()
780 static int ir_dessa_parallel_copy(ir_ctx *ctx, ir_dessa_copy *copies, int count, ir_reg tmp_reg, ir… in ir_dessa_parallel_copy() argument
794 ir_emit_dessa_move(ctx, type, to, from, tmp_reg, tmp_fp_reg); in ir_dessa_parallel_copy()
798 len = IR_REG_NUM + ctx->vregs_count + 1; in ir_dessa_parallel_copy()
838 ir_emit_dessa_move(ctx, type, to, from, tmp_reg, tmp_fp_reg); in ir_dessa_parallel_copy()
841 ir_emit_dessa_move(ctx, type, to, r, tmp_reg, tmp_fp_reg); in ir_dessa_parallel_copy()
864 ir_dessa_resolve_cycle(ctx, pred, loc, types, todo, to, tmp_reg, tmp_fp_reg); in ir_dessa_parallel_copy()
880 ir_emit_dessa_move(ctx, type, to, from, tmp_reg, tmp_fp_reg); in ir_dessa_parallel_copy()
883 ir_emit_dessa_move(ctx, type, to, r, tmp_reg, tmp_fp_reg); in ir_dessa_parallel_copy()
901 static void ir_emit_dessa_moves(ir_ctx *ctx, int b, ir_block *bb) in ir_emit_dessa_moves() argument
908 ir_reg tmp_reg = ctx->regs[bb->end][0]; in ir_emit_dessa_moves()
909 ir_reg tmp_fp_reg = ctx->regs[bb->end][1]; in ir_emit_dessa_moves()
912 succ = ctx->cfg_edges[bb->successors]; in ir_emit_dessa_moves()
913 succ_bb = &ctx->cfg_blocks[succ]; in ir_emit_dessa_moves()
915 use_list = &ctx->use_lists[succ_bb->start]; in ir_emit_dessa_moves()
916 k = ir_phi_input_number(ctx, succ_bb, b); in ir_emit_dessa_moves()
920 for (i = 0, p = &ctx->use_edges[use_list->refs]; i < use_list->count; i++, p++) { in ir_emit_dessa_moves()
922 ir_insn *insn = &ctx->ir_base[ref]; in ir_emit_dessa_moves()
926 ir_reg src = ir_get_alocated_reg(ctx, ref, k); in ir_emit_dessa_moves()
927 ir_reg dst = ctx->regs[ref][0]; in ir_emit_dessa_moves()
933 } else if (ir_rule(ctx, input) == IR_STATIC_ALLOCA) { in ir_emit_dessa_moves()
935 from = -(ctx->consts_count + input); in ir_emit_dessa_moves()
938 (ir_ref)src : (ir_ref)(IR_REG_NUM + ctx->vregs[input]); in ir_emit_dessa_moves()
941 (ir_ref)dst : (ir_ref)(IR_REG_NUM + ctx->vregs[ref]); in ir_emit_dessa_moves()
945 && IR_MEM_VAL(ir_vreg_spill_slot(ctx, from - IR_REG_NUM)) == in ir_emit_dessa_moves()
946 IR_MEM_VAL(ir_vreg_spill_slot(ctx, to - IR_REG_NUM))) { in ir_emit_dessa_moves()
960 ir_dessa_parallel_copy(ctx, copies, n, tmp_reg, tmp_fp_reg); in ir_emit_dessa_moves()
964 int ir_match(ir_ctx *ctx) in ir_match() argument
972 ctx->rules = ir_mem_calloc(ctx->insns_count, sizeof(uint32_t)); in ir_match()
974 prev_ref = ctx->prev_ref; in ir_match()
976 ir_build_prev_refs(ctx); in ir_match()
977 prev_ref = ctx->prev_ref; in ir_match()
980 if (ctx->entries_count) { in ir_match()
981 ctx->entries = ir_mem_malloc(ctx->entries_count * sizeof(ir_ref)); in ir_match()
984 for (b = ctx->cfg_blocks_count, bb = ctx->cfg_blocks + b; b > 0; b--, bb--) { in ir_match()
988 IR_ASSERT(entries_count < ctx->entries_count); in ir_match()
989 insn = &ctx->ir_base[start]; in ir_match()
992 ctx->entries[entries_count] = b; in ir_match()
995 ctx->rules[start] = IR_SKIPPED | IR_NOP; in ir_match()
998 insn = &ctx->ir_base[ref]; in ir_match()
1000 ctx->rules[ref] = insn->op; in ir_match()
1002 if (ref == start && ctx->cfg_edges[bb->successors] != b) { in ir_match()
1005 } else if (ctx->flags & IR_MERGE_EMPTY_ENTRIES) { in ir_match()
1007 if (ctx->cfg_edges[bb->successors] == b + 1) { in ir_match()
1016ctx->bb_start = start; /* bb_start is used by matcher to avoid fusion of insns from different bloc… in ir_match()
1019 uint32_t rule = ctx->rules[ref]; in ir_match()
1022 ctx->rules[ref] = rule = ir_match_insn(ctx, ref); in ir_match()
1024 ir_match_insn2(ctx, ref, rule); in ir_match()
1029 if (ctx->entries_count) { in ir_match()
1030 ctx->entries_count = entries_count; in ir_match()
1032 ir_mem_free(ctx->entries); in ir_match()
1033 ctx->entries = NULL; in ir_match()
1040 int32_t ir_get_spill_slot_offset(ir_ctx *ctx, ir_ref ref) in ir_get_spill_slot_offset() argument
1044 IR_ASSERT(ref >= 0 && ctx->vregs[ref] && ctx->live_intervals[ctx->vregs[ref]]); in ir_get_spill_slot_offset()
1045 offset = ctx->live_intervals[ctx->vregs[ref]]->stack_spill_pos; in ir_get_spill_slot_offset()