Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/instruction-selector.h" |
| 6 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | #include <limits> |
| 8 | |
| 9 | #include "src/base/adapters.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/compiler/instruction-selector-impl.h" |
| 11 | #include "src/compiler/node-matchers.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 12 | #include "src/compiler/pipeline.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/compiler/schedule.h" |
| 14 | #include "src/compiler/state-values-utils.h" |
| 15 | #include "src/deoptimizer.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 16 | |
| 17 | namespace v8 { |
| 18 | namespace internal { |
| 19 | namespace compiler { |
| 20 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 21 | InstructionSelector::InstructionSelector( |
| 22 | Zone* zone, size_t node_count, Linkage* linkage, |
| 23 | InstructionSequence* sequence, Schedule* schedule, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 24 | SourcePositionTable* source_positions, Frame* frame, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 25 | SourcePositionMode source_position_mode, Features features) |
| 26 | : zone_(zone), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 27 | linkage_(linkage), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | sequence_(sequence), |
| 29 | source_positions_(source_positions), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | source_position_mode_(source_position_mode), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | features_(features), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 32 | schedule_(schedule), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | current_block_(nullptr), |
| 34 | instructions_(zone), |
| 35 | defined_(node_count, false, zone), |
| 36 | used_(node_count, false, zone), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 37 | effect_level_(node_count, 0, zone), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 38 | virtual_registers_(node_count, |
| 39 | InstructionOperand::kInvalidVirtualRegister, zone), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 40 | scheduler_(nullptr), |
| 41 | frame_(frame) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 42 | instructions_.reserve(node_count); |
| 43 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | void InstructionSelector::SelectInstructions() { |
| 47 | // Mark the inputs of all phis in loop headers as used. |
| 48 | BasicBlockVector* blocks = schedule()->rpo_order(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | for (auto const block : *blocks) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | if (!block->IsLoopHeader()) continue; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 51 | DCHECK_LE(2u, block->PredecessorCount()); |
| 52 | for (Node* const phi : *block) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | if (phi->opcode() != IrOpcode::kPhi) continue; |
| 54 | |
| 55 | // Mark all inputs as used. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | for (Node* const input : phi->inputs()) { |
| 57 | MarkAsUsed(input); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Visit each basic block in post order. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 63 | for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | VisitBlock(*i); |
| 65 | } |
| 66 | |
| 67 | // Schedule the selected instructions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | if (FLAG_turbo_instruction_scheduling && |
| 69 | InstructionScheduler::SchedulerSupported()) { |
| 70 | scheduler_ = new (zone()) InstructionScheduler(zone(), sequence()); |
| 71 | } |
| 72 | |
| 73 | for (auto const block : *blocks) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 74 | InstructionBlock* instruction_block = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 75 | sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 76 | size_t end = instruction_block->code_end(); |
| 77 | size_t start = instruction_block->code_start(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 78 | DCHECK_LE(end, start); |
| 79 | StartBlock(RpoNumber::FromInt(block->rpo_number())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 80 | while (start-- > end) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | AddInstruction(instructions_[start]); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 82 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 83 | EndBlock(RpoNumber::FromInt(block->rpo_number())); |
| 84 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 85 | #if DEBUG |
| 86 | sequence()->ValidateSSA(); |
| 87 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
| 91 | void InstructionSelector::StartBlock(RpoNumber rpo) { |
| 92 | if (FLAG_turbo_instruction_scheduling && |
| 93 | InstructionScheduler::SchedulerSupported()) { |
| 94 | DCHECK_NOT_NULL(scheduler_); |
| 95 | scheduler_->StartBlock(rpo); |
| 96 | } else { |
| 97 | sequence()->StartBlock(rpo); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | void InstructionSelector::EndBlock(RpoNumber rpo) { |
| 103 | if (FLAG_turbo_instruction_scheduling && |
| 104 | InstructionScheduler::SchedulerSupported()) { |
| 105 | DCHECK_NOT_NULL(scheduler_); |
| 106 | scheduler_->EndBlock(rpo); |
| 107 | } else { |
| 108 | sequence()->EndBlock(rpo); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | |
| 113 | void InstructionSelector::AddInstruction(Instruction* instr) { |
| 114 | if (FLAG_turbo_instruction_scheduling && |
| 115 | InstructionScheduler::SchedulerSupported()) { |
| 116 | DCHECK_NOT_NULL(scheduler_); |
| 117 | scheduler_->AddInstruction(instr); |
| 118 | } else { |
| 119 | sequence()->AddInstruction(instr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | |
| 124 | Instruction* InstructionSelector::Emit(InstructionCode opcode, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 125 | InstructionOperand output, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | size_t temp_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | InstructionOperand* temps) { |
| 128 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 129 | return Emit(opcode, output_count, &output, 0, nullptr, temp_count, temps); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | Instruction* InstructionSelector::Emit(InstructionCode opcode, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 134 | InstructionOperand output, |
| 135 | InstructionOperand a, size_t temp_count, |
| 136 | InstructionOperand* temps) { |
| 137 | size_t output_count = output.IsInvalid() ? 0 : 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | return Emit(opcode, output_count, &output, 1, &a, temp_count, temps); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | Instruction* InstructionSelector::Emit(InstructionCode opcode, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 143 | InstructionOperand output, |
| 144 | InstructionOperand a, |
| 145 | InstructionOperand b, size_t temp_count, |
| 146 | InstructionOperand* temps) { |
| 147 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 148 | InstructionOperand inputs[] = {a, b}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 149 | size_t input_count = arraysize(inputs); |
| 150 | return Emit(opcode, output_count, &output, input_count, inputs, temp_count, |
| 151 | temps); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | Instruction* InstructionSelector::Emit(InstructionCode opcode, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 156 | InstructionOperand output, |
| 157 | InstructionOperand a, |
| 158 | InstructionOperand b, |
| 159 | InstructionOperand c, size_t temp_count, |
| 160 | InstructionOperand* temps) { |
| 161 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 162 | InstructionOperand inputs[] = {a, b, c}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 163 | size_t input_count = arraysize(inputs); |
| 164 | return Emit(opcode, output_count, &output, input_count, inputs, temp_count, |
| 165 | temps); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | Instruction* InstructionSelector::Emit( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 170 | InstructionCode opcode, InstructionOperand output, InstructionOperand a, |
| 171 | InstructionOperand b, InstructionOperand c, InstructionOperand d, |
| 172 | size_t temp_count, InstructionOperand* temps) { |
| 173 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 174 | InstructionOperand inputs[] = {a, b, c, d}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 175 | size_t input_count = arraysize(inputs); |
| 176 | return Emit(opcode, output_count, &output, input_count, inputs, temp_count, |
| 177 | temps); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | Instruction* InstructionSelector::Emit( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 182 | InstructionCode opcode, InstructionOperand output, InstructionOperand a, |
| 183 | InstructionOperand b, InstructionOperand c, InstructionOperand d, |
| 184 | InstructionOperand e, size_t temp_count, InstructionOperand* temps) { |
| 185 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 186 | InstructionOperand inputs[] = {a, b, c, d, e}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 187 | size_t input_count = arraysize(inputs); |
| 188 | return Emit(opcode, output_count, &output, input_count, inputs, temp_count, |
| 189 | temps); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | Instruction* InstructionSelector::Emit( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 194 | InstructionCode opcode, InstructionOperand output, InstructionOperand a, |
| 195 | InstructionOperand b, InstructionOperand c, InstructionOperand d, |
| 196 | InstructionOperand e, InstructionOperand f, size_t temp_count, |
| 197 | InstructionOperand* temps) { |
| 198 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 199 | InstructionOperand inputs[] = {a, b, c, d, e, f}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 200 | size_t input_count = arraysize(inputs); |
| 201 | return Emit(opcode, output_count, &output, input_count, inputs, temp_count, |
| 202 | temps); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | Instruction* InstructionSelector::Emit( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 207 | InstructionCode opcode, size_t output_count, InstructionOperand* outputs, |
| 208 | size_t input_count, InstructionOperand* inputs, size_t temp_count, |
| 209 | InstructionOperand* temps) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | Instruction* instr = |
| 211 | Instruction::New(instruction_zone(), opcode, output_count, outputs, |
| 212 | input_count, inputs, temp_count, temps); |
| 213 | return Emit(instr); |
| 214 | } |
| 215 | |
| 216 | |
| 217 | Instruction* InstructionSelector::Emit(Instruction* instr) { |
| 218 | instructions_.push_back(instr); |
| 219 | return instr; |
| 220 | } |
| 221 | |
| 222 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 223 | bool InstructionSelector::CanCover(Node* user, Node* node) const { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 224 | // 1. Both {user} and {node} must be in the same basic block. |
| 225 | if (schedule()->block(node) != schedule()->block(user)) { |
| 226 | return false; |
| 227 | } |
| 228 | // 2. Pure {node}s must be owned by the {user}. |
| 229 | if (node->op()->HasProperty(Operator::kPure)) { |
| 230 | return node->OwnedBy(user); |
| 231 | } |
| 232 | // 3. Impure {node}s must match the effect level of {user}. |
| 233 | if (GetEffectLevel(node) != GetEffectLevel(user)) { |
| 234 | return false; |
| 235 | } |
| 236 | // 4. Only {node} must have value edges pointing to {user}. |
| 237 | for (Edge const edge : node->use_edges()) { |
| 238 | if (edge.from() != user && NodeProperties::IsValueEdge(edge)) { |
| 239 | return false; |
| 240 | } |
| 241 | } |
| 242 | return true; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 245 | int InstructionSelector::GetVirtualRegister(const Node* node) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 246 | DCHECK_NOT_NULL(node); |
| 247 | size_t const id = node->id(); |
| 248 | DCHECK_LT(id, virtual_registers_.size()); |
| 249 | int virtual_register = virtual_registers_[id]; |
| 250 | if (virtual_register == InstructionOperand::kInvalidVirtualRegister) { |
| 251 | virtual_register = sequence()->NextVirtualRegister(); |
| 252 | virtual_registers_[id] = virtual_register; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 253 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 254 | return virtual_register; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 258 | const std::map<NodeId, int> InstructionSelector::GetVirtualRegistersForTesting() |
| 259 | const { |
| 260 | std::map<NodeId, int> virtual_registers; |
| 261 | for (size_t n = 0; n < virtual_registers_.size(); ++n) { |
| 262 | if (virtual_registers_[n] != InstructionOperand::kInvalidVirtualRegister) { |
| 263 | NodeId const id = static_cast<NodeId>(n); |
| 264 | virtual_registers.insert(std::make_pair(id, virtual_registers_[n])); |
| 265 | } |
| 266 | } |
| 267 | return virtual_registers; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 271 | bool InstructionSelector::IsDefined(Node* node) const { |
| 272 | DCHECK_NOT_NULL(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 273 | size_t const id = node->id(); |
| 274 | DCHECK_LT(id, defined_.size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 275 | return defined_[id]; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | void InstructionSelector::MarkAsDefined(Node* node) { |
| 280 | DCHECK_NOT_NULL(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 281 | size_t const id = node->id(); |
| 282 | DCHECK_LT(id, defined_.size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 283 | defined_[id] = true; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | bool InstructionSelector::IsUsed(Node* node) const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 288 | DCHECK_NOT_NULL(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 289 | if (!node->op()->HasProperty(Operator::kEliminatable)) return true; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 290 | size_t const id = node->id(); |
| 291 | DCHECK_LT(id, used_.size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | return used_[id]; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | void InstructionSelector::MarkAsUsed(Node* node) { |
| 297 | DCHECK_NOT_NULL(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 298 | size_t const id = node->id(); |
| 299 | DCHECK_LT(id, used_.size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | used_[id] = true; |
| 301 | } |
| 302 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 303 | int InstructionSelector::GetEffectLevel(Node* node) const { |
| 304 | DCHECK_NOT_NULL(node); |
| 305 | size_t const id = node->id(); |
| 306 | DCHECK_LT(id, effect_level_.size()); |
| 307 | return effect_level_[id]; |
| 308 | } |
| 309 | |
| 310 | void InstructionSelector::SetEffectLevel(Node* node, int effect_level) { |
| 311 | DCHECK_NOT_NULL(node); |
| 312 | size_t const id = node->id(); |
| 313 | DCHECK_LT(id, effect_level_.size()); |
| 314 | effect_level_[id] = effect_level; |
| 315 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 316 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 317 | void InstructionSelector::MarkAsRepresentation(MachineRepresentation rep, |
| 318 | const InstructionOperand& op) { |
| 319 | UnallocatedOperand unalloc = UnallocatedOperand::cast(op); |
| 320 | sequence()->MarkAsRepresentation(rep, unalloc.virtual_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 324 | void InstructionSelector::MarkAsRepresentation(MachineRepresentation rep, |
| 325 | Node* node) { |
| 326 | sequence()->MarkAsRepresentation(rep, GetVirtualRegister(node)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 330 | namespace { |
| 331 | |
| 332 | enum class FrameStateInputKind { kAny, kStackSlot }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 333 | |
| 334 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 335 | InstructionOperand OperandForDeopt(OperandGenerator* g, Node* input, |
| 336 | FrameStateInputKind kind) { |
| 337 | switch (input->opcode()) { |
| 338 | case IrOpcode::kInt32Constant: |
| 339 | case IrOpcode::kNumberConstant: |
| 340 | case IrOpcode::kFloat32Constant: |
| 341 | case IrOpcode::kFloat64Constant: |
| 342 | case IrOpcode::kHeapConstant: |
| 343 | return g->UseImmediate(input); |
| 344 | case IrOpcode::kObjectState: |
| 345 | UNREACHABLE(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 346 | break; |
| 347 | default: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 348 | switch (kind) { |
| 349 | case FrameStateInputKind::kStackSlot: |
| 350 | return g->UseUniqueSlot(input); |
| 351 | case FrameStateInputKind::kAny: |
| 352 | return g->UseAny(input); |
| 353 | } |
| 354 | } |
| 355 | UNREACHABLE(); |
| 356 | return InstructionOperand(); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | class StateObjectDeduplicator { |
| 361 | public: |
| 362 | explicit StateObjectDeduplicator(Zone* zone) : objects_(zone) {} |
| 363 | static const size_t kNotDuplicated = SIZE_MAX; |
| 364 | |
| 365 | size_t GetObjectId(Node* node) { |
| 366 | for (size_t i = 0; i < objects_.size(); ++i) { |
| 367 | if (objects_[i] == node) { |
| 368 | return i; |
| 369 | } |
| 370 | } |
| 371 | return kNotDuplicated; |
| 372 | } |
| 373 | |
| 374 | size_t InsertObject(Node* node) { |
| 375 | size_t id = objects_.size(); |
| 376 | objects_.push_back(node); |
| 377 | return id; |
| 378 | } |
| 379 | |
| 380 | private: |
| 381 | ZoneVector<Node*> objects_; |
| 382 | }; |
| 383 | |
| 384 | |
| 385 | // Returns the number of instruction operands added to inputs. |
| 386 | size_t AddOperandToStateValueDescriptor(StateValueDescriptor* descriptor, |
| 387 | InstructionOperandVector* inputs, |
| 388 | OperandGenerator* g, |
| 389 | StateObjectDeduplicator* deduplicator, |
| 390 | Node* input, MachineType type, |
| 391 | FrameStateInputKind kind, Zone* zone) { |
| 392 | switch (input->opcode()) { |
| 393 | case IrOpcode::kObjectState: { |
| 394 | size_t id = deduplicator->GetObjectId(input); |
| 395 | if (id == StateObjectDeduplicator::kNotDuplicated) { |
| 396 | size_t entries = 0; |
| 397 | id = deduplicator->InsertObject(input); |
| 398 | descriptor->fields().push_back( |
| 399 | StateValueDescriptor::Recursive(zone, id)); |
| 400 | StateValueDescriptor* new_desc = &descriptor->fields().back(); |
| 401 | for (Edge edge : input->input_edges()) { |
| 402 | entries += AddOperandToStateValueDescriptor( |
| 403 | new_desc, inputs, g, deduplicator, edge.to(), |
| 404 | MachineType::AnyTagged(), kind, zone); |
| 405 | } |
| 406 | return entries; |
| 407 | } else { |
| 408 | // Crankshaft counts duplicate objects for the running id, so we have |
| 409 | // to push the input again. |
| 410 | deduplicator->InsertObject(input); |
| 411 | descriptor->fields().push_back( |
| 412 | StateValueDescriptor::Duplicate(zone, id)); |
| 413 | return 0; |
| 414 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 415 | break; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 416 | } |
| 417 | default: { |
| 418 | inputs->push_back(OperandForDeopt(g, input, kind)); |
| 419 | descriptor->fields().push_back(StateValueDescriptor::Plain(zone, type)); |
| 420 | return 1; |
| 421 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 422 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 426 | // Returns the number of instruction operands added to inputs. |
| 427 | size_t AddInputsToFrameStateDescriptor(FrameStateDescriptor* descriptor, |
| 428 | Node* state, OperandGenerator* g, |
| 429 | StateObjectDeduplicator* deduplicator, |
| 430 | InstructionOperandVector* inputs, |
| 431 | FrameStateInputKind kind, Zone* zone) { |
| 432 | DCHECK_EQ(IrOpcode::kFrameState, state->op()->opcode()); |
| 433 | |
| 434 | size_t entries = 0; |
| 435 | size_t initial_size = inputs->size(); |
| 436 | USE(initial_size); // initial_size is only used for debug. |
| 437 | |
| 438 | if (descriptor->outer_state()) { |
| 439 | entries += AddInputsToFrameStateDescriptor( |
| 440 | descriptor->outer_state(), state->InputAt(kFrameStateOuterStateInput), |
| 441 | g, deduplicator, inputs, kind, zone); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 442 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 443 | |
| 444 | Node* parameters = state->InputAt(kFrameStateParametersInput); |
| 445 | Node* locals = state->InputAt(kFrameStateLocalsInput); |
| 446 | Node* stack = state->InputAt(kFrameStateStackInput); |
| 447 | Node* context = state->InputAt(kFrameStateContextInput); |
| 448 | Node* function = state->InputAt(kFrameStateFunctionInput); |
| 449 | |
| 450 | DCHECK_EQ(descriptor->parameters_count(), |
| 451 | StateValuesAccess(parameters).size()); |
| 452 | DCHECK_EQ(descriptor->locals_count(), StateValuesAccess(locals).size()); |
| 453 | DCHECK_EQ(descriptor->stack_count(), StateValuesAccess(stack).size()); |
| 454 | |
| 455 | StateValueDescriptor* values_descriptor = |
| 456 | descriptor->GetStateValueDescriptor(); |
| 457 | entries += AddOperandToStateValueDescriptor( |
| 458 | values_descriptor, inputs, g, deduplicator, function, |
| 459 | MachineType::AnyTagged(), FrameStateInputKind::kStackSlot, zone); |
| 460 | for (StateValuesAccess::TypedNode input_node : |
| 461 | StateValuesAccess(parameters)) { |
| 462 | entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g, |
| 463 | deduplicator, input_node.node, |
| 464 | input_node.type, kind, zone); |
| 465 | } |
| 466 | if (descriptor->HasContext()) { |
| 467 | entries += AddOperandToStateValueDescriptor( |
| 468 | values_descriptor, inputs, g, deduplicator, context, |
| 469 | MachineType::AnyTagged(), FrameStateInputKind::kStackSlot, zone); |
| 470 | } |
| 471 | for (StateValuesAccess::TypedNode input_node : StateValuesAccess(locals)) { |
| 472 | entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g, |
| 473 | deduplicator, input_node.node, |
| 474 | input_node.type, kind, zone); |
| 475 | } |
| 476 | for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { |
| 477 | entries += AddOperandToStateValueDescriptor(values_descriptor, inputs, g, |
| 478 | deduplicator, input_node.node, |
| 479 | input_node.type, kind, zone); |
| 480 | } |
| 481 | DCHECK_EQ(initial_size + entries, inputs->size()); |
| 482 | return entries; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 485 | } // namespace |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 486 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 487 | |
| 488 | // An internal helper class for generating the operands to calls. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 489 | // TODO(bmeurer): Get rid of the CallBuffer business and make |
| 490 | // InstructionSelector::VisitCall platform independent instead. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 491 | struct CallBuffer { |
| 492 | CallBuffer(Zone* zone, const CallDescriptor* descriptor, |
| 493 | FrameStateDescriptor* frame_state) |
| 494 | : descriptor(descriptor), |
| 495 | frame_state_descriptor(frame_state), |
| 496 | output_nodes(zone), |
| 497 | outputs(zone), |
| 498 | instruction_args(zone), |
| 499 | pushed_nodes(zone) { |
| 500 | output_nodes.reserve(descriptor->ReturnCount()); |
| 501 | outputs.reserve(descriptor->ReturnCount()); |
| 502 | pushed_nodes.reserve(input_count()); |
| 503 | instruction_args.reserve(input_count() + frame_state_value_count()); |
| 504 | } |
| 505 | |
| 506 | |
| 507 | const CallDescriptor* descriptor; |
| 508 | FrameStateDescriptor* frame_state_descriptor; |
| 509 | NodeVector output_nodes; |
| 510 | InstructionOperandVector outputs; |
| 511 | InstructionOperandVector instruction_args; |
| 512 | ZoneVector<PushParameter> pushed_nodes; |
| 513 | |
| 514 | size_t input_count() const { return descriptor->InputCount(); } |
| 515 | |
| 516 | size_t frame_state_count() const { return descriptor->FrameStateCount(); } |
| 517 | |
| 518 | size_t frame_state_value_count() const { |
| 519 | return (frame_state_descriptor == nullptr) |
| 520 | ? 0 |
| 521 | : (frame_state_descriptor->GetTotalSize() + |
| 522 | 1); // Include deopt id. |
| 523 | } |
| 524 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 525 | |
| 526 | |
| 527 | // TODO(bmeurer): Get rid of the CallBuffer business and make |
| 528 | // InstructionSelector::VisitCall platform independent instead. |
| 529 | void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 530 | CallBufferFlags flags, |
| 531 | int stack_param_delta) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | OperandGenerator g(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 533 | DCHECK_LE(call->op()->ValueOutputCount(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 534 | static_cast<int>(buffer->descriptor->ReturnCount())); |
| 535 | DCHECK_EQ( |
| 536 | call->op()->ValueInputCount(), |
| 537 | static_cast<int>(buffer->input_count() + buffer->frame_state_count())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 538 | |
| 539 | if (buffer->descriptor->ReturnCount() > 0) { |
| 540 | // Collect the projections that represent multiple outputs from this call. |
| 541 | if (buffer->descriptor->ReturnCount() == 1) { |
| 542 | buffer->output_nodes.push_back(call); |
| 543 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 544 | buffer->output_nodes.resize(buffer->descriptor->ReturnCount(), nullptr); |
| 545 | for (auto use : call->uses()) { |
| 546 | if (use->opcode() != IrOpcode::kProjection) continue; |
| 547 | size_t const index = ProjectionIndexOf(use->op()); |
| 548 | DCHECK_LT(index, buffer->output_nodes.size()); |
| 549 | DCHECK(!buffer->output_nodes[index]); |
| 550 | buffer->output_nodes[index] = use; |
| 551 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | // Filter out the outputs that aren't live because no projection uses them. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 555 | size_t outputs_needed_by_framestate = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 556 | buffer->frame_state_descriptor == nullptr |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 557 | ? 0 |
| 558 | : buffer->frame_state_descriptor->state_combine() |
| 559 | .ConsumedOutputCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 560 | for (size_t i = 0; i < buffer->output_nodes.size(); i++) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 561 | bool output_is_live = buffer->output_nodes[i] != nullptr || |
| 562 | i < outputs_needed_by_framestate; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 563 | if (output_is_live) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 564 | MachineType type = |
| 565 | buffer->descriptor->GetReturnType(static_cast<int>(i)); |
| 566 | LinkageLocation location = |
| 567 | buffer->descriptor->GetReturnLocation(static_cast<int>(i)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 568 | |
| 569 | Node* output = buffer->output_nodes[i]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 570 | InstructionOperand op = |
| 571 | output == nullptr |
| 572 | ? g.TempLocation(location, type.representation()) |
| 573 | : g.DefineAsLocation(output, location, type.representation()); |
| 574 | MarkAsRepresentation(type.representation(), op); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 575 | |
| 576 | buffer->outputs.push_back(op); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | // The first argument is always the callee code. |
| 582 | Node* callee = call->InputAt(0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 583 | bool call_code_immediate = (flags & kCallCodeImmediate) != 0; |
| 584 | bool call_address_immediate = (flags & kCallAddressImmediate) != 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 585 | switch (buffer->descriptor->kind()) { |
| 586 | case CallDescriptor::kCallCodeObject: |
| 587 | buffer->instruction_args.push_back( |
| 588 | (call_code_immediate && callee->opcode() == IrOpcode::kHeapConstant) |
| 589 | ? g.UseImmediate(callee) |
| 590 | : g.UseRegister(callee)); |
| 591 | break; |
| 592 | case CallDescriptor::kCallAddress: |
| 593 | buffer->instruction_args.push_back( |
| 594 | (call_address_immediate && |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 595 | callee->opcode() == IrOpcode::kExternalConstant) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 596 | ? g.UseImmediate(callee) |
| 597 | : g.UseRegister(callee)); |
| 598 | break; |
| 599 | case CallDescriptor::kCallJSFunction: |
| 600 | buffer->instruction_args.push_back( |
| 601 | g.UseLocation(callee, buffer->descriptor->GetInputLocation(0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 602 | buffer->descriptor->GetInputType(0).representation())); |
| 603 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 604 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 605 | DCHECK_EQ(1u, buffer->instruction_args.size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 606 | |
| 607 | // If the call needs a frame state, we insert the state information as |
| 608 | // follows (n is the number of value inputs to the frame state): |
| 609 | // arg 1 : deoptimization id. |
| 610 | // arg 2 - arg (n + 1) : value inputs to the frame state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 611 | size_t frame_state_entries = 0; |
| 612 | USE(frame_state_entries); // frame_state_entries is only used for debug. |
| 613 | if (buffer->frame_state_descriptor != nullptr) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 614 | Node* frame_state = |
| 615 | call->InputAt(static_cast<int>(buffer->descriptor->InputCount())); |
| 616 | |
| 617 | // If it was a syntactic tail call we need to drop the current frame and |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 618 | // all the frames on top of it that are either an arguments adaptor frame |
| 619 | // or a tail caller frame. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 620 | if (buffer->descriptor->SupportsTailCalls()) { |
| 621 | frame_state = NodeProperties::GetFrameStateInput(frame_state, 0); |
| 622 | buffer->frame_state_descriptor = |
| 623 | buffer->frame_state_descriptor->outer_state(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 624 | while (buffer->frame_state_descriptor != nullptr && |
| 625 | (buffer->frame_state_descriptor->type() == |
| 626 | FrameStateType::kArgumentsAdaptor || |
| 627 | buffer->frame_state_descriptor->type() == |
| 628 | FrameStateType::kTailCallerFunction)) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 629 | frame_state = NodeProperties::GetFrameStateInput(frame_state, 0); |
| 630 | buffer->frame_state_descriptor = |
| 631 | buffer->frame_state_descriptor->outer_state(); |
| 632 | } |
| 633 | } |
| 634 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 635 | InstructionSequence::StateId state_id = |
| 636 | sequence()->AddFrameStateDescriptor(buffer->frame_state_descriptor); |
| 637 | buffer->instruction_args.push_back(g.TempImmediate(state_id.ToInt())); |
| 638 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 639 | StateObjectDeduplicator deduplicator(instruction_zone()); |
| 640 | |
| 641 | frame_state_entries = |
| 642 | 1 + AddInputsToFrameStateDescriptor( |
| 643 | buffer->frame_state_descriptor, frame_state, &g, &deduplicator, |
| 644 | &buffer->instruction_args, FrameStateInputKind::kStackSlot, |
| 645 | instruction_zone()); |
| 646 | |
| 647 | DCHECK_EQ(1 + frame_state_entries, buffer->instruction_args.size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 648 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 649 | |
| 650 | size_t input_count = static_cast<size_t>(buffer->input_count()); |
| 651 | |
| 652 | // Split the arguments into pushed_nodes and instruction_args. Pushed |
| 653 | // arguments require an explicit push instruction before the call and do |
| 654 | // not appear as arguments to the call. Everything else ends up |
| 655 | // as an InstructionOperand argument to the call. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 656 | auto iter(call->inputs().begin()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 657 | size_t pushed_count = 0; |
| 658 | bool call_tail = (flags & kCallTail) != 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 659 | for (size_t index = 0; index < input_count; ++iter, ++index) { |
| 660 | DCHECK(iter != call->inputs().end()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 661 | DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState); |
| 662 | if (index == 0) continue; // The first argument (callee) is already done. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 663 | |
| 664 | LinkageLocation location = buffer->descriptor->GetInputLocation(index); |
| 665 | if (call_tail) { |
| 666 | location = LinkageLocation::ConvertToTailCallerLocation( |
| 667 | location, stack_param_delta); |
| 668 | } |
| 669 | InstructionOperand op = |
| 670 | g.UseLocation(*iter, location, |
| 671 | buffer->descriptor->GetInputType(index).representation()); |
| 672 | if (UnallocatedOperand::cast(op).HasFixedSlotPolicy() && !call_tail) { |
| 673 | int stack_index = -UnallocatedOperand::cast(op).fixed_slot_index() - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 674 | if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 675 | buffer->pushed_nodes.resize(stack_index + 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 676 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 677 | PushParameter parameter(*iter, buffer->descriptor->GetInputType(index)); |
| 678 | buffer->pushed_nodes[stack_index] = parameter; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 679 | pushed_count++; |
| 680 | } else { |
| 681 | buffer->instruction_args.push_back(op); |
| 682 | } |
| 683 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 684 | DCHECK_EQ(input_count, buffer->instruction_args.size() + pushed_count - |
| 685 | frame_state_entries); |
| 686 | if (V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK && call_tail && |
| 687 | stack_param_delta != 0) { |
| 688 | // For tail calls that change the size of their parameter list and keep |
| 689 | // their return address on the stack, move the return address to just above |
| 690 | // the parameters. |
| 691 | LinkageLocation saved_return_location = |
| 692 | LinkageLocation::ForSavedCallerReturnAddress(); |
| 693 | InstructionOperand return_address = |
| 694 | g.UsePointerLocation(LinkageLocation::ConvertToTailCallerLocation( |
| 695 | saved_return_location, stack_param_delta), |
| 696 | saved_return_location); |
| 697 | buffer->instruction_args.push_back(return_address); |
| 698 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | |
| 702 | void InstructionSelector::VisitBlock(BasicBlock* block) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 703 | DCHECK(!current_block_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | current_block_ = block; |
| 705 | int current_block_end = static_cast<int>(instructions_.size()); |
| 706 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 707 | int effect_level = 0; |
| 708 | for (Node* const node : *block) { |
| 709 | if (node->opcode() == IrOpcode::kStore || |
| 710 | node->opcode() == IrOpcode::kCheckedStore || |
| 711 | node->opcode() == IrOpcode::kCall) { |
| 712 | ++effect_level; |
| 713 | } |
| 714 | SetEffectLevel(node, effect_level); |
| 715 | } |
| 716 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 717 | // Generate code for the block control "top down", but schedule the code |
| 718 | // "bottom up". |
| 719 | VisitControl(block); |
| 720 | std::reverse(instructions_.begin() + current_block_end, instructions_.end()); |
| 721 | |
| 722 | // Visit code in reverse control flow order, because architecture-specific |
| 723 | // matching may cover more than one node at a time. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 724 | for (auto node : base::Reversed(*block)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | // Skip nodes that are unused or already defined. |
| 726 | if (!IsUsed(node) || IsDefined(node)) continue; |
| 727 | // Generate code for this node "top down", but schedule the code "bottom |
| 728 | // up". |
| 729 | size_t current_node_end = instructions_.size(); |
| 730 | VisitNode(node); |
| 731 | std::reverse(instructions_.begin() + current_node_end, instructions_.end()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 732 | if (instructions_.size() == current_node_end) continue; |
| 733 | // Mark source position on first instruction emitted. |
| 734 | SourcePosition source_position = source_positions_->GetSourcePosition(node); |
| 735 | if (source_position.IsKnown() && |
| 736 | (source_position_mode_ == kAllSourcePositions || |
| 737 | node->opcode() == IrOpcode::kCall)) { |
| 738 | sequence()->SetSourcePosition(instructions_[current_node_end], |
| 739 | source_position); |
| 740 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | // We're done with the block. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 744 | InstructionBlock* instruction_block = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 745 | sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 746 | instruction_block->set_code_start(static_cast<int>(instructions_.size())); |
| 747 | instruction_block->set_code_end(current_block_end); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 748 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 749 | current_block_ = nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | |
| 753 | void InstructionSelector::VisitControl(BasicBlock* block) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 754 | #ifdef DEBUG |
| 755 | // SSA deconstruction requires targets of branches not to have phis. |
| 756 | // Edge split form guarantees this property, but is more strict. |
| 757 | if (block->SuccessorCount() > 1) { |
| 758 | for (BasicBlock* const successor : block->successors()) { |
| 759 | for (Node* const node : *successor) { |
| 760 | CHECK(!IrOpcode::IsPhiOpcode(node->opcode())); |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | #endif |
| 765 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 766 | Node* input = block->control_input(); |
| 767 | switch (block->control()) { |
| 768 | case BasicBlock::kGoto: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 769 | return VisitGoto(block->SuccessorAt(0)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 770 | case BasicBlock::kCall: { |
| 771 | DCHECK_EQ(IrOpcode::kCall, input->opcode()); |
| 772 | BasicBlock* success = block->SuccessorAt(0); |
| 773 | BasicBlock* exception = block->SuccessorAt(1); |
| 774 | return VisitCall(input, exception), VisitGoto(success); |
| 775 | } |
| 776 | case BasicBlock::kTailCall: { |
| 777 | DCHECK_EQ(IrOpcode::kTailCall, input->opcode()); |
| 778 | return VisitTailCall(input); |
| 779 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 780 | case BasicBlock::kBranch: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 781 | DCHECK_EQ(IrOpcode::kBranch, input->opcode()); |
| 782 | BasicBlock* tbranch = block->SuccessorAt(0); |
| 783 | BasicBlock* fbranch = block->SuccessorAt(1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 784 | if (tbranch == fbranch) return VisitGoto(tbranch); |
| 785 | return VisitBranch(input, tbranch, fbranch); |
| 786 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 787 | case BasicBlock::kSwitch: { |
| 788 | DCHECK_EQ(IrOpcode::kSwitch, input->opcode()); |
| 789 | SwitchInfo sw; |
| 790 | // Last successor must be Default. |
| 791 | sw.default_branch = block->successors().back(); |
| 792 | DCHECK_EQ(IrOpcode::kIfDefault, sw.default_branch->front()->opcode()); |
| 793 | // All other successors must be cases. |
| 794 | sw.case_count = block->SuccessorCount() - 1; |
| 795 | sw.case_branches = &block->successors().front(); |
| 796 | // Determine case values and their min/max. |
| 797 | sw.case_values = zone()->NewArray<int32_t>(sw.case_count); |
| 798 | sw.min_value = std::numeric_limits<int32_t>::max(); |
| 799 | sw.max_value = std::numeric_limits<int32_t>::min(); |
| 800 | for (size_t index = 0; index < sw.case_count; ++index) { |
| 801 | BasicBlock* branch = sw.case_branches[index]; |
| 802 | int32_t value = OpParameter<int32_t>(branch->front()->op()); |
| 803 | sw.case_values[index] = value; |
| 804 | if (sw.min_value > value) sw.min_value = value; |
| 805 | if (sw.max_value < value) sw.max_value = value; |
| 806 | } |
| 807 | DCHECK_LE(sw.min_value, sw.max_value); |
| 808 | // Note that {value_range} can be 0 if {min_value} is -2^31 and |
| 809 | // {max_value} |
| 810 | // is 2^31-1, so don't assume that it's non-zero below. |
| 811 | sw.value_range = 1u + bit_cast<uint32_t>(sw.max_value) - |
| 812 | bit_cast<uint32_t>(sw.min_value); |
| 813 | return VisitSwitch(input, sw); |
| 814 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 815 | case BasicBlock::kReturn: { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 816 | DCHECK_EQ(IrOpcode::kReturn, input->opcode()); |
| 817 | return VisitReturn(input); |
| 818 | } |
| 819 | case BasicBlock::kDeoptimize: { |
| 820 | DeoptimizeKind kind = DeoptimizeKindOf(input->op()); |
| 821 | Node* value = input->InputAt(0); |
| 822 | return VisitDeoptimize(kind, value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 823 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 824 | case BasicBlock::kThrow: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 825 | DCHECK_EQ(IrOpcode::kThrow, input->opcode()); |
| 826 | return VisitThrow(input->InputAt(0)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 827 | case BasicBlock::kNone: { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 828 | // Exit block doesn't have control. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 829 | DCHECK_NULL(input); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 830 | break; |
| 831 | } |
| 832 | default: |
| 833 | UNREACHABLE(); |
| 834 | break; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 839 | void InstructionSelector::VisitNode(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 840 | DCHECK_NOT_NULL(schedule()->block(node)); // should only use scheduled nodes. |
| 841 | switch (node->opcode()) { |
| 842 | case IrOpcode::kStart: |
| 843 | case IrOpcode::kLoop: |
| 844 | case IrOpcode::kEnd: |
| 845 | case IrOpcode::kBranch: |
| 846 | case IrOpcode::kIfTrue: |
| 847 | case IrOpcode::kIfFalse: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 848 | case IrOpcode::kIfSuccess: |
| 849 | case IrOpcode::kSwitch: |
| 850 | case IrOpcode::kIfValue: |
| 851 | case IrOpcode::kIfDefault: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 852 | case IrOpcode::kEffectPhi: |
| 853 | case IrOpcode::kMerge: |
| 854 | case IrOpcode::kTerminate: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 855 | case IrOpcode::kBeginRegion: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | // No code needed for these graph artifacts. |
| 857 | return; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 858 | case IrOpcode::kIfException: |
| 859 | return MarkAsReference(node), VisitIfException(node); |
| 860 | case IrOpcode::kFinishRegion: |
| 861 | return MarkAsReference(node), VisitFinishRegion(node); |
| 862 | case IrOpcode::kGuard: |
| 863 | return MarkAsReference(node), VisitGuard(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 864 | case IrOpcode::kParameter: { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 865 | MachineType type = |
| 866 | linkage()->GetParameterType(ParameterIndexOf(node->op())); |
| 867 | MarkAsRepresentation(type.representation(), node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 868 | return VisitParameter(node); |
| 869 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 870 | case IrOpcode::kOsrValue: |
| 871 | return MarkAsReference(node), VisitOsrValue(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 872 | case IrOpcode::kPhi: { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 873 | MachineRepresentation rep = PhiRepresentationOf(node->op()); |
| 874 | MarkAsRepresentation(rep, node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 875 | return VisitPhi(node); |
| 876 | } |
| 877 | case IrOpcode::kProjection: |
| 878 | return VisitProjection(node); |
| 879 | case IrOpcode::kInt32Constant: |
| 880 | case IrOpcode::kInt64Constant: |
| 881 | case IrOpcode::kExternalConstant: |
| 882 | return VisitConstant(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 883 | case IrOpcode::kFloat32Constant: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 884 | return MarkAsFloat32(node), VisitConstant(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 885 | case IrOpcode::kFloat64Constant: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 886 | return MarkAsFloat64(node), VisitConstant(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 887 | case IrOpcode::kHeapConstant: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 888 | return MarkAsReference(node), VisitConstant(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 889 | case IrOpcode::kNumberConstant: { |
| 890 | double value = OpParameter<double>(node); |
| 891 | if (!IsSmiDouble(value)) MarkAsReference(node); |
| 892 | return VisitConstant(node); |
| 893 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 894 | case IrOpcode::kCall: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 895 | return VisitCall(node); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 896 | case IrOpcode::kDeoptimizeIf: |
| 897 | return VisitDeoptimizeIf(node); |
| 898 | case IrOpcode::kDeoptimizeUnless: |
| 899 | return VisitDeoptimizeUnless(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 900 | case IrOpcode::kFrameState: |
| 901 | case IrOpcode::kStateValues: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 902 | case IrOpcode::kObjectState: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 903 | return; |
| 904 | case IrOpcode::kLoad: { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 905 | LoadRepresentation type = LoadRepresentationOf(node->op()); |
| 906 | MarkAsRepresentation(type.representation(), node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 907 | return VisitLoad(node); |
| 908 | } |
| 909 | case IrOpcode::kStore: |
| 910 | return VisitStore(node); |
| 911 | case IrOpcode::kWord32And: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 912 | return MarkAsWord32(node), VisitWord32And(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 913 | case IrOpcode::kWord32Or: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 914 | return MarkAsWord32(node), VisitWord32Or(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 915 | case IrOpcode::kWord32Xor: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 916 | return MarkAsWord32(node), VisitWord32Xor(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 917 | case IrOpcode::kWord32Shl: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 918 | return MarkAsWord32(node), VisitWord32Shl(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 919 | case IrOpcode::kWord32Shr: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 920 | return MarkAsWord32(node), VisitWord32Shr(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 921 | case IrOpcode::kWord32Sar: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 922 | return MarkAsWord32(node), VisitWord32Sar(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 923 | case IrOpcode::kWord32Ror: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 924 | return MarkAsWord32(node), VisitWord32Ror(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 925 | case IrOpcode::kWord32Equal: |
| 926 | return VisitWord32Equal(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 927 | case IrOpcode::kWord32Clz: |
| 928 | return MarkAsWord32(node), VisitWord32Clz(node); |
| 929 | case IrOpcode::kWord32Ctz: |
| 930 | return MarkAsWord32(node), VisitWord32Ctz(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 931 | case IrOpcode::kWord32ReverseBits: |
| 932 | return MarkAsWord32(node), VisitWord32ReverseBits(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 933 | case IrOpcode::kWord32Popcnt: |
| 934 | return MarkAsWord32(node), VisitWord32Popcnt(node); |
| 935 | case IrOpcode::kWord64Popcnt: |
| 936 | return MarkAsWord32(node), VisitWord64Popcnt(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 937 | case IrOpcode::kWord64And: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 938 | return MarkAsWord64(node), VisitWord64And(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 939 | case IrOpcode::kWord64Or: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 940 | return MarkAsWord64(node), VisitWord64Or(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 941 | case IrOpcode::kWord64Xor: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 942 | return MarkAsWord64(node), VisitWord64Xor(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 943 | case IrOpcode::kWord64Shl: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 944 | return MarkAsWord64(node), VisitWord64Shl(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 945 | case IrOpcode::kWord64Shr: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 946 | return MarkAsWord64(node), VisitWord64Shr(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 947 | case IrOpcode::kWord64Sar: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 948 | return MarkAsWord64(node), VisitWord64Sar(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 949 | case IrOpcode::kWord64Ror: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 950 | return MarkAsWord64(node), VisitWord64Ror(node); |
| 951 | case IrOpcode::kWord64Clz: |
| 952 | return MarkAsWord64(node), VisitWord64Clz(node); |
| 953 | case IrOpcode::kWord64Ctz: |
| 954 | return MarkAsWord64(node), VisitWord64Ctz(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 955 | case IrOpcode::kWord64ReverseBits: |
| 956 | return MarkAsWord64(node), VisitWord64ReverseBits(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 957 | case IrOpcode::kWord64Equal: |
| 958 | return VisitWord64Equal(node); |
| 959 | case IrOpcode::kInt32Add: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 960 | return MarkAsWord32(node), VisitInt32Add(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 961 | case IrOpcode::kInt32AddWithOverflow: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 962 | return MarkAsWord32(node), VisitInt32AddWithOverflow(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 963 | case IrOpcode::kInt32Sub: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 964 | return MarkAsWord32(node), VisitInt32Sub(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 965 | case IrOpcode::kInt32SubWithOverflow: |
| 966 | return VisitInt32SubWithOverflow(node); |
| 967 | case IrOpcode::kInt32Mul: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 968 | return MarkAsWord32(node), VisitInt32Mul(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 969 | case IrOpcode::kInt32MulHigh: |
| 970 | return VisitInt32MulHigh(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 971 | case IrOpcode::kInt32Div: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 972 | return MarkAsWord32(node), VisitInt32Div(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 973 | case IrOpcode::kInt32Mod: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 974 | return MarkAsWord32(node), VisitInt32Mod(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 975 | case IrOpcode::kInt32LessThan: |
| 976 | return VisitInt32LessThan(node); |
| 977 | case IrOpcode::kInt32LessThanOrEqual: |
| 978 | return VisitInt32LessThanOrEqual(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 979 | case IrOpcode::kUint32Div: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 980 | return MarkAsWord32(node), VisitUint32Div(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 981 | case IrOpcode::kUint32LessThan: |
| 982 | return VisitUint32LessThan(node); |
| 983 | case IrOpcode::kUint32LessThanOrEqual: |
| 984 | return VisitUint32LessThanOrEqual(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 985 | case IrOpcode::kUint32Mod: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 986 | return MarkAsWord32(node), VisitUint32Mod(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 987 | case IrOpcode::kUint32MulHigh: |
| 988 | return VisitUint32MulHigh(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 989 | case IrOpcode::kInt64Add: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 990 | return MarkAsWord64(node), VisitInt64Add(node); |
| 991 | case IrOpcode::kInt64AddWithOverflow: |
| 992 | return MarkAsWord64(node), VisitInt64AddWithOverflow(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 993 | case IrOpcode::kInt64Sub: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 994 | return MarkAsWord64(node), VisitInt64Sub(node); |
| 995 | case IrOpcode::kInt64SubWithOverflow: |
| 996 | return MarkAsWord64(node), VisitInt64SubWithOverflow(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 997 | case IrOpcode::kInt64Mul: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 998 | return MarkAsWord64(node), VisitInt64Mul(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 999 | case IrOpcode::kInt64Div: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1000 | return MarkAsWord64(node), VisitInt64Div(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | case IrOpcode::kInt64Mod: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1002 | return MarkAsWord64(node), VisitInt64Mod(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | case IrOpcode::kInt64LessThan: |
| 1004 | return VisitInt64LessThan(node); |
| 1005 | case IrOpcode::kInt64LessThanOrEqual: |
| 1006 | return VisitInt64LessThanOrEqual(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1007 | case IrOpcode::kUint64Div: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1008 | return MarkAsWord64(node), VisitUint64Div(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1009 | case IrOpcode::kUint64LessThan: |
| 1010 | return VisitUint64LessThan(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1011 | case IrOpcode::kUint64LessThanOrEqual: |
| 1012 | return VisitUint64LessThanOrEqual(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1013 | case IrOpcode::kUint64Mod: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1014 | return MarkAsWord64(node), VisitUint64Mod(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1015 | case IrOpcode::kChangeFloat32ToFloat64: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1016 | return MarkAsFloat64(node), VisitChangeFloat32ToFloat64(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1017 | case IrOpcode::kChangeInt32ToFloat64: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1018 | return MarkAsFloat64(node), VisitChangeInt32ToFloat64(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1019 | case IrOpcode::kChangeUint32ToFloat64: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1020 | return MarkAsFloat64(node), VisitChangeUint32ToFloat64(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1021 | case IrOpcode::kChangeFloat64ToInt32: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1022 | return MarkAsWord32(node), VisitChangeFloat64ToInt32(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1023 | case IrOpcode::kChangeFloat64ToUint32: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1024 | return MarkAsWord32(node), VisitChangeFloat64ToUint32(node); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1025 | case IrOpcode::kTruncateFloat64ToUint32: |
| 1026 | return MarkAsWord32(node), VisitTruncateFloat64ToUint32(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1027 | case IrOpcode::kTruncateFloat32ToInt32: |
| 1028 | return MarkAsWord32(node), VisitTruncateFloat32ToInt32(node); |
| 1029 | case IrOpcode::kTruncateFloat32ToUint32: |
| 1030 | return MarkAsWord32(node), VisitTruncateFloat32ToUint32(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1031 | case IrOpcode::kTryTruncateFloat32ToInt64: |
| 1032 | return MarkAsWord64(node), VisitTryTruncateFloat32ToInt64(node); |
| 1033 | case IrOpcode::kTryTruncateFloat64ToInt64: |
| 1034 | return MarkAsWord64(node), VisitTryTruncateFloat64ToInt64(node); |
| 1035 | case IrOpcode::kTryTruncateFloat32ToUint64: |
| 1036 | return MarkAsWord64(node), VisitTryTruncateFloat32ToUint64(node); |
| 1037 | case IrOpcode::kTryTruncateFloat64ToUint64: |
| 1038 | return MarkAsWord64(node), VisitTryTruncateFloat64ToUint64(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1039 | case IrOpcode::kChangeInt32ToInt64: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1040 | return MarkAsWord64(node), VisitChangeInt32ToInt64(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1041 | case IrOpcode::kChangeUint32ToUint64: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1042 | return MarkAsWord64(node), VisitChangeUint32ToUint64(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1043 | case IrOpcode::kTruncateFloat64ToFloat32: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1044 | return MarkAsFloat32(node), VisitTruncateFloat64ToFloat32(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1045 | case IrOpcode::kTruncateFloat64ToInt32: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1046 | return MarkAsWord32(node), VisitTruncateFloat64ToInt32(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1047 | case IrOpcode::kTruncateInt64ToInt32: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1048 | return MarkAsWord32(node), VisitTruncateInt64ToInt32(node); |
| 1049 | case IrOpcode::kRoundInt64ToFloat32: |
| 1050 | return MarkAsFloat32(node), VisitRoundInt64ToFloat32(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1051 | case IrOpcode::kRoundInt32ToFloat32: |
| 1052 | return MarkAsFloat32(node), VisitRoundInt32ToFloat32(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1053 | case IrOpcode::kRoundInt64ToFloat64: |
| 1054 | return MarkAsFloat64(node), VisitRoundInt64ToFloat64(node); |
| 1055 | case IrOpcode::kBitcastFloat32ToInt32: |
| 1056 | return MarkAsWord32(node), VisitBitcastFloat32ToInt32(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1057 | case IrOpcode::kRoundUint32ToFloat32: |
| 1058 | return MarkAsFloat32(node), VisitRoundUint32ToFloat32(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1059 | case IrOpcode::kRoundUint64ToFloat32: |
| 1060 | return MarkAsFloat64(node), VisitRoundUint64ToFloat32(node); |
| 1061 | case IrOpcode::kRoundUint64ToFloat64: |
| 1062 | return MarkAsFloat64(node), VisitRoundUint64ToFloat64(node); |
| 1063 | case IrOpcode::kBitcastFloat64ToInt64: |
| 1064 | return MarkAsWord64(node), VisitBitcastFloat64ToInt64(node); |
| 1065 | case IrOpcode::kBitcastInt32ToFloat32: |
| 1066 | return MarkAsFloat32(node), VisitBitcastInt32ToFloat32(node); |
| 1067 | case IrOpcode::kBitcastInt64ToFloat64: |
| 1068 | return MarkAsFloat64(node), VisitBitcastInt64ToFloat64(node); |
| 1069 | case IrOpcode::kFloat32Add: |
| 1070 | return MarkAsFloat32(node), VisitFloat32Add(node); |
| 1071 | case IrOpcode::kFloat32Sub: |
| 1072 | return MarkAsFloat32(node), VisitFloat32Sub(node); |
| 1073 | case IrOpcode::kFloat32Mul: |
| 1074 | return MarkAsFloat32(node), VisitFloat32Mul(node); |
| 1075 | case IrOpcode::kFloat32Div: |
| 1076 | return MarkAsFloat32(node), VisitFloat32Div(node); |
| 1077 | case IrOpcode::kFloat32Min: |
| 1078 | return MarkAsFloat32(node), VisitFloat32Min(node); |
| 1079 | case IrOpcode::kFloat32Max: |
| 1080 | return MarkAsFloat32(node), VisitFloat32Max(node); |
| 1081 | case IrOpcode::kFloat32Abs: |
| 1082 | return MarkAsFloat32(node), VisitFloat32Abs(node); |
| 1083 | case IrOpcode::kFloat32Sqrt: |
| 1084 | return MarkAsFloat32(node), VisitFloat32Sqrt(node); |
| 1085 | case IrOpcode::kFloat32Equal: |
| 1086 | return VisitFloat32Equal(node); |
| 1087 | case IrOpcode::kFloat32LessThan: |
| 1088 | return VisitFloat32LessThan(node); |
| 1089 | case IrOpcode::kFloat32LessThanOrEqual: |
| 1090 | return VisitFloat32LessThanOrEqual(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1091 | case IrOpcode::kFloat64Add: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1092 | return MarkAsFloat64(node), VisitFloat64Add(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1093 | case IrOpcode::kFloat64Sub: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1094 | return MarkAsFloat64(node), VisitFloat64Sub(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1095 | case IrOpcode::kFloat64Mul: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1096 | return MarkAsFloat64(node), VisitFloat64Mul(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1097 | case IrOpcode::kFloat64Div: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1098 | return MarkAsFloat64(node), VisitFloat64Div(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1099 | case IrOpcode::kFloat64Mod: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1100 | return MarkAsFloat64(node), VisitFloat64Mod(node); |
| 1101 | case IrOpcode::kFloat64Min: |
| 1102 | return MarkAsFloat64(node), VisitFloat64Min(node); |
| 1103 | case IrOpcode::kFloat64Max: |
| 1104 | return MarkAsFloat64(node), VisitFloat64Max(node); |
| 1105 | case IrOpcode::kFloat64Abs: |
| 1106 | return MarkAsFloat64(node), VisitFloat64Abs(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1107 | case IrOpcode::kFloat64Sqrt: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1108 | return MarkAsFloat64(node), VisitFloat64Sqrt(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1109 | case IrOpcode::kFloat64Equal: |
| 1110 | return VisitFloat64Equal(node); |
| 1111 | case IrOpcode::kFloat64LessThan: |
| 1112 | return VisitFloat64LessThan(node); |
| 1113 | case IrOpcode::kFloat64LessThanOrEqual: |
| 1114 | return VisitFloat64LessThanOrEqual(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1115 | case IrOpcode::kFloat32RoundDown: |
| 1116 | return MarkAsFloat32(node), VisitFloat32RoundDown(node); |
| 1117 | case IrOpcode::kFloat64RoundDown: |
| 1118 | return MarkAsFloat64(node), VisitFloat64RoundDown(node); |
| 1119 | case IrOpcode::kFloat32RoundUp: |
| 1120 | return MarkAsFloat32(node), VisitFloat32RoundUp(node); |
| 1121 | case IrOpcode::kFloat64RoundUp: |
| 1122 | return MarkAsFloat64(node), VisitFloat64RoundUp(node); |
| 1123 | case IrOpcode::kFloat32RoundTruncate: |
| 1124 | return MarkAsFloat32(node), VisitFloat32RoundTruncate(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1125 | case IrOpcode::kFloat64RoundTruncate: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1126 | return MarkAsFloat64(node), VisitFloat64RoundTruncate(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1127 | case IrOpcode::kFloat64RoundTiesAway: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1128 | return MarkAsFloat64(node), VisitFloat64RoundTiesAway(node); |
| 1129 | case IrOpcode::kFloat32RoundTiesEven: |
| 1130 | return MarkAsFloat32(node), VisitFloat32RoundTiesEven(node); |
| 1131 | case IrOpcode::kFloat64RoundTiesEven: |
| 1132 | return MarkAsFloat64(node), VisitFloat64RoundTiesEven(node); |
| 1133 | case IrOpcode::kFloat64ExtractLowWord32: |
| 1134 | return MarkAsWord32(node), VisitFloat64ExtractLowWord32(node); |
| 1135 | case IrOpcode::kFloat64ExtractHighWord32: |
| 1136 | return MarkAsWord32(node), VisitFloat64ExtractHighWord32(node); |
| 1137 | case IrOpcode::kFloat64InsertLowWord32: |
| 1138 | return MarkAsFloat64(node), VisitFloat64InsertLowWord32(node); |
| 1139 | case IrOpcode::kFloat64InsertHighWord32: |
| 1140 | return MarkAsFloat64(node), VisitFloat64InsertHighWord32(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1141 | case IrOpcode::kStackSlot: |
| 1142 | return VisitStackSlot(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1143 | case IrOpcode::kLoadStackPointer: |
| 1144 | return VisitLoadStackPointer(node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1145 | case IrOpcode::kLoadFramePointer: |
| 1146 | return VisitLoadFramePointer(node); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1147 | case IrOpcode::kLoadParentFramePointer: |
| 1148 | return VisitLoadParentFramePointer(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1149 | case IrOpcode::kCheckedLoad: { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1150 | MachineRepresentation rep = |
| 1151 | CheckedLoadRepresentationOf(node->op()).representation(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1152 | MarkAsRepresentation(rep, node); |
| 1153 | return VisitCheckedLoad(node); |
| 1154 | } |
| 1155 | case IrOpcode::kCheckedStore: |
| 1156 | return VisitCheckedStore(node); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1157 | case IrOpcode::kInt32PairAdd: |
| 1158 | MarkAsWord32(NodeProperties::FindProjection(node, 0)); |
| 1159 | MarkAsWord32(NodeProperties::FindProjection(node, 1)); |
| 1160 | return VisitInt32PairAdd(node); |
| 1161 | case IrOpcode::kInt32PairSub: |
| 1162 | MarkAsWord32(NodeProperties::FindProjection(node, 0)); |
| 1163 | MarkAsWord32(NodeProperties::FindProjection(node, 1)); |
| 1164 | return VisitInt32PairSub(node); |
| 1165 | case IrOpcode::kInt32PairMul: |
| 1166 | MarkAsWord32(NodeProperties::FindProjection(node, 0)); |
| 1167 | MarkAsWord32(NodeProperties::FindProjection(node, 1)); |
| 1168 | return VisitInt32PairMul(node); |
| 1169 | case IrOpcode::kWord32PairShl: |
| 1170 | MarkAsWord32(NodeProperties::FindProjection(node, 0)); |
| 1171 | MarkAsWord32(NodeProperties::FindProjection(node, 1)); |
| 1172 | return VisitWord32PairShl(node); |
| 1173 | case IrOpcode::kWord32PairShr: |
| 1174 | MarkAsWord32(NodeProperties::FindProjection(node, 0)); |
| 1175 | MarkAsWord32(NodeProperties::FindProjection(node, 1)); |
| 1176 | return VisitWord32PairShr(node); |
| 1177 | case IrOpcode::kWord32PairSar: |
| 1178 | MarkAsWord32(NodeProperties::FindProjection(node, 0)); |
| 1179 | MarkAsWord32(NodeProperties::FindProjection(node, 1)); |
| 1180 | return VisitWord32PairSar(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1181 | default: |
| 1182 | V8_Fatal(__FILE__, __LINE__, "Unexpected operator #%d:%s @ node #%d", |
| 1183 | node->opcode(), node->op()->mnemonic(), node->id()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1184 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1189 | void InstructionSelector::VisitLoadStackPointer(Node* node) { |
| 1190 | OperandGenerator g(this); |
| 1191 | Emit(kArchStackPointer, g.DefineAsRegister(node)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1194 | |
| 1195 | void InstructionSelector::VisitLoadFramePointer(Node* node) { |
| 1196 | OperandGenerator g(this); |
| 1197 | Emit(kArchFramePointer, g.DefineAsRegister(node)); |
| 1198 | } |
| 1199 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1200 | void InstructionSelector::VisitLoadParentFramePointer(Node* node) { |
| 1201 | OperandGenerator g(this); |
| 1202 | Emit(kArchParentFramePointer, g.DefineAsRegister(node)); |
| 1203 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1204 | |
| 1205 | void InstructionSelector::EmitTableSwitch(const SwitchInfo& sw, |
| 1206 | InstructionOperand& index_operand) { |
| 1207 | OperandGenerator g(this); |
| 1208 | size_t input_count = 2 + sw.value_range; |
| 1209 | auto* inputs = zone()->NewArray<InstructionOperand>(input_count); |
| 1210 | inputs[0] = index_operand; |
| 1211 | InstructionOperand default_operand = g.Label(sw.default_branch); |
| 1212 | std::fill(&inputs[1], &inputs[input_count], default_operand); |
| 1213 | for (size_t index = 0; index < sw.case_count; ++index) { |
| 1214 | size_t value = sw.case_values[index] - sw.min_value; |
| 1215 | BasicBlock* branch = sw.case_branches[index]; |
| 1216 | DCHECK_LE(0u, value); |
| 1217 | DCHECK_LT(value + 2, input_count); |
| 1218 | inputs[value + 2] = g.Label(branch); |
| 1219 | } |
| 1220 | Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr); |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | void InstructionSelector::EmitLookupSwitch(const SwitchInfo& sw, |
| 1225 | InstructionOperand& value_operand) { |
| 1226 | OperandGenerator g(this); |
| 1227 | size_t input_count = 2 + sw.case_count * 2; |
| 1228 | auto* inputs = zone()->NewArray<InstructionOperand>(input_count); |
| 1229 | inputs[0] = value_operand; |
| 1230 | inputs[1] = g.Label(sw.default_branch); |
| 1231 | for (size_t index = 0; index < sw.case_count; ++index) { |
| 1232 | int32_t value = sw.case_values[index]; |
| 1233 | BasicBlock* branch = sw.case_branches[index]; |
| 1234 | inputs[index * 2 + 2 + 0] = g.TempImmediate(value); |
| 1235 | inputs[index * 2 + 2 + 1] = g.Label(branch); |
| 1236 | } |
| 1237 | Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr); |
| 1238 | } |
| 1239 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1240 | void InstructionSelector::VisitStackSlot(Node* node) { |
| 1241 | int size = 1 << ElementSizeLog2Of(StackSlotRepresentationOf(node->op())); |
| 1242 | int slot = frame_->AllocateSpillSlot(size); |
| 1243 | OperandGenerator g(this); |
| 1244 | |
| 1245 | Emit(kArchStackSlot, g.DefineAsRegister(node), |
| 1246 | sequence()->AddImmediate(Constant(slot)), 0, nullptr); |
| 1247 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1248 | |
| 1249 | // 32 bit targets do not implement the following instructions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1250 | #if V8_TARGET_ARCH_32_BIT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1251 | |
| 1252 | void InstructionSelector::VisitWord64And(Node* node) { UNIMPLEMENTED(); } |
| 1253 | |
| 1254 | |
| 1255 | void InstructionSelector::VisitWord64Or(Node* node) { UNIMPLEMENTED(); } |
| 1256 | |
| 1257 | |
| 1258 | void InstructionSelector::VisitWord64Xor(Node* node) { UNIMPLEMENTED(); } |
| 1259 | |
| 1260 | |
| 1261 | void InstructionSelector::VisitWord64Shl(Node* node) { UNIMPLEMENTED(); } |
| 1262 | |
| 1263 | |
| 1264 | void InstructionSelector::VisitWord64Shr(Node* node) { UNIMPLEMENTED(); } |
| 1265 | |
| 1266 | |
| 1267 | void InstructionSelector::VisitWord64Sar(Node* node) { UNIMPLEMENTED(); } |
| 1268 | |
| 1269 | |
| 1270 | void InstructionSelector::VisitWord64Ror(Node* node) { UNIMPLEMENTED(); } |
| 1271 | |
| 1272 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1273 | void InstructionSelector::VisitWord64Clz(Node* node) { UNIMPLEMENTED(); } |
| 1274 | |
| 1275 | |
| 1276 | void InstructionSelector::VisitWord64Ctz(Node* node) { UNIMPLEMENTED(); } |
| 1277 | |
| 1278 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1279 | void InstructionSelector::VisitWord64ReverseBits(Node* node) { |
| 1280 | UNIMPLEMENTED(); |
| 1281 | } |
| 1282 | |
| 1283 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1284 | void InstructionSelector::VisitWord64Popcnt(Node* node) { UNIMPLEMENTED(); } |
| 1285 | |
| 1286 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1287 | void InstructionSelector::VisitWord64Equal(Node* node) { UNIMPLEMENTED(); } |
| 1288 | |
| 1289 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1290 | void InstructionSelector::VisitInt64Add(Node* node) { UNIMPLEMENTED(); } |
| 1291 | |
| 1292 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1293 | void InstructionSelector::VisitInt64AddWithOverflow(Node* node) { |
| 1294 | UNIMPLEMENTED(); |
| 1295 | } |
| 1296 | |
| 1297 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1298 | void InstructionSelector::VisitInt64Sub(Node* node) { UNIMPLEMENTED(); } |
| 1299 | |
| 1300 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1301 | void InstructionSelector::VisitInt64SubWithOverflow(Node* node) { |
| 1302 | UNIMPLEMENTED(); |
| 1303 | } |
| 1304 | |
| 1305 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1306 | void InstructionSelector::VisitInt64Mul(Node* node) { UNIMPLEMENTED(); } |
| 1307 | |
| 1308 | |
| 1309 | void InstructionSelector::VisitInt64Div(Node* node) { UNIMPLEMENTED(); } |
| 1310 | |
| 1311 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1312 | void InstructionSelector::VisitInt64LessThan(Node* node) { UNIMPLEMENTED(); } |
| 1313 | |
| 1314 | |
| 1315 | void InstructionSelector::VisitInt64LessThanOrEqual(Node* node) { |
| 1316 | UNIMPLEMENTED(); |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | void InstructionSelector::VisitUint64Div(Node* node) { UNIMPLEMENTED(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1321 | |
| 1322 | |
| 1323 | void InstructionSelector::VisitInt64Mod(Node* node) { UNIMPLEMENTED(); } |
| 1324 | |
| 1325 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1326 | void InstructionSelector::VisitUint64LessThan(Node* node) { UNIMPLEMENTED(); } |
| 1327 | |
| 1328 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1329 | void InstructionSelector::VisitUint64LessThanOrEqual(Node* node) { |
| 1330 | UNIMPLEMENTED(); |
| 1331 | } |
| 1332 | |
| 1333 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1334 | void InstructionSelector::VisitUint64Mod(Node* node) { UNIMPLEMENTED(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1335 | |
| 1336 | |
| 1337 | void InstructionSelector::VisitChangeInt32ToInt64(Node* node) { |
| 1338 | UNIMPLEMENTED(); |
| 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | void InstructionSelector::VisitChangeUint32ToUint64(Node* node) { |
| 1343 | UNIMPLEMENTED(); |
| 1344 | } |
| 1345 | |
| 1346 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1347 | void InstructionSelector::VisitTryTruncateFloat32ToInt64(Node* node) { |
| 1348 | UNIMPLEMENTED(); |
| 1349 | } |
| 1350 | |
| 1351 | |
| 1352 | void InstructionSelector::VisitTryTruncateFloat64ToInt64(Node* node) { |
| 1353 | UNIMPLEMENTED(); |
| 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | void InstructionSelector::VisitTryTruncateFloat32ToUint64(Node* node) { |
| 1358 | UNIMPLEMENTED(); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | void InstructionSelector::VisitTryTruncateFloat64ToUint64(Node* node) { |
| 1363 | UNIMPLEMENTED(); |
| 1364 | } |
| 1365 | |
| 1366 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1367 | void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) { |
| 1368 | UNIMPLEMENTED(); |
| 1369 | } |
| 1370 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1371 | |
| 1372 | void InstructionSelector::VisitRoundInt64ToFloat32(Node* node) { |
| 1373 | UNIMPLEMENTED(); |
| 1374 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1375 | |
| 1376 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1377 | void InstructionSelector::VisitRoundInt64ToFloat64(Node* node) { |
| 1378 | UNIMPLEMENTED(); |
| 1379 | } |
| 1380 | |
| 1381 | |
| 1382 | void InstructionSelector::VisitRoundUint64ToFloat32(Node* node) { |
| 1383 | UNIMPLEMENTED(); |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | void InstructionSelector::VisitRoundUint64ToFloat64(Node* node) { |
| 1388 | UNIMPLEMENTED(); |
| 1389 | } |
| 1390 | |
| 1391 | |
| 1392 | void InstructionSelector::VisitBitcastFloat64ToInt64(Node* node) { |
| 1393 | UNIMPLEMENTED(); |
| 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | void InstructionSelector::VisitBitcastInt64ToFloat64(Node* node) { |
| 1398 | UNIMPLEMENTED(); |
| 1399 | } |
| 1400 | |
| 1401 | #endif // V8_TARGET_ARCH_32_BIT |
| 1402 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1403 | // 64 bit targets do not implement the following instructions. |
| 1404 | #if V8_TARGET_ARCH_64_BIT |
| 1405 | void InstructionSelector::VisitInt32PairAdd(Node* node) { UNIMPLEMENTED(); } |
| 1406 | |
| 1407 | void InstructionSelector::VisitInt32PairSub(Node* node) { UNIMPLEMENTED(); } |
| 1408 | |
| 1409 | void InstructionSelector::VisitInt32PairMul(Node* node) { UNIMPLEMENTED(); } |
| 1410 | |
| 1411 | void InstructionSelector::VisitWord32PairShl(Node* node) { UNIMPLEMENTED(); } |
| 1412 | |
| 1413 | void InstructionSelector::VisitWord32PairShr(Node* node) { UNIMPLEMENTED(); } |
| 1414 | |
| 1415 | void InstructionSelector::VisitWord32PairSar(Node* node) { UNIMPLEMENTED(); } |
| 1416 | #endif // V8_TARGET_ARCH_64_BIT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1417 | |
| 1418 | void InstructionSelector::VisitFinishRegion(Node* node) { |
| 1419 | OperandGenerator g(this); |
| 1420 | Node* value = node->InputAt(0); |
| 1421 | Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value)); |
| 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | void InstructionSelector::VisitGuard(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1426 | OperandGenerator g(this); |
| 1427 | Node* value = node->InputAt(0); |
| 1428 | Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value)); |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | void InstructionSelector::VisitParameter(Node* node) { |
| 1433 | OperandGenerator g(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1434 | int index = ParameterIndexOf(node->op()); |
| 1435 | InstructionOperand op = |
| 1436 | linkage()->ParameterHasSecondaryLocation(index) |
| 1437 | ? g.DefineAsDualLocation( |
| 1438 | node, linkage()->GetParameterLocation(index), |
| 1439 | linkage()->GetParameterSecondaryLocation(index)) |
| 1440 | : g.DefineAsLocation( |
| 1441 | node, linkage()->GetParameterLocation(index), |
| 1442 | linkage()->GetParameterType(index).representation()); |
| 1443 | |
| 1444 | Emit(kArchNop, op); |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | void InstructionSelector::VisitIfException(Node* node) { |
| 1449 | OperandGenerator g(this); |
| 1450 | Node* call = node->InputAt(1); |
| 1451 | DCHECK_EQ(IrOpcode::kCall, call->opcode()); |
| 1452 | const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1453 | Emit(kArchNop, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1454 | g.DefineAsLocation(node, descriptor->GetReturnLocation(0), |
| 1455 | descriptor->GetReturnType(0).representation())); |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | void InstructionSelector::VisitOsrValue(Node* node) { |
| 1460 | OperandGenerator g(this); |
| 1461 | int index = OpParameter<int>(node); |
| 1462 | Emit(kArchNop, g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index), |
| 1463 | MachineRepresentation::kTagged)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | |
| 1467 | void InstructionSelector::VisitPhi(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1468 | const int input_count = node->op()->ValueInputCount(); |
| 1469 | PhiInstruction* phi = new (instruction_zone()) |
| 1470 | PhiInstruction(instruction_zone(), GetVirtualRegister(node), |
| 1471 | static_cast<size_t>(input_count)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1472 | sequence() |
| 1473 | ->InstructionBlockAt(RpoNumber::FromInt(current_block_->rpo_number())) |
| 1474 | ->AddPhi(phi); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1475 | for (int i = 0; i < input_count; ++i) { |
| 1476 | Node* const input = node->InputAt(i); |
| 1477 | MarkAsUsed(input); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1478 | phi->SetInput(static_cast<size_t>(i), GetVirtualRegister(input)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | void InstructionSelector::VisitProjection(Node* node) { |
| 1484 | OperandGenerator g(this); |
| 1485 | Node* value = node->InputAt(0); |
| 1486 | switch (value->opcode()) { |
| 1487 | case IrOpcode::kInt32AddWithOverflow: |
| 1488 | case IrOpcode::kInt32SubWithOverflow: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1489 | case IrOpcode::kInt64AddWithOverflow: |
| 1490 | case IrOpcode::kInt64SubWithOverflow: |
| 1491 | case IrOpcode::kTryTruncateFloat32ToInt64: |
| 1492 | case IrOpcode::kTryTruncateFloat64ToInt64: |
| 1493 | case IrOpcode::kTryTruncateFloat32ToUint64: |
| 1494 | case IrOpcode::kTryTruncateFloat64ToUint64: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1495 | case IrOpcode::kInt32PairAdd: |
| 1496 | case IrOpcode::kInt32PairSub: |
| 1497 | case IrOpcode::kInt32PairMul: |
| 1498 | case IrOpcode::kWord32PairShl: |
| 1499 | case IrOpcode::kWord32PairShr: |
| 1500 | case IrOpcode::kWord32PairSar: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1501 | if (ProjectionIndexOf(node->op()) == 0u) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1502 | Emit(kArchNop, g.DefineSameAsFirst(node), g.Use(value)); |
| 1503 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1504 | DCHECK(ProjectionIndexOf(node->op()) == 1u); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1505 | MarkAsUsed(value); |
| 1506 | } |
| 1507 | break; |
| 1508 | default: |
| 1509 | break; |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | void InstructionSelector::VisitConstant(Node* node) { |
| 1515 | // We must emit a NOP here because every live range needs a defining |
| 1516 | // instruction in the register allocator. |
| 1517 | OperandGenerator g(this); |
| 1518 | Emit(kArchNop, g.DefineAsConstant(node)); |
| 1519 | } |
| 1520 | |
| 1521 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1522 | void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1523 | OperandGenerator g(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1524 | const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node); |
| 1525 | |
| 1526 | FrameStateDescriptor* frame_state_descriptor = nullptr; |
| 1527 | if (descriptor->NeedsFrameState()) { |
| 1528 | frame_state_descriptor = GetFrameStateDescriptor( |
| 1529 | node->InputAt(static_cast<int>(descriptor->InputCount()))); |
| 1530 | } |
| 1531 | |
| 1532 | CallBuffer buffer(zone(), descriptor, frame_state_descriptor); |
| 1533 | |
| 1534 | // Compute InstructionOperands for inputs and outputs. |
| 1535 | // TODO(turbofan): on some architectures it's probably better to use |
| 1536 | // the code object in a register if there are multiple uses of it. |
| 1537 | // Improve constant pool and the heuristics in the register allocator |
| 1538 | // for where to emit constants. |
| 1539 | CallBufferFlags call_buffer_flags(kCallCodeImmediate | kCallAddressImmediate); |
| 1540 | InitializeCallBuffer(node, &buffer, call_buffer_flags); |
| 1541 | |
| 1542 | EmitPrepareArguments(&(buffer.pushed_nodes), descriptor, node); |
| 1543 | |
| 1544 | // Pass label of exception handler block. |
| 1545 | CallDescriptor::Flags flags = descriptor->flags(); |
| 1546 | if (handler) { |
| 1547 | DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); |
| 1548 | IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); |
| 1549 | if (hint == IfExceptionHint::kLocallyCaught) { |
| 1550 | flags |= CallDescriptor::kHasLocalCatchHandler; |
| 1551 | } |
| 1552 | flags |= CallDescriptor::kHasExceptionHandler; |
| 1553 | buffer.instruction_args.push_back(g.Label(handler)); |
| 1554 | } |
| 1555 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1556 | bool from_native_stack = linkage()->GetIncomingDescriptor()->UseNativeStack(); |
| 1557 | bool to_native_stack = descriptor->UseNativeStack(); |
| 1558 | if (from_native_stack != to_native_stack) { |
| 1559 | // (arm64 only) Mismatch in the use of stack pointers. One or the other |
| 1560 | // has to be restored manually by the code generator. |
| 1561 | flags |= to_native_stack ? CallDescriptor::kRestoreJSSP |
| 1562 | : CallDescriptor::kRestoreCSP; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1565 | // Select the appropriate opcode based on the call type. |
| 1566 | InstructionCode opcode = kArchNop; |
| 1567 | switch (descriptor->kind()) { |
| 1568 | case CallDescriptor::kCallAddress: |
| 1569 | opcode = |
| 1570 | kArchCallCFunction | |
| 1571 | MiscField::encode(static_cast<int>(descriptor->CParameterCount())); |
| 1572 | break; |
| 1573 | case CallDescriptor::kCallCodeObject: |
| 1574 | opcode = kArchCallCodeObject | MiscField::encode(flags); |
| 1575 | break; |
| 1576 | case CallDescriptor::kCallJSFunction: |
| 1577 | opcode = kArchCallJSFunction | MiscField::encode(flags); |
| 1578 | break; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | // Emit the call instruction. |
| 1582 | size_t const output_count = buffer.outputs.size(); |
| 1583 | auto* outputs = output_count ? &buffer.outputs.front() : nullptr; |
| 1584 | Emit(opcode, output_count, outputs, buffer.instruction_args.size(), |
| 1585 | &buffer.instruction_args.front()) |
| 1586 | ->MarkAsCall(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1590 | void InstructionSelector::VisitTailCall(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1591 | OperandGenerator g(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1592 | CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node); |
| 1593 | DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls); |
| 1594 | DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite); |
| 1595 | DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall); |
| 1596 | |
| 1597 | // TODO(turbofan): Relax restriction for stack parameters. |
| 1598 | |
| 1599 | int stack_param_delta = 0; |
| 1600 | if (linkage()->GetIncomingDescriptor()->CanTailCall(node, |
| 1601 | &stack_param_delta)) { |
| 1602 | CallBuffer buffer(zone(), descriptor, nullptr); |
| 1603 | |
| 1604 | // Compute InstructionOperands for inputs and outputs. |
| 1605 | CallBufferFlags flags(kCallCodeImmediate | kCallTail); |
| 1606 | if (IsTailCallAddressImmediate()) { |
| 1607 | flags |= kCallAddressImmediate; |
| 1608 | } |
| 1609 | InitializeCallBuffer(node, &buffer, flags, stack_param_delta); |
| 1610 | |
| 1611 | // Select the appropriate opcode based on the call type. |
| 1612 | InstructionCode opcode; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1613 | InstructionOperandVector temps(zone()); |
| 1614 | if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { |
| 1615 | switch (descriptor->kind()) { |
| 1616 | case CallDescriptor::kCallCodeObject: |
| 1617 | opcode = kArchTailCallCodeObjectFromJSFunction; |
| 1618 | break; |
| 1619 | case CallDescriptor::kCallJSFunction: |
| 1620 | opcode = kArchTailCallJSFunctionFromJSFunction; |
| 1621 | break; |
| 1622 | default: |
| 1623 | UNREACHABLE(); |
| 1624 | return; |
| 1625 | } |
| 1626 | int temps_count = GetTempsCountForTailCallFromJSFunction(); |
| 1627 | for (int i = 0; i < temps_count; i++) { |
| 1628 | temps.push_back(g.TempRegister()); |
| 1629 | } |
| 1630 | } else { |
| 1631 | switch (descriptor->kind()) { |
| 1632 | case CallDescriptor::kCallCodeObject: |
| 1633 | opcode = kArchTailCallCodeObject; |
| 1634 | break; |
| 1635 | case CallDescriptor::kCallJSFunction: |
| 1636 | opcode = kArchTailCallJSFunction; |
| 1637 | break; |
| 1638 | default: |
| 1639 | UNREACHABLE(); |
| 1640 | return; |
| 1641 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1642 | } |
| 1643 | opcode |= MiscField::encode(descriptor->flags()); |
| 1644 | |
| 1645 | buffer.instruction_args.push_back(g.TempImmediate(stack_param_delta)); |
| 1646 | |
| 1647 | Emit(kArchPrepareTailCall, g.NoOutput(), |
| 1648 | g.TempImmediate(stack_param_delta)); |
| 1649 | |
| 1650 | // Emit the tailcall instruction. |
| 1651 | Emit(opcode, 0, nullptr, buffer.instruction_args.size(), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1652 | &buffer.instruction_args.front(), temps.size(), |
| 1653 | temps.empty() ? nullptr : &temps.front()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1654 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1655 | FrameStateDescriptor* frame_state_descriptor = |
| 1656 | descriptor->NeedsFrameState() |
| 1657 | ? GetFrameStateDescriptor( |
| 1658 | node->InputAt(static_cast<int>(descriptor->InputCount()))) |
| 1659 | : nullptr; |
| 1660 | |
| 1661 | CallBuffer buffer(zone(), descriptor, frame_state_descriptor); |
| 1662 | |
| 1663 | // Compute InstructionOperands for inputs and outputs. |
| 1664 | CallBufferFlags flags = kCallCodeImmediate; |
| 1665 | if (IsTailCallAddressImmediate()) { |
| 1666 | flags |= kCallAddressImmediate; |
| 1667 | } |
| 1668 | InitializeCallBuffer(node, &buffer, flags); |
| 1669 | |
| 1670 | EmitPrepareArguments(&(buffer.pushed_nodes), descriptor, node); |
| 1671 | |
| 1672 | // Select the appropriate opcode based on the call type. |
| 1673 | InstructionCode opcode; |
| 1674 | switch (descriptor->kind()) { |
| 1675 | case CallDescriptor::kCallCodeObject: |
| 1676 | opcode = kArchCallCodeObject; |
| 1677 | break; |
| 1678 | case CallDescriptor::kCallJSFunction: |
| 1679 | opcode = kArchCallJSFunction; |
| 1680 | break; |
| 1681 | default: |
| 1682 | UNREACHABLE(); |
| 1683 | return; |
| 1684 | } |
| 1685 | opcode |= MiscField::encode(descriptor->flags()); |
| 1686 | |
| 1687 | // Emit the call instruction. |
| 1688 | size_t output_count = buffer.outputs.size(); |
| 1689 | auto* outputs = &buffer.outputs.front(); |
| 1690 | Emit(opcode, output_count, outputs, buffer.instruction_args.size(), |
| 1691 | &buffer.instruction_args.front()) |
| 1692 | ->MarkAsCall(); |
| 1693 | Emit(kArchRet, 0, nullptr, output_count, outputs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1698 | void InstructionSelector::VisitGoto(BasicBlock* target) { |
| 1699 | // jump to the next block. |
| 1700 | OperandGenerator g(this); |
| 1701 | Emit(kArchJmp, g.NoOutput(), g.Label(target)); |
| 1702 | } |
| 1703 | |
| 1704 | |
| 1705 | void InstructionSelector::VisitReturn(Node* ret) { |
| 1706 | OperandGenerator g(this); |
| 1707 | if (linkage()->GetIncomingDescriptor()->ReturnCount() == 0) { |
| 1708 | Emit(kArchRet, g.NoOutput()); |
| 1709 | } else { |
| 1710 | const int ret_count = ret->op()->ValueInputCount(); |
| 1711 | auto value_locations = zone()->NewArray<InstructionOperand>(ret_count); |
| 1712 | for (int i = 0; i < ret_count; ++i) { |
| 1713 | value_locations[i] = |
| 1714 | g.UseLocation(ret->InputAt(i), linkage()->GetReturnLocation(i), |
| 1715 | linkage()->GetReturnType(i).representation()); |
| 1716 | } |
| 1717 | Emit(kArchRet, 0, nullptr, ret_count, value_locations); |
| 1718 | } |
| 1719 | } |
| 1720 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1721 | Instruction* InstructionSelector::EmitDeoptimize(InstructionCode opcode, |
| 1722 | InstructionOperand output, |
| 1723 | InstructionOperand a, |
| 1724 | InstructionOperand b, |
| 1725 | Node* frame_state) { |
| 1726 | size_t output_count = output.IsInvalid() ? 0 : 1; |
| 1727 | InstructionOperand inputs[] = {a, b}; |
| 1728 | size_t input_count = arraysize(inputs); |
| 1729 | return EmitDeoptimize(opcode, output_count, &output, input_count, inputs, |
| 1730 | frame_state); |
| 1731 | } |
| 1732 | |
| 1733 | Instruction* InstructionSelector::EmitDeoptimize( |
| 1734 | InstructionCode opcode, size_t output_count, InstructionOperand* outputs, |
| 1735 | size_t input_count, InstructionOperand* inputs, Node* frame_state) { |
| 1736 | OperandGenerator g(this); |
| 1737 | FrameStateDescriptor* const descriptor = GetFrameStateDescriptor(frame_state); |
| 1738 | InstructionOperandVector args(instruction_zone()); |
| 1739 | args.reserve(input_count + 1 + descriptor->GetTotalSize()); |
| 1740 | for (size_t i = 0; i < input_count; ++i) { |
| 1741 | args.push_back(inputs[i]); |
| 1742 | } |
| 1743 | opcode |= MiscField::encode(static_cast<int>(input_count)); |
| 1744 | InstructionSequence::StateId const state_id = |
| 1745 | sequence()->AddFrameStateDescriptor(descriptor); |
| 1746 | args.push_back(g.TempImmediate(state_id.ToInt())); |
| 1747 | StateObjectDeduplicator deduplicator(instruction_zone()); |
| 1748 | AddInputsToFrameStateDescriptor(descriptor, frame_state, &g, &deduplicator, |
| 1749 | &args, FrameStateInputKind::kAny, |
| 1750 | instruction_zone()); |
| 1751 | return Emit(opcode, output_count, outputs, args.size(), &args.front(), 0, |
| 1752 | nullptr); |
| 1753 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1754 | |
| 1755 | void InstructionSelector::VisitDeoptimize(DeoptimizeKind kind, Node* value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1756 | InstructionCode opcode = kArchDeoptimize; |
| 1757 | switch (kind) { |
| 1758 | case DeoptimizeKind::kEager: |
| 1759 | opcode |= MiscField::encode(Deoptimizer::EAGER); |
| 1760 | break; |
| 1761 | case DeoptimizeKind::kSoft: |
| 1762 | opcode |= MiscField::encode(Deoptimizer::SOFT); |
| 1763 | break; |
| 1764 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1765 | EmitDeoptimize(opcode, 0, nullptr, 0, nullptr, value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1769 | void InstructionSelector::VisitThrow(Node* value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1770 | OperandGenerator g(this); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1771 | Emit(kArchThrowTerminator, g.NoOutput()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1775 | FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor( |
| 1776 | Node* state) { |
| 1777 | DCHECK(state->opcode() == IrOpcode::kFrameState); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1778 | DCHECK_EQ(kFrameStateInputCount, state->InputCount()); |
| 1779 | FrameStateInfo state_info = OpParameter<FrameStateInfo>(state); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1780 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1781 | int parameters = static_cast<int>( |
| 1782 | StateValuesAccess(state->InputAt(kFrameStateParametersInput)).size()); |
| 1783 | int locals = static_cast<int>( |
| 1784 | StateValuesAccess(state->InputAt(kFrameStateLocalsInput)).size()); |
| 1785 | int stack = static_cast<int>( |
| 1786 | StateValuesAccess(state->InputAt(kFrameStateStackInput)).size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1787 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1788 | DCHECK_EQ(parameters, state_info.parameter_count()); |
| 1789 | DCHECK_EQ(locals, state_info.local_count()); |
| 1790 | |
| 1791 | FrameStateDescriptor* outer_state = nullptr; |
| 1792 | Node* outer_node = state->InputAt(kFrameStateOuterStateInput); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1793 | if (outer_node->opcode() == IrOpcode::kFrameState) { |
| 1794 | outer_state = GetFrameStateDescriptor(outer_node); |
| 1795 | } |
| 1796 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1797 | return new (instruction_zone()) FrameStateDescriptor( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1798 | instruction_zone(), state_info.type(), state_info.bailout_id(), |
| 1799 | state_info.state_combine(), parameters, locals, stack, |
| 1800 | state_info.shared_info(), outer_state); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1804 | } // namespace compiler |
| 1805 | } // namespace internal |
| 1806 | } // namespace v8 |