Skip to content
Snippets Groups Projects
Commit 6f997c94 authored by Russel Arbore's avatar Russel Arbore
Browse files

Rust futures are :):(

parent d9046f51
No related branches found
No related tags found
1 merge request!193Fix parallel code gen in RT backend
Pipeline #201788 failed
This commit is part of merge request !193. Comments created here will be created in the context of that merge request.
...@@ -138,7 +138,6 @@ struct RTContext<'a> { ...@@ -138,7 +138,6 @@ struct RTContext<'a> {
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
struct RustBlock { struct RustBlock {
prologue: String, prologue: String,
arc_clones: String,
data: String, data: String,
phi_tmp_assignments: String, phi_tmp_assignments: String,
phi_assignments: String, phi_assignments: String,
...@@ -269,9 +268,8 @@ impl<'a> RTContext<'a> { ...@@ -269,9 +268,8 @@ impl<'a> RTContext<'a> {
} else { } else {
write!( write!(
w, w,
"{}{}{}{}{}{}", "{}{}{}{}{}",
block.prologue, block.prologue,
block.arc_clones,
block.data, block.data,
block.phi_tmp_assignments, block.phi_tmp_assignments,
block.phi_assignments, block.phi_assignments,
...@@ -361,6 +359,16 @@ impl<'a> RTContext<'a> { ...@@ -361,6 +359,16 @@ impl<'a> RTContext<'a> {
write!(prologue, " {{")?; write!(prologue, " {{")?;
} }
// Emit clones of arcs used inside the fork-join.
for other_id in (0..func.nodes.len()).map(NodeID::new) {
if self.def_use.get_users(other_id).into_iter().any(|user_id| {
self.nodes_in_fork_joins[&id].contains(&self.bbs.0[user_id.idx()])
}) && let Some(arc) = self.clone_arc(other_id)
{
write!(prologue, "{}", arc)?;
}
}
// Spawn an async closure and push its future to a Vec. // Spawn an async closure and push its future to a Vec.
write!( write!(
prologue, prologue,
...@@ -569,13 +577,12 @@ impl<'a> RTContext<'a> { ...@@ -569,13 +577,12 @@ impl<'a> RTContext<'a> {
// The device backends ensure that device functions have the // The device backends ensure that device functions have the
// same interface as AsyncRust functions. // same interface as AsyncRust functions.
let block = &mut blocks.get_mut(&bb).unwrap(); let block = &mut blocks.get_mut(&bb).unwrap();
let arc_clones = &mut block.arc_clones;
let block = &mut block.data; let block = &mut block.data;
let is_async = func.schedules[id.idx()].contains(&Schedule::AsyncCall); let is_async = func.schedules[id.idx()].contains(&Schedule::AsyncCall);
if is_async { if is_async {
for arg in args { for arg in args {
if let Some(arc) = self.clone_arc(*arg) { if let Some(arc) = self.clone_arc(*arg) {
write!(arc_clones, "{}", arc)?; write!(block, "{}", arc)?;
} }
} }
} }
...@@ -585,7 +592,7 @@ impl<'a> RTContext<'a> { ...@@ -585,7 +592,7 @@ impl<'a> RTContext<'a> {
format!("{} = ", self.get_value(id, bb, true)) format!("{} = ", self.get_value(id, bb, true))
} }
(_, true) => { (_, true) => {
write!(arc_clones, "{}", self.clone_arc(id).unwrap())?; write!(block, "{}", self.clone_arc(id).unwrap())?;
format!( format!(
"*async_call_{}.lock().await = Some(::async_std::task::spawn(async move {{ ", "*async_call_{}.lock().await = Some(::async_std::task::spawn(async move {{ ",
id.idx(), id.idx(),
......
no-memset(test6@const);
ccp(*); ccp(*);
gvn(*); gvn(*);
phi-elim(*); phi-elim(*);
...@@ -63,7 +61,9 @@ gvn(*); ...@@ -63,7 +61,9 @@ gvn(*);
phi-elim(*); phi-elim(*);
dce(*); dce(*);
fork-tile[32, 0, false, true](test6@loop); async-call(test6@call);
no-memset(test6@const);
fork-tile[2, 0, false, false](test6@loop);
let out = fork-split(test6@loop); let out = fork-split(test6@loop);
let out = outline(out.test6.fj1); let out = outline(out.test6.fj1);
cpu(out); cpu(out);
......
...@@ -73,11 +73,16 @@ fn test5(input : i32) -> i32[4] { ...@@ -73,11 +73,16 @@ fn test5(input : i32) -> i32[4] {
return arr1; return arr1;
} }
fn test6_helper(input: i32) -> i32 {
return input;
}
#[entry] #[entry]
fn test6(input: i32) -> i32[1024] { fn test6(input: i32) -> i32[1024] {
@call let x = test6_helper(input);
@const let arr : i32[1024]; @const let arr : i32[1024];
@loop for i = 0 to 1024 { @loop for i = 0 to 1024 {
arr[i] = i as i32 + input; arr[i] = i as i32 + x;
} }
return arr; return arr;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment