ir_semantics.rs 2.76 KB
Newer Older
1 2
use inst::*;
use inst::Instruction_::*;
3 4 5

pub fn is_terminal_inst(inst: &Instruction_) -> bool {
    match inst {
qinsoon's avatar
qinsoon committed
6 7
        &BinOp(_, _, _)
        | &BinOpWithStatus(_, _, _, _)
8
        | &CmpOp(_, _, _)
qinsoon's avatar
qinsoon committed
9
        | &ConvOp{..}
10
        | &ExprCall{..}
qinsoon's avatar
qinsoon committed
11
        | &ExprCCall{..}
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
        | &Load{..}
        | &Store{..}
        | &CmpXchg{..}
        | &AtomicRMW{..}
        | &New(_)
        | &AllocA(_)
        | &NewHybrid(_, _)
        | &AllocAHybrid(_, _)
        | &NewStack(_)
        | &NewThread(_, _)
        | &NewThreadExn(_, _)
        | &NewFrameCursor(_)
        | &GetIRef(_)
        | &GetFieldIRef{..}
        | &GetElementIRef{..}
        | &ShiftIRef{..}
        | &GetVarPartIRef{..}
qinsoon's avatar
qinsoon committed
29
        | &Select{..}
30 31
        | &Fence(_)
        | &CommonInst_GetThreadLocal
32
        | &CommonInst_SetThreadLocal(_)
33 34
        | &CommonInst_Pin(_)
        | &CommonInst_Unpin(_)
35
        | &Move(_) => false,
36 37 38 39 40 41 42 43 44
        &Return(_)
        | &ThreadExit
        | &Throw(_)
        | &TailCall(_)
        | &Branch1(_)
        | &Branch2{..}
        | &Watchpoint{..}
        | &WPBranch{..}
        | &Call{..}
qinsoon's avatar
qinsoon committed
45
        | &CCall{..}
46 47 48 49 50 51 52 53 54 55 56 57 58 59
        | &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,
qinsoon's avatar
qinsoon committed
60
        &BinOpWithStatus(_, _, _, _) => false,
61
        &CmpOp(_, _, _) => false,
qinsoon's avatar
qinsoon committed
62
        &ConvOp{..} => false,
63
        &ExprCall{..} => true,
qinsoon's avatar
qinsoon committed
64
        &ExprCCall{..} => true,
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        &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,
qinsoon's avatar
qinsoon committed
89
        &Select{..} => false,
90 91 92
        &Watchpoint{..} => true,
        &WPBranch{..} => true,
        &Call{..} => true,
qinsoon's avatar
qinsoon committed
93
        &CCall{..} => true,
94 95
        &SwapStack{..} => true,
        &Switch{..} => true,
96 97 98
        &ExnInstruction{..} => true,
        &CommonInst_GetThreadLocal => true,
        &CommonInst_SetThreadLocal(_) => true,
99 100
        &CommonInst_Pin(_) => true,
        &CommonInst_Unpin(_) => true,
101
        &Move(_) => false,
102
    }
103
}