| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef jit_BaselineCacheIRCompiler_h |
| 8 |
#define jit_BaselineCacheIRCompiler_h |
| 9 |
|
| 10 |
#include "mozilla/Attributes.h" |
| 11 |
#include "mozilla/Maybe.h" |
| 12 |
|
| 13 |
#include <stddef.h> |
| 14 |
#include <stdint.h> |
| 15 |
|
| 16 |
#include "jstypes.h" |
| 17 |
|
| 18 |
#include "jit/CacheIR.h" |
| 19 |
#include "jit/CacheIRCompiler.h" |
| 20 |
#include "jit/CacheIROpsGenerated.h" |
| 21 |
#include "jit/CacheIRReader.h" |
| 22 |
|
| 23 |
struct JS_PUBLIC_API JSContext; |
| 24 |
|
| 25 |
class JSScript; |
| 26 |
|
| 27 |
namespace js { |
| 28 |
namespace jit { |
| 29 |
|
| 30 |
class CacheIRWriter; |
| 31 |
class ICFallbackStub; |
| 32 |
class ICScript; |
| 33 |
class JitCode; |
| 34 |
class Label; |
| 35 |
class MacroAssembler; |
| 36 |
|
| 37 |
struct Address; |
| 38 |
struct Register; |
| 39 |
|
| 40 |
enum class ICAttachResult { Attached, DuplicateStub, TooLarge, OOM }; |
| 41 |
|
| 42 |
bool TryFoldingStubs(JSContext* cx, ICFallbackStub* fallback, JSScript* script, |
| 43 |
ICScript* icScript); |
| 44 |
|
| 45 |
ICAttachResult AttachBaselineCacheIRStub(JSContext* cx, |
| 46 |
const CacheIRWriter& writer, |
| 47 |
CacheKind kind, JSScript* outerScript, |
| 48 |
ICScript* icScript, |
| 49 |
ICFallbackStub* stub, |
| 50 |
const char* name); |
| 51 |
|
| 52 |
// BaselineCacheIRCompiler compiles CacheIR to BaselineIC native code. |
| 53 |
class MOZ_RAII BaselineCacheIRCompiler : public CacheIRCompiler { |
| 54 |
bool makesGCCalls_; |
| 55 |
uint8_t localTracingSlots_ = 0; |
| 56 |
Register baselineFrameReg_ = FramePointer; |
| 57 |
|
| 58 |
// This register points to the baseline frame of the caller. It should only |
| 59 |
// be used before we enter a stub frame. This is normally the frame pointer |
| 60 |
// register, but with --enable-ic-frame-pointers we have to allocate a |
| 61 |
// separate register. |
| 62 |
inline Register baselineFrameReg() { |
| 63 |
MOZ_ASSERT(!enteredStubFrame_); |
| 64 |
return baselineFrameReg_; |
| 65 |
} |
| 66 |
|
| 67 |
[[nodiscard]] bool emitStoreSlotShared(bool isFixed, ObjOperandId objId, |
| 68 |
uint32_t offsetOffset, |
| 69 |
ValOperandId rhsId); |
| 70 |
[[nodiscard]] bool emitAddAndStoreSlotShared( |
| 71 |
CacheOp op, ObjOperandId objId, uint32_t offsetOffset, ValOperandId rhsId, |
| 72 |
uint32_t newShapeOffset, mozilla::Maybe<uint32_t> numNewSlotsOffset); |
| 73 |
|
| 74 |
bool updateArgc(CallFlags flags, Register argcReg, Register scratch); |
| 75 |
void loadStackObject(ArgumentKind kind, CallFlags flags, Register argcReg, |
| 76 |
Register dest, uint32_t extraArgs = 0); |
| 77 |
void pushArguments(Register argcReg, Register calleeReg, Register scratch, |
| 78 |
Register scratch2, CallFlags flags, uint32_t argcFixed, |
| 79 |
bool isJitCall); |
| 80 |
void pushStandardArguments(Register argcReg, Register scratch, |
| 81 |
Register scratch2, uint32_t argcFixed, |
| 82 |
bool isJitCall, bool isConstructing); |
| 83 |
void pushArrayArguments(Register argcReg, Register scratch, Register scratch2, |
| 84 |
bool isJitCall, bool isConstructing); |
| 85 |
void pushFunCallArguments(Register argcReg, Register calleeReg, |
| 86 |
Register scratch, Register scratch2, |
| 87 |
uint32_t argcFixed, bool isJitCall); |
| 88 |
void pushFunApplyArgsObj(Register argcReg, Register calleeReg, |
| 89 |
Register scratch, Register scratch2, bool isJitCall); |
| 90 |
void pushFunApplyNullUndefinedArguments(Register calleeReg, bool isJitCall); |
| 91 |
void pushBoundFunctionArguments(Register argcReg, Register calleeReg, |
| 92 |
Register scratch, Register scratch2, |
| 93 |
CallFlags flags, uint32_t numBoundArgs, |
| 94 |
bool isJitCall); |
| 95 |
void createThis(Register argcReg, Register calleeReg, Register scratch, |
| 96 |
Register scratch2, CallFlags flags, |
| 97 |
mozilla::Maybe<uint32_t> numBoundArgs = mozilla::Nothing()); |
| 98 |
void updateReturnValue(); |
| 99 |
|
| 100 |
enum class NativeCallType { Native, ClassHook }; |
| 101 |
enum class ClearLocalAllocSite { No, Yes }; |
| 102 |
bool emitCallNativeShared( |
| 103 |
NativeCallType callType, ObjOperandId calleeId, Int32OperandId argcId, |
| 104 |
CallFlags flags, uint32_t argcFixed, |
| 105 |
mozilla::Maybe<bool> ignoresReturnValue, |
| 106 |
mozilla::Maybe<uint32_t> targetOffset, |
| 107 |
ClearLocalAllocSite clearLocalAllocSite = ClearLocalAllocSite::No); |
| 108 |
void loadAllocSiteIntoContext(uint32_t siteOffset); |
| 109 |
|
| 110 |
enum class StringCode { CodeUnit, CodePoint }; |
| 111 |
bool emitStringFromCodeResult(Int32OperandId codeId, StringCode stringCode); |
| 112 |
|
| 113 |
enum class StringCharOutOfBounds { Failure, EmptyString, UndefinedValue }; |
| 114 |
bool emitLoadStringCharResult(StringOperandId strId, Int32OperandId indexId, |
| 115 |
StringCharOutOfBounds outOfBounds); |
| 116 |
|
| 117 |
void emitAtomizeString(Register str, Register temp, Label* failure); |
| 118 |
|
| 119 |
bool emitCallScriptedGetterShared(ValOperandId receiverId, |
| 120 |
uint32_t getterOffset, bool sameRealm, |
| 121 |
uint32_t nargsAndFlagsOffset, |
| 122 |
mozilla::Maybe<uint32_t> icScriptOffset); |
| 123 |
bool emitCallScriptedSetterShared(ObjOperandId receiverId, |
| 124 |
uint32_t setterOffset, ValOperandId rhsId, |
| 125 |
bool sameRealm, |
| 126 |
uint32_t nargsAndFlagsOffset, |
| 127 |
mozilla::Maybe<uint32_t> icScriptOffset); |
| 128 |
|
| 129 |
template <typename IdType> |
| 130 |
bool emitCallScriptedProxyGetShared(ValOperandId targetId, |
| 131 |
ObjOperandId receiverId, |
| 132 |
ObjOperandId handlerId, |
| 133 |
ObjOperandId trapId, IdType id, |
| 134 |
uint32_t nargsAndFlags); |
| 135 |
|
| 136 |
BaselineICPerfSpewer perfSpewer_; |
| 137 |
|
| 138 |
public: |
| 139 |
BaselineICPerfSpewer& perfSpewer() { return perfSpewer_; } |
| 140 |
|
| 141 |
friend class AutoStubFrame; |
| 142 |
|
| 143 |
BaselineCacheIRCompiler(JSContext* cx, TempAllocator& alloc, |
| 144 |
const CacheIRWriter& writer, uint32_t stubDataOffset); |
| 145 |
|
| 146 |
[[nodiscard]] bool init(CacheKind kind); |
| 147 |
|
| 148 |
template <typename Fn, Fn fn> |
| 149 |
void callVM(MacroAssembler& masm); |
| 150 |
|
| 151 |
JitCode* compile(); |
| 152 |
|
| 153 |
bool makesGCCalls() const; |
| 154 |
bool localTracingSlots() const { return localTracingSlots_; } |
| 155 |
|
| 156 |
Address stubAddress(uint32_t offset) const; |
| 157 |
|
| 158 |
private: |
| 159 |
CACHE_IR_COMPILER_UNSHARED_GENERATED |
| 160 |
}; |
| 161 |
|
| 162 |
// Special object used for storing a list of shapes to guard against. These are |
| 163 |
// only used in the fields of CacheIR stubs and do not escape. |
| 164 |
class ShapeListObject : public ListObject { |
| 165 |
public: |
| 166 |
static const JSClass class_; |
| 167 |
static const JSClassOps classOps_; |
| 168 |
static ShapeListObject* create(JSContext* cx); |
| 169 |
static void trace(JSTracer* trc, JSObject* obj); |
| 170 |
|
| 171 |
Shape* get(uint32_t index); |
| 172 |
bool traceWeak(JSTracer* trc); |
| 173 |
}; |
| 174 |
|
| 175 |
} // namespace jit |
| 176 |
} // namespace js |
| 177 |
|
| 178 |
#endif /* jit_BaselineCacheIRCompiler_h */ |