To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

ir_semantics.rs 4.69 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
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
        | &Move(_)
50
51
        | &PrintHex(_)
        | &SetRetval(_) => false,
52
53
54
55
56
57
58
59
60
        &Return(_)
        | &ThreadExit
        | &Throw(_)
        | &TailCall(_)
        | &Branch1(_)
        | &Branch2{..}
        | &Watchpoint{..}
        | &WPBranch{..}
        | &Call{..}
qinsoon's avatar
qinsoon committed
61
        | &CCall{..}
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        | &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
76
        &BinOpWithStatus(_, _, _, _) => false,
77
        &CmpOp(_, _, _) => false,
qinsoon's avatar
qinsoon committed
78
        &ConvOp{..} => false,
79
        &ExprCall{..} => true,
qinsoon's avatar
qinsoon committed
80
        &ExprCCall{..} => true,
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
        &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
105
        &Select{..} => false,
106
107
108
        &Watchpoint{..} => true,
        &WPBranch{..} => true,
        &Call{..} => true,
qinsoon's avatar
qinsoon committed
109
        &CCall{..} => true,
110
111
        &SwapStack{..} => true,
        &Switch{..} => true,
112
113
114
        &ExnInstruction{..} => true,
        &CommonInst_GetThreadLocal => true,
        &CommonInst_SetThreadLocal(_) => true,
qinsoon's avatar
qinsoon committed
115
116
        &CommonInst_Pin(_) => true,
        &CommonInst_Unpin(_) => true,
117
        &Move(_) => false,
118
119
        &PrintHex(_) => true,
        &SetRetval(_) => true,
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

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(_)
169
170
        | &PrintHex(_)
        | &SetRetval(_) => false
171
172
    }
}