| 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 #ifndef V8_COMPILER_INSTRUCTION_SELECTOR_IMPL_H_ | 5 #ifndef V8_COMPILER_INSTRUCTION_SELECTOR_IMPL_H_ |
| 6 #define V8_COMPILER_INSTRUCTION_SELECTOR_IMPL_H_ | 6 #define V8_COMPILER_INSTRUCTION_SELECTOR_IMPL_H_ |
| 7 | 7 |
| 8 #include "src/compiler/instruction.h" | 8 #include "src/compiler/instruction.h" |
| 9 #include "src/compiler/instruction-selector.h" | 9 #include "src/compiler/instruction-selector.h" |
| 10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 InstructionOperand DefineAsConstant(Node* node) { | 63 InstructionOperand DefineAsConstant(Node* node) { |
| 64 selector()->MarkAsDefined(node); | 64 selector()->MarkAsDefined(node); |
| 65 int virtual_register = GetVReg(node); | 65 int virtual_register = GetVReg(node); |
| 66 sequence()->AddConstant(virtual_register, ToConstant(node)); | 66 sequence()->AddConstant(virtual_register, ToConstant(node)); |
| 67 return ConstantOperand(virtual_register); | 67 return ConstantOperand(virtual_register); |
| 68 } | 68 } |
| 69 | 69 |
| 70 InstructionOperand DefineAsLocation(Node* node, LinkageLocation location, | 70 InstructionOperand DefineAsLocation(Node* node, LinkageLocation location, |
| 71 MachineType type) { | 71 MachineRepresentation rep) { |
| 72 return Define(node, ToUnallocatedOperand(location, type, GetVReg(node))); | 72 return Define(node, ToUnallocatedOperand(location, rep, GetVReg(node))); |
| 73 } | 73 } |
| 74 | 74 |
| 75 InstructionOperand DefineAsDualLocation(Node* node, | 75 InstructionOperand DefineAsDualLocation(Node* node, |
| 76 LinkageLocation primary_location, | 76 LinkageLocation primary_location, |
| 77 LinkageLocation secondary_location) { | 77 LinkageLocation secondary_location) { |
| 78 return Define(node, | 78 return Define(node, |
| 79 ToDualLocationUnallocatedOperand( | 79 ToDualLocationUnallocatedOperand( |
| 80 primary_location, secondary_location, GetVReg(node))); | 80 primary_location, secondary_location, GetVReg(node))); |
| 81 } | 81 } |
| 82 | 82 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 reg.code(), GetVReg(node))); | 122 reg.code(), GetVReg(node))); |
| 123 } | 123 } |
| 124 | 124 |
| 125 InstructionOperand UseFixed(Node* node, DoubleRegister reg) { | 125 InstructionOperand UseFixed(Node* node, DoubleRegister reg) { |
| 126 return Use(node, | 126 return Use(node, |
| 127 UnallocatedOperand(UnallocatedOperand::FIXED_DOUBLE_REGISTER, | 127 UnallocatedOperand(UnallocatedOperand::FIXED_DOUBLE_REGISTER, |
| 128 reg.code(), GetVReg(node))); | 128 reg.code(), GetVReg(node))); |
| 129 } | 129 } |
| 130 | 130 |
| 131 InstructionOperand UseExplicit(LinkageLocation location) { | 131 InstructionOperand UseExplicit(LinkageLocation location) { |
| 132 MachineType machine_type = InstructionSequence::DefaultRepresentation(); | 132 MachineRepresentation rep = InstructionSequence::DefaultRepresentation(); |
| 133 if (location.IsRegister()) { | 133 if (location.IsRegister()) { |
| 134 return ExplicitOperand(LocationOperand::REGISTER, machine_type, | 134 return ExplicitOperand(LocationOperand::REGISTER, rep, |
| 135 location.AsRegister()); | 135 location.AsRegister()); |
| 136 } else { | 136 } else { |
| 137 return ExplicitOperand(LocationOperand::STACK_SLOT, machine_type, | 137 return ExplicitOperand(LocationOperand::STACK_SLOT, rep, |
| 138 location.GetLocation()); | 138 location.GetLocation()); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 InstructionOperand UseImmediate(Node* node) { | 142 InstructionOperand UseImmediate(Node* node) { |
| 143 return sequence()->AddImmediate(ToConstant(node)); | 143 return sequence()->AddImmediate(ToConstant(node)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 InstructionOperand UseLocation(Node* node, LinkageLocation location, | 146 InstructionOperand UseLocation(Node* node, LinkageLocation location, |
| 147 MachineType type) { | 147 MachineRepresentation rep) { |
| 148 return Use(node, ToUnallocatedOperand(location, type, GetVReg(node))); | 148 return Use(node, ToUnallocatedOperand(location, rep, GetVReg(node))); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Used to force gap moves from the from_location to the to_location | 151 // Used to force gap moves from the from_location to the to_location |
| 152 // immediately before an instruction. | 152 // immediately before an instruction. |
| 153 InstructionOperand UsePointerLocation(LinkageLocation to_location, | 153 InstructionOperand UsePointerLocation(LinkageLocation to_location, |
| 154 LinkageLocation from_location) { | 154 LinkageLocation from_location) { |
| 155 MachineType type = static_cast<MachineType>(kTypeAny | kMachPtr); | 155 MachineRepresentation rep = MachineType::PointerRepresentation(); |
| 156 UnallocatedOperand casted_from_operand = | 156 UnallocatedOperand casted_from_operand = |
| 157 UnallocatedOperand::cast(TempLocation(from_location, type)); | 157 UnallocatedOperand::cast(TempLocation(from_location, rep)); |
| 158 selector_->Emit(kArchNop, casted_from_operand); | 158 selector_->Emit(kArchNop, casted_from_operand); |
| 159 return ToUnallocatedOperand(to_location, type, | 159 return ToUnallocatedOperand(to_location, rep, |
| 160 casted_from_operand.virtual_register()); | 160 casted_from_operand.virtual_register()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 InstructionOperand TempRegister() { | 163 InstructionOperand TempRegister() { |
| 164 return UnallocatedOperand(UnallocatedOperand::MUST_HAVE_REGISTER, | 164 return UnallocatedOperand(UnallocatedOperand::MUST_HAVE_REGISTER, |
| 165 UnallocatedOperand::USED_AT_START, | 165 UnallocatedOperand::USED_AT_START, |
| 166 sequence()->NextVirtualRegister()); | 166 sequence()->NextVirtualRegister()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 InstructionOperand TempDoubleRegister() { | 169 InstructionOperand TempDoubleRegister() { |
| 170 UnallocatedOperand op = UnallocatedOperand( | 170 UnallocatedOperand op = UnallocatedOperand( |
| 171 UnallocatedOperand::MUST_HAVE_REGISTER, | 171 UnallocatedOperand::MUST_HAVE_REGISTER, |
| 172 UnallocatedOperand::USED_AT_START, sequence()->NextVirtualRegister()); | 172 UnallocatedOperand::USED_AT_START, sequence()->NextVirtualRegister()); |
| 173 sequence()->MarkAsRepresentation(kRepFloat64, op.virtual_register()); | 173 sequence()->MarkAsRepresentation(MachineRepresentation::kFloat64, |
| 174 op.virtual_register()); |
| 174 return op; | 175 return op; |
| 175 } | 176 } |
| 176 | 177 |
| 177 InstructionOperand TempRegister(Register reg) { | 178 InstructionOperand TempRegister(Register reg) { |
| 178 return UnallocatedOperand(UnallocatedOperand::FIXED_REGISTER, reg.code(), | 179 return UnallocatedOperand(UnallocatedOperand::FIXED_REGISTER, reg.code(), |
| 179 InstructionOperand::kInvalidVirtualRegister); | 180 InstructionOperand::kInvalidVirtualRegister); |
| 180 } | 181 } |
| 181 | 182 |
| 182 InstructionOperand TempImmediate(int32_t imm) { | 183 InstructionOperand TempImmediate(int32_t imm) { |
| 183 return sequence()->AddImmediate(Constant(imm)); | 184 return sequence()->AddImmediate(Constant(imm)); |
| 184 } | 185 } |
| 185 | 186 |
| 186 InstructionOperand TempLocation(LinkageLocation location, MachineType type) { | 187 InstructionOperand TempLocation(LinkageLocation location, |
| 187 return ToUnallocatedOperand(location, type, | 188 MachineRepresentation rep) { |
| 189 return ToUnallocatedOperand(location, rep, |
| 188 sequence()->NextVirtualRegister()); | 190 sequence()->NextVirtualRegister()); |
| 189 } | 191 } |
| 190 | 192 |
| 191 InstructionOperand Label(BasicBlock* block) { | 193 InstructionOperand Label(BasicBlock* block) { |
| 192 return sequence()->AddImmediate( | 194 return sequence()->AddImmediate( |
| 193 Constant(RpoNumber::FromInt(block->rpo_number()))); | 195 Constant(RpoNumber::FromInt(block->rpo_number()))); |
| 194 } | 196 } |
| 195 | 197 |
| 196 protected: | 198 protected: |
| 197 InstructionSelector* selector() const { return selector_; } | 199 InstructionSelector* selector() const { return selector_; } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // We only support the primary location being a register and the secondary | 245 // We only support the primary location being a register and the secondary |
| 244 // one a slot. | 246 // one a slot. |
| 245 DCHECK(primary_location.IsRegister() && | 247 DCHECK(primary_location.IsRegister() && |
| 246 secondary_location.IsCalleeFrameSlot()); | 248 secondary_location.IsCalleeFrameSlot()); |
| 247 int reg_id = primary_location.AsRegister(); | 249 int reg_id = primary_location.AsRegister(); |
| 248 int slot_id = secondary_location.AsCalleeFrameSlot(); | 250 int slot_id = secondary_location.AsCalleeFrameSlot(); |
| 249 return UnallocatedOperand(reg_id, slot_id, virtual_register); | 251 return UnallocatedOperand(reg_id, slot_id, virtual_register); |
| 250 } | 252 } |
| 251 | 253 |
| 252 UnallocatedOperand ToUnallocatedOperand(LinkageLocation location, | 254 UnallocatedOperand ToUnallocatedOperand(LinkageLocation location, |
| 253 MachineType type, | 255 MachineRepresentation rep, |
| 254 int virtual_register) { | 256 int virtual_register) { |
| 255 if (location.IsAnyRegister()) { | 257 if (location.IsAnyRegister()) { |
| 256 // any machine register. | 258 // any machine register. |
| 257 return UnallocatedOperand(UnallocatedOperand::MUST_HAVE_REGISTER, | 259 return UnallocatedOperand(UnallocatedOperand::MUST_HAVE_REGISTER, |
| 258 virtual_register); | 260 virtual_register); |
| 259 } | 261 } |
| 260 if (location.IsCallerFrameSlot()) { | 262 if (location.IsCallerFrameSlot()) { |
| 261 // a location on the caller frame. | 263 // a location on the caller frame. |
| 262 return UnallocatedOperand(UnallocatedOperand::FIXED_SLOT, | 264 return UnallocatedOperand(UnallocatedOperand::FIXED_SLOT, |
| 263 location.AsCallerFrameSlot(), virtual_register); | 265 location.AsCallerFrameSlot(), virtual_register); |
| 264 } | 266 } |
| 265 if (location.IsCalleeFrameSlot()) { | 267 if (location.IsCalleeFrameSlot()) { |
| 266 // a spill location on this (callee) frame. | 268 // a spill location on this (callee) frame. |
| 267 return UnallocatedOperand(UnallocatedOperand::FIXED_SLOT, | 269 return UnallocatedOperand(UnallocatedOperand::FIXED_SLOT, |
| 268 location.AsCalleeFrameSlot(), virtual_register); | 270 location.AsCalleeFrameSlot(), virtual_register); |
| 269 } | 271 } |
| 270 // a fixed register. | 272 // a fixed register. |
| 271 MachineType rep = RepresentationOf(type); | 273 if (IsFloatingPoint(rep)) { |
| 272 if (rep == kRepFloat64 || rep == kRepFloat32) { | |
| 273 return UnallocatedOperand(UnallocatedOperand::FIXED_DOUBLE_REGISTER, | 274 return UnallocatedOperand(UnallocatedOperand::FIXED_DOUBLE_REGISTER, |
| 274 location.AsRegister(), virtual_register); | 275 location.AsRegister(), virtual_register); |
| 275 } | 276 } |
| 276 return UnallocatedOperand(UnallocatedOperand::FIXED_REGISTER, | 277 return UnallocatedOperand(UnallocatedOperand::FIXED_REGISTER, |
| 277 location.AsRegister(), virtual_register); | 278 location.AsRegister(), virtual_register); |
| 278 } | 279 } |
| 279 | 280 |
| 280 InstructionSelector* selector_; | 281 InstructionSelector* selector_; |
| 281 }; | 282 }; |
| 282 | 283 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 Node* result_; // Only valid if mode_ == kFlags_set. | 360 Node* result_; // Only valid if mode_ == kFlags_set. |
| 360 BasicBlock* true_block_; // Only valid if mode_ == kFlags_branch. | 361 BasicBlock* true_block_; // Only valid if mode_ == kFlags_branch. |
| 361 BasicBlock* false_block_; // Only valid if mode_ == kFlags_branch. | 362 BasicBlock* false_block_; // Only valid if mode_ == kFlags_branch. |
| 362 }; | 363 }; |
| 363 | 364 |
| 364 } // namespace compiler | 365 } // namespace compiler |
| 365 } // namespace internal | 366 } // namespace internal |
| 366 } // namespace v8 | 367 } // namespace v8 |
| 367 | 368 |
| 368 #endif // V8_COMPILER_INSTRUCTION_SELECTOR_IMPL_H_ | 369 #endif // V8_COMPILER_INSTRUCTION_SELECTOR_IMPL_H_ |
| OLD | NEW |