1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
/*
* Copyright (C) 2011, 2013-2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if ENABLE(DFG_JIT)
#include "CCallHelpers.h"
#include "CodeBlock.h"
#include "DFGDisassembler.h"
#include "DFGGraph.h"
#include "DFGInlineCacheWrapper.h"
#include "DFGJITCode.h"
#include "DFGOSRExitCompilationInfo.h"
#include "DFGRegisterBank.h"
#include "FPRInfo.h"
#include "GPRInfo.h"
#include "HandlerInfo.h"
#include "JITCode.h"
#include "JITInlineCacheGenerator.h"
#include "LinkBuffer.h"
#include "MacroAssembler.h"
#include "PCToCodeOriginMap.h"
#include "TempRegisterSet.h"
namespace JSC {
class AbstractSamplingCounter;
class CodeBlock;
class VM;
namespace DFG {
class JITCodeGenerator;
class NodeToRegisterMap;
class OSRExitJumpPlaceholder;
class SlowPathGenerator;
class SpeculativeJIT;
class SpeculationRecovery;
struct EntryLocation;
struct OSRExit;
// === CallLinkRecord ===
//
// A record of a call out from JIT code that needs linking to a helper function.
// Every CallLinkRecord contains a reference to the call instruction & the function
// that it needs to be linked to.
struct CallLinkRecord {
CallLinkRecord(MacroAssembler::Call call, FunctionPtr function)
: m_call(call)
, m_function(function)
{
}
MacroAssembler::Call m_call;
FunctionPtr m_function;
};
struct InRecord {
InRecord(
MacroAssembler::PatchableJump jump, MacroAssembler::Label done,
SlowPathGenerator* slowPathGenerator, StructureStubInfo* stubInfo)
: m_jump(jump)
, m_done(done)
, m_slowPathGenerator(slowPathGenerator)
, m_stubInfo(stubInfo)
{
}
MacroAssembler::PatchableJump m_jump;
MacroAssembler::Label m_done;
SlowPathGenerator* m_slowPathGenerator;
StructureStubInfo* m_stubInfo;
};
// === JITCompiler ===
//
// DFG::JITCompiler is responsible for generating JIT code from the dataflow graph.
// It does so by delegating to the speculative & non-speculative JITs, which
// generate to a MacroAssembler (which the JITCompiler owns through an inheritance
// relationship). The JITCompiler holds references to information required during
// compilation, and also records information used in linking (e.g. a list of all
// call to be linked).
class JITCompiler : public CCallHelpers {
public:
JITCompiler(Graph& dfg);
~JITCompiler();
void compile();
void compileFunction();
// Accessors for properties.
Graph& graph() { return m_graph; }
// Methods to set labels for the disassembler.
void setStartOfCode()
{
m_pcToCodeOriginMapBuilder.appendItem(labelIgnoringWatchpoints(), CodeOrigin(0, nullptr));
if (LIKELY(!m_disassembler))
return;
m_disassembler->setStartOfCode(labelIgnoringWatchpoints());
}
void setForBlockIndex(BlockIndex blockIndex)
{
if (LIKELY(!m_disassembler))
return;
m_disassembler->setForBlockIndex(blockIndex, labelIgnoringWatchpoints());
}
void setForNode(Node* node)
{
if (LIKELY(!m_disassembler))
return;
m_disassembler->setForNode(node, labelIgnoringWatchpoints());
}
void setEndOfMainPath();
void setEndOfCode();
CallSiteIndex addCallSite(CodeOrigin codeOrigin)
{
return m_jitCode->common.addCodeOrigin(codeOrigin);
}
CallSiteIndex emitStoreCodeOrigin(CodeOrigin codeOrigin)
{
CallSiteIndex callSite = addCallSite(codeOrigin);
emitStoreCallSiteIndex(callSite);
return callSite;
}
void emitStoreCallSiteIndex(CallSiteIndex callSite)
{
store32(TrustedImm32(callSite.bits()), tagFor(static_cast<VirtualRegister>(CallFrameSlot::argumentCount)));
}
// Add a call out from JIT code, without an exception check.
Call appendCall(const FunctionPtr& function)
{
Call functionCall = call();
m_calls.append(CallLinkRecord(functionCall, function));
return functionCall;
}
void exceptionCheck();
void exceptionCheckWithCallFrameRollback()
{
m_exceptionChecksWithCallFrameRollback.append(emitExceptionCheck());
}
// Add a call out from JIT code, with a fast exception check that tests if the return value is zero.
void fastExceptionCheck()
{
callExceptionFuzz();
m_exceptionChecks.append(branchTestPtr(Zero, GPRInfo::returnValueGPR));
}
OSRExitCompilationInfo& appendExitInfo(MacroAssembler::JumpList jumpsToFail = MacroAssembler::JumpList())
{
OSRExitCompilationInfo info;
info.m_failureJumps = jumpsToFail;
m_exitCompilationInfo.append(info);
return m_exitCompilationInfo.last();
}
#if USE(JSVALUE32_64)
void* addressOfDoubleConstant(Node*);
#endif
void addGetById(const JITGetByIdGenerator& gen, SlowPathGenerator* slowPath)
{
m_getByIds.append(InlineCacheWrapper<JITGetByIdGenerator>(gen, slowPath));
}
void addPutById(const JITPutByIdGenerator& gen, SlowPathGenerator* slowPath)
{
m_putByIds.append(InlineCacheWrapper<JITPutByIdGenerator>(gen, slowPath));
}
void addIn(const InRecord& record)
{
m_ins.append(record);
}
void addJSCall(Call fastCall, Call slowCall, DataLabelPtr targetToCheck, CallLinkInfo* info)
{
m_jsCalls.append(JSCallRecord(fastCall, slowCall, targetToCheck, info));
}
void addJSDirectCall(Call call, Label slowPath, CallLinkInfo* info)
{
m_jsDirectCalls.append(JSDirectCallRecord(call, slowPath, info));
}
void addJSDirectTailCall(PatchableJump patchableJump, Call call, Label slowPath, CallLinkInfo* info)
{
m_jsDirectTailCalls.append(JSDirectTailCallRecord(patchableJump, call, slowPath, info));
}
void addWeakReference(JSCell* target)
{
m_graph.m_plan.weakReferences.addLazily(target);
}
void addWeakReferences(const StructureSet& structureSet)
{
for (unsigned i = structureSet.size(); i--;)
addWeakReference(structureSet[i]);
}
template<typename T>
Jump branchWeakPtr(RelationalCondition cond, T left, JSCell* weakPtr)
{
Jump result = branchPtr(cond, left, TrustedImmPtr(weakPtr));
addWeakReference(weakPtr);
return result;
}
template<typename T>
Jump branchWeakStructure(RelationalCondition cond, T left, RegisteredStructure weakStructure)
{
Structure* structure = weakStructure.get();
#if USE(JSVALUE64)
Jump result = branch32(cond, left, TrustedImm32(structure->id()));
return result;
#else
return branchPtr(cond, left, TrustedImmPtr(structure));
#endif
}
void noticeOSREntry(BasicBlock&, JITCompiler::Label blockHead, LinkBuffer&);
RefPtr<JITCode> jitCode() { return m_jitCode; }
Vector<Label>& blockHeads() { return m_blockHeads; }
CallSiteIndex recordCallSiteAndGenerateExceptionHandlingOSRExitIfNeeded(const CodeOrigin&, unsigned eventStreamIndex);
PCToCodeOriginMapBuilder& pcToCodeOriginMapBuilder() { return m_pcToCodeOriginMapBuilder; }
private:
friend class OSRExitJumpPlaceholder;
// Internal implementation to compile.
void compileEntry();
void compileSetupRegistersForEntry();
void compileEntryExecutionFlag();
void compileBody();
void link(LinkBuffer&);
void exitSpeculativeWithOSR(const OSRExit&, SpeculationRecovery*);
void compileExceptionHandlers();
void linkOSRExits();
void disassemble(LinkBuffer&);
void appendExceptionHandlingOSRExit(ExitKind, unsigned eventStreamIndex, CodeOrigin, HandlerInfo* exceptionHandler, CallSiteIndex, MacroAssembler::JumpList jumpsToFail = MacroAssembler::JumpList());
// The dataflow graph currently being generated.
Graph& m_graph;
std::unique_ptr<Disassembler> m_disassembler;
RefPtr<JITCode> m_jitCode;
// Vector of calls out from JIT code, including exception handler information.
// Count of the number of CallRecords with exception handlers.
Vector<CallLinkRecord> m_calls;
JumpList m_exceptionChecks;
JumpList m_exceptionChecksWithCallFrameRollback;
Vector<Label> m_blockHeads;
struct JSCallRecord {
JSCallRecord(Call fastCall, Call slowCall, DataLabelPtr targetToCheck, CallLinkInfo* info)
: fastCall(fastCall)
, slowCall(slowCall)
, targetToCheck(targetToCheck)
, info(info)
{
}
Call fastCall;
Call slowCall;
DataLabelPtr targetToCheck;
CallLinkInfo* info;
};
struct JSDirectCallRecord {
JSDirectCallRecord(Call call, Label slowPath, CallLinkInfo* info)
: call(call)
, slowPath(slowPath)
, info(info)
{
}
Call call;
Label slowPath;
CallLinkInfo* info;
};
struct JSDirectTailCallRecord {
JSDirectTailCallRecord(PatchableJump patchableJump, Call call, Label slowPath, CallLinkInfo* info)
: patchableJump(patchableJump)
, call(call)
, slowPath(slowPath)
, info(info)
{
}
PatchableJump patchableJump;
Call call;
Label slowPath;
CallLinkInfo* info;
};
Vector<InlineCacheWrapper<JITGetByIdGenerator>, 4> m_getByIds;
Vector<InlineCacheWrapper<JITPutByIdGenerator>, 4> m_putByIds;
Vector<InRecord, 4> m_ins;
Vector<JSCallRecord, 4> m_jsCalls;
Vector<JSDirectCallRecord, 4> m_jsDirectCalls;
Vector<JSDirectTailCallRecord, 4> m_jsDirectTailCalls;
SegmentedVector<OSRExitCompilationInfo, 4> m_exitCompilationInfo;
Vector<Vector<Label>> m_exitSiteLabels;
struct ExceptionHandlingOSRExitInfo {
OSRExitCompilationInfo& exitInfo;
HandlerInfo baselineExceptionHandler;
CallSiteIndex callSiteIndex;
};
Vector<ExceptionHandlingOSRExitInfo> m_exceptionHandlerOSRExitCallSites;
Call m_callArityFixup;
Label m_arityCheck;
std::unique_ptr<SpeculativeJIT> m_speculative;
PCToCodeOriginMapBuilder m_pcToCodeOriginMapBuilder;
};
} } // namespace JSC::DFG
#endif
|