source: webkit/trunk/Source/JavaScriptCore/dfg/DFGEdge.h

Last change on this file was 261464, checked in by Ross Kirsling, 5 years ago

[clang-tidy] Run modernize-use-nullptr over JSC
https://bugs.webkit.org/show_bug.cgi?id=211706

Reviewed by Darin Adler.

  • API/APICallbackFunction.h:
  • API/JSAPIGlobalObject.h:
  • API/JSBase.cpp:
  • API/JSCallbackObjectFunctions.h:
  • API/JSClassRef.cpp:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSScriptRef.cpp:
  • API/JSValueRef.cpp:
  • API/JSWeakObjectMapRefPrivate.cpp:
  • API/tests/ExecutionTimeLimitTest.cpp:
  • API/tests/PingPongStackOverflowTest.cpp:
  • assembler/AbstractMacroAssembler.h:
  • assembler/CPU.cpp:
  • bytecode/CodeBlock.cpp:
  • bytecode/DeleteByIdVariant.cpp:
  • bytecode/GetByIdVariant.cpp:
  • bytecode/InByIdVariant.cpp:
  • bytecode/InlineCallFrame.cpp:
  • bytecode/LazyOperandValueProfile.cpp:
  • bytecode/PutByIdVariant.cpp:
  • bytecode/ValueProfile.h:
  • bytecode/ValueRecovery.cpp:
  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:
  • debugger/DebuggerScope.h:
  • dfg/DFGAbstractValue.cpp:
  • dfg/DFGAdjacencyList.h:
  • dfg/DFGArgumentPosition.h:
  • dfg/DFGArrayifySlowPathGenerator.h:
  • dfg/DFGAvailability.h:
  • dfg/DFGByteCodeParser.cpp:
  • dfg/DFGCFGSimplificationPhase.cpp:
  • dfg/DFGCPSRethreadingPhase.cpp:
  • dfg/DFGCompilationKey.h:
  • dfg/DFGConstantFoldingPhase.cpp:
  • dfg/DFGDisassembler.cpp:
  • dfg/DFGDoubleFormatState.h:
  • dfg/DFGEdge.h:
  • dfg/DFGFixupPhase.cpp:
  • dfg/DFGFrozenValue.cpp:
  • dfg/DFGGenerationInfo.h:
  • dfg/DFGGraph.h:
  • dfg/DFGInPlaceAbstractState.cpp:
  • dfg/DFGIntegerCheckCombiningPhase.cpp:
  • dfg/DFGLazyJSValue.cpp:
  • dfg/DFGNode.h:
  • dfg/DFGOSREntrypointCreationPhase.cpp:
  • dfg/DFGOSRExit.cpp:
  • dfg/DFGOperations.cpp:
  • dfg/DFGSilentRegisterSavePlan.h:
  • dfg/DFGSpeculativeJIT.cpp:
  • dfg/DFGSpeculativeJIT.h:
  • dfg/DFGSpeculativeJIT64.cpp:
  • dfg/DFGStructureAbstractValue.cpp:
  • dfg/DFGTransition.cpp:
  • dfg/DFGTypeCheckHoistingPhase.cpp:
  • dfg/DFGWorklist.cpp:
  • ftl/FTLAbstractHeapRepository.h:
  • ftl/FTLAvailableRecovery.h:
  • ftl/FTLExitValue.cpp:
  • ftl/FTLFormattedValue.h:
  • ftl/FTLJITCode.cpp:
  • ftl/FTLLink.cpp:
  • ftl/FTLLowerDFGToB3.cpp:
  • ftl/FTLLoweredNodeValue.h:
  • ftl/FTLOSREntry.cpp:
  • ftl/FTLOSRExitCompiler.cpp:
  • ftl/FTLTypedPointer.h:
  • ftl/FTLValueFromBlock.h:
  • ftl/FTLValueRange.h:
  • heap/GCSegmentedArray.h:
  • heap/Handle.h:
  • heap/HandleSet.h:
  • heap/HandleTypes.h:
  • heap/HeapSnapshotBuilder.cpp:
  • heap/MarkedBlockInlines.h:
  • heap/Strong.h:
  • heap/WeakImpl.h:
  • heap/WeakInlines.h:
  • heap/WeakSet.cpp:
  • heap/WeakSet.h:
  • interpreter/CallFrame.cpp:
  • interpreter/CallFrame.h:
  • interpreter/Interpreter.cpp:
  • interpreter/ProtoCallFrame.h:
  • interpreter/StackVisitor.cpp:
  • interpreter/StackVisitor.h:
  • jit/AssemblyHelpers.h:
  • jit/CCallHelpers.h:
  • jit/JITCode.cpp:
  • jit/JITOperations.cpp:
  • jit/Repatch.cpp:
  • jit/ThunkGenerators.cpp:
  • jsc.cpp:
  • llint/LLIntSlowPaths.cpp:
  • parser/ASTBuilder.h:
  • parser/Lexer.cpp:
  • parser/Lexer.h:
  • parser/Nodes.cpp:
  • parser/Nodes.h:
  • parser/Parser.cpp:
  • parser/Parser.h:
  • parser/ParserArena.cpp:
  • parser/ParserArena.h:
  • parser/ParserFunctionInfo.h:
  • parser/SyntaxChecker.h:
  • parser/UnlinkedSourceCode.h:
  • profiler/ProfilerBytecodeSequence.cpp:
  • profiler/ProfilerCompilation.cpp:
  • profiler/ProfilerDatabase.cpp:
  • profiler/ProfilerOSRExitSite.cpp:
  • profiler/ProfilerOriginStack.cpp:
  • runtime/ArgList.h:
  • runtime/ArrayPrototype.cpp:
  • runtime/ClonedArguments.cpp:
  • runtime/CommonSlowPaths.cpp:
  • runtime/Completion.h:
  • runtime/DataView.h:
  • runtime/DatePrototype.cpp:
  • runtime/DirectEvalExecutable.cpp:
  • runtime/DumpContext.cpp:
  • runtime/FunctionExecutable.cpp:
  • runtime/IndirectEvalExecutable.cpp:
  • runtime/JSArray.cpp:
  • runtime/JSArrayBufferView.cpp:
  • runtime/JSCJSValue.cpp:
  • runtime/JSCJSValueInlines.h:
  • runtime/JSCell.cpp:
  • runtime/JSDataView.cpp:
  • runtime/JSDestructibleObject.h:
  • runtime/JSFunction.cpp:
  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:
  • runtime/JSONObject.cpp:
  • runtime/JSObject.cpp:
  • runtime/JSObject.h:
  • runtime/JSScope.cpp:
  • runtime/JSScope.h:
  • runtime/LiteralParser.cpp:
  • runtime/OptionsList.h:
  • runtime/PropertyDescriptor.cpp:
  • runtime/PropertyMapHashTable.h:
  • runtime/PropertySlot.h:
  • runtime/PutPropertySlot.h:
  • runtime/RegExpMatchesArray.h:
  • runtime/RegExpPrototype.cpp:
  • runtime/StringPrototype.cpp:
  • runtime/Structure.cpp:
  • runtime/Structure.h:
  • runtime/TestRunnerUtils.cpp:
  • runtime/TypedArrayType.cpp:
  • runtime/VM.cpp:
  • runtime/Watchdog.cpp:
  • runtime/Watchdog.h:
  • runtime/WriteBarrier.h:
  • testRegExp.cpp:
  • tools/JSDollarVM.cpp:
  • wasm/WasmSlowPaths.cpp:
  • yarr/RegularExpression.h:
  • yarr/YarrInterpreter.cpp:
  • yarr/YarrJIT.cpp:
  • yarr/YarrJIT.h:
  • yarr/YarrPattern.cpp:
  • yarr/YarrPattern.h:
File size: 7.4 KB
Line 
1/*
2 * Copyright (C) 2011, 2013, 2014 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(DFG_JIT)
29
30#include "DFGCommon.h"
31#include "DFGUseKind.h"
32
33namespace JSC { namespace DFG {
34
35class AdjacencyList;
36
37class Edge {
38public:
39 explicit Edge(Node* node = nullptr, UseKind useKind = UntypedUse, ProofStatus proofStatus = NeedsCheck, KillStatus killStatus = DoesNotKill)
40#if USE(JSVALUE64)
41 : m_encodedWord(makeWord(node, useKind, proofStatus, killStatus))
42#else
43 : m_node(node)
44 , m_encodedWord(makeWord(useKind, proofStatus, killStatus))
45#endif
46 {
47 }
48
49#if USE(JSVALUE64)
50 Node* node() const { return bitwise_cast<Node*>(m_encodedWord >> shift()); }
51#else
52 Node* node() const { return m_node; }
53#endif
54
55 Node& operator*() const { return *node(); }
56 Node* operator->() const { return node(); }
57
58 void setNode(Node* node)
59 {
60#if USE(JSVALUE64)
61 m_encodedWord = makeWord(node, useKind(), proofStatus(), killStatus());
62#else
63 m_node = node;
64#endif
65 }
66
67 UseKind useKindUnchecked() const
68 {
69#if USE(JSVALUE64)
70 unsigned masked = m_encodedWord & (((1 << shift()) - 1));
71 unsigned shifted = masked >> 2;
72#else
73 unsigned shifted = static_cast<UseKind>(m_encodedWord) >> 2;
74#endif
75 ASSERT(shifted < static_cast<unsigned>(LastUseKind));
76 UseKind result = static_cast<UseKind>(shifted);
77 ASSERT(node() || result == UntypedUse);
78 return result;
79 }
80 UseKind useKind() const
81 {
82 ASSERT(node());
83 return useKindUnchecked();
84 }
85 void setUseKind(UseKind useKind)
86 {
87 ASSERT(node());
88#if USE(JSVALUE64)
89 m_encodedWord = makeWord(node(), useKind, proofStatus(), killStatus());
90#else
91 m_encodedWord = makeWord(useKind, proofStatus(), killStatus());
92#endif
93 }
94
95 ProofStatus proofStatusUnchecked() const
96 {
97 return proofStatusForIsProved(m_encodedWord & 1);
98 }
99 ProofStatus proofStatus() const
100 {
101 ASSERT(node());
102 return proofStatusUnchecked();
103 }
104 void setProofStatus(ProofStatus proofStatus)
105 {
106 ASSERT(node());
107#if USE(JSVALUE64)
108 m_encodedWord = makeWord(node(), useKind(), proofStatus, killStatus());
109#else
110 m_encodedWord = makeWord(useKind(), proofStatus, killStatus());
111#endif
112 }
113 bool isProved() const
114 {
115 return proofStatus() == IsProved;
116 }
117
118 bool willNotHaveCheck() const
119 {
120 return isProved() || shouldNotHaveTypeCheck(useKind());
121 }
122 bool willHaveCheck() const
123 {
124 return !willNotHaveCheck();
125 }
126
127 KillStatus killStatusUnchecked() const
128 {
129 return killStatusForDoesKill(m_encodedWord & 2);
130 }
131 KillStatus killStatus() const
132 {
133 ASSERT(node());
134 return killStatusUnchecked();
135 }
136 void setKillStatus(KillStatus killStatus)
137 {
138 ASSERT(node());
139#if USE(JSVALUE64)
140 m_encodedWord = makeWord(node(), useKind(), proofStatus(), killStatus);
141#else
142 m_encodedWord = makeWord(useKind(), proofStatus(), killStatus);
143#endif
144 }
145 bool doesKill() const { return DFG::doesKill(killStatus()); }
146
147 bool isSet() const { return !!node(); }
148
149 Edge sanitized() const
150 {
151 Edge result = *this;
152#if USE(JSVALUE64)
153 result.m_encodedWord = makeWord(node(), useKindUnchecked(), NeedsCheck, DoesNotKill);
154#else
155 result.m_encodedWord = makeWord(useKindUnchecked(), NeedsCheck, DoesNotKill);
156#endif
157 return result;
158 }
159
160 bool operator!() const { return !isSet(); }
161 explicit operator bool() const { return isSet(); }
162
163 bool operator==(Edge other) const
164 {
165#if USE(JSVALUE64)
166 return m_encodedWord == other.m_encodedWord;
167#else
168 return m_node == other.m_node && m_encodedWord == other.m_encodedWord;
169#endif
170 }
171 bool operator!=(Edge other) const
172 {
173 return !(*this == other);
174 }
175
176 void dump(PrintStream&) const;
177
178 unsigned hash() const
179 {
180#if USE(JSVALUE64)
181 return IntHash<uintptr_t>::hash(m_encodedWord);
182#else
183 return PtrHash<Node*>::hash(m_node) + m_encodedWord;
184#endif
185 }
186
187private:
188 friend class AdjacencyList;
189
190#if USE(JSVALUE64)
191 static constexpr uint32_t shift() { return 8; }
192
193 static uintptr_t makeWord(Node* node, UseKind useKind, ProofStatus proofStatus, KillStatus killStatus)
194 {
195 ASSERT(sizeof(node) == 8);
196 uintptr_t shiftedValue = bitwise_cast<uintptr_t>(node) << shift();
197 ASSERT((shiftedValue >> shift()) == bitwise_cast<uintptr_t>(node));
198 ASSERT(useKind >= 0 && useKind < LastUseKind);
199 static_assert((static_cast<uintptr_t>(LastUseKind) << 2) < (static_cast<uintptr_t>(1) << shift()), "We rely on this being true to not clobber the node pointer.");
200 uintptr_t result = shiftedValue | (static_cast<uintptr_t>(useKind) << 2) | (DFG::doesKill(killStatus) << 1) | static_cast<uintptr_t>(DFG::isProved(proofStatus));
201 if (ASSERT_ENABLED) {
202 union U {
203 U() { word = 0; }
204 uintptr_t word;
205 Edge edge;
206 } u;
207 u.word = result;
208 ASSERT(u.edge.useKindUnchecked() == useKind);
209 ASSERT(u.edge.node() == node);
210 ASSERT(u.edge.proofStatusUnchecked() == proofStatus);
211 ASSERT(u.edge.killStatusUnchecked() == killStatus);
212 }
213 return result;
214 }
215
216#else
217 static uintptr_t makeWord(UseKind useKind, ProofStatus proofStatus, KillStatus killStatus)
218 {
219 return (static_cast<uintptr_t>(useKind) << 2) | (DFG::doesKill(killStatus) << 1) | static_cast<uintptr_t>(DFG::isProved(proofStatus));
220 }
221
222 Node* m_node;
223#endif
224 // On 64-bit this holds both the pointer and the use kind, while on 32-bit
225 // this just holds the use kind. In both cases this may be hijacked by
226 // AdjacencyList for storing firstChild and numChildren.
227 uintptr_t m_encodedWord;
228};
229
230inline bool operator==(Edge edge, Node* node)
231{
232 return edge.node() == node;
233}
234inline bool operator==(Node* node, Edge edge)
235{
236 return edge.node() == node;
237}
238inline bool operator!=(Edge edge, Node* node)
239{
240 return edge.node() != node;
241}
242inline bool operator!=(Node* node, Edge edge)
243{
244 return edge.node() != node;
245}
246
247} } // namespace JSC::DFG
248
249#endif // ENABLE(DFG_JIT)
Note: See TracBrowser for help on using the repository browser.