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

Fix index math for multiple indices, read chains work just w/o SROA

parent 0a1c166d
No related branches found
No related tags found
1 merge request!119Read chains
Pipeline #201115 passed
......@@ -638,7 +638,7 @@ impl<'a> CPUContext<'a> {
fn codegen_index_math(
&self,
collect_name: &str,
collect_ty: TypeID,
mut collect_ty: TypeID,
indices: &[Index],
body: &mut String,
) -> Result<String, Error> {
......@@ -666,10 +666,15 @@ impl<'a> CPUContext<'a> {
body,
)?;
acc_ptr = Self::gep(&acc_ptr, &acc_offset, body)?;
collect_ty = fields[*idx];
}
Index::Variant(_) => {
Index::Variant(idx) => {
// The tag of a summation is at the end of the summation, so
// the variant pointer is just the base pointer. Do nothing.
let Type::Summation(ref variants) = self.types[collect_ty.idx()] else {
panic!()
};
collect_ty = variants[*idx];
}
Index::Position(ref pos) => {
let Type::Array(elem, ref dims) = self.types[collect_ty.idx()] else {
......@@ -691,6 +696,7 @@ impl<'a> CPUContext<'a> {
// Convert offset in # elements -> # bytes.
acc_offset = Self::multiply(&acc_offset, &elem_size, body)?;
acc_ptr = Self::gep(&acc_ptr, &acc_offset, body)?;
collect_ty = elem;
}
}
}
......
......@@ -612,7 +612,11 @@ impl<'a> RTContext<'a> {
/*
* Emit logic to index into an collection.
*/
fn codegen_index_math(&self, collect_ty: TypeID, indices: &[Index]) -> Result<String, Error> {
fn codegen_index_math(
&self,
mut collect_ty: TypeID,
indices: &[Index],
) -> Result<String, Error> {
let mut acc_offset = "0".to_string();
for index in indices {
match index {
......@@ -642,10 +646,15 @@ impl<'a> RTContext<'a> {
last_align - 1,
last_align - 1
);
collect_ty = fields[*idx];
}
Index::Variant(_) => {
Index::Variant(idx) => {
// The tag of a summation is at the end of the summation, so
// the variant pointer is just the base pointer. Do nothing.
let Type::Summation(ref variants) = self.module.types[collect_ty.idx()] else {
panic!()
};
collect_ty = variants[*idx];
}
Index::Position(ref pos) => {
let Type::Array(elem, ref dims) = self.module.types[collect_ty.idx()] else {
......@@ -665,6 +674,7 @@ impl<'a> RTContext<'a> {
// Convert offset in # elements -> # bytes.
acc_offset = format!("({} * {})", acc_offset, elem_size);
collect_ty = elem;
}
}
}
......
......@@ -167,7 +167,7 @@ pub fn compile_ir(
// Run SROA pretty early (though after inlining which can make SROA more effective) so that
// CCP, GVN, etc. can work on the result of SROA
add_pass!(pm, verify, InterproceduralSROA);
add_pass!(pm, verify, SROA);
//add_pass!(pm, verify, SROA);
// We run phi-elim again because SROA can introduce new phis that might be able to be
// simplified
add_verified_pass!(pm, verify, PhiElim);
......@@ -203,7 +203,7 @@ pub fn compile_ir(
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, Outline);
add_pass!(pm, verify, InterproceduralSROA);
add_pass!(pm, verify, SROA);
//add_pass!(pm, verify, SROA);
add_pass!(pm, verify, InferSchedules);
add_verified_pass!(pm, verify, DCE);
if x_dot {
......
......@@ -117,5 +117,8 @@ fn read_chains(input : i32) -> i32 {
let sub = arrs.0;
sub[1] = input + 7;
arrs.0[1] = input + 3;
return sub[1] + arrs.0[1];
let result = sub[1] + arrs.0[1];
sub[1] = 99;
arrs.0[1] = 99;
return result + sub[1] - arrs.0[1];
}
\ No newline at end of file
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