Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/js/src/jit/shared/BaselineCompiler-shared.h
Line
Count
Source (jump to first uncovered line)
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_shared_BaselineCompiler_shared_h
8
#define jit_shared_BaselineCompiler_shared_h
9
10
#include "jit/BaselineFrameInfo.h"
11
#include "jit/BaselineIC.h"
12
#include "jit/BytecodeAnalysis.h"
13
#include "jit/MacroAssembler.h"
14
15
namespace js {
16
namespace jit {
17
18
class BaselineCompilerShared
19
{
20
  protected:
21
    JSContext* cx;
22
    JSScript* script;
23
    jsbytecode* pc;
24
    StackMacroAssembler masm;
25
    bool ionCompileable_;
26
    bool compileDebugInstrumentation_;
27
28
    TempAllocator& alloc_;
29
    BytecodeAnalysis analysis_;
30
    FrameInfo frame;
31
32
    FallbackICStubSpace stubSpace_;
33
    js::Vector<ICEntry, 16, SystemAllocPolicy> icEntries_;
34
35
    // Stores the native code offset for a bytecode pc.
36
    struct PCMappingEntry
37
    {
38
        uint32_t pcOffset;
39
        uint32_t nativeOffset;
40
        PCMappingSlotInfo slotInfo;
41
42
        // If set, insert a PCMappingIndexEntry before encoding the
43
        // current entry.
44
        bool addIndexEntry;
45
    };
46
47
    js::Vector<PCMappingEntry, 16, SystemAllocPolicy> pcMappingEntries_;
48
49
    // Labels for the 'movWithPatch' for loading IC entry pointers in
50
    // the generated IC-calling code in the main jitcode.  These need
51
    // to be patched with the actual icEntry offsets after the BaselineScript
52
    // has been allocated.
53
    struct ICLoadLabel {
54
        size_t icEntry;
55
        CodeOffset label;
56
    };
57
    js::Vector<ICLoadLabel, 16, SystemAllocPolicy> icLoadLabels_;
58
59
    uint32_t pushedBeforeCall_;
60
#ifdef DEBUG
61
    bool inCall_;
62
#endif
63
64
    CodeOffset profilerPushToggleOffset_;
65
    CodeOffset profilerEnterFrameToggleOffset_;
66
    CodeOffset profilerExitFrameToggleOffset_;
67
68
    Vector<CodeOffset> traceLoggerToggleOffsets_;
69
    CodeOffset traceLoggerScriptTextIdOffset_;
70
71
    BaselineCompilerShared(JSContext* cx, TempAllocator& alloc, JSScript* script);
72
73
334
    ICEntry* allocateICEntry(ICStub* stub, ICEntry::Kind kind) {
74
334
        if (!stub) {
75
0
            return nullptr;
76
0
        }
77
334
78
334
        // Create the entry and add it to the vector.
79
334
        if (!icEntries_.append(ICEntry(script->pcToOffset(pc), kind))) {
80
0
            ReportOutOfMemory(cx);
81
0
            return nullptr;
82
0
        }
83
334
        ICEntry& vecEntry = icEntries_.back();
84
334
85
334
        // Set the first stub for the IC entry to the fallback stub
86
334
        vecEntry.setFirstStub(stub);
87
334
88
334
        // Return pointer to the IC entry
89
334
        return &vecEntry;
90
334
    }
91
92
    // Append an ICEntry without a stub.
93
45
    bool appendICEntry(ICEntry::Kind kind, uint32_t returnOffset) {
94
45
        ICEntry entry(script->pcToOffset(pc), kind);
95
45
        entry.setReturnOffset(CodeOffset(returnOffset));
96
45
        if (!icEntries_.append(entry)) {
97
0
            ReportOutOfMemory(cx);
98
0
            return false;
99
0
        }
100
45
        return true;
101
45
    }
102
103
334
    bool addICLoadLabel(CodeOffset label) {
104
334
        MOZ_ASSERT(!icEntries_.empty());
105
334
        ICLoadLabel loadLabel;
106
334
        loadLabel.label = label;
107
334
        loadLabel.icEntry = icEntries_.length() - 1;
108
334
        if (!icLoadLabels_.append(loadLabel)) {
109
0
            ReportOutOfMemory(cx);
110
0
            return false;
111
0
        }
112
334
        return true;
113
334
    }
114
115
90
    JSFunction* function() const {
116
90
        // Not delazifying here is ok as the function is guaranteed to have
117
90
        // been delazified before compilation started.
118
90
        return script->functionNonDelazifying();
119
90
    }
120
121
0
    ModuleObject* module() const {
122
0
        return script->module();
123
0
    }
124
125
1.02k
    PCMappingSlotInfo getStackTopSlotInfo() {
126
1.02k
        MOZ_ASSERT(frame.numUnsyncedSlots() <= 2);
127
1.02k
        switch (frame.numUnsyncedSlots()) {
128
1.02k
          case 0:
129
364
            return PCMappingSlotInfo::MakeSlotInfo();
130
1.02k
          case 1:
131
391
            return PCMappingSlotInfo::MakeSlotInfo(PCMappingSlotInfo::ToSlotLocation(frame.peek(-1)));
132
1.02k
          case 2:
133
271
          default:
134
271
            return PCMappingSlotInfo::MakeSlotInfo(PCMappingSlotInfo::ToSlotLocation(frame.peek(-1)),
135
271
                                                   PCMappingSlotInfo::ToSlotLocation(frame.peek(-2)));
136
1.02k
        }
137
1.02k
    }
138
139
    template <typename T>
140
60
    void pushArg(const T& t) {
141
60
        masm.Push(t);
142
60
    }
void js::jit::BaselineCompilerShared::pushArg<js::jit::Imm32>(js::jit::Imm32 const&)
Line
Count
Source
140
35
    void pushArg(const T& t) {
141
35
        masm.Push(t);
142
35
    }
void js::jit::BaselineCompilerShared::pushArg<js::jit::Register>(js::jit::Register const&)
Line
Count
Source
140
20
    void pushArg(const T& t) {
141
20
        masm.Push(t);
142
20
    }
Unexecuted instantiation: void js::jit::BaselineCompilerShared::pushArg<js::jit::ImmPtr>(js::jit::ImmPtr const&)
void js::jit::BaselineCompilerShared::pushArg<js::jit::ValueOperand>(js::jit::ValueOperand const&)
Line
Count
Source
140
2
    void pushArg(const T& t) {
141
2
        masm.Push(t);
142
2
    }
Unexecuted instantiation: void js::jit::BaselineCompilerShared::pushArg<js::jit::ImmWord>(js::jit::ImmWord const&)
void js::jit::BaselineCompilerShared::pushArg<js::jit::ImmGCPtr>(js::jit::ImmGCPtr const&)
Line
Count
Source
140
3
    void pushArg(const T& t) {
141
3
        masm.Push(t);
142
3
    }
143
    void prepareVMCall();
144
145
    enum CallVMPhase {
146
        POST_INITIALIZE,
147
        PRE_INITIALIZE,
148
        CHECK_OVER_RECURSED
149
    };
150
    bool callVM(const VMFunction& fun, CallVMPhase phase=POST_INITIALIZE);
151
152
16
    bool callVMNonOp(const VMFunction& fun, CallVMPhase phase=POST_INITIALIZE) {
153
16
        if (!callVM(fun, phase)) {
154
0
            return false;
155
0
        }
156
16
        icEntries_.back().setFakeKind(ICEntry::Kind_NonOpCallVM);
157
16
        return true;
158
16
    }
159
160
  public:
161
0
    BytecodeAnalysis& analysis() {
162
0
        return analysis_;
163
0
    }
164
165
0
    void setCompileDebugInstrumentation() {
166
0
        compileDebugInstrumentation_ = true;
167
0
    }
168
};
169
170
} // namespace jit
171
} // namespace js
172
173
#endif /* jit_shared_BaselineCompiler_shared_h */