Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / jit / CacheIRReader.h
blobaffefdac010766cc889f0487e7336209828d435d
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_CacheIRReader_h
8 #define jit_CacheIRReader_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
13 #include <stdint.h>
14 #include "NamespaceImports.h"
16 #include "jit/CacheIR.h"
17 #include "jit/CacheIRWriter.h"
18 #include "jit/CompactBuffer.h"
19 #include "js/ScalarType.h"
20 #include "js/Value.h"
21 #include "wasm/WasmValType.h"
23 enum class JSOp : uint8_t;
25 namespace js {
27 enum class UnaryMathFunction : uint8_t;
29 namespace gc {
30 enum class AllocKind : uint8_t;
33 namespace jit {
35 class CacheIRStubInfo;
37 // Helper class for reading CacheIR bytecode.
38 class MOZ_RAII CacheIRReader {
39 CompactBufferReader buffer_;
41 CacheIRReader(const CacheIRReader&) = delete;
42 CacheIRReader& operator=(const CacheIRReader&) = delete;
44 public:
45 CacheIRReader(const uint8_t* start, const uint8_t* end)
46 : buffer_(start, end) {}
47 explicit CacheIRReader(const CacheIRWriter& writer)
48 : CacheIRReader(writer.codeStart(), writer.codeEnd()) {}
49 explicit CacheIRReader(const CacheIRStubInfo* stubInfo);
51 bool more() const { return buffer_.more(); }
53 CacheOp readOp() { return CacheOp(buffer_.readFixedUint16_t()); }
54 CacheOp peekOp() { return CacheOp(buffer_.peekFixedUint16_t()); }
56 // Skip data not currently used.
57 void skip() { buffer_.readByte(); }
58 void skip(uint32_t skipLength) {
59 if (skipLength > 0) {
60 buffer_.seek(buffer_.currentPosition(), skipLength);
64 ValOperandId valOperandId() { return ValOperandId(buffer_.readByte()); }
65 ValueTagOperandId valueTagOperandId() {
66 return ValueTagOperandId(buffer_.readByte());
69 IntPtrOperandId intPtrOperandId() {
70 return IntPtrOperandId(buffer_.readByte());
73 ObjOperandId objOperandId() { return ObjOperandId(buffer_.readByte()); }
74 NumberOperandId numberOperandId() {
75 return NumberOperandId(buffer_.readByte());
77 StringOperandId stringOperandId() {
78 return StringOperandId(buffer_.readByte());
81 SymbolOperandId symbolOperandId() {
82 return SymbolOperandId(buffer_.readByte());
85 BigIntOperandId bigIntOperandId() {
86 return BigIntOperandId(buffer_.readByte());
89 BooleanOperandId booleanOperandId() {
90 return BooleanOperandId(buffer_.readByte());
93 Int32OperandId int32OperandId() { return Int32OperandId(buffer_.readByte()); }
95 uint32_t rawOperandId() { return buffer_.readByte(); }
97 uint32_t stubOffset() { return buffer_.readByte() * sizeof(uintptr_t); }
98 GuardClassKind guardClassKind() { return GuardClassKind(buffer_.readByte()); }
99 ValueType valueType() { return ValueType(buffer_.readByte()); }
100 wasm::ValType::Kind wasmValType() {
101 return wasm::ValType::Kind(buffer_.readByte());
103 gc::AllocKind allocKind() { return gc::AllocKind(buffer_.readByte()); }
104 CompletionKind completionKind() { return CompletionKind(buffer_.readByte()); }
105 RealmFuses::FuseIndex realmFuseIndex() {
106 return RealmFuses::FuseIndex(buffer_.readByte());
109 Scalar::Type scalarType() { return Scalar::Type(buffer_.readByte()); }
110 JSWhyMagic whyMagic() { return JSWhyMagic(buffer_.readByte()); }
111 JSOp jsop() { return JSOp(buffer_.readByte()); }
112 int32_t int32Immediate() { return int32_t(buffer_.readFixedUint32_t()); }
113 uint32_t uint32Immediate() { return buffer_.readFixedUint32_t(); }
114 void* pointer() { return buffer_.readRawPointer(); }
116 UnaryMathFunction unaryMathFunction() {
117 return UnaryMathFunction(buffer_.readByte());
120 CallFlags callFlags() {
121 // See CacheIRWriter::writeCallFlagsImm()
122 uint8_t encoded = buffer_.readByte();
123 CallFlags::ArgFormat format =
124 CallFlags::ArgFormat(encoded & CallFlags::ArgFormatMask);
125 bool isConstructing = encoded & CallFlags::IsConstructing;
126 bool isSameRealm = encoded & CallFlags::IsSameRealm;
127 bool needsUninitializedThis = encoded & CallFlags::NeedsUninitializedThis;
128 MOZ_ASSERT_IF(needsUninitializedThis, isConstructing);
129 switch (format) {
130 case CallFlags::Unknown:
131 MOZ_CRASH("Unexpected call flags");
132 case CallFlags::Standard:
133 return CallFlags(isConstructing, /*isSpread =*/false, isSameRealm,
134 needsUninitializedThis);
135 case CallFlags::Spread:
136 return CallFlags(isConstructing, /*isSpread =*/true, isSameRealm,
137 needsUninitializedThis);
138 default:
139 // The existing non-standard argument formats (FunCall and FunApply)
140 // can't be constructors.
141 MOZ_ASSERT(!isConstructing);
142 return CallFlags(format);
146 uint8_t readByte() { return buffer_.readByte(); }
147 bool readBool() {
148 uint8_t b = buffer_.readByte();
149 MOZ_ASSERT(b <= 1);
150 return bool(b);
153 const uint8_t* currentPosition() const { return buffer_.currentPosition(); }
156 } // namespace jit
157 } // namespace js
159 #endif /* jit_CacheIRReader_h */