add constructor info in more cases

This commit is contained in:
Folkert 2021-05-26 21:51:18 +02:00
parent 9bbed89e6a
commit fdfc99e4e8
2 changed files with 38 additions and 6 deletions

View file

@ -1101,7 +1101,13 @@ fn test_to_equality<'a>(
cond_layout: &Layout<'a>, cond_layout: &Layout<'a>,
path: &[PathInstruction], path: &[PathInstruction],
test: Test<'a>, test: Test<'a>,
) -> (StoresVec<'a>, Symbol, Symbol, Layout<'a>) { ) -> (
StoresVec<'a>,
Symbol,
Symbol,
Layout<'a>,
Option<ConstructorKnown<'a>>,
) {
let (rhs_symbol, mut stores, _layout) = let (rhs_symbol, mut stores, _layout) =
path_to_expr_help(env, cond_symbol, &path, *cond_layout); path_to_expr_help(env, cond_symbol, &path, *cond_layout);
@ -1148,6 +1154,11 @@ fn test_to_equality<'a>(
lhs_symbol, lhs_symbol,
rhs_symbol, rhs_symbol,
Layout::Builtin(Builtin::Int64), Layout::Builtin(Builtin::Int64),
Some(ConstructorKnown::OnlyPass {
scrutinee: path_symbol,
layout: *cond_layout,
tag_id,
}),
) )
} }
Test::IsInt(test_int) => { Test::IsInt(test_int) => {
@ -1162,6 +1173,7 @@ fn test_to_equality<'a>(
lhs_symbol, lhs_symbol,
rhs_symbol, rhs_symbol,
Layout::Builtin(Builtin::Int64), Layout::Builtin(Builtin::Int64),
None,
) )
} }
@ -1177,6 +1189,7 @@ fn test_to_equality<'a>(
lhs_symbol, lhs_symbol,
rhs_symbol, rhs_symbol,
Layout::Builtin(Builtin::Float64), Layout::Builtin(Builtin::Float64),
None,
) )
} }
@ -1192,6 +1205,7 @@ fn test_to_equality<'a>(
lhs_symbol, lhs_symbol,
rhs_symbol, rhs_symbol,
Layout::Builtin(Builtin::Int8), Layout::Builtin(Builtin::Int8),
None,
) )
} }
@ -1205,6 +1219,7 @@ fn test_to_equality<'a>(
lhs_symbol, lhs_symbol,
rhs_symbol, rhs_symbol,
Layout::Builtin(Builtin::Int1), Layout::Builtin(Builtin::Int1),
None,
) )
} }
@ -1219,6 +1234,7 @@ fn test_to_equality<'a>(
lhs_symbol, lhs_symbol,
rhs_symbol, rhs_symbol,
Layout::Builtin(Builtin::Str), Layout::Builtin(Builtin::Str),
None,
) )
} }
@ -1231,6 +1247,7 @@ type Tests<'a> = std::vec::Vec<(
Symbol, Symbol,
Symbol, Symbol,
Layout<'a>, Layout<'a>,
Option<ConstructorKnown<'a>>,
)>; )>;
fn stores_and_condition<'a>( fn stores_and_condition<'a>(
@ -1239,7 +1256,7 @@ fn stores_and_condition<'a>(
cond_layout: &Layout<'a>, cond_layout: &Layout<'a>,
test_chain: Vec<(Vec<PathInstruction>, Test<'a>)>, test_chain: Vec<(Vec<PathInstruction>, Test<'a>)>,
) -> (Tests<'a>, Option<(Symbol, JoinPointId, Stmt<'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; let mut guard = None;
@ -1444,12 +1461,20 @@ fn compile_tests<'a>(
cond = compile_guard(env, ret_layout, id, arena.alloc(stmt), fail, cond); cond = compile_guard(env, ret_layout, id, arena.alloc(stmt), fail, cond);
} }
for (new_stores, lhs, rhs, _layout) in tests.into_iter() { for (new_stores, lhs, rhs, _layout, opt_constructor_info) in tests.into_iter() {
cond = compile_test(env, ret_layout, new_stores, lhs, rhs, fail, cond); 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 cond
} }
#[derive(Debug)]
enum ConstructorKnown<'a> { enum ConstructorKnown<'a> {
Both { Both {
scrutinee: Symbol, scrutinee: Symbol,
@ -1571,7 +1596,7 @@ fn decide_to_branching<'a>(
// use knowledge about constructors for optimization // use knowledge about constructors for optimization
debug_assert_eq!(tests.len(), 1); 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( compile_test_help(
env, env,

View file

@ -916,7 +916,14 @@ impl<'a> BranchInfo<'a> {
.append(", tag_id: ") .append(", tag_id: ")
.append(format!("{}", tag_id)) .append(format!("{}", tag_id))
.append("} "), .append("} "),
_ => alloc.text(""),
_ => {
if PRETTY_PRINT_IR_SYMBOLS {
alloc.text(" <no branch info>")
} else {
alloc.text("")
}
}
} }
} }
} }