diff --git a/library/init/lean/compiler/default.lean b/library/init/lean/compiler/default.lean index 960e022875..d3436a9fb5 100644 --- a/library/init/lean/compiler/default.lean +++ b/library/init/lean/compiler/default.lean @@ -5,4 +5,6 @@ Authors: Leonardo de Moura -/ prelude import init.lean.compiler.constfolding -import init.lean.compiler.ir init.lean.compiler.pushproj +import init.lean.compiler.ir +import init.lean.compiler.pushproj +import init.lean.compiler.elimdead diff --git a/library/init/lean/compiler/elimdead.lean b/library/init/lean/compiler/elimdead.lean new file mode 100644 index 0000000000..cd6e2eb4d1 --- /dev/null +++ b/library/init/lean/compiler/elimdead.lean @@ -0,0 +1,48 @@ +/- +Copyright (c) 2019 Microsoft Corporation. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Leonardo de Moura +-/ +import init.lean.compiler.ir + +namespace Lean +namespace IR + +partial def reshapeWithoutDeadAux : Array FnBody → FnBody → VarIdxSet → FnBody +| bs b used := + if bs.isEmpty then b + else + let curr := bs.back in + let bs := bs.pop in + let keep (_ : Unit) := + let used := curr.collectFreeVars used in + let b := curr.setBody b in + reshapeWithoutDeadAux bs b used in + let keepIfUsed (vidx : Index) := + if used.contains vidx then keep () + else reshapeWithoutDeadAux bs b used in + match curr with + | FnBody.vdecl x _ _ _ := keepIfUsed x.idx + | FnBody.jdecl j _ _ _ _ := keepIfUsed j.idx + | _ := keep () + +def reshapeWithoutDead (bs : Array FnBody) (term : FnBody) : FnBody := +reshapeWithoutDeadAux bs term term.freeVars + +partial def FnBody.elimDead : FnBody → FnBody +| b := + let (bs, term) := b.flatten in + let term := match term with + | FnBody.case tid x alts := + let alts := alts.hmap $ λ alt, alt.modifyBody $ λ b, FnBody.elimDead b in + FnBody.case tid x alts + | other := other in + reshape bs term + +@[export lean.ir.decl_elim_dead_core] +def Decl.elimDead : Decl → Decl +| (Decl.fdecl f xs t b) := Decl.fdecl f xs t b.elimDead +| other := other + +end IR +end Lean diff --git a/src/stage0/CMakeLists.txt b/src/stage0/CMakeLists.txt index 22ff1b68e0..4e2bb3d458 100644 --- a/src/stage0/CMakeLists.txt +++ b/src/stage0/CMakeLists.txt @@ -1 +1 @@ -add_library (stage0 OBJECT ./init/coe.cpp ./init/control/alternative.cpp ./init/control/applicative.cpp ./init/control/combinators.cpp ./init/control/default.cpp ./init/control/estate.cpp ./init/control/except.cpp ./init/control/functor.cpp ./init/control/id.cpp ./init/control/lift.cpp ./init/control/monad.cpp ./init/control/monadfail.cpp ./init/control/option.cpp ./init/control/reader.cpp ./init/control/state.cpp ./init/core.cpp ./init/data/array/basic.cpp ./init/data/array/default.cpp ./init/data/assoclist.cpp ./init/data/basic.cpp ./init/data/char/basic.cpp ./init/data/char/default.cpp ./init/data/default.cpp ./init/data/dlist.cpp ./init/data/fin/basic.cpp ./init/data/fin/default.cpp ./init/data/hashable.cpp ./init/data/hashmap/basic.cpp ./init/data/hashmap/default.cpp ./init/data/int/basic.cpp ./init/data/int/default.cpp ./init/data/list/basic.cpp ./init/data/list/default.cpp ./init/data/list/instances.cpp ./init/data/nat/basic.cpp ./init/data/nat/bitwise.cpp ./init/data/nat/default.cpp ./init/data/nat/div.cpp ./init/data/option/basic.cpp ./init/data/option/instances.cpp ./init/data/ordering/basic.cpp ./init/data/ordering/default.cpp ./init/data/rbmap/basic.cpp ./init/data/rbmap/default.cpp ./init/data/rbtree/basic.cpp ./init/data/rbtree/default.cpp ./init/data/repr.cpp ./init/data/string/basic.cpp ./init/data/string/default.cpp ./init/data/tostring.cpp ./init/data/uint.cpp ./init/default.cpp ./init/env_ext.cpp ./init/fix.cpp ./init/io.cpp ./init/lean/compiler/constfolding.cpp ./init/lean/compiler/default.cpp ./init/lean/compiler/ir.cpp ./init/lean/compiler/pushproj.cpp ./init/lean/compiler/util.cpp ./init/lean/config.cpp ./init/lean/declaration.cpp ./init/lean/default.cpp ./init/lean/disjoint_set.cpp ./init/lean/elaborator.cpp ./init/lean/expander.cpp ./init/lean/expr.cpp ./init/lean/extern.cpp ./init/lean/format.cpp ./init/lean/frontend.cpp ./init/lean/kvmap.cpp ./init/lean/level.cpp ./init/lean/message.cpp ./init/lean/name.cpp ./init/lean/name_mangling.cpp ./init/lean/options.cpp ./init/lean/parser/basic.cpp ./init/lean/parser/combinators.cpp ./init/lean/parser/command.cpp ./init/lean/parser/declaration.cpp ./init/lean/parser/identifier.cpp ./init/lean/parser/level.cpp ./init/lean/parser/module.cpp ./init/lean/parser/notation.cpp ./init/lean/parser/parsec.cpp ./init/lean/parser/pratt.cpp ./init/lean/parser/rec.cpp ./init/lean/parser/stringliteral.cpp ./init/lean/parser/syntax.cpp ./init/lean/parser/term.cpp ./init/lean/parser/token.cpp ./init/lean/parser/trie.cpp ./init/lean/position.cpp ./init/lean/trace.cpp ./init/lean/util.cpp ./init/platform.cpp ./init/util.cpp ./init/wf.cpp) +add_library (stage0 OBJECT ./init/coe.cpp ./init/control/alternative.cpp ./init/control/applicative.cpp ./init/control/combinators.cpp ./init/control/default.cpp ./init/control/estate.cpp ./init/control/except.cpp ./init/control/functor.cpp ./init/control/id.cpp ./init/control/lift.cpp ./init/control/monad.cpp ./init/control/monadfail.cpp ./init/control/option.cpp ./init/control/reader.cpp ./init/control/state.cpp ./init/core.cpp ./init/data/array/basic.cpp ./init/data/array/default.cpp ./init/data/assoclist.cpp ./init/data/basic.cpp ./init/data/char/basic.cpp ./init/data/char/default.cpp ./init/data/default.cpp ./init/data/dlist.cpp ./init/data/fin/basic.cpp ./init/data/fin/default.cpp ./init/data/hashable.cpp ./init/data/hashmap/basic.cpp ./init/data/hashmap/default.cpp ./init/data/int/basic.cpp ./init/data/int/default.cpp ./init/data/list/basic.cpp ./init/data/list/default.cpp ./init/data/list/instances.cpp ./init/data/nat/basic.cpp ./init/data/nat/bitwise.cpp ./init/data/nat/default.cpp ./init/data/nat/div.cpp ./init/data/option/basic.cpp ./init/data/option/instances.cpp ./init/data/ordering/basic.cpp ./init/data/ordering/default.cpp ./init/data/rbmap/basic.cpp ./init/data/rbmap/default.cpp ./init/data/rbtree/basic.cpp ./init/data/rbtree/default.cpp ./init/data/repr.cpp ./init/data/string/basic.cpp ./init/data/string/default.cpp ./init/data/tostring.cpp ./init/data/uint.cpp ./init/default.cpp ./init/env_ext.cpp ./init/fix.cpp ./init/io.cpp ./init/lean/compiler/constfolding.cpp ./init/lean/compiler/default.cpp ./init/lean/compiler/elimdead.cpp ./init/lean/compiler/ir.cpp ./init/lean/compiler/pushproj.cpp ./init/lean/compiler/util.cpp ./init/lean/config.cpp ./init/lean/declaration.cpp ./init/lean/default.cpp ./init/lean/disjoint_set.cpp ./init/lean/elaborator.cpp ./init/lean/expander.cpp ./init/lean/expr.cpp ./init/lean/extern.cpp ./init/lean/format.cpp ./init/lean/frontend.cpp ./init/lean/kvmap.cpp ./init/lean/level.cpp ./init/lean/message.cpp ./init/lean/name.cpp ./init/lean/name_mangling.cpp ./init/lean/options.cpp ./init/lean/parser/basic.cpp ./init/lean/parser/combinators.cpp ./init/lean/parser/command.cpp ./init/lean/parser/declaration.cpp ./init/lean/parser/identifier.cpp ./init/lean/parser/level.cpp ./init/lean/parser/module.cpp ./init/lean/parser/notation.cpp ./init/lean/parser/parsec.cpp ./init/lean/parser/pratt.cpp ./init/lean/parser/rec.cpp ./init/lean/parser/stringliteral.cpp ./init/lean/parser/syntax.cpp ./init/lean/parser/term.cpp ./init/lean/parser/token.cpp ./init/lean/parser/trie.cpp ./init/lean/position.cpp ./init/lean/trace.cpp ./init/lean/util.cpp ./init/platform.cpp ./init/util.cpp ./init/wf.cpp) diff --git a/src/stage0/init/data/array/basic.cpp b/src/stage0/init/data/array/basic.cpp index 0f5f85ac23..cda32a081f 100644 --- a/src/stage0/init/data/array/basic.cpp +++ b/src/stage0/init/data/array/basic.cpp @@ -18,6 +18,7 @@ obj* l_List_toArrayAux___rarg(obj*, obj*); obj* l_Array_extractAux___main___rarg___boxed(obj*, obj*, obj*, obj*, obj*); obj* l_Array_append(obj*); obj* l_Array_foldlFrom___rarg(obj*, obj*, obj*, obj*); +obj* l_Array_fswapAt___boxed(obj*); obj* l_Array_miterateAux___main___at_Array_append___spec__1___boxed(obj*); obj* l_Array_hmmapAux___main___at_Array_hmapIdx___spec__1(obj*); obj* l_Array_shrink___main___rarg___boxed(obj*, obj*); @@ -57,6 +58,7 @@ obj* l_Array_miterateAux___main___at_Array_foldlFrom___spec__1___boxed(obj*, obj obj* l___private_init_data_array_basic_1__revIterateAux___main___at_Array_revFoldl___spec__1___rarg(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Array_shrink___rarg(obj*, obj*); obj* l_Array_fswap___boxed(obj*, obj*, obj*, obj*); +obj* l_Array_swapAt___boxed(obj*); obj* l_Array_hmmapAux___main___at_Array_hmapIdx___spec__1___rarg(obj*, obj*, obj*, obj*); obj* l_Array_any___boxed(obj*); obj* l_Array_extractAux(obj*); @@ -79,6 +81,7 @@ obj* l_Array_size___boxed(obj*, obj*); obj* l_Array_isEqvAux___main___boxed(obj*); obj* l_List_toArrayAux___main___rarg(obj*, obj*); obj* l_Array_isEqv___rarg___boxed(obj*, obj*, obj*); +obj* l_Array_fswapAt___rarg___boxed(obj*, obj*, obj*); obj* l_Array_mfoldlFrom___rarg(obj*, obj*, obj*, obj*, obj*); uint8 l_Array_anyAux___main___at_Array_all___spec__1___rarg(obj*, obj*, obj*); obj* l_Array_extractAux___rarg(obj*, obj*, obj*, obj*, obj*); @@ -92,6 +95,7 @@ obj* l_Array_mfind(obj*, obj*, obj*); obj* l_Array_mfindAux___main___rarg___lambda__1___boxed(obj*, obj*, obj*, obj*, obj*); obj* l_Array_foldl___rarg___boxed(obj*, obj*, obj*); obj* l_Array_extractAux___rarg___boxed(obj*, obj*, obj*, obj*, obj*); +obj* l_Array_swapAt(obj*); obj* l_Array_hmmapAux___main___at_Array_hmmap___spec__1___rarg(obj*, obj*, obj*, obj*, obj*); obj* l_Array_hmmap(obj*, obj*); obj* l_List_redLength___main(obj*); @@ -149,6 +153,7 @@ obj* l_Array_miterate_u_2082Aux(obj*, obj*, obj*); obj* l_Array_revIterate___boxed(obj*, obj*); obj* l_Array_revFoldl___rarg___boxed(obj*, obj*, obj*); obj* l_Array_miterateAux___main___at_Array_foldlFrom___spec__1___rarg(obj*, obj*, obj*, obj*, obj*); +obj* l_Array_swapAt___rarg___boxed(obj*, obj*, obj*); namespace lean { uint8 nat_dec_lt(obj*, obj*); } @@ -232,6 +237,7 @@ obj* l_Array_HasAppend___closed__1; obj* l_Array_isEmpty___rarg___boxed(obj*); obj* l_Array_isEqv___boxed(obj*); obj* l_Array_miterateAux___main___at_Array_mfoldlFrom___spec__1(obj*, obj*, obj*); +obj* l_Array_fswapAt(obj*); obj* l_Array_hmmapAux___main___at_Array_hmmap___spec__1___rarg___lambda__1(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Array_shrink___main___rarg(obj*, obj*); obj* l_Array_iterate___rarg(obj*, obj*, obj*); @@ -303,6 +309,7 @@ obj* l_Array_reverse___rarg(obj*); obj* l_Array_mmap___boxed(obj*, obj*); obj* l_Array_shrink___main___boxed(obj*); obj* l_Array_find(obj*, obj*); +obj* l_Array_swapAt___rarg(obj*, obj*, obj*); obj* l_Array_extractAux___boxed(obj*); obj* l_Array_miterateAux___main___at_Array_mmap___spec__1(obj*, obj*); obj* l_Array_miterate_u_2082Aux___main___at_Array_mfoldl_u_2082___spec__1___rarg___boxed(obj*, obj*, obj*, obj*, obj*, obj*, obj*); @@ -340,6 +347,7 @@ obj* l_Array_mkEmpty___boxed(obj*, obj*); obj* l_Array_miterateAux___main___at_Array_map___spec__1___boxed(obj*, obj*); uint8 l_Array_all___rarg(obj*, obj*); obj* l_Array_miterateAux___main___at_Array_iterate___spec__1___boxed(obj*, obj*); +obj* l_Array_fswapAt___rarg(obj*, obj*, obj*); obj* l_Array_miterateAux___main___at_Array_map___spec__1___rarg(obj*, obj*, obj*, obj*, obj*); obj* l_Array_miterateAux___main___at_Array_mmap___spec__1___boxed(obj*, obj*); obj* l_Array_miterate_u_2082Aux___rarg(obj*, obj*, obj*, obj*, obj*, obj*); @@ -670,6 +678,97 @@ lean::dec(x_3); return x_4; } } +obj* l_Array_fswapAt___rarg(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; obj* x_4; obj* x_5; +x_3 = lean::array_index(x_0, x_1); +x_4 = lean::array_update(x_0, x_1, x_2); +x_5 = lean::alloc_cnstr(0, 2, 0); +lean::cnstr_set(x_5, 0, x_3); +lean::cnstr_set(x_5, 1, x_4); +return x_5; +} +} +obj* l_Array_fswapAt(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = lean::alloc_closure(reinterpret_cast(l_Array_fswapAt___rarg___boxed), 3, 0); +return x_1; +} +} +obj* l_Array_fswapAt___rarg___boxed(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; +x_3 = l_Array_fswapAt___rarg(x_0, x_1, x_2); +lean::dec(x_1); +return x_3; +} +} +obj* l_Array_fswapAt___boxed(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Array_fswapAt(x_0); +lean::dec(x_0); +return x_1; +} +} +obj* l_Array_swapAt___rarg(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; uint8 x_4; +x_3 = lean::array_get_size(x_0); +x_4 = lean::nat_dec_lt(x_1, x_3); +lean::dec(x_3); +if (x_4 == 0) +{ +obj* x_6; +x_6 = lean::alloc_cnstr(0, 2, 0); +lean::cnstr_set(x_6, 0, x_2); +lean::cnstr_set(x_6, 1, x_0); +return x_6; +} +else +{ +obj* x_7; obj* x_8; obj* x_9; +x_7 = lean::array_index(x_0, x_1); +x_8 = lean::array_update(x_0, x_1, x_2); +x_9 = lean::alloc_cnstr(0, 2, 0); +lean::cnstr_set(x_9, 0, x_7); +lean::cnstr_set(x_9, 1, x_8); +return x_9; +} +} +} +obj* l_Array_swapAt(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = lean::alloc_closure(reinterpret_cast(l_Array_swapAt___rarg___boxed), 3, 0); +return x_1; +} +} +obj* l_Array_swapAt___rarg___boxed(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; +x_3 = l_Array_swapAt___rarg(x_0, x_1, x_2); +lean::dec(x_1); +return x_3; +} +} +obj* l_Array_swapAt___boxed(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Array_swapAt(x_0); +lean::dec(x_0); +return x_1; +} +} obj* l_Array_pop___boxed(obj* x_0, obj* x_1) { _start: { diff --git a/src/stage0/init/data/rbtree/basic.cpp b/src/stage0/init/data/rbtree/basic.cpp index 8df627ea30..478d9c282c 100644 --- a/src/stage0/init/data/rbtree/basic.cpp +++ b/src/stage0/init/data/rbtree/basic.cpp @@ -27,6 +27,7 @@ obj* l_rbtreeOf___boxed(obj*); obj* l_rbtreeOf(obj*); obj* l_List_foldl___main___at_RBTree_fromList___spec__1___rarg(obj*, obj*, obj*); obj* l_RBTree_max___boxed(obj*, obj*); +obj* l_RBTree_HasInsert(obj*); obj* l_RBNode_all___main___at_RBTree_subset___spec__1___rarg___boxed(obj*, obj*, obj*); obj* l_RBTree_ofList___main(obj*); obj* l_RBNode_fold___main___at_RBTree_fold___spec__1(obj*, obj*); @@ -66,6 +67,7 @@ uint8 l_RBNode_any___main___at_RBTree_any___spec__1___rarg(obj*, obj*); namespace lean { obj* string_append(obj*, obj*); } +obj* l_RBTree_HasInsert___boxed(obj*); obj* l_RBTree_contains___rarg___boxed(obj*, obj*, obj*); uint8 l_RBTree_seteq___rarg(obj*, obj*, obj*); obj* l_RBTree_fromList(obj*); @@ -121,6 +123,7 @@ uint8 l_RBTree_isEmpty___rarg(obj*); obj* l_RBTree_ofList(obj*); obj* l_RBTree_ofList___main___boxed(obj*); obj* l_RBTree_depth(obj*, obj*); +obj* l_RBTree_HasInsert___rarg(obj*, obj*, obj*); obj* l_RBTree_fold___boxed(obj*, obj*, obj*); obj* l_RBTree_toList___boxed(obj*, obj*); obj* l_RBNode_mfold___main___at_RBTree_mfor___spec__1___rarg___lambda__2(obj*, obj*, obj*, obj*, obj*, obj*); @@ -895,6 +898,45 @@ lean::dec(x_0); return x_1; } } +obj* l_RBTree_HasInsert___rarg(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +uint8 x_3; +x_3 = l_RBNode_isRed___main___rarg(x_2); +if (x_3 == 0) +{ +obj* x_4; obj* x_5; +x_4 = lean::box(0); +x_5 = l_RBNode_ins___main___rarg(x_0, x_2, x_1, x_4); +return x_5; +} +else +{ +obj* x_6; obj* x_7; obj* x_8; +x_6 = lean::box(0); +x_7 = l_RBNode_ins___main___rarg(x_0, x_2, x_1, x_6); +x_8 = l_RBNode_setBlack___main___rarg(x_7); +return x_8; +} +} +} +obj* l_RBTree_HasInsert(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = lean::alloc_closure(reinterpret_cast(l_RBTree_HasInsert___rarg), 3, 0); +return x_1; +} +} +obj* l_RBTree_HasInsert___boxed(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_RBTree_HasInsert(x_0); +lean::dec(x_0); +return x_1; +} +} obj* l_RBTree_ofList___main___rarg(obj* x_0, obj* x_1) { _start: { diff --git a/src/stage0/init/lean/compiler/default.cpp b/src/stage0/init/lean/compiler/default.cpp index b07752722e..0c319a4d6b 100644 --- a/src/stage0/init/lean/compiler/default.cpp +++ b/src/stage0/init/lean/compiler/default.cpp @@ -1,6 +1,6 @@ // Lean compiler output // Module: init.lean.compiler.default -// Imports: init.lean.compiler.constfolding init.lean.compiler.ir +// Imports: init.lean.compiler.constfolding init.lean.compiler.ir init.lean.compiler.pushproj init.lean.compiler.elimdead #include "runtime/object.h" #include "runtime/apply.h" typedef lean::object obj; typedef lean::usize usize; @@ -16,6 +16,8 @@ typedef lean::uint32 uint32; typedef lean::uint64 uint64; #endif obj* initialize_init_lean_compiler_constfolding(obj*); obj* initialize_init_lean_compiler_ir(obj*); +obj* initialize_init_lean_compiler_pushproj(obj*); +obj* initialize_init_lean_compiler_elimdead(obj*); static bool _G_initialized = false; obj* initialize_init_lean_compiler_default(obj* w) { if (_G_initialized) return w; @@ -25,5 +27,9 @@ w = initialize_init_lean_compiler_constfolding(w); if (io_result_is_error(w)) return w; w = initialize_init_lean_compiler_ir(w); if (io_result_is_error(w)) return w; +w = initialize_init_lean_compiler_pushproj(w); +if (io_result_is_error(w)) return w; +w = initialize_init_lean_compiler_elimdead(w); +if (io_result_is_error(w)) return w; return w; } diff --git a/src/stage0/init/lean/compiler/elimdead.cpp b/src/stage0/init/lean/compiler/elimdead.cpp new file mode 100644 index 0000000000..775f3c07b1 --- /dev/null +++ b/src/stage0/init/lean/compiler/elimdead.cpp @@ -0,0 +1,391 @@ +// Lean compiler output +// Module: init.lean.compiler.elimdead +// Imports: init.default init.lean.compiler.ir +#include "runtime/object.h" +#include "runtime/apply.h" +typedef lean::object obj; typedef lean::usize usize; +typedef lean::uint8 uint8; typedef lean::uint16 uint16; +typedef lean::uint32 uint32; typedef lean::uint64 uint64; +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wunused-label" +#elif defined(__GNUC__) && !defined(__CLANG__) +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-label" +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif +obj* l_Lean_IR_FnBody_collectFreeVars(obj*, obj*); +namespace lean { +obj* nat_sub(obj*, obj*); +} +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(obj*, obj*); +obj* l_Lean_IR_reshapeWithoutDead(obj*, obj*); +obj* l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1(obj*); +obj* l_Lean_IR_reshapeWithoutDeadAux(obj*, obj*, obj*); +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1; +obj* l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1___boxed(obj*); +obj* l_Lean_IR_FnBody_elimDead___main(obj*); +obj* l_Lean_IR_FnBody_freeVars(obj*); +obj* l_Lean_IR_reshape(obj*, obj*); +obj* l_Lean_IR_reshapeWithoutDeadAux___main(obj*, obj*, obj*); +namespace lean { +uint8 nat_dec_lt(obj*, obj*); +} +namespace lean { +namespace ir { +obj* decl_elim_dead_core(obj*); +}} +obj* l_RBNode_findCore___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__1(obj*, obj*); +obj* l_Lean_IR_FnBody_flatten(obj*); +namespace lean { +obj* nat_add(obj*, obj*); +} +uint8 l_Array_isEmpty___rarg(obj*); +obj* l_Lean_IR_Decl_elimDead___main(obj*); +obj* l_Lean_IR_FnBody_setBody___main(obj*, obj*); +obj* l_Lean_IR_FnBody_elimDead(obj*); +extern obj* l_Lean_IR_Inhabited; +obj* l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1(obj* x_0) { +_start: +{ +obj* x_1; obj* x_2; obj* x_3; obj* x_5; obj* x_6; +x_1 = lean::array_get_size(x_0); +x_2 = lean::mk_nat_obj(1ul); +x_3 = lean::nat_sub(x_1, x_2); +lean::dec(x_1); +x_5 = l_Lean_IR_Inhabited; +x_6 = lean::array_get(x_5, x_0, x_3); +lean::dec(x_3); +return x_6; +} +} +obj* l_Lean_IR_reshapeWithoutDeadAux___main(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +uint8 x_3; +x_3 = l_Array_isEmpty___rarg(x_0); +if (x_3 == 0) +{ +obj* x_4; obj* x_5; +x_4 = l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1(x_0); +x_5 = lean::array_pop(x_0); +switch (lean::obj_tag(x_4)) { +case 0: +{ +obj* x_6; obj* x_9; +x_6 = lean::cnstr_get(x_4, 0); +lean::inc(x_6); +lean::inc(x_2); +x_9 = l_RBNode_findCore___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__1(x_2, x_6); +lean::dec(x_6); +if (lean::obj_tag(x_9) == 0) +{ +lean::dec(x_4); +x_0 = x_5; +goto _start; +} +else +{ +obj* x_15; obj* x_16; +lean::dec(x_9); +lean::inc(x_4); +x_15 = l_Lean_IR_FnBody_collectFreeVars(x_4, x_2); +x_16 = l_Lean_IR_FnBody_setBody___main(x_4, x_1); +x_0 = x_5; +x_1 = x_16; +x_2 = x_15; +goto _start; +} +} +case 1: +{ +obj* x_18; obj* x_21; +x_18 = lean::cnstr_get(x_4, 0); +lean::inc(x_18); +lean::inc(x_2); +x_21 = l_RBNode_findCore___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__1(x_2, x_18); +lean::dec(x_18); +if (lean::obj_tag(x_21) == 0) +{ +lean::dec(x_4); +x_0 = x_5; +goto _start; +} +else +{ +obj* x_27; obj* x_28; +lean::dec(x_21); +lean::inc(x_4); +x_27 = l_Lean_IR_FnBody_collectFreeVars(x_4, x_2); +x_28 = l_Lean_IR_FnBody_setBody___main(x_4, x_1); +x_0 = x_5; +x_1 = x_28; +x_2 = x_27; +goto _start; +} +} +case 12: +{ +obj* x_30; obj* x_31; +x_30 = l_Lean_IR_FnBody_collectFreeVars(x_4, x_2); +x_31 = l_Lean_IR_FnBody_setBody___main(x_4, x_1); +x_0 = x_5; +x_1 = x_31; +x_2 = x_30; +goto _start; +} +default: +{ +obj* x_34; obj* x_35; +lean::inc(x_4); +x_34 = l_Lean_IR_FnBody_collectFreeVars(x_4, x_2); +x_35 = l_Lean_IR_FnBody_setBody___main(x_4, x_1); +x_0 = x_5; +x_1 = x_35; +x_2 = x_34; +goto _start; +} +} +} +else +{ +lean::dec(x_0); +lean::dec(x_2); +return x_1; +} +} +} +obj* l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1___boxed(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Array_back___at_Lean_IR_reshapeWithoutDeadAux___main___spec__1(x_0); +lean::dec(x_0); +return x_1; +} +} +obj* l_Lean_IR_reshapeWithoutDeadAux(obj* x_0, obj* x_1, obj* x_2) { +_start: +{ +obj* x_3; +x_3 = l_Lean_IR_reshapeWithoutDeadAux___main(x_0, x_1, x_2); +return x_3; +} +} +obj* l_Lean_IR_reshapeWithoutDead(obj* x_0, obj* x_1) { +_start: +{ +obj* x_3; obj* x_4; +lean::inc(x_1); +x_3 = l_Lean_IR_FnBody_freeVars(x_1); +x_4 = l_Lean_IR_reshapeWithoutDeadAux___main(x_0, x_1, x_3); +return x_4; +} +} +obj* _init_l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1() { +_start: +{ +obj* x_0; obj* x_1; +x_0 = lean::box(12); +x_1 = lean::alloc_cnstr(1, 1, 0); +lean::cnstr_set(x_1, 0, x_0); +return x_1; +} +} +obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(obj* x_0, obj* x_1) { +_start: +{ +obj* x_2; uint8 x_3; +x_2 = lean::array_get_size(x_1); +x_3 = lean::nat_dec_lt(x_0, x_2); +lean::dec(x_2); +if (x_3 == 0) +{ +lean::dec(x_0); +return x_1; +} +else +{ +obj* x_6; obj* x_7; obj* x_8; obj* x_9; obj* x_10; +x_6 = lean::array_index(x_1, x_0); +x_7 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1; +x_8 = lean::array_update(x_1, x_0, x_7); +x_9 = lean::mk_nat_obj(1ul); +x_10 = lean::nat_add(x_0, x_9); +if (lean::obj_tag(x_6) == 0) +{ +obj* x_11; obj* x_13; obj* x_15; obj* x_16; obj* x_17; obj* x_18; +x_11 = lean::cnstr_get(x_6, 0); +x_13 = lean::cnstr_get(x_6, 1); +if (lean::is_exclusive(x_6)) { + x_15 = x_6; +} else { + lean::inc(x_11); + lean::inc(x_13); + lean::dec(x_6); + x_15 = lean::box(0); +} +x_16 = l_Lean_IR_FnBody_elimDead___main(x_13); +if (lean::is_scalar(x_15)) { + x_17 = lean::alloc_cnstr(0, 2, 0); +} else { + x_17 = x_15; +} +lean::cnstr_set(x_17, 0, x_11); +lean::cnstr_set(x_17, 1, x_16); +x_18 = lean::array_update(x_8, x_0, x_17); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_18; +goto _start; +} +else +{ +obj* x_21; obj* x_23; obj* x_24; obj* x_25; obj* x_26; +x_21 = lean::cnstr_get(x_6, 0); +if (lean::is_exclusive(x_6)) { + x_23 = x_6; +} else { + lean::inc(x_21); + lean::dec(x_6); + x_23 = lean::box(0); +} +x_24 = l_Lean_IR_FnBody_elimDead___main(x_21); +if (lean::is_scalar(x_23)) { + x_25 = lean::alloc_cnstr(1, 1, 0); +} else { + x_25 = x_23; +} +lean::cnstr_set(x_25, 0, x_24); +x_26 = lean::array_update(x_8, x_0, x_25); +lean::dec(x_0); +x_0 = x_10; +x_1 = x_26; +goto _start; +} +} +} +} +obj* l_Lean_IR_FnBody_elimDead___main(obj* x_0) { +_start: +{ +obj* x_1; obj* x_2; +x_1 = l_Lean_IR_FnBody_flatten(x_0); +x_2 = lean::cnstr_get(x_1, 1); +lean::inc(x_2); +switch (lean::obj_tag(x_2)) { +case 9: +{ +obj* x_4; obj* x_7; obj* x_9; obj* x_11; obj* x_13; obj* x_14; obj* x_15; obj* x_16; obj* x_17; +x_4 = lean::cnstr_get(x_1, 0); +lean::inc(x_4); +lean::dec(x_1); +x_7 = lean::cnstr_get(x_2, 0); +x_9 = lean::cnstr_get(x_2, 1); +x_11 = lean::cnstr_get(x_2, 2); +if (lean::is_exclusive(x_2)) { + x_13 = x_2; +} else { + lean::inc(x_7); + lean::inc(x_9); + lean::inc(x_11); + lean::dec(x_2); + x_13 = lean::box(0); +} +x_14 = lean::mk_nat_obj(0ul); +x_15 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1(x_14, x_11); +if (lean::is_scalar(x_13)) { + x_16 = lean::alloc_cnstr(9, 3, 0); +} else { + x_16 = x_13; +} +lean::cnstr_set(x_16, 0, x_7); +lean::cnstr_set(x_16, 1, x_9); +lean::cnstr_set(x_16, 2, x_15); +x_17 = l_Lean_IR_reshape(x_4, x_16); +return x_17; +} +default: +{ +obj* x_18; obj* x_21; +x_18 = lean::cnstr_get(x_1, 0); +lean::inc(x_18); +lean::dec(x_1); +x_21 = l_Lean_IR_reshape(x_18, x_2); +return x_21; +} +} +} +} +obj* l_Lean_IR_FnBody_elimDead(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Lean_IR_FnBody_elimDead___main(x_0); +return x_1; +} +} +obj* l_Lean_IR_Decl_elimDead___main(obj* x_0) { +_start: +{ +if (lean::obj_tag(x_0) == 0) +{ +obj* x_1; obj* x_3; uint8 x_5; obj* x_6; obj* x_8; obj* x_9; obj* x_10; obj* x_11; +x_1 = lean::cnstr_get(x_0, 0); +x_3 = lean::cnstr_get(x_0, 1); +x_5 = lean::cnstr_get_scalar(x_0, sizeof(void*)*3); +x_6 = lean::cnstr_get(x_0, 2); +if (lean::is_exclusive(x_0)) { + x_8 = x_0; +} else { + lean::inc(x_1); + lean::inc(x_3); + lean::inc(x_6); + lean::dec(x_0); + x_8 = lean::box(0); +} +x_9 = l_Lean_IR_FnBody_elimDead___main(x_6); +if (lean::is_scalar(x_8)) { + x_10 = lean::alloc_cnstr(0, 3, 1); +} else { + x_10 = x_8; +} +lean::cnstr_set(x_10, 0, x_1); +lean::cnstr_set(x_10, 1, x_3); +lean::cnstr_set(x_10, 2, x_9); +lean::cnstr_set_scalar(x_10, sizeof(void*)*3, x_5); +x_11 = x_10; +return x_11; +} +else +{ +return x_0; +} +} +} +namespace lean { +namespace ir { +obj* decl_elim_dead_core(obj* x_0) { +_start: +{ +obj* x_1; +x_1 = l_Lean_IR_Decl_elimDead___main(x_0); +return x_1; +} +} +}} +obj* initialize_init_default(obj*); +obj* initialize_init_lean_compiler_ir(obj*); +static bool _G_initialized = false; +obj* initialize_init_lean_compiler_elimdead(obj* w) { + if (_G_initialized) return w; + _G_initialized = true; +if (io_result_is_error(w)) return w; +w = initialize_init_default(w); +if (io_result_is_error(w)) return w; +w = initialize_init_lean_compiler_ir(w); +if (io_result_is_error(w)) return w; + l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1 = _init_l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1(); +lean::mark_persistent(l_Array_hmmapAux___main___at_Lean_IR_FnBody_elimDead___main___spec__1___closed__1); +return w; +} diff --git a/src/stage0/init/lean/compiler/ir.cpp b/src/stage0/init/lean/compiler/ir.cpp index 212d4b067f..a123f7fa3d 100644 --- a/src/stage0/init/lean/compiler/ir.cpp +++ b/src/stage0/init/lean/compiler/ir.cpp @@ -2001,22 +2001,37 @@ x_3 = lean::mk_nat_obj(0ul); x_4 = lean::nat_dec_eq(x_1, x_3); if (x_4 == 0) { -obj* x_5; obj* x_6; obj* x_8; obj* x_9; obj* x_10; obj* x_11; obj* x_12; +obj* x_5; obj* x_6; obj* x_8; uint8 x_9; x_5 = lean::mk_nat_obj(1ul); x_6 = lean::nat_sub(x_1, x_5); lean::dec(x_1); -x_8 = l_Lean_IR_Inhabited; -x_9 = lean::array_get(x_8, x_0, x_6); -x_10 = lean::box(12); -x_11 = lean::array_set(x_0, x_6, x_10); -x_12 = l_Lean_IR_FnBody_setBody___main(x_9, x_2); -x_0 = x_11; +x_8 = lean::array_get_size(x_0); +x_9 = lean::nat_dec_lt(x_6, x_8); +lean::dec(x_8); +if (x_9 == 0) +{ +obj* x_11; obj* x_12; +x_11 = lean::box(12); +x_12 = l_Lean_IR_FnBody_setBody___main(x_11, x_2); x_1 = x_6; x_2 = x_12; goto _start; } else { +obj* x_14; obj* x_15; obj* x_16; obj* x_17; +x_14 = lean::array_index(x_0, x_6); +x_15 = lean::box(12); +x_16 = lean::array_update(x_0, x_6, x_15); +x_17 = l_Lean_IR_FnBody_setBody___main(x_14, x_2); +x_0 = x_16; +x_1 = x_6; +x_2 = x_17; +goto _start; +} +} +else +{ lean::dec(x_1); lean::dec(x_0); return x_2; diff --git a/src/stage0/init/lean/compiler/pushproj.cpp b/src/stage0/init/lean/compiler/pushproj.cpp index 8bb6152f1e..b12d277ee3 100644 --- a/src/stage0/init/lean/compiler/pushproj.cpp +++ b/src/stage0/init/lean/compiler/pushproj.cpp @@ -14,6 +14,7 @@ typedef lean::uint32 uint32; typedef lean::uint64 uint64; #pragma GCC diagnostic ignored "-Wunused-label" #pragma GCC diagnostic ignored "-Wunused-but-set-variable" #endif +obj* l_RBNode_setBlack___main___rarg(obj*); obj* l_Array_hmmapAux___main___at_Lean_IR_pushProjs___main___spec__3(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Lean_IR_FnBody_collectFreeVars(obj*, obj*); extern obj* l_Array_empty___closed__1; @@ -25,6 +26,7 @@ namespace lean { namespace ir { obj* decl_push_proj_core(obj*); }} +obj* l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(obj*, obj*, obj*); obj* l_Lean_IR_pushProjs___main___closed__1; obj* l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1___boxed(obj*, obj*, obj*, obj*); obj* l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(obj*, obj*); @@ -43,6 +45,7 @@ namespace lean { obj* nat_add(obj*, obj*); } uint8 l_Array_isEmpty___rarg(obj*); +uint8 l_RBNode_isRed___main___rarg(obj*); obj* l_Lean_IR_pushProjs(obj*, obj*, obj*, obj*, obj*); obj* l_Lean_IR_FnBody_pushProj___main(obj*); obj* l_Nat_decLt___boxed(obj*, obj*); @@ -611,7 +614,7 @@ lean::inc(x_2); switch (lean::obj_tag(x_2)) { case 9: { -obj* x_4; obj* x_7; obj* x_9; obj* x_11; obj* x_13; obj* x_14; obj* x_15; obj* x_17; obj* x_18; obj* x_19; obj* x_20; obj* x_21; obj* x_22; obj* x_24; obj* x_27; obj* x_28; obj* x_29; +obj* x_4; obj* x_7; obj* x_9; obj* x_11; obj* x_13; obj* x_14; obj* x_15; obj* x_17; obj* x_18; obj* x_19; uint8 x_20; x_4 = lean::cnstr_get(x_1, 0); lean::inc(x_4); lean::dec(x_1); @@ -619,6 +622,9 @@ x_7 = lean::cnstr_get(x_2, 0); x_9 = lean::cnstr_get(x_2, 1); x_11 = lean::cnstr_get(x_2, 2); if (lean::is_exclusive(x_2)) { + lean::cnstr_set(x_2, 0, lean::box(0)); + lean::cnstr_set(x_2, 1, lean::box(0)); + lean::cnstr_set(x_2, 2, lean::box(0)); x_13 = x_2; } else { lean::inc(x_7); @@ -633,33 +639,67 @@ lean::dec(x_14); x_17 = lean::mk_nat_obj(0ul); x_18 = l_Array_miterateAux___main___at_Lean_IR_FnBody_pushProj___main___spec__1(x_11, x_11, x_17, x_15); x_19 = lean::box(0); -x_20 = l_Array_empty___closed__1; -x_21 = l_Lean_IR_pushProjs___main(x_4, x_11, x_18, x_20, x_19); -x_22 = lean::cnstr_get(x_21, 0); -lean::inc(x_22); -x_24 = lean::cnstr_get(x_21, 1); -lean::inc(x_24); -lean::dec(x_21); -x_27 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_17, x_24); +x_20 = l_RBNode_isRed___main___rarg(x_19); +if (x_20 == 0) +{ +obj* x_21; obj* x_23; obj* x_24; obj* x_25; obj* x_26; obj* x_28; obj* x_31; obj* x_32; obj* x_33; +x_21 = lean::box(0); +lean::inc(x_9); +x_23 = l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(x_19, x_9, x_21); +x_24 = l_Array_empty___closed__1; +x_25 = l_Lean_IR_pushProjs___main(x_4, x_11, x_18, x_24, x_23); +x_26 = lean::cnstr_get(x_25, 0); +lean::inc(x_26); +x_28 = lean::cnstr_get(x_25, 1); +lean::inc(x_28); +lean::dec(x_25); +x_31 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_17, x_28); if (lean::is_scalar(x_13)) { - x_28 = lean::alloc_cnstr(9, 3, 0); + x_32 = lean::alloc_cnstr(9, 3, 0); } else { - x_28 = x_13; + x_32 = x_13; +} +lean::cnstr_set(x_32, 0, x_7); +lean::cnstr_set(x_32, 1, x_9); +lean::cnstr_set(x_32, 2, x_31); +x_33 = l_Lean_IR_reshape(x_26, x_32); +return x_33; +} +else +{ +obj* x_34; obj* x_36; obj* x_37; obj* x_38; obj* x_39; obj* x_40; obj* x_42; obj* x_45; obj* x_46; obj* x_47; +x_34 = lean::box(0); +lean::inc(x_9); +x_36 = l_RBNode_ins___main___at___private_init_lean_compiler_ir_2__collectIndex___spec__2(x_19, x_9, x_34); +x_37 = l_RBNode_setBlack___main___rarg(x_36); +x_38 = l_Array_empty___closed__1; +x_39 = l_Lean_IR_pushProjs___main(x_4, x_11, x_18, x_38, x_37); +x_40 = lean::cnstr_get(x_39, 0); +lean::inc(x_40); +x_42 = lean::cnstr_get(x_39, 1); +lean::inc(x_42); +lean::dec(x_39); +x_45 = l_Array_hmmapAux___main___at_Lean_IR_FnBody_pushProj___main___spec__2(x_17, x_42); +if (lean::is_scalar(x_13)) { + x_46 = lean::alloc_cnstr(9, 3, 0); +} else { + x_46 = x_13; +} +lean::cnstr_set(x_46, 0, x_7); +lean::cnstr_set(x_46, 1, x_9); +lean::cnstr_set(x_46, 2, x_45); +x_47 = l_Lean_IR_reshape(x_40, x_46); +return x_47; } -lean::cnstr_set(x_28, 0, x_7); -lean::cnstr_set(x_28, 1, x_9); -lean::cnstr_set(x_28, 2, x_27); -x_29 = l_Lean_IR_reshape(x_22, x_28); -return x_29; } default: { -obj* x_30; obj* x_33; -x_30 = lean::cnstr_get(x_1, 0); -lean::inc(x_30); +obj* x_48; obj* x_51; +x_48 = lean::cnstr_get(x_1, 0); +lean::inc(x_48); lean::dec(x_1); -x_33 = l_Lean_IR_reshape(x_30, x_2); -return x_33; +x_51 = l_Lean_IR_reshape(x_48, x_2); +return x_51; } } }