updated tuple pass

This commit is contained in:
Edward Chen
2022-05-25 02:42:24 -04:00
parent f29eec8d7b
commit 01d5b3bcfa
5 changed files with 67 additions and 42 deletions

View File

@@ -2,8 +2,8 @@
* Example on how to merge two data sets and to perform various analyses
*/
#define LEN_A 11
#define LEN_B 11
#define LEN_A 7
#define LEN_B 7
#define ATT_A 2 //Number of attributes
#define ATT_B 2

View File

@@ -256,8 +256,8 @@ fn main() {
// The linear scan pass produces more tuples, that must be eliminated
Opt::Tuple,
Opt::ConstantFold(Box::new(ignore.clone())),
// Inline Function Calls
Opt::InlineCalls,
// // Inline Function Calls
// Opt::InlineCalls,
// Binarize nary terms
Opt::Binarize,
],
@@ -288,21 +288,21 @@ fn main() {
),
};
for (name, comp) in cs.computations.iter() {
println!("functions: {}", name);
for t in &comp.outputs {
println!("function term: {}, {}", t, t.uid());
// for t1 in PostOrderIter::new(t.clone()) {
// println!("term: {}, {}", t1, t1.uid());
// for c in t1.cs.iter() {
// println!("children: {}, {}", c, c.uid());
// }
// println!();
// }
println!();
}
println!("\n");
}
// for (name, comp) in cs.computations.iter() {
// println!("functions: {}", name);
// for t in &comp.outputs {
// println!("function term: {}, {}", t, t.uid());
// for t1 in PostOrderIter::new(t.clone()) {
// println!("term: {}, {}", t1, t1.uid());
// for c in t1.cs.iter() {
// println!("children: {}, {}", c, c.uid());
// }
// println!();
// }
// println!();
// }
// println!("\n");
// }
println!("Done with IR optimization");

View File

@@ -30,10 +30,10 @@ function mpc_test_2 {
RUST_BACKTRACE=1 measure_time $BIN --parties $parties $cpath mpc --cost-model "hycc" --selection-scheme "a+b"
}
mpc_test_2 2 ./examples/C/mpc/playground.c
# mpc_test_2 2 ./examples/C/mpc/playground.c
# mpc_test 2 ./examples/C/mpc/benchmarks/kmeans/2pc_kmeans_.c
# mpc_test_2 2 ./examples/C/mpc/benchmarks/gauss/2pc_gauss_inline.c
# mpc_test_2 2 ./examples/C/mpc/benchmarks/db/db_join.c
mpc_test_2 2 ./examples/C/mpc/benchmarks/db/db_join.c
# # build mpc arithmetic tests
# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_add.c

View File

@@ -39,16 +39,12 @@ fn match_arg(name: &String, params: &BTreeMap<String, Term>) -> Term {
fn inline(name: &str, params: BTreeMap<String, Term>, fs: &Functions) -> Vec<Term> {
let mut res: Vec<Term> = Vec::new();
let comp = fs.computations.get(name).unwrap();
println!("Comp: {}", name);
println!("params: {:#?}", params);
for o in comp.outputs.iter() {
println!("o: {}", o);
let mut cache = TermMap::new();
for t in PostOrderIter::new(o.clone()) {
match &t.op {
Op::Var(name, _) => {
let ret = match_arg(name, &params);
println!("ret: {}", ret);
cache.insert(t.clone(), ret.clone());
}
_ => {
@@ -66,7 +62,6 @@ fn inline(name: &str, params: BTreeMap<String, Term>, fs: &Functions) -> Vec<Ter
}
res.push(cache.get(o).unwrap().clone());
}
println!("res: {:#?}", res);
res
}
@@ -78,13 +73,10 @@ pub fn inline_function_calls(
) -> Term {
let mut call_cache: HashMap<Term, Vec<Term>> = HashMap::new();
for t in PostOrderIter::new(term_.clone()) {
println!("inline t: {}", t);
let mut children = Vec::new();
for c in &t.cs {
if let Some(rewritten_c) = rewritten.get(c) {
if !call_cache.contains_key(c) {
children.push(rewritten_c.clone());
}
children.push(rewritten_c.clone());
} else {
children.push(c.clone());
}
@@ -164,7 +156,6 @@ pub fn inline_function_calls(
}
_ => term(t.op.clone(), children),
};
println!("rewritten: {}\n", entry);
rewritten.insert(t.clone(), entry);
}

View File

@@ -60,8 +60,7 @@
//! fast vector type, instead of standard terms. This allows for log-time updates.
use crate::ir::term::{
bv_lit, check, leaf_term, term, Array, Computation, Op, PostOrderIter, Sort, Term, TermMap,
Value, AND,
check, leaf_term, term, Array, Computation, Op, PostOrderIter, Sort, Term, TermMap, Value, AND,
};
use std::collections::BTreeMap;
@@ -108,13 +107,22 @@ impl TupleTree {
}
fn get(&self, i: usize) -> Self {
match self {
TupleTree::NonTuple(cs) => match cs.op {
Op::Call(..) => TupleTree::NonTuple(term![Op::Field(i); cs.clone()]),
_ => panic!("Get ({}) on non-tuple {:?}", i, self),
},
TupleTree::NonTuple(cs) => panic!("Get ({}) on non-tuple {:?}", i, self),
TupleTree::Tuple(t) => {
assert!(i < t.len());
t.get(i).unwrap().clone()
if let TupleTree::NonTuple(leaf) = &t[0] {
if t.len() == 1 {
let new_leaf = TupleTree::NonTuple(term![Op::Field(i); leaf.clone()]);
let mut tree: im::Vector<TupleTree> = im::Vector::new();
tree.push_back(new_leaf);
TupleTree::Tuple(tree)
} else {
assert!(i < t.len());
t.get(i).unwrap().clone()
}
} else {
assert!(i < t.len());
t.get(i).unwrap().clone()
}
}
}
}
@@ -122,15 +130,35 @@ impl TupleTree {
match self {
TupleTree::NonTuple(cs) => panic!("Update ({}) on non-tuple {:?}", i, self),
TupleTree::Tuple(t) => {
assert!(i < t.len());
TupleTree::Tuple(t.update(i, v.clone()))
if let TupleTree::NonTuple(leaf) = &t[0] {
if t.len() == 1 {
let new_leaf = TupleTree::NonTuple(
term![Op::Update(i); leaf.clone(), v.clone().unwrap_non_tuple()],
);
let mut tree: im::Vector<TupleTree> = im::Vector::new();
tree.push_back(new_leaf);
TupleTree::Tuple(tree)
} else {
assert!(i < t.len());
TupleTree::Tuple(t.update(i, v.clone()))
}
} else {
assert!(i < t.len());
TupleTree::Tuple(t.update(i, v.clone()))
}
}
}
}
fn unwrap_non_tuple(self) -> Term {
match self {
TupleTree::NonTuple(t) => t,
_ => panic!("{:?} is tuple!", self),
TupleTree::Tuple(t) => {
assert!(t.len() == 1);
match t[0].clone() {
TupleTree::NonTuple(nt) => nt.clone(),
_ => panic!("{:?} is tuple!", t),
}
}
}
}
}
@@ -262,6 +290,12 @@ pub fn eliminate_tuples(cs: &mut Computation) {
t.update(*i, &v)
}
Op::Tuple => TupleTree::Tuple(cs.into()),
Op::Call(..) => {
let leaf = TupleTree::NonTuple(t.clone());
let mut tree: im::Vector<TupleTree> = im::Vector::new();
tree.push_back(leaf);
TupleTree::Tuple(tree)
}
_ => TupleTree::NonTuple(term(
t.op.clone(),
cs.into_iter().map(|c| c.unwrap_non_tuple()).collect(),