| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #include "v8.h" | |
| 29 | |
| 30 #include "cfg.h" | |
| 31 #include "codegen-inl.h" | |
| 32 #include "codegen-ia32.h" | |
| 33 #include "macro-assembler-ia32.h" | |
| 34 | |
| 35 namespace v8 { | |
| 36 namespace internal { | |
| 37 | |
| 38 #define __ ACCESS_MASM(masm) | |
| 39 | |
| 40 void InstructionBlock::Compile(MacroAssembler* masm) { | |
| 41 ASSERT(!is_marked()); | |
| 42 is_marked_ = true; | |
| 43 { | |
| 44 Comment cmt(masm, "[ InstructionBlock"); | |
| 45 for (int i = 0, len = instructions_.length(); i < len; i++) { | |
| 46 // If the location of the current instruction is a temp, then the | |
| 47 // instruction cannot be in tail position in the block. Allocate the | |
| 48 // temp based on peeking ahead to the next instruction. | |
| 49 Instruction* instr = instructions_[i]; | |
| 50 Location* loc = instr->location(); | |
| 51 if (loc->is_temporary()) { | |
| 52 instructions_[i+1]->FastAllocate(TempLocation::cast(loc)); | |
| 53 } | |
| 54 instructions_[i]->Compile(masm); | |
| 55 } | |
| 56 } | |
| 57 successor_->Compile(masm); | |
| 58 } | |
| 59 | |
| 60 | |
| 61 void EntryNode::Compile(MacroAssembler* masm) { | |
| 62 ASSERT(!is_marked()); | |
| 63 is_marked_ = true; | |
| 64 Label deferred_enter, deferred_exit; | |
| 65 { | |
| 66 Comment cmnt(masm, "[ EntryNode"); | |
| 67 __ push(ebp); | |
| 68 __ mov(ebp, esp); | |
| 69 __ push(esi); | |
| 70 __ push(edi); | |
| 71 int count = CfgGlobals::current()->fun()->scope()->num_stack_slots(); | |
| 72 if (count > 0) { | |
| 73 __ Set(eax, Immediate(Factory::undefined_value())); | |
| 74 for (int i = 0; i < count; i++) { | |
| 75 __ push(eax); | |
| 76 } | |
| 77 } | |
| 78 if (FLAG_trace) { | |
| 79 __ CallRuntime(Runtime::kTraceEnter, 0); | |
| 80 } | |
| 81 if (FLAG_check_stack) { | |
| 82 ExternalReference stack_limit = | |
| 83 ExternalReference::address_of_stack_guard_limit(); | |
| 84 __ cmp(esp, Operand::StaticVariable(stack_limit)); | |
| 85 __ j(below, &deferred_enter); | |
| 86 __ bind(&deferred_exit); | |
| 87 } | |
| 88 } | |
| 89 successor_->Compile(masm); | |
| 90 if (FLAG_check_stack) { | |
| 91 Comment cmnt(masm, "[ Deferred Stack Check"); | |
| 92 __ bind(&deferred_enter); | |
| 93 StackCheckStub stub; | |
| 94 __ CallStub(&stub); | |
| 95 __ jmp(&deferred_exit); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 | |
| 100 void ExitNode::Compile(MacroAssembler* masm) { | |
| 101 ASSERT(!is_marked()); | |
| 102 is_marked_ = true; | |
| 103 Comment cmnt(masm, "[ ExitNode"); | |
| 104 if (FLAG_trace) { | |
| 105 __ push(eax); | |
| 106 __ CallRuntime(Runtime::kTraceExit, 1); | |
| 107 } | |
| 108 __ RecordJSReturn(); | |
| 109 __ mov(esp, ebp); | |
| 110 __ pop(ebp); | |
| 111 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); | |
| 112 __ ret((count + 1) * kPointerSize); | |
| 113 } | |
| 114 | |
| 115 | |
| 116 void PropLoadInstr::Compile(MacroAssembler* masm) { | |
| 117 // The key should not be on the stack---if it is a compiler-generated | |
| 118 // temporary it is in the accumulator. | |
| 119 ASSERT(!key()->is_on_stack()); | |
| 120 | |
| 121 Comment cmnt(masm, "[ Load from Property"); | |
| 122 // If the key is known at compile-time we may be able to use a load IC. | |
| 123 bool is_keyed_load = true; | |
| 124 if (key()->is_constant()) { | |
| 125 // Still use the keyed load IC if the key can be parsed as an integer so | |
| 126 // we will get into the case that handles [] on string objects. | |
| 127 Handle<Object> key_val = Constant::cast(key())->handle(); | |
| 128 uint32_t ignored; | |
| 129 if (key_val->IsSymbol() && | |
| 130 !String::cast(*key_val)->AsArrayIndex(&ignored)) { | |
| 131 is_keyed_load = false; | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 if (!object()->is_on_stack()) object()->Push(masm); | |
| 136 // A test eax instruction after the call indicates to the IC code that it | |
| 137 // was inlined. Ensure there is not one here. | |
| 138 if (is_keyed_load) { | |
| 139 key()->Push(masm); | |
| 140 Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); | |
| 141 __ call(ic, RelocInfo::CODE_TARGET); | |
| 142 __ pop(ebx); // Discard key. | |
| 143 } else { | |
| 144 key()->Get(masm, ecx); | |
| 145 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); | |
| 146 __ call(ic, RelocInfo::CODE_TARGET); | |
| 147 } | |
| 148 __ pop(ebx); // Discard receiver. | |
| 149 location()->Set(masm, eax); | |
| 150 } | |
| 151 | |
| 152 | |
| 153 void BinaryOpInstr::Compile(MacroAssembler* masm) { | |
| 154 // The right-hand value should not be on the stack---if it is a | |
| 155 // compiler-generated temporary it is in the accumulator. | |
| 156 ASSERT(!right()->is_on_stack()); | |
| 157 | |
| 158 Comment cmnt(masm, "[ BinaryOpInstr"); | |
| 159 // We can overwrite one of the operands if it is a temporary. | |
| 160 OverwriteMode mode = NO_OVERWRITE; | |
| 161 if (left()->is_temporary()) { | |
| 162 mode = OVERWRITE_LEFT; | |
| 163 } else if (right()->is_temporary()) { | |
| 164 mode = OVERWRITE_RIGHT; | |
| 165 } | |
| 166 | |
| 167 // Push both operands and call the specialized stub. | |
| 168 if (!left()->is_on_stack()) left()->Push(masm); | |
| 169 right()->Push(masm); | |
| 170 GenericBinaryOpStub stub(op(), mode, SMI_CODE_IN_STUB); | |
| 171 __ CallStub(&stub); | |
| 172 location()->Set(masm, eax); | |
| 173 } | |
| 174 | |
| 175 | |
| 176 void ReturnInstr::Compile(MacroAssembler* masm) { | |
| 177 // The location should be 'Effect'. As a side effect, move the value to | |
| 178 // the accumulator. | |
| 179 Comment cmnt(masm, "[ ReturnInstr"); | |
| 180 value_->Get(masm, eax); | |
| 181 } | |
| 182 | |
| 183 | |
| 184 void Constant::Get(MacroAssembler* masm, Register reg) { | |
| 185 __ mov(reg, Immediate(handle_)); | |
| 186 } | |
| 187 | |
| 188 | |
| 189 void Constant::Push(MacroAssembler* masm) { | |
| 190 __ push(Immediate(handle_)); | |
| 191 } | |
| 192 | |
| 193 | |
| 194 static Operand ToOperand(SlotLocation* loc) { | |
| 195 switch (loc->type()) { | |
| 196 case Slot::PARAMETER: { | |
| 197 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); | |
| 198 return Operand(ebp, (1 + count - loc->index()) * kPointerSize); | |
| 199 } | |
| 200 case Slot::LOCAL: { | |
| 201 const int kOffset = JavaScriptFrameConstants::kLocal0Offset; | |
| 202 return Operand(ebp, kOffset - loc->index() * kPointerSize); | |
| 203 } | |
| 204 default: | |
| 205 UNREACHABLE(); | |
| 206 return Operand(eax); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 | |
| 211 void Constant::MoveToSlot(MacroAssembler* masm, SlotLocation* loc) { | |
| 212 __ mov(ToOperand(loc), Immediate(handle_)); | |
| 213 } | |
| 214 | |
| 215 | |
| 216 void SlotLocation::Get(MacroAssembler* masm, Register reg) { | |
| 217 __ mov(reg, ToOperand(this)); | |
| 218 } | |
| 219 | |
| 220 | |
| 221 void SlotLocation::Set(MacroAssembler* masm, Register reg) { | |
| 222 __ mov(ToOperand(this), reg); | |
| 223 } | |
| 224 | |
| 225 | |
| 226 void SlotLocation::Push(MacroAssembler* masm) { | |
| 227 __ push(ToOperand(this)); | |
| 228 } | |
| 229 | |
| 230 | |
| 231 void SlotLocation::Move(MacroAssembler* masm, Value* value) { | |
| 232 // We dispatch to the value because in some cases (temp or constant) | |
| 233 // we can use a single instruction. | |
| 234 value->MoveToSlot(masm, this); | |
| 235 } | |
| 236 | |
| 237 | |
| 238 void SlotLocation::MoveToSlot(MacroAssembler* masm, SlotLocation* loc) { | |
| 239 // The accumulator is not live across a MoveInstr. | |
| 240 __ mov(eax, ToOperand(this)); | |
| 241 __ mov(ToOperand(loc), eax); | |
| 242 } | |
| 243 | |
| 244 | |
| 245 void TempLocation::Get(MacroAssembler* masm, Register reg) { | |
| 246 switch (where_) { | |
| 247 case ACCUMULATOR: | |
| 248 if (!reg.is(eax)) __ mov(reg, eax); | |
| 249 break; | |
| 250 case STACK: | |
| 251 __ pop(reg); | |
| 252 break; | |
| 253 case NOT_ALLOCATED: | |
| 254 UNREACHABLE(); | |
| 255 } | |
| 256 } | |
| 257 | |
| 258 | |
| 259 void TempLocation::Set(MacroAssembler* masm, Register reg) { | |
| 260 switch (where_) { | |
| 261 case ACCUMULATOR: | |
| 262 if (!reg.is(eax)) __ mov(eax, reg); | |
| 263 break; | |
| 264 case STACK: | |
| 265 __ push(reg); | |
| 266 break; | |
| 267 case NOT_ALLOCATED: | |
| 268 UNREACHABLE(); | |
| 269 } | |
| 270 } | |
| 271 | |
| 272 | |
| 273 void TempLocation::Push(MacroAssembler* masm) { | |
| 274 switch (where_) { | |
| 275 case ACCUMULATOR: | |
| 276 __ push(eax); | |
| 277 break; | |
| 278 case STACK: | |
| 279 case NOT_ALLOCATED: | |
| 280 UNREACHABLE(); | |
| 281 } | |
| 282 } | |
| 283 | |
| 284 | |
| 285 void TempLocation::Move(MacroAssembler* masm, Value* value) { | |
| 286 switch (where_) { | |
| 287 case ACCUMULATOR: | |
| 288 value->Get(masm, eax); | |
| 289 break; | |
| 290 case STACK: | |
| 291 value->Push(masm); | |
| 292 break; | |
| 293 case NOT_ALLOCATED: | |
| 294 UNREACHABLE(); | |
| 295 } | |
| 296 } | |
| 297 | |
| 298 | |
| 299 void TempLocation::MoveToSlot(MacroAssembler* masm, SlotLocation* loc) { | |
| 300 switch (where_) { | |
| 301 case ACCUMULATOR: | |
| 302 __ mov(ToOperand(loc), eax); | |
| 303 break; | |
| 304 case STACK: | |
| 305 __ pop(ToOperand(loc)); | |
| 306 break; | |
| 307 case NOT_ALLOCATED: | |
| 308 UNREACHABLE(); | |
| 309 } | |
| 310 } | |
| 311 | |
| 312 | |
| 313 #undef __ | |
| 314 | |
| 315 } } // namespace v8::internal | |
| OLD | NEW |