WasmBCClass-inl.h (5200B)
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 // This is an INTERNAL header for Wasm baseline compiler: inline BaseCompiler 20 // methods that don't fit in any other group in particular. 21 22 #ifndef wasm_wasm_baseline_object_inl_h 23 #define wasm_wasm_baseline_object_inl_h 24 25 namespace js { 26 namespace wasm { 27 28 const FuncType& BaseCompiler::funcType() const { 29 return codeMeta_.getFuncType(func_.index); 30 } 31 32 bool BaseCompiler::usesMemory() const { 33 return codeMeta_.memories.length() > 0; 34 } 35 36 bool BaseCompiler::usesSharedMemory(uint32_t memoryIndex) const { 37 return codeMeta_.usesSharedMemory(memoryIndex); 38 } 39 40 const Local& BaseCompiler::localFromSlot(uint32_t slot, MIRType type) { 41 MOZ_ASSERT(localInfo_[slot].type == type); 42 return localInfo_[slot]; 43 } 44 45 BytecodeOffset BaseCompiler::bytecodeOffset() const { 46 return iter_.bytecodeOffset(); 47 } 48 49 TrapSiteDesc BaseCompiler::trapSiteDesc() const { 50 return TrapSiteDesc(bytecodeOffset()); 51 } 52 53 bool BaseCompiler::isMem32(uint32_t memoryIndex) const { 54 return codeMeta_.memories[memoryIndex].addressType() == AddressType::I32; 55 } 56 57 bool BaseCompiler::isMem64(uint32_t memoryIndex) const { 58 return codeMeta_.memories[memoryIndex].addressType() == AddressType::I64; 59 } 60 61 bool BaseCompiler::hugeMemoryEnabled(uint32_t memoryIndex) const { 62 return codeMeta_.hugeMemoryEnabled(memoryIndex); 63 } 64 65 uint32_t BaseCompiler::instanceOffsetOfMemoryBase(uint32_t memoryIndex) const { 66 if (memoryIndex == 0) { 67 return Instance::offsetOfMemory0Base(); 68 } 69 return Instance::offsetInData( 70 codeMeta_.offsetOfMemoryInstanceData(memoryIndex) + 71 offsetof(MemoryInstanceData, base)); 72 } 73 74 uint32_t BaseCompiler::instanceOffsetOfBoundsCheckLimit( 75 uint32_t memoryIndex, unsigned byteSize) const { 76 bool hasCustomPageSize = false; 77 #ifdef ENABLE_WASM_CUSTOM_PAGE_SIZES 78 hasCustomPageSize = 79 codeMeta_.memories[memoryIndex].pageSize() != PageSize::Standard; 80 #endif 81 82 if (memoryIndex == 0 && !hasCustomPageSize) { 83 return Instance::offsetOfMemory0BoundsCheckLimit(); 84 } 85 uintptr_t boundsCheckOffset; 86 #ifndef ENABLE_WASM_CUSTOM_PAGE_SIZES 87 boundsCheckOffset = offsetof(MemoryInstanceData, boundsCheckLimit); 88 #else 89 switch (byteSize) { 90 case 1: 91 boundsCheckOffset = offsetof(MemoryInstanceData, boundsCheckLimit); 92 break; 93 case 2: 94 boundsCheckOffset = offsetof(MemoryInstanceData, boundsCheckLimit16); 95 break; 96 case 4: 97 boundsCheckOffset = offsetof(MemoryInstanceData, boundsCheckLimit32); 98 break; 99 case 8: 100 boundsCheckOffset = offsetof(MemoryInstanceData, boundsCheckLimit64); 101 break; 102 case 16: 103 boundsCheckOffset = offsetof(MemoryInstanceData, boundsCheckLimit128); 104 break; 105 default: 106 MOZ_CRASH("invalid byte size for memory access"); 107 break; 108 } 109 #endif 110 return Instance::offsetInData( 111 codeMeta_.offsetOfMemoryInstanceData(memoryIndex) + boundsCheckOffset); 112 } 113 114 // The results parameter for BaseCompiler::emitCallArgs is used for 115 // regular Wasm calls. 116 struct NormalCallResults final { 117 const StackResultsLoc& results; 118 explicit NormalCallResults(const StackResultsLoc& results) 119 : results(results) {} 120 inline uint32_t onStackCount() const { return results.count(); } 121 inline StackResults stackResults() const { return results.stackResults(); } 122 inline void getStackResultArea(BaseStackFrame fr, RegPtr dest) const { 123 fr.computeOutgoingStackResultAreaPtr(results, dest); 124 } 125 }; 126 127 // The results parameter for BaseCompiler::emitCallArgs is used for 128 // Wasm return/tail calls. 129 struct TailCallResults final { 130 bool hasStackResults; 131 explicit TailCallResults(const FuncType& funcType) { 132 hasStackResults = 133 ABIResultIter::HasStackResults(ResultType::Vector(funcType.results())); 134 } 135 inline uint32_t onStackCount() const { return 0; } 136 inline StackResults stackResults() const { 137 return hasStackResults ? StackResults::HasStackResults 138 : StackResults::NoStackResults; 139 } 140 inline void getStackResultArea(BaseStackFrame fr, RegPtr dest) const { 141 fr.loadIncomingStackResultAreaPtr(dest); 142 } 143 }; 144 145 // The results parameter for BaseCompiler::emitCallArgs is used when 146 // no result (area) is expected. 147 struct NoCallResults final { 148 inline uint32_t onStackCount() const { return 0; } 149 inline StackResults stackResults() const { 150 return StackResults::NoStackResults; 151 } 152 inline void getStackResultArea(BaseStackFrame fr, RegPtr dest) const { 153 MOZ_CRASH(); 154 } 155 }; 156 157 } // namespace wasm 158 } // namespace js 159 160 #endif // wasm_wasm_baseline_object_inl_h