instruction-selector-unittest.cc 22.9 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "test/unittests/compiler/instruction-selector-unittest.h"
6

7
#include "src/code-factory.h"
8
#include "src/compiler/graph.h"
9
#include "src/compiler/schedule.h"
10
#include "src/flags.h"
11
#include "test/unittests/compiler/compiler-test-utils.h"
12

13 14 15 16
namespace v8 {
namespace internal {
namespace compiler {

17

18 19 20
InstructionSelectorTest::InstructionSelectorTest() : rng_(FLAG_random_seed) {}


21 22 23
InstructionSelectorTest::~InstructionSelectorTest() {}


24 25
InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
    InstructionSelector::Features features,
26 27
    InstructionSelectorTest::StreamBuilderMode mode,
    InstructionSelector::SourcePositionMode source_position_mode) {
28
  Schedule* schedule = Export();
29 30
  if (FLAG_trace_turbo) {
    OFStream out(stdout);
31 32
    out << "=== Schedule before instruction selection ===" << std::endl
        << *schedule;
33
  }
34 35
  size_t const node_count = graph()->NodeCount();
  EXPECT_NE(0u, node_count);
36
  Linkage linkage(call_descriptor());
37 38
  InstructionBlocks* instruction_blocks =
      InstructionSequence::InstructionBlocksFor(test_->zone(), schedule);
39 40
  InstructionSequence sequence(test_->isolate(), test_->zone(),
                               instruction_blocks);
41
  SourcePositionTable source_position_table(graph());
42
  InstructionSelector selector(test_->zone(), node_count, &linkage, &sequence,
43
                               schedule, &source_position_table, nullptr,
44 45
                               source_position_mode, features,
                               InstructionSelector::kDisableScheduling);
46 47 48
  selector.SelectInstructions();
  if (FLAG_trace_turbo) {
    OFStream out(stdout);
49 50
    PrintableInstructionSequence printable = {RegisterConfiguration::Turbofan(),
                                              &sequence};
51
    out << "=== Code sequence after instruction selection ===" << std::endl
52
        << printable;
53 54
  }
  Stream s;
55
  s.virtual_registers_ = selector.GetVirtualRegistersForTesting();
56
  // Map virtual registers.
57
  for (Instruction* const instr : sequence) {
58 59 60 61 62 63 64 65 66 67 68 69
    if (instr->opcode() < 0) continue;
    if (mode == kTargetInstructions) {
      switch (instr->arch_opcode()) {
#define CASE(Name) \
  case k##Name:    \
    break;
        TARGET_ARCH_OPCODE_LIST(CASE)
#undef CASE
        default:
          continue;
      }
    }
70 71 72
    if (mode == kAllExceptNopInstructions && instr->arch_opcode() == kArchNop) {
      continue;
    }
73 74 75 76
    for (size_t i = 0; i < instr->OutputCount(); ++i) {
      InstructionOperand* output = instr->OutputAt(i);
      EXPECT_NE(InstructionOperand::IMMEDIATE, output->kind());
      if (output->IsConstant()) {
77 78
        int vreg = ConstantOperand::cast(output)->virtual_register();
        s.constants_.insert(std::make_pair(vreg, sequence.GetConstant(vreg)));
79 80 81 82 83 84
      }
    }
    for (size_t i = 0; i < instr->InputCount(); ++i) {
      InstructionOperand* input = instr->InputAt(i);
      EXPECT_NE(InstructionOperand::CONSTANT, input->kind());
      if (input->IsImmediate()) {
85 86 87 88 89 90
        auto imm = ImmediateOperand::cast(input);
        if (imm->type() == ImmediateOperand::INDEXED) {
          int index = imm->indexed_value();
          s.immediates_.insert(
              std::make_pair(index, sequence.GetImmediate(imm)));
        }
91 92 93 94
      }
    }
    s.instructions_.push_back(instr);
  }
95 96
  for (auto i : s.virtual_registers_) {
    int const virtual_register = i.second;
97
    if (sequence.IsFP(virtual_register)) {
98 99 100 101
      EXPECT_FALSE(sequence.IsReference(virtual_register));
      s.doubles_.insert(virtual_register);
    }
    if (sequence.IsReference(virtual_register)) {
102
      EXPECT_FALSE(sequence.IsFP(virtual_register));
103 104 105
      s.references_.insert(virtual_register);
    }
  }
106 107 108
  for (int i = 0; i < sequence.GetDeoptimizationEntryCount(); i++) {
    s.deoptimization_entries_.push_back(
        sequence.GetDeoptimizationEntry(i).descriptor());
109
  }
110 111 112 113
  return s;
}


114 115 116 117 118 119 120
int InstructionSelectorTest::Stream::ToVreg(const Node* node) const {
  VirtualRegisters::const_iterator i = virtual_registers_.find(node->id());
  CHECK(i != virtual_registers_.end());
  return i->second;
}


121 122 123 124 125
bool InstructionSelectorTest::Stream::IsFixed(const InstructionOperand* operand,
                                              Register reg) const {
  if (!operand->IsUnallocated()) return false;
  const UnallocatedOperand* unallocated = UnallocatedOperand::cast(operand);
  if (!unallocated->HasFixedRegisterPolicy()) return false;
126
  return unallocated->fixed_register_index() == reg.code();
127 128 129
}


130 131 132 133 134 135 136 137
bool InstructionSelectorTest::Stream::IsSameAsFirst(
    const InstructionOperand* operand) const {
  if (!operand->IsUnallocated()) return false;
  const UnallocatedOperand* unallocated = UnallocatedOperand::cast(operand);
  return unallocated->HasSameAsInputPolicy();
}


138 139 140 141 142 143 144 145
bool InstructionSelectorTest::Stream::IsUsedAtStart(
    const InstructionOperand* operand) const {
  if (!operand->IsUnallocated()) return false;
  const UnallocatedOperand* unallocated = UnallocatedOperand::cast(operand);
  return unallocated->IsUsedAtStart();
}


146 147 148 149 150
const FrameStateFunctionInfo*
InstructionSelectorTest::StreamBuilder::GetFrameStateFunctionInfo(
    int parameter_count, int local_count) {
  return common()->CreateFrameStateFunctionInfo(
      FrameStateType::kJavaScriptFunction, parameter_count, local_count,
151
      Handle<SharedFunctionInfo>());
152 153 154
}


155 156 157 158
// -----------------------------------------------------------------------------
// Return.


159 160
TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) {
  const float kValue = 4.2f;
161
  StreamBuilder m(this, MachineType::Float32());
162 163
  m.Return(m.Float32Constant(kValue));
  Stream s = m.Build(kAllInstructions);
164
  ASSERT_EQ(3U, s.size());
165 166 167 168 169 170 171 172
  EXPECT_EQ(kArchNop, s[0]->arch_opcode());
  ASSERT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind());
  EXPECT_FLOAT_EQ(kValue, s.ToFloat32(s[0]->OutputAt(0)));
  EXPECT_EQ(kArchRet, s[1]->arch_opcode());
  EXPECT_EQ(1U, s[1]->InputCount());
}


173
TARGET_TEST_F(InstructionSelectorTest, ReturnParameter) {
174
  StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
175 176
  m.Return(m.Parameter(0));
  Stream s = m.Build(kAllInstructions);
177
  ASSERT_EQ(3U, s.size());
178 179 180 181 182 183 184
  EXPECT_EQ(kArchNop, s[0]->arch_opcode());
  ASSERT_EQ(1U, s[0]->OutputCount());
  EXPECT_EQ(kArchRet, s[1]->arch_opcode());
  EXPECT_EQ(1U, s[1]->InputCount());
}


185
TARGET_TEST_F(InstructionSelectorTest, ReturnZero) {
186
  StreamBuilder m(this, MachineType::Int32());
187 188
  m.Return(m.Int32Constant(0));
  Stream s = m.Build(kAllInstructions);
189
  ASSERT_EQ(3U, s.size());
190 191 192 193 194 195 196 197
  EXPECT_EQ(kArchNop, s[0]->arch_opcode());
  ASSERT_EQ(1U, s[0]->OutputCount());
  EXPECT_EQ(InstructionOperand::CONSTANT, s[0]->OutputAt(0)->kind());
  EXPECT_EQ(0, s.ToInt32(s[0]->OutputAt(0)));
  EXPECT_EQ(kArchRet, s[1]->arch_opcode());
  EXPECT_EQ(1U, s[1]->InputCount());
}

198 199 200 201

// -----------------------------------------------------------------------------
// Conversions.

202
TARGET_TEST_F(InstructionSelectorTest, TruncateFloat64ToWord32WithParameter) {
203
  StreamBuilder m(this, MachineType::Int32(), MachineType::Float64());
204
  m.Return(m.TruncateFloat64ToWord32(m.Parameter(0)));
205
  Stream s = m.Build(kAllInstructions);
206
  ASSERT_EQ(4U, s.size());
207 208 209 210 211 212 213
  EXPECT_EQ(kArchNop, s[0]->arch_opcode());
  EXPECT_EQ(kArchTruncateDoubleToI, s[1]->arch_opcode());
  EXPECT_EQ(1U, s[1]->InputCount());
  EXPECT_EQ(1U, s[1]->OutputCount());
  EXPECT_EQ(kArchRet, s[2]->arch_opcode());
}

214 215 216 217 218 219

// -----------------------------------------------------------------------------
// Parameters.


TARGET_TEST_F(InstructionSelectorTest, DoubleParameter) {
220
  StreamBuilder m(this, MachineType::Float64(), MachineType::Float64());
221 222 223
  Node* param = m.Parameter(0);
  m.Return(param);
  Stream s = m.Build(kAllInstructions);
224
  EXPECT_TRUE(s.IsDouble(param));
225 226 227 228
}


TARGET_TEST_F(InstructionSelectorTest, ReferenceParameter) {
229
  StreamBuilder m(this, MachineType::AnyTagged(), MachineType::AnyTagged());
230 231 232
  Node* param = m.Parameter(0);
  m.Return(param);
  Stream s = m.Build(kAllInstructions);
233
  EXPECT_TRUE(s.IsReference(param));
234 235 236 237
}


// -----------------------------------------------------------------------------
238
// FinishRegion.
239 240


241
TARGET_TEST_F(InstructionSelectorTest, FinishRegion) {
242
  StreamBuilder m(this, MachineType::AnyTagged(), MachineType::AnyTagged());
243
  Node* param = m.Parameter(0);
244 245
  Node* finish =
      m.AddNode(m.common()->FinishRegion(), param, m.graph()->start());
246 247
  m.Return(finish);
  Stream s = m.Build(kAllInstructions);
248
  ASSERT_EQ(3U, s.size());
249 250 251
  EXPECT_EQ(kArchNop, s[0]->arch_opcode());
  ASSERT_EQ(1U, s[0]->OutputCount());
  ASSERT_TRUE(s[0]->Output()->IsUnallocated());
252
  EXPECT_EQ(kArchRet, s[1]->arch_opcode());
253 254 255
  EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output()));
  EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0)));
  EXPECT_TRUE(s.IsReference(finish));
256 257 258 259
}


// -----------------------------------------------------------------------------
260
// Phi.
261 262 263 264 265 266


typedef InstructionSelectorTestWithParam<MachineType>
    InstructionSelectorPhiTest;


267
TARGET_TEST_P(InstructionSelectorPhiTest, Doubleness) {
268 269 270 271
  const MachineType type = GetParam();
  StreamBuilder m(this, type, type, type);
  Node* param0 = m.Parameter(0);
  Node* param1 = m.Parameter(1);
272
  RawMachineLabel a, b, c;
273 274 275 276 277 278
  m.Branch(m.Int32Constant(0), &a, &b);
  m.Bind(&a);
  m.Goto(&c);
  m.Bind(&b);
  m.Goto(&c);
  m.Bind(&c);
279
  Node* phi = m.Phi(type.representation(), param0, param1);
280 281
  m.Return(phi);
  Stream s = m.Build(kAllInstructions);
282 283
  EXPECT_EQ(s.IsDouble(phi), s.IsDouble(param0));
  EXPECT_EQ(s.IsDouble(phi), s.IsDouble(param1));
284 285 286
}


287
TARGET_TEST_P(InstructionSelectorPhiTest, Referenceness) {
288 289 290 291
  const MachineType type = GetParam();
  StreamBuilder m(this, type, type, type);
  Node* param0 = m.Parameter(0);
  Node* param1 = m.Parameter(1);
292
  RawMachineLabel a, b, c;
293 294 295 296 297 298
  m.Branch(m.Int32Constant(1), &a, &b);
  m.Bind(&a);
  m.Goto(&c);
  m.Bind(&b);
  m.Goto(&c);
  m.Bind(&c);
299
  Node* phi = m.Phi(type.representation(), param0, param1);
300 301
  m.Return(phi);
  Stream s = m.Build(kAllInstructions);
302 303
  EXPECT_EQ(s.IsReference(phi), s.IsReference(param0));
  EXPECT_EQ(s.IsReference(phi), s.IsReference(param1));
304 305 306
}


307 308 309 310 311 312 313 314
INSTANTIATE_TEST_CASE_P(
    InstructionSelectorTest, InstructionSelectorPhiTest,
    ::testing::Values(MachineType::Float64(), MachineType::Int8(),
                      MachineType::Uint8(), MachineType::Int16(),
                      MachineType::Uint16(), MachineType::Int32(),
                      MachineType::Uint32(), MachineType::Int64(),
                      MachineType::Uint64(), MachineType::Pointer(),
                      MachineType::AnyTagged()));
315 316 317 318 319 320 321


// -----------------------------------------------------------------------------
// ValueEffect.


TARGET_TEST_F(InstructionSelectorTest, ValueEffect) {
322
  StreamBuilder m1(this, MachineType::Int32(), MachineType::Pointer());
323
  Node* p1 = m1.Parameter(0);
324
  m1.Return(m1.Load(MachineType::Int32(), p1, m1.Int32Constant(0)));
325
  Stream s1 = m1.Build(kAllInstructions);
326
  StreamBuilder m2(this, MachineType::Int32(), MachineType::Pointer());
327
  Node* p2 = m2.Parameter(0);
328 329
  m2.Return(m2.AddNode(
      m2.machine()->Load(MachineType::Int32()), p2, m2.Int32Constant(0),
330 331
      m2.AddNode(m2.common()->BeginRegion(RegionObservability::kObservable),
                 m2.graph()->start())));
332 333 334 335 336 337 338 339 340 341 342 343
  Stream s2 = m2.Build(kAllInstructions);
  EXPECT_LE(3U, s1.size());
  ASSERT_EQ(s1.size(), s2.size());
  TRACED_FORRANGE(size_t, i, 0, s1.size() - 1) {
    const Instruction* i1 = s1[i];
    const Instruction* i2 = s2[i];
    EXPECT_EQ(i1->arch_opcode(), i2->arch_opcode());
    EXPECT_EQ(i1->InputCount(), i2->InputCount());
    EXPECT_EQ(i1->OutputCount(), i2->OutputCount());
  }
}

344 345 346

// -----------------------------------------------------------------------------
// Calls with deoptimization.
347 348


349
TARGET_TEST_F(InstructionSelectorTest, CallJSFunctionWithDeopt) {
350 351
  StreamBuilder m(this, MachineType::AnyTagged(), MachineType::AnyTagged(),
                  MachineType::AnyTagged(), MachineType::AnyTagged());
352 353 354 355 356

  BailoutId bailout_id(42);

  Node* function_node = m.Parameter(0);
  Node* receiver = m.Parameter(1);
357
  Node* context = m.Parameter(2);
358

359
  ZoneVector<MachineType> int32_type(1, MachineType::Int32(), zone());
360 361
  ZoneVector<MachineType> empty_types(zone());

362 363 364
  CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(
      zone(), false, 1, CallDescriptor::kNeedsFrameState);

365
  // Build frame state for the state before the call.
366
  Node* parameters =
367 368 369
      m.AddNode(m.common()->TypedStateValues(&int32_type), m.Int32Constant(1));
  Node* locals = m.AddNode(m.common()->TypedStateValues(&empty_types));
  Node* stack = m.AddNode(m.common()->TypedStateValues(&empty_types));
370
  Node* context_sentinel = m.Int32Constant(0);
371
  Node* state_node = m.AddNode(
372 373
      m.common()->FrameState(bailout_id, OutputFrameStateCombine::Push(),
                             m.GetFrameStateFunctionInfo(1, 0)),
374
      parameters, locals, stack, context_sentinel, function_node,
375
      m.UndefinedConstant());
376 377

  // Build the call.
378
  Node* args[] = {receiver, m.UndefinedConstant(), m.Int32Constant(1), context};
379 380
  Node* call =
      m.CallNWithFrameState(descriptor, function_node, args, state_node);
381
  m.Return(call);
382 383 384 385 386 387 388 389

  Stream s = m.Build(kAllExceptNopInstructions);

  // Skip until kArchCallJSFunction.
  size_t index = 0;
  for (; index < s.size() && s[index]->arch_opcode() != kArchCallJSFunction;
       index++) {
  }
390 391
  // Now we should have two instructions: call and return.
  ASSERT_EQ(index + 2, s.size());
392 393 394

  EXPECT_EQ(kArchCallJSFunction, s[index++]->arch_opcode());
  EXPECT_EQ(kArchRet, s[index++]->arch_opcode());
395 396

  // TODO(jarin) Check deoptimization table.
397 398 399
}


400
TARGET_TEST_F(InstructionSelectorTest, CallStubWithDeopt) {
401 402
  StreamBuilder m(this, MachineType::AnyTagged(), MachineType::AnyTagged(),
                  MachineType::AnyTagged(), MachineType::AnyTagged());
403 404 405 406 407 408 409 410

  BailoutId bailout_id_before(42);

  // Some arguments for the call node.
  Node* function_node = m.Parameter(0);
  Node* receiver = m.Parameter(1);
  Node* context = m.Int32Constant(1);  // Context is ignored.

411 412 413
  ZoneVector<MachineType> int32_type(1, MachineType::Int32(), zone());
  ZoneVector<MachineType> float64_type(1, MachineType::Float64(), zone());
  ZoneVector<MachineType> tagged_type(1, MachineType::AnyTagged(), zone());
414

415 416 417 418 419
  Callable callable = CodeFactory::ToObject(isolate());
  CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
      isolate(), zone(), callable.descriptor(), 1,
      CallDescriptor::kNeedsFrameState, Operator::kNoProperties);

420
  // Build frame state for the state before the call.
421
  Node* parameters =
422 423
      m.AddNode(m.common()->TypedStateValues(&int32_type), m.Int32Constant(43));
  Node* locals = m.AddNode(m.common()->TypedStateValues(&float64_type),
424
                           m.Float64Constant(0.5));
425
  Node* stack = m.AddNode(m.common()->TypedStateValues(&tagged_type),
426
                          m.UndefinedConstant());
427
  Node* context_sentinel = m.Int32Constant(0);
428
  Node* state_node = m.AddNode(
429 430 431 432
      m.common()->FrameState(bailout_id_before, OutputFrameStateCombine::Push(),
                             m.GetFrameStateFunctionInfo(1, 1)),
      parameters, locals, stack, context_sentinel, function_node,
      m.UndefinedConstant());
433 434

  // Build the call.
435 436 437
  Node* args[] = {function_node, receiver, context};
  Node* stub_code = m.HeapConstant(callable.code());
  Node* call = m.CallNWithFrameState(descriptor, stub_code, args, state_node);
438 439 440 441 442 443 444 445 446
  m.Return(call);

  Stream s = m.Build(kAllExceptNopInstructions);

  // Skip until kArchCallJSFunction.
  size_t index = 0;
  for (; index < s.size() && s[index]->arch_opcode() != kArchCallCodeObject;
       index++) {
  }
447 448
  // Now we should have two instructions: call, return.
  ASSERT_EQ(index + 2, s.size());
449 450 451 452 453 454 455

  // Check the call instruction
  const Instruction* call_instr = s[index++];
  EXPECT_EQ(kArchCallCodeObject, call_instr->arch_opcode());
  size_t num_operands =
      1 +  // Code object.
      1 +
456
      5 +  // Frame state deopt id + one input for each value in frame state.
457
      1 +  // Function.
458
      1;   // Context.
459 460 461 462 463 464 465
  ASSERT_EQ(num_operands, call_instr->InputCount());

  // Code object.
  EXPECT_TRUE(call_instr->InputAt(0)->IsImmediate());

  // Deoptimization id.
  int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1));
466 467
  FrameStateDescriptor* desc_before =
      s.GetFrameStateDescriptor(deopt_id_before);
468
  EXPECT_EQ(bailout_id_before, desc_before->bailout_id());
469 470
  EXPECT_EQ(OutputFrameStateCombine::kPushOutput,
            desc_before->state_combine().kind());
471 472 473
  EXPECT_EQ(1u, desc_before->parameters_count());
  EXPECT_EQ(1u, desc_before->locals_count());
  EXPECT_EQ(1u, desc_before->stack_count());
474 475
  EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(3)));
  EXPECT_EQ(0, s.ToInt32(call_instr->InputAt(4)));  // This should be a context.
476
                                                    // We inserted 0 here.
477
  EXPECT_EQ(0.5, s.ToFloat64(call_instr->InputAt(5)));
478
  EXPECT_TRUE(s.ToHeapObject(call_instr->InputAt(6))->IsUndefined(isolate()));
479 480 481 482 483 484 485 486 487
  EXPECT_EQ(MachineType::AnyTagged(),
            desc_before->GetType(0));  // function is always
                                       // tagged/any.
  EXPECT_EQ(MachineType::Int32(), desc_before->GetType(1));
  EXPECT_EQ(MachineType::AnyTagged(),
            desc_before->GetType(2));  // context is always
                                       // tagged/any.
  EXPECT_EQ(MachineType::Float64(), desc_before->GetType(3));
  EXPECT_EQ(MachineType::AnyTagged(), desc_before->GetType(4));
488 489

  // Function.
490
  EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(7)));
491
  // Context.
492
  EXPECT_EQ(s.ToVreg(context), s.ToVreg(call_instr->InputAt(8)));
493 494 495 496 497 498

  EXPECT_EQ(kArchRet, s[index++]->arch_opcode());

  EXPECT_EQ(index, s.size());
}

499

500
TARGET_TEST_F(InstructionSelectorTest, CallStubWithDeoptRecursiveFrameState) {
501 502
  StreamBuilder m(this, MachineType::AnyTagged(), MachineType::AnyTagged(),
                  MachineType::AnyTagged(), MachineType::AnyTagged());
503 504 505 506 507 508 509 510

  BailoutId bailout_id_before(42);
  BailoutId bailout_id_parent(62);

  // Some arguments for the call node.
  Node* function_node = m.Parameter(0);
  Node* receiver = m.Parameter(1);
  Node* context = m.Int32Constant(66);
511
  Node* context2 = m.Int32Constant(46);
512

513 514 515
  ZoneVector<MachineType> int32_type(1, MachineType::Int32(), zone());
  ZoneVector<MachineType> int32x2_type(2, MachineType::Int32(), zone());
  ZoneVector<MachineType> float64_type(1, MachineType::Float64(), zone());
516

517 518 519 520 521
  Callable callable = CodeFactory::ToObject(isolate());
  CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
      isolate(), zone(), callable.descriptor(), 1,
      CallDescriptor::kNeedsFrameState, Operator::kNoProperties);

522
  // Build frame state for the state before the call.
523
  Node* parameters =
524
      m.AddNode(m.common()->TypedStateValues(&int32_type), m.Int32Constant(63));
525
  Node* locals =
526
      m.AddNode(m.common()->TypedStateValues(&int32_type), m.Int32Constant(64));
527
  Node* stack =
528 529
      m.AddNode(m.common()->TypedStateValues(&int32_type), m.Int32Constant(65));
  Node* frame_state_parent = m.AddNode(
530 531 532
      m.common()->FrameState(bailout_id_parent,
                             OutputFrameStateCombine::Ignore(),
                             m.GetFrameStateFunctionInfo(1, 1)),
533
      parameters, locals, stack, context, function_node, m.UndefinedConstant());
534 535

  Node* parameters2 =
536 537
      m.AddNode(m.common()->TypedStateValues(&int32_type), m.Int32Constant(43));
  Node* locals2 = m.AddNode(m.common()->TypedStateValues(&float64_type),
538
                            m.Float64Constant(0.25));
539
  Node* stack2 = m.AddNode(m.common()->TypedStateValues(&int32x2_type),
540
                           m.Int32Constant(44), m.Int32Constant(45));
541
  Node* state_node = m.AddNode(
542 543 544 545
      m.common()->FrameState(bailout_id_before, OutputFrameStateCombine::Push(),
                             m.GetFrameStateFunctionInfo(1, 1)),
      parameters2, locals2, stack2, context2, function_node,
      frame_state_parent);
546 547

  // Build the call.
548 549 550
  Node* args[] = {function_node, receiver, context2};
  Node* stub_code = m.HeapConstant(callable.code());
  Node* call = m.CallNWithFrameState(descriptor, stub_code, args, state_node);
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
  m.Return(call);

  Stream s = m.Build(kAllExceptNopInstructions);

  // Skip until kArchCallJSFunction.
  size_t index = 0;
  for (; index < s.size() && s[index]->arch_opcode() != kArchCallCodeObject;
       index++) {
  }
  // Now we should have three instructions: call, return.
  EXPECT_EQ(index + 2, s.size());

  // Check the call instruction
  const Instruction* call_instr = s[index++];
  EXPECT_EQ(kArchCallCodeObject, call_instr->arch_opcode());
  size_t num_operands =
      1 +  // Code object.
      1 +  // Frame state deopt id
569 570
      6 +  // One input for each value in frame state + context.
      5 +  // One input for each value in the parent frame state + context.
571 572 573 574 575 576 577 578 579 580
      1 +  // Function.
      1;   // Context.
  EXPECT_EQ(num_operands, call_instr->InputCount());
  // Code object.
  EXPECT_TRUE(call_instr->InputAt(0)->IsImmediate());

  // Deoptimization id.
  int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1));
  FrameStateDescriptor* desc_before =
      s.GetFrameStateDescriptor(deopt_id_before);
581
  FrameStateDescriptor* desc_before_outer = desc_before->outer_state();
582
  EXPECT_EQ(bailout_id_before, desc_before->bailout_id());
583 584 585 586
  EXPECT_EQ(1u, desc_before_outer->parameters_count());
  EXPECT_EQ(1u, desc_before_outer->locals_count());
  EXPECT_EQ(1u, desc_before_outer->stack_count());
  // Values from parent environment.
587
  EXPECT_EQ(MachineType::AnyTagged(), desc_before->GetType(0));
588
  EXPECT_EQ(63, s.ToInt32(call_instr->InputAt(3)));
589
  EXPECT_EQ(MachineType::Int32(), desc_before_outer->GetType(1));
590
  // Context:
591
  EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(4)));
592
  EXPECT_EQ(MachineType::AnyTagged(), desc_before_outer->GetType(2));
593
  EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(5)));
594
  EXPECT_EQ(MachineType::Int32(), desc_before_outer->GetType(3));
595
  EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(6)));
596
  EXPECT_EQ(MachineType::Int32(), desc_before_outer->GetType(4));
597 598 599 600
  // Values from the nested frame.
  EXPECT_EQ(1u, desc_before->parameters_count());
  EXPECT_EQ(1u, desc_before->locals_count());
  EXPECT_EQ(2u, desc_before->stack_count());
601
  EXPECT_EQ(MachineType::AnyTagged(), desc_before->GetType(0));
602
  EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(8)));
603
  EXPECT_EQ(MachineType::Int32(), desc_before->GetType(1));
604
  EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(9)));
605
  EXPECT_EQ(MachineType::AnyTagged(), desc_before->GetType(2));
606
  EXPECT_EQ(0.25, s.ToFloat64(call_instr->InputAt(10)));
607
  EXPECT_EQ(MachineType::Float64(), desc_before->GetType(3));
608
  EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(11)));
609
  EXPECT_EQ(MachineType::Int32(), desc_before->GetType(4));
610
  EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(12)));
611
  EXPECT_EQ(MachineType::Int32(), desc_before->GetType(5));
612 613

  // Function.
614
  EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(13)));
615
  // Context.
616
  EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(14)));
617 618 619 620 621 622
  // Continuation.

  EXPECT_EQ(kArchRet, s[index++]->arch_opcode());
  EXPECT_EQ(index, s.size());
}

623 624 625
}  // namespace compiler
}  // namespace internal
}  // namespace v8