2 * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "B3HeapRange.h"
31 #include <wtf/PrintStream.h>
33 namespace JSC { namespace B3 {
36 // True if this cannot continue execution in the current block.
37 bool terminal { false };
39 // True if this value can cause execution to terminate abruptly, and that this abrupt termination is
40 // observable. An example of how this gets used is to limit the hoisting of controlDependent values.
41 // Note that if exitsSideways is set to true but reads is bottom, then B3 is free to assume that
42 // after abrupt termination of this procedure, none of the heap will be read. That's usually false,
43 // so make sure that reads corresponds to the set of things that are readable after this function
44 // terminates abruptly.
45 bool exitsSideways { false };
47 // True if the instruction may change semantics if hoisted above some control flow. For example,
48 // loads are usually control-dependent because we must assume that any control construct (either
49 // a terminal like Branch or anything that exits sideways, like Check) validates whether the
50 // pointer is valid. Hoisting the load above control may cause the load to trap even though it
51 // would not have otherwise trapped.
52 bool controlDependent { false };
54 // True if this writes to the local state. Operations that write local state don't write to anything
55 // in "memory" but they have a side-effect anyway. This is for modeling Upsilons, Sets, and Fences.
56 // This is a way of saying: even though this operation is not a terminal, does not exit sideways,
57 // and does not write to the heap, you still cannot kill this operation.
58 bool writesLocalState { false };
60 // True if this reads from the local state. This is only used for Phi and Get.
61 bool readsLocalState { false };
71 static Effects forCall()
74 result.exitsSideways = true;
75 result.controlDependent = true;
76 result.writes = HeapRange::top();
77 result.reads = HeapRange::top();
81 bool mustExecute() const
83 return terminal || exitsSideways || writesLocalState || writes;
86 // Returns true if reordering instructions with these respective effects would change program
87 // behavior in an observable way.
88 bool interferes(const Effects&) const;
90 JS_EXPORT_PRIVATE bool operator==(const Effects&) const;
91 JS_EXPORT_PRIVATE bool operator!=(const Effects&) const;
93 JS_EXPORT_PRIVATE void dump(PrintStream& out) const;
96 } } // namespace JSC::B3
98 #endif // ENABLE(B3_JIT)