1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sts=4 et sw=4 tw=99:
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_BaselineCacheIR_h
8 #define jit_BaselineCacheIR_h
9 
10 #include "gc/Barrier.h"
11 #include "jit/CacheIR.h"
12 
13 namespace js {
14 namespace jit {
15 
16 class ICFallbackStub;
17 class ICStub;
18 
19 // See the 'Sharing Baseline stub code' comment in CacheIR.h for a description
20 // of this class.
21 class CacheIRStubInfo
22 {
23     CacheKind kind_;
24     uint8_t stubDataOffset_;
25     const uint8_t* code_;
26     uint32_t length_;
27     const uint8_t* gcTypes_;
28 
CacheIRStubInfo(CacheKind kind,uint32_t stubDataOffset,const uint8_t * code,uint32_t codeLength,const uint8_t * gcTypes)29     CacheIRStubInfo(CacheKind kind, uint32_t stubDataOffset, const uint8_t* code, uint32_t codeLength,
30                     const uint8_t* gcTypes)
31       : kind_(kind),
32         stubDataOffset_(stubDataOffset),
33         code_(code),
34         length_(codeLength),
35         gcTypes_(gcTypes)
36     {
37         MOZ_ASSERT(stubDataOffset_ == stubDataOffset, "stubDataOffset must fit in uint8_t");
38     }
39 
40     CacheIRStubInfo(const CacheIRStubInfo&) = delete;
41     CacheIRStubInfo& operator=(const CacheIRStubInfo&) = delete;
42 
43   public:
kind()44     CacheKind kind() const { return kind_; }
45 
code()46     const uint8_t* code() const { return code_; }
codeLength()47     uint32_t codeLength() const { return length_; }
stubDataOffset()48     uint32_t stubDataOffset() const { return stubDataOffset_; }
49 
gcType(uint32_t i)50     StubField::GCType gcType(uint32_t i) const { return (StubField::GCType)gcTypes_[i]; }
51 
52     static CacheIRStubInfo* New(CacheKind kind, uint32_t stubDataOffset,
53                                 const CacheIRWriter& writer);
54 
55     template <class T>
56     js::GCPtr<T>& getStubField(ICStub* stub, uint32_t field) const;
57 };
58 
59 void TraceBaselineCacheIRStub(JSTracer* trc, ICStub* stub, const CacheIRStubInfo* stubInfo);
60 
61 ICStub* AttachBaselineCacheIRStub(JSContext* cx, const CacheIRWriter& writer, CacheKind kind,
62                                   ICFallbackStub* stub);
63 
64 } // namespace jit
65 } // namespace js
66 
67 #endif /* jit_BaselineCacheIR_h */
68