| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "src/base/adapters.h" | 7 #include "src/base/adapters.h" |
| 8 #include "src/compiler/instruction-selector-impl.h" | 8 #include "src/compiler/instruction-selector-impl.h" |
| 9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 opcode = kX64Movq; | 206 opcode = kX64Movq; |
| 207 break; | 207 break; |
| 208 case MachineRepresentation::kSimd128: // Fall through. | 208 case MachineRepresentation::kSimd128: // Fall through. |
| 209 case MachineRepresentation::kNone: | 209 case MachineRepresentation::kNone: |
| 210 UNREACHABLE(); | 210 UNREACHABLE(); |
| 211 break; | 211 break; |
| 212 } | 212 } |
| 213 return opcode; | 213 return opcode; |
| 214 } | 214 } |
| 215 | 215 |
| 216 ArchOpcode GetStoreOpcode(StoreRepresentation store_rep) { |
| 217 switch (store_rep.representation()) { |
| 218 case MachineRepresentation::kFloat32: |
| 219 return kX64Movss; |
| 220 break; |
| 221 case MachineRepresentation::kFloat64: |
| 222 return kX64Movsd; |
| 223 break; |
| 224 case MachineRepresentation::kBit: // Fall through. |
| 225 case MachineRepresentation::kWord8: |
| 226 return kX64Movb; |
| 227 break; |
| 228 case MachineRepresentation::kWord16: |
| 229 return kX64Movw; |
| 230 break; |
| 231 case MachineRepresentation::kWord32: |
| 232 return kX64Movl; |
| 233 break; |
| 234 case MachineRepresentation::kTaggedSigned: // Fall through. |
| 235 case MachineRepresentation::kTaggedPointer: // Fall through. |
| 236 case MachineRepresentation::kTagged: // Fall through. |
| 237 case MachineRepresentation::kWord64: |
| 238 return kX64Movq; |
| 239 break; |
| 240 case MachineRepresentation::kSimd128: // Fall through. |
| 241 case MachineRepresentation::kNone: |
| 242 UNREACHABLE(); |
| 243 return kArchNop; |
| 244 } |
| 245 UNREACHABLE(); |
| 246 return kArchNop; |
| 247 } |
| 248 |
| 216 } // namespace | 249 } // namespace |
| 217 | 250 |
| 218 void InstructionSelector::VisitLoad(Node* node) { | 251 void InstructionSelector::VisitLoad(Node* node) { |
| 219 LoadRepresentation load_rep = LoadRepresentationOf(node->op()); | 252 LoadRepresentation load_rep = LoadRepresentationOf(node->op()); |
| 220 X64OperandGenerator g(this); | 253 X64OperandGenerator g(this); |
| 221 | 254 |
| 222 ArchOpcode opcode = GetLoadOpcode(load_rep); | 255 ArchOpcode opcode = GetLoadOpcode(load_rep); |
| 223 InstructionOperand outputs[1]; | 256 InstructionOperand outputs[1]; |
| 224 outputs[0] = g.DefineAsRegister(node); | 257 outputs[0] = g.DefineAsRegister(node); |
| 225 InstructionOperand inputs[3]; | 258 InstructionOperand inputs[3]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 238 InstructionOperand outputs[1]; | 271 InstructionOperand outputs[1]; |
| 239 outputs[0] = g.DefineAsRegister(node); | 272 outputs[0] = g.DefineAsRegister(node); |
| 240 InstructionOperand inputs[4]; | 273 InstructionOperand inputs[4]; |
| 241 size_t input_count = 0; | 274 size_t input_count = 0; |
| 242 AddressingMode mode = | 275 AddressingMode mode = |
| 243 g.GetEffectiveAddressMemoryOperand(node, inputs, &input_count); | 276 g.GetEffectiveAddressMemoryOperand(node, inputs, &input_count); |
| 244 // Add the context parameter as an input. | 277 // Add the context parameter as an input. |
| 245 inputs[input_count++] = g.UseUniqueRegister(node->InputAt(2)); | 278 inputs[input_count++] = g.UseUniqueRegister(node->InputAt(2)); |
| 246 // Add the source position as an input | 279 // Add the source position as an input |
| 247 inputs[input_count++] = g.UseImmediate(node->InputAt(3)); | 280 inputs[input_count++] = g.UseImmediate(node->InputAt(3)); |
| 248 InstructionCode code = opcode | AddressingModeField::encode(mode); | 281 InstructionCode code = opcode | AddressingModeField::encode(mode) | |
| 282 MiscField::encode(X64MemoryProtection::kProtected); |
| 249 Emit(code, 1, outputs, input_count, inputs); | 283 Emit(code, 1, outputs, input_count, inputs); |
| 250 } | 284 } |
| 251 | 285 |
| 252 void InstructionSelector::VisitStore(Node* node) { | 286 void InstructionSelector::VisitStore(Node* node) { |
| 253 X64OperandGenerator g(this); | 287 X64OperandGenerator g(this); |
| 254 Node* base = node->InputAt(0); | 288 Node* base = node->InputAt(0); |
| 255 Node* index = node->InputAt(1); | 289 Node* index = node->InputAt(1); |
| 256 Node* value = node->InputAt(2); | 290 Node* value = node->InputAt(2); |
| 257 | 291 |
| 258 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); | 292 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); |
| 259 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind(); | 293 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind(); |
| 260 MachineRepresentation rep = store_rep.representation(); | |
| 261 | 294 |
| 262 if (write_barrier_kind != kNoWriteBarrier) { | 295 if (write_barrier_kind != kNoWriteBarrier) { |
| 263 DCHECK(CanBeTaggedPointer(rep)); | 296 DCHECK(CanBeTaggedPointer(store_rep.representation())); |
| 264 AddressingMode addressing_mode; | 297 AddressingMode addressing_mode; |
| 265 InstructionOperand inputs[3]; | 298 InstructionOperand inputs[3]; |
| 266 size_t input_count = 0; | 299 size_t input_count = 0; |
| 267 inputs[input_count++] = g.UseUniqueRegister(base); | 300 inputs[input_count++] = g.UseUniqueRegister(base); |
| 268 if (g.CanBeImmediate(index)) { | 301 if (g.CanBeImmediate(index)) { |
| 269 inputs[input_count++] = g.UseImmediate(index); | 302 inputs[input_count++] = g.UseImmediate(index); |
| 270 addressing_mode = kMode_MRI; | 303 addressing_mode = kMode_MRI; |
| 271 } else { | 304 } else { |
| 272 inputs[input_count++] = g.UseUniqueRegister(index); | 305 inputs[input_count++] = g.UseUniqueRegister(index); |
| 273 addressing_mode = kMode_MR1; | 306 addressing_mode = kMode_MR1; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 288 record_write_mode = RecordWriteMode::kValueIsAny; | 321 record_write_mode = RecordWriteMode::kValueIsAny; |
| 289 break; | 322 break; |
| 290 } | 323 } |
| 291 InstructionOperand temps[] = {g.TempRegister(), g.TempRegister()}; | 324 InstructionOperand temps[] = {g.TempRegister(), g.TempRegister()}; |
| 292 size_t const temp_count = arraysize(temps); | 325 size_t const temp_count = arraysize(temps); |
| 293 InstructionCode code = kArchStoreWithWriteBarrier; | 326 InstructionCode code = kArchStoreWithWriteBarrier; |
| 294 code |= AddressingModeField::encode(addressing_mode); | 327 code |= AddressingModeField::encode(addressing_mode); |
| 295 code |= MiscField::encode(static_cast<int>(record_write_mode)); | 328 code |= MiscField::encode(static_cast<int>(record_write_mode)); |
| 296 Emit(code, 0, nullptr, input_count, inputs, temp_count, temps); | 329 Emit(code, 0, nullptr, input_count, inputs, temp_count, temps); |
| 297 } else { | 330 } else { |
| 298 ArchOpcode opcode = kArchNop; | 331 ArchOpcode opcode = GetStoreOpcode(store_rep); |
| 299 switch (rep) { | |
| 300 case MachineRepresentation::kFloat32: | |
| 301 opcode = kX64Movss; | |
| 302 break; | |
| 303 case MachineRepresentation::kFloat64: | |
| 304 opcode = kX64Movsd; | |
| 305 break; | |
| 306 case MachineRepresentation::kBit: // Fall through. | |
| 307 case MachineRepresentation::kWord8: | |
| 308 opcode = kX64Movb; | |
| 309 break; | |
| 310 case MachineRepresentation::kWord16: | |
| 311 opcode = kX64Movw; | |
| 312 break; | |
| 313 case MachineRepresentation::kWord32: | |
| 314 opcode = kX64Movl; | |
| 315 break; | |
| 316 case MachineRepresentation::kTaggedSigned: // Fall through. | |
| 317 case MachineRepresentation::kTaggedPointer: // Fall through. | |
| 318 case MachineRepresentation::kTagged: // Fall through. | |
| 319 case MachineRepresentation::kWord64: | |
| 320 opcode = kX64Movq; | |
| 321 break; | |
| 322 case MachineRepresentation::kSimd128: // Fall through. | |
| 323 case MachineRepresentation::kNone: | |
| 324 UNREACHABLE(); | |
| 325 return; | |
| 326 } | |
| 327 InstructionOperand inputs[4]; | 332 InstructionOperand inputs[4]; |
| 328 size_t input_count = 0; | 333 size_t input_count = 0; |
| 329 AddressingMode addressing_mode = | 334 AddressingMode addressing_mode = |
| 330 g.GetEffectiveAddressMemoryOperand(node, inputs, &input_count); | 335 g.GetEffectiveAddressMemoryOperand(node, inputs, &input_count); |
| 331 InstructionCode code = | 336 InstructionCode code = |
| 332 opcode | AddressingModeField::encode(addressing_mode); | 337 opcode | AddressingModeField::encode(addressing_mode); |
| 333 InstructionOperand value_operand = | 338 InstructionOperand value_operand = |
| 334 g.CanBeImmediate(value) ? g.UseImmediate(value) : g.UseRegister(value); | 339 g.CanBeImmediate(value) ? g.UseImmediate(value) : g.UseRegister(value); |
| 335 inputs[input_count++] = value_operand; | 340 inputs[input_count++] = value_operand; |
| 336 Emit(code, 0, static_cast<InstructionOperand*>(nullptr), input_count, | 341 Emit(code, 0, static_cast<InstructionOperand*>(nullptr), input_count, |
| 337 inputs); | 342 inputs); |
| 338 } | 343 } |
| 339 } | 344 } |
| 340 | 345 |
| 346 void InstructionSelector::VisitProtectedStore(Node* node) { |
| 347 X64OperandGenerator g(this); |
| 348 Node* value = node->InputAt(2); |
| 349 Node* context = node->InputAt(3); |
| 350 Node* position = node->InputAt(4); |
| 351 |
| 352 StoreRepresentation store_rep = StoreRepresentationOf(node->op()); |
| 353 |
| 354 ArchOpcode opcode = GetStoreOpcode(store_rep); |
| 355 InstructionOperand inputs[6]; |
| 356 size_t input_count = 0; |
| 357 AddressingMode addressing_mode = |
| 358 g.GetEffectiveAddressMemoryOperand(node, inputs, &input_count); |
| 359 InstructionCode code = opcode | AddressingModeField::encode(addressing_mode) | |
| 360 MiscField::encode(X64MemoryProtection::kProtected); |
| 361 InstructionOperand value_operand = |
| 362 g.CanBeImmediate(value) ? g.UseImmediate(value) : g.UseRegister(value); |
| 363 inputs[input_count++] = value_operand; |
| 364 inputs[input_count++] = g.UseRegister(context); |
| 365 inputs[input_count++] = g.UseImmediate(position); |
| 366 Emit(code, 0, static_cast<InstructionOperand*>(nullptr), input_count, inputs); |
| 367 } |
| 368 |
| 341 // Architecture supports unaligned access, therefore VisitLoad is used instead | 369 // Architecture supports unaligned access, therefore VisitLoad is used instead |
| 342 void InstructionSelector::VisitUnalignedLoad(Node* node) { UNREACHABLE(); } | 370 void InstructionSelector::VisitUnalignedLoad(Node* node) { UNREACHABLE(); } |
| 343 | 371 |
| 344 // Architecture supports unaligned access, therefore VisitStore is used instead | 372 // Architecture supports unaligned access, therefore VisitStore is used instead |
| 345 void InstructionSelector::VisitUnalignedStore(Node* node) { UNREACHABLE(); } | 373 void InstructionSelector::VisitUnalignedStore(Node* node) { UNREACHABLE(); } |
| 346 | 374 |
| 347 void InstructionSelector::VisitCheckedLoad(Node* node) { | 375 void InstructionSelector::VisitCheckedLoad(Node* node) { |
| 348 CheckedLoadRepresentation load_rep = CheckedLoadRepresentationOf(node->op()); | 376 CheckedLoadRepresentation load_rep = CheckedLoadRepresentationOf(node->op()); |
| 349 X64OperandGenerator g(this); | 377 X64OperandGenerator g(this); |
| 350 Node* const buffer = node->InputAt(0); | 378 Node* const buffer = node->InputAt(0); |
| (...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 // static | 2408 // static |
| 2381 MachineOperatorBuilder::AlignmentRequirements | 2409 MachineOperatorBuilder::AlignmentRequirements |
| 2382 InstructionSelector::AlignmentRequirements() { | 2410 InstructionSelector::AlignmentRequirements() { |
| 2383 return MachineOperatorBuilder::AlignmentRequirements:: | 2411 return MachineOperatorBuilder::AlignmentRequirements:: |
| 2384 FullUnalignedAccessSupport(); | 2412 FullUnalignedAccessSupport(); |
| 2385 } | 2413 } |
| 2386 | 2414 |
| 2387 } // namespace compiler | 2415 } // namespace compiler |
| 2388 } // namespace internal | 2416 } // namespace internal |
| 2389 } // namespace v8 | 2417 } // namespace v8 |
| OLD | NEW |