code wiki / (root) / nx_opt.nx

nx_opt.nx

buildroot/runtime/nx_opt.nx

165533 B3846 linesdepth 5pulls 6 transitivereach 33 importersview sourcekind library
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 4 imports · 19 importers

nx_syscalls.nx nx_types.nx nx_ir.nx nx_dom_fn.nx nx_opt.nx nx_compile_wat.nx nx_compile_x86.nx nx_dom_oracle_gate.nx nx_main.nx nx_nxc.nx nx_smoke_nxc_pipeline.nx nx_smoke_nxc_pipeline10.nx nx_smoke_nxc_pipeline12.nx nx_smoke_nxc_pipeline13.nx nx_smoke_nxc_pipeline14.nx

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

imports: nx_syscalls.nxnx_types.nxnx_ir.nxnx_dom_fn.nx

imported by: nx_compile_wat.nxnx_compile_x86.nxnx_dom_oracle_gate.nxnx_main.nxnx_nxc.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.nxopt.nx

structs

3166struct VraResult

consts

330const INL_MAX_BODY_INSTRS: i64 = 24
935const OPT_LOAD_FWD_MAX_WALK: i64 = 64
958const OPT_LOAD_FWD_CROSS_BLOCK: i64 = 0
2151const CSE_TABLE_CAP: i64 = 256
2469const LICM_MAX_BLOCKS: i64 = 4096
2593const LICM_HOIST_LIVE: i64 = 1
2597const LICM_G9_LOAD_HOIST: i64 = 1
2601const LICM_CONSERVATIVE: i64 = 0
2606const NEGCTL_SKIP_PARENT_REBUILD: i64 = 0
3527const DSE_MAX_TRACKED: i64 = 256

functions

43func fold_binop(op: i64, a: i64, b: i64, ok: *i64) -> i64
called by 1: opt_const_fold
93func opt_const_fold(f: *Function) -> i64
called by 1: opt_run calls 3: block_atval_atfold_binop
147func is_const_val(f: *Function, id: i64, want: i64) -> i64
called by 1: opt_simplify calls 1: val_at
154func rewrite_to_copy(inst: *Instr, src_id: i64) -> i64
162func make_result_zero(f: *Function, inst: *Instr) -> i64
called by 2: opt_simplifyopt_compare_fold calls 1: val_at
192func can_inline(callee: *Function) -> i64;
called by 1: opt_inline_module
193func inline_call(caller: *Function, bb: *BasicBlock,
called by 1: opt_inline_module
199func inl_remap(table: *i64, id: i64, cap: i64) -> i64
216func inl_snapshot_block(cb: *BasicBlock, snap: *i64) -> i64
called by 1: inline_call
227func inl_clone_instr(caller: *Function, bb: *BasicBlock, call_inst: *Instr,
257func inl_clone_all(caller: *Function, bb: *BasicBlock, call_inst: *Instr,
275func opt_inline_module(m: *Module) -> i64
345func inl_op_safe(op: i64) -> i64
called by 1: can_inline
370func can_inline(callee: *Function) -> i64
394func inline_call(caller: *Function, bb: *BasicBlock,
513func opt_gvn_block(f: *Function) -> i64
626func opt_sccp_branches(f: *Function) -> i64
called by 1: opt_run calls 2: block_atval_at
682func opt_mem2reg_simple(f: *Function) -> i64
called by 1: opt_run calls 2: block_atrewrite_to_copy
801func opt_alloca_const(f: *Function) -> i64
960func opt_load_forward(f: *Function) -> i64
1075func const_one(f: *Function) -> i64;
1077func opt_simplify(f: *Function) -> i64
1160func const_one(f: *Function) -> i64
1191func op_is_pure(op: i64) -> i64
called by 1: opt_dce
1208func mark_used(f: *Function, used: *u8) -> i64
called by 1: opt_dce calls 1: block_at
1275func opt_dce(f: *Function) -> i64
1316func comptime_eval_binop(op: i64, a: i64, b: i64) -> i64
1384func opt_module_const_return(m: *Module) -> i64
1532func opt_module_dce(m: *Module) -> i64
1662func opt_sweep_unreachable_function(f: *Function) -> i64
called by 1: opt_run calls 2: sys_mmapblock_at
1864func opt_copyprop(f: *Function) -> i64
called by 1: opt_run calls 3: sys_mmapblock_atval_at
1944func if_br_cond_then_1_else_n(inst: *Instr) -> i64;
called by 1: opt_copy_forward
1945func read_op(inst: *Instr, idx: i64) -> i64;
1946func write_op(inst: *Instr, idx: i64, v: i64) -> i64;
1959func opt_copy_forward(f: *Function) -> i64
2056func if_br_cond_then_1_else_n(inst: *Instr) -> i64
2067func read_op(inst: *Instr, idx: i64) -> i64
2094func write_op(inst: *Instr, idx: i64, v: i64) -> i64
2155func cse_is_candidate(op: i64) -> i64
called by 1: opt_cse
2180func cse_is_commutative(op: i64) -> i64
called by 1: opt_cse
2191func opt_cse(f: *Function) -> i64
2291func skip_bridges(f: *Function, b: *BasicBlock, hops_left: i64) -> *BasicBlock
called by 1: opt_thread_jumps calls 1: block_at
2311func add_succ(bb: *BasicBlock, t: *BasicBlock) -> i64
called by 1: opt_thread_jumps
2317func add_pred(bb: *BasicBlock, p: *BasicBlock) -> i64
called by 1: opt_thread_jumps
2324func opt_thread_jumps(f: *Function) -> i64
2417func licm_is_hoistable(op: i64) -> i64;
called by 1: opt_licm
2423func operands_are_loop_invariant(f: *Function, inst: *Instr,
called by 1: opt_licm
2426func hoist_instr(inst: *Instr, preheader: *BasicBlock) -> i64;
called by 1: opt_licm
2427func mark_loop_body_nx(f: *Function, header: *BasicBlock,
called by 1: opt_licm
2485func cfg_block_by_id(f: *Function, id: i64) -> *BasicBlock
called by 1: cfg_rebuild_edges calls 1: block_at
2495func cfg_add_pred(b: *BasicBlock, p: *BasicBlock) -> i64
called by 1: cfg_rebuild_edges
2503func cfg_rebuild_edges(f: *Function) -> i64
2569func cfg_rebuild_parents(f: *Function) -> i64
called by 2: opt_load_forwardopt_licm calls 1: block_at
2608func opt_licm(f: *Function) -> i64
2838func licm_is_hoistable(op: i64) -> i64
2878func opt_opk(inst: *Instr, k: i64) -> i64
2909func licm_alloca_noescape(f: *Function, aid: i64) -> i64
2941func licm_store_dominated_by_header(f: *Function, aid: i64, info: *DomInfoFn,
2960func licm_load_hoistable(f: *Function, inst: *Instr, info: *DomInfoFn,
2988func operands_are_loop_invariant(f: *Function, inst: *Instr,
3064func hoist_instr(inst: *Instr, preheader: *BasicBlock) -> i64
3108func mark_loop_body_nx(f: *Function, header: *BasicBlock,
3172func opt_vra_compute(f: *Function) -> *VraResult;
3173func vra_is_nonneg(vra: *VraResult, v: i64) -> i64;
called by 1: opt_strength_reduce
3175func opt_compare_fold(f: *Function) -> i64
3265func opt_vra_compute(f: *Function) -> *VraResult
3353func vra_is_nonneg(vra: *VraResult, v: i64) -> i64
3390func opt_reassoc(f: *Function) -> i64
3457func opt_block_merge(f: *Function) -> i64
called by 1: opt_run calls 2: block_atunlink
3529func opt_dse(f: *Function) -> i64
called by 1: opt_run calls 3: sys_mmapblock_atunlink
3621func is_pow2(n: i64, shift_out: *i64) -> i64
called by 1: opt_strength_reduce
3634func opt_strength_reduce(f: *Function) -> i64
3735func opt_tail_call(f: *Function) -> i64
called by 1: opt_run calls 1: block_at
3775func opt_run(f: *Function) -> i64