1/*
2 * Copyright (C) 2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#pragma once
27
28#if ENABLE(B3_JIT)
29
30#include "B3MemoryValue.h"
31#include "B3Width.h"
32
33namespace JSC { namespace B3 {
34
35class JS_EXPORT_PRIVATE AtomicValue : public MemoryValue {
36public:
37 static bool accepts(Kind kind)
38 {
39 return isAtom(kind.opcode());
40 }
41
42 ~AtomicValue();
43
44 Type accessType() const { return child(0)->type(); }
45
46 Width accessWidth() const { return m_width; }
47
48 B3_SPECIALIZE_VALUE_FOR_FINAL_SIZE_FIXED_CHILDREN
49
50protected:
51 void dumpMeta(CommaPrinter&, PrintStream&) const override;
52
53private:
54 friend class Procedure;
55 friend class Value;
56
57 enum AtomicValueRMW { AtomicValueRMWTag };
58 enum AtomicValueCAS { AtomicValueCASTag };
59
60 AtomicValue(Kind kind, Origin origin, Width width, Value* operand, Value* pointer)
61 : AtomicValue(kind, origin, width, operand, pointer, 0)
62 {
63 }
64 template<typename Int,
65 typename = typename std::enable_if<std::is_integral<Int>::value>::type,
66 typename = typename std::enable_if<std::is_signed<Int>::value>::type,
67 typename = typename std::enable_if<sizeof(Int) <= sizeof(OffsetType)>::type
68 >
69 AtomicValue(Kind kind, Origin origin, Width width, Value* operand, Value* pointer, Int offset, HeapRange range = HeapRange::top(), HeapRange fenceRange = HeapRange::top())
70 : AtomicValue(AtomicValueRMWTag, kind, origin, width, operand, pointer, offset, range, fenceRange)
71 {
72 }
73
74 AtomicValue(Kind kind, Origin origin, Width width, Value* expectedValue, Value* newValue, Value* pointer)
75 : AtomicValue(kind, origin, width, expectedValue, newValue, pointer, 0)
76 {
77 }
78 template<typename Int,
79 typename = typename std::enable_if<std::is_integral<Int>::value>::type,
80 typename = typename std::enable_if<std::is_signed<Int>::value>::type,
81 typename = typename std::enable_if<sizeof(Int) <= sizeof(OffsetType)>::type
82 >
83 AtomicValue(Kind kind, Origin origin, Width width, Value* expectedValue, Value* newValue, Value* pointer, Int offset, HeapRange range = HeapRange::top(), HeapRange fenceRange = HeapRange::top())
84 : AtomicValue(AtomicValueCASTag, kind, origin, width, expectedValue, newValue, pointer, offset, range, fenceRange)
85 {
86 }
87
88 // The above templates forward to these implementations.
89 AtomicValue(AtomicValueRMW, Kind, Origin, Width, Value* operand, Value* pointer, OffsetType, HeapRange = HeapRange::top(), HeapRange fenceRange = HeapRange::top());
90 AtomicValue(AtomicValueCAS, Kind, Origin, Width, Value* expectedValue, Value* newValue, Value* pointer, OffsetType, HeapRange = HeapRange::top(), HeapRange fenceRange = HeapRange::top());
91
92 Width m_width;
93};
94
95} } // namespace JSC::B3
96
97#endif // ENABLE(B3_JIT)
98