1/*
2 * Copyright (C) 2015-2018 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(FTL_JIT)
29
30#include "CCallHelpers.h"
31#include "CodeBlock.h"
32#include "CodeLocation.h"
33#include "GPRInfo.h"
34#include "MacroAssemblerCodeRef.h"
35#include "RegisterSet.h"
36#include "ScratchRegisterAllocator.h"
37#include <wtf/SharedTask.h>
38
39namespace JSC { namespace FTL {
40
41// A LazySlowPath is an object that represents a piece of code that is part of FTL generated code
42// that will be generated lazily. It holds all of the important information needed to generate that
43// code, such as where to link jumps to and which registers are in use. It also has a reference to a
44// SharedTask that will do the actual code generation. That SharedTask may have additional data, like
45// which registers hold the inputs or outputs.
46class LazySlowPath {
47 WTF_MAKE_NONCOPYABLE(LazySlowPath);
48 WTF_MAKE_FAST_ALLOCATED;
49public:
50 struct GenerationParams {
51 // Extra parameters to the GeneratorFunction are made into fields of this struct, so that if
52 // we add new parameters, we don't have to change all of the users.
53 CCallHelpers::JumpList doneJumps;
54 CCallHelpers::JumpList* exceptionJumps;
55 LazySlowPath* lazySlowPath;
56 };
57
58 typedef void GeneratorFunction(CCallHelpers&, GenerationParams&);
59 typedef SharedTask<GeneratorFunction> Generator;
60
61 template<typename Functor>
62 static Ref<Generator> createGenerator(const Functor& functor)
63 {
64 return createSharedTask<GeneratorFunction>(functor);
65 }
66
67 LazySlowPath() = default;
68
69 ~LazySlowPath();
70
71 void initialize(
72 CodeLocationJump<JSInternalPtrTag> patchableJump, CodeLocationLabel<JSInternalPtrTag> done,
73 CodeLocationLabel<ExceptionHandlerPtrTag> exceptionTarget, const RegisterSet& usedRegisters,
74 CallSiteIndex, RefPtr<Generator>
75 );
76
77 CodeLocationJump<JSInternalPtrTag> patchableJump() const { return m_patchableJump; }
78 CodeLocationLabel<JSInternalPtrTag> done() const { return m_done; }
79 const RegisterSet& usedRegisters() const { return m_usedRegisters; }
80 CallSiteIndex callSiteIndex() const { return m_callSiteIndex; }
81
82 void generate(CodeBlock*);
83
84 MacroAssemblerCodeRef<JITStubRoutinePtrTag> stub() const { return m_stub; }
85
86private:
87 CodeLocationJump<JSInternalPtrTag> m_patchableJump;
88 CodeLocationLabel<JSInternalPtrTag> m_done;
89 CodeLocationLabel<ExceptionHandlerPtrTag> m_exceptionTarget;
90 RegisterSet m_usedRegisters;
91 CallSiteIndex m_callSiteIndex;
92 MacroAssemblerCodeRef<JITStubRoutinePtrTag> m_stub;
93 RefPtr<Generator> m_generator;
94};
95
96} } // namespace JSC::FTL
97
98#endif // ENABLE(FTL_JIT)
99