Skip to content

Commit

Permalink
Merge pull request #75 from Y-Nak/side-effect
Browse files Browse the repository at this point in the history
Introduce `SideEffect`
  • Loading branch information
Y-Nak authored Oct 14, 2024
2 parents f4e7b9e + 49e0fc2 commit 495e3f7
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 70 deletions.
3 changes: 2 additions & 1 deletion crates/codegen/src/optim/adce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::collections::BTreeSet;
use cranelift_entity::SecondaryMap;
use sonatina_ir::{
func_cursor::{CursorLocation, FuncCursor, InstInserter},
inst::SideEffect,
BlockId, Function, InstId,
};

Expand Down Expand Up @@ -56,7 +57,7 @@ impl AdceSolver {

for block in func.layout.iter_block() {
for inst in func.layout.iter_inst(block) {
if func.dfg.has_side_effect(inst) {
if matches!(func.dfg.side_effect(inst), SideEffect::Write) {
self.mark_inst(func, inst);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/src/optim/licm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl LicmSolver {

/// Returns `true` if the `inst` is safe to hoist.
fn is_safe_to_hoist(&self, func: &Function, inst_id: InstId) -> bool {
!(func.dfg.has_side_effect(inst_id)
!(func.dfg.side_effect(inst_id).has_effect()
|| func.dfg.is_branch(inst_id)
|| func.dfg.is_phi(inst_id))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/src/optim/sccp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl SccpSolver {
};

let inst = func.dfg.inst(inst_id);
if inst.has_side_effect() {
if inst.side_effect().has_effect() {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions crates/ir/src/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{Immediate, Type, Value, ValueId};
use crate::{
inst::{
control_flow::{self, Branch, Jump, Phi},
InstId,
InstId, SideEffect,
},
ir_writer::{FuncWriteCtx, WriteWithFunc},
module::ModuleCtx,
Expand Down Expand Up @@ -244,8 +244,8 @@ impl DataFlowGraph {
self.users[alias].append(&mut users);
}

pub fn has_side_effect(&self, inst: InstId) -> bool {
self.inst(inst).has_side_effect()
pub fn side_effect(&self, inst: InstId) -> SideEffect {
self.inst(inst).side_effect()
}

pub fn is_branch(&self, inst: InstId) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions crates/ir/src/inst/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl InstWrite for Phi {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
#[inst(side_effect(super::SideEffect::Write))]
#[inst(terminator)]
pub struct Call {
callee: FuncRef,
Expand Down Expand Up @@ -143,7 +143,7 @@ impl InstWrite for Call {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
#[inst(side_effect(super::SideEffect::Write))]
#[inst(terminator)]
pub struct Return {
#[inst(value)]
Expand Down
4 changes: 2 additions & 2 deletions crates/ir/src/inst/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use smallvec::SmallVec;
use crate::{inst::impl_inst_write, Type, ValueId};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
#[inst(side_effect(super::SideEffect::Read))]
pub struct Mload {
#[inst(value)]
addr: ValueId,
Expand All @@ -13,7 +13,7 @@ pub struct Mload {
impl_inst_write!(Mload, (addr: ValueId, ty: Type));

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Inst)]
#[inst(has_side_effect)]
#[inst(side_effect(super::SideEffect::Write))]
pub struct Mstore {
#[inst(value)]
value: ValueId,
Expand Down
Loading

0 comments on commit 495e3f7

Please sign in to comment.