| 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 |
* |
| 4 |
* Copyright 2016 Mozilla Foundation |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, software |
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
* See the License for the specific language governing permissions and |
| 16 |
* limitations under the License. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef asmjs_wasm_baseline_compile_h |
| 20 |
#define asmjs_wasm_baseline_compile_h |
| 21 |
|
| 22 |
#include "jit/ABIArgGenerator.h" |
| 23 |
#include "wasm/WasmGenerator.h" |
| 24 |
|
| 25 |
namespace js { |
| 26 |
namespace wasm { |
| 27 |
|
| 28 |
// Return whether BaselineCompileFunction can generate code on the current |
| 29 |
// device. Usually you do *not* want to call this, you want |
| 30 |
// BaselineAvailable(). |
| 31 |
[[nodiscard]] bool BaselinePlatformSupport(); |
| 32 |
|
| 33 |
// Generate adequate code quickly. |
| 34 |
[[nodiscard]] bool BaselineCompileFunctions( |
| 35 |
const CodeMetadata& codeMeta, const CompilerEnvironment& compilerEnv, |
| 36 |
LifoAlloc& lifo, const FuncCompileInputVector& inputs, CompiledCode* code, |
| 37 |
UniqueChars* error); |
| 38 |
|
| 39 |
// BaseLocalIter iterates over a vector of types of locals and provides offsets |
| 40 |
// from the Frame address for those locals, and associated data. |
| 41 |
// |
| 42 |
// The implementation of BaseLocalIter is the property of the BaseStackFrame. |
| 43 |
// But it is also exposed for eg the debugger to use. |
| 44 |
class BaseLocalIter { |
| 45 |
private: |
| 46 |
using ConstValTypeRange = mozilla::Range<const ValType>; |
| 47 |
|
| 48 |
const ValTypeVector& locals_; |
| 49 |
const ArgTypeVector& args_; |
| 50 |
jit::WasmABIArgIter<ArgTypeVector> argsIter_; |
| 51 |
size_t index_; |
| 52 |
int32_t frameSize_; |
| 53 |
int32_t nextFrameSize_; |
| 54 |
int32_t frameOffset_; |
| 55 |
int32_t stackResultPointerOffset_; |
| 56 |
jit::MIRType mirType_; |
| 57 |
bool done_; |
| 58 |
|
| 59 |
void settle(); |
| 60 |
int32_t pushLocal(size_t nbytes); |
| 61 |
|
| 62 |
public: |
| 63 |
BaseLocalIter(const ValTypeVector& locals, const ArgTypeVector& args, |
| 64 |
bool debugEnabled); |
| 65 |
void operator++(int); |
| 66 |
bool done() const { return done_; } |
| 67 |
|
| 68 |
jit::MIRType mirType() const { |
| 69 |
MOZ_ASSERT(!done_); |
| 70 |
return mirType_; |
| 71 |
} |
| 72 |
int32_t frameOffset() const { |
| 73 |
MOZ_ASSERT(!done_); |
| 74 |
MOZ_ASSERT(frameOffset_ != INT32_MAX); |
| 75 |
return frameOffset_; |
| 76 |
} |
| 77 |
size_t index() const { |
| 78 |
MOZ_ASSERT(!done_); |
| 79 |
return index_; |
| 80 |
} |
| 81 |
// The size in bytes taken up by the previous `index_` locals, also including |
| 82 |
// fixed allocations like the DebugFrame and "hidden" locals like a spilled |
| 83 |
// stack results pointer. |
| 84 |
int32_t frameSize() const { return frameSize_; } |
| 85 |
|
| 86 |
int32_t stackResultPointerOffset() const { |
| 87 |
MOZ_ASSERT(args_.hasSyntheticStackResultPointerArg()); |
| 88 |
MOZ_ASSERT(stackResultPointerOffset_ != INT32_MAX); |
| 89 |
return stackResultPointerOffset_; |
| 90 |
} |
| 91 |
|
| 92 |
#ifdef DEBUG |
| 93 |
bool isArg() const { |
| 94 |
MOZ_ASSERT(!done_); |
| 95 |
return !argsIter_.done(); |
| 96 |
} |
| 97 |
#endif |
| 98 |
}; |
| 99 |
|
| 100 |
} // namespace wasm |
| 101 |
} // namespace js |
| 102 |
|
| 103 |
#endif // asmjs_wasm_baseline_compile_h |