diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2021-04-26 20:50:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-26 20:50:43 +0100 |
| commit | 53c7e65c57ff0042a0851781712d8fc1e5cae8be (patch) | |
| tree | 1640bdc8740d0fa6fbdd8231b5cd0235727cdba5 /src/llvm_backend.cpp | |
| parent | aa846d0ea5f40361cc4ada2213c4659fe1b59580 (diff) | |
| parent | a38586420cd2d8534a7be83851d8ca174cce1bcb (diff) | |
Merge pull request #914 from odin-lang/old-backend-removal
Removal of the Old Backend
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index a92f53774..0fd778b9c 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2545,8 +2545,6 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) { Type *pt = base_type(entity->type); GB_ASSERT(pt->kind == Type_Proc); - set_procedure_abi_types(entity->type); - p->type = entity->type; p->type_expr = decl->type_expr; p->body = pl->body; @@ -2845,6 +2843,14 @@ lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbP return res; } +Type *struct_type_from_systemv_distribute_struct_fields(Type *abi_type) { + GB_ASSERT(is_type_tuple(abi_type)); + Type *final_type = alloc_type_struct(); + final_type->Struct.fields = abi_type->Tuple.variables; + return final_type; +} + + lbValue lb_add_param(lbProcedure *p, Entity *e, Ast *expr, Type *abi_type, i32 index) { lbParamPasskind kind = lbParamPass_Value; lbValue v = lb_value_param(p, e, abi_type, index, &kind); @@ -3476,9 +3482,6 @@ void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) { name_len = gb_snprintf(name_text, name_len, "%.*s.%.*s-%d", LIT(p->name), LIT(pd_name), guid); String name = make_string(cast(u8 *)name_text, name_len-1); - set_procedure_abi_types(e->type); - - e->Procedure.link_name = name; lbProcedure *nested_proc = lb_create_procedure(p->module, e); @@ -3613,7 +3616,6 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { return; } - set_procedure_abi_types(e->type); e->Procedure.link_name = name; lbProcedure *nested_proc = lb_create_procedure(p->module, e); @@ -8201,8 +8203,6 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args, LLVMBuildUnreachable(p->builder); }); - set_procedure_abi_types(pt); - bool is_c_vararg = pt->Proc.c_vararg; isize param_count = pt->Proc.param_count; if (is_c_vararg) { @@ -9106,11 +9106,15 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, return res; } - case BuiltinProc_trailing_zeros: - return lb_emit_trailing_zeros(p, lb_build_expr(p, ce->args[0]), tv.type); + case BuiltinProc_count_trailing_zeros: + return lb_emit_count_trailing_zeros(p, lb_build_expr(p, ce->args[0]), tv.type); + case BuiltinProc_count_leading_zeros: + return lb_emit_count_leading_zeros(p, lb_build_expr(p, ce->args[0]), tv.type); case BuiltinProc_count_ones: return lb_emit_count_ones(p, lb_build_expr(p, ce->args[0]), tv.type); + case BuiltinProc_count_zeros: + return lb_emit_count_zeros(p, lb_build_expr(p, ce->args[0]), tv.type); case BuiltinProc_reverse_bits: return lb_emit_reverse_bits(p, lb_build_expr(p, ce->args[0]), tv.type); @@ -9584,7 +9588,6 @@ lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) { Type *proc_type_ = base_type(value.type); GB_ASSERT(proc_type_->kind == Type_Proc); TypeProc *pt = &proc_type_->Proc; - set_procedure_abi_types(proc_type_); if (is_call_expr_field_value(ce)) { auto args = array_make<lbValue>(permanent_allocator(), pt->param_count); @@ -9970,8 +9973,16 @@ lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) { return res; } +lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) { + i64 sz = 8*type_size_of(type); + lbValue size = lb_const_int(p->module, type, cast(u64)sz); + lbValue count = lb_emit_count_ones(p, x, type); + return lb_emit_arith(p, Token_Sub, size, count, type); +} -lbValue lb_emit_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { + + +lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { x = lb_emit_conv(p, x, type); char const *name = "llvm.cttz"; @@ -9990,6 +10001,26 @@ lbValue lb_emit_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { return res; } +lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) { + x = lb_emit_conv(p, x, type); + + char const *name = "llvm.ctlz"; + LLVMTypeRef types[1] = {lb_type(p->module, type)}; + unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name)); + GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0])); + LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types)); + + LLVMValueRef args[2] = {}; + args[0] = x.value; + args[1] = LLVMConstNull(LLVMInt1TypeInContext(p->module->ctx)); + + lbValue res = {}; + res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), ""); + res.type = type; + return res; +} + + lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) { x = lb_emit_conv(p, x, type); @@ -10768,8 +10799,6 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A String name = make_string((u8 *)name_text, name_len-1); Type *type = type_of_expr(expr); - set_procedure_abi_types(type); - Token token = {}; token.pos = ast_token(expr).pos; |