Line data Source code
1 : // Copyright 2018 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 "test/unittests/test-utils.h"
6 :
7 : #include "src/compiler/linkage.h"
8 : #include "src/compiler/wasm-compiler.h"
9 : #include "src/machine-type.h"
10 : #include "src/signature.h"
11 : #include "src/wasm/value-type.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 : namespace wasm {
16 :
17 2 : class WasmCallDescriptorTest : public TestWithZone {};
18 :
19 15374 : TEST_F(WasmCallDescriptorTest, TestAnyRefIsGrouped) {
20 : constexpr size_t kMaxCount = 30;
21 : ValueType params[kMaxCount];
22 :
23 31 : for (size_t i = 0; i < kMaxCount; i += 2) {
24 15 : params[i] = ValueType::kWasmAnyRef;
25 15 : CHECK_LT(i + 1, kMaxCount);
26 15 : params[i + 1] = ValueType::kWasmI32;
27 : }
28 :
29 61 : for (size_t count = 1; count <= kMaxCount; ++count) {
30 : FunctionSig sig(/*return_count=*/0, count, params);
31 : compiler::CallDescriptor* desc =
32 30 : compiler::GetWasmCallDescriptor(zone(), &sig);
33 :
34 : // The WasmInstance is the implicit first parameter.
35 30 : CHECK_EQ(count + 1, desc->ParameterCount());
36 :
37 : bool has_untagged_stack_param = false;
38 : bool has_tagged_register_param = false;
39 30 : int max_tagged_stack_location = std::numeric_limits<int>::min();
40 30 : int min_untagged_stack_location = std::numeric_limits<int>::max();
41 960 : for (size_t i = 1; i < desc->ParameterCount(); ++i) {
42 : // InputLocation i + 1, because target is the first input.
43 465 : compiler::LinkageLocation location = desc->GetInputLocation(i + 1);
44 465 : if (desc->GetParameterType(i).IsTagged()) {
45 240 : if (location.IsRegister()) {
46 : has_tagged_register_param = true;
47 : } else {
48 225 : CHECK(location.IsCallerFrameSlot());
49 : max_tagged_stack_location =
50 450 : std::max(max_tagged_stack_location, location.AsCallerFrameSlot());
51 : }
52 : } else { // !isTagged()
53 225 : if (location.IsCallerFrameSlot()) {
54 : has_untagged_stack_param = true;
55 : min_untagged_stack_location = std::min(min_untagged_stack_location,
56 200 : location.AsCallerFrameSlot());
57 : } else {
58 125 : CHECK(location.IsRegister());
59 : }
60 : }
61 : }
62 : // There should never be a tagged parameter in a register and an untagged
63 : // parameter on the stack at the same time.
64 30 : CHECK_EQ(false, has_tagged_register_param && has_untagged_stack_param);
65 30 : CHECK_LT(max_tagged_stack_location, min_untagged_stack_location);
66 : }
67 1 : }
68 :
69 : } // namespace wasm
70 : } // namespace internal
71 9222 : } // namespace v8
|