2 * Copyright (C) 2013 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.
26 #ifndef FTLSlowPathCallKey_h
27 #define FTLSlowPathCallKey_h
31 #include "RegisterSet.h"
33 namespace JSC
{ namespace FTL
{
35 // This is used for creating some sanity in slow-path calls out of the FTL's inline
36 // caches. The idea is that we don't want all of the register save/restore stuff to
37 // be generated at each IC site. Instead, the IC slow path call site will just save
38 // the registers needed for the arguments. It will arrange for there to be enough
39 // space on top of stack to save the remaining registers and the return PC. Then it
40 // will call a shared thunk that will save the remaining registers. That thunk needs
41 // to know the stack offset at which things get saved along with the call target.
43 // Note that the offset is *not including* the return PC that would be pushed on X86.
45 class SlowPathCallKey
{
54 const RegisterSet
& set
, void* callTarget
, const RegisterSet
& argumentRegisters
,
56 : m_usedRegisters(set
)
57 , m_callTarget(callTarget
)
58 , m_argumentRegisters(argumentRegisters
)
63 const RegisterSet
& usedRegisters() const { return m_usedRegisters
; }
64 void* callTarget() const { return m_callTarget
; }
65 const RegisterSet
& argumentRegisters() const { return m_argumentRegisters
; }
66 ptrdiff_t offset() const { return m_offset
; }
68 SlowPathCallKey
withCallTarget(void* callTarget
)
70 return SlowPathCallKey(usedRegisters(), callTarget
, argumentRegisters(), offset());
73 void dump(PrintStream
&) const;
75 enum EmptyValueTag
{ EmptyValue
};
76 enum DeletedValueTag
{ DeletedValue
};
78 SlowPathCallKey(EmptyValueTag
)
79 : m_usedRegisters(RegisterSet::EmptyValue
)
85 SlowPathCallKey(DeletedValueTag
)
86 : m_usedRegisters(RegisterSet::DeletedValue
)
92 bool isEmptyValue() const { return m_usedRegisters
.isEmptyValue(); }
93 bool isDeletedValue() const { return m_usedRegisters
.isDeletedValue(); }
95 bool operator==(const SlowPathCallKey
& other
) const
97 return m_usedRegisters
== other
.m_usedRegisters
98 && m_callTarget
== other
.m_callTarget
99 && m_offset
== other
.m_offset
;
101 unsigned hash() const
103 return m_usedRegisters
.hash() + PtrHash
<void*>::hash(m_callTarget
) + m_offset
;
107 RegisterSet m_usedRegisters
;
109 RegisterSet m_argumentRegisters
;
113 struct SlowPathCallKeyHash
{
114 static unsigned hash(const SlowPathCallKey
& key
) { return key
.hash(); }
115 static bool equal(const SlowPathCallKey
& a
, const SlowPathCallKey
& b
) { return a
== b
; }
116 static const bool safeToCompareToEmptyOrDeleted
= false;
119 } } // namespace JSC::FTL
123 template<typename T
> struct DefaultHash
;
124 template<> struct DefaultHash
<JSC::FTL::SlowPathCallKey
> {
125 typedef JSC::FTL::SlowPathCallKeyHash Hash
;
128 template<typename T
> struct HashTraits
;
129 template<> struct HashTraits
<JSC::FTL::SlowPathCallKey
> : public CustomHashTraits
<JSC::FTL::SlowPathCallKey
> { };
133 #endif // ENABLE(FTL_JIT)
135 #endif // FTLSlowPathCallKey_h