|
Line 0
Source/JavaScriptCore/ftl/FTLExitValue.h_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2013 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 |
#ifndef FTLExitValue_h |
| 27 |
#define FTLExitValue_h |
| 28 |
|
| 29 |
#include <wtf/Platform.h> |
| 30 |
|
| 31 |
#if ENABLE(FTL_JIT) |
| 32 |
|
| 33 |
#include "FTLExitArgument.h" |
| 34 |
#include "JSCJSValue.h" |
| 35 |
#include <wtf/PrintStream.h> |
| 36 |
|
| 37 |
namespace JSC { namespace FTL { |
| 38 |
|
| 39 |
// This is like ValueRecovery, but respects the way that the FTL does OSR |
| 40 |
// exit: the live non-constant non-flushed values are passed as arguments |
| 41 |
// to a noreturn tail call. ExitValue is hence mostly responsible for |
| 42 |
// telling us the mapping between operands in bytecode and the arguments to |
| 43 |
// the call. |
| 44 |
|
| 45 |
enum ExitValueKind { |
| 46 |
InvalidExitValue, |
| 47 |
ExitValueDead, |
| 48 |
ExitValueArgument, |
| 49 |
ExitValueConstant |
| 50 |
ExitValueInJSStack |
| 51 |
}; |
| 52 |
|
| 53 |
class ExitValue { |
| 54 |
public: |
| 55 |
ExitValue() |
| 56 |
: m_kind(InvalidExitValue) |
| 57 |
{ |
| 58 |
} |
| 59 |
|
| 60 |
bool operator!() const { return m_kind == InvalidExitValue; } |
| 61 |
|
| 62 |
static ExitValue dead() |
| 63 |
{ |
| 64 |
ExitValue result; |
| 65 |
result.m_kind = ExitValueDead; |
| 66 |
return result; |
| 67 |
} |
| 68 |
|
| 69 |
static ExitValue inJSStack() |
| 70 |
{ |
| 71 |
ExitValue result; |
| 72 |
result.m_kind = ExitValueInJSStack; |
| 73 |
return result; |
| 74 |
} |
| 75 |
|
| 76 |
static ExitValue constant(JSValue value) |
| 77 |
{ |
| 78 |
ExitValue result; |
| 79 |
result.m_kind = ExitValueConstant; |
| 80 |
result.u.constant = JSValue::encode(value); |
| 81 |
return result; |
| 82 |
} |
| 83 |
|
| 84 |
static ExitValue argument(const ExitArgument& argument) |
| 85 |
{ |
| 86 |
ExitValue result; |
| 87 |
result.m_kind = ExitValueArgument; |
| 88 |
result.u.argument = argument.representation(); |
| 89 |
return result; |
| 90 |
} |
| 91 |
|
| 92 |
ExitValueKind kind() const { return m_kind; } |
| 93 |
|
| 94 |
bool isDead() const { return kind() == ExitValueDead; } |
| 95 |
bool isInJSStack() const { return kind() == ExitValueInJSStack; } |
| 96 |
bool isConstant() const { return kind() == ExitValueConstant; } |
| 97 |
bool isArgument() const { return kind() == ExitValueArgument; } |
| 98 |
|
| 99 |
ExitArgument argument() const |
| 100 |
{ |
| 101 |
ASSERT(isArgument()); |
| 102 |
return ExitArgument(u.argument); |
| 103 |
} |
| 104 |
|
| 105 |
JSValue constant() const |
| 106 |
{ |
| 107 |
ASSERT(isConstant()); |
| 108 |
return JSValue::decode(u.constant); |
| 109 |
} |
| 110 |
|
| 111 |
void dump(PrintStream&) const; |
| 112 |
|
| 113 |
private: |
| 114 |
ExitValueKind m_kind; |
| 115 |
union { |
| 116 |
ExitArgumentRepresentation argument; |
| 117 |
EncodedJSValue constant; |
| 118 |
} u; |
| 119 |
}; |
| 120 |
|
| 121 |
} } // namespace JSC::FTL |
| 122 |
|
| 123 |
#endif // ENABLE(FTL_JIT) |
| 124 |
|
| 125 |
#endif // FTLExitValue_h |