nx_opt.nx
buildroot/runtime/nx_opt.nx
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
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
| 3166 | struct VraResult |
consts
| 330 | const INL_MAX_BODY_INSTRS: i64 = 24 |
| 935 | const OPT_LOAD_FWD_MAX_WALK: i64 = 64 |
| 958 | const OPT_LOAD_FWD_CROSS_BLOCK: i64 = 0 |
| 2151 | const CSE_TABLE_CAP: i64 = 256 |
| 2469 | const LICM_MAX_BLOCKS: i64 = 4096 |
| 2593 | const LICM_HOIST_LIVE: i64 = 1 |
| 2597 | const LICM_G9_LOAD_HOIST: i64 = 1 |
| 2601 | const LICM_CONSERVATIVE: i64 = 0 |
| 2606 | const NEGCTL_SKIP_PARENT_REBUILD: i64 = 0 |
| 3527 | const DSE_MAX_TRACKED: i64 = 256 |
functions
| 43 | func fold_binop(op: i64, a: i64, b: i64, ok: *i64) -> i64 called by 1: opt_const_fold |
| 93 | func opt_const_fold(f: *Function) -> i64 |
| 147 | func is_const_val(f: *Function, id: i64, want: i64) -> i64 |
| 154 | func rewrite_to_copy(inst: *Instr, src_id: i64) -> i64 |
| 162 | func make_result_zero(f: *Function, inst: *Instr) -> i64 |
| 192 | func can_inline(callee: *Function) -> i64; called by 1: opt_inline_module |
| 193 | func inline_call(caller: *Function, bb: *BasicBlock, called by 1: opt_inline_module |
| 199 | func inl_remap(table: *i64, id: i64, cap: i64) -> i64 |
| 216 | func inl_snapshot_block(cb: *BasicBlock, snap: *i64) -> i64 called by 1: inline_call |
| 227 | func inl_clone_instr(caller: *Function, bb: *BasicBlock, call_inst: *Instr, |
| 257 | func inl_clone_all(caller: *Function, bb: *BasicBlock, call_inst: *Instr, |
| 275 | func opt_inline_module(m: *Module) -> i64 called by 4: nxc_compilemainnxc_compilenxc_compile calls 5: sys_mmapsys_read_fileblock_atcan_inlineinline_call |
| 345 | func inl_op_safe(op: i64) -> i64 called by 1: can_inline |
| 370 | func can_inline(callee: *Function) -> i64 |
| 394 | func inline_call(caller: *Function, bb: *BasicBlock, |
| 513 | func opt_gvn_block(f: *Function) -> i64 |
| 626 | func opt_sccp_branches(f: *Function) -> i64 |
| 682 | func opt_mem2reg_simple(f: *Function) -> i64 |
| 801 | func opt_alloca_const(f: *Function) -> i64 |
| 960 | func opt_load_forward(f: *Function) -> i64 |
| 1075 | func const_one(f: *Function) -> i64; |
| 1077 | func opt_simplify(f: *Function) -> i64 |
| 1160 | func const_one(f: *Function) -> i64 |
| 1191 | func op_is_pure(op: i64) -> i64 called by 1: opt_dce |
| 1208 | func mark_used(f: *Function, used: *u8) -> i64 |
| 1259 | func unlink(b: *BasicBlock, inst: *Instr) -> i64 |
| 1275 | func opt_dce(f: *Function) -> i64 |
| 1316 | func comptime_eval_binop(op: i64, a: i64, b: i64) -> i64 |
| 1384 | func opt_module_const_return(m: *Module) -> i64 |
| 1532 | func opt_module_dce(m: *Module) -> i64 |
| 1662 | func opt_sweep_unreachable_function(f: *Function) -> i64 |
| 1864 | func opt_copyprop(f: *Function) -> i64 |
| 1944 | func if_br_cond_then_1_else_n(inst: *Instr) -> i64; called by 1: opt_copy_forward |
| 1945 | func read_op(inst: *Instr, idx: i64) -> i64; |
| 1946 | func write_op(inst: *Instr, idx: i64, v: i64) -> i64; |
| 1959 | func opt_copy_forward(f: *Function) -> i64 |
| 2056 | func if_br_cond_then_1_else_n(inst: *Instr) -> i64 |
| 2067 | func read_op(inst: *Instr, idx: i64) -> i64 |
| 2094 | func write_op(inst: *Instr, idx: i64, v: i64) -> i64 |
| 2155 | func cse_is_candidate(op: i64) -> i64 called by 1: opt_cse |
| 2180 | func cse_is_commutative(op: i64) -> i64 called by 1: opt_cse |
| 2191 | func opt_cse(f: *Function) -> i64 |
| 2291 | func skip_bridges(f: *Function, b: *BasicBlock, hops_left: i64) -> *BasicBlock |
| 2311 | func add_succ(bb: *BasicBlock, t: *BasicBlock) -> i64 called by 1: opt_thread_jumps |
| 2317 | func add_pred(bb: *BasicBlock, p: *BasicBlock) -> i64 called by 1: opt_thread_jumps |
| 2324 | func opt_thread_jumps(f: *Function) -> i64 |
| 2417 | func licm_is_hoistable(op: i64) -> i64; called by 1: opt_licm |
| 2423 | func operands_are_loop_invariant(f: *Function, inst: *Instr, called by 1: opt_licm |
| 2426 | func hoist_instr(inst: *Instr, preheader: *BasicBlock) -> i64; called by 1: opt_licm |
| 2427 | func mark_loop_body_nx(f: *Function, header: *BasicBlock, called by 1: opt_licm |
| 2485 | func cfg_block_by_id(f: *Function, id: i64) -> *BasicBlock |
| 2495 | func cfg_add_pred(b: *BasicBlock, p: *BasicBlock) -> i64 called by 1: cfg_rebuild_edges |
| 2503 | func cfg_rebuild_edges(f: *Function) -> i64 |
| 2569 | func cfg_rebuild_parents(f: *Function) -> i64 |
| 2608 | func opt_licm(f: *Function) -> i64 called by 1: opt_run calls 12: cfg_rebuild_edgescfg_rebuild_parentsblock_atsys_mmapdom_compute_fndom_dominates+6 |
| 2838 | func licm_is_hoistable(op: i64) -> i64 |
| 2878 | func opt_opk(inst: *Instr, k: i64) -> i64 called by 1: licm_alloca_noescape |
| 2909 | func licm_alloca_noescape(f: *Function, aid: i64) -> i64 |
| 2941 | func licm_store_dominated_by_header(f: *Function, aid: i64, info: *DomInfoFn, |
| 2960 | func licm_load_hoistable(f: *Function, inst: *Instr, info: *DomInfoFn, |
| 2988 | func operands_are_loop_invariant(f: *Function, inst: *Instr, |
| 3064 | func hoist_instr(inst: *Instr, preheader: *BasicBlock) -> i64 |
| 3108 | func mark_loop_body_nx(f: *Function, header: *BasicBlock, |
| 3172 | func opt_vra_compute(f: *Function) -> *VraResult; |
| 3173 | func vra_is_nonneg(vra: *VraResult, v: i64) -> i64; called by 1: opt_strength_reduce |
| 3175 | func opt_compare_fold(f: *Function) -> i64 |
| 3265 | func opt_vra_compute(f: *Function) -> *VraResult |
| 3353 | func vra_is_nonneg(vra: *VraResult, v: i64) -> i64 |
| 3390 | func opt_reassoc(f: *Function) -> i64 |
| 3457 | func opt_block_merge(f: *Function) -> i64 |
| 3529 | func opt_dse(f: *Function) -> i64 |
| 3621 | func is_pow2(n: i64, shift_out: *i64) -> i64 called by 1: opt_strength_reduce |
| 3634 | func opt_strength_reduce(f: *Function) -> i64 |
| 3735 | func opt_tail_call(f: *Function) -> i64 |
| 3775 | func opt_run(f: *Function) -> i64 called by 30: nxc_compilecompilemainmainmaincompile+24 calls 17: opt_mem2reg_simpleopt_sccp_branchesopt_const_foldopt_copypropopt_copy_forwardopt_cse+11 |