1 | /* |
2 | * Copyright (C) 2016-2017 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 | #include "config.h" |
27 | #include "WasmCallee.h" |
28 | |
29 | #if ENABLE(WEBASSEMBLY) |
30 | |
31 | #include "LLIntThunks.h" |
32 | #include "WasmCalleeRegistry.h" |
33 | #include "WasmCallingConvention.h" |
34 | |
35 | namespace JSC { namespace Wasm { |
36 | |
37 | Callee::Callee(Wasm::CompilationMode compilationMode) |
38 | : m_compilationMode(compilationMode) |
39 | { |
40 | CalleeRegistry::singleton().registerCallee(this); |
41 | } |
42 | |
43 | Callee::Callee(Wasm::CompilationMode compilationMode, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name) |
44 | : m_compilationMode(compilationMode) |
45 | , m_indexOrName(index, WTFMove(name)) |
46 | { |
47 | CalleeRegistry::singleton().registerCallee(this); |
48 | } |
49 | |
50 | Callee::~Callee() |
51 | { |
52 | CalleeRegistry::singleton().unregisterCallee(this); |
53 | } |
54 | |
55 | void Callee::dump(PrintStream& out) const |
56 | { |
57 | out.print(makeString(m_indexOrName)); |
58 | } |
59 | |
60 | JITCallee::JITCallee(Wasm::CompilationMode compilationMode, Entrypoint&& entrypoint) |
61 | : Callee(compilationMode) |
62 | , m_entrypoint(WTFMove(entrypoint)) |
63 | { |
64 | } |
65 | |
66 | JITCallee::JITCallee(Wasm::CompilationMode compilationMode, Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name, Vector<UnlinkedWasmToWasmCall>&& unlinkedCalls) |
67 | : Callee(compilationMode, index, WTFMove(name)) |
68 | , m_wasmToWasmCallsites(WTFMove(unlinkedCalls)) |
69 | , m_entrypoint(WTFMove(entrypoint)) |
70 | { |
71 | } |
72 | |
73 | void LLIntCallee::setEntrypoint(MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint) |
74 | { |
75 | m_entrypoint = entrypoint; |
76 | } |
77 | |
78 | MacroAssemblerCodePtr<WasmEntryPtrTag> LLIntCallee::entrypoint() const |
79 | { |
80 | return m_entrypoint; |
81 | } |
82 | |
83 | RegisterAtOffsetList* LLIntCallee::calleeSaveRegisters() |
84 | { |
85 | static LazyNeverDestroyed<RegisterAtOffsetList> calleeSaveRegisters; |
86 | static std::once_flag initializeFlag; |
87 | std::call_once(initializeFlag, [] { |
88 | RegisterSet registers; |
89 | registers.set(GPRInfo::regCS0); // Wasm::Instance |
90 | #if CPU(X86_64) |
91 | registers.set(GPRInfo::regCS2); // PB |
92 | #elif CPU(ARM64) |
93 | registers.set(GPRInfo::regCS7); // PB |
94 | #else |
95 | #error Unsupported architecture. |
96 | #endif |
97 | registers.set(GPRInfo::regCS3); // Memory base |
98 | registers.set(GPRInfo::regCS4); // Memory size |
99 | ASSERT(registers.numberOfSetRegisters() == numberOfLLIntCalleeSaveRegisters); |
100 | calleeSaveRegisters.construct(WTFMove(registers)); |
101 | }); |
102 | return &calleeSaveRegisters.get(); |
103 | } |
104 | |
105 | std::tuple<void*, void*> LLIntCallee::range() const |
106 | { |
107 | return { nullptr, nullptr }; |
108 | } |
109 | |
110 | } } // namespace JSC::Wasm |
111 | |
112 | #endif // ENABLE(WEBASSEMBLY) |
113 | |