interpreter-assembler-unittest.cc 22.1 KB
Newer Older
1 2 3 4
// Copyright 2015 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/interpreter/interpreter-assembler-unittest.h"
6

7 8
#include "src/codegen/code-factory.h"
#include "src/codegen/interface-descriptors.h"
9
#include "src/compiler/node-properties.h"
10
#include "src/compiler/node.h"
11
#include "src/execution/isolate.h"
12
#include "src/objects/objects-inl.h"
13 14 15
#include "test/unittests/compiler/compiler-test-utils.h"
#include "test/unittests/compiler/node-test-utils.h"

16
using ::testing::_;
17
using ::testing::Eq;
18 19

namespace c = v8::internal::compiler;
20

21 22
namespace v8 {
namespace internal {
23
namespace interpreter {
24
namespace interpreter_assembler_unittest {
25

26 27 28
InterpreterAssemblerTestState::InterpreterAssemblerTestState(
    InterpreterAssemblerTest* test, Bytecode bytecode)
    : compiler::CodeAssemblerState(
29
          test->isolate(), test->zone(), InterpreterDispatchDescriptor{},
30
          CodeKind::BYTECODE_HANDLER, Bytecodes::ToString(bytecode),
31
          PoisoningMitigationLevel::kPoisonCriticalOnly) {}
32

33
const interpreter::Bytecode kBytecodes[] = {
34
#define DEFINE_BYTECODE(Name, ...) interpreter::Bytecode::k##Name,
35 36 37 38
    BYTECODE_LIST(DEFINE_BYTECODE)
#undef DEFINE_BYTECODE
};

39

40 41 42 43 44 45 46 47
InterpreterAssemblerTest::InterpreterAssemblerForTest::
    ~InterpreterAssemblerForTest() {
  // Tests don't necessarily read and write accumulator but
  // InterpreterAssembler checks accumulator uses.
  if (Bytecodes::ReadsAccumulator(bytecode())) {
    GetAccumulator();
  }
  if (Bytecodes::WritesAccumulator(bytecode())) {
48
    SetAccumulator(NullConstant());
49
  }
50 51 52
  if (Bytecodes::WritesImplicitRegister(bytecode())) {
    StoreRegisterForShortStar(NullConstant(), IntPtrConstant(2));
  }
53 54
}

55
Matcher<c::Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
56
    const Matcher<c::LoadRepresentation>& rep_matcher,
57 58
    const Matcher<c::Node*>& base_matcher,
    const Matcher<c::Node*>& index_matcher, LoadSensitivity needs_poisoning) {
59 60 61 62
  CHECK_NE(LoadSensitivity::kUnsafe, needs_poisoning);
  CHECK_NE(PoisoningMitigationLevel::kPoisonAll, poisoning_level());
  if (poisoning_level() == PoisoningMitigationLevel::kPoisonCriticalOnly &&
      needs_poisoning == LoadSensitivity::kCritical) {
63 64 65
    return ::i::compiler::IsPoisonedLoad(rep_matcher, base_matcher,
                                         index_matcher, _, _);
  }
66
  return ::i::compiler::IsLoad(rep_matcher, base_matcher, index_matcher, _, _);
67 68
}

69
Matcher<c::Node*>
70 71
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoadFromObject(
    const Matcher<c::LoadRepresentation>& rep_matcher,
72 73
    const Matcher<c::Node*>& base_matcher,
    const Matcher<c::Node*>& index_matcher) {
74 75 76 77 78
  CHECK_NE(PoisoningMitigationLevel::kPoisonAll, poisoning_level());
  return ::i::compiler::IsLoadFromObject(rep_matcher, base_matcher,
                                         index_matcher, _, _);
}

79 80
Matcher<c::Node*>
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsStore(
81
    const Matcher<c::StoreRepresentation>& rep_matcher,
82 83 84
    const Matcher<c::Node*>& base_matcher,
    const Matcher<c::Node*>& index_matcher,
    const Matcher<c::Node*>& value_matcher) {
85
  return ::i::compiler::IsStore(rep_matcher, base_matcher, index_matcher,
86
                                value_matcher, _, _);
87 88
}

89 90 91
Matcher<c::Node*>
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsWordNot(
    const Matcher<c::Node*>& value_matcher) {
92 93 94
  return kSystemPointerSize == 8
             ? IsWord64Xor(value_matcher, c::IsInt64Constant(-1))
             : IsWord32Xor(value_matcher, c::IsInt32Constant(-1));
95 96
}

97
Matcher<c::Node*>
98
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand(
99
    int offset, LoadSensitivity needs_poisoning) {
100 101 102 103 104
  return IsLoad(
      MachineType::Uint8(),
      c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
      c::IsIntPtrAdd(
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
105 106
          c::IsIntPtrConstant(offset)),
      needs_poisoning);
107 108
}

109
Matcher<c::Node*>
110
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand(
111
    int offset, LoadSensitivity needs_poisoning) {
112 113 114 115 116
  return IsLoad(
      MachineType::Int8(),
      c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
      c::IsIntPtrAdd(
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
117 118
          c::IsIntPtrConstant(offset)),
      needs_poisoning);
119 120
}

121
Matcher<c::Node*>
122
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedShortOperand(
123
    int offset, LoadSensitivity needs_poisoning) {
124 125
  if (TargetSupportsUnalignedAccess()) {
    return IsLoad(
126
        MachineType::Uint16(),
127
        c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
128
        c::IsIntPtrAdd(
129
            c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
130 131
            c::IsIntPtrConstant(offset)),
        needs_poisoning);
132 133
  } else {
#if V8_TARGET_LITTLE_ENDIAN
134 135
    const int kStep = -1;
    const int kMsbOffset = 1;
136
#elif V8_TARGET_BIG_ENDIAN
137 138
    const int kStep = 1;
    const int kMsbOffset = 0;
139 140 141
#else
#error "Unknown Architecture"
#endif
142
    Matcher<c::Node*> bytes[2];
143 144 145
    for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
      bytes[i] = IsLoad(
          MachineType::Uint8(),
146
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
147
          c::IsIntPtrAdd(
148
              c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
149 150
              c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
          needs_poisoning);
151
    }
152 153
    return c::IsWord32Or(
        c::IsWord32Shl(bytes[0], c::IsInt32Constant(kBitsPerByte)), bytes[1]);
154 155 156
  }
}

157
Matcher<c::Node*>
158
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand(
159
    int offset, LoadSensitivity needs_poisoning) {
160
  if (TargetSupportsUnalignedAccess()) {
161
    return IsLoad(
162
        MachineType::Int16(),
163
        c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
164
        c::IsIntPtrAdd(
165
            c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
166 167
            c::IsIntPtrConstant(offset)),
        needs_poisoning);
168 169
  } else {
#if V8_TARGET_LITTLE_ENDIAN
170 171
    const int kStep = -1;
    const int kMsbOffset = 1;
172
#elif V8_TARGET_BIG_ENDIAN
173 174
    const int kStep = 1;
    const int kMsbOffset = 0;
175 176 177
#else
#error "Unknown Architecture"
#endif
178
    Matcher<c::Node*> bytes[2];
179 180 181
    for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
      bytes[i] = IsLoad(
          (i == 0) ? MachineType::Int8() : MachineType::Uint8(),
182
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
183
          c::IsIntPtrAdd(
184
              c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
185 186
              c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
          needs_poisoning);
187
    }
188 189
    return c::IsWord32Or(
        c::IsWord32Shl(bytes[0], c::IsInt32Constant(kBitsPerByte)), bytes[1]);
190 191 192
  }
}

193
Matcher<c::Node*>
194
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand(
195
    int offset, LoadSensitivity needs_poisoning) {
196 197 198
  if (TargetSupportsUnalignedAccess()) {
    return IsLoad(
        MachineType::Uint32(),
199
        c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
200
        c::IsIntPtrAdd(
201
            c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
202 203
            c::IsIntPtrConstant(offset)),
        needs_poisoning);
204 205 206 207 208 209 210 211 212 213
  } else {
#if V8_TARGET_LITTLE_ENDIAN
    const int kStep = -1;
    const int kMsbOffset = 3;
#elif V8_TARGET_BIG_ENDIAN
    const int kStep = 1;
    const int kMsbOffset = 0;
#else
#error "Unknown Architecture"
#endif
214
    Matcher<c::Node*> bytes[4];
215 216 217
    for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
      bytes[i] = IsLoad(
          MachineType::Uint8(),
218
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
219
          c::IsIntPtrAdd(
220
              c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
221 222
              c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
          needs_poisoning);
223
    }
224 225 226 227 228 229 230
    return c::IsWord32Or(
        c::IsWord32Shl(bytes[0], c::IsInt32Constant(3 * kBitsPerByte)),
        c::IsWord32Or(
            c::IsWord32Shl(bytes[1], c::IsInt32Constant(2 * kBitsPerByte)),
            c::IsWord32Or(
                c::IsWord32Shl(bytes[2], c::IsInt32Constant(1 * kBitsPerByte)),
                bytes[3])));
231 232 233
  }
}

234
Matcher<c::Node*>
235
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand(
236
    int offset, LoadSensitivity needs_poisoning) {
237
  if (TargetSupportsUnalignedAccess()) {
238
    return IsLoad(
239
        MachineType::Int32(),
240
        c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
241
        c::IsIntPtrAdd(
242
            c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
243 244
            c::IsIntPtrConstant(offset)),
        needs_poisoning);
245 246 247 248 249 250 251 252 253 254
  } else {
#if V8_TARGET_LITTLE_ENDIAN
    const int kStep = -1;
    int kMsbOffset = 3;
#elif V8_TARGET_BIG_ENDIAN
    const int kStep = 1;
    int kMsbOffset = 0;
#else
#error "Unknown Architecture"
#endif
255
    Matcher<c::Node*> bytes[4];
256 257 258
    for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
      bytes[i] = IsLoad(
          (i == 0) ? MachineType::Int8() : MachineType::Uint8(),
259
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
260
          c::IsIntPtrAdd(
261
              c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
262 263
              c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)),
          needs_poisoning);
264
    }
265 266 267 268 269 270 271
    return c::IsWord32Or(
        c::IsWord32Shl(bytes[0], c::IsInt32Constant(3 * kBitsPerByte)),
        c::IsWord32Or(
            c::IsWord32Shl(bytes[1], c::IsInt32Constant(2 * kBitsPerByte)),
            c::IsWord32Or(
                c::IsWord32Shl(bytes[2], c::IsInt32Constant(1 * kBitsPerByte)),
                bytes[3])));
272 273 274
  }
}

275
Matcher<c::Node*>
276 277
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedOperand(
    int offset, OperandSize operand_size, LoadSensitivity needs_poisoning) {
278 279
  switch (operand_size) {
    case OperandSize::kByte:
280
      return IsSignedByteOperand(offset, needs_poisoning);
281
    case OperandSize::kShort:
282
      return IsSignedShortOperand(offset, needs_poisoning);
283
    case OperandSize::kQuad:
284
      return IsSignedQuadOperand(offset, needs_poisoning);
285 286 287 288 289 290
    case OperandSize::kNone:
      UNREACHABLE();
  }
  return nullptr;
}

291
Matcher<c::Node*>
292 293
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand(
    int offset, OperandSize operand_size, LoadSensitivity needs_poisoning) {
294 295
  switch (operand_size) {
    case OperandSize::kByte:
296
      return IsUnsignedByteOperand(offset, needs_poisoning);
297
    case OperandSize::kShort:
298
      return IsUnsignedShortOperand(offset, needs_poisoning);
299
    case OperandSize::kQuad:
300
      return IsUnsignedQuadOperand(offset, needs_poisoning);
301 302 303 304 305 306
    case OperandSize::kNone:
      UNREACHABLE();
  }
  return nullptr;
}

307
Matcher<c::Node*>
308 309
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoadRegisterOperand(
    int offset, OperandSize operand_size) {
310
  Matcher<c::Node*> reg_operand = IsChangeInt32ToIntPtr(
311
      IsSignedOperand(offset, operand_size, LoadSensitivity::kSafe));
312 313 314 315
  return IsBitcastWordToTagged(IsLoad(
      MachineType::Pointer(), c::IsLoadParentFramePointer(),
      c::IsWordShl(reg_operand, c::IsIntPtrConstant(kSystemPointerSizeLog2)),
      LoadSensitivity::kCritical));
316 317
}

318
TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
319 320
  static const OperandScale kOperandScales[] = {
      OperandScale::kSingle, OperandScale::kDouble, OperandScale::kQuadruple};
321
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
322
    TRACED_FOREACH(interpreter::OperandScale, operand_scale, kOperandScales) {
323 324
      InterpreterAssemblerTestState state(this, bytecode);
      InterpreterAssemblerForTest m(&state, bytecode, operand_scale);
325 326 327 328 329 330 331 332 333 334 335 336
      int number_of_operands =
          interpreter::Bytecodes::NumberOfOperands(bytecode);
      for (int i = 0; i < number_of_operands; i++) {
        int offset = interpreter::Bytecodes::GetOperandOffset(bytecode, i,
                                                              operand_scale);
        OperandType operand_type =
            interpreter::Bytecodes::GetOperandType(bytecode, i);
        OperandSize operand_size =
            Bytecodes::SizeOfOperand(operand_type, operand_scale);
        switch (interpreter::Bytecodes::GetOperandType(bytecode, i)) {
          case interpreter::OperandType::kRegCount:
            EXPECT_THAT(m.BytecodeOperandCount(i),
337
                        m.IsUnsignedOperand(offset, operand_size,
338
                                            LoadSensitivity::kCritical));
339 340 341
            break;
          case interpreter::OperandType::kFlag8:
            EXPECT_THAT(m.BytecodeOperandFlag(i),
342
                        m.IsUnsignedOperand(offset, operand_size,
343
                                            LoadSensitivity::kCritical));
344 345
            break;
          case interpreter::OperandType::kIdx:
346 347 348
            EXPECT_THAT(m.BytecodeOperandIdx(i),
                        c::IsChangeUint32ToWord(m.IsUnsignedOperand(
                            offset, operand_size, LoadSensitivity::kCritical)));
349
            break;
350
          case interpreter::OperandType::kNativeContextIndex:
351 352 353
            EXPECT_THAT(m.BytecodeOperandNativeContextIndex(i),
                        c::IsChangeUint32ToWord(m.IsUnsignedOperand(
                            offset, operand_size, LoadSensitivity::kCritical)));
354
            break;
355 356
          case interpreter::OperandType::kUImm:
            EXPECT_THAT(m.BytecodeOperandUImm(i),
357
                        m.IsUnsignedOperand(offset, operand_size,
358
                                            LoadSensitivity::kCritical));
359
            break;
360 361
          case interpreter::OperandType::kImm: {
            EXPECT_THAT(m.BytecodeOperandImm(i),
362
                        m.IsSignedOperand(offset, operand_size,
363
                                          LoadSensitivity::kCritical));
364 365 366 367
            break;
          }
          case interpreter::OperandType::kRuntimeId:
            EXPECT_THAT(m.BytecodeOperandRuntimeId(i),
368
                        m.IsUnsignedOperand(offset, operand_size,
369
                                            LoadSensitivity::kCritical));
370
            break;
371 372
          case interpreter::OperandType::kIntrinsicId:
            EXPECT_THAT(m.BytecodeOperandIntrinsicId(i),
373
                        m.IsUnsignedOperand(offset, operand_size,
374
                                            LoadSensitivity::kCritical));
375
            break;
376 377 378 379 380 381 382 383 384 385
          case interpreter::OperandType::kRegList:
          case interpreter::OperandType::kReg:
          case interpreter::OperandType::kRegPair:
          case interpreter::OperandType::kRegOut:
          case interpreter::OperandType::kRegOutList:
          case interpreter::OperandType::kRegOutPair:
          case interpreter::OperandType::kRegOutTriple:
            EXPECT_THAT(m.LoadRegisterAtOperandIndex(i),
                        m.IsLoadRegisterOperand(offset, operand_size));
            break;
386 387 388
          case interpreter::OperandType::kNone:
            UNREACHABLE();
        }
389
      }
390 391 392 393
    }
  }
}

394
TARGET_TEST_F(InterpreterAssemblerTest, GetContext) {
395
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
396 397
    InterpreterAssemblerTestState state(this, bytecode);
    InterpreterAssemblerForTest m(&state, bytecode);
398 399
    EXPECT_THAT(
        m.GetContext(),
400 401 402 403
        IsBitcastWordToTagged(m.IsLoad(
            MachineType::Pointer(), c::IsLoadParentFramePointer(),
            c::IsIntPtrConstant(Register::current_context().ToOperand() *
                                kSystemPointerSize))));
404 405 406
  }
}

407 408
TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) {
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
409 410
    InterpreterAssemblerTestState state(this, bytecode);
    InterpreterAssemblerForTest m(&state, bytecode);
411
    {
412
      TNode<IntPtrT> index = m.IntPtrConstant(2);
413
      TNode<Object> load_constant = m.LoadConstantPoolEntry(index);
414 415 416 417 418 419 420 421 422 423 424
      Matcher<c::Node*> constant_pool_matcher = m.IsLoadFromObject(
          MachineType::AnyTagged(),
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
          c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
                              kHeapObjectTag));
      EXPECT_THAT(
          load_constant,
          m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher,
                   c::IsIntPtrConstant(FixedArray::OffsetOfElementAt(2) -
                                       kHeapObjectTag),
                   LoadSensitivity::kCritical));
425 426
    }
    {
427
      c::Node* index = m.UntypedParameter(2);
428 429
      TNode<Object> load_constant =
          m.LoadConstantPoolEntry(m.ReinterpretCast<IntPtrT>(index));
430 431 432 433 434 435 436 437 438 439 440 441 442
      Matcher<c::Node*> constant_pool_matcher = m.IsLoadFromObject(
          MachineType::AnyTagged(),
          c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
          c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
                              kHeapObjectTag));
      EXPECT_THAT(
          load_constant,
          m.IsLoad(
              MachineType::AnyTagged(), constant_pool_matcher,
              c::IsIntPtrAdd(
                  c::IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
                  c::IsWordShl(index, c::IsIntPtrConstant(kTaggedSizeLog2))),
              LoadSensitivity::kCritical));
443
    }
444 445 446 447 448
  }
}

TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) {
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
449 450
    InterpreterAssemblerTestState state(this, bytecode);
    InterpreterAssemblerForTest m(&state, bytecode);
451 452
    TNode<HeapObject> object =
        m.ReinterpretCast<HeapObject>(m.IntPtrConstant(0xDEADBEEF));
453
    int offset = 16;
454
    TNode<Object> load_field = m.LoadObjectField(object, offset);
455 456 457 458
      EXPECT_THAT(
          load_field,
          m.IsLoadFromObject(MachineType::AnyTagged(), Eq(object),
                             c::IsIntPtrConstant(offset - kHeapObjectTag)));
459 460 461
  }
}

462
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime2) {
463
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
464 465
    InterpreterAssemblerTestState state(this, bytecode);
    InterpreterAssemblerForTest m(&state, bytecode);
466 467 468 469 470 471 472 473
    TNode<Object> arg1 = m.ReinterpretCast<Object>(m.Int32Constant(2));
    TNode<Object> arg2 = m.ReinterpretCast<Object>(m.Int32Constant(3));
    TNode<Object> context = m.ReinterpretCast<Object>(m.Int32Constant(4));
    TNode<Object> call_runtime =
        m.CallRuntime(Runtime::kAdd, context, arg1, arg2);
    EXPECT_THAT(call_runtime,
                c::IsCall(_, _, Eq(arg1), Eq(arg2), _, c::IsInt32Constant(2),
                          Eq(context), _, _));
474 475 476
  }
}

477
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime) {
478
  const int kResultSizes[] = {1, 2};
479
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
480
    TRACED_FOREACH(int, result_size, kResultSizes) {
481 482 483 484 485 486
      if (Bytecodes::IsCallRuntime(bytecode)) {
        InterpreterAssemblerTestState state(this, bytecode);
        InterpreterAssemblerForTest m(&state, bytecode);
        Callable builtin =
            CodeFactory::InterpreterCEntry(isolate(), result_size);

487
        TNode<Uint32T> function_id = m.Uint32Constant(0);
488 489
        InterpreterAssembler::RegListNodePair registers(m.IntPtrConstant(1),
                                                        m.Int32Constant(2));
490
        TNode<Context> context = m.ReinterpretCast<Context>(m.Int32Constant(4));
491

492
        Matcher<c::Node*> function_table = c::IsExternalConstant(
493 494
            ExternalReference::runtime_function_table_address_for_unittests(
                isolate()));
495
        Matcher<c::Node*> function =
496 497 498 499
            c::IsIntPtrAdd(function_table,
                           c::IsChangeUint32ToWord(c::IsInt32Mul(
                               Eq(function_id),
                               c::IsInt32Constant(sizeof(Runtime::Function)))));
500
        Matcher<c::Node*> function_entry =
501
            m.IsLoad(MachineType::Pointer(), function,
502
                     c::IsIntPtrConstant(offsetof(Runtime::Function, entry)));
503

504
        c::Node* call_runtime =
505
            m.CallRuntimeN(function_id, context, registers, result_size);
506 507 508 509 510
        EXPECT_THAT(call_runtime,
                    c::IsCall(_, c::IsHeapConstant(builtin.code()),
                              Eq(registers.reg_count()),
                              Eq(registers.base_reg_location()), function_entry,
                              Eq(context), _, _));
511
      }
512
    }
513 514 515
  }
}

516
TARGET_TEST_F(InterpreterAssemblerTest, LoadFeedbackVector) {
517
  TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
518 519
    InterpreterAssemblerTestState state(this, bytecode);
    InterpreterAssemblerForTest m(&state, bytecode);
520
    TNode<HeapObject> feedback_vector = m.LoadFeedbackVector();
521

522 523 524
    // Feedback vector is a phi node with two inputs. One of them is loading the
    // feedback vector and the other is undefined constant (when feedback
    // vectors aren't allocated). Find the input that loads feedback vector.
525
    CHECK_EQ(static_cast<c::Node*>(feedback_vector)->opcode(),
526
             i::compiler::IrOpcode::kPhi);
527
    c::Node* value0 =
528
        i::compiler::NodeProperties::GetValueInput(feedback_vector, 0);
529
    c::Node* value1 =
530
        i::compiler::NodeProperties::GetValueInput(feedback_vector, 1);
531
    c::Node* load_feedback_vector = value0;
532 533 534 535
    if (value0->opcode() == i::compiler::IrOpcode::kHeapConstant) {
      load_feedback_vector = value1;
    }

536
    Matcher<c::Node*> load_function_matcher = IsBitcastWordToTagged(
537
        m.IsLoad(MachineType::Pointer(), c::IsLoadParentFramePointer(),
538
                 c::IsIntPtrConstant(Register::function_closure().ToOperand() *
539
                                     kSystemPointerSize)));
540 541 542 543 544 545 546
    Matcher<c::Node*> load_vector_cell_matcher = m.IsLoadFromObject(
        MachineType::TaggedPointer(), load_function_matcher,
        c::IsIntPtrConstant(JSFunction::kFeedbackCellOffset - kHeapObjectTag));
    EXPECT_THAT(load_feedback_vector,
                m.IsLoadFromObject(
                    MachineType::TaggedPointer(), load_vector_cell_matcher,
                    c::IsIntPtrConstant(Cell::kValueOffset - kHeapObjectTag)));
547 548 549
  }
}

550
}  // namespace interpreter_assembler_unittest
551
}  // namespace interpreter
552 553
}  // namespace internal
}  // namespace v8