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-x64.h" |
32 #include "debug.h" | 33 #include "debug.h" |
33 #include "macro-assembler-x64.h" | 34 #include "macro-assembler-x64.h" |
34 | 35 |
35 namespace v8 { | 36 namespace v8 { |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
38 #define __ ACCESS_MASM(masm) | 39 #define __ ACCESS_MASM(masm) |
39 | 40 |
40 void InstructionBlock::Compile(MacroAssembler* masm) { | 41 void InstructionBlock::Compile(MacroAssembler* masm) { |
41 ASSERT(!is_marked()); | 42 ASSERT(!is_marked()); |
42 is_marked_ = true; | 43 is_marked_ = true; |
43 { | 44 { |
44 Comment cmt(masm, "[ InstructionBlock"); | 45 Comment cmt(masm, "[ InstructionBlock"); |
45 for (int i = 0, len = instructions_.length(); i < len; i++) { | 46 for (int i = 0, len = instructions_.length(); i < len; i++) { |
| 47 // If the location of the current instruction is a temp, then the |
| 48 // instruction cannot be in tail position in the block. Allocate the |
| 49 // temp based on peeking ahead to the next instruction. |
| 50 Instruction* instr = instructions_[i]; |
| 51 Location* loc = instr->location(); |
| 52 if (loc->is_temporary()) { |
| 53 instructions_[i+1]->FastAllocate(TempLocation::cast(loc)); |
| 54 } |
46 instructions_[i]->Compile(masm); | 55 instructions_[i]->Compile(masm); |
47 } | 56 } |
48 } | 57 } |
49 successor_->Compile(masm); | 58 successor_->Compile(masm); |
50 } | 59 } |
51 | 60 |
52 | 61 |
53 void EntryNode::Compile(MacroAssembler* masm) { | 62 void EntryNode::Compile(MacroAssembler* masm) { |
54 ASSERT(!is_marked()); | 63 ASSERT(!is_marked()); |
55 is_marked_ = true; | 64 is_marked_ = true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 __ ret((count + 1) * kPointerSize); | 115 __ ret((count + 1) * kPointerSize); |
107 // Add padding that will be overwritten by a debugger breakpoint. | 116 // Add padding that will be overwritten by a debugger breakpoint. |
108 // "movq rsp, rbp; pop rbp" has length 5. "ret k" has length 2. | 117 // "movq rsp, rbp; pop rbp" has length 5. "ret k" has length 2. |
109 const int kPadding = Debug::kX64JSReturnSequenceLength - 5 - 2; | 118 const int kPadding = Debug::kX64JSReturnSequenceLength - 5 - 2; |
110 for (int i = 0; i < kPadding; ++i) { | 119 for (int i = 0; i < kPadding; ++i) { |
111 __ int3(); | 120 __ int3(); |
112 } | 121 } |
113 } | 122 } |
114 | 123 |
115 | 124 |
| 125 void BinaryOpInstr::Compile(MacroAssembler* masm) { |
| 126 // The right value should not be on the stack---if it is a |
| 127 // compiler-generated temporary it is in the accumulator. |
| 128 ASSERT(!val1_->is_on_stack()); |
| 129 |
| 130 // We can overwrite one of the operands if it is a temporary. |
| 131 OverwriteMode mode = NO_OVERWRITE; |
| 132 if (val0_->is_temporary()) { |
| 133 mode = OVERWRITE_LEFT; |
| 134 } else if (val1_->is_temporary()) { |
| 135 mode = OVERWRITE_RIGHT; |
| 136 } |
| 137 |
| 138 // Push both operands and call the specialized stub. |
| 139 if (!val0_->is_on_stack()) { |
| 140 val0_->Push(masm); |
| 141 } |
| 142 val1_->Push(masm); |
| 143 GenericBinaryOpStub stub(op_, mode, SMI_CODE_IN_STUB); |
| 144 __ CallStub(&stub); |
| 145 loc_->Set(masm, rax); |
| 146 } |
| 147 |
| 148 |
116 void ReturnInstr::Compile(MacroAssembler* masm) { | 149 void ReturnInstr::Compile(MacroAssembler* masm) { |
| 150 // The location should be 'Effect'. As a side effect, move the value to |
| 151 // the accumulator. |
117 Comment cmnt(masm, "[ ReturnInstr"); | 152 Comment cmnt(masm, "[ ReturnInstr"); |
118 value_->ToRegister(masm, rax); | 153 value_->Get(masm, rax); |
119 } | 154 } |
120 | 155 |
121 | 156 |
122 void Constant::ToRegister(MacroAssembler* masm, Register reg) { | 157 void Constant::Get(MacroAssembler* masm, Register reg) { |
123 __ Move(reg, handle_); | 158 __ Move(reg, handle_); |
124 } | 159 } |
125 | 160 |
126 | 161 |
127 void SlotLocation::ToRegister(MacroAssembler* masm, Register reg) { | 162 void Constant::Push(MacroAssembler* masm) { |
128 switch (type_) { | 163 __ Push(handle_); |
| 164 } |
| 165 |
| 166 |
| 167 static Operand ToOperand(SlotLocation* loc) { |
| 168 switch (loc->type()) { |
129 case Slot::PARAMETER: { | 169 case Slot::PARAMETER: { |
130 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); | 170 int count = CfgGlobals::current()->fun()->scope()->num_parameters(); |
131 __ movq(reg, Operand(rbp, (1 + count - index_) * kPointerSize)); | 171 return Operand(rbp, (1 + count - loc->index()) * kPointerSize); |
132 break; | |
133 } | 172 } |
134 case Slot::LOCAL: { | 173 case Slot::LOCAL: { |
135 const int kOffset = JavaScriptFrameConstants::kLocal0Offset; | 174 const int kOffset = JavaScriptFrameConstants::kLocal0Offset; |
136 __ movq(reg, Operand(rbp, kOffset - index_ * kPointerSize)); | 175 return Operand(rbp, kOffset - loc->index() * kPointerSize); |
137 break; | |
138 } | 176 } |
139 default: | 177 default: |
140 UNREACHABLE(); | 178 UNREACHABLE(); |
| 179 return Operand(rax, 0); |
141 } | 180 } |
142 } | 181 } |
143 | 182 |
| 183 |
| 184 void SlotLocation::Get(MacroAssembler* masm, Register reg) { |
| 185 __ movq(reg, ToOperand(this)); |
| 186 } |
| 187 |
| 188 |
| 189 void SlotLocation::Set(MacroAssembler* masm, Register reg) { |
| 190 __ movq(ToOperand(this), reg); |
| 191 } |
| 192 |
| 193 |
| 194 void SlotLocation::Push(MacroAssembler* masm) { |
| 195 __ push(ToOperand(this)); |
| 196 } |
| 197 |
| 198 |
| 199 void TempLocation::Get(MacroAssembler* masm, Register reg) { |
| 200 switch (where_) { |
| 201 case ACCUMULATOR: |
| 202 if (!reg.is(rax)) __ movq(reg, rax); |
| 203 break; |
| 204 case STACK: |
| 205 __ pop(reg); |
| 206 break; |
| 207 case NOWHERE: |
| 208 UNREACHABLE(); |
| 209 break; |
| 210 } |
| 211 } |
| 212 |
| 213 |
| 214 void TempLocation::Set(MacroAssembler* masm, Register reg) { |
| 215 switch (where_) { |
| 216 case ACCUMULATOR: |
| 217 if (!reg.is(rax)) __ movq(rax, reg); |
| 218 break; |
| 219 case STACK: |
| 220 __ push(reg); |
| 221 break; |
| 222 case NOWHERE: |
| 223 UNREACHABLE(); |
| 224 break; |
| 225 } |
| 226 } |
| 227 |
| 228 |
| 229 void TempLocation::Push(MacroAssembler* masm) { |
| 230 switch (where_) { |
| 231 case ACCUMULATOR: |
| 232 __ push(rax); |
| 233 break; |
| 234 case STACK: |
| 235 case NOWHERE: |
| 236 UNREACHABLE(); |
| 237 break; |
| 238 } |
| 239 } |
| 240 |
| 241 |
144 #undef __ | 242 #undef __ |
145 | 243 |
146 } } // namespace v8::internal | 244 } } // namespace v8::internal |
OLD | NEW |