Lines Matching refs:fn
24 LLVMValueRef fn;
369 static LLVMValueRef pseudo_to_value(struct function *fn, struct symbol *ctype, pseudo_t pseudo)
378 result = get_sym_value(fn->module, pseudo->sym);
384 result = LLVMGetParam(fn->fn, pseudo->nr - 1);
403 static LLVMValueRef pseudo_to_rvalue(struct function *fn, struct symbol *ctype, pseudo_t pseudo)
405 LLVMValueRef val = pseudo_to_value(fn, ctype, pseudo);
410 return LLVMBuildBitCast(fn->builder, val, dtype, name);
413 static LLVMValueRef value_to_ivalue(struct function *fn, struct symbol *ctype, LLVMValueRef val)
420 val = LLVMBuildPtrToInt(fn->builder, val, dtype, name);
423 val = LLVMBuildIntCast(fn->builder, val, dtype, name);
428 static LLVMValueRef value_to_pvalue(struct function *fn, struct symbol *ctype, LLVMValueRef val)
436 val = LLVMBuildIntToPtr(fn->builder, val, dtype, name);
439 val = LLVMBuildBitCast(fn->builder, val, dtype, name);
447 static LLVMValueRef adjust_type(struct function *fn, struct symbol *ctype, LLVMValueRef val)
450 return value_to_ivalue(fn, ctype, val);
452 return value_to_pvalue(fn, ctype, val);
460 static LLVMValueRef get_operand(struct function *fn, struct symbol *ctype, pseudo_t pseudo)
462 LLVMValueRef target = pseudo_to_value(fn, ctype, pseudo);
463 return adjust_type(fn, ctype, target);
471 static LLVMValueRef get_ioperand(struct function *fn, struct symbol *ctype, pseudo_t pseudo)
473 LLVMValueRef target = pseudo_to_value(fn, ctype, pseudo);
474 return value_to_ivalue(fn, ctype, target);
534 static void output_op_binary(struct function *fn, struct instruction *insn)
539 lhs = get_ioperand(fn, insn->type, insn->src1);
540 rhs = get_ioperand(fn, insn->type, insn->src2);
547 target = LLVMBuildAdd(fn->builder, lhs, rhs, target_name);
550 target = LLVMBuildSub(fn->builder, lhs, rhs, target_name);
553 target = LLVMBuildMul(fn->builder, lhs, rhs, target_name);
556 target = LLVMBuildUDiv(fn->builder, lhs, rhs, target_name);
560 target = LLVMBuildSDiv(fn->builder, lhs, rhs, target_name);
564 target = LLVMBuildURem(fn->builder, lhs, rhs, target_name);
568 target = LLVMBuildSRem(fn->builder, lhs, rhs, target_name);
572 target = LLVMBuildShl(fn->builder, lhs, rhs, target_name);
576 target = LLVMBuildLShr(fn->builder, lhs, rhs, target_name);
580 target = LLVMBuildAShr(fn->builder, lhs, rhs, target_name);
585 target = LLVMBuildFAdd(fn->builder, lhs, rhs, target_name);
588 target = LLVMBuildFSub(fn->builder, lhs, rhs, target_name);
591 target = LLVMBuildFMul(fn->builder, lhs, rhs, target_name);
594 target = LLVMBuildFDiv(fn->builder, lhs, rhs, target_name);
600 target = LLVMBuildAnd(fn->builder, lhs, rhs, target_name);
604 target = LLVMBuildOr(fn->builder, lhs, rhs, target_name);
608 target = LLVMBuildXor(fn->builder, lhs, rhs, target_name);
615 target = adjust_type(fn, insn->type, target);
619 static void output_op_compare(struct function *fn, struct instruction *insn)
624 lhs = pseudo_to_value(fn, NULL, insn->src1);
628 rhs = pseudo_to_value(fn, NULL, insn->src2);
638 lhs = value_to_pvalue(fn, &ptr_ctype, lhs);
639 rhs = value_to_pvalue(fn, &ptr_ctype, rhs);
647 rhs = LLVMBuildPtrToInt(fn->builder, rhs, ltype, "");
649 target = LLVMBuildICmp(fn->builder, op, lhs, rhs, target_name);
660 target = LLVMBuildFCmp(fn->builder, op, lhs, rhs, target_name);
667 target = LLVMBuildZExt(fn->builder, target, dst_type, target_name);
672 static void output_op_ret(struct function *fn, struct instruction *insn)
677 LLVMValueRef result = get_operand(fn, insn->type, pseudo);
678 LLVMBuildRet(fn->builder, result);
680 LLVMBuildRetVoid(fn->builder);
683 static LLVMValueRef calc_memop_addr(struct function *fn, struct instruction *insn)
694 src = pseudo_to_value(fn, insn->type, insn->src);
697 src = LLVMBuildPointerCast(fn->builder, src, addr_type, LLVMGetValueName(src));
700 addr = calc_gep(fn->builder, src, off);
705 static void output_op_load(struct function *fn, struct instruction *insn)
710 addr = calc_memop_addr(fn, insn);
714 target = LLVMBuildLoad(fn->builder, addr, name);
719 static void output_op_store(struct function *fn, struct instruction *insn)
723 addr = calc_memop_addr(fn, insn);
725 target_in = pseudo_to_rvalue(fn, insn->type, insn->target);
728 LLVMBuildStore(fn->builder, target_in, addr);
731 static LLVMValueRef bool_value(struct function *fn, LLVMValueRef value)
734 value = LLVMBuildIsNotNull(fn->builder, value, LLVMGetValueName(value));
739 static void output_op_cbr(struct function *fn, struct instruction *br)
741 LLVMValueRef cond = bool_value(fn,
742 pseudo_to_value(fn, NULL, br->cond));
744 LLVMBuildCondBr(fn->builder, cond,
749 static void output_op_br(struct function *fn, struct instruction *br)
751 LLVMBuildBr(fn->builder, br->bb_true->priv);
754 static void output_op_sel(struct function *fn, struct instruction *insn)
759 src1 = bool_value(fn, pseudo_to_value(fn, NULL, insn->src1));
760 src2 = get_operand(fn, insn->type, insn->src2);
761 src3 = get_operand(fn, insn->type, insn->src3);
764 target = LLVMBuildSelect(fn->builder, src1, src2, src3, name);
766 insn->target->priv = adjust_type(fn, insn->type, target);
769 static void output_op_switch(struct function *fn, struct instruction *insn)
783 sw_val = get_ioperand(fn, insn->type, insn->cond);
784 target = LLVMBuildSwitch(fn->builder, sw_val,
797 static void output_op_call(struct function *fn, struct instruction *insn)
811 func = get_operand(fn, ctype, insn->func);
813 func = pseudo_to_value(fn, ctype, insn->func);
817 args[i++] = pseudo_to_rvalue(fn, ctype, arg);
822 target = LLVMBuildCall(fn->builder, func, args, n_arg, name);
827 static void output_op_phisrc(struct function *fn, struct instruction *insn)
829 insn->src->priv = get_operand(fn, insn->type, insn->src);
832 static void output_op_phi(struct function *fn, struct instruction *insn)
836 insn->target->priv = LLVMBuildPhi(fn->builder, dst_type, "");
839 static void output_op_ptrcast(struct function *fn, struct instruction *insn)
847 src = get_operand(fn, otype, insn->src);
873 target = LLVMBuildCast(fn->builder, op, src, dtype, target_name);
877 static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOpcode op)
885 return output_op_ptrcast(fn, insn);
889 src = get_operand(fn, otype, insn->src);
907 target = LLVMBuildCast(fn->builder, op, src, dtype, target_name);
911 static void output_op_fpcast(struct function *fn, struct instruction *insn)
921 src = get_operand(fn, otype, insn->src);
924 target = LLVMBuildFPCast(fn->builder, src, dtype, name);
927 target = LLVMBuildSIToFP(fn->builder, src, dtype, name);
930 target = LLVMBuildUIToFP(fn->builder, src, dtype, name);
938 static void output_op_label(struct function *fn, struct instruction *insn)
940 insn->target->priv = LLVMBlockAddress(fn->fn, insn->bb_true->priv);
943 static void output_op_setval(struct function *fn, struct instruction *insn)
950 target = LLVMBlockAddress(fn->fn, val->symbol->bb_target->priv);
959 static void output_op_setfval(struct function *fn, struct instruction *insn)
968 static void output_insn(struct function *fn, struct instruction *insn)
972 output_op_ret(fn, insn);
975 output_op_br(fn, insn);
978 output_op_cbr(fn, insn);
984 output_op_label(fn, insn);
987 output_op_setval(fn, insn);
990 output_op_setfval(fn, insn);
993 output_op_switch(fn, insn);
999 output_op_phisrc(fn, insn);
1002 output_op_phi(fn, insn);
1005 output_op_load(fn, insn);
1008 output_op_store(fn, insn);
1013 output_op_call(fn, insn);
1016 output_op_cast(fn, insn, LLVMZExt);
1019 output_op_cast(fn, insn, LLVMSExt);
1022 output_op_cast(fn, insn, LLVMTrunc);
1025 output_op_cast(fn, insn, LLVMFPToUI);
1028 output_op_cast(fn, insn, LLVMFPToSI);
1032 output_op_fpcast(fn, insn);
1037 output_op_ptrcast(fn, insn);
1040 output_op_binary(fn, insn);
1043 output_op_compare(fn, insn);
1046 output_op_sel(fn, insn);
1055 src = pseudo_to_value(fn, insn->type, insn->src);
1059 target = LLVMBuildNot(fn->builder, src, target_name);
1069 src = pseudo_to_value(fn, insn->type, insn->src);
1074 target = LLVMBuildFNeg(fn->builder, src, target_name);
1076 target = LLVMBuildNeg(fn->builder, src, target_name);
1103 static void output_bb(struct function *fn, struct basic_block *bb)
1111 output_insn(fn, insn);
1127 function.fn = get_sym_value(module, sym);
1128 LLVMSetFunctionCallConv(function.fn, LLVMCCallConv);
1129 LLVMSetLinkage(function.fn, function_linkage(sym));
1139 arg = LLVMGetParam(function.fn, i);
1151 bbr = LLVMAppendBasicBlock(function.fn, bbname);