| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "cfg.h" | 30 #include "cfg.h" |
| 31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
| 32 #include "codegen-ia32.h" |
| 32 #include "macro-assembler-ia32.h" | 33 #include "macro-assembler-ia32.h" |
| 33 | 34 |
| 34 namespace v8 { | 35 namespace v8 { |
| 35 namespace internal { | 36 namespace internal { |
| 36 | 37 |
| 37 #define __ ACCESS_MASM(masm) | 38 #define __ ACCESS_MASM(masm) |
| 38 | 39 |
| 39 void InstructionBlock::Compile(MacroAssembler* masm) { | 40 void InstructionBlock::Compile(MacroAssembler* masm) { |
| 40 ASSERT(!is_marked()); | 41 ASSERT(!is_marked()); |
| 41 is_marked_ = true; | 42 is_marked_ = true; |
| 42 { | 43 { |
| 43 Comment cmt(masm, "[ InstructionBlock"); | 44 Comment cmt(masm, "[ InstructionBlock"); |
| 44 for (int i = 0, len = instructions_.length(); i < len; i++) { | 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 } |
| 45 instructions_[i]->Compile(masm); | 54 instructions_[i]->Compile(masm); |
| 46 } | 55 } |
| 47 } | 56 } |
| 48 successor_->Compile(masm); | 57 successor_->Compile(masm); |
| 49 } | 58 } |
| 50 | 59 |
| 51 | 60 |
| 52 void EntryNode::Compile(MacroAssembler* masm) { | 61 void EntryNode::Compile(MacroAssembler* masm) { |
| 53 ASSERT(!is_marked()); | 62 ASSERT(!is_marked()); |
| 54 is_marked_ = true; | 63 is_marked_ = true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 __ CallRuntime(Runtime::kTraceExit, 1); | 105 __ CallRuntime(Runtime::kTraceExit, 1); |
| 97 } | 106 } |
| 98 __ RecordJSReturn(); | 107 __ RecordJSReturn(); |
| 99 __ mov(esp, ebp); | 108 __ mov(esp, ebp); |
| 100 __ pop(ebp); | 109 __ pop(ebp); |
| 101 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); | 110 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); |
| 102 __ ret((count + 1) * kPointerSize); | 111 __ ret((count + 1) * kPointerSize); |
| 103 } | 112 } |
| 104 | 113 |
| 105 | 114 |
| 115 void BinaryOpInstr::Compile(MacroAssembler* masm) { |
| 116 // The right value should not be on the stack---if it is a |
| 117 // compiler-generated temporary it is in the accumulator. |
| 118 ASSERT(!val1_->is_on_stack()); |
| 119 |
| 120 // We can overwrite one of the operands if it is a temporary. |
| 121 OverwriteMode mode = NO_OVERWRITE; |
| 122 if (val0_->is_temporary()) { |
| 123 mode = OVERWRITE_LEFT; |
| 124 } else if (val1_->is_temporary()) { |
| 125 mode = OVERWRITE_RIGHT; |
| 126 } |
| 127 |
| 128 // Push both operands and call the specialized stub. |
| 129 if (!val0_->is_on_stack()) { |
| 130 val0_->Push(masm); |
| 131 } |
| 132 val1_->Push(masm); |
| 133 GenericBinaryOpStub stub(op_, mode, SMI_CODE_IN_STUB); |
| 134 __ CallStub(&stub); |
| 135 loc_->Set(masm, eax); |
| 136 } |
| 137 |
| 138 |
| 106 void ReturnInstr::Compile(MacroAssembler* masm) { | 139 void ReturnInstr::Compile(MacroAssembler* masm) { |
| 140 // The location should be 'Effect'. As a side effect, move the value to |
| 141 // the accumulator. |
| 107 Comment cmnt(masm, "[ ReturnInstr"); | 142 Comment cmnt(masm, "[ ReturnInstr"); |
| 108 value_->ToRegister(masm, eax); | 143 value_->Get(masm, eax); |
| 109 } | 144 } |
| 110 | 145 |
| 111 | 146 |
| 112 void Constant::ToRegister(MacroAssembler* masm, Register reg) { | 147 void Constant::Get(MacroAssembler* masm, Register reg) { |
| 113 __ mov(reg, Immediate(handle_)); | 148 __ mov(reg, Immediate(handle_)); |
| 114 } | 149 } |
| 115 | 150 |
| 116 | 151 |
| 117 void SlotLocation::ToRegister(MacroAssembler* masm, Register reg) { | 152 void Constant::Push(MacroAssembler* masm) { |
| 118 switch (type_) { | 153 __ push(Immediate(handle_)); |
| 154 } |
| 155 |
| 156 |
| 157 static Operand ToOperand(SlotLocation* loc) { |
| 158 switch (loc->type()) { |
| 119 case Slot::PARAMETER: { | 159 case Slot::PARAMETER: { |
| 120 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); | 160 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); |
| 121 __ mov(reg, Operand(ebp, (1 + count - index_) * kPointerSize)); | 161 return Operand(ebp, (1 + count - loc->index()) * kPointerSize); |
| 122 break; | |
| 123 } | 162 } |
| 124 case Slot::LOCAL: { | 163 case Slot::LOCAL: { |
| 125 const int kOffset = JavaScriptFrameConstants::kLocal0Offset; | 164 const int kOffset = JavaScriptFrameConstants::kLocal0Offset; |
| 126 __ mov(reg, Operand(ebp, kOffset - index_ * kPointerSize)); | 165 return Operand(ebp, kOffset - loc->index() * kPointerSize); |
| 127 break; | |
| 128 } | 166 } |
| 129 default: | 167 default: |
| 130 UNREACHABLE(); | 168 UNREACHABLE(); |
| 169 return Operand(eax); |
| 170 } |
| 171 } |
| 172 |
| 173 |
| 174 void SlotLocation::Get(MacroAssembler* masm, Register reg) { |
| 175 __ mov(reg, ToOperand(this)); |
| 176 } |
| 177 |
| 178 |
| 179 void SlotLocation::Set(MacroAssembler* masm, Register reg) { |
| 180 __ mov(ToOperand(this), reg); |
| 181 } |
| 182 |
| 183 |
| 184 void SlotLocation::Push(MacroAssembler* masm) { |
| 185 __ push(ToOperand(this)); |
| 186 } |
| 187 |
| 188 |
| 189 void TempLocation::Get(MacroAssembler* masm, Register reg) { |
| 190 switch (where_) { |
| 191 case ACCUMULATOR: |
| 192 if (!reg.is(eax)) __ mov(reg, eax); |
| 193 break; |
| 194 case STACK: |
| 195 __ pop(reg); |
| 196 break; |
| 197 case NOWHERE: |
| 198 UNREACHABLE(); |
| 199 break; |
| 200 } |
| 201 } |
| 202 |
| 203 |
| 204 void TempLocation::Set(MacroAssembler* masm, Register reg) { |
| 205 switch (where_) { |
| 206 case ACCUMULATOR: |
| 207 if (!reg.is(eax)) __ mov(eax, reg); |
| 208 break; |
| 209 case STACK: |
| 210 __ push(reg); |
| 211 break; |
| 212 case NOWHERE: |
| 213 UNREACHABLE(); |
| 214 break; |
| 215 } |
| 216 } |
| 217 |
| 218 |
| 219 void TempLocation::Push(MacroAssembler* masm) { |
| 220 switch (where_) { |
| 221 case ACCUMULATOR: |
| 222 __ push(eax); |
| 223 break; |
| 224 case STACK: |
| 225 case NOWHERE: |
| 226 UNREACHABLE(); |
| 227 break; |
| 131 } | 228 } |
| 132 } | 229 } |
| 133 | 230 |
| 134 | 231 |
| 135 #undef __ | 232 #undef __ |
| 136 | 233 |
| 137 } } // namespace v8::internal | 234 } } // namespace v8::internal |
| OLD | NEW |