ir_semantics.rs 4.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2017 The Australian National University
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

qinsoon's avatar
qinsoon committed
15 16
use inst::*;
use inst::Instruction_::*;
17 18 19

pub fn is_terminal_inst(inst: &Instruction_) -> bool {
    match inst {
qinsoon's avatar
qinsoon committed
20 21
        &BinOp(_, _, _)
        | &BinOpWithStatus(_, _, _, _)
22
        | &CmpOp(_, _, _)
qinsoon's avatar
qinsoon committed
23
        | &ConvOp{..}
24
        | &ExprCall{..}
qinsoon's avatar
qinsoon committed
25
        | &ExprCCall{..}
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
        | &Load{..}
        | &Store{..}
        | &CmpXchg{..}
        | &AtomicRMW{..}
        | &New(_)
        | &AllocA(_)
        | &NewHybrid(_, _)
        | &AllocAHybrid(_, _)
        | &NewStack(_)
        | &NewThread(_, _)
        | &NewThreadExn(_, _)
        | &NewFrameCursor(_)
        | &GetIRef(_)
        | &GetFieldIRef{..}
        | &GetElementIRef{..}
        | &ShiftIRef{..}
        | &GetVarPartIRef{..}
qinsoon's avatar
qinsoon committed
43
        | &Select{..}
44 45
        | &Fence(_)
        | &CommonInst_GetThreadLocal
46
        | &CommonInst_SetThreadLocal(_)
qinsoon's avatar
qinsoon committed
47 48
        | &CommonInst_Pin(_)
        | &CommonInst_Unpin(_)
49 50
        | &Move(_)
        | &PrintHex(_) => false,
51 52 53 54 55 56 57 58 59
        &Return(_)
        | &ThreadExit
        | &Throw(_)
        | &TailCall(_)
        | &Branch1(_)
        | &Branch2{..}
        | &Watchpoint{..}
        | &WPBranch{..}
        | &Call{..}
qinsoon's avatar
qinsoon committed
60
        | &CCall{..}
61 62 63 64 65 66 67 68 69 70 71 72 73 74
        | &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
75
        &BinOpWithStatus(_, _, _, _) => false,
76
        &CmpOp(_, _, _) => false,
qinsoon's avatar
qinsoon committed
77
        &ConvOp{..} => false,
78
        &ExprCall{..} => true,
qinsoon's avatar
qinsoon committed
79
        &ExprCCall{..} => true,
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
        &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
104
        &Select{..} => false,
105 106 107
        &Watchpoint{..} => true,
        &WPBranch{..} => true,
        &Call{..} => true,
qinsoon's avatar
qinsoon committed
108
        &CCall{..} => true,
109 110
        &SwapStack{..} => true,
        &Switch{..} => true,
111 112 113
        &ExnInstruction{..} => true,
        &CommonInst_GetThreadLocal => true,
        &CommonInst_SetThreadLocal(_) => true,
qinsoon's avatar
qinsoon committed
114 115
        &CommonInst_Pin(_) => true,
        &CommonInst_Unpin(_) => true,
116
        &Move(_) => false,
117
        &PrintHex(_) => true
118
    }
119
}
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

pub fn is_potentially_excepting_instruction(inst: &Instruction_) -> bool {
    match inst {
        &Watchpoint{..}
        | &Call{..}
        | &CCall{..}
        | &SwapStack{..}
        | &ExnInstruction{..} => true,

        &BinOp(_, _, _)
        | &BinOpWithStatus(_, _, _, _)
        | &CmpOp(_, _, _)
        | &ConvOp{..}
        | &ExprCall{..}
        | &ExprCCall{..}
        | &Load{..}
        | &Store{..}
        | &CmpXchg{..}
        | &AtomicRMW{..}
        | &New(_)
        | &AllocA(_)
        | &NewHybrid(_, _)
        | &AllocAHybrid(_, _)
        | &NewStack(_)
        | &NewThread(_, _)
        | &NewThreadExn(_, _)
        | &NewFrameCursor(_)
        | &GetIRef(_)
        | &GetFieldIRef{..}
        | &GetElementIRef{..}
        | &ShiftIRef{..}
        | &GetVarPartIRef{..}
        | &Fence(_)
        | &Return(_)
        | &ThreadExit
        | &Throw(_)
        | &TailCall(_)
        | &Branch1(_)
        | &Branch2{..}
        | &Select{..}
        | &WPBranch{..}
        | &Switch{..}
        | &CommonInst_GetThreadLocal
        | &CommonInst_SetThreadLocal(_)
        | &CommonInst_Pin(_)
        | &CommonInst_Unpin(_)
        | &Move(_)
        | &PrintHex(_) => false
    }
}