Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • llvm/hercules
1 result
Show changes
...@@ -281,6 +281,13 @@ impl ModuleSelection { ...@@ -281,6 +281,13 @@ impl ModuleSelection {
} }
} }
#[derive(Debug, Clone)]
pub enum SetOp {
Difference,
Union,
Intersection,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Value { pub enum Value {
Label { Label {
...@@ -303,7 +310,7 @@ pub enum Value { ...@@ -303,7 +310,7 @@ pub enum Value {
selection: Vec<Value>, selection: Vec<Value>,
}, },
SetOp { SetOp {
op: parser::SetOp, op: SetOp,
lhs: Box<Value>, lhs: Box<Value>,
rhs: Box<Value>, rhs: Box<Value>,
}, },
...@@ -364,9 +371,9 @@ impl Value { ...@@ -364,9 +371,9 @@ impl Value {
let lhs = lhs.as_selection(pm, funcs)?; let lhs = lhs.as_selection(pm, funcs)?;
let rhs = rhs.as_selection(pm, funcs)?; let rhs = rhs.as_selection(pm, funcs)?;
let res = match op { let res = match op {
parser::SetOp::Union => lhs.union(rhs), SetOp::Union => lhs.union(rhs),
parser::SetOp::Intersection => lhs.intersection(rhs), SetOp::Intersection => lhs.intersection(rhs),
parser::SetOp::Difference => lhs.difference(rhs), SetOp::Difference => lhs.difference(rhs),
}; };
selection.add(res); selection.add(res);
} }
...@@ -1301,17 +1308,62 @@ fn interp_expr( ...@@ -1301,17 +1308,62 @@ fn interp_expr(
ScheduleExp::Integer { val } => Ok((Value::Integer { val: *val }, false)), ScheduleExp::Integer { val } => Ok((Value::Integer { val: *val }, false)),
ScheduleExp::Boolean { val } => Ok((Value::Boolean { val: *val }, false)), ScheduleExp::Boolean { val } => Ok((Value::Boolean { val: *val }, false)),
ScheduleExp::String { val } => Ok((Value::String { val: val.clone() }, false)), ScheduleExp::String { val } => Ok((Value::String { val: val.clone() }, false)),
ScheduleExp::SetOp { op, lhs, rhs } => { ScheduleExp::UnaryOp { op, exp } => {
let (exp, modified) = interp_expr(pm, exp, stringtab, env, functions)?;
match op {
parser::UnaryOp::Not => {
let Value::Boolean { val } = exp else {
return Err(SchedulerError::SemanticError(
"Not can only be applied to boolean values".to_string(),
));
};
Ok((Value::Boolean { val: !val }, modified))
}
}
}
ScheduleExp::BinaryOp { op, lhs, rhs } => {
let (lhs, lhs_mod) = interp_expr(pm, lhs, stringtab, env, functions)?; let (lhs, lhs_mod) = interp_expr(pm, lhs, stringtab, env, functions)?;
let (rhs, rhs_mod) = interp_expr(pm, rhs, stringtab, env, functions)?; let (rhs, rhs_mod) = interp_expr(pm, rhs, stringtab, env, functions)?;
Ok(( match op {
Value::SetOp { parser::BinaryOp::Difference
op: *op, | parser::BinaryOp::Union
lhs: Box::new(lhs), | parser::BinaryOp::Intersection => Ok((
rhs: Box::new(rhs), Value::SetOp {
}, op: match op {
lhs_mod || rhs_mod, parser::BinaryOp::Difference => SetOp::Difference,
)) parser::BinaryOp::Union => SetOp::Union,
parser::BinaryOp::Intersection => SetOp::Intersection,
_ => panic!(),
},
lhs: Box::new(lhs),
rhs: Box::new(rhs),
},
lhs_mod || rhs_mod,
)),
parser::BinaryOp::Or | parser::BinaryOp::And => {
let (Value::Boolean { val: lhs }, Value::Boolean { val: rhs }) = (lhs, rhs)
else {
return Err(SchedulerError::SemanticError(format!(
"{} can only be applied to boolean values",
match op {
parser::BinaryOp::Or => "or",
parser::BinaryOp::And => "and",
_ => panic!(),
},
)));
};
Ok((
Value::Boolean {
val: match op {
parser::BinaryOp::Or => lhs || rhs,
parser::BinaryOp::And => lhs && rhs,
_ => panic!(),
},
},
lhs_mod || rhs_mod,
))
}
}
} }
ScheduleExp::Field { collect, field } => { ScheduleExp::Field { collect, field } => {
let (lhs, changed) = interp_expr(pm, collect, stringtab, env, functions)?; let (lhs, changed) = interp_expr(pm, collect, stringtab, env, functions)?;
...@@ -2780,7 +2832,7 @@ fn run_pass( ...@@ -2780,7 +2832,7 @@ fn run_pass(
} }
pm.delete_gravestones(); pm.delete_gravestones();
pm.clear_analyses(); pm.clear_analyses();
}, }
Pass::ForkFission => { Pass::ForkFission => {
assert!(args.len() == 1); assert!(args.len() == 1);
...@@ -2794,7 +2846,6 @@ fn run_pass( ...@@ -2794,7 +2846,6 @@ fn run_pass(
}); });
}; };
pm.make_fork_join_maps(); pm.make_fork_join_maps();
pm.make_loops(); pm.make_loops();
pm.make_reduce_cycles(); pm.make_reduce_cycles();
...@@ -2817,18 +2868,18 @@ fn run_pass( ...@@ -2817,18 +2868,18 @@ fn run_pass(
let fork_label = fork_labels[0].label; let fork_label = fork_labels[0].label;
for ((((func, fork_join_map), loop_tree), reduce_cycles), nodes_in_fork_joins, for ((((func, fork_join_map), loop_tree), reduce_cycles), nodes_in_fork_joins) in
) in build_selection(pm, selection, false) build_selection(pm, selection, false)
.into_iter() .into_iter()
.zip(fork_join_maps.iter()) .zip(fork_join_maps.iter())
.zip(loops.iter()) .zip(loops.iter())
.zip(reduce_cycles.iter()) .zip(reduce_cycles.iter())
.zip(nodes_in_fork_joins.iter()) .zip(nodes_in_fork_joins.iter())
{ {
let Some(mut func) = func else { let Some(mut func) = func else {
continue; continue;
}; };
let new_forks = fork_fission( let new_forks = fork_fission(
&mut func, &mut func,
nodes_in_fork_joins, nodes_in_fork_joins,
...@@ -2837,12 +2888,12 @@ fn run_pass( ...@@ -2837,12 +2888,12 @@ fn run_pass(
fork_join_map, fork_join_map,
fork_label, fork_label,
); );
let created_fork_joins = &mut created_fork_joins[func.func_id().idx()]; let created_fork_joins = &mut created_fork_joins[func.func_id().idx()];
for f in new_forks { for f in new_forks {
created_fork_joins.push(f); created_fork_joins.push(f);
}; }
changed |= func.modified(); changed |= func.modified();
} }
...@@ -2899,8 +2950,7 @@ fn run_pass( ...@@ -2899,8 +2950,7 @@ fn run_pass(
result = Value::Record { result = Value::Record {
fields: new_fork_joins, fields: new_fork_joins,
}; };
}
},
Pass::ForkFissionBufferize => { Pass::ForkFissionBufferize => {
assert!(args.len() == 1 || args.len() == 2); assert!(args.len() == 1 || args.len() == 2);
let Some(Value::Label { let Some(Value::Label {
......