IonCacheIRCompiler.h (3153B)
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_IonCacheIRCompiler_h 8 #define jit_IonCacheIRCompiler_h 9 10 #include "mozilla/Attributes.h" 11 #include "mozilla/Maybe.h" 12 13 #include <stdint.h> 14 15 #include "jstypes.h" 16 17 #include "jit/CacheIR.h" 18 #include "jit/CacheIRCompiler.h" 19 #include "jit/CacheIROpsGenerated.h" 20 #include "jit/CacheIRReader.h" 21 #include "jit/Registers.h" 22 #include "jit/RegisterSets.h" 23 #include "js/Vector.h" 24 25 struct JS_PUBLIC_API JSContext; 26 27 namespace js { 28 namespace jit { 29 30 class CacheIRWriter; 31 class CodeOffset; 32 class IonIC; 33 class IonICStub; 34 class IonScript; 35 class JitCode; 36 class MacroAssembler; 37 38 // IonCacheIRCompiler compiles CacheIR to IonIC native code. 39 class MOZ_RAII IonCacheIRCompiler : public CacheIRCompiler { 40 public: 41 friend class AutoSaveLiveRegisters; 42 friend class AutoCallVM; 43 44 IonCacheIRCompiler(JSContext* cx, TempAllocator& alloc, 45 const CacheIRWriter& writer, IonIC* ic, 46 IonScript* ionScript, uint32_t stubDataOffset); 47 48 [[nodiscard]] bool init(); 49 JitCode* compile(IonICStub* stub); 50 51 #ifdef DEBUG 52 void assertFloatRegisterAvailable(FloatRegister reg); 53 #endif 54 55 IonICPerfSpewer& perfSpewer() { return perfSpewer_; } 56 uint8_t localTracingSlots() const { return localTracingSlots_; } 57 58 private: 59 const CacheIRWriter& writer_; 60 IonIC* ic_; 61 IonScript* ionScript_; 62 63 Vector<CodeOffset, 4, SystemAllocPolicy> nextCodeOffsets_; 64 mozilla::Maybe<LiveRegisterSet> liveRegs_; 65 mozilla::Maybe<CodeOffset> stubJitCodeOffset_; 66 67 bool savedLiveRegs_; 68 uint8_t localTracingSlots_; 69 70 IonICPerfSpewer perfSpewer_; 71 72 template <typename T> 73 T rawPointerStubField(uint32_t offset); 74 75 template <typename T> 76 T rawInt64StubField(uint32_t offset); 77 78 void enterStubFrame(MacroAssembler& masm, const AutoSaveLiveRegisters&); 79 void storeTracedValue(MacroAssembler& masm, ValueOperand value); 80 void loadTracedValue(MacroAssembler& masm, uint8_t slotIndex, 81 ValueOperand value); 82 83 template <typename Fn, Fn fn> 84 void callVM(MacroAssembler& masm); 85 86 [[nodiscard]] bool emitAddAndStoreSlotShared( 87 CacheOp op, ObjOperandId objId, uint32_t offsetOffset, ValOperandId rhsId, 88 uint32_t newShapeOffset, mozilla::Maybe<uint32_t> numNewSlotsOffset, 89 bool preserveWrapper); 90 91 template <typename IdType> 92 [[nodiscard]] bool emitCallScriptedProxyGetShared( 93 ValOperandId targetId, ObjOperandId receiverId, ObjOperandId handlerId, 94 ObjOperandId trapId, IdType id, uint32_t nargsAndFlags); 95 96 enum class StringCharOutOfBounds { Failure, EmptyString, UndefinedValue }; 97 bool emitLoadStringCharResult(StringOperandId strId, Int32OperandId indexId, 98 StringCharOutOfBounds outOfBounds); 99 100 void pushStubCodePointer(); 101 102 CACHE_IR_COMPILER_UNSHARED_GENERATED 103 }; 104 105 } // namespace jit 106 } // namespace js 107 108 #endif /* jit_IonCacheIRCompiler_h */