From fdfc99e4e8d074ae58381be77a44ff9489a89778 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 26 May 2021 21:51:18 +0200 Subject: [PATCH] add constructor info in more cases --- compiler/mono/src/decision_tree.rs | 35 +++++++++++++++++++++++++----- compiler/mono/src/ir.rs | 9 +++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/compiler/mono/src/decision_tree.rs b/compiler/mono/src/decision_tree.rs index d3979f9529..565e9f7126 100644 --- a/compiler/mono/src/decision_tree.rs +++ b/compiler/mono/src/decision_tree.rs @@ -1101,7 +1101,13 @@ fn test_to_equality<'a>( cond_layout: &Layout<'a>, path: &[PathInstruction], test: Test<'a>, -) -> (StoresVec<'a>, Symbol, Symbol, Layout<'a>) { +) -> ( + StoresVec<'a>, + Symbol, + Symbol, + Layout<'a>, + Option>, +) { let (rhs_symbol, mut stores, _layout) = path_to_expr_help(env, cond_symbol, &path, *cond_layout); @@ -1148,6 +1154,11 @@ fn test_to_equality<'a>( lhs_symbol, rhs_symbol, Layout::Builtin(Builtin::Int64), + Some(ConstructorKnown::OnlyPass { + scrutinee: path_symbol, + layout: *cond_layout, + tag_id, + }), ) } Test::IsInt(test_int) => { @@ -1162,6 +1173,7 @@ fn test_to_equality<'a>( lhs_symbol, rhs_symbol, Layout::Builtin(Builtin::Int64), + None, ) } @@ -1177,6 +1189,7 @@ fn test_to_equality<'a>( lhs_symbol, rhs_symbol, Layout::Builtin(Builtin::Float64), + None, ) } @@ -1192,6 +1205,7 @@ fn test_to_equality<'a>( lhs_symbol, rhs_symbol, Layout::Builtin(Builtin::Int8), + None, ) } @@ -1205,6 +1219,7 @@ fn test_to_equality<'a>( lhs_symbol, rhs_symbol, Layout::Builtin(Builtin::Int1), + None, ) } @@ -1219,6 +1234,7 @@ fn test_to_equality<'a>( lhs_symbol, rhs_symbol, Layout::Builtin(Builtin::Str), + None, ) } @@ -1231,6 +1247,7 @@ type Tests<'a> = std::vec::Vec<( Symbol, Symbol, Layout<'a>, + Option>, )>; fn stores_and_condition<'a>( @@ -1239,7 +1256,7 @@ fn stores_and_condition<'a>( cond_layout: &Layout<'a>, test_chain: Vec<(Vec, Test<'a>)>, ) -> (Tests<'a>, Option<(Symbol, JoinPointId, Stmt<'a>)>) { - let mut tests = Vec::with_capacity(test_chain.len()); + let mut tests: Tests = Vec::with_capacity(test_chain.len()); let mut guard = None; @@ -1444,12 +1461,20 @@ fn compile_tests<'a>( cond = compile_guard(env, ret_layout, id, arena.alloc(stmt), fail, cond); } - for (new_stores, lhs, rhs, _layout) in tests.into_iter() { - cond = compile_test(env, ret_layout, new_stores, lhs, rhs, fail, cond); + for (new_stores, lhs, rhs, _layout, opt_constructor_info) in tests.into_iter() { + match opt_constructor_info { + None => { + cond = compile_test(env, ret_layout, new_stores, lhs, rhs, fail, cond); + } + Some(cinfo) => { + cond = compile_test_help(env, cinfo, ret_layout, new_stores, lhs, rhs, fail, cond); + } + } } cond } +#[derive(Debug)] enum ConstructorKnown<'a> { Both { scrutinee: Symbol, @@ -1571,7 +1596,7 @@ fn decide_to_branching<'a>( // use knowledge about constructors for optimization debug_assert_eq!(tests.len(), 1); - let (new_stores, lhs, rhs, _layout) = tests.into_iter().next().unwrap(); + let (new_stores, lhs, rhs, _layout, _cinfo) = tests.into_iter().next().unwrap(); compile_test_help( env, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index cbf8649aaf..b7660b4c61 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -916,7 +916,14 @@ impl<'a> BranchInfo<'a> { .append(", tag_id: ") .append(format!("{}", tag_id)) .append("} "), - _ => alloc.text(""), + + _ => { + if PRETTY_PRINT_IR_SYMBOLS { + alloc.text(" ") + } else { + alloc.text("") + } + } } } }