]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/CallLinkStatus.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / bytecode / CallLinkStatus.h
CommitLineData
b37bf2e1 1/*
ed1e77d3 2 * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
b37bf2e1
A
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 *
9dae56ea 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
b37bf2e1
A
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
9dae56ea 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
b37bf2e1
A
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
6fe7ccc8
A
26#ifndef CallLinkStatus_h
27#define CallLinkStatus_h
b37bf2e1 28
81345200 29#include "CallLinkInfo.h"
ed1e77d3 30#include "CallVariant.h"
81345200 31#include "CodeOrigin.h"
93a37866 32#include "CodeSpecializationKind.h"
81345200 33#include "ConcurrentJITLock.h"
ed1e77d3 34#include "ExitingJITType.h"
93a37866
A
35#include "Intrinsic.h"
36#include "JSCJSValue.h"
37
9dae56ea 38namespace JSC {
9dae56ea 39
6fe7ccc8 40class CodeBlock;
93a37866
A
41class ExecutableBase;
42class InternalFunction;
43class JSFunction;
44class Structure;
ed1e77d3 45class CallLinkInfo;
9dae56ea 46
6fe7ccc8
A
47class CallLinkStatus {
48public:
49 CallLinkStatus()
ed1e77d3 50 : m_couldTakeSlowPath(false)
93a37866
A
51 , m_isProved(false)
52 {
53 }
54
55 static CallLinkStatus takesSlowPath()
56 {
57 CallLinkStatus result;
58 result.m_couldTakeSlowPath = true;
59 return result;
60 }
61
62 explicit CallLinkStatus(JSValue);
63
ed1e77d3
A
64 CallLinkStatus(CallVariant variant)
65 : m_variants(1, variant)
6fe7ccc8 66 , m_couldTakeSlowPath(false)
93a37866 67 , m_isProved(false)
6fe7ccc8 68 {
6fe7ccc8
A
69 }
70
81345200
A
71 static CallLinkStatus computeFor(
72 CodeBlock*, unsigned bytecodeIndex, const CallLinkInfoMap&);
73
ed1e77d3
A
74 struct ExitSiteData {
75 ExitSiteData()
76 : m_takesSlowPath(false)
77 , m_badFunction(false)
78 {
79 }
80
81 bool m_takesSlowPath;
82 bool m_badFunction;
83 };
84 static ExitSiteData computeExitSiteData(const ConcurrentJITLocker&, CodeBlock*, unsigned bytecodeIndex);
85
81345200
A
86#if ENABLE(JIT)
87 // Computes the status assuming that we never took slow path and never previously
88 // exited.
ed1e77d3
A
89 static CallLinkStatus computeFor(const ConcurrentJITLocker&, CodeBlock*, CallLinkInfo&);
90 static CallLinkStatus computeFor(
91 const ConcurrentJITLocker&, CodeBlock*, CallLinkInfo&, ExitSiteData);
81345200 92#endif
6fe7ccc8 93
81345200 94 typedef HashMap<CodeOrigin, CallLinkStatus, CodeOriginApproximateHash> ContextMap;
93a37866 95
81345200
A
96 // Computes all of the statuses of the DFG code block. Doesn't include statuses that had
97 // no information. Currently we use this when compiling FTL code, to enable polyvariant
98 // inlining.
99 static void computeDFGStatuses(CodeBlock* dfgCodeBlock, ContextMap&);
93a37866 100
81345200
A
101 // Helper that first consults the ContextMap and then does computeFor().
102 static CallLinkStatus computeFor(
103 CodeBlock*, CodeOrigin, const CallLinkInfoMap&, const ContextMap&);
93a37866 104
ed1e77d3
A
105 void setProvenConstantCallee(CallVariant);
106
107 bool isSet() const { return !m_variants.isEmpty() || m_couldTakeSlowPath; }
6fe7ccc8
A
108
109 bool operator!() const { return !isSet(); }
110
111 bool couldTakeSlowPath() const { return m_couldTakeSlowPath; }
ed1e77d3
A
112
113 CallVariantList variants() const { return m_variants; }
114 unsigned size() const { return m_variants.size(); }
115 CallVariant at(unsigned i) const { return m_variants[i]; }
116 CallVariant operator[](unsigned i) const { return at(i); }
93a37866 117 bool isProved() const { return m_isProved; }
ed1e77d3
A
118 bool canOptimize() const { return !m_variants.isEmpty(); }
119
120 bool isClosureCall() const; // Returns true if any callee is a closure call.
121
122 unsigned maxNumArguments() const { return m_maxNumArguments; }
6fe7ccc8 123
93a37866 124 void dump(PrintStream&) const;
6fe7ccc8
A
125
126private:
ed1e77d3 127 void makeClosureCall();
81345200
A
128
129 static CallLinkStatus computeFromLLInt(const ConcurrentJITLocker&, CodeBlock*, unsigned bytecodeIndex);
ed1e77d3
A
130#if ENABLE(JIT)
131 static CallLinkStatus computeFromCallLinkInfo(
132 const ConcurrentJITLocker&, CallLinkInfo&);
133#endif
6fe7ccc8 134
ed1e77d3 135 CallVariantList m_variants;
6fe7ccc8 136 bool m_couldTakeSlowPath;
93a37866 137 bool m_isProved;
ed1e77d3 138 unsigned m_maxNumArguments;
6fe7ccc8 139};
9dae56ea 140
4e4e5a6f 141} // namespace JSC
6fe7ccc8
A
142
143#endif // CallLinkStatus_h
144