code wiki / (root) / nx_ir.nx

nx_ir.nx

buildroot/runtime/nx_ir.nx

76588 B1804 linesdepth 3pulls 5 transitivereach 281 importersview sourcekind librarytopic ir
docsdependenciesstructsconstsfunctions

about

ir.nx -- nxc2's SSA IR, ported to NishiLang. Mirrors ir.c: Type, Value, Instr, BasicBlock, Function, Module. Uses fixed-capacity arena pools instead of per-object malloc -- simple, fast, and no free path needed for a run-once compiler. Layout choices: * Each entity is a struct allocated in a dedicated pool (big up-front arena, indexed by a small int id). * Instructions are linked into their block's doubly-linked list. * Values carry their type as a pointer to a shared Type table. * No TypeTable interning yet -- each call to ir_type_i64 returns the same shared Type pointer. Scope this turn: enough to emit a small function body (consts, binops, returns, branches). Covers the opcodes the fib and const benches need. Extending to the full opset is mechanical. Opcode/TypeKind/ValueKind integer assignments live in types.nx comments and are reproduced in callers that actually emit them.

dependencies 4 imports · 92 importers

nx_types.nx nx_syscalls.nx nx_assert.nx nx_linemap.nx nx_ir.nx _offc_probe_callchain.nx _offc_probe_irbuild.nx _offc_probe_irfn.nx _offc_probe_module.nx _offc_regalloc_min.nx end2end_test.nx ir.nx nx_bck_elide.nx nx_cap_detect_ir_candidate_t278.nx nx_compile_field_candidate_t280.nx

diagram shows first 10 each side; +0 more imports, +82 more importers in the complete lists below.

imports: nx_types.nxnx_syscalls.nxnx_assert.nxnx_linemap.nx

imported by: _offc_probe_callchain.nx_offc_probe_irbuild.nx_offc_probe_irfn.nx_offc_probe_module.nx_offc_regalloc_min.nxend2end_test.nxir.nxnx_bck_elide.nxnx_cap_detect_ir_candidate_t278.nxnx_compile_field_candidate_t280.nxnx_compile_wat.nxnx_compile_wat_call_operands_t143.nxnx_compile_wat_scalararm.nxnx_compile_x86.nxnx_dom_fn.nxnx_dom_oracle_gate.nxnx_ir_validate.nxnx_lang_struct.nxnx_lsp.nxnx_main.nxnx_nxc.nxnx_operand_layout_probe_t143.nxnx_opt.nxnx_opt_eqsat_pass.nxnx_parse.nxnx_parse_field_candidate_t280.nxnx_quality_grade_daemon.nxnx_quality_grade_quad.nxnx_quality_grade_self.nxnx_quality_grade_septagon.nxnx_regalloc.nxnx_regalloc_liveness_diag.nxnx_regalloc_soundness_test.nxnx_riscv.nxnx_rv64_atomic_gate.nxnx_smoke_nxc_pipeline.nxnx_smoke_nxc_pipeline10.nxnx_smoke_nxc_pipeline11.nxnx_smoke_nxc_pipeline12.nxnx_smoke_nxc_pipeline13.nxnx_smoke_nxc_pipeline14.nxnx_smoke_nxc_pipeline15.nxnx_smoke_nxc_pipeline2.nxnx_smoke_nxc_pipeline3.nxnx_smoke_nxc_pipeline4.nxnx_smoke_nxc_pipeline5.nxnx_smoke_nxc_pipeline7.nxnx_smoke_nxc_pipeline8.nxnx_smoke_nxc_pipeline9.nxnx_smoke_nxc_tilde.nxnx_smoke_regalloc_min.nxnx_smoke_regalloc_min2.nxnx_smoke_regalloc_min3.nxnx_smoke_regalloc_min4.nxnx_smoke_regalloc_min5.nxnx_smoke_regalloc_min6.nxnx_smoke_regalloc_min7.nxnx_smoke_regalloc_step.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nxnx_wasm.nxnx_wasm_call_operands_t143.nxnx_wasm_data.nxnx_wasm_scalararm.nxnx_wgsl.nxnx_wgsl_authored_t55.nxnx_wgsl_before_front_t217.nxnx_wgsl_canonical_skin_t140.nxnx_wgsl_cast_control_t181.nxnx_wgsl_cast_lbs_t181.nxnx_wgsl_cast_material_t181.nxnx_wgsl_cloud_transport_t155.nxnx_wgsl_cumulus_release_t161.nxnx_wgsl_cumulus_t156.nxnx_wgsl_depth_candidate_t192.nxnx_wgsl_eye_t138.nxnx_wgsl_face_mask_t163.nxnx_wgsl_front_candidate_t217.nxnx_wgsl_inspection_t165.nxnx_wgsl_sand_baseline_t137.nxnx_wgsl_sand_private_t137.nxnx_wgsl_scene_light_candidate_t364.nxnx_wgsl_skin_t138.nxnx_wgsl_sky_light_t154.nxnx_wgsl_sky_private_20260910.nxnx_wgsl_sky_review_t154.nxnx_wgsl_static_t335.nxnx_wgsl_world_depth_t195.nxnx_x86_64_ctx_test.nxnx_x86_64_module_test.nxregalloc_evict_test.nxregalloc_test.nx

structs

none

consts

1514const NX_IR_MODULE_POOL_SLOTS: i64 = 4096

functions

68func alloc_type(kind: i64, size: i64, align: i64) -> *Type {
95func alloc_type_s(kind: i64, size: i64, align: i64) -> *Type {
called by 2: parse_typeparse_type calls 1: alloc_type
130func ir_type_vec(lane: *Type, lane_count: i64) -> *Type {
calls 1: alloc_type
141func ir_type_vec_lane(t: *Type) -> *Type {
149func ir_type_vec_lanes(t: *Type) -> i64 {
155func ir_type_struct_new(name_bytes: *u8, name_len: i64) -> *Type {
169func ir_type_struct_add_field(t: *Type, name_bytes: *u8, name_len: i64,
184func ir_type_struct_find_field(t: *Type, name_bytes: *u8, name_len: i64) -> *StructField {
203func ir_type_void() -> *Type { return alloc_type(0, 0, 1) }
204func ir_type_bool() -> *Type { return alloc_type(1, 1, 1) }
205func ir_type_i32() -> *Type { return alloc_type(4, 4, 4) }
calls 1: alloc_type
206func ir_type_i64() -> *Type { return alloc_type(5, 8, 8) }
called by 100: mainmainmainmainmainmain+94 calls 1: alloc_type
210func ir_type_f32() -> *Type { return alloc_type(9, 4, 4) }
calls 1: alloc_type
211func ir_type_f64() -> *Type { return alloc_type(10, 8, 8) }
calls 1: alloc_type
235func ir_function_new(m: *Module, name: *u8, name_len: i64,
307func val_at(f: *Function, id: i64) -> *Value {
313func block_at(f: *Function, id: i64) -> *BasicBlock {
319func alloc_value(f: *Function, kind: i64, ty: *Type) -> i64 {
353func diag_put_dec(v: i64) -> i64 {
367func diag_capacity_named(pool: *u8, name: *u8, name_len: i64, measured: i64, cap: i64, remedy: *u8) -> i64 {
386func ir_block_new(f: *Function) -> *BasicBlock {
414func ir_const_i64(f: *Function, n: i64) -> i64 {
425func ir_param(f: *Function, idx: i64, ty: *Type) -> i64 {
436func append_instr(bb: *BasicBlock, inst: *Instr) -> i64 {
451func alloc_instr(f: *Function, op: i64, ty: *Type) -> *Instr {
489func ir_emit_binop(bb: *BasicBlock, op: i64,
510func ir_emit_unop(bb: *BasicBlock, op: i64, a: i64, ret_ty: *Type) -> i64 {
530func ir_emit_atomic_load_i64(bb: *BasicBlock, addr: i64, mo: i64) -> i64 {
544func ir_emit_atomic_store_i64(bb: *BasicBlock, addr: i64, val: i64, mo: i64) -> i64 {
558func ir_emit_adc_acc(bb: *BasicBlock, acc_ptr: i64, lo: i64, hi: i64) -> i64 {
569func ir_emit_q8rowdot(bb: *BasicBlock, qrow: i64, arow: i64, nblk: i64) -> i64 {
584func ir_emit_i8fma32(bb: *BasicBlock, a: i64, b: i64, d: i64, acc: i64) -> i64 {
600func ir_emit_atomic_cas_i64(bb: *BasicBlock, addr: i64, exp: i64, newv: i64, mo: i64) -> i64 {
616func ir_emit_atomic_faa_i64(bb: *BasicBlock, addr: i64, delta: i64, mo: i64) -> i64 {
631func ir_emit_atomic_fence(bb: *BasicBlock, mo: i64) -> i64 {
641func ir_emit_thread_clone(bb: *BasicBlock, stack_top: i64, entry_fn: i64, ctx: i64) -> i64 {
665func ir_bb_sealed(bb: *BasicBlock) -> i64 {
676func ir_emit_return(bb: *BasicBlock, v: i64) -> i64 {
692func ir_emit_wfi(bb: *BasicBlock) -> i64 {
702func ir_emit_csr_read(bb: *BasicBlock, csr_num: i64) -> i64 {
717func ir_emit_csr_write(bb: *BasicBlock, csr_num: i64, val: i64) -> i64 {
728func ir_emit_fence(bb: *BasicBlock) -> i64 {
739func ir_emit_mret(bb: *BasicBlock) -> i64 {
751func ir_emit_syscall(bb: *BasicBlock, args: *i64, n_args: i64) -> i64 {
775func ir_emit_f32_binop(bb: *BasicBlock, op: i64, a: i64, b: i64) -> i64 {
790func ir_emit_f32_unop(bb: *BasicBlock, op: i64, a: i64) -> i64 {
806func ir_emit_f64_unop(bb: *BasicBlock, op: i64, a: i64) -> i64 {
820func ir_emit_f32x8_fma(bb: *BasicBlock, acc: i64, a: i64, b: i64) -> i64 {
836func ir_emit_i16dot(bb: *BasicBlock, a: i64, b: i64, n: i64) -> i64 {
851func ir_emit_q8blkdot(bb: *BasicBlock, a: i64, b: i64) -> i64 {
865func ir_emit_i16x16_madd(bb: *BasicBlock, acc: i64, a: i64, b: i64) -> i64 {
881func ir_emit_q5unpack32(bb: *BasicBlock, qhqs: i64, out: i64, consts: i64) -> i64 {
898func ir_emit_q4kunpack32s(bb: *BasicBlock, qs: i64, out: i64, scpack: i64) -> i64 {
915func ir_emit_q4ksbdot(bb: *BasicBlock, sb: i64, col: i64, scpre: i64, out: i64) -> i64 {
931func ir_emit_sha256_ni_block(bb: *BasicBlock, state: i64, block: i64, k: i64) -> i64 {
949func ir_emit_mul256_wide(bb: *BasicBlock, dst: i64, a: i64, b: i64) -> i64 {
969func ir_emit_simd_vdot_i16_x16(bb: *BasicBlock, a: i64, b: i64) -> i64 {
984func ir_emit_simd_vreduce_min_i16_x16(bb: *BasicBlock, p: i64) -> i64 {
996func ir_emit_simd_vreduce_max_i16_x16(bb: *BasicBlock, p: i64) -> i64 {
1010func ir_emit_simd_vsadd_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1025func ir_emit_simd_vssub_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1037func ir_emit_simd_vsaddu_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1049func ir_emit_simd_vssubu_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1062func ir_emit_simd_vmin_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1072func ir_emit_simd_vmax_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1082func ir_emit_simd_vadd_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1092func ir_emit_simd_vsub_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1102func ir_emit_simd_vmul_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1114func ir_emit_simd_vsll_i16_x16(bb: *BasicBlock, a: i64, count: i64, out: i64) -> i64 {
1124func ir_emit_simd_vsrl_i16_x16(bb: *BasicBlock, a: i64, count: i64, out: i64) -> i64 {
1134func ir_emit_simd_vsra_i16_x16(bb: *BasicBlock, a: i64, count: i64, out: i64) -> i64 {
1145func ir_emit_simd_vreduce_sum_i16_x16(bb: *BasicBlock, p: i64) -> i64 {
1156func ir_emit_simd_vbroadcast_i16_x16(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1169func ir_emit_simd_vadd_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1179func ir_emit_simd_vsub_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1189func ir_emit_simd_vsadd_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1199func ir_emit_simd_vssub_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1209func ir_emit_simd_vreduce_sum_i8_x32(bb: *BasicBlock, p: i64) -> i64 {
1219func ir_emit_simd_vbroadcast_i8_x32(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1230func ir_emit_simd_vadd_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1240func ir_emit_simd_vsub_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1250func ir_emit_simd_vmul_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1260func ir_emit_simd_vsadd_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1270func ir_emit_simd_vssub_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1280func ir_emit_simd_vreduce_sum_i32_x8(bb: *BasicBlock, p: i64) -> i64 {
1290func ir_emit_simd_vbroadcast_i32_x8(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1301func ir_emit_simd_vadd_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1310func ir_emit_simd_vsub_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1319func ir_emit_simd_vmul_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1328func ir_emit_simd_vsadd_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1337func ir_emit_simd_vssub_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1346func ir_emit_simd_vreduce_sum_i64_x4(bb: *BasicBlock, p: i64) -> i64 {
1355func ir_emit_simd_vbroadcast_i64_x4(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1370func ir_move_instr_before(anchor: *Instr, movee: *Instr) -> i64 {
called by 1: inl_clone_instr
1397func ir_emit_gep(bb: *BasicBlock, base: i64, offset: i64,
1418func ir_emit_call(bb: *BasicBlock, callee: *Function,
1462func ir_emit_call_indirect(bb: *BasicBlock, callee_val: i64, ret_ty: *Type, args: *i64, n_args: i64) -> i64 {
1516func ir_module_new(name_bytes: *u8) -> *Module {
called by 1: main calls 1: sys_mmap
1547func ir_add_global_bss(m: *Module, name_bytes: *u8, name_len: i64,
1581func ir_add_global_data(m: *Module, name_bytes: *u8, name_len: i64,
1617func ir_add_global_string(m: *Module, bytes: *u8, len: i64) -> i64 {
1650func ir_global_value(f: *Function, gid: i64, ty: *Type) -> i64 {
1660func ir_func_addr_value(f: *Function, fn: *Function, ty: *Type) -> i64 {
1669func find_function(m: *Module, name: *u8, name_len: i64) -> *Function {
1692func ir_emit_br(bb: *BasicBlock, target: *BasicBlock) -> i64 {
1717func ir_emit_br_cond(bb: *BasicBlock, cond: i64,
1752func ir_emit_alloca(bb: *BasicBlock, elem_ty: *Type) -> i64 {
1769func ir_emit_load(bb: *BasicBlock, addr: i64, load_ty: *Type) -> i64 {
1791func ir_emit_store(bb: *BasicBlock, addr: i64, val: i64, ty: *Type) -> i64 {