code wiki / (root) / nx_ir.nx

nx_ir.nx

buildroot/runtime/nx_ir.nx

62557 B1582 linesdepth 3pulls 4 transitivereach 100 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 3 imports · 55 importers

nx_types.nx nx_syscalls.nx nx_assert.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_compile_wat.nx nx_compile_x86.nx nx_dom_fn.nx

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

imports: nx_types.nxnx_syscalls.nxnx_assert.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_compile_wat.nxnx_compile_x86.nxnx_dom_fn.nxnx_dom_oracle_gate.nxnx_ir_validate.nxnx_lang_struct.nxnx_main.nxnx_nxc.nxnx_opt.nxnx_parse.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_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_x86_64_ctx_test.nxnx_x86_64_module_test.nxregalloc_evict_test.nxregalloc_test.nx

structs

none

consts

none

functions

64func alloc_type(kind: i64, size: i64, align: i64) -> *Type {
91func alloc_type_s(kind: i64, size: i64, align: i64) -> *Type {
100func ir_type_struct_new(name_bytes: *u8, name_len: i64) -> *Type {
114func ir_type_struct_add_field(t: *Type, name_bytes: *u8, name_len: i64,
129func ir_type_struct_find_field(t: *Type, name_bytes: *u8, name_len: i64) -> *StructField {
148func ir_type_void() -> *Type { return alloc_type(0, 0, 1) }
149func ir_type_bool() -> *Type { return alloc_type(1, 1, 1) }
150func ir_type_i32() -> *Type { return alloc_type(4, 4, 4) }
calls 1: alloc_type
151func ir_type_i64() -> *Type { return alloc_type(5, 8, 8) }
called by 113: mainmainmainmainmainmain+107 calls 1: alloc_type
155func ir_type_f32() -> *Type { return alloc_type(9, 4, 4) }
called by 1: main calls 1: alloc_type
156func ir_type_f64() -> *Type { return alloc_type(10, 8, 8) }
calls 1: alloc_type
180func ir_function_new(m: *Module, name: *u8, name_len: i64,
called by 35: mainmainmainmainmainmain+29 calls 1: sys_mmap
238func val_at(f: *Function, id: i64) -> *Value {
244func block_at(f: *Function, id: i64) -> *BasicBlock {
250func alloc_value(f: *Function, kind: i64, ty: *Type) -> i64 {
270func ir_block_new(f: *Function) -> *BasicBlock {
292func ir_const_i64(f: *Function, n: i64) -> i64 {
303func ir_param(f: *Function, idx: i64, ty: *Type) -> i64 {
314func append_instr(bb: *BasicBlock, inst: *Instr) -> i64 {
329func alloc_instr(f: *Function, op: i64, ty: *Type) -> *Instr {
358func ir_emit_binop(bb: *BasicBlock, op: i64,
379func ir_emit_unop(bb: *BasicBlock, op: i64, a: i64, ret_ty: *Type) -> i64 {
399func ir_emit_atomic_load_i64(bb: *BasicBlock, addr: i64, mo: i64) -> i64 {
413func ir_emit_atomic_store_i64(bb: *BasicBlock, addr: i64, val: i64, mo: i64) -> i64 {
427func ir_emit_adc_acc(bb: *BasicBlock, acc_ptr: i64, lo: i64, hi: i64) -> i64 {
438func ir_emit_q8rowdot(bb: *BasicBlock, qrow: i64, arow: i64, nblk: i64) -> i64 {
453func ir_emit_i8fma32(bb: *BasicBlock, a: i64, b: i64, d: i64, acc: i64) -> i64 {
469func ir_emit_atomic_cas_i64(bb: *BasicBlock, addr: i64, exp: i64, newv: i64, mo: i64) -> i64 {
485func ir_emit_atomic_faa_i64(bb: *BasicBlock, addr: i64, delta: i64, mo: i64) -> i64 {
500func ir_emit_atomic_fence(bb: *BasicBlock, mo: i64) -> i64 {
510func ir_emit_thread_clone(bb: *BasicBlock, stack_top: i64, entry_fn: i64, ctx: i64) -> i64 {
534func ir_bb_sealed(bb: *BasicBlock) -> i64 {
545func ir_emit_return(bb: *BasicBlock, v: i64) -> i64 {
561func ir_emit_wfi(bb: *BasicBlock) -> i64 {
571func ir_emit_csr_read(bb: *BasicBlock, csr_num: i64) -> i64 {
586func ir_emit_csr_write(bb: *BasicBlock, csr_num: i64, val: i64) -> i64 {
597func ir_emit_fence(bb: *BasicBlock) -> i64 {
608func ir_emit_mret(bb: *BasicBlock) -> i64 {
620func ir_emit_syscall(bb: *BasicBlock, args: *i64, n_args: i64) -> i64 {
644func ir_emit_f32_binop(bb: *BasicBlock, op: i64, a: i64, b: i64) -> i64 {
659func ir_emit_f32_unop(bb: *BasicBlock, op: i64, a: i64) -> i64 {
675func ir_emit_f64_unop(bb: *BasicBlock, op: i64, a: i64) -> i64 {
689func ir_emit_f32x8_fma(bb: *BasicBlock, acc: i64, a: i64, b: i64) -> i64 {
704func ir_emit_i16x16_madd(bb: *BasicBlock, acc: i64, a: i64, b: i64) -> i64 {
720func ir_emit_q5unpack32(bb: *BasicBlock, qhqs: i64, out: i64, consts: i64) -> i64 {
735func ir_emit_sha256_ni_block(bb: *BasicBlock, state: i64, block: i64, k: i64) -> i64 {
753func ir_emit_mul256_wide(bb: *BasicBlock, dst: i64, a: i64, b: i64) -> i64 {
773func ir_emit_simd_vdot_i16_x16(bb: *BasicBlock, a: i64, b: i64) -> i64 {
788func ir_emit_simd_vreduce_min_i16_x16(bb: *BasicBlock, p: i64) -> i64 {
800func ir_emit_simd_vreduce_max_i16_x16(bb: *BasicBlock, p: i64) -> i64 {
814func ir_emit_simd_vsadd_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
829func ir_emit_simd_vssub_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
841func ir_emit_simd_vsaddu_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
853func ir_emit_simd_vssubu_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
866func ir_emit_simd_vmin_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
876func ir_emit_simd_vmax_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
886func ir_emit_simd_vadd_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
896func ir_emit_simd_vsub_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
906func ir_emit_simd_vmul_lane_i16_x16(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
918func ir_emit_simd_vsll_i16_x16(bb: *BasicBlock, a: i64, count: i64, out: i64) -> i64 {
928func ir_emit_simd_vsrl_i16_x16(bb: *BasicBlock, a: i64, count: i64, out: i64) -> i64 {
938func ir_emit_simd_vsra_i16_x16(bb: *BasicBlock, a: i64, count: i64, out: i64) -> i64 {
949func ir_emit_simd_vreduce_sum_i16_x16(bb: *BasicBlock, p: i64) -> i64 {
960func ir_emit_simd_vbroadcast_i16_x16(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
973func ir_emit_simd_vadd_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
983func ir_emit_simd_vsub_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
993func ir_emit_simd_vsadd_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1003func ir_emit_simd_vssub_i8_x32(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1013func ir_emit_simd_vreduce_sum_i8_x32(bb: *BasicBlock, p: i64) -> i64 {
1023func ir_emit_simd_vbroadcast_i8_x32(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1034func ir_emit_simd_vadd_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1044func ir_emit_simd_vsub_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1054func ir_emit_simd_vmul_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1064func ir_emit_simd_vsadd_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1074func ir_emit_simd_vssub_i32_x8(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1084func ir_emit_simd_vreduce_sum_i32_x8(bb: *BasicBlock, p: i64) -> i64 {
1094func ir_emit_simd_vbroadcast_i32_x8(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1105func ir_emit_simd_vadd_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1114func ir_emit_simd_vsub_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1123func ir_emit_simd_vmul_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1132func ir_emit_simd_vsadd_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1141func ir_emit_simd_vssub_i64_x4(bb: *BasicBlock, a: i64, b: i64, out: i64) -> i64 {
1150func ir_emit_simd_vreduce_sum_i64_x4(bb: *BasicBlock, p: i64) -> i64 {
1159func ir_emit_simd_vbroadcast_i64_x4(bb: *BasicBlock, scalar: i64, out: i64) -> i64 {
1174func ir_move_instr_before(anchor: *Instr, movee: *Instr) -> i64 {
called by 1: inl_clone_instr
1201func ir_emit_gep(bb: *BasicBlock, base: i64, offset: i64,
1222func ir_emit_call(bb: *BasicBlock, callee: *Function,
1266func ir_emit_call_indirect(bb: *BasicBlock, callee_val: i64, ret_ty: *Type, args: *i64, n_args: i64) -> i64 {
1311func ir_module_new(name_bytes: *u8) -> *Module {
called by 3: mainmainmain calls 1: sys_mmap
1337func ir_add_global_bss(m: *Module, name_bytes: *u8, name_len: i64,
calls 1: nx_assert_lt
1367func ir_add_global_data(m: *Module, name_bytes: *u8, name_len: i64,
1399func ir_add_global_string(m: *Module, bytes: *u8, len: i64) -> i64 {
1428func ir_global_value(f: *Function, gid: i64, ty: *Type) -> i64 {
1438func ir_func_addr_value(f: *Function, fn: *Function, ty: *Type) -> i64 {
1447func find_function(m: *Module, name: *u8, name_len: i64) -> *Function {
1470func ir_emit_br(bb: *BasicBlock, target: *BasicBlock) -> i64 {
1495func ir_emit_br_cond(bb: *BasicBlock, cond: i64,
1530func ir_emit_alloca(bb: *BasicBlock, elem_ty: *Type) -> i64 {
1547func ir_emit_load(bb: *BasicBlock, addr: i64, load_ty: *Type) -> i64 {
1569func ir_emit_store(bb: *BasicBlock, addr: i64, val: i64, ty: *Type) -> i64 {