code wiki / (root) / nx_opt.nx

nx_opt.nx

buildroot/runtime/nx_opt.nx

178367 B4024 linesdepth 8pulls 16 transitivereach 195 importersview sourcekind librarytopic opt
docsdependenciesstructsconstsfunctions

about

opt.nx -- first slice of the optimizer, in NishiLang. Three passes, mirroring opt.c: * opt_const_fold -- binops whose operands are both CONST_INT become CONST_INT themselves. * opt_simplify -- peephole identities (x+0=x, x*1=x, etc.) * opt_dce -- pure unused instructions are unlinked. Uses the same Type/Value/Instr/BasicBlock/Function layout as runtime/ir.nx. To stay self-contained without a module system, the struct types are redeclared here identically; a real import step in a future turn deduplicates them.

dependencies 6 imports · 49 importers

nx_syscalls.nx nx_types.nx nx_ir.nx nx_dom_fn.nx nx_bck_elide.nx nx_opt_eqsat_pass.nx nx_opt.nx nx_compile_field_candidate_t280.nx nx_compile_wat.nx nx_compile_wat_call_operands_t143. nx_compile_wat_scalararm.nx nx_compile_x86.nx nx_dom_oracle_gate.nx nx_main.nx nx_nxc.nx nx_opt_eqsat_oracle_gate.nx nx_opt_eqsat_pass_gate.nx

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

imports: nx_syscalls.nxnx_types.nxnx_ir.nxnx_dom_fn.nxnx_bck_elide.nxnx_opt_eqsat_pass.nx

imported by: nx_compile_field_candidate_t280.nxnx_compile_wat.nxnx_compile_wat_call_operands_t143.nxnx_compile_wat_scalararm.nxnx_compile_x86.nxnx_dom_oracle_gate.nxnx_main.nxnx_nxc.nxnx_opt_eqsat_oracle_gate.nxnx_opt_eqsat_pass_gate.nxnx_rv64_atomic_gate.nxnx_smoke_nxc_pipeline.nxnx_smoke_nxc_pipeline10.nxnx_smoke_nxc_pipeline12.nxnx_smoke_nxc_pipeline13.nxnx_smoke_nxc_pipeline14.nxnx_smoke_nxc_pipeline15.nxnx_smoke_nxc_pipeline2.nxnx_smoke_nxc_pipeline7.nxnx_smoke_nxc_pipeline8.nxnx_smoke_nxc_pipeline9.nxnx_smoke_nxc_tilde.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.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.nxopt.nx

structs

3286struct VraResult

consts

334const INL_MAX_BODY_INSTRS: i64 = 24
939const OPT_LOAD_FWD_MAX_WALK: i64 = 64
962const OPT_LOAD_FWD_CROSS_BLOCK: i64 = 0
2148const CSE_TABLE_CAP: i64 = 256
2466const LICM_MAX_BLOCKS: i64 = 4096
2590const LICM_HOIST_LIVE: i64 = 1
2594const LICM_G9_LOAD_HOIST: i64 = 1
2598const LICM_CONSERVATIVE: i64 = 0
2603const NEGCTL_SKIP_PARENT_REBUILD: i64 = 0
3647const DSE_MAX_TRACKED: i64 = 256

functions

47func fold_binop(op: i64, a: i64, b: i64, ok: *i64) -> i64
called by 1: opt_const_fold
97func opt_const_fold(f: *Function) -> i64
151func is_const_val(f: *Function, id: i64, want: i64) -> i64
called by 1: opt_simplify calls 1: val_at
158func rewrite_to_copy(inst: *Instr, src_id: i64) -> i64
166func make_result_zero(f: *Function, inst: *Instr) -> i64
called by 2: opt_simplifyopt_compare_fold calls 1: val_at
196func can_inline(callee: *Function) -> i64;
called by 1: opt_inline_module
197func inline_call(caller: *Function, bb: *BasicBlock,
called by 1: opt_inline_module
203func inl_remap(table: *i64, id: i64, cap: i64) -> i64
220func inl_snapshot_block(cb: *BasicBlock, snap: *i64) -> i64
called by 1: inline_call
231func inl_clone_instr(caller: *Function, bb: *BasicBlock, call_inst: *Instr,
261func inl_clone_all(caller: *Function, bb: *BasicBlock, call_inst: *Instr,
279func opt_inline_module(m: *Module) -> i64
349func inl_op_safe(op: i64) -> i64
called by 1: can_inline
374func can_inline(callee: *Function) -> i64
398func inline_call(caller: *Function, bb: *BasicBlock,
517func opt_gvn_block(f: *Function) -> i64
630func opt_sccp_branches(f: *Function) -> i64
called by 1: opt_run calls 2: block_atval_at
686func opt_mem2reg_simple(f: *Function) -> i64
called by 1: opt_run calls 2: block_atrewrite_to_copy
805func opt_alloca_const(f: *Function) -> i64
964func opt_load_forward(f: *Function) -> i64
1079func const_one(f: *Function) -> i64;
1081func opt_simplify(f: *Function) -> i64
1164func const_one(f: *Function) -> i64
1195func op_is_pure(op: i64) -> i64
called by 1: opt_dce
1212func mark_used(f: *Function, used: *u8) -> i64
called by 1: opt_dce calls 1: block_at
1279func opt_dce(f: *Function) -> i64
1320func comptime_eval_binop(op: i64, a: i64, b: i64) -> i64
1388func opt_module_const_return(m: *Module) -> i64
1551func opt_module_dce_mark(m: *Module, live: *u8) -> i64
1659func opt_sweep_unreachable_function(f: *Function) -> i64
called by 1: opt_run calls 2: sys_mmapblock_at
1861func opt_copyprop(f: *Function) -> i64
called by 1: opt_run calls 3: sys_mmapblock_atval_at
1941func if_br_cond_then_1_else_n(inst: *Instr) -> i64;
called by 1: opt_copy_forward
1942func read_op(inst: *Instr, idx: i64) -> i64;
1943func write_op(inst: *Instr, idx: i64, v: i64) -> i64;
1956func opt_copy_forward(f: *Function) -> i64
2053func if_br_cond_then_1_else_n(inst: *Instr) -> i64
2064func read_op(inst: *Instr, idx: i64) -> i64
2091func write_op(inst: *Instr, idx: i64, v: i64) -> i64
2152func cse_is_candidate(op: i64) -> i64
called by 1: opt_cse
2177func cse_is_commutative(op: i64) -> i64
called by 1: opt_cse
2188func opt_cse(f: *Function) -> i64
2288func skip_bridges(f: *Function, b: *BasicBlock, hops_left: i64) -> *BasicBlock
called by 1: opt_thread_jumps calls 1: block_at
2308func add_succ(bb: *BasicBlock, t: *BasicBlock) -> i64
called by 1: opt_thread_jumps
2314func add_pred(bb: *BasicBlock, p: *BasicBlock) -> i64
called by 1: opt_thread_jumps
2321func opt_thread_jumps(f: *Function) -> i64
2414func licm_is_hoistable(op: i64) -> i64;
called by 1: opt_licm
2420func operands_are_loop_invariant(f: *Function, inst: *Instr,
called by 1: opt_licm
2423func hoist_instr(inst: *Instr, preheader: *BasicBlock) -> i64;
called by 1: opt_licm
2424func mark_loop_body_nx(f: *Function, header: *BasicBlock,
called by 1: opt_licm
2482func cfg_block_by_id(f: *Function, id: i64) -> *BasicBlock
called by 1: cfg_rebuild_edges calls 1: block_at
2492func cfg_add_pred(b: *BasicBlock, p: *BasicBlock) -> i64
called by 1: cfg_rebuild_edges
2500func cfg_rebuild_edges(f: *Function) -> i64
2566func cfg_rebuild_parents(f: *Function) -> i64
2618func opt_bounds_check_elim(f: *Function) -> i64
2638func opt_licm(f: *Function) -> i64
2885func licm_is_hoistable(op: i64) -> i64
2925func opt_opk(inst: *Instr, k: i64) -> i64
2956func licm_alloca_noescape(f: *Function, aid: i64) -> i64
2988func licm_store_dominated_by_header(f: *Function, aid: i64, info: *DomInfoFn,
3009func licm_build_escape_map(f: *Function, esc: *u8) -> i64
called by 1: opt_licm calls 2: block_atopt_opk
3040func licm_build_store_dom_map(f: *Function, info: *DomInfoFn, header: *BasicBlock, stdom: *u8) -> i64
called by 1: opt_licm calls 2: block_atdom_dominates
3064func licm_load_hoistable_memo(f: *Function, inst: *Instr, esc: *u8, stdom: *u8) -> i64
called by 1: opt_licm calls 1: val_at
3080func licm_load_hoistable(f: *Function, inst: *Instr, info: *DomInfoFn,
3108func operands_are_loop_invariant(f: *Function, inst: *Instr,
3184func hoist_instr(inst: *Instr, preheader: *BasicBlock) -> i64
3228func mark_loop_body_nx(f: *Function, header: *BasicBlock,
3292func opt_vra_compute(f: *Function) -> *VraResult;
3293func vra_is_nonneg(vra: *VraResult, v: i64) -> i64;
called by 1: opt_strength_reduce
3295func opt_compare_fold(f: *Function) -> i64
3385func opt_vra_compute(f: *Function) -> *VraResult
3473func vra_is_nonneg(vra: *VraResult, v: i64) -> i64
3510func opt_reassoc(f: *Function) -> i64
3577func opt_block_merge(f: *Function) -> i64
called by 1: opt_run calls 2: block_atunlink
3649func opt_dse(f: *Function) -> i64
called by 1: opt_run calls 3: sys_mmapblock_atunlink
3741func is_pow2(n: i64, shift_out: *i64) -> i64
3754func opt_strength_reduce(f: *Function) -> i64
3855func opt_tail_call(f: *Function) -> i64
called by 1: opt_run calls 1: block_at
3946func opt_run(f: *Function) -> i64