Lines Matching refs:fn

24 	LLVMValueRef			fn;  member
369 static LLVMValueRef pseudo_to_value(struct function *fn, struct symbol *ctype, pseudo_t pseudo) in pseudo_to_value() argument
378 result = get_sym_value(fn->module, pseudo->sym); in pseudo_to_value()
384 result = LLVMGetParam(fn->fn, pseudo->nr - 1); in pseudo_to_value()
403 static LLVMValueRef pseudo_to_rvalue(struct function *fn, struct symbol *ctype, pseudo_t pseudo) in pseudo_to_rvalue() argument
405 LLVMValueRef val = pseudo_to_value(fn, ctype, pseudo); in pseudo_to_rvalue()
410 return LLVMBuildBitCast(fn->builder, val, dtype, name); in pseudo_to_rvalue()
413 static LLVMValueRef value_to_ivalue(struct function *fn, struct symbol *ctype, LLVMValueRef val) in value_to_ivalue() argument
420 val = LLVMBuildPtrToInt(fn->builder, val, dtype, name); in value_to_ivalue()
423 val = LLVMBuildIntCast(fn->builder, val, dtype, name); in value_to_ivalue()
428 static LLVMValueRef value_to_pvalue(struct function *fn, struct symbol *ctype, LLVMValueRef val) in value_to_pvalue() argument
436 val = LLVMBuildIntToPtr(fn->builder, val, dtype, name); in value_to_pvalue()
439 val = LLVMBuildBitCast(fn->builder, val, dtype, name); in value_to_pvalue()
447 static LLVMValueRef adjust_type(struct function *fn, struct symbol *ctype, LLVMValueRef val) in adjust_type() argument
450 return value_to_ivalue(fn, ctype, val); in adjust_type()
452 return value_to_pvalue(fn, ctype, val); in adjust_type()
460 static LLVMValueRef get_operand(struct function *fn, struct symbol *ctype, pseudo_t pseudo) in get_operand() argument
462 LLVMValueRef target = pseudo_to_value(fn, ctype, pseudo); in get_operand()
463 return adjust_type(fn, ctype, target); in get_operand()
471 static LLVMValueRef get_ioperand(struct function *fn, struct symbol *ctype, pseudo_t pseudo) in get_ioperand() argument
473 LLVMValueRef target = pseudo_to_value(fn, ctype, pseudo); in get_ioperand()
474 return value_to_ivalue(fn, ctype, target); in get_ioperand()
534 static void output_op_binary(struct function *fn, struct instruction *insn) in output_op_binary() argument
539 lhs = get_ioperand(fn, insn->type, insn->src1); in output_op_binary()
540 rhs = get_ioperand(fn, insn->type, insn->src2); in output_op_binary()
547 target = LLVMBuildAdd(fn->builder, lhs, rhs, target_name); in output_op_binary()
550 target = LLVMBuildSub(fn->builder, lhs, rhs, target_name); in output_op_binary()
553 target = LLVMBuildMul(fn->builder, lhs, rhs, target_name); in output_op_binary()
556 target = LLVMBuildUDiv(fn->builder, lhs, rhs, target_name); in output_op_binary()
560 target = LLVMBuildSDiv(fn->builder, lhs, rhs, target_name); in output_op_binary()
564 target = LLVMBuildURem(fn->builder, lhs, rhs, target_name); in output_op_binary()
568 target = LLVMBuildSRem(fn->builder, lhs, rhs, target_name); in output_op_binary()
572 target = LLVMBuildShl(fn->builder, lhs, rhs, target_name); in output_op_binary()
576 target = LLVMBuildLShr(fn->builder, lhs, rhs, target_name); in output_op_binary()
580 target = LLVMBuildAShr(fn->builder, lhs, rhs, target_name); in output_op_binary()
585 target = LLVMBuildFAdd(fn->builder, lhs, rhs, target_name); in output_op_binary()
588 target = LLVMBuildFSub(fn->builder, lhs, rhs, target_name); in output_op_binary()
591 target = LLVMBuildFMul(fn->builder, lhs, rhs, target_name); in output_op_binary()
594 target = LLVMBuildFDiv(fn->builder, lhs, rhs, target_name); in output_op_binary()
600 target = LLVMBuildAnd(fn->builder, lhs, rhs, target_name); in output_op_binary()
604 target = LLVMBuildOr(fn->builder, lhs, rhs, target_name); in output_op_binary()
608 target = LLVMBuildXor(fn->builder, lhs, rhs, target_name); in output_op_binary()
615 target = adjust_type(fn, insn->type, target); in output_op_binary()
619 static void output_op_compare(struct function *fn, struct instruction *insn) in output_op_compare() argument
624 lhs = pseudo_to_value(fn, NULL, insn->src1); in output_op_compare()
628 rhs = pseudo_to_value(fn, NULL, insn->src2); in output_op_compare()
638 lhs = value_to_pvalue(fn, &ptr_ctype, lhs); in output_op_compare()
639 rhs = value_to_pvalue(fn, &ptr_ctype, rhs); in output_op_compare()
647 rhs = LLVMBuildPtrToInt(fn->builder, rhs, ltype, ""); in output_op_compare()
649 target = LLVMBuildICmp(fn->builder, op, lhs, rhs, target_name); in output_op_compare()
660 target = LLVMBuildFCmp(fn->builder, op, lhs, rhs, target_name); in output_op_compare()
667 target = LLVMBuildZExt(fn->builder, target, dst_type, target_name); in output_op_compare()
672 static void output_op_ret(struct function *fn, struct instruction *insn) in output_op_ret() argument
677 LLVMValueRef result = get_operand(fn, insn->type, pseudo); in output_op_ret()
678 LLVMBuildRet(fn->builder, result); in output_op_ret()
680 LLVMBuildRetVoid(fn->builder); in output_op_ret()
683 static LLVMValueRef calc_memop_addr(struct function *fn, struct instruction *insn) in calc_memop_addr() argument
694 src = pseudo_to_value(fn, insn->type, insn->src); in calc_memop_addr()
697 src = LLVMBuildPointerCast(fn->builder, src, addr_type, LLVMGetValueName(src)); in calc_memop_addr()
700 addr = calc_gep(fn->builder, src, off); in calc_memop_addr()
705 static void output_op_load(struct function *fn, struct instruction *insn) in output_op_load() argument
710 addr = calc_memop_addr(fn, insn); in output_op_load()
714 target = LLVMBuildLoad(fn->builder, addr, name); in output_op_load()
719 static void output_op_store(struct function *fn, struct instruction *insn) in output_op_store() argument
723 addr = calc_memop_addr(fn, insn); in output_op_store()
725 target_in = pseudo_to_rvalue(fn, insn->type, insn->target); in output_op_store()
728 LLVMBuildStore(fn->builder, target_in, addr); in output_op_store()
731 static LLVMValueRef bool_value(struct function *fn, LLVMValueRef value) in bool_value() argument
734 value = LLVMBuildIsNotNull(fn->builder, value, LLVMGetValueName(value)); in bool_value()
739 static void output_op_cbr(struct function *fn, struct instruction *br) in output_op_cbr() argument
741 LLVMValueRef cond = bool_value(fn, in output_op_cbr()
742 pseudo_to_value(fn, NULL, br->cond)); in output_op_cbr()
744 LLVMBuildCondBr(fn->builder, cond, in output_op_cbr()
749 static void output_op_br(struct function *fn, struct instruction *br) in output_op_br() argument
751 LLVMBuildBr(fn->builder, br->bb_true->priv); in output_op_br()
754 static void output_op_sel(struct function *fn, struct instruction *insn) in output_op_sel() argument
759 src1 = bool_value(fn, pseudo_to_value(fn, NULL, insn->src1)); in output_op_sel()
760 src2 = get_operand(fn, insn->type, insn->src2); in output_op_sel()
761 src3 = get_operand(fn, insn->type, insn->src3); in output_op_sel()
764 target = LLVMBuildSelect(fn->builder, src1, src2, src3, name); in output_op_sel()
766 insn->target->priv = adjust_type(fn, insn->type, target); in output_op_sel()
769 static void output_op_switch(struct function *fn, struct instruction *insn) in output_op_switch() argument
783 sw_val = get_ioperand(fn, insn->type, insn->cond); in output_op_switch()
784 target = LLVMBuildSwitch(fn->builder, sw_val, in output_op_switch()
797 static void output_op_call(struct function *fn, struct instruction *insn) in output_op_call() argument
811 func = get_operand(fn, ctype, insn->func); in output_op_call()
813 func = pseudo_to_value(fn, ctype, insn->func); in output_op_call()
817 args[i++] = pseudo_to_rvalue(fn, ctype, arg); in output_op_call()
822 target = LLVMBuildCall(fn->builder, func, args, n_arg, name); in output_op_call()
827 static void output_op_phisrc(struct function *fn, struct instruction *insn) in output_op_phisrc() argument
835 v = get_operand(fn, insn->type, insn->phi_src); in output_op_phisrc()
846 LLVMBuildStore(fn->builder, v, ptr); in output_op_phisrc()
850 static void output_op_phi(struct function *fn, struct instruction *insn) in output_op_phi() argument
859 LLVMInsertIntoBuilder(fn->builder, load); in output_op_phi()
862 static void output_op_ptrcast(struct function *fn, struct instruction *insn) in output_op_ptrcast() argument
870 src = get_operand(fn, otype, insn->src); in output_op_ptrcast()
896 target = LLVMBuildCast(fn->builder, op, src, dtype, target_name); in output_op_ptrcast()
900 static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOpcode op) in output_op_cast() argument
908 return output_op_ptrcast(fn, insn); in output_op_cast()
912 src = get_operand(fn, otype, insn->src); in output_op_cast()
930 target = LLVMBuildCast(fn->builder, op, src, dtype, target_name); in output_op_cast()
934 static void output_op_fpcast(struct function *fn, struct instruction *insn) in output_op_fpcast() argument
944 src = get_operand(fn, otype, insn->src); in output_op_fpcast()
947 target = LLVMBuildFPCast(fn->builder, src, dtype, name); in output_op_fpcast()
950 target = LLVMBuildSIToFP(fn->builder, src, dtype, name); in output_op_fpcast()
953 target = LLVMBuildUIToFP(fn->builder, src, dtype, name); in output_op_fpcast()
961 static void output_op_setval(struct function *fn, struct instruction *insn) in output_op_setval() argument
968 target = LLVMBlockAddress(fn->fn, val->symbol->bb_target->priv); in output_op_setval()
977 static void output_op_setfval(struct function *fn, struct instruction *insn) in output_op_setfval() argument
986 static void output_insn(struct function *fn, struct instruction *insn) in output_insn() argument
990 output_op_ret(fn, insn); in output_insn()
993 output_op_br(fn, insn); in output_insn()
996 output_op_cbr(fn, insn); in output_insn()
1002 output_op_setval(fn, insn); in output_insn()
1005 output_op_setfval(fn, insn); in output_insn()
1008 output_op_switch(fn, insn); in output_insn()
1014 output_op_phisrc(fn, insn); in output_insn()
1017 output_op_phi(fn, insn); in output_insn()
1020 output_op_load(fn, insn); in output_insn()
1023 output_op_store(fn, insn); in output_insn()
1028 output_op_call(fn, insn); in output_insn()
1031 output_op_cast(fn, insn, LLVMZExt); in output_insn()
1034 output_op_cast(fn, insn, LLVMSExt); in output_insn()
1037 output_op_cast(fn, insn, LLVMTrunc); in output_insn()
1040 output_op_cast(fn, insn, LLVMFPToUI); in output_insn()
1043 output_op_cast(fn, insn, LLVMFPToSI); in output_insn()
1047 output_op_fpcast(fn, insn); in output_insn()
1052 output_op_ptrcast(fn, insn); in output_insn()
1055 output_op_binary(fn, insn); in output_insn()
1058 output_op_compare(fn, insn); in output_insn()
1061 output_op_sel(fn, insn); in output_insn()
1070 src = pseudo_to_value(fn, insn->type, insn->src); in output_insn()
1074 target = LLVMBuildNot(fn->builder, src, target_name); in output_insn()
1084 src = pseudo_to_value(fn, insn->type, insn->src); in output_insn()
1089 target = LLVMBuildFNeg(fn->builder, src, target_name); in output_insn()
1091 target = LLVMBuildNeg(fn->builder, src, target_name); in output_insn()
1118 static void output_bb(struct function *fn, struct basic_block *bb) in output_bb() argument
1126 output_insn(fn, insn); in output_bb()
1142 function.fn = get_sym_value(module, sym); in output_fn()
1143 LLVMSetFunctionCallConv(function.fn, LLVMCCallConv); in output_fn()
1144 LLVMSetLinkage(function.fn, function_linkage(sym)); in output_fn()
1154 arg = LLVMGetParam(function.fn, i); in output_fn()
1167 bbr = LLVMAppendBasicBlock(function.fn, bbname); in output_fn()
1180 entrybbr = LLVMGetEntryBasicBlock(function.fn); in output_fn()