2014-09-12 07:06:50 +00:00
|
|
|
// 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.
|
|
|
|
|
2016-09-05 15:58:05 +00:00
|
|
|
#include "src/compiler/simplified-operator.h"
|
2014-12-23 12:50:43 +00:00
|
|
|
#include "src/compiler/opcodes.h"
|
|
|
|
#include "src/compiler/operator-properties.h"
|
2016-09-05 15:58:05 +00:00
|
|
|
#include "src/compiler/operator.h"
|
|
|
|
#include "src/compiler/types.h"
|
2014-10-01 08:34:25 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
2014-09-12 07:06:50 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Pure operators.
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct PureOperator {
|
2014-09-15 09:09:45 +00:00
|
|
|
const Operator* (SimplifiedOperatorBuilder::*constructor)();
|
2014-09-12 07:06:50 +00:00
|
|
|
IrOpcode::Value opcode;
|
|
|
|
Operator::Properties properties;
|
|
|
|
int value_input_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const PureOperator& pop) {
|
|
|
|
return os << IrOpcode::Mnemonic(pop.opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PureOperator kPureOperators[] = {
|
|
|
|
#define PURE(Name, properties, input_count) \
|
|
|
|
{ \
|
|
|
|
&SimplifiedOperatorBuilder::Name, IrOpcode::k##Name, \
|
|
|
|
Operator::kPure | properties, input_count \
|
|
|
|
}
|
|
|
|
PURE(BooleanNot, Operator::kNoProperties, 1),
|
|
|
|
PURE(NumberEqual, Operator::kCommutative, 2),
|
|
|
|
PURE(NumberLessThan, Operator::kNoProperties, 2),
|
|
|
|
PURE(NumberLessThanOrEqual, Operator::kNoProperties, 2),
|
|
|
|
PURE(NumberAdd, Operator::kCommutative, 2),
|
|
|
|
PURE(NumberSubtract, Operator::kNoProperties, 2),
|
|
|
|
PURE(NumberMultiply, Operator::kCommutative, 2),
|
|
|
|
PURE(NumberDivide, Operator::kNoProperties, 2),
|
|
|
|
PURE(NumberModulus, Operator::kNoProperties, 2),
|
[turbofan] Introduce simplified NumberBitwise{Or,Xor,And} operators.
Currently we still (mis)used some machine operators in typed lowering
(namely Word32Or, Word32Xor and Word32And). But these operators are
"polymorphic" in the signedness of their inputs and output, hence the
representation selection (and thereby simplified lowering) was unable to
figure out whether a bitwise operation that was seen would produce an
unsigned or a signed result. If such nodes also have frame state uses,
the only safe choice was float64, which was not only a lot less ideal,
but also the main cause of the for-in related deoptimizer loops.
Adding dedicated NumberBitwiseOr, NumberBitwiseAnd and NumberBitwiseXor
simplified operators not only gives us precise (and correct) typing for
the bitwise operations, but also allows us to actually verify the graph
properly after typed lowering.
Drive-by-fix: Remove the double-to-smi magic from the Deoptimizer, which
is responsible for various deopt-loops in TurboFan, and is no longer
needed with the addition of the NumberBitwise operators.
R=jarin@chromium.org
Review URL: https://codereview.chromium.org/1422213002
Cr-Commit-Position: refs/heads/master@{#31594}
2015-10-27 09:07:54 +00:00
|
|
|
PURE(NumberBitwiseOr, Operator::kCommutative, 2),
|
|
|
|
PURE(NumberBitwiseXor, Operator::kCommutative, 2),
|
|
|
|
PURE(NumberBitwiseAnd, Operator::kCommutative, 2),
|
|
|
|
PURE(NumberShiftLeft, Operator::kNoProperties, 2),
|
|
|
|
PURE(NumberShiftRight, Operator::kNoProperties, 2),
|
|
|
|
PURE(NumberShiftRightLogical, Operator::kNoProperties, 2),
|
2014-09-12 07:06:50 +00:00
|
|
|
PURE(NumberToInt32, Operator::kNoProperties, 1),
|
|
|
|
PURE(NumberToUint32, Operator::kNoProperties, 1),
|
2016-04-24 11:39:31 +00:00
|
|
|
PURE(ChangeTaggedSignedToInt32, Operator::kNoProperties, 1),
|
2014-09-12 07:06:50 +00:00
|
|
|
PURE(ChangeTaggedToInt32, Operator::kNoProperties, 1),
|
|
|
|
PURE(ChangeTaggedToUint32, Operator::kNoProperties, 1),
|
|
|
|
PURE(ChangeTaggedToFloat64, Operator::kNoProperties, 1),
|
|
|
|
PURE(ChangeInt32ToTagged, Operator::kNoProperties, 1),
|
|
|
|
PURE(ChangeUint32ToTagged, Operator::kNoProperties, 1),
|
2016-05-02 10:23:02 +00:00
|
|
|
PURE(ChangeTaggedToBit, Operator::kNoProperties, 1),
|
|
|
|
PURE(ChangeBitToTagged, Operator::kNoProperties, 1),
|
2016-04-24 11:39:31 +00:00
|
|
|
PURE(TruncateTaggedToWord32, Operator::kNoProperties, 1),
|
2016-09-14 13:12:11 +00:00
|
|
|
PURE(TruncateTaggedToFloat64, Operator::kNoProperties, 1),
|
|
|
|
PURE(TruncateTaggedToBit, Operator::kNoProperties, 1),
|
2016-02-19 10:13:37 +00:00
|
|
|
PURE(ObjectIsNumber, Operator::kNoProperties, 1),
|
2016-02-02 11:42:38 +00:00
|
|
|
PURE(ObjectIsReceiver, Operator::kNoProperties, 1),
|
2015-09-04 08:44:27 +00:00
|
|
|
PURE(ObjectIsSmi, Operator::kNoProperties, 1)
|
2014-09-12 07:06:50 +00:00
|
|
|
#undef PURE
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
class SimplifiedPureOperatorTest
|
|
|
|
: public TestWithZone,
|
|
|
|
public ::testing::WithParamInterface<PureOperator> {};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedPureOperatorTest, InstancesAreGloballyShared) {
|
|
|
|
const PureOperator& pop = GetParam();
|
|
|
|
SimplifiedOperatorBuilder simplified1(zone());
|
|
|
|
SimplifiedOperatorBuilder simplified2(zone());
|
|
|
|
EXPECT_EQ((simplified1.*pop.constructor)(), (simplified2.*pop.constructor)());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedPureOperatorTest, NumberOfInputsAndOutputs) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
const PureOperator& pop = GetParam();
|
|
|
|
const Operator* op = (simplified.*pop.constructor)();
|
|
|
|
|
2014-10-29 18:46:44 +00:00
|
|
|
EXPECT_EQ(pop.value_input_count, op->ValueInputCount());
|
|
|
|
EXPECT_EQ(0, op->EffectInputCount());
|
|
|
|
EXPECT_EQ(0, op->ControlInputCount());
|
2014-09-12 07:06:50 +00:00
|
|
|
EXPECT_EQ(pop.value_input_count, OperatorProperties::GetTotalInputCount(op));
|
|
|
|
|
2014-10-29 18:46:44 +00:00
|
|
|
EXPECT_EQ(1, op->ValueOutputCount());
|
|
|
|
EXPECT_EQ(0, op->EffectOutputCount());
|
|
|
|
EXPECT_EQ(0, op->ControlOutputCount());
|
2014-09-12 07:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedPureOperatorTest, OpcodeIsCorrect) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
const PureOperator& pop = GetParam();
|
|
|
|
const Operator* op = (simplified.*pop.constructor)();
|
|
|
|
EXPECT_EQ(pop.opcode, op->opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedPureOperatorTest, Properties) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
const PureOperator& pop = GetParam();
|
|
|
|
const Operator* op = (simplified.*pop.constructor)();
|
|
|
|
EXPECT_EQ(pop.properties, op->properties() & pop.properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest, SimplifiedPureOperatorTest,
|
|
|
|
::testing::ValuesIn(kPureOperators));
|
|
|
|
|
2014-09-24 09:28:56 +00:00
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Buffer access operators.
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const ExternalArrayType kExternalArrayTypes[] = {
|
|
|
|
kExternalUint8Array, kExternalInt8Array, kExternalUint16Array,
|
|
|
|
kExternalInt16Array, kExternalUint32Array, kExternalInt32Array,
|
|
|
|
kExternalFloat32Array, kExternalFloat64Array};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
class SimplifiedBufferAccessOperatorTest
|
|
|
|
: public TestWithZone,
|
|
|
|
public ::testing::WithParamInterface<ExternalArrayType> {};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedBufferAccessOperatorTest, InstancesAreGloballyShared) {
|
|
|
|
BufferAccess const access(GetParam());
|
|
|
|
SimplifiedOperatorBuilder simplified1(zone());
|
|
|
|
SimplifiedOperatorBuilder simplified2(zone());
|
|
|
|
EXPECT_EQ(simplified1.LoadBuffer(access), simplified2.LoadBuffer(access));
|
|
|
|
EXPECT_EQ(simplified1.StoreBuffer(access), simplified2.StoreBuffer(access));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedBufferAccessOperatorTest, LoadBuffer) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
BufferAccess const access(GetParam());
|
|
|
|
const Operator* op = simplified.LoadBuffer(access);
|
|
|
|
|
|
|
|
EXPECT_EQ(IrOpcode::kLoadBuffer, op->opcode());
|
2016-06-20 10:46:12 +00:00
|
|
|
EXPECT_EQ(Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,
|
|
|
|
op->properties());
|
2014-12-02 04:48:57 +00:00
|
|
|
EXPECT_EQ(access, BufferAccessOf(op));
|
|
|
|
|
|
|
|
EXPECT_EQ(3, op->ValueInputCount());
|
|
|
|
EXPECT_EQ(1, op->EffectInputCount());
|
|
|
|
EXPECT_EQ(1, op->ControlInputCount());
|
|
|
|
EXPECT_EQ(5, OperatorProperties::GetTotalInputCount(op));
|
|
|
|
|
|
|
|
EXPECT_EQ(1, op->ValueOutputCount());
|
|
|
|
EXPECT_EQ(1, op->EffectOutputCount());
|
|
|
|
EXPECT_EQ(0, op->ControlOutputCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedBufferAccessOperatorTest, StoreBuffer) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
BufferAccess const access(GetParam());
|
|
|
|
const Operator* op = simplified.StoreBuffer(access);
|
|
|
|
|
|
|
|
EXPECT_EQ(IrOpcode::kStoreBuffer, op->opcode());
|
2016-06-20 10:46:12 +00:00
|
|
|
EXPECT_EQ(Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,
|
|
|
|
op->properties());
|
2014-12-02 04:48:57 +00:00
|
|
|
EXPECT_EQ(access, BufferAccessOf(op));
|
|
|
|
|
|
|
|
EXPECT_EQ(4, op->ValueInputCount());
|
|
|
|
EXPECT_EQ(1, op->EffectInputCount());
|
|
|
|
EXPECT_EQ(1, op->ControlInputCount());
|
|
|
|
EXPECT_EQ(6, OperatorProperties::GetTotalInputCount(op));
|
|
|
|
|
|
|
|
EXPECT_EQ(0, op->ValueOutputCount());
|
|
|
|
EXPECT_EQ(1, op->EffectOutputCount());
|
|
|
|
EXPECT_EQ(0, op->ControlOutputCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest,
|
|
|
|
SimplifiedBufferAccessOperatorTest,
|
|
|
|
::testing::ValuesIn(kExternalArrayTypes));
|
|
|
|
|
|
|
|
|
2014-09-24 09:28:56 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Element access operators.
|
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
|
2014-09-24 09:28:56 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const ElementAccess kElementAccesses[] = {
|
2015-12-10 09:03:30 +00:00
|
|
|
{kTaggedBase, FixedArray::kHeaderSize, Type::Any(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::AnyTagged(), kFullWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Any(), MachineType::Int8(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Any(), MachineType::Int16(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Any(), MachineType::Int32(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Any(), MachineType::Uint8(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Any(), MachineType::Uint16(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Any(), MachineType::Uint32(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Signed32(), MachineType::Int8(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Unsigned32(), MachineType::Uint8(),
|
|
|
|
kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Signed32(), MachineType::Int16(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Unsigned32(), MachineType::Uint16(),
|
|
|
|
kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Signed32(), MachineType::Int32(), kNoWriteBarrier},
|
|
|
|
{kUntaggedBase, 0, Type::Unsigned32(), MachineType::Uint32(),
|
|
|
|
kNoWriteBarrier},
|
2015-12-10 09:03:30 +00:00
|
|
|
{kUntaggedBase, 0, Type::Number(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType(MachineRepresentation::kFloat32, MachineSemantic::kNone),
|
|
|
|
kNoWriteBarrier},
|
2015-12-10 09:03:30 +00:00
|
|
|
{kUntaggedBase, 0, Type::Number(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType(MachineRepresentation::kFloat64, MachineSemantic::kNone),
|
|
|
|
kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Signed32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Int8(), kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Unsigned32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Uint8(), kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Signed32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Int16(), kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Unsigned32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Uint16(), kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Signed32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Int32(), kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Unsigned32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Uint32(), kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Number(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType(MachineRepresentation::kFloat32, MachineSemantic::kNone),
|
|
|
|
kNoWriteBarrier},
|
2014-12-02 04:48:57 +00:00
|
|
|
{kTaggedBase, FixedTypedArrayBase::kDataOffset, Type::Number(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType(MachineRepresentation::kFloat32, MachineSemantic::kNone),
|
|
|
|
kNoWriteBarrier}};
|
2014-09-24 09:28:56 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
class SimplifiedElementAccessOperatorTest
|
|
|
|
: public TestWithZone,
|
|
|
|
public ::testing::WithParamInterface<ElementAccess> {};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedElementAccessOperatorTest, LoadElement) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
const ElementAccess& access = GetParam();
|
|
|
|
const Operator* op = simplified.LoadElement(access);
|
|
|
|
|
|
|
|
EXPECT_EQ(IrOpcode::kLoadElement, op->opcode());
|
2016-06-20 10:46:12 +00:00
|
|
|
EXPECT_EQ(Operator::kNoDeopt | Operator::kNoThrow | Operator::kNoWrite,
|
|
|
|
op->properties());
|
2014-09-24 09:28:56 +00:00
|
|
|
EXPECT_EQ(access, ElementAccessOf(op));
|
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
EXPECT_EQ(2, op->ValueInputCount());
|
2014-10-29 18:46:44 +00:00
|
|
|
EXPECT_EQ(1, op->EffectInputCount());
|
2014-12-02 04:48:57 +00:00
|
|
|
EXPECT_EQ(1, op->ControlInputCount());
|
2014-10-28 13:00:11 +00:00
|
|
|
EXPECT_EQ(4, OperatorProperties::GetTotalInputCount(op));
|
2014-09-24 09:28:56 +00:00
|
|
|
|
2014-10-29 18:46:44 +00:00
|
|
|
EXPECT_EQ(1, op->ValueOutputCount());
|
|
|
|
EXPECT_EQ(1, op->EffectOutputCount());
|
|
|
|
EXPECT_EQ(0, op->ControlOutputCount());
|
2014-09-24 09:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(SimplifiedElementAccessOperatorTest, StoreElement) {
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
const ElementAccess& access = GetParam();
|
|
|
|
const Operator* op = simplified.StoreElement(access);
|
|
|
|
|
|
|
|
EXPECT_EQ(IrOpcode::kStoreElement, op->opcode());
|
2016-06-20 10:46:12 +00:00
|
|
|
EXPECT_EQ(Operator::kNoDeopt | Operator::kNoRead | Operator::kNoThrow,
|
|
|
|
op->properties());
|
2014-09-24 09:28:56 +00:00
|
|
|
EXPECT_EQ(access, ElementAccessOf(op));
|
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
EXPECT_EQ(3, op->ValueInputCount());
|
2014-10-29 18:46:44 +00:00
|
|
|
EXPECT_EQ(1, op->EffectInputCount());
|
|
|
|
EXPECT_EQ(1, op->ControlInputCount());
|
2014-12-02 04:48:57 +00:00
|
|
|
EXPECT_EQ(5, OperatorProperties::GetTotalInputCount(op));
|
2014-09-24 09:28:56 +00:00
|
|
|
|
2014-10-29 18:46:44 +00:00
|
|
|
EXPECT_EQ(0, op->ValueOutputCount());
|
|
|
|
EXPECT_EQ(1, op->EffectOutputCount());
|
|
|
|
EXPECT_EQ(0, op->ControlOutputCount());
|
2014-09-24 09:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest,
|
|
|
|
SimplifiedElementAccessOperatorTest,
|
|
|
|
::testing::ValuesIn(kElementAccesses));
|
|
|
|
|
2014-09-12 07:06:50 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|