Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpal committed May 27, 2024
1 parent eb03bdf commit c39f93b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
24 changes: 12 additions & 12 deletions dag_in_context/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
//! shared as the same Rc pointer. Otherwise, effects may be executed multiple times.
//! The invariant is maintained by translation from RVSDG, type checking, and translation from egglog.

use std::{collections::HashMap, fmt::Display, ops::{Shl, Shr}, rc::Rc};
use std::{
collections::HashMap,
fmt::Display,
ops::{Shl, Shr},
rc::Rc,
};

use crate::{
schema::{BinaryOp, Constant, Expr, RcExpr, TernaryOp, TreeProgram, UnaryOp},
Expand Down Expand Up @@ -246,18 +251,14 @@ impl<'a> VirtualMachine<'a> {
let a = get_int(e1, self);
let b = get_int(e2, self);
Const(Constant::Int(if a > b { a } else { b }))
},
}
BinaryOp::Smin => {
let a = get_int(e1, self);
let b = get_int(e2, self);
Const(Constant::Int(if a < b { a } else { b }))
},
BinaryOp::Shl => Const(Constant::Int(
get_int(e1, self).shl(get_int(e2, self))
)),
BinaryOp::Shr => Const(Constant::Int(
get_int(e1, self).shr(get_int(e2, self))
)),
}
BinaryOp::Shl => Const(Constant::Int(get_int(e1, self).shl(get_int(e2, self)))),
BinaryOp::Shr => Const(Constant::Int(get_int(e1, self).shr(get_int(e2, self)))),
BinaryOp::Eq => Const(Constant::Bool(get_int(e1, self) == get_int(e2, self))),
BinaryOp::LessThan => Const(Constant::Bool(get_int(e1, self) < get_int(e2, self))),
BinaryOp::GreaterThan => Const(Constant::Bool(get_int(e1, self) > get_int(e2, self))),
Expand Down Expand Up @@ -323,13 +324,12 @@ impl<'a> VirtualMachine<'a> {
let a = get_float(e1, self);
let b = get_float(e2, self);
Const(Constant::Float(if a > b { a } else { b }))
},
}
BinaryOp::Fmin => {
let a = get_float(e1, self);
let b = get_float(e2, self);
Const(Constant::Float(if a < b { a } else { b }))
},

}
}
}

Expand Down
6 changes: 4 additions & 2 deletions dag_in_context/src/optimizations/purity_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ fn top_is_pure(top: &TernaryOp) -> bool {
fn bop_is_pure(bop: &BinaryOp) -> bool {
use BinaryOp::*;
match bop {
Add | Sub | Mul | LessThan | Div | Eq | GreaterThan | LessEq | GreaterEq | Smax | Smin | Shl | Shr => true,
FAdd | FSub | FMul | FLessThan | FDiv | FEq | FGreaterThan | FLessEq | FGreaterEq | Fmax | Fmin => true,
Add | Sub | Mul | LessThan | Div | Eq | GreaterThan | LessEq | GreaterEq | Smax | Smin
| Shl | Shr => true,
FAdd | FSub | FMul | FLessThan | FDiv | FEq | FGreaterThan | FLessEq | FGreaterEq
| Fmax | Fmin => true,
PtrAdd => true,
And | Or => true,
Load | Print | Free => false,
Expand Down
20 changes: 14 additions & 6 deletions dag_in_context/src/schema_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,20 @@ impl BinaryOp {
/// When a binary op has concrete input sorts, return them.
pub fn types(&self) -> Option<(Type, Type, Type)> {
match self {
BinaryOp::Add | BinaryOp::Sub | BinaryOp::Mul | BinaryOp::Div | BinaryOp::Smax | BinaryOp::Smin | BinaryOp::Shl | BinaryOp::Shr => {
Some((base(intt()), base(intt()), base(intt())))
}
BinaryOp::FAdd | BinaryOp::FSub | BinaryOp::FMul | BinaryOp::FDiv | BinaryOp::Fmax | BinaryOp::Fmin => {
Some((base(floatt()), base(floatt()), base(floatt())))
}
BinaryOp::Add
| BinaryOp::Sub
| BinaryOp::Mul
| BinaryOp::Div
| BinaryOp::Smax
| BinaryOp::Smin
| BinaryOp::Shl
| BinaryOp::Shr => Some((base(intt()), base(intt()), base(intt()))),
BinaryOp::FAdd
| BinaryOp::FSub
| BinaryOp::FMul
| BinaryOp::FDiv
| BinaryOp::Fmax
| BinaryOp::Fmin => Some((base(floatt()), base(floatt()), base(floatt()))),
BinaryOp::And | BinaryOp::Or => Some((base(boolt()), base(boolt()), base(boolt()))),
BinaryOp::LessThan
| BinaryOp::GreaterThan
Expand Down

0 comments on commit c39f93b

Please sign in to comment.