added branch info and uniqueness check

This commit is contained in:
J.Teeuwissen 2023-06-18 20:00:15 +02:00
parent d10d71cdec
commit fdfa978ca8
No known key found for this signature in database
GPG key ID: DB5F7A1ED8D478AD
3 changed files with 45 additions and 14 deletions

View file

@ -1355,8 +1355,21 @@ where
arena.alloc(Stmt::Switch { arena.alloc(Stmt::Switch {
cond_symbol: unique_symbol, cond_symbol: unique_symbol,
cond_layout: Layout::BOOL, cond_layout: Layout::BOOL,
branches: &*arena.alloc([(1, BranchInfo::None, u.clone())]), branches: &*arena.alloc([(
default_branch: (BranchInfo::None, n), 1,
BranchInfo::Unique {
scrutinee: unique_symbol,
unique: true,
},
u.clone(),
)]),
default_branch: (
BranchInfo::Unique {
scrutinee: unique_symbol,
unique: false,
},
n,
),
ret_layout: environment.layout, ret_layout: environment.layout,
}) })
}; };

View file

@ -1607,6 +1607,10 @@ pub enum BranchInfo<'a> {
scrutinee: Symbol, scrutinee: Symbol,
len: u64, len: u64,
}, },
Unique {
scrutinee: Symbol,
unique: bool,
},
} }
impl<'a> BranchInfo<'a> { impl<'a> BranchInfo<'a> {

View file

@ -67,6 +67,7 @@ fn insert_reset_reuse_operations_proc<'a, 'i>(
let mut env = ReuseEnvironment { let mut env = ReuseEnvironment {
symbol_tags: MutMap::default(), symbol_tags: MutMap::default(),
non_unique_symbols: MutSet::default(),
reuse_tokens: MutMap::default(), reuse_tokens: MutMap::default(),
symbol_layouts: symbol_layout, symbol_layouts: symbol_layout,
joinpoint_reuse_tokens: MutMap::default(), joinpoint_reuse_tokens: MutMap::default(),
@ -236,13 +237,21 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
.iter() .iter()
.map(|(tag_id, info, branch)| { .map(|(tag_id, info, branch)| {
let mut branch_env = environment.clone(); let mut branch_env = environment.clone();
if let BranchInfo::Constructor { match info {
scrutinee, BranchInfo::Constructor {
tag_id: tag, scrutinee,
.. tag_id: tag,
} = info ..
{ } => {
branch_env.add_symbol_tag(*scrutinee, *tag); branch_env.add_symbol_tag(*scrutinee, *tag);
}
BranchInfo::Unique {
scrutinee,
unique: false,
} => {
branch_env.non_unique_symbols.insert(*scrutinee);
}
_ => {}
} }
let new_branch = insert_reset_reuse_operations_stmt( let new_branch = insert_reset_reuse_operations_stmt(
@ -387,11 +396,9 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
} }
Stmt::Refcounting(rc, continuation) => { Stmt::Refcounting(rc, continuation) => {
let reuse_pair = match rc { let reuse_pair = match rc {
ModifyRc::Inc(_, _) => { ModifyRc::Dec(symbol) | ModifyRc::DecRef(symbol)
// We don't need to do anything for an inc. if !environment.non_unique_symbols.contains(symbol) =>
None {
}
ModifyRc::Dec(symbol) | ModifyRc::DecRef(symbol) => {
// Get the layout of the symbol from where it is defined. // Get the layout of the symbol from where it is defined.
let layout_option = environment.get_symbol_layout(*symbol); let layout_option = environment.get_symbol_layout(*symbol);
@ -430,6 +437,10 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
_ => None, _ => None,
} }
} }
_ => {
// We don't need to do anything for an inc or symbols known to be non-unique.
None
}
}; };
let new_continuation = insert_reset_reuse_operations_stmt( let new_continuation = insert_reset_reuse_operations_stmt(
@ -648,6 +659,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
// Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump. // Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump.
let mut first_pass_body_environment = ReuseEnvironment { let mut first_pass_body_environment = ReuseEnvironment {
symbol_tags: environment.symbol_tags.clone(), symbol_tags: environment.symbol_tags.clone(),
non_unique_symbols: environment.non_unique_symbols.clone(),
reuse_tokens: max_reuse_token_symbols.clone(), reuse_tokens: max_reuse_token_symbols.clone(),
symbol_layouts: environment.symbol_layouts.clone(), symbol_layouts: environment.symbol_layouts.clone(),
joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(), joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(),
@ -822,6 +834,7 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
// Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump. // Create a new environment for the body. With everything but the jump reuse tokens. As those should be given by the jump.
let mut body_environment = ReuseEnvironment { let mut body_environment = ReuseEnvironment {
symbol_tags: environment.symbol_tags.clone(), symbol_tags: environment.symbol_tags.clone(),
non_unique_symbols: environment.non_unique_symbols.clone(),
reuse_tokens: used_reuse_tokens.clone(), reuse_tokens: used_reuse_tokens.clone(),
symbol_layouts: environment.symbol_layouts.clone(), symbol_layouts: environment.symbol_layouts.clone(),
joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(), joinpoint_reuse_tokens: environment.joinpoint_reuse_tokens.clone(),
@ -1082,6 +1095,7 @@ enum JoinPointReuseTokens<'a> {
#[derive(Default, Clone)] #[derive(Default, Clone)]
struct ReuseEnvironment<'a> { struct ReuseEnvironment<'a> {
symbol_tags: MutMap<Symbol, Tag>, symbol_tags: MutMap<Symbol, Tag>,
non_unique_symbols: MutSet<Symbol>,
reuse_tokens: ReuseTokens<'a>, reuse_tokens: ReuseTokens<'a>,
symbol_layouts: SymbolLayout<'a>, symbol_layouts: SymbolLayout<'a>,
// A map containing the amount of reuse tokens a join point expects for each layout. // A map containing the amount of reuse tokens a join point expects for each layout.