ir_semantics.rs 2.23 KB
Newer Older
qinsoon's avatar
qinsoon committed
1 2
use inst::*;
use inst::Instruction_::*;
3 4 5 6 7

pub fn is_terminal_inst(inst: &Instruction_) -> bool {
    match inst {
        &BinOp(_, _, _) 
        | &CmpOp(_, _, _)
qinsoon's avatar
qinsoon committed
8
        | &ConvOp{..}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        | &ExprCall{..}
        | &Load{..}
        | &Store{..}
        | &CmpXchg{..}
        | &AtomicRMW{..}
        | &New(_)
        | &AllocA(_)
        | &NewHybrid(_, _)
        | &AllocAHybrid(_, _)
        | &NewStack(_)
        | &NewThread(_, _)
        | &NewThreadExn(_, _)
        | &NewFrameCursor(_)
        | &GetIRef(_)
        | &GetFieldIRef{..}
        | &GetElementIRef{..}
        | &ShiftIRef{..}
        | &GetVarPartIRef{..}
        | &Fence(_) => false,
        &Return(_)
        | &ThreadExit
        | &Throw(_)
        | &TailCall(_)
        | &Branch1(_)
        | &Branch2{..}
        | &Watchpoint{..}
        | &WPBranch{..}
        | &Call{..}
qinsoon's avatar
qinsoon committed
37
        | &CCall{..}
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
        | &SwapStack{..}
        | &Switch{..}
        | &ExnInstruction{..} => true
    }
}

pub fn is_non_terminal_inst(inst: &Instruction_) -> bool {
    !is_terminal_inst(inst)
}

// FIXME: check the correctness
pub fn has_side_effect(inst: &Instruction_) -> bool {
    match inst {
        &BinOp(_, _, _) => false,
        &CmpOp(_, _, _) => false,
qinsoon's avatar
qinsoon committed
53
        &ConvOp{..} => false,
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        &ExprCall{..} => true,
        &Load{..} => true,
        &Store{..} => true,
        &CmpXchg{..} => true,
        &AtomicRMW{..} => true,
        &New(_) => true,
        &AllocA(_) => true,
        &NewHybrid(_, _) => true,
        &AllocAHybrid(_, _) => true,
        &NewStack(_) => true,
        &NewThread(_, _) => true,
        &NewThreadExn(_, _) => true,
        &NewFrameCursor(_) => true,
        &GetIRef(_) => false,
        &GetFieldIRef{..} => false,
        &GetElementIRef{..} => false,
        &ShiftIRef{..} => false,
        &GetVarPartIRef{..} => false,
        &Fence(_) => true,
        &Return(_) => true,
        &ThreadExit => true,
        &Throw(_) => true,
        &TailCall(_) => true,
        &Branch1(_) => true,
        &Branch2{..} => true,
        &Watchpoint{..} => true,
        &WPBranch{..} => true,
        &Call{..} => true,
qinsoon's avatar
qinsoon committed
82
        &CCall{..} => true,
83 84 85 86
        &SwapStack{..} => true,
        &Switch{..} => true,
        &ExnInstruction{..} => true
    }
87
}