Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / jit / Safepoints.h
blobb5e2f4f091f8aadfdec4956252f54bad2b7b18c3
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/. */
7 #ifndef jit_Safepoints_h
8 #define jit_Safepoints_h
10 #include <stddef.h>
11 #include <stdint.h>
13 #include "jit/BitSet.h"
14 #include "jit/CompactBuffer.h"
15 #include "jit/RegisterSets.h"
17 namespace js {
18 namespace jit {
20 class CodeLocationLabel;
21 class IonScript;
22 class SafepointIndex;
23 struct SafepointSlotEntry;
24 class TempAllocator;
26 class LAllocation;
27 class LSafepoint;
29 static const uint32_t INVALID_SAFEPOINT_OFFSET = uint32_t(-1);
31 class SafepointWriter {
32 CompactBufferWriter stream_;
33 BitSet localSlots_;
34 BitSet argumentSlots_;
36 public:
37 explicit SafepointWriter(uint32_t localSlotsSize, uint32_t argumentsSize);
38 [[nodiscard]] bool init(TempAllocator& alloc);
40 private:
41 // A safepoint entry is written in the order these functions appear.
42 uint32_t startEntry();
44 void writeOsiCallPointOffset(uint32_t osiPointOffset);
45 void writeGcRegs(LSafepoint* safepoint);
46 void writeGcSlots(LSafepoint* safepoint);
48 void writeSlotsOrElementsSlots(LSafepoint* safepoint);
49 void writeWasmAnyRefSlots(LSafepoint* safepoint);
51 #ifdef JS_PUNBOX64
52 void writeValueSlots(LSafepoint* safepoint);
53 #else
54 void writeNunboxParts(LSafepoint* safepoint);
55 #endif
57 void endEntry();
59 public:
60 void encode(LSafepoint* safepoint);
62 size_t size() const { return stream_.length(); }
63 const uint8_t* buffer() const { return stream_.buffer(); }
64 bool oom() const { return stream_.oom(); }
67 class SafepointReader {
68 CompactBufferReader stream_;
69 uint32_t localSlots_;
70 uint32_t argumentSlots_;
71 uint32_t currentSlotChunk_;
72 bool currentSlotsAreStack_;
73 uint32_t nextSlotChunkNumber_;
74 uint32_t osiCallPointOffset_;
75 GeneralRegisterSet gcSpills_;
76 GeneralRegisterSet valueSpills_;
77 GeneralRegisterSet slotsOrElementsSpills_;
78 GeneralRegisterSet allGprSpills_;
79 GeneralRegisterSet wasmAnyRefSpills_;
80 FloatRegisterSet allFloatSpills_;
81 uint32_t nunboxSlotsRemaining_;
82 uint32_t slotsOrElementsSlotsRemaining_;
83 uint32_t wasmAnyRefSlotsRemaining_;
85 private:
86 void advanceFromGcRegs();
87 void advanceFromGcSlots();
88 void advanceFromNunboxOrValueSlots();
89 void advanceFromSlotsOrElementsSlots();
90 [[nodiscard]] bool getSlotFromBitmap(SafepointSlotEntry* entry);
92 public:
93 SafepointReader(IonScript* script, const SafepointIndex* si);
95 static CodeLocationLabel InvalidationPatchPoint(IonScript* script,
96 const SafepointIndex* si);
98 uint32_t osiCallPointOffset() const { return osiCallPointOffset_; }
99 LiveGeneralRegisterSet gcSpills() const {
100 return LiveGeneralRegisterSet(gcSpills_);
102 LiveGeneralRegisterSet slotsOrElementsSpills() const {
103 return LiveGeneralRegisterSet(slotsOrElementsSpills_);
105 LiveGeneralRegisterSet wasmAnyRefSpills() const {
106 return LiveGeneralRegisterSet(wasmAnyRefSpills_);
108 LiveGeneralRegisterSet valueSpills() const {
109 return LiveGeneralRegisterSet(valueSpills_);
111 LiveGeneralRegisterSet allGprSpills() const {
112 return LiveGeneralRegisterSet(allGprSpills_);
114 LiveFloatRegisterSet allFloatSpills() const {
115 return LiveFloatRegisterSet(allFloatSpills_);
117 uint32_t osiReturnPointOffset() const;
119 // Returns true if a slot was read, false if there are no more slots.
120 [[nodiscard]] bool getGcSlot(SafepointSlotEntry* entry);
122 // Returns true if a slot was read, false if there are no more value slots.
123 [[nodiscard]] bool getValueSlot(SafepointSlotEntry* entry);
125 // Returns true if a nunbox slot was read, false if there are no more
126 // nunbox slots.
127 [[nodiscard]] bool getNunboxSlot(LAllocation* type, LAllocation* payload);
129 // Returns true if a slot was read, false if there are no more slots.
130 [[nodiscard]] bool getSlotsOrElementsSlot(SafepointSlotEntry* entry);
132 // Returns true if a slot was read, false if there are no more slots.
133 [[nodiscard]] bool getWasmAnyRefSlot(SafepointSlotEntry* entry);
136 } // namespace jit
137 } // namespace js
139 #endif /* jit_Safepoints_h */