310 auto app = lam->
body()->as<
App>();
313 if (app->callee() ==
root()->ret_var()) {
314 std::vector<std::string> values;
315 std::vector<const Def*> types;
317 for (
auto arg : app->args()) {
319 values.emplace_back(val);
320 types.emplace_back(arg->type());
324 switch (values.size()) {
325 case 0:
return bb.tail(
"ret void");
326 case 1:
return bb.tail(
"ret {} {}", convert(types[0]), values[0]);
328 std::string prev =
"undef";
329 auto type = convert(
world().sigma(types));
330 for (
size_t i = 0, n = values.size(); i != n; ++i) {
331 auto v_elem = values[i];
332 auto t_elem = convert(types[i]);
333 auto namei =
"%ret_val." + std::to_string(i);
334 bb.tail(
"{} = insertvalue {} {}, {} {}, {}", namei, type, prev, t_elem, v_elem, i);
338 bb.tail(
"ret {} {}", type, prev);
345 for (
auto callee_def : ex->tuple()->projs()) {
347 auto callee = callee_def->as_mut<
Lam>();
351 assert(callee->num_tvars() == app->num_targs());
352 size_t n = callee->num_tvars();
353 for (
size_t i = 0; i != n; ++i) {
355 if (
auto arg =
emit_unsafe(app->arg(n, i)); !arg.empty()) {
356 auto phi = callee->var(n, i);
358 lam2bb_[callee].phis[phi].emplace_back(arg,
id(lam,
true));
364 auto c =
emit(ex->index());
365 if (ex->tuple()->num_projs() == 2) {
366 auto [f, t] = ex->tuple()->projs<2>([
this](
auto def) {
return emit(def); });
367 return bb.tail(
"br i1 {}, label {}, label {}", c, t, f);
369 auto t_c = convert(ex->index()->type());
370 bb.tail(
"switch {} {}, label {} [ ", t_c, c,
emit(ex->tuple()->proj(0)));
371 for (
auto i = 1u; i < ex->tuple()->num_projs(); i++)
372 print(bb.tail().back(),
"{} {}, label {} ", t_c, std::to_string(i),
emit(ex->tuple()->proj(i)));
373 print(bb.tail().back(),
"]");
375 }
else if (app->callee()->isa<
Bot>()) {
376 return bb.tail(
"ret ; bottom: unreachable");
378 size_t n = callee->num_tvars();
379 for (
size_t i = 0; i != n; ++i) {
380 if (
auto arg =
emit_unsafe(app->arg(n, i)); !arg.empty()) {
381 auto phi = callee->var(n, i);
383 lam2bb_[callee].phis[phi].emplace_back(arg,
id(lam,
true));
387 return bb.tail(
"br label {}",
id(callee));
389 declare(
"void @longjmp(i8*, i32) noreturn");
391 auto [
mem, jbuf, tag] = app->args<3>();
393 auto v_jb =
emit(jbuf);
394 auto v_tag =
emit(tag);
395 bb.tail(
"call void @longjmp(i8* {}, i32 {})", v_jb, v_tag);
396 return bb.tail(
"unreachable");
398 auto v_callee =
emit(app->callee());
400 std::vector<std::string> args;
401 auto app_args = app->args();
402 for (
auto arg : app_args.view().rsubspan(1))
403 if (
auto v_arg =
emit_unsafe(arg); !v_arg.empty()) args.emplace_back(convert(arg->type()) +
" " + v_arg);
405 if (app->args().back()->isa<
Bot>()) {
407 assert(convert_ret_pi(app->callee_type()->ret_pi()) ==
"void");
408 bb.tail(
"call void {}({, })", v_callee, args);
409 return bb.tail(
"unreachable");
412 auto ret_lam = app->args().back()->as_mut<
Lam>();
413 size_t num_vars = ret_lam->
num_vars();
417 for (
auto var : ret_lam->vars()) {
420 types[n] = var->type();
425 bb.tail(
"call void {}({, })", v_callee, args);
427 auto name =
"%" + app->unique_name() +
"ret";
428 auto t_ret = convert_ret_pi(ret_lam->type());
429 bb.tail(
"{} = call {} {}({, })",
name, t_ret, v_callee, args);
431 for (
size_t i = 0, e = ret_lam->num_vars(); i != e; ++i) {
432 auto phi = ret_lam->var(i);
437 namei +=
'.' + std::to_string(i - 1);
438 bb.tail(
"{} = extractvalue {} {}, {}", namei, t_ret,
name, i - 1);
441 lam2bb_[ret_lam].phis[phi].emplace_back(namei,
id(lam,
true));
446 return bb.tail(
"br label {}",
id(ret_lam));
451 if (
auto lam = def->isa<
Lam>())
return id(lam);
456 auto emit_tuple = [&](
const Def* tuple) {
457 if (isa_mem_sigma_2(tuple->type())) {
459 return emit(tuple->proj(2, 1));
462 if (is_const(tuple)) {
463 bool is_array = tuple->type()->isa<
Arr>();
466 s += is_array ?
"[" :
"{";
468 for (
size_t i = 0, n = tuple->num_projs(); i != n; ++i) {
469 auto e = tuple->proj(n, i);
470 if (
auto v_elem =
emit_unsafe(e); !v_elem.empty()) {
471 auto t_elem = convert(e->type());
472 s += sep + t_elem +
" " + v_elem;
477 return s += is_array ?
"]" :
"}";
480 std::string prev =
"undef";
481 auto t = convert(tuple->type());
482 for (
size_t src = 0, dst = 0, n = tuple->num_projs(); src != n; ++src) {
483 auto e = tuple->proj(n, src);
485 auto elem_t = convert(e->type());
487 auto namei =
name +
"." + std::to_string(dst);
488 prev = bb.
assign(namei,
"insertvalue {} {}, {} {}, {}", t, prev, elem_t, elem, dst);
495 if (def->isa<
Var>()) {
497 if (std::ranges::any_of(ts, [](
auto t) {
return match<mem::M>(t); }))
return {};
498 return emit_tuple(def);
501 auto emit_gep_index = [&](
const Def* index) {
502 auto v_i =
emit(index);
503 auto t_i = convert(index->type());
505 if (
auto size =
Idx::isa(index->type())) {
508 "zext {} {} to i{} ; add one more bit for gep index as it is treated as signed value",
510 t_i =
"i" + std::to_string(*w + 1);
514 return std::pair(v_i, t_i);
517 if (
auto lit = def->isa<
Lit>()) {
518 if (lit->type()->isa<
Nat>() ||
Idx::isa(lit->type())) {
519 return std::to_string(lit->get());
526 s <<
"0xH" << std::setfill(
'0') << std::setw(4) << std::right << std::hex << lit->get<
u16>();
529 hex = std::bit_cast<u64>(
f64(lit->get<
f32>()));
532 case 64: hex = lit->get<
u64>();
break;
533 default: fe::unreachable();
536 s <<
"0x" << std::setfill(
'0') << std::setw(16) << std::right << std::hex << hex;
540 }
else if (def->isa<
Bot>()) {
542 }
else if (
auto top = def->isa<
Top>()) {
545 }
else if (
auto tuple = def->isa<
Tuple>()) {
546 return emit_tuple(tuple);
547 }
else if (
auto pack = def->isa<
Pack>()) {
548 if (
auto lit =
Lit::isa(pack->body()); lit && *lit == 0)
return "zeroinitializer";
549 return emit_tuple(pack);
550 }
else if (
auto extract = def->isa<
Extract>()) {
551 auto tuple = extract->tuple();
552 auto index = extract->index();
557 if (
auto app = extract->type()->isa<
App>();
559 if (
auto arity = tuple->type()->isa_lit_arity(); arity && *arity == 2) {
560 auto t = convert(extract->type());
561 auto [elem_a, elem_b] = tuple->projs<2>([&](
auto e) {
return emit_unsafe(e); });
563 return bb.
assign(
name,
"select {} {}, {} {}, {} {}", convert(index->type()),
emit(index), t, elem_b, t,
574 auto t_tup = convert(tuple->type());
576 if (isa_mem_sigma_2(tuple->type()))
return v_tup;
578 auto v_i =
match<mem::M>(tuple->proj(0)->type()) ? std::to_string(*li - 1) : std::to_string(*li);
579 return bb.
assign(
name,
"extractvalue {} {}, {}", t_tup, v_tup, v_i);
582 auto t_elem = convert(extract->type());
583 auto [v_i, t_i] = emit_gep_index(index);
586 "{}.alloca = alloca {} ; copy to alloca to emulate extract with store + gep + load",
name, t_tup);
587 print(bb.
body().emplace_back(),
"store {} {}, {}* {}.alloca", t_tup, v_tup, t_tup,
name);
588 print(bb.
body().emplace_back(),
"{}.gep = getelementptr inbounds {}, {}* {}.alloca, i64 0, {} {}",
name, t_tup,
589 t_tup,
name, t_i, v_i);
590 return bb.
assign(
name,
"load {}, {}* {}.gep", t_elem, t_elem,
name);
591 }
else if (
auto insert = def->isa<
Insert>()) {
593 auto t_tup = convert(insert->tuple()->type());
594 auto t_val = convert(insert->value()->type());
595 auto v_tup =
emit(insert->tuple());
596 auto v_val =
emit(insert->value());
597 if (
auto idx =
Lit::isa(insert->index())) {
598 auto v_idx =
emit(insert->index());
599 return bb.
assign(
name,
"insertvalue {} {}, {} {}, {}", t_tup, v_tup, t_val, v_val, v_idx);
601 auto t_elem = convert(insert->value()->type());
602 auto [v_i, t_i] = emit_gep_index(insert->index());
604 "{}.alloca = alloca {} ; copy to alloca to emulate insert with store + gep + load",
name, t_tup);
605 print(bb.
body().emplace_back(),
"store {} {}, {}* {}.alloca", t_tup, v_tup, t_tup,
name);
606 print(bb.
body().emplace_back(),
"{}.gep = getelementptr inbounds {}, {}* {}.alloca, i64 0, {} {}",
name,
607 t_tup, t_tup,
name, t_i, v_i);
608 print(bb.
body().emplace_back(),
"store {} {}, {}* {}.gep", t_val, v_val, t_val,
name);
609 return bb.
assign(
name,
"load {}, {}* {}.alloca", t_tup, t_tup,
name);
611 }
else if (
auto global = def->isa<
Global>()) {
612 auto v_init =
emit(global->init());
613 auto [pointee, addr_space] =
force<mem::Ptr>(global->type())->args<2>();
614 print(vars_decls_,
"{} = global {} {}\n",
name, convert(pointee), v_init);
617 auto [a, b] = nat->args<2>([
this](
auto def) {
return emit(def); });
620 case core::nat::add: op =
"add";
break;
621 case core::nat::sub: op =
"sub";
break;
622 case core::nat::mul: op =
"mul";
break;
625 return bb.
assign(
name,
"{} nsw nuw i64 {}, {}", op, a, b);
627 auto [a, b] = ncmp->args<2>([
this](
auto def) {
return emit(def); });
632 case core::ncmp::e: op +=
"eq" ;
break;
633 case core::ncmp::ne: op +=
"ne" ;
break;
634 case core::ncmp::g: op +=
"ugt";
break;
635 case core::ncmp::ge: op +=
"uge";
break;
636 case core::ncmp::l: op +=
"ult";
break;
637 case core::ncmp::le: op +=
"ule";
break;
639 default: fe::unreachable();
642 return bb.
assign(
name,
"{} i64 {}, {}", op, a, b);
644 auto x =
emit(idx->arg());
646 auto t = convert(idx->type());
647 if (s < 64)
return bb.
assign(
name,
"trunc i64 {} to {}", x, t);
650 assert(bit1.id() == core::bit1::neg);
651 auto x =
emit(bit1->arg());
652 auto t = convert(bit1->type());
653 return bb.
assign(
name,
"xor {} -1, {}", t, x);
655 auto [a, b] = bit2->args<2>([
this](
auto def) {
return emit(def); });
656 auto t = convert(bit2->type());
658 auto neg = [&](std::string_view x) {
return bb.
assign(
name +
".neg",
"xor {} -1, {}", t, x); };
662 case core::bit2::and_:
return bb.
assign(
name,
"and {} {}, {}", t, a, b);
663 case core::bit2:: or_:
return bb.
assign(
name,
"or {} {}, {}", t, a, b);
664 case core::bit2::xor_:
return bb.
assign(
name,
"xor {} {}, {}", t, a, b);
665 case core::bit2::nand:
return neg(bb.
assign(
name,
"and {} {}, {}", t, a, b));
666 case core::bit2:: nor:
return neg(bb.
assign(
name,
"or {} {}, {}", t, a, b));
667 case core::bit2::nxor:
return neg(bb.
assign(
name,
"xor {} {}, {}", t, a, b));
668 case core::bit2:: iff:
return bb.
assign(
name,
"and {} {}, {}", neg(a), b);
669 case core::bit2::niff:
return bb.
assign(
name,
"or {} {}, {}", neg(a), b);
671 default: fe::unreachable();
674 auto [a, b] = shr->args<2>([
this](
auto def) {
return emit(def); });
675 auto t = convert(shr->type());
678 case core::shr::a: op =
"ashr";
break;
679 case core::shr::l: op =
"lshr";
break;
682 return bb.
assign(
name,
"{} {} {}, {}", op, t, a, b);
684 auto [a, b] = wrap->args<2>([
this](
auto def) {
return emit(def); });
685 auto t = convert(wrap->type());
686 auto mode =
Lit::as(wrap->decurry()->arg());
689 case core::wrap::add: op =
"add";
break;
690 case core::wrap::sub: op =
"sub";
break;
691 case core::wrap::mul: op =
"mul";
break;
692 case core::wrap::shl: op =
"shl";
break;
695 if (mode & core::Mode::nuw) op +=
" nuw";
696 if (mode & core::Mode::nsw) op +=
" nsw";
698 return bb.
assign(
name,
"{} {} {}, {}", op, t, a, b);
700 auto [m, xy] = div->args<2>();
701 auto [x, y] = xy->projs<2>();
702 auto t = convert(x->type());
708 case core::div::sdiv: op =
"sdiv";
break;
709 case core::div::udiv: op =
"udiv";
break;
710 case core::div::srem: op =
"srem";
break;
711 case core::div::urem: op =
"urem";
break;
714 return bb.
assign(
name,
"{} {} {}, {}", op, t, a, b);
716 auto [a, b] = icmp->args<2>([
this](
auto def) {
return emit(def); });
717 auto t = convert(icmp->arg(0)->type());
722 case core::icmp::e: op +=
"eq" ;
break;
723 case core::icmp::ne: op +=
"ne" ;
break;
724 case core::icmp::sg: op +=
"sgt";
break;
725 case core::icmp::sge: op +=
"sge";
break;
726 case core::icmp::sl: op +=
"slt";
break;
727 case core::icmp::sle: op +=
"sle";
break;
728 case core::icmp::ug: op +=
"ugt";
break;
729 case core::icmp::uge: op +=
"uge";
break;
730 case core::icmp::ul: op +=
"ult";
break;
731 case core::icmp::ule: op +=
"ule";
break;
733 default: fe::unreachable();
736 return bb.
assign(
name,
"{} {} {}, {}", op, t, a, b);
738 auto [x, y] = extr->args<2>();
739 auto t = convert(x->type());
742 std::string f =
"llvm.";
744 case core::extrema::Sm: f +=
"smin.";
break;
745 case core::extrema::SM: f +=
"smax.";
break;
746 case core::extrema::sm: f +=
"umin.";
break;
747 case core::extrema::sM: f +=
"umax.";
break;
750 declare(
"{} @{}({}, {})", t, f, t, t);
751 return bb.
assign(
name,
"tail call {} @{}({} {}, {} {})", t, f, t, a, t, b);
753 auto [m, x] = abs->args<2>();
754 auto t = convert(x->type());
756 std::string f =
"llvm.abs." + t;
757 declare(
"{} @{}({}, {})", t, f, t,
"i1");
758 return bb.
assign(
name,
"tail call {} @{}({} {}, {} {})", t, f, t, a,
"i1",
"1");
760 auto v_src =
emit(conv->arg());
761 auto t_src = convert(conv->arg()->type());
762 auto t_dst = convert(conv->type());
767 if (w_src == w_dst)
return v_src;
770 case core::conv::s: op = w_src < w_dst ?
"sext" :
"trunc";
break;
771 case core::conv::u: op = w_src < w_dst ?
"zext" :
"trunc";
break;
774 return bb.
assign(
name,
"{} {} {} to {}", op, t_src, v_src, t_dst);
779 auto t_src = convert(
bitcast->arg()->type());
780 auto t_dst = convert(
bitcast->type());
782 if (
auto lit =
Lit::isa(
bitcast->arg()); lit && *lit == 0)
return "zeroinitializer";
784 if (src_type_ptr && dst_type_ptr)
return bb.
assign(
name,
"bitcast {} {} to {}", t_src, v_src, t_dst);
785 if (src_type_ptr)
return bb.
assign(
name,
"ptrtoint {} {} to {}", t_src, v_src, t_dst);
786 if (dst_type_ptr)
return bb.
assign(
name,
"inttoptr {} {} to {}", t_src, v_src, t_dst);
789 auto size2width = [&](
const Def* type) {
790 if (type->isa<
Nat>())
return 64_n;
795 auto src_size = size2width(
bitcast->arg()->type());
796 auto dst_size = size2width(
bitcast->type());
799 if (src_size && dst_size) {
800 if (src_size == dst_size)
return v_src;
801 op = (src_size < dst_size) ?
"zext" :
"trunc";
803 return bb.
assign(
name,
"{} {} {} to {}", op, t_src, v_src, t_dst);
805 auto [ptr, i] = lea->args<2>();
807 auto v_ptr =
emit(ptr);
808 auto t_pointee = convert(pointee);
809 auto t_ptr = convert(ptr->type());
810 if (pointee->isa<
Sigma>())
811 return bb.
assign(
name,
"getelementptr inbounds {}, {} {}, i64 0, i32 {}", t_pointee, t_ptr, v_ptr,
814 assert(pointee->isa<
Arr>());
815 auto [v_i, t_i] = emit_gep_index(i);
817 return bb.
assign(
name,
"getelementptr inbounds {}, {} {}, i64 0, {} {}", t_pointee, t_ptr, v_ptr, t_i, v_i);
822 auto size =
emit(malloc->arg(1));
824 bb.
assign(
name +
"i8",
"call i8* @malloc(i64 {})", size);
825 return bb.
assign(
name,
"bitcast i8* {} to {}",
name +
"i8", ptr_t);
829 auto ptr =
emit(free->arg(1));
832 bb.
assign(
name +
"i8",
"bitcast {} {} to i8*", ptr_t, ptr);
833 bb.
tail(
"call void @free(i8* {})",
name +
"i8");
839 auto [pointee, addr_space] = mslot->decurry()->args<2>();
840 print(bb.
body().emplace_back(),
"{} = alloca {}",
name, convert(pointee));
846 auto v_ptr =
emit(free->arg(1));
849 bb.
assign(
name +
"i8",
"bitcast {} {} to i8*", t_ptr, v_ptr);
850 bb.
tail(
"call void @free(i8* {})",
name +
"i8");
854 auto v_ptr =
emit(load->arg(1));
855 auto t_ptr = convert(load->arg(1)->type());
856 auto t_pointee = convert(
force<mem::Ptr>(load->arg(1)->type())->arg(0));
857 return bb.
assign(
name,
"load {}, {} {}", t_pointee, t_ptr, v_ptr);
860 auto v_ptr =
emit(store->arg(1));
861 auto v_val =
emit(store->arg(2));
862 auto t_ptr = convert(store->arg(1)->type());
863 auto t_val = convert(store->arg(2)->type());
864 print(bb.
body().emplace_back(),
"store {} {}, {} {}", t_val, v_val, t_ptr, v_ptr);
870 auto size =
name +
".size";
871 bb.
assign(size,
"call i64 @jmpbuf_size()");
872 return bb.
assign(
name,
"alloca i8, i64 {}", size);
874 declare(
"i32 @_setjmp(i8*) returns_twice");
876 auto [
mem, jmpbuf] = setjmp->arg()->projs<2>();
878 auto v_jb =
emit(jmpbuf);
879 return bb.
assign(
name,
"call i32 @_setjmp(i8* {})", v_jb);
881 auto [a, b] = arith->args<2>([
this](
auto def) {
return emit(def); });
882 auto t = convert(arith->type());
883 auto mode =
Lit::as(arith->decurry()->arg());
885 switch (arith.id()) {
886 case math::arith::add: op =
"fadd";
break;
887 case math::arith::sub: op =
"fsub";
break;
888 case math::arith::mul: op =
"fmul";
break;
889 case math::arith::div: op =
"fdiv";
break;
890 case math::arith::rem: op =
"frem";
break;
893 if (mode == math::Mode::fast)
897 if (mode & math::Mode::nnan ) op +=
" nnan";
898 if (mode & math::Mode::ninf ) op +=
" ninf";
899 if (mode & math::Mode::nsz ) op +=
" nsz";
900 if (mode & math::Mode::arcp ) op +=
" arcp";
901 if (mode & math::Mode::contract) op +=
" contract";
902 if (mode & math::Mode::afn ) op +=
" afn";
903 if (mode & math::Mode::reassoc ) op +=
" reassoc";
907 return bb.
assign(
name,
"{} {} {}, {}", op, t, a, b);
909 auto a =
emit(tri->arg());
910 auto t = convert(tri->type());
914 if (tri.id() == math::tri::sin) {
915 f =
"llvm.sin"s + llvm_suffix(tri->type());
916 }
else if (tri.id() == math::tri::cos) {
917 f =
"llvm.cos"s + llvm_suffix(tri->type());
919 if (tri.sub() &
sub_t(math::tri::a)) f +=
"a";
922 case math::tri::sin: f +=
"sin";
break;
923 case math::tri::cos: f +=
"cos";
break;
924 case math::tri::tan: f +=
"tan";
break;
925 case math::tri::ahFF:
error(
"this axiom is supposed to be unused");
926 default: fe::unreachable();
929 if (tri.sub() &
sub_t(math::tri::h)) f +=
"h";
930 f += math_suffix(tri->type());
933 declare(
"{} @{}({})", t, f, t);
934 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
936 auto [a, b] = extrema->args<2>([
this](
auto def) {
return emit(def); });
937 auto t = convert(extrema->type());
938 std::string f =
"llvm.";
939 switch (extrema.id()) {
940 case math::extrema::fmin: f +=
"minnum";
break;
941 case math::extrema::fmax: f +=
"maxnum";
break;
942 case math::extrema::ieee754min: f +=
"minimum";
break;
943 case math::extrema::ieee754max: f +=
"maximum";
break;
945 f += llvm_suffix(extrema->type());
947 declare(
"{} @{}({}, {})", t, f, t, t);
948 return bb.
assign(
name,
"tail call {} @{}({} {}, {} {})", t, f, t, a, t, b);
950 auto [a, b] = pow->args<2>([
this](
auto def) {
return emit(def); });
951 auto t = convert(pow->type());
952 std::string f =
"llvm.pow";
953 f += llvm_suffix(pow->type());
954 declare(
"{} @{}({}, {})", t, f, t, t);
955 return bb.
assign(
name,
"tail call {} @{}({} {}, {} {})", t, f, t, a, t, b);
957 auto a =
emit(rt->arg());
958 auto t = convert(rt->type());
960 if (rt.id() == math::rt::sq)
961 f =
"llvm.sqrt"s + llvm_suffix(rt->type());
963 f =
"cbrt"s += math_suffix(rt->type());
964 declare(
"{} @{}({})", t, f, t);
965 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
967 auto a =
emit(exp->arg());
968 auto t = convert(exp->type());
969 std::string f =
"llvm.";
970 f += (exp.sub() &
sub_t(math::exp::log)) ?
"log" :
"exp";
971 f += (exp.sub() &
sub_t(math::exp::bin)) ?
"2" : (exp.sub() &
sub_t(math::exp::dec)) ?
"10" :
"";
972 f += llvm_suffix(exp->type());
974 declare(
"{} @{}({})", t, f, t);
975 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
977 auto a =
emit(er->arg());
978 auto t = convert(er->type());
979 auto f = er.id() == math::er::f ?
"erf"s :
"erfc"s;
980 f += math_suffix(er->type());
981 declare(
"{} @{}({})", t, f, t);
982 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
984 auto a =
emit(gamma->arg());
985 auto t = convert(gamma->type());
986 std::string f = gamma.id() == math::gamma::t ?
"tgamma" :
"lgamma";
987 f += math_suffix(gamma->type());
988 declare(
"{} @{}({})", t, f, t);
989 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
991 auto [a, b] = cmp->args<2>([
this](
auto def) {
return emit(def); });
992 auto t = convert(cmp->arg(0)->type());
997 case math::cmp:: e: op +=
"oeq";
break;
998 case math::cmp:: l: op +=
"olt";
break;
999 case math::cmp:: le: op +=
"ole";
break;
1000 case math::cmp:: g: op +=
"ogt";
break;
1001 case math::cmp:: ge: op +=
"oge";
break;
1002 case math::cmp:: ne: op +=
"one";
break;
1003 case math::cmp:: o: op +=
"ord";
break;
1004 case math::cmp:: u: op +=
"uno";
break;
1005 case math::cmp:: ue: op +=
"ueq";
break;
1006 case math::cmp:: ul: op +=
"ult";
break;
1007 case math::cmp::ule: op +=
"ule";
break;
1008 case math::cmp:: ug: op +=
"ugt";
break;
1009 case math::cmp::uge: op +=
"uge";
break;
1010 case math::cmp::une: op +=
"une";
break;
1012 default: fe::unreachable();
1015 return bb.
assign(
name,
"{} {} {}, {}", op, t, a, b);
1017 auto v_src =
emit(conv->arg());
1018 auto t_src = convert(conv->arg()->type());
1019 auto t_dst = convert(conv->type());
1024 switch (conv.id()) {
1025 case math::conv::f2f: op = s_src < s_dst ?
"fpext" :
"fptrunc";
break;
1026 case math::conv::s2f: op =
"sitofp";
break;
1027 case math::conv::u2f: op =
"uitofp";
break;
1028 case math::conv::f2s: op =
"fptosi";
break;
1029 case math::conv::f2u: op =
"fptoui";
break;
1032 return bb.
assign(
name,
"{} {} {} to {}", op, t_src, v_src, t_dst);
1034 auto a =
emit(abs->arg());
1035 auto t = convert(abs->type());
1036 std::string f =
"llvm.fabs";
1037 f += llvm_suffix(abs->type());
1038 declare(
"{} @{}({})", t, f, t);
1039 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
1041 auto a =
emit(round->arg());
1042 auto t = convert(round->type());
1043 std::string f =
"llvm.";
1044 switch (round.id()) {
1045 case math::round::f: f +=
"floor";
break;
1046 case math::round::c: f +=
"ceil";
break;
1047 case math::round::r: f +=
"round";
break;
1048 case math::round::t: f +=
"trunc";
break;
1050 f += llvm_suffix(round->type());
1051 declare(
"{} @{}({})", t, f, t);
1052 return bb.
assign(
name,
"tail call {} @{}({} {})", t, f, t, a);
1054 error(
"unhandled def in LLVM backend: {} : {}", def, def->
type());