diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/build_settings.cpp | 6 | ||||
| -rw-r--r-- | src/check_builtin.cpp | 6 | ||||
| -rw-r--r-- | src/llvm_backend.cpp | 436 | ||||
| -rw-r--r-- | src/llvm_backend_const.cpp | 3 | ||||
| -rw-r--r-- | src/llvm_backend_general.cpp | 6 | ||||
| -rw-r--r-- | src/llvm_backend_opt.cpp | 7 | ||||
| -rw-r--r-- | src/llvm_backend_proc.cpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend_type.cpp | 95 | ||||
| -rw-r--r-- | src/tilde_stmt.cpp | 20 |
9 files changed, 511 insertions, 70 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp index d734073c0..ffb276d1e 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -1388,8 +1388,10 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta bc->optimization_level = gb_clamp(bc->optimization_level, -1, 3); - // ENFORCE DYNAMIC MAP CALLS - bc->dynamic_map_calls = true; + if (bc->metrics.os != TargetOs_windows) { + // ENFORCE DYNAMIC MAP CALLS + bc->dynamic_map_calls = true; + } bc->ODIN_VALGRIND_SUPPORT = false; if (build_context.metrics.os != TargetOs_windows) { diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 49095a7a8..77ba6b435 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -5170,7 +5170,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As Operand op = {}; check_expr(c, &op, ce->args[1]); - if (op.mode != Addressing_Constant && !is_type_integer(op.type)) { + if (op.mode != Addressing_Constant || !is_type_integer(op.type)) { error(op.expr, "Expected a constant integer for the index of procedure parameter value"); return false; } @@ -5229,7 +5229,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As Operand op = {}; check_expr(c, &op, ce->args[1]); - if (op.mode != Addressing_Constant && !is_type_integer(op.type)) { + if (op.mode != Addressing_Constant || !is_type_integer(op.type)) { error(op.expr, "Expected a constant integer for the index of procedure parameter value"); return false; } @@ -5307,7 +5307,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As } else { Operand op = {}; check_expr(c, &op, ce->args[1]); - if (op.mode != Addressing_Constant && !is_type_integer(op.type)) { + if (op.mode != Addressing_Constant || !is_type_integer(op.type)) { error(op.expr, "Expected a constant integer for the index of record parameter value"); return false; } diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 00c62f0f1..513b40a4d 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -506,9 +506,9 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { LLVMSetLinkage(p->value, LLVMInternalLinkage); lb_add_attribute_to_proc(m, p->value, "nounwind"); - // if (build_context.ODIN_DEBUG) { + if (build_context.ODIN_DEBUG) { lb_add_attribute_to_proc(m, p->value, "noinline"); - // } + } LLVMValueRef x = LLVMGetParam(p->value, 0); LLVMValueRef y = LLVMGetParam(p->value, 1); @@ -692,7 +692,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { } lbValue map_ptr = {LLVMGetParam(p->value, 0), t_rawptr}; - lbValue hash = {LLVMGetParam(p->value, 1), t_uintptr}; + lbValue hash_param = {LLVMGetParam(p->value, 1), t_uintptr}; lbValue key_ptr = {LLVMGetParam(p->value, 2), t_rawptr}; lbValue value_ptr = {LLVMGetParam(p->value, 3), t_rawptr}; lbValue location_ptr = {LLVMGetParam(p->value, 4), t_source_code_location_ptr}; @@ -700,6 +700,12 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { map_ptr = lb_emit_conv(p, map_ptr, alloc_type_pointer(type)); key_ptr = lb_emit_conv(p, key_ptr, alloc_type_pointer(type->Map.key)); + LLVM_SET_VALUE_NAME(map_ptr.value, "map_ptr"); + LLVM_SET_VALUE_NAME(hash_param.value, "hash_param"); + LLVM_SET_VALUE_NAME(key_ptr.value, "key_ptr"); + LLVM_SET_VALUE_NAME(value_ptr.value, "value_ptr"); + LLVM_SET_VALUE_NAME(location_ptr.value, "location"); + lb_add_proc_attribute_at_index(p, 1+0, "nonnull"); lb_add_proc_attribute_at_index(p, 1+0, "noalias"); @@ -719,6 +725,10 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { lb_add_proc_attribute_at_index(p, 1+4, "noalias"); lb_add_proc_attribute_at_index(p, 1+4, "readonly"); + lbAddr hash_addr = lb_add_local_generated(p, t_uintptr, false); + lb_addr_store(p, hash_addr, hash_param); + LLVM_SET_VALUE_NAME(hash_addr.addr.value, "hash"); + //// lbValue found_ptr = {}; { @@ -726,17 +736,19 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { auto args = array_make<lbValue>(temporary_allocator(), 3); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); - args[1] = hash; + args[1] = lb_addr_load(p, hash_addr); args[2] = key_ptr; found_ptr = lb_emit_call(p, map_get_proc, args); } + LLVM_SET_VALUE_NAME(found_ptr.value, "found_ptr"); lbBlock *found_block = lb_create_block(p, "found"); lbBlock *check_grow_block = lb_create_block(p, "check-grow"); lbBlock *grow_fail_block = lb_create_block(p, "grow-fail"); lbBlock *insert_block = lb_create_block(p, "insert"); + lbBlock *check_has_grown_block = lb_create_block(p, "check-has-grown"); lbBlock *rehash_block = lb_create_block(p, "rehash"); lb_emit_if(p, lb_emit_comp_against_nil(p, Token_NotEq, found_ptr), found_block, check_grow_block); @@ -749,6 +761,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { lbValue map_info = lb_gen_map_info_ptr(p->module, type); + LLVM_SET_VALUE_NAME(map_info.value, "map_info"); { auto args = array_make<lbValue>(temporary_allocator(), 3); @@ -758,16 +771,23 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { lbValue grow_err_and_has_grown = lb_emit_runtime_call(p, "__dynamic_map_check_grow", args); lbValue grow_err = lb_emit_struct_ev(p, grow_err_and_has_grown, 0); lbValue has_grown = lb_emit_struct_ev(p, grow_err_and_has_grown, 1); + LLVM_SET_VALUE_NAME(grow_err.value, "grow_err"); + LLVM_SET_VALUE_NAME(has_grown.value, "has_grown"); - lb_emit_if(p, lb_emit_comp_against_nil(p, Token_NotEq, grow_err), grow_fail_block, insert_block); + lb_emit_if(p, lb_emit_comp_against_nil(p, Token_NotEq, grow_err), grow_fail_block, check_has_grown_block); lb_start_block(p, grow_fail_block); LLVMBuildRet(p->builder, LLVMConstNull(lb_type(m, t_rawptr))); - lb_emit_if(p, has_grown, grow_fail_block, rehash_block); + lb_start_block(p, check_has_grown_block); + + lb_emit_if(p, has_grown, rehash_block, insert_block); lb_start_block(p, rehash_block); lbValue key = lb_emit_load(p, key_ptr); - hash = lb_gen_map_key_hash(p, map_ptr, key, nullptr); + lbValue new_hash = lb_gen_map_key_hash(p, map_ptr, key, nullptr); + LLVM_SET_VALUE_NAME(new_hash.value, "new_hash"); + lb_addr_store(p, hash_addr, new_hash); + lb_emit_jump(p, insert_block); } lb_start_block(p, insert_block); @@ -775,7 +795,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { auto args = array_make<lbValue>(temporary_allocator(), 5); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = map_info; - args[2] = hash; + args[2] = lb_addr_load(p, hash_addr); args[3] = lb_emit_conv(p, key_ptr, t_uintptr); args[4] = lb_emit_conv(p, value_ptr, t_uintptr); @@ -1471,13 +1491,390 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) { array_add(&passes, "function(annotation-remarks)"); break; case 1: - array_add(&passes, "default<Os>"); +// default<Os> +// Passes removed: coro, openmp, sroa + array_add(&passes, u8R"( +annotation2metadata, +forceattrs, +inferattrs, +function<eager-inv>( + lower-expect, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + early-cse<> +), +ipsccp, +called-value-propagation, +globalopt, +function<eager-inv>( + mem2reg, + instcombine<max-iterations=1000;no-use-loop-info>, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>), + require<globals-aa>, + function( + invalidate<aa> + ), + require<profile-summary>, + cgscc( + devirt<4>( + inline<only-mandatory>, + inline, + function-attrs<skip-non-recursive>, + function<eager-inv;no-rerun>( + early-cse<memssa>, + speculative-execution, + jump-threading, + correlated-propagation, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info>, + aggressive-instcombine, + constraint-elimination, + tailcallelim, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + reassociate, + loop-mssa( + loop-instsimplify, + loop-simplifycfg, + licm<no-allowspeculation>, + loop-rotate<header-duplication;no-prepare-for-lto>, + licm<allowspeculation>, + simple-loop-unswitch<no-nontrivial;trivial> + ), + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info>, + loop( + loop-idiom, + indvars, + loop-deletion, + loop-unroll-full + ), + vector-combine, + mldst-motion<no-split-footer-bb>, + gvn<>, + sccp, + bdce, + instcombine<max-iterations=1000;no-use-loop-info>, + jump-threading, + correlated-propagation, + adce, + memcpyopt, + dse, + move-auto-init, + loop-mssa( + licm<allowspeculation> + ), + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info> + ), + function-attrs, + function( + require<should-not-run-function-passes> + ) + ) +), +deadargelim, +globalopt, +globaldce, +elim-avail-extern, +rpo-function-attrs, +recompute-globalsaa, +function<eager-inv>( + float2int, + lower-constant-intrinsics, + loop( + loop-rotate<header-duplication;no-prepare-for-lto>, + loop-deletion + ), + loop-distribute, + inject-tli-mappings, + loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>, + loop-load-elim, + instcombine<max-iterations=1000;no-use-loop-info>, + simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>, + slp-vectorizer, + vector-combine, + instcombine<max-iterations=1000;no-use-loop-info>, + loop-unroll<O2>, + transform-warning, + instcombine<max-iterations=1000;no-use-loop-info>, + loop-mssa( + licm<allowspeculation> + ), + alignment-from-assumptions, + loop-sink, + instsimplify, + div-rem-pairs, + tailcallelim, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch> +), +globaldce, +constmerge, +cg-profile, +rel-lookup-table-converter, +function( + annotation-remarks +), +verify +)"); break; +// default<O2> +// Passes removed: coro, openmp, sroa case 2: - array_add(&passes, "default<O2>"); + array_add(&passes, u8R"( +annotation2metadata, +forceattrs, +inferattrs, +function<eager-inv>( + lower-expect, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + early-cse<> +), +ipsccp, +called-value-propagation, +globalopt, +function<eager-inv>( + mem2reg, + instcombine<max-iterations=1000;no-use-loop-info>, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch> +), +require<globals-aa>, +function( + invalidate<aa> +), +require<profile-summary>, +cgscc( + devirt<4>( + inline<only-mandatory>, + inline, + function-attrs<skip-non-recursive>, + function<eager-inv;no-rerun>( + early-cse<memssa>, + speculative-execution, + jump-threading, + correlated-propagation, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info>, + aggressive-instcombine, + constraint-elimination, + libcalls-shrinkwrap, + tailcallelim, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + reassociate, + loop-mssa( + loop-instsimplify, + loop-simplifycfg, + licm<no-allowspeculation>, + loop-rotate<header-duplication;no-prepare-for-lto>, + licm<allowspeculation>, + simple-loop-unswitch<no-nontrivial;trivial> + ), + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info>, + loop( + loop-idiom, + indvars, + loop-deletion, + loop-unroll-full + ), + vector-combine, + mldst-motion<no-split-footer-bb>, + gvn<>, + sccp, + bdce, + instcombine<max-iterations=1000;no-use-loop-info>, + jump-threading, + correlated-propagation, + adce, + memcpyopt, + dse, + move-auto-init, + loop-mssa( + licm<allowspeculation> + ), + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info> + ), + function-attrs, + function( + require<should-not-run-function-passes> + ) + ) +), +deadargelim, +globalopt, +globaldce, +elim-avail-extern, +rpo-function-attrs, +recompute-globalsaa, +function<eager-inv>( + float2int, + lower-constant-intrinsics, + loop( + loop-rotate<header-duplication;no-prepare-for-lto>, + loop-deletion + ), + loop-distribute, + inject-tli-mappings, + loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>, + loop-load-elim, + instcombine<max-iterations=1000;no-use-loop-info>, + simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>, + slp-vectorizer, + vector-combine, + instcombine<max-iterations=1000;no-use-loop-info>, + loop-unroll<O2>, + transform-warning, + instcombine<max-iterations=1000;no-use-loop-info>, + loop-mssa( + licm<allowspeculation> + ), + alignment-from-assumptions, + loop-sink, + instsimplify, + div-rem-pairs, + tailcallelim, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch> +), +globaldce, +constmerge, +cg-profile, +rel-lookup-table-converter, +function( + annotation-remarks +), +verify +)"); break; + case 3: - array_add(&passes, "default<O3>"); +// default<O3> +// Passes removed: coro, openmp, sroa + array_add(&passes, u8R"( +annotation2metadata, +forceattrs, +inferattrs, +function<eager-inv>( + lower-expect, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + early-cse<>, + callsite-splitting +), +ipsccp, +called-value-propagation, +globalopt, +function<eager-inv>( + mem2reg, + instcombine<max-iterations=1000;no-use-loop-info>, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch> +), +require<globals-aa>, +function( + invalidate<aa> +), +require<profile-summary>, +cgscc( + devirt<4>( + inline<only-mandatory>, + inline, + function-attrs<skip-non-recursive>, + argpromotion, + function<eager-inv;no-rerun>( + early-cse<memssa>, + speculative-execution, + jump-threading, + correlated-propagation, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info>, + aggressive-instcombine, + constraint-elimination, + libcalls-shrinkwrap, + tailcallelim, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + reassociate, + loop-mssa( + loop-instsimplify, + loop-simplifycfg, + licm<no-allowspeculation>, + loop-rotate<header-duplication;no-prepare-for-lto>, + licm<allowspeculation>, + simple-loop-unswitch<nontrivial;trivial> + ), + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info>, + loop( + loop-idiom, + indvars, + loop-deletion, + loop-unroll-full + ), + vector-combine, + mldst-motion<no-split-footer-bb>, + gvn<>, + sccp, + bdce, + instcombine<max-iterations=1000;no-use-loop-info>, + jump-threading, + correlated-propagation, + adce, + memcpyopt, + dse, + move-auto-init, + loop-mssa( + licm<allowspeculation> + ), + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>, + instcombine<max-iterations=1000;no-use-loop-info> + ), + function-attrs, + function( + require<should-not-run-function-passes> + ), + ) +), +deadargelim, +globalopt, +globaldce, +elim-avail-extern, +rpo-function-attrs, +recompute-globalsaa, +function<eager-inv>( + float2int, + lower-constant-intrinsics, + chr, + loop( + loop-rotate<header-duplication;no-prepare-for-lto>, + loop-deletion + ), + loop-distribute, + inject-tli-mappings, + loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>, + loop-load-elim, + instcombine<max-iterations=1000;no-use-loop-info>, + simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>, + slp-vectorizer, + vector-combine, + instcombine<max-iterations=1000;no-use-loop-info>, + loop-unroll<O3>, + transform-warning, + instcombine<max-iterations=1000;no-use-loop-info>, + loop-mssa( + licm<allowspeculation> + ), + alignment-from-assumptions, + loop-sink, + instsimplify, + div-rem-pairs, + tailcallelim, + simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch> +), +globaldce, +constmerge, +cg-profile, +rel-lookup-table-converter, +function( + annotation-remarks +), +verify +)"); break; } @@ -1508,6 +1905,19 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) { } passes_str = gb_string_appendc(passes_str, passes[i]); } + for (isize i = 0; i < gb_string_length(passes_str); /**/) { + switch (passes_str[i]) { + case ' ': + case '\n': + case '\t': + gb_memmove(&passes_str[i], &passes_str[i+1], gb_string_length(passes_str)-i); + GB_STRING_HEADER(passes_str)->length -= 1; + continue; + default: + i += 1; + break; + } + } LLVMErrorRef llvm_err = LLVMRunPasses(wd->m->mod, passes_str, wd->target_machine, pb_options); @@ -2247,7 +2657,9 @@ gb_internal bool lb_generate_code(lbGenerator *gen) { lb_add_entity(m, lb_global_type_info_data_entity, value); if (LB_USE_GIANT_PACKED_STRUCT) { - lb_make_global_private_const(g); + LLVMSetLinkage(g, LLVMPrivateLinkage); + LLVMSetUnnamedAddress(g, LLVMGlobalUnnamedAddr); + LLVMSetGlobalConstant(g, /*true*/false); } } { // Type info member buffer diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index a16b2293c..7584df3ee 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -94,6 +94,9 @@ gb_internal LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) { LLVMTypeKind kind = LLVMGetTypeKind(dst); switch (kind) { case LLVMPointerTypeKind: + if (LB_USE_NEW_PASS_SYSTEM) { + return val; + } return LLVMConstPointerCast(val, dst); case LLVMStructTypeKind: // GB_PANIC("%s -> %s", LLVMPrintValueToString(val), LLVMPrintTypeToString(dst)); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 0f0df7ca5..fdcf94f29 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -962,8 +962,12 @@ gb_internal bool lb_is_type_proc_recursive(Type *t) { gb_internal void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { GB_ASSERT(value.value != nullptr); - Type *a = type_deref(ptr.type); + if (LLVMIsUndef(value.value)) { + return; + } + + Type *a = type_deref(ptr.type); if (LLVMIsNull(value.value)) { LLVMTypeRef src_t = llvm_addr_type(p->module, ptr); if (is_type_proc(a)) { diff --git a/src/llvm_backend_opt.cpp b/src/llvm_backend_opt.cpp index 4424bde7c..2e03b7974 100644 --- a/src/llvm_backend_opt.cpp +++ b/src/llvm_backend_opt.cpp @@ -322,7 +322,11 @@ gb_internal void lb_run_remove_dead_instruction_pass(lbProcedure *p) { // NOTE(bill): Explicit instructions are set here because some instructions could have side effects switch (LLVMGetInstructionOpcode(curr_instr)) { // case LLVMAlloca: - + case LLVMLoad: + if (LLVMGetVolatile(curr_instr)) { + break; + } + /*fallthrough*/ case LLVMFNeg: case LLVMAdd: case LLVMFAdd: @@ -342,7 +346,6 @@ gb_internal void lb_run_remove_dead_instruction_pass(lbProcedure *p) { case LLVMAnd: case LLVMOr: case LLVMXor: - case LLVMLoad: case LLVMGetElementPtr: case LLVMTrunc: case LLVMZExt: diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index ba920c042..f64cbd52a 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -2769,7 +2769,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu { GB_ASSERT(arg_count <= 7); - char asm_string_default[] = "int $0x80"; + char asm_string_default[] = "int $$0x80"; char *asm_string = asm_string_default; gbString constraints = gb_string_make(heap_allocator(), "={eax}"); diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp index a78c0eacd..02dad2a3a 100644 --- a/src/llvm_backend_type.cpp +++ b/src/llvm_backend_type.cpp @@ -175,7 +175,8 @@ gb_internal lbValue lb_type_info_member_tags_offset(lbModule *m, isize count, i6 return offset; } -enum {LB_USE_GIANT_PACKED_STRUCT = LB_USE_NEW_PASS_SYSTEM}; +// enum {LB_USE_GIANT_PACKED_STRUCT = LB_USE_NEW_PASS_SYSTEM}; +enum {LB_USE_GIANT_PACKED_STRUCT = 0}; gb_internal LLVMTypeRef lb_setup_type_info_data_internal_type(lbModule *m, isize max_type_info_count) { if (!LB_USE_GIANT_PACKED_STRUCT) { @@ -269,7 +270,7 @@ gb_internal LLVMTypeRef lb_setup_type_info_data_internal_type(lbModule *m, isize return LLVMStructType(element_types, cast(unsigned)max_type_info_count, true); } -gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 global_type_info_data_entity_count) { // NOTE(bill): Setup type_info data +gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 global_type_info_data_entity_count, lbProcedure *p) { // NOTE(bill): Setup type_info data CheckerInfo *info = m->info; // Useful types @@ -286,7 +287,6 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl defer (gb_free(heap_allocator(), entries_handled.data)); entries_handled[0] = true; - LLVMValueRef giant_struct = lb_global_type_info_data_ptr(m).value; LLVMTypeRef giant_struct_type = LLVMGlobalGetValueType(giant_struct); GB_ASSERT(LLVMGetTypeKind(giant_struct_type) == LLVMStructTypeKind); @@ -320,6 +320,30 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl type_info_allocate_values(lb_global_type_info_member_usings); type_info_allocate_values(lb_global_type_info_member_tags); + + i64 const type_info_struct_size = type_size_of(t_type_info); + LLVMTypeRef llvm_u8 = lb_type(m, t_u8); + LLVMTypeRef llvm_int = lb_type(m, t_int); + // LLVMTypeRef llvm_type_info_ptr = lb_type(m, t_type_info_ptr); + + auto const get_type_info_ptr = [&](lbModule *m, Type *type) -> LLVMValueRef { + type = default_type(type); + + isize index = lb_type_info_index(m->info, type); + GB_ASSERT(index >= 0); + + u64 offset = cast(u64)(index * type_info_struct_size); + + LLVMValueRef indices[1] = { + LLVMConstInt(llvm_int, offset, false) + }; + + // LLVMValueRef ptr = LLVMConstInBoundsGEP2(llvm_u8, giant_struct, indices, gb_count_of(indices)); + LLVMValueRef ptr = LLVMConstGEP2(llvm_u8, giant_struct, indices, gb_count_of(indices)); + return ptr; + // return LLVMConstPointerCast(ptr, llvm_type_info_ptr); + }; + for_array(type_info_type_index, info->type_info_types) { Type *t = info->type_info_types[type_info_type_index]; if (t == nullptr || t == t_invalid) { @@ -394,7 +418,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl LLVMValueRef vals[4] = { lb_const_string(m, t->Named.type_name->token.string).value, - lb_type_info(m, t->Named.base).value, + get_type_info_ptr(m, t->Named.base), pkg_name, loc.value }; @@ -541,10 +565,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl case Type_Pointer: { tag_type = t_type_info_pointer; - lbValue gep = lb_type_info(m, t->Pointer.elem); - LLVMValueRef vals[1] = { - gep.value, + get_type_info_ptr(m, t->Pointer.elem), }; @@ -553,10 +575,9 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl } case Type_MultiPointer: { tag_type = t_type_info_multi_pointer; - lbValue gep = lb_type_info(m, t->MultiPointer.elem); LLVMValueRef vals[1] = { - gep.value, + get_type_info_ptr(m, t->MultiPointer.elem), }; variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); @@ -564,10 +585,9 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl } case Type_SoaPointer: { tag_type = t_type_info_soa_pointer; - lbValue gep = lb_type_info(m, t->SoaPointer.elem); LLVMValueRef vals[1] = { - gep.value, + get_type_info_ptr(m, t->SoaPointer.elem), }; variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); @@ -578,7 +598,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl i64 ez = type_size_of(t->Array.elem); LLVMValueRef vals[3] = { - lb_type_info(m, t->Array.elem).value, + get_type_info_ptr(m, t->Array.elem), lb_const_int(m, t_int, ez).value, lb_const_int(m, t_int, t->Array.count).value, }; @@ -590,8 +610,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl tag_type = t_type_info_enumerated_array; LLVMValueRef vals[7] = { - lb_type_info(m, t->EnumeratedArray.elem).value, - lb_type_info(m, t->EnumeratedArray.index).value, + get_type_info_ptr(m, t->EnumeratedArray.elem), + get_type_info_ptr(m, t->EnumeratedArray.index), lb_const_int(m, t_int, type_size_of(t->EnumeratedArray.elem)).value, lb_const_int(m, t_int, t->EnumeratedArray.count).value, @@ -609,7 +629,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl tag_type = t_type_info_dynamic_array; LLVMValueRef vals[2] = { - lb_type_info(m, t->DynamicArray.elem).value, + get_type_info_ptr(m, t->DynamicArray.elem), lb_const_int(m, t_int, type_size_of(t->DynamicArray.elem)).value, }; @@ -620,7 +640,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl tag_type = t_type_info_slice; LLVMValueRef vals[2] = { - lb_type_info(m, t->Slice.elem).value, + get_type_info_ptr(m, t->Slice.elem), lb_const_int(m, t_int, type_size_of(t->Slice.elem)).value, }; @@ -633,10 +653,10 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl LLVMValueRef params = LLVMConstNull(lb_type(m, t_type_info_ptr)); LLVMValueRef results = LLVMConstNull(lb_type(m, t_type_info_ptr)); if (t->Proc.params != nullptr) { - params = lb_type_info(m, t->Proc.params).value; + params = get_type_info_ptr(m, t->Proc.params); } if (t->Proc.results != nullptr) { - results = lb_type_info(m, t->Proc.results).value; + results = get_type_info_ptr(m, t->Proc.results); } LLVMValueRef vals[4] = { @@ -663,7 +683,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl lbValue index = lb_const_int(m, t_int, i); lbValue type_info = lb_const_ptr_offset(m, memory_types, index); - lb_global_type_info_member_types_values[type_offset+i] = lb_type_info(m, f->type).value; + lb_global_type_info_member_types_values[type_offset+i] = get_type_info_ptr(m, f->type); if (f->token.string.len > 0) { lb_global_type_info_member_names_values[name_offset+i] = lb_const_string(m, f->token.string).value; } @@ -692,7 +712,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl LLVMValueRef vals[3] = {}; - vals[0] = lb_type_info(m, t->Enum.base_type).value; + vals[0] = get_type_info_ptr(m, t->Enum.base_type); if (t->Enum.fields.count > 0) { auto fields = t->Enum.fields; lbValue name_array = lb_generate_global_array(m, t_string, fields.count, @@ -744,9 +764,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl for (isize variant_index = 0; variant_index < variant_count; variant_index++) { Type *vt = t->Union.variants[variant_index]; - lbValue tip = lb_type_info(m, vt); - - lb_global_type_info_member_types_values[variant_offset+variant_index] = lb_type_info(m, vt).value; + lb_global_type_info_member_types_values[variant_offset+variant_index] = get_type_info_ptr(m, vt); } lbValue count = lb_const_int(m, t_int, variant_count); @@ -756,7 +774,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl if (tag_size > 0) { i64 tag_offset = align_formula(t->Union.variant_block_size, tag_size); vals[1] = lb_const_int(m, t_uintptr, tag_offset).value; - vals[2] = lb_type_info(m, union_tag_type(t)).value; + vals[2] = get_type_info_ptr(m, union_tag_type(t)); } else { vals[1] = lb_const_int(m, t_uintptr, 0).value; vals[2] = LLVMConstNull(lb_type(m, t_type_info_ptr)); @@ -805,11 +823,11 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl Type *kind_type = get_struct_field_type(tag_type, 10); lbValue soa_kind = lb_const_value(m, kind_type, exact_value_i64(t->Struct.soa_kind)); - lbValue soa_type = lb_type_info(m, t->Struct.soa_elem); + LLVMValueRef soa_type = get_type_info_ptr(m, t->Struct.soa_elem); lbValue soa_len = lb_const_int(m, t_int, t->Struct.soa_count); vals[10] = soa_kind.value; - vals[11] = soa_type.value; + vals[11] = soa_type; vals[12] = soa_len.value; } } @@ -831,7 +849,6 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl type_set_offsets(t); // NOTE(bill): Just incase the offsets have not been set yet for (isize source_index = 0; source_index < count; source_index++) { Entity *f = t->Struct.fields[source_index]; - lbValue tip = lb_type_info(m, f->type); i64 foffset = 0; if (!t->Struct.is_raw_union) { GB_ASSERT(t->Struct.offsets != nullptr); @@ -841,7 +858,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field); - lb_global_type_info_member_types_values[types_offset+source_index] = lb_type_info(m, f->type).value; + lb_global_type_info_member_types_values[types_offset+source_index] = get_type_info_ptr(m, f->type); lb_global_type_info_member_offsets_values[offsets_offset+source_index] = lb_const_int(m, t_uintptr, foffset).value; lb_global_type_info_member_usings_values[usings_offset+source_index] = lb_const_bool(m, t_bool, (f->flags&EntityFlag_Using) != 0).value; @@ -880,8 +897,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl init_map_internal_types(t); LLVMValueRef vals[3] = { - lb_type_info(m, t->Map.key).value, - lb_type_info(m, t->Map.value).value, + get_type_info_ptr(m, t->Map.key), + get_type_info_ptr(m, t->Map.value), lb_gen_map_info_ptr(m, t).value }; @@ -897,13 +914,13 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl LLVMValueRef vals[4] = { - lb_type_info(m, t->BitSet.elem).value, + get_type_info_ptr(m, t->BitSet.elem), LLVMConstNull(lb_type(m, t_type_info_ptr)), lb_const_int(m, t_i64, t->BitSet.lower).value, lb_const_int(m, t_i64, t->BitSet.upper).value, }; if (t->BitSet.underlying != nullptr) { - vals[1] = lb_type_info(m, t->BitSet.underlying).value; + vals[1] = get_type_info_ptr(m, t->BitSet.underlying); } variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); @@ -916,7 +933,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl LLVMValueRef vals[3] = {}; - vals[0] = lb_type_info(m, t->SimdVector.elem).value; + vals[0] = get_type_info_ptr(m, t->SimdVector.elem); vals[1] = lb_const_int(m, t_int, type_size_of(t->SimdVector.elem)).value; vals[2] = lb_const_int(m, t_int, t->SimdVector.count).value; @@ -928,8 +945,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl { tag_type = t_type_info_relative_pointer; LLVMValueRef vals[2] = { - lb_type_info(m, t->RelativePointer.pointer_type).value, - lb_type_info(m, t->RelativePointer.base_integer).value, + get_type_info_ptr(m, t->RelativePointer.pointer_type), + get_type_info_ptr(m, t->RelativePointer.base_integer), }; variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); @@ -940,8 +957,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl { tag_type = t_type_info_relative_multi_pointer; LLVMValueRef vals[2] = { - lb_type_info(m, t->RelativeMultiPointer.pointer_type).value, - lb_type_info(m, t->RelativeMultiPointer.base_integer).value, + get_type_info_ptr(m, t->RelativeMultiPointer.pointer_type), + get_type_info_ptr(m, t->RelativeMultiPointer.base_integer), }; variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); @@ -954,7 +971,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl i64 ez = type_size_of(t->Matrix.elem); LLVMValueRef vals[5] = { - lb_type_info(m, t->Matrix.elem).value, + get_type_info_ptr(m, t->Matrix.elem), lb_const_int(m, t_int, ez).value, lb_const_int(m, t_int, matrix_type_stride_in_elems(t)).value, lb_const_int(m, t_int, t->Matrix.row_count).value, @@ -1037,7 +1054,7 @@ gb_internal void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup } if (LB_USE_GIANT_PACKED_STRUCT) { - lb_setup_type_info_data_giant_packed_struct(m, global_type_info_data_entity_count); + lb_setup_type_info_data_giant_packed_struct(m, global_type_info_data_entity_count, p); return; } diff --git a/src/tilde_stmt.cpp b/src/tilde_stmt.cpp index f45dda0bc..1a7dcce4d 100644 --- a/src/tilde_stmt.cpp +++ b/src/tilde_stmt.cpp @@ -1032,22 +1032,22 @@ gb_internal void cg_build_assignment(cgProcedure *p, Array<cgAddr> const &lvals, continue; } - Type *type = cg_addr_type(lval); + Type *type = cg_addr_type(lval); if (!cg_addr_is_empty(lval)) { GB_ASSERT_MSG(are_types_identical(init.type, type), "%s = %s", type_to_string(init.type), type_to_string(type)); } if (init.kind == cgValue_Addr && !cg_addr_is_empty(lval)) { - // NOTE(bill): This is needed for certain constructs such as this: - // a, b = b, a - // NOTE(bill): This is a bodge and not necessarily a good way of doing things whatsoever - TB_CharUnits size = cast(TB_CharUnits)type_size_of(type); - TB_CharUnits align = cast(TB_CharUnits)type_align_of(type); - TB_Node *copy = tb_inst_local(p->func, size, align); - tb_inst_memcpy(p->func, copy, init.node, tb_inst_uint(p->func, TB_TYPE_INT, size), align); - // use the copy instead - init.node = copy; + // NOTE(bill): This is needed for certain constructs such as this: + // a, b = b, a + // NOTE(bill): This is a bodge and not necessarily a good way of doing things whatsoever + TB_CharUnits size = cast(TB_CharUnits)type_size_of(type); + TB_CharUnits align = cast(TB_CharUnits)type_align_of(type); + TB_Node *copy = tb_inst_local(p->func, size, align); + tb_inst_memcpy(p->func, copy, init.node, tb_inst_uint(p->func, TB_TYPE_INT, size), align); + // use the copy instead + init.node = copy; } inits[i] = init; } |