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 "wasm/WasmGenerator.h" 23 24 namespace js { 25 namespace wasm { 26 27 // Return whether BaselineCompileFunction can generate code on the current 28 // device. Usually you do *not* want to call this, you want 29 // BaselineAvailable(). 30 [[nodiscard]] bool BaselinePlatformSupport(); 31 32 // Generate adequate code quickly. 33 [[nodiscard]] bool BaselineCompileFunctions( 34 const ModuleEnvironment& moduleEnv, const CompilerEnvironment& compilerEnv, 35 LifoAlloc& lifo, const FuncCompileInputVector& inputs, CompiledCode* code, 36 UniqueChars* error); 37 38 class BaseLocalIter { 39 private: 40 using ConstValTypeRange = mozilla::Range<const ValType>; 41 42 const ValTypeVector& locals_; 43 const ArgTypeVector& args_; 44 jit::WasmABIArgIter<ArgTypeVector> argsIter_; 45 size_t index_; 46 int32_t frameSize_; 47 int32_t nextFrameSize_; 48 int32_t frameOffset_; 49 int32_t stackResultPointerOffset_; 50 jit::MIRType mirType_; 51 bool done_; 52 53 void settle(); 54 int32_t pushLocal(size_t nbytes); 55 56 public: 57 BaseLocalIter(const ValTypeVector& locals, const ArgTypeVector& args, 58 bool debugEnabled); 59 void operator++(int); done()60 bool done() const { return done_; } 61 mirType()62 jit::MIRType mirType() const { 63 MOZ_ASSERT(!done_); 64 return mirType_; 65 } frameOffset()66 int32_t frameOffset() const { 67 MOZ_ASSERT(!done_); 68 MOZ_ASSERT(frameOffset_ != INT32_MAX); 69 return frameOffset_; 70 } index()71 size_t index() const { 72 MOZ_ASSERT(!done_); 73 return index_; 74 } 75 // The size in bytes taken up by the previous `index_` locals, also including 76 // fixed allocations like the DebugFrame and "hidden" locals like a spilled 77 // stack results pointer. frameSize()78 int32_t frameSize() const { return frameSize_; } 79 stackResultPointerOffset()80 int32_t stackResultPointerOffset() const { 81 MOZ_ASSERT(args_.hasSyntheticStackResultPointerArg()); 82 MOZ_ASSERT(stackResultPointerOffset_ != INT32_MAX); 83 return stackResultPointerOffset_; 84 } 85 86 #ifdef DEBUG isArg()87 bool isArg() const { 88 MOZ_ASSERT(!done_); 89 return !argsIter_.done(); 90 } 91 #endif 92 }; 93 94 } // namespace wasm 95 } // namespace js 96 97 #endif // asmjs_wasm_baseline_compile_h 98