2015-01-26 09:05:47 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "src/compiler/access-builder.h"
|
2015-03-31 13:23:06 +00:00
|
|
|
#include "src/compiler/diamond.h"
|
2015-01-26 09:05:47 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
|
|
|
#include "src/compiler/js-intrinsic-lowering.h"
|
|
|
|
#include "src/compiler/js-operator.h"
|
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
|
|
|
#include "testing/gmock-support.h"
|
|
|
|
|
2015-03-31 13:23:06 +00:00
|
|
|
|
2015-01-26 09:05:47 +00:00
|
|
|
using testing::_;
|
|
|
|
using testing::AllOf;
|
|
|
|
using testing::BitEq;
|
|
|
|
using testing::Capture;
|
|
|
|
using testing::CaptureEq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2016-02-02 11:42:38 +00:00
|
|
|
class JSIntrinsicLoweringTest : public GraphTest {
|
2015-01-26 09:05:47 +00:00
|
|
|
public:
|
2016-02-02 11:42:38 +00:00
|
|
|
JSIntrinsicLoweringTest() : GraphTest(3), javascript_(zone()) {}
|
2018-09-17 11:30:48 +00:00
|
|
|
~JSIntrinsicLoweringTest() override = default;
|
2015-01-26 09:05:47 +00:00
|
|
|
|
|
|
|
protected:
|
2016-07-25 10:37:25 +00:00
|
|
|
Reduction Reduce(Node* node) {
|
|
|
|
MachineOperatorBuilder machine(zone(),
|
|
|
|
MachineType::PointerRepresentation());
|
2015-10-19 08:05:05 +00:00
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified,
|
2015-10-16 12:38:46 +00:00
|
|
|
&machine);
|
2020-09-11 15:42:50 +00:00
|
|
|
GraphReducer graph_reducer(zone(), graph(), tick_counter(), broker());
|
2020-01-22 10:50:01 +00:00
|
|
|
JSIntrinsicLowering reducer(&graph_reducer, &jsgraph, broker());
|
2015-01-26 09:05:47 +00:00
|
|
|
return reducer.Reduce(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSOperatorBuilder* javascript() { return &javascript_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSOperatorBuilder javascript_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// %_IsSmi
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(JSIntrinsicLoweringTest, InlineIsSmi) {
|
|
|
|
Node* const input = Parameter(0);
|
|
|
|
Node* const context = Parameter(1);
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Reduction const r = Reduce(
|
|
|
|
graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsSmi, 1),
|
|
|
|
input, context, effect, control));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsObjectIsSmi(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// %_IsArray
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(JSIntrinsicLoweringTest, InlineIsArray) {
|
|
|
|
Node* const input = Parameter(0);
|
|
|
|
Node* const context = Parameter(1);
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Reduction const r = Reduce(
|
|
|
|
graph()->NewNode(javascript()->CallRuntime(Runtime::kInlineIsArray, 1),
|
|
|
|
input, context, effect, control));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
|
|
|
|
Node* phi = r.replacement();
|
|
|
|
Capture<Node*> branch, if_false;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
|
|
|
IsPhi(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineRepresentation::kTagged, IsFalseConstant(),
|
2016-07-25 10:37:25 +00:00
|
|
|
IsNumberEqual(IsLoadField(AccessBuilder::ForMapInstanceType(),
|
2015-01-26 09:05:47 +00:00
|
|
|
IsLoadField(AccessBuilder::ForMap(), input,
|
|
|
|
effect, CaptureEq(&if_false)),
|
2017-10-18 12:29:31 +00:00
|
|
|
_, _),
|
2016-07-25 10:37:25 +00:00
|
|
|
IsNumberConstant(JS_ARRAY_TYPE)),
|
2015-01-26 09:05:47 +00:00
|
|
|
IsMerge(IsIfTrue(AllOf(CaptureEq(&branch),
|
|
|
|
IsBranch(IsObjectIsSmi(input), control))),
|
2015-06-15 22:16:33 +00:00
|
|
|
AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch))))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-12 14:05:36 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2015-11-30 11:56:11 +00:00
|
|
|
// %_IsJSReceiver
|
2015-11-12 14:05:36 +00:00
|
|
|
|
|
|
|
|
2016-02-02 11:42:38 +00:00
|
|
|
TEST_F(JSIntrinsicLoweringTest, InlineIsJSReceiver) {
|
|
|
|
Node* const input = Parameter(0);
|
|
|
|
Node* const context = Parameter(1);
|
2015-12-02 14:35:44 +00:00
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Reduction const r = Reduce(graph()->NewNode(
|
|
|
|
javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), input,
|
|
|
|
context, effect, control));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-02-02 11:42:38 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsObjectIsReceiver(input));
|
2015-12-02 14:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 19:53:06 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// %_CreateJSGeneratorObject
|
|
|
|
|
|
|
|
TEST_F(JSIntrinsicLoweringTest, InlineCreateJSGeneratorObject) {
|
|
|
|
Node* const function = Parameter(0);
|
|
|
|
Node* const receiver = Parameter(1);
|
|
|
|
Node* const context = Parameter(2);
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Reduction const r = Reduce(graph()->NewNode(
|
|
|
|
javascript()->CallRuntime(Runtime::kInlineCreateJSGeneratorObject, 2),
|
|
|
|
function, receiver, context, effect, control));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(IrOpcode::kJSCreateGeneratorObject,
|
|
|
|
r.replacement()->op()->opcode());
|
|
|
|
}
|
|
|
|
|
2015-01-26 09:05:47 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|