2014-07-30 13:54:45 +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.
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/ast/scopes.h"
|
2014-08-28 17:53:24 +00:00
|
|
|
#include "src/compiler/access-builder.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/control-builders.h"
|
2016-04-25 09:25:59 +00:00
|
|
|
#include "src/compiler/effect-control-linearizer.h"
|
2014-08-11 09:40:02 +00:00
|
|
|
#include "src/compiler/graph-visualizer.h"
|
2016-05-10 10:11:06 +00:00
|
|
|
#include "src/compiler/memory-optimizer.h"
|
2015-01-29 09:17:45 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/pipeline.h"
|
2014-08-11 09:40:02 +00:00
|
|
|
#include "src/compiler/representation-change.h"
|
2016-04-25 09:25:59 +00:00
|
|
|
#include "src/compiler/scheduler.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/simplified-lowering.h"
|
2015-02-05 13:16:48 +00:00
|
|
|
#include "src/compiler/source-position.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/typer.h"
|
|
|
|
#include "src/compiler/verifier.h"
|
|
|
|
#include "src/execution.h"
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/parsing/parser.h"
|
|
|
|
#include "src/parsing/rewriter.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/compiler/codegen-tester.h"
|
2015-05-04 12:07:12 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/compiler/graph-builder-tester.h"
|
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
template <typename ReturnType>
|
2014-08-11 09:40:02 +00:00
|
|
|
class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester(MachineType p0 = MachineType::None(),
|
|
|
|
MachineType p1 = MachineType::None())
|
2015-06-01 15:54:53 +00:00
|
|
|
: GraphBuilderTester<ReturnType>(p0, p1),
|
2016-06-29 10:29:37 +00:00
|
|
|
typer(new Typer(this->isolate(), this->graph())),
|
2014-09-12 11:06:37 +00:00
|
|
|
javascript(this->zone()),
|
2015-01-23 15:19:34 +00:00
|
|
|
jsgraph(this->isolate(), this->graph(), this->common(), &javascript,
|
2015-10-19 08:05:05 +00:00
|
|
|
this->simplified(), this->machine()),
|
2015-02-05 13:16:48 +00:00
|
|
|
source_positions(jsgraph.graph()),
|
|
|
|
lowering(&jsgraph, this->zone(), &source_positions) {}
|
2016-06-29 10:29:37 +00:00
|
|
|
~SimplifiedLoweringTester() final { delete typer; }
|
2014-08-01 08:16:19 +00:00
|
|
|
|
2016-06-29 10:29:37 +00:00
|
|
|
Typer* typer = nullptr;
|
2014-09-12 11:06:37 +00:00
|
|
|
JSOperatorBuilder javascript;
|
2014-08-01 08:16:19 +00:00
|
|
|
JSGraph jsgraph;
|
2015-02-05 13:16:48 +00:00
|
|
|
SourcePositionTable source_positions;
|
2014-08-01 08:16:19 +00:00
|
|
|
SimplifiedLowering lowering;
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
void LowerAllNodes() {
|
2014-07-30 13:54:45 +00:00
|
|
|
this->End();
|
2016-06-29 10:29:37 +00:00
|
|
|
typer->Run();
|
|
|
|
delete typer, typer = nullptr;
|
2014-08-11 09:40:02 +00:00
|
|
|
lowering.LowerAllNodes();
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 12:18:39 +00:00
|
|
|
void LowerAllNodesAndLowerChanges() {
|
|
|
|
this->End();
|
2016-06-29 10:29:37 +00:00
|
|
|
typer->Run();
|
|
|
|
delete typer, typer = nullptr;
|
2014-10-07 12:18:39 +00:00
|
|
|
lowering.LowerAllNodes();
|
|
|
|
|
2016-04-25 09:25:59 +00:00
|
|
|
Schedule* schedule = Scheduler::ComputeSchedule(this->zone(), this->graph(),
|
|
|
|
Scheduler::kNoFlags);
|
|
|
|
EffectControlLinearizer linearizer(&jsgraph, schedule, this->zone());
|
|
|
|
linearizer.Run();
|
|
|
|
|
2016-05-10 10:11:06 +00:00
|
|
|
MemoryOptimizer memory_optimizer(&jsgraph, this->zone());
|
|
|
|
memory_optimizer.Optimize();
|
2014-10-07 12:18:39 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 10:53:46 +00:00
|
|
|
void CheckNumberCall(double expected, double input) {
|
|
|
|
// TODO(titzer): make calls to NewNumber work in cctests.
|
|
|
|
if (expected <= Smi::kMinValue) return;
|
|
|
|
if (expected >= Smi::kMaxValue) return;
|
|
|
|
Handle<Object> num = factory()->NewNumber(input);
|
|
|
|
Object* result = this->Call(*num);
|
|
|
|
CHECK(factory()->NewNumber(expected)->SameValue(result));
|
|
|
|
}
|
|
|
|
|
2015-05-04 12:07:12 +00:00
|
|
|
template <typename T>
|
|
|
|
T* CallWithPotentialGC() {
|
|
|
|
// TODO(titzer): we wrap the code in a JSFunction here to reuse the
|
|
|
|
// JSEntryStub; that could be done with a special prologue or other stub.
|
2015-12-02 12:35:12 +00:00
|
|
|
Handle<JSFunction> fun = FunctionTester::ForMachineGraph(this->graph(), 0);
|
2015-05-04 12:07:12 +00:00
|
|
|
Handle<Object>* args = NULL;
|
|
|
|
MaybeHandle<Object> result = Execution::Call(
|
2015-09-17 17:11:38 +00:00
|
|
|
this->isolate(), fun, factory()->undefined_value(), 0, args);
|
2015-05-04 12:07:12 +00:00
|
|
|
return T::cast(*result.ToHandleChecked());
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
Factory* factory() { return this->isolate()->factory(); }
|
|
|
|
Heap* heap() { return this->isolate()->heap(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-28 13:31:55 +00:00
|
|
|
// TODO(titzer): factor these tests out to test-run-simplifiedops.cc.
|
|
|
|
// TODO(titzer): test tagged representation for input to NumberToInt32.
|
|
|
|
TEST(RunNumberToInt32_float64) {
|
|
|
|
// TODO(titzer): explicit load/stores here are only because of representations
|
|
|
|
double input;
|
|
|
|
int32_t result;
|
|
|
|
SimplifiedLoweringTester<Object*> t;
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess load = {kUntaggedBase, 0,
|
|
|
|
Handle<Name>(), Type::Number(),
|
|
|
|
MachineType::Float64(), kNoWriteBarrier};
|
2014-08-28 13:31:55 +00:00
|
|
|
Node* loaded = t.LoadField(load, t.PointerConstant(&input));
|
2015-09-16 11:55:27 +00:00
|
|
|
NodeProperties::SetType(loaded, Type::Number());
|
2014-08-28 13:31:55 +00:00
|
|
|
Node* convert = t.NumberToInt32(loaded);
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess store = {kUntaggedBase, 0,
|
|
|
|
Handle<Name>(), Type::Signed32(),
|
|
|
|
MachineType::Int32(), kNoWriteBarrier};
|
2014-08-28 13:31:55 +00:00
|
|
|
t.StoreField(store, t.PointerConstant(&result), convert);
|
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-28 13:31:55 +00:00
|
|
|
t.GenerateCode();
|
|
|
|
|
|
|
|
FOR_FLOAT64_INPUTS(i) {
|
|
|
|
input = *i;
|
|
|
|
int32_t expected = DoubleToInt32(*i);
|
|
|
|
t.Call();
|
|
|
|
CHECK_EQ(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(titzer): test tagged representation for input to NumberToUint32.
|
|
|
|
TEST(RunNumberToUint32_float64) {
|
|
|
|
// TODO(titzer): explicit load/stores here are only because of representations
|
|
|
|
double input;
|
|
|
|
uint32_t result;
|
|
|
|
SimplifiedLoweringTester<Object*> t;
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess load = {kUntaggedBase, 0,
|
|
|
|
Handle<Name>(), Type::Number(),
|
|
|
|
MachineType::Float64(), kNoWriteBarrier};
|
2014-08-28 13:31:55 +00:00
|
|
|
Node* loaded = t.LoadField(load, t.PointerConstant(&input));
|
2015-09-16 11:55:27 +00:00
|
|
|
NodeProperties::SetType(loaded, Type::Number());
|
2014-08-28 13:31:55 +00:00
|
|
|
Node* convert = t.NumberToUint32(loaded);
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess store = {kUntaggedBase, 0,
|
|
|
|
Handle<Name>(), Type::Unsigned32(),
|
|
|
|
MachineType::Uint32(), kNoWriteBarrier};
|
2014-08-28 13:31:55 +00:00
|
|
|
t.StoreField(store, t.PointerConstant(&result), convert);
|
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-28 13:31:55 +00:00
|
|
|
t.GenerateCode();
|
|
|
|
|
|
|
|
FOR_FLOAT64_INPUTS(i) {
|
|
|
|
input = *i;
|
|
|
|
uint32_t expected = DoubleToUint32(*i);
|
|
|
|
t.Call();
|
|
|
|
CHECK_EQ(static_cast<int32_t>(expected), static_cast<int32_t>(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Create a simple JSObject with a unique map.
|
|
|
|
static Handle<JSObject> TestObject() {
|
|
|
|
static int index = 0;
|
|
|
|
char buffer[50];
|
|
|
|
v8::base::OS::SNPrintF(buffer, 50, "({'a_%d':1})", index++);
|
|
|
|
return Handle<JSObject>::cast(v8::Utils::OpenHandle(*CompileRun(buffer)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadMap) {
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged());
|
2014-08-28 17:53:24 +00:00
|
|
|
FieldAccess access = AccessBuilder::ForMap();
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* load = t.LoadField(access, t.Parameter(0));
|
|
|
|
t.Return(load);
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-08-10 07:17:16 +00:00
|
|
|
Handle<JSObject> src = TestObject();
|
|
|
|
Handle<Map> src_map(src->map());
|
|
|
|
Object* result = t.Call(*src); // TODO(titzer): raw pointers in call
|
|
|
|
CHECK_EQ(*src_map, result);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunStoreMap) {
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<int32_t> t(MachineType::AnyTagged(),
|
|
|
|
MachineType::AnyTagged());
|
2014-08-28 17:53:24 +00:00
|
|
|
FieldAccess access = AccessBuilder::ForMap();
|
2014-07-30 13:54:45 +00:00
|
|
|
t.StoreField(access, t.Parameter(1), t.Parameter(0));
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
Handle<JSObject> src = TestObject();
|
|
|
|
Handle<Map> src_map(src->map());
|
|
|
|
Handle<JSObject> dst = TestObject();
|
|
|
|
CHECK(src->map() != dst->map());
|
|
|
|
t.Call(*src_map, *dst); // TODO(titzer): raw pointers in call
|
|
|
|
CHECK(*src_map == dst->map());
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadProperties) {
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged());
|
2014-08-28 17:53:24 +00:00
|
|
|
FieldAccess access = AccessBuilder::ForJSObjectProperties();
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* load = t.LoadField(access, t.Parameter(0));
|
|
|
|
t.Return(load);
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
Handle<JSObject> src = TestObject();
|
|
|
|
Handle<FixedArray> src_props(src->properties());
|
|
|
|
Object* result = t.Call(*src); // TODO(titzer): raw pointers in call
|
|
|
|
CHECK_EQ(*src_props, result);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadStoreMap) {
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged(),
|
|
|
|
MachineType::AnyTagged());
|
2014-08-28 17:53:24 +00:00
|
|
|
FieldAccess access = AccessBuilder::ForMap();
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* load = t.LoadField(access, t.Parameter(0));
|
|
|
|
t.StoreField(access, t.Parameter(1), load);
|
|
|
|
t.Return(load);
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
Handle<JSObject> src = TestObject();
|
|
|
|
Handle<Map> src_map(src->map());
|
|
|
|
Handle<JSObject> dst = TestObject();
|
|
|
|
CHECK(src->map() != dst->map());
|
|
|
|
Object* result = t.Call(*src, *dst); // TODO(titzer): raw pointers in call
|
|
|
|
CHECK(result->IsMap());
|
|
|
|
CHECK_EQ(*src_map, result);
|
|
|
|
CHECK(*src_map == dst->map());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadStoreFixedArrayIndex) {
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged());
|
2014-08-28 17:53:24 +00:00
|
|
|
ElementAccess access = AccessBuilder::ForFixedArrayElement();
|
2014-12-02 04:48:57 +00:00
|
|
|
Node* load = t.LoadElement(access, t.Parameter(0), t.Int32Constant(0));
|
|
|
|
t.StoreElement(access, t.Parameter(0), t.Int32Constant(1), load);
|
2014-07-30 13:54:45 +00:00
|
|
|
t.Return(load);
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
Handle<FixedArray> array = t.factory()->NewFixedArray(2);
|
|
|
|
Handle<JSObject> src = TestObject();
|
|
|
|
Handle<JSObject> dst = TestObject();
|
|
|
|
array->set(0, *src);
|
|
|
|
array->set(1, *dst);
|
|
|
|
Object* result = t.Call(*array);
|
|
|
|
CHECK_EQ(*src, result);
|
|
|
|
CHECK_EQ(*src, array->get(0));
|
|
|
|
CHECK_EQ(*src, array->get(1));
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadStoreArrayBuffer) {
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged());
|
2014-07-30 13:54:45 +00:00
|
|
|
const int index = 12;
|
2014-09-24 09:28:56 +00:00
|
|
|
const int array_length = 2 * index;
|
2014-08-28 17:53:24 +00:00
|
|
|
ElementAccess buffer_access =
|
2015-04-20 13:31:38 +00:00
|
|
|
AccessBuilder::ForTypedArrayElement(kExternalInt8Array, true);
|
2014-08-28 17:53:24 +00:00
|
|
|
Node* backing_store = t.LoadField(
|
|
|
|
AccessBuilder::ForJSArrayBufferBackingStore(), t.Parameter(0));
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* load =
|
2014-12-02 04:48:57 +00:00
|
|
|
t.LoadElement(buffer_access, backing_store, t.Int32Constant(index));
|
2014-07-30 13:54:45 +00:00
|
|
|
t.StoreElement(buffer_access, backing_store, t.Int32Constant(index + 1),
|
2014-12-02 04:48:57 +00:00
|
|
|
load);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
Handle<JSArrayBuffer> array = t.factory()->NewJSArrayBuffer();
|
2015-08-26 13:59:35 +00:00
|
|
|
JSArrayBuffer::SetupAllocatingData(array, t.isolate(), array_length);
|
2014-08-11 09:40:02 +00:00
|
|
|
uint8_t* data = reinterpret_cast<uint8_t*>(array->backing_store());
|
|
|
|
for (int i = 0; i < array_length; i++) {
|
|
|
|
data[i] = i;
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
// TODO(titzer): raw pointers in call
|
|
|
|
Object* result = t.Call(*array);
|
|
|
|
CHECK_EQ(t.isolate()->heap()->true_value(), result);
|
|
|
|
for (int i = 0; i < array_length; i++) {
|
|
|
|
uint8_t expected = i;
|
|
|
|
if (i == (index + 1)) expected = index;
|
|
|
|
CHECK_EQ(data[i], expected);
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
2014-08-04 12:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadFieldFromUntaggedBase) {
|
|
|
|
Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3)};
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(smis); i++) {
|
2014-08-04 13:27:33 +00:00
|
|
|
int offset = static_cast<int>(i * sizeof(Smi*));
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {kUntaggedBase,
|
|
|
|
offset,
|
|
|
|
Handle<Name>(),
|
|
|
|
Type::Integral32(),
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
kNoWriteBarrier};
|
2014-08-04 12:39:15 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t;
|
2014-08-04 12:39:15 +00:00
|
|
|
Node* load = t.LoadField(access, t.PointerConstant(smis));
|
|
|
|
t.Return(load);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-04 12:39:15 +00:00
|
|
|
|
|
|
|
for (int j = -5; j <= 5; j++) {
|
|
|
|
Smi* expected = Smi::FromInt(j);
|
|
|
|
smis[i] = expected;
|
|
|
|
CHECK_EQ(expected, t.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunStoreFieldToUntaggedBase) {
|
|
|
|
Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3)};
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(smis); i++) {
|
2014-08-04 13:27:33 +00:00
|
|
|
int offset = static_cast<int>(i * sizeof(Smi*));
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {kUntaggedBase,
|
|
|
|
offset,
|
|
|
|
Handle<Name>(),
|
|
|
|
Type::Integral32(),
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
kNoWriteBarrier};
|
2014-08-04 12:39:15 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged());
|
2014-08-04 12:39:15 +00:00
|
|
|
Node* p0 = t.Parameter(0);
|
|
|
|
t.StoreField(access, t.PointerConstant(smis), p0);
|
|
|
|
t.Return(p0);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-04 12:39:15 +00:00
|
|
|
|
|
|
|
for (int j = -5; j <= 5; j++) {
|
|
|
|
Smi* expected = Smi::FromInt(j);
|
|
|
|
smis[i] = Smi::FromInt(-100);
|
|
|
|
CHECK_EQ(expected, t.Call(expected));
|
|
|
|
CHECK_EQ(expected, smis[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunLoadElementFromUntaggedBase) {
|
|
|
|
Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3),
|
|
|
|
Smi::FromInt(4), Smi::FromInt(5)};
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(smis); i++) { // for header sizes
|
|
|
|
for (size_t j = 0; (i + j) < arraysize(smis); j++) { // for element index
|
2014-08-04 13:27:33 +00:00
|
|
|
int offset = static_cast<int>(i * sizeof(Smi*));
|
2014-12-02 04:48:57 +00:00
|
|
|
ElementAccess access = {kUntaggedBase, offset, Type::Integral32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
2014-08-04 12:39:15 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t;
|
2014-12-02 04:48:57 +00:00
|
|
|
Node* load = t.LoadElement(access, t.PointerConstant(smis),
|
|
|
|
t.Int32Constant(static_cast<int>(j)));
|
2014-08-04 12:39:15 +00:00
|
|
|
t.Return(load);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-04 12:39:15 +00:00
|
|
|
|
|
|
|
for (int k = -5; k <= 5; k++) {
|
|
|
|
Smi* expected = Smi::FromInt(k);
|
|
|
|
smis[i + j] = expected;
|
|
|
|
CHECK_EQ(expected, t.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunStoreElementFromUntaggedBase) {
|
|
|
|
Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3),
|
|
|
|
Smi::FromInt(4), Smi::FromInt(5)};
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(smis); i++) { // for header sizes
|
|
|
|
for (size_t j = 0; (i + j) < arraysize(smis); j++) { // for element index
|
2014-08-04 13:27:33 +00:00
|
|
|
int offset = static_cast<int>(i * sizeof(Smi*));
|
2014-12-02 04:48:57 +00:00
|
|
|
ElementAccess access = {kUntaggedBase, offset, Type::Integral32(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
2014-08-04 12:39:15 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t(MachineType::AnyTagged());
|
2014-08-04 12:39:15 +00:00
|
|
|
Node* p0 = t.Parameter(0);
|
2014-08-04 13:27:33 +00:00
|
|
|
t.StoreElement(access, t.PointerConstant(smis),
|
2014-12-02 04:48:57 +00:00
|
|
|
t.Int32Constant(static_cast<int>(j)), p0);
|
2014-08-04 12:39:15 +00:00
|
|
|
t.Return(p0);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-04 12:39:15 +00:00
|
|
|
|
|
|
|
for (int k = -5; k <= 5; k++) {
|
|
|
|
Smi* expected = Smi::FromInt(k);
|
|
|
|
smis[i + j] = Smi::FromInt(-100);
|
|
|
|
CHECK_EQ(expected, t.Call(expected));
|
|
|
|
CHECK_EQ(expected, smis[i + j]);
|
|
|
|
}
|
2014-08-04 14:17:52 +00:00
|
|
|
|
|
|
|
// TODO(titzer): assert the contents of the array.
|
2014-08-04 12:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
// A helper class for accessing fields and elements of various types, on both
|
|
|
|
// tagged and untagged base pointers. Contains both tagged and untagged buffers
|
|
|
|
// for testing direct memory access from generated code.
|
|
|
|
template <typename E>
|
|
|
|
class AccessTester : public HandleAndZoneScope {
|
|
|
|
public:
|
|
|
|
bool tagged;
|
2014-08-11 15:55:28 +00:00
|
|
|
MachineType rep;
|
2014-08-11 09:40:02 +00:00
|
|
|
E* original_elements;
|
|
|
|
size_t num_elements;
|
|
|
|
E* untagged_array;
|
|
|
|
Handle<ByteArray> tagged_array; // TODO(titzer): use FixedArray for tagged.
|
|
|
|
|
2014-08-11 15:55:28 +00:00
|
|
|
AccessTester(bool t, MachineType r, E* orig, size_t num)
|
2014-08-11 09:40:02 +00:00
|
|
|
: tagged(t),
|
|
|
|
rep(r),
|
|
|
|
original_elements(orig),
|
|
|
|
num_elements(num),
|
|
|
|
untagged_array(static_cast<E*>(malloc(ByteSize()))),
|
2014-08-11 10:06:36 +00:00
|
|
|
tagged_array(main_isolate()->factory()->NewByteArray(
|
|
|
|
static_cast<int>(ByteSize()))) {
|
2014-08-11 09:40:02 +00:00
|
|
|
Reinitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AccessTester() { free(untagged_array); }
|
|
|
|
|
|
|
|
size_t ByteSize() { return num_elements * sizeof(E); }
|
|
|
|
|
|
|
|
// Nuke both {untagged_array} and {tagged_array} with {original_elements}.
|
|
|
|
void Reinitialize() {
|
|
|
|
memcpy(untagged_array, original_elements, ByteSize());
|
2014-08-11 10:06:36 +00:00
|
|
|
CHECK_EQ(static_cast<int>(ByteSize()), tagged_array->length());
|
2014-08-11 09:40:02 +00:00
|
|
|
E* raw = reinterpret_cast<E*>(tagged_array->GetDataStartAddress());
|
|
|
|
memcpy(raw, original_elements, ByteSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create and run code that copies the element in either {untagged_array}
|
|
|
|
// or {tagged_array} at index {from_index} to index {to_index}.
|
|
|
|
void RunCopyElement(int from_index, int to_index) {
|
|
|
|
// TODO(titzer): test element and field accesses where the base is not
|
|
|
|
// a constant in the code.
|
|
|
|
BoundsCheck(from_index);
|
|
|
|
BoundsCheck(to_index);
|
|
|
|
ElementAccess access = GetElementAccess();
|
|
|
|
|
|
|
|
SimplifiedLoweringTester<Object*> t;
|
|
|
|
Node* ptr = GetBaseNode(&t);
|
2014-12-02 04:48:57 +00:00
|
|
|
Node* load = t.LoadElement(access, ptr, t.Int32Constant(from_index));
|
|
|
|
t.StoreElement(access, ptr, t.Int32Constant(to_index), load);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Object* result = t.Call();
|
|
|
|
CHECK_EQ(t.isolate()->heap()->true_value(), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create and run code that copies the field in either {untagged_array}
|
|
|
|
// or {tagged_array} at index {from_index} to index {to_index}.
|
|
|
|
void RunCopyField(int from_index, int to_index) {
|
|
|
|
BoundsCheck(from_index);
|
|
|
|
BoundsCheck(to_index);
|
|
|
|
FieldAccess from_access = GetFieldAccess(from_index);
|
|
|
|
FieldAccess to_access = GetFieldAccess(to_index);
|
|
|
|
|
|
|
|
SimplifiedLoweringTester<Object*> t;
|
|
|
|
Node* ptr = GetBaseNode(&t);
|
|
|
|
Node* load = t.LoadField(from_access, ptr);
|
|
|
|
t.StoreField(to_access, ptr, load);
|
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Object* result = t.Call();
|
|
|
|
CHECK_EQ(t.isolate()->heap()->true_value(), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create and run code that copies the elements from {this} to {that}.
|
|
|
|
void RunCopyElements(AccessTester<E>* that) {
|
2014-09-04 10:23:51 +00:00
|
|
|
// TODO(titzer): Rewrite this test without StructuredGraphBuilder support.
|
|
|
|
#if 0
|
2014-08-11 09:40:02 +00:00
|
|
|
SimplifiedLoweringTester<Object*> t;
|
|
|
|
|
|
|
|
Node* one = t.Int32Constant(1);
|
|
|
|
Node* index = t.Int32Constant(0);
|
|
|
|
Node* limit = t.Int32Constant(static_cast<int>(num_elements));
|
|
|
|
t.environment()->Push(index);
|
|
|
|
Node* src = this->GetBaseNode(&t);
|
|
|
|
Node* dst = that->GetBaseNode(&t);
|
|
|
|
{
|
|
|
|
LoopBuilder loop(&t);
|
|
|
|
loop.BeginLoop();
|
|
|
|
// Loop exit condition
|
|
|
|
index = t.environment()->Top();
|
|
|
|
Node* condition = t.Int32LessThan(index, limit);
|
|
|
|
loop.BreakUnless(condition);
|
|
|
|
// dst[index] = src[index]
|
|
|
|
index = t.environment()->Pop();
|
|
|
|
Node* load = t.LoadElement(this->GetElementAccess(), src, index);
|
|
|
|
t.StoreElement(that->GetElementAccess(), dst, index, load);
|
|
|
|
// index++
|
|
|
|
index = t.Int32Add(index, one);
|
|
|
|
t.environment()->Push(index);
|
|
|
|
// continue
|
|
|
|
loop.EndBody();
|
|
|
|
loop.EndLoop();
|
|
|
|
}
|
|
|
|
index = t.environment()->Pop();
|
|
|
|
t.Return(t.jsgraph.TrueConstant());
|
|
|
|
t.LowerAllNodes();
|
2014-08-12 08:06:02 +00:00
|
|
|
t.GenerateCode();
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Object* result = t.Call();
|
|
|
|
CHECK_EQ(t.isolate()->heap()->true_value(), result);
|
2014-09-04 10:23:51 +00:00
|
|
|
#endif
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
E GetElement(int index) {
|
|
|
|
BoundsCheck(index);
|
|
|
|
if (tagged) {
|
2015-06-18 19:48:23 +00:00
|
|
|
return GetTaggedElement(index);
|
2014-08-11 09:40:02 +00:00
|
|
|
} else {
|
|
|
|
return untagged_array[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ElementAccess GetElementAccess() {
|
2014-12-02 04:48:57 +00:00
|
|
|
ElementAccess access = {tagged ? kTaggedBase : kUntaggedBase,
|
|
|
|
tagged ? FixedArrayBase::kHeaderSize : 0,
|
2016-05-06 10:20:01 +00:00
|
|
|
Type::Any(), rep, kFullWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
return access;
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldAccess GetFieldAccess(int field) {
|
|
|
|
int offset = field * sizeof(E);
|
|
|
|
FieldAccess access = {tagged ? kTaggedBase : kUntaggedBase,
|
|
|
|
offset + (tagged ? FixedArrayBase::kHeaderSize : 0),
|
2016-05-06 10:20:01 +00:00
|
|
|
Handle<Name>(),
|
|
|
|
Type::Any(),
|
|
|
|
rep,
|
|
|
|
kFullWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
return access;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
Node* GetBaseNode(SimplifiedLoweringTester<T>* t) {
|
|
|
|
return tagged ? t->HeapConstant(tagged_array)
|
|
|
|
: t->PointerConstant(untagged_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoundsCheck(int index) {
|
|
|
|
CHECK_GE(index, 0);
|
|
|
|
CHECK_LT(index, static_cast<int>(num_elements));
|
2014-08-11 10:06:36 +00:00
|
|
|
CHECK_EQ(static_cast<int>(ByteSize()), tagged_array->length());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
2015-06-18 19:48:23 +00:00
|
|
|
|
|
|
|
E GetTaggedElement(int index) {
|
|
|
|
E* raw = reinterpret_cast<E*>(tagged_array->GetDataStartAddress());
|
|
|
|
return raw[index];
|
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
};
|
|
|
|
|
2015-06-18 19:48:23 +00:00
|
|
|
template <>
|
|
|
|
double AccessTester<double>::GetTaggedElement(int index) {
|
|
|
|
return ReadDoubleValue(tagged_array->GetDataStartAddress() +
|
|
|
|
index * sizeof(double));
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
template <typename E>
|
2014-08-11 15:55:28 +00:00
|
|
|
static void RunAccessTest(MachineType rep, E* original_elements, size_t num) {
|
2014-08-11 09:40:02 +00:00
|
|
|
int num_elements = static_cast<int>(num);
|
|
|
|
|
|
|
|
for (int taggedness = 0; taggedness < 2; taggedness++) {
|
|
|
|
AccessTester<E> a(taggedness == 1, rep, original_elements, num);
|
|
|
|
for (int field = 0; field < 2; field++) {
|
|
|
|
for (int i = 0; i < num_elements - 1; i++) {
|
|
|
|
a.Reinitialize();
|
|
|
|
if (field == 0) {
|
|
|
|
a.RunCopyField(i, i + 1); // Test field read/write.
|
|
|
|
} else {
|
|
|
|
a.RunCopyElement(i, i + 1); // Test element read/write.
|
|
|
|
}
|
|
|
|
for (int j = 0; j < num_elements; j++) {
|
|
|
|
E expect =
|
|
|
|
j == (i + 1) ? original_elements[i] : original_elements[j];
|
|
|
|
CHECK_EQ(expect, a.GetElement(j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Test array copy.
|
|
|
|
for (int tf = 0; tf < 2; tf++) {
|
|
|
|
for (int tt = 0; tt < 2; tt++) {
|
|
|
|
AccessTester<E> a(tf == 1, rep, original_elements, num);
|
|
|
|
AccessTester<E> b(tt == 1, rep, original_elements, num);
|
|
|
|
a.RunCopyElements(&b);
|
|
|
|
for (int i = 0; i < num_elements; i++) {
|
|
|
|
CHECK_EQ(a.GetElement(i), b.GetElement(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunAccessTests_uint8) {
|
|
|
|
uint8_t data[] = {0x07, 0x16, 0x25, 0x34, 0x43, 0x99,
|
|
|
|
0xab, 0x78, 0x89, 0x19, 0x2b, 0x38};
|
2015-12-10 09:03:30 +00:00
|
|
|
RunAccessTest<uint8_t>(MachineType::Int8(), data, arraysize(data));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunAccessTests_uint16) {
|
|
|
|
uint16_t data[] = {0x071a, 0x162b, 0x253c, 0x344d, 0x435e, 0x7777};
|
2015-12-10 09:03:30 +00:00
|
|
|
RunAccessTest<uint16_t>(MachineType::Int16(), data, arraysize(data));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunAccessTests_int32) {
|
|
|
|
int32_t data[] = {-211, 211, 628347, 2000000000, -2000000000, -1, -100000034};
|
2015-12-10 09:03:30 +00:00
|
|
|
RunAccessTest<int32_t>(MachineType::Int32(), data, arraysize(data));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define V8_2PART_INT64(a, b) (((static_cast<int64_t>(a) << 32) + 0x##b##u))
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunAccessTests_int64) {
|
|
|
|
if (kPointerSize != 8) return;
|
|
|
|
int64_t data[] = {V8_2PART_INT64(0x10111213, 14151617),
|
|
|
|
V8_2PART_INT64(0x20212223, 24252627),
|
|
|
|
V8_2PART_INT64(0x30313233, 34353637),
|
|
|
|
V8_2PART_INT64(0xa0a1a2a3, a4a5a6a7),
|
|
|
|
V8_2PART_INT64(0xf0f1f2f3, f4f5f6f7)};
|
2015-12-10 09:03:30 +00:00
|
|
|
RunAccessTest<int64_t>(MachineType::Int64(), data, arraysize(data));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunAccessTests_float64) {
|
|
|
|
double data[] = {1.25, -1.25, 2.75, 11.0, 11100.8};
|
2015-12-10 09:03:30 +00:00
|
|
|
RunAccessTest<double>(MachineType::Float64(), data, arraysize(data));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RunAccessTests_Smi) {
|
|
|
|
Smi* data[] = {Smi::FromInt(-1), Smi::FromInt(-9),
|
|
|
|
Smi::FromInt(0), Smi::FromInt(666),
|
|
|
|
Smi::FromInt(77777), Smi::FromInt(Smi::kMaxValue)};
|
2015-12-10 09:03:30 +00:00
|
|
|
RunAccessTest<Smi*>(MachineType::AnyTagged(), data, arraysize(data));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 07:17:16 +00:00
|
|
|
|
2015-05-04 12:07:12 +00:00
|
|
|
TEST(RunAllocate) {
|
|
|
|
PretenureFlag flag[] = {NOT_TENURED, TENURED};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(flag); i++) {
|
|
|
|
SimplifiedLoweringTester<HeapObject*> t;
|
|
|
|
FieldAccess access = AccessBuilder::ForMap();
|
|
|
|
Node* size = t.jsgraph.Constant(HeapNumber::kSize);
|
|
|
|
Node* alloc = t.NewNode(t.simplified()->Allocate(flag[i]), size);
|
|
|
|
Node* map = t.jsgraph.Constant(t.factory()->heap_number_map());
|
|
|
|
t.StoreField(access, alloc, map);
|
|
|
|
t.Return(alloc);
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2015-05-04 12:07:12 +00:00
|
|
|
t.GenerateCode();
|
|
|
|
|
|
|
|
HeapObject* result = t.CallWithPotentialGC<HeapObject>();
|
|
|
|
CHECK(t.heap()->new_space()->Contains(result) || flag[i] == TENURED);
|
|
|
|
CHECK(t.heap()->old_space()->Contains(result) || flag[i] == NOT_TENURED);
|
|
|
|
CHECK(result->IsHeapNumber());
|
|
|
|
}
|
|
|
|
}
|
2015-08-10 07:17:16 +00:00
|
|
|
|
2015-05-04 12:07:12 +00:00
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
// Fills in most of the nodes of the graph in order to make tests shorter.
|
|
|
|
class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders {
|
|
|
|
public:
|
2016-06-29 10:29:37 +00:00
|
|
|
Typer* typer = nullptr;
|
2014-09-12 11:06:37 +00:00
|
|
|
JSOperatorBuilder javascript;
|
2014-08-11 09:40:02 +00:00
|
|
|
JSGraph jsgraph;
|
|
|
|
Node* p0;
|
|
|
|
Node* p1;
|
2014-09-24 09:28:56 +00:00
|
|
|
Node* p2;
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* start;
|
|
|
|
Node* end;
|
|
|
|
Node* ret;
|
|
|
|
|
2014-09-24 09:28:56 +00:00
|
|
|
explicit TestingGraph(Type* p0_type, Type* p1_type = Type::None(),
|
|
|
|
Type* p2_type = Type::None())
|
2014-08-11 09:40:02 +00:00
|
|
|
: GraphAndBuilders(main_zone()),
|
2016-06-29 10:29:37 +00:00
|
|
|
typer(new Typer(main_isolate(), graph())),
|
2014-09-12 11:06:37 +00:00
|
|
|
javascript(main_zone()),
|
2015-10-19 08:05:05 +00:00
|
|
|
jsgraph(main_isolate(), graph(), common(), &javascript, simplified(),
|
2015-10-16 12:38:46 +00:00
|
|
|
machine()) {
|
2015-11-13 08:11:59 +00:00
|
|
|
start = graph()->NewNode(common()->Start(4));
|
2014-08-11 09:40:02 +00:00
|
|
|
graph()->SetStart(start);
|
|
|
|
ret =
|
|
|
|
graph()->NewNode(common()->Return(), jsgraph.Constant(0), start, start);
|
2015-05-26 10:31:55 +00:00
|
|
|
end = graph()->NewNode(common()->End(1), ret);
|
2014-08-11 09:40:02 +00:00
|
|
|
graph()->SetEnd(end);
|
|
|
|
p0 = graph()->NewNode(common()->Parameter(0), start);
|
|
|
|
p1 = graph()->NewNode(common()->Parameter(1), start);
|
2014-09-24 09:28:56 +00:00
|
|
|
p2 = graph()->NewNode(common()->Parameter(2), start);
|
2016-06-29 10:29:37 +00:00
|
|
|
typer->Run();
|
2015-09-16 11:55:27 +00:00
|
|
|
NodeProperties::SetType(p0, p0_type);
|
|
|
|
NodeProperties::SetType(p1, p1_type);
|
|
|
|
NodeProperties::SetType(p2, p2_type);
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
2016-06-29 10:29:37 +00:00
|
|
|
~TestingGraph() { delete typer; }
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
void CheckLoweringBinop(IrOpcode::Value expected, const Operator* op) {
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* node = Return(graph()->NewNode(op, p0, p1));
|
|
|
|
Lower();
|
|
|
|
CHECK_EQ(expected, node->opcode());
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:38:56 +00:00
|
|
|
void CheckLoweringStringBinop(IrOpcode::Value expected, const Operator* op) {
|
|
|
|
Node* node = Return(
|
|
|
|
graph()->NewNode(op, p0, p1, graph()->start(), graph()->start()));
|
|
|
|
Lower();
|
|
|
|
CHECK_EQ(expected, node->opcode());
|
|
|
|
}
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
void CheckLoweringTruncatedBinop(IrOpcode::Value expected, const Operator* op,
|
|
|
|
const Operator* trunc) {
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* node = graph()->NewNode(op, p0, p1);
|
|
|
|
Return(graph()->NewNode(trunc, node));
|
|
|
|
Lower();
|
|
|
|
CHECK_EQ(expected, node->opcode());
|
|
|
|
}
|
|
|
|
|
2015-02-05 13:16:48 +00:00
|
|
|
void Lower() {
|
2016-06-29 10:29:37 +00:00
|
|
|
delete typer;
|
2015-02-05 13:16:48 +00:00
|
|
|
SourcePositionTable table(jsgraph.graph());
|
|
|
|
SimplifiedLowering(&jsgraph, jsgraph.zone(), &table).LowerAllNodes();
|
2016-06-29 10:29:37 +00:00
|
|
|
typer = new Typer(main_isolate(), graph());
|
2015-02-05 13:16:48 +00:00
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
void LowerAllNodesAndLowerChanges() {
|
2016-06-29 10:29:37 +00:00
|
|
|
delete typer;
|
2015-11-13 08:11:59 +00:00
|
|
|
SourcePositionTable table(jsgraph.graph());
|
|
|
|
SimplifiedLowering(&jsgraph, jsgraph.zone(), &table).LowerAllNodes();
|
|
|
|
|
2016-04-25 09:25:59 +00:00
|
|
|
Schedule* schedule = Scheduler::ComputeSchedule(this->zone(), this->graph(),
|
|
|
|
Scheduler::kNoFlags);
|
|
|
|
EffectControlLinearizer linearizer(&jsgraph, schedule, this->zone());
|
|
|
|
linearizer.Run();
|
|
|
|
|
2016-05-10 10:11:06 +00:00
|
|
|
MemoryOptimizer memory_optimizer(&jsgraph, this->zone());
|
|
|
|
memory_optimizer.Optimize();
|
2016-06-29 10:29:37 +00:00
|
|
|
typer = new Typer(main_isolate(), graph());
|
2015-11-13 08:11:59 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
// Inserts the node as the return value of the graph.
|
|
|
|
Node* Return(Node* node) {
|
|
|
|
ret->ReplaceInput(0, node);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inserts the node as the effect input to the return of the graph.
|
|
|
|
void Effect(Node* node) { ret->ReplaceInput(1, node); }
|
|
|
|
|
2014-08-14 09:19:54 +00:00
|
|
|
Node* ExampleWithOutput(MachineType type) {
|
2015-12-10 09:03:30 +00:00
|
|
|
if (type.semantic() == MachineSemantic::kInt32) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Int32Add(), jsgraph.Int32Constant(1),
|
|
|
|
jsgraph.Int32Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.semantic() == MachineSemantic::kUint32) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Word32Shr(), jsgraph.Int32Constant(1),
|
|
|
|
jsgraph.Int32Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.representation() == MachineRepresentation::kFloat64) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Float64Add(),
|
|
|
|
jsgraph.Float64Constant(1),
|
|
|
|
jsgraph.Float64Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.representation() == MachineRepresentation::kBit) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Word32Equal(),
|
|
|
|
jsgraph.Int32Constant(1),
|
|
|
|
jsgraph.Int32Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.representation() == MachineRepresentation::kWord64) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Int64Add(), Int64Constant(1),
|
|
|
|
Int64Constant(1));
|
|
|
|
} else {
|
2015-12-10 09:03:30 +00:00
|
|
|
CHECK(type.representation() == MachineRepresentation::kTagged);
|
2014-08-11 09:40:02 +00:00
|
|
|
return p0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 09:19:54 +00:00
|
|
|
Node* Use(Node* node, MachineType type) {
|
2015-12-10 09:03:30 +00:00
|
|
|
if (type.semantic() == MachineSemantic::kInt32) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Int32LessThan(), node,
|
|
|
|
jsgraph.Int32Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.semantic() == MachineSemantic::kUint32) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Uint32LessThan(), node,
|
|
|
|
jsgraph.Int32Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.representation() == MachineRepresentation::kFloat64) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Float64Add(), node,
|
|
|
|
jsgraph.Float64Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.representation() == MachineRepresentation::kWord64) {
|
2014-08-11 09:40:02 +00:00
|
|
|
return graph()->NewNode(machine()->Int64LessThan(), node,
|
|
|
|
Int64Constant(1));
|
2015-12-10 09:03:30 +00:00
|
|
|
} else if (type.representation() == MachineRepresentation::kWord32) {
|
2014-11-10 14:28:09 +00:00
|
|
|
return graph()->NewNode(machine()->Word32Equal(), node,
|
|
|
|
jsgraph.Int32Constant(1));
|
2014-08-11 09:40:02 +00:00
|
|
|
} else {
|
|
|
|
return graph()->NewNode(simplified()->ReferenceEqual(Type::Any()), node,
|
|
|
|
jsgraph.TrueConstant());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* Branch(Node* cond) {
|
|
|
|
Node* br = graph()->NewNode(common()->Branch(), cond, start);
|
|
|
|
Node* tb = graph()->NewNode(common()->IfTrue(), br);
|
|
|
|
Node* fb = graph()->NewNode(common()->IfFalse(), br);
|
|
|
|
Node* m = graph()->NewNode(common()->Merge(2), tb, fb);
|
2014-08-12 12:20:39 +00:00
|
|
|
NodeProperties::ReplaceControlInput(ret, m);
|
2014-08-11 09:40:02 +00:00
|
|
|
return br;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* Int64Constant(int64_t v) {
|
|
|
|
return graph()->NewNode(common()->Int64Constant(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
SimplifiedOperatorBuilder* simplified() { return &main_simplified_; }
|
|
|
|
MachineOperatorBuilder* machine() { return &main_machine_; }
|
|
|
|
CommonOperatorBuilder* common() { return &main_common_; }
|
|
|
|
Graph* graph() { return main_graph_; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerBooleanNot_bit_bit) {
|
2014-08-14 09:19:54 +00:00
|
|
|
// BooleanNot(x: kRepBit) used as kRepBit
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Boolean());
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* b = t.ExampleWithOutput(MachineType::Bool());
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* inv = t.graph()->NewNode(t.simplified()->BooleanNot(), b);
|
|
|
|
Node* use = t.Branch(inv);
|
|
|
|
t.Lower();
|
|
|
|
Node* cmp = use->InputAt(0);
|
2014-10-23 10:22:06 +00:00
|
|
|
CHECK_EQ(t.machine()->Word32Equal()->opcode(), cmp->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK(b == cmp->InputAt(0) || b == cmp->InputAt(1));
|
|
|
|
Node* f = t.jsgraph.Int32Constant(0);
|
|
|
|
CHECK(f == cmp->InputAt(0) || f == cmp->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerBooleanNot_bit_tagged) {
|
2014-08-14 09:19:54 +00:00
|
|
|
// BooleanNot(x: kRepBit) used as kRepTagged
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Boolean());
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* b = t.ExampleWithOutput(MachineType::Bool());
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* inv = t.graph()->NewNode(t.simplified()->BooleanNot(), b);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(inv, MachineType::AnyTagged());
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-05-02 10:23:02 +00:00
|
|
|
CHECK_EQ(IrOpcode::kChangeBitToTagged, use->InputAt(0)->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* cmp = use->InputAt(0)->InputAt(0);
|
2014-10-23 10:22:06 +00:00
|
|
|
CHECK_EQ(t.machine()->Word32Equal()->opcode(), cmp->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK(b == cmp->InputAt(0) || b == cmp->InputAt(1));
|
|
|
|
Node* f = t.jsgraph.Int32Constant(0);
|
|
|
|
CHECK(f == cmp->InputAt(0) || f == cmp->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerBooleanNot_tagged_bit) {
|
2014-08-14 09:19:54 +00:00
|
|
|
// BooleanNot(x: kRepTagged) used as kRepBit
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Boolean());
|
|
|
|
Node* b = t.p0;
|
|
|
|
Node* inv = t.graph()->NewNode(t.simplified()->BooleanNot(), b);
|
|
|
|
Node* use = t.Branch(inv);
|
|
|
|
t.Lower();
|
|
|
|
Node* cmp = use->InputAt(0);
|
|
|
|
CHECK_EQ(t.machine()->WordEqual()->opcode(), cmp->opcode());
|
|
|
|
CHECK(b == cmp->InputAt(0) || b == cmp->InputAt(1));
|
|
|
|
Node* f = t.jsgraph.FalseConstant();
|
|
|
|
CHECK(f == cmp->InputAt(0) || f == cmp->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerBooleanNot_tagged_tagged) {
|
2014-08-14 09:19:54 +00:00
|
|
|
// BooleanNot(x: kRepTagged) used as kRepTagged
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Boolean());
|
|
|
|
Node* b = t.p0;
|
|
|
|
Node* inv = t.graph()->NewNode(t.simplified()->BooleanNot(), b);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(inv, MachineType::AnyTagged());
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-05-02 10:23:02 +00:00
|
|
|
CHECK_EQ(IrOpcode::kChangeBitToTagged, use->InputAt(0)->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* cmp = use->InputAt(0)->InputAt(0);
|
|
|
|
CHECK_EQ(t.machine()->WordEqual()->opcode(), cmp->opcode());
|
|
|
|
CHECK(b == cmp->InputAt(0) || b == cmp->InputAt(1));
|
|
|
|
Node* f = t.jsgraph.FalseConstant();
|
|
|
|
CHECK(f == cmp->InputAt(0) || f == cmp->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static Type* test_types[] = {Type::Signed32(), Type::Unsigned32(),
|
2016-03-22 06:50:16 +00:00
|
|
|
Type::Number()};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
TEST(LowerNumberCmp_to_int32) {
|
|
|
|
TestingGraph t(Type::Signed32(), Type::Signed32());
|
|
|
|
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kWord32Equal, t.simplified()->NumberEqual());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kInt32LessThan,
|
|
|
|
t.simplified()->NumberLessThan());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kInt32LessThanOrEqual,
|
|
|
|
t.simplified()->NumberLessThanOrEqual());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberCmp_to_uint32) {
|
|
|
|
TestingGraph t(Type::Unsigned32(), Type::Unsigned32());
|
|
|
|
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kWord32Equal, t.simplified()->NumberEqual());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kUint32LessThan,
|
|
|
|
t.simplified()->NumberLessThan());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kUint32LessThanOrEqual,
|
|
|
|
t.simplified()->NumberLessThanOrEqual());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberCmp_to_float64) {
|
2016-03-22 06:50:16 +00:00
|
|
|
TestingGraph t(Type::Number(), Type::Number());
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2016-03-22 06:50:16 +00:00
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64Equal, t.simplified()->NumberEqual());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64LessThan,
|
|
|
|
t.simplified()->NumberLessThan());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64LessThanOrEqual,
|
|
|
|
t.simplified()->NumberLessThanOrEqual());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberAddSub_to_int32) {
|
2014-10-23 14:40:43 +00:00
|
|
|
HandleAndZoneScope scope;
|
2015-01-28 13:55:35 +00:00
|
|
|
Type* small_range = Type::Range(1, 10, scope.main_zone());
|
|
|
|
Type* large_range = Type::Range(-1e+13, 1e+14, scope.main_zone());
|
2014-10-23 14:40:43 +00:00
|
|
|
static Type* types[] = {Type::Signed32(), Type::Integral32(), small_range,
|
|
|
|
large_range};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(types); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(types); j++) {
|
|
|
|
TestingGraph t(types[i], types[j]);
|
|
|
|
t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Add,
|
|
|
|
t.simplified()->NumberAdd(),
|
|
|
|
t.simplified()->NumberToInt32());
|
|
|
|
t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Sub,
|
|
|
|
t.simplified()->NumberSubtract(),
|
|
|
|
t.simplified()->NumberToInt32());
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberAddSub_to_uint32) {
|
2014-10-23 14:40:43 +00:00
|
|
|
HandleAndZoneScope scope;
|
2015-01-28 13:55:35 +00:00
|
|
|
Type* small_range = Type::Range(1, 10, scope.main_zone());
|
|
|
|
Type* large_range = Type::Range(-1e+13, 1e+14, scope.main_zone());
|
2014-10-23 14:40:43 +00:00
|
|
|
static Type* types[] = {Type::Signed32(), Type::Integral32(), small_range,
|
|
|
|
large_range};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(types); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(types); j++) {
|
|
|
|
TestingGraph t(types[i], types[j]);
|
|
|
|
t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Add,
|
|
|
|
t.simplified()->NumberAdd(),
|
|
|
|
t.simplified()->NumberToUint32());
|
|
|
|
t.CheckLoweringTruncatedBinop(IrOpcode::kInt32Sub,
|
|
|
|
t.simplified()->NumberSubtract(),
|
|
|
|
t.simplified()->NumberToUint32());
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberAddSub_to_float64) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(test_types); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(test_types[i], test_types[i]);
|
|
|
|
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64Add, t.simplified()->NumberAdd());
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64Sub,
|
|
|
|
t.simplified()->NumberSubtract());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberDivMod_to_float64) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(test_types); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(test_types[i], test_types[i]);
|
|
|
|
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64Div, t.simplified()->NumberDivide());
|
2014-10-31 07:58:49 +00:00
|
|
|
if (!test_types[i]->Is(Type::Unsigned32())) {
|
|
|
|
t.CheckLoweringBinop(IrOpcode::kFloat64Mod,
|
|
|
|
t.simplified()->NumberModulus());
|
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CheckChangeOf(IrOpcode::Value change, Node* of, Node* node) {
|
|
|
|
CHECK_EQ(change, node->opcode());
|
|
|
|
CHECK_EQ(of, node->InputAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerNumberToInt32_to_ChangeTaggedToInt32) {
|
2014-08-14 09:19:54 +00:00
|
|
|
// NumberToInt32(x: kRepTagged | kTypeInt32) used as kRepWord32
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), t.p0);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::Int32());
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
|
|
|
CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p0, use->InputAt(0));
|
|
|
|
}
|
|
|
|
|
2016-04-24 11:39:31 +00:00
|
|
|
TEST(LowerNumberToInt32_to_TruncateFloat64ToWord32) {
|
2015-12-10 09:03:30 +00:00
|
|
|
// NumberToInt32(x: kRepFloat64) used as MachineType::Int32()
|
2014-08-28 13:31:55 +00:00
|
|
|
TestingGraph t(Type::Number());
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* p0 = t.ExampleWithOutput(MachineType::Float64());
|
2014-08-28 13:31:55 +00:00
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), p0);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::Int32());
|
2014-08-28 13:31:55 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-04-24 11:39:31 +00:00
|
|
|
CheckChangeOf(IrOpcode::kTruncateFloat64ToWord32, p0, use->InputAt(0));
|
2014-08-28 13:31:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 11:39:31 +00:00
|
|
|
TEST(LowerNumberToInt32_to_TruncateTaggedToWord32) {
|
2015-12-10 09:03:30 +00:00
|
|
|
// NumberToInt32(x: kTypeNumber | kRepTagged) used as MachineType::Int32()
|
2014-08-28 13:31:55 +00:00
|
|
|
TestingGraph t(Type::Number());
|
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), t.p0);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::Int32());
|
2014-08-28 13:31:55 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-04-24 11:39:31 +00:00
|
|
|
CheckChangeOf(IrOpcode::kTruncateTaggedToWord32, t.p0, use->InputAt(0));
|
2014-08-28 13:31:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
TEST(LowerNumberToUint32_to_ChangeTaggedToUint32) {
|
2014-08-14 09:19:54 +00:00
|
|
|
// NumberToUint32(x: kRepTagged | kTypeUint32) used as kRepWord32
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Unsigned32());
|
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), t.p0);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::Uint32());
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
|
|
|
CheckChangeOf(IrOpcode::kChangeTaggedToUint32, t.p0, use->InputAt(0));
|
|
|
|
}
|
|
|
|
|
2016-04-24 11:39:31 +00:00
|
|
|
TEST(LowerNumberToUint32_to_TruncateFloat64ToWord32) {
|
2015-12-10 09:03:30 +00:00
|
|
|
// NumberToUint32(x: kRepFloat64) used as MachineType::Uint32()
|
2014-08-28 13:31:55 +00:00
|
|
|
TestingGraph t(Type::Number());
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* p0 = t.ExampleWithOutput(MachineType::Float64());
|
2014-10-07 12:18:39 +00:00
|
|
|
// TODO(titzer): run the typer here, or attach machine type to param.
|
2015-09-16 11:55:27 +00:00
|
|
|
NodeProperties::SetType(p0, Type::Number());
|
2014-08-28 13:31:55 +00:00
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), p0);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::Uint32());
|
2014-08-28 13:31:55 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-04-24 11:39:31 +00:00
|
|
|
CheckChangeOf(IrOpcode::kTruncateFloat64ToWord32, p0, use->InputAt(0));
|
2014-08-28 13:31:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 11:39:31 +00:00
|
|
|
TEST(LowerNumberToUint32_to_TruncateTaggedToWord32) {
|
2015-12-10 09:03:30 +00:00
|
|
|
// NumberToInt32(x: kTypeNumber | kRepTagged) used as MachineType::Uint32()
|
2014-08-28 13:31:55 +00:00
|
|
|
TestingGraph t(Type::Number());
|
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), t.p0);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::Uint32());
|
2014-08-28 13:31:55 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-04-24 11:39:31 +00:00
|
|
|
CheckChangeOf(IrOpcode::kTruncateTaggedToWord32, t.p0, use->InputAt(0));
|
2014-08-28 13:31:55 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 11:39:31 +00:00
|
|
|
TEST(LowerNumberToUint32_to_TruncateFloat64ToWord32_uint32) {
|
2014-11-10 14:28:09 +00:00
|
|
|
// NumberToUint32(x: kRepFloat64) used as kRepWord32
|
|
|
|
TestingGraph t(Type::Unsigned32());
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* input = t.ExampleWithOutput(MachineType::Float64());
|
2014-11-10 14:28:09 +00:00
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), input);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(trunc, MachineType::RepWord32());
|
2014-11-10 14:28:09 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2016-04-24 11:39:31 +00:00
|
|
|
CheckChangeOf(IrOpcode::kTruncateFloat64ToWord32, input, use->InputAt(0));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerReferenceEqual_to_wordeq) {
|
|
|
|
TestingGraph t(Type::Any(), Type::Any());
|
|
|
|
IrOpcode::Value opcode =
|
|
|
|
static_cast<IrOpcode::Value>(t.machine()->WordEqual()->opcode());
|
|
|
|
t.CheckLoweringBinop(opcode, t.simplified()->ReferenceEqual(Type::Any()));
|
|
|
|
}
|
|
|
|
|
2016-03-04 09:38:31 +00:00
|
|
|
void CheckChangeInsertion(IrOpcode::Value expected, MachineType from,
|
|
|
|
MachineType to, Type* type = Type::Any()) {
|
2014-08-11 09:40:02 +00:00
|
|
|
TestingGraph t(Type::Any());
|
|
|
|
Node* in = t.ExampleWithOutput(from);
|
2015-11-18 10:02:12 +00:00
|
|
|
NodeProperties::SetType(in, type);
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* use = t.Use(in, to);
|
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
|
|
|
CHECK_EQ(expected, use->InputAt(0)->opcode());
|
|
|
|
CHECK_EQ(in, use->InputAt(0)->InputAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(InsertBasicChanges) {
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeFloat64ToInt32, MachineType::Float64(),
|
|
|
|
MachineType::Int32(), Type::Signed32());
|
|
|
|
CheckChangeInsertion(IrOpcode::kChangeFloat64ToUint32, MachineType::Float64(),
|
|
|
|
MachineType::Uint32(), Type::Unsigned32());
|
2016-04-24 11:39:31 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kTruncateFloat64ToWord32,
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Float64(), MachineType::Uint32(),
|
|
|
|
Type::Integral32());
|
|
|
|
CheckChangeInsertion(IrOpcode::kChangeTaggedToInt32, MachineType::AnyTagged(),
|
|
|
|
MachineType::Int32(), Type::Signed32());
|
|
|
|
CheckChangeInsertion(IrOpcode::kChangeTaggedToUint32,
|
|
|
|
MachineType::AnyTagged(), MachineType::Uint32(),
|
2015-11-18 10:02:12 +00:00
|
|
|
Type::Unsigned32());
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeFloat64ToTagged, MachineType::Float64(),
|
2016-06-06 09:16:46 +00:00
|
|
|
MachineType::AnyTagged(), Type::Number());
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeTaggedToFloat64,
|
2016-03-22 06:50:16 +00:00
|
|
|
MachineType::AnyTagged(), MachineType::Float64(),
|
|
|
|
Type::Number());
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeInt32ToFloat64, MachineType::Int32(),
|
2016-03-21 06:28:36 +00:00
|
|
|
MachineType::Float64(), Type::Signed32());
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeInt32ToTagged, MachineType::Int32(),
|
2016-03-21 06:28:36 +00:00
|
|
|
MachineType::AnyTagged(), Type::Signed32());
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeUint32ToFloat64, MachineType::Uint32(),
|
2016-03-21 06:28:36 +00:00
|
|
|
MachineType::Float64(), Type::Unsigned32());
|
2015-12-10 09:03:30 +00:00
|
|
|
CheckChangeInsertion(IrOpcode::kChangeUint32ToTagged, MachineType::Uint32(),
|
2016-03-21 06:28:36 +00:00
|
|
|
MachineType::AnyTagged(), Type::Unsigned32());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
static void CheckChangesAroundBinop(TestingGraph* t, const Operator* op,
|
2014-08-11 09:40:02 +00:00
|
|
|
IrOpcode::Value input_change,
|
2016-07-20 08:48:51 +00:00
|
|
|
IrOpcode::Value output_change, Type* type) {
|
2015-09-23 09:08:15 +00:00
|
|
|
Node* binop =
|
|
|
|
op->ControlInputCount() == 0
|
|
|
|
? t->graph()->NewNode(op, t->p0, t->p1)
|
|
|
|
: t->graph()->NewNode(op, t->p0, t->p1, t->graph()->start());
|
2016-03-21 06:28:36 +00:00
|
|
|
NodeProperties::SetType(binop, type);
|
2014-08-11 09:40:02 +00:00
|
|
|
t->Return(binop);
|
|
|
|
t->Lower();
|
|
|
|
CHECK_EQ(input_change, binop->InputAt(0)->opcode());
|
|
|
|
CHECK_EQ(input_change, binop->InputAt(1)->opcode());
|
|
|
|
CHECK_EQ(t->p0, binop->InputAt(0)->InputAt(0));
|
|
|
|
CHECK_EQ(t->p1, binop->InputAt(1)->InputAt(0));
|
|
|
|
CHECK_EQ(output_change, t->ret->InputAt(0)->opcode());
|
|
|
|
CHECK_EQ(binop, t->ret->InputAt(0)->InputAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangesAroundInt32Binops) {
|
|
|
|
TestingGraph t(Type::Signed32(), Type::Signed32());
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* ops[] = {t.machine()->Int32Add(), t.machine()->Int32Sub(),
|
|
|
|
t.machine()->Int32Mul(), t.machine()->Int32Div(),
|
|
|
|
t.machine()->Int32Mod(), t.machine()->Word32And(),
|
|
|
|
t.machine()->Word32Or(), t.machine()->Word32Xor(),
|
|
|
|
t.machine()->Word32Shl(), t.machine()->Word32Sar()};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(ops); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
CheckChangesAroundBinop(&t, ops[i], IrOpcode::kChangeTaggedToInt32,
|
2016-03-21 06:28:36 +00:00
|
|
|
IrOpcode::kChangeInt32ToTagged, Type::Signed32());
|
|
|
|
CheckChangesAroundBinop(&t, ops[i], IrOpcode::kChangeTaggedToInt32,
|
|
|
|
IrOpcode::kChangeInt32ToTagged, Type::Signed32());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangesAroundInt32Cmp) {
|
|
|
|
TestingGraph t(Type::Signed32(), Type::Signed32());
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* ops[] = {t.machine()->Int32LessThan(),
|
|
|
|
t.machine()->Int32LessThanOrEqual()};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(ops); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
CheckChangesAroundBinop(&t, ops[i], IrOpcode::kChangeTaggedToInt32,
|
2016-07-20 08:48:51 +00:00
|
|
|
IrOpcode::kChangeBitToTagged, Type::Boolean());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangesAroundUint32Cmp) {
|
|
|
|
TestingGraph t(Type::Unsigned32(), Type::Unsigned32());
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* ops[] = {t.machine()->Uint32LessThan(),
|
|
|
|
t.machine()->Uint32LessThanOrEqual()};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(ops); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
CheckChangesAroundBinop(&t, ops[i], IrOpcode::kChangeTaggedToUint32,
|
2016-07-20 08:48:51 +00:00
|
|
|
IrOpcode::kChangeBitToTagged, Type::Boolean());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangesAroundFloat64Binops) {
|
|
|
|
TestingGraph t(Type::Number(), Type::Number());
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* ops[] = {
|
2014-08-11 09:40:02 +00:00
|
|
|
t.machine()->Float64Add(), t.machine()->Float64Sub(),
|
|
|
|
t.machine()->Float64Mul(), t.machine()->Float64Div(),
|
|
|
|
t.machine()->Float64Mod(),
|
|
|
|
};
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(ops); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
CheckChangesAroundBinop(&t, ops[i], IrOpcode::kChangeTaggedToFloat64,
|
2016-06-06 09:16:46 +00:00
|
|
|
IrOpcode::kChangeFloat64ToTagged, Type::Number());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangesAroundFloat64Cmp) {
|
|
|
|
TestingGraph t(Type::Number(), Type::Number());
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* ops[] = {t.machine()->Float64Equal(),
|
|
|
|
t.machine()->Float64LessThan(),
|
|
|
|
t.machine()->Float64LessThanOrEqual()};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(ops); i++) {
|
2014-08-11 09:40:02 +00:00
|
|
|
CheckChangesAroundBinop(&t, ops[i], IrOpcode::kChangeTaggedToFloat64,
|
2016-07-20 08:48:51 +00:00
|
|
|
IrOpcode::kChangeBitToTagged, Type::Boolean());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
namespace {
|
|
|
|
|
2014-08-11 09:40:02 +00:00
|
|
|
void CheckFieldAccessArithmetic(FieldAccess access, Node* load_or_store) {
|
2014-10-31 06:41:07 +00:00
|
|
|
IntPtrMatcher mindex(load_or_store->InputAt(1));
|
|
|
|
CHECK(mindex.Is(access.offset - access.tag()));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* CheckElementAccessArithmetic(ElementAccess access, Node* load_or_store) {
|
2014-10-31 06:41:07 +00:00
|
|
|
Node* index = load_or_store->InputAt(1);
|
|
|
|
if (kPointerSize == 8) {
|
2016-07-26 13:13:39 +00:00
|
|
|
Int64BinopMatcher mindex(index);
|
|
|
|
CHECK_EQ(IrOpcode::kInt64Add, mindex.node()->opcode());
|
|
|
|
CHECK(mindex.right().Is(access.header_size - access.tag()));
|
|
|
|
|
|
|
|
const int element_size_shift =
|
|
|
|
ElementSizeLog2Of(access.machine_type.representation());
|
|
|
|
Node* index;
|
|
|
|
if (element_size_shift) {
|
|
|
|
Int64BinopMatcher shl(mindex.left().node());
|
|
|
|
CHECK_EQ(IrOpcode::kWord64Shl, shl.node()->opcode());
|
|
|
|
CHECK(shl.right().Is(element_size_shift));
|
|
|
|
index = shl.left().node();
|
|
|
|
} else {
|
|
|
|
index = mindex.left().node();
|
|
|
|
}
|
2014-10-31 06:41:07 +00:00
|
|
|
CHECK_EQ(IrOpcode::kChangeUint32ToUint64, index->opcode());
|
2016-07-26 13:13:39 +00:00
|
|
|
return index->InputAt(0);
|
2014-08-11 09:40:02 +00:00
|
|
|
} else {
|
2016-07-26 13:13:39 +00:00
|
|
|
Int32BinopMatcher mindex(index);
|
|
|
|
CHECK_EQ(IrOpcode::kInt32Add, mindex.node()->opcode());
|
|
|
|
CHECK(mindex.right().Is(access.header_size - access.tag()));
|
|
|
|
|
|
|
|
const int element_size_shift =
|
|
|
|
ElementSizeLog2Of(access.machine_type.representation());
|
|
|
|
if (element_size_shift) {
|
|
|
|
Int32BinopMatcher shl(mindex.left().node());
|
|
|
|
CHECK_EQ(IrOpcode::kWord32Shl, shl.node()->opcode());
|
|
|
|
CHECK(shl.right().Is(element_size_shift));
|
|
|
|
return shl.left().node();
|
|
|
|
} else {
|
|
|
|
return mindex.left().node();
|
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
const MachineType kMachineReps[] = {
|
|
|
|
MachineType::Int8(), MachineType::Int16(), MachineType::Int32(),
|
|
|
|
MachineType::Uint32(), MachineType::Int64(), MachineType::Float64(),
|
|
|
|
MachineType::AnyTagged()};
|
2014-10-31 06:41:07 +00:00
|
|
|
|
|
|
|
} // namespace
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerLoadField_to_load) {
|
2014-10-31 06:41:07 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kMachineReps); i++) {
|
2016-04-25 09:25:59 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Handle<Name>::null(), Type::Any(),
|
|
|
|
kMachineReps[i], kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* load = t.graph()->NewNode(t.simplified()->LoadField(access), t.p0,
|
|
|
|
t.start, t.start);
|
2014-10-31 06:41:07 +00:00
|
|
|
Node* use = t.Use(load, kMachineReps[i]);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(use);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(IrOpcode::kLoad, load->opcode());
|
|
|
|
CHECK_EQ(t.p0, load->InputAt(0));
|
|
|
|
CheckFieldAccessArithmetic(access, load);
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType rep = LoadRepresentationOf(load->op());
|
2014-10-31 06:41:07 +00:00
|
|
|
CHECK_EQ(kMachineReps[i], rep);
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerStoreField_to_store) {
|
2015-03-02 13:10:27 +00:00
|
|
|
{
|
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-03-02 13:10:27 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kMachineReps); i++) {
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Handle<Name>::null(), Type::Any(),
|
|
|
|
kMachineReps[i], kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-03-02 13:10:27 +00:00
|
|
|
Node* val = t.ExampleWithOutput(kMachineReps[i]);
|
|
|
|
Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0,
|
|
|
|
val, t.start, t.start);
|
|
|
|
t.Effect(store);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2015-03-02 13:10:27 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStore, store->opcode());
|
|
|
|
CHECK_EQ(val, store->InputAt(2));
|
|
|
|
CheckFieldAccessArithmetic(access, store);
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-12-11 15:34:00 +00:00
|
|
|
StoreRepresentation rep = StoreRepresentationOf(store->op());
|
2015-12-10 09:03:30 +00:00
|
|
|
if (kMachineReps[i].representation() == MachineRepresentation::kTagged) {
|
2016-05-03 13:55:16 +00:00
|
|
|
CHECK_EQ(kNoWriteBarrier, rep.write_barrier_kind());
|
2015-03-02 13:10:27 +00:00
|
|
|
}
|
2015-12-11 15:34:00 +00:00
|
|
|
CHECK_EQ(kMachineReps[i].representation(), rep.representation());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-02 13:10:27 +00:00
|
|
|
{
|
2015-09-03 12:53:19 +00:00
|
|
|
HandleAndZoneScope scope;
|
|
|
|
Zone* z = scope.main_zone();
|
|
|
|
TestingGraph t(Type::Any(), Type::Intersect(Type::SignedSmall(),
|
|
|
|
Type::TaggedSigned(), z));
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {
|
|
|
|
kTaggedBase, FixedArrayBase::kHeaderSize, Handle<Name>::null(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(), kNoWriteBarrier};
|
2015-03-02 09:08:46 +00:00
|
|
|
Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0,
|
2015-03-02 13:10:27 +00:00
|
|
|
t.p1, t.start, t.start);
|
2015-03-02 09:08:46 +00:00
|
|
|
t.Effect(store);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2015-03-02 09:08:46 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStore, store->opcode());
|
2015-03-02 13:10:27 +00:00
|
|
|
CHECK_EQ(t.p1, store->InputAt(2));
|
2015-12-11 15:34:00 +00:00
|
|
|
StoreRepresentation rep = StoreRepresentationOf(store->op());
|
2016-05-03 13:55:16 +00:00
|
|
|
CHECK_EQ(kNoWriteBarrier, rep.write_barrier_kind());
|
2015-03-02 09:08:46 +00:00
|
|
|
}
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerLoadElement_to_load) {
|
2014-10-31 06:41:07 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kMachineReps); i++) {
|
2016-04-25 09:25:59 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
2014-12-02 04:48:57 +00:00
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
2016-05-06 10:20:01 +00:00
|
|
|
Type::Any(), kMachineReps[i], kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0,
|
|
|
|
t.p1, t.start, t.start);
|
2014-10-31 06:41:07 +00:00
|
|
|
Node* use = t.Use(load, kMachineReps[i]);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(use);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(IrOpcode::kLoad, load->opcode());
|
|
|
|
CHECK_EQ(t.p0, load->InputAt(0));
|
|
|
|
CheckElementAccessArithmetic(access, load);
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType rep = LoadRepresentationOf(load->op());
|
2014-10-31 06:41:07 +00:00
|
|
|
CHECK_EQ(kMachineReps[i], rep);
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LowerStoreElement_to_store) {
|
2015-03-02 13:10:27 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < arraysize(kMachineReps); i++) {
|
2016-04-25 12:40:46 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
|
|
|
|
2015-03-02 13:10:27 +00:00
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
2016-05-06 10:20:01 +00:00
|
|
|
Type::Any(), kMachineReps[i], kNoWriteBarrier};
|
2015-03-02 13:10:27 +00:00
|
|
|
|
|
|
|
Node* val = t.ExampleWithOutput(kMachineReps[i]);
|
|
|
|
Node* store = t.graph()->NewNode(t.simplified()->StoreElement(access),
|
|
|
|
t.p0, t.p1, val, t.start, t.start);
|
|
|
|
t.Effect(store);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2015-03-02 13:10:27 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStore, store->opcode());
|
|
|
|
CHECK_EQ(val, store->InputAt(2));
|
|
|
|
CheckElementAccessArithmetic(access, store);
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-12-11 15:34:00 +00:00
|
|
|
StoreRepresentation rep = StoreRepresentationOf(store->op());
|
2015-12-10 09:03:30 +00:00
|
|
|
if (kMachineReps[i].representation() == MachineRepresentation::kTagged) {
|
2016-05-03 13:55:16 +00:00
|
|
|
CHECK_EQ(kNoWriteBarrier, rep.write_barrier_kind());
|
2015-03-02 13:10:27 +00:00
|
|
|
}
|
2015-12-11 15:34:00 +00:00
|
|
|
CHECK_EQ(kMachineReps[i].representation(), rep.representation());
|
2015-03-02 13:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2015-09-03 12:53:19 +00:00
|
|
|
HandleAndZoneScope scope;
|
|
|
|
Zone* z = scope.main_zone();
|
|
|
|
TestingGraph t(
|
|
|
|
Type::Any(), Type::Signed32(),
|
|
|
|
Type::Intersect(Type::SignedSmall(), Type::TaggedSigned(), z));
|
2015-03-02 13:10:27 +00:00
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
2016-05-06 10:20:01 +00:00
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
|
|
|
kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
Node* store = t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0,
|
2015-03-02 13:10:27 +00:00
|
|
|
t.p1, t.p2, t.start, t.start);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Effect(store);
|
2015-11-13 08:11:59 +00:00
|
|
|
t.LowerAllNodesAndLowerChanges();
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStore, store->opcode());
|
2015-03-02 13:10:27 +00:00
|
|
|
CHECK_EQ(t.p2, store->InputAt(2));
|
2015-12-11 15:34:00 +00:00
|
|
|
StoreRepresentation rep = StoreRepresentationOf(store->op());
|
2016-05-03 13:55:16 +00:00
|
|
|
CHECK_EQ(kNoWriteBarrier, rep.write_barrier_kind());
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangeForLoadElementIndex) {
|
2014-09-24 09:28:56 +00:00
|
|
|
// LoadElement(obj: Tagged, index: kTypeInt32 | kRepTagged, length) =>
|
2014-08-11 09:40:02 +00:00
|
|
|
// Load(obj, Int32Add(Int32Mul(ChangeTaggedToInt32(index), #k), #k))
|
2014-12-02 04:48:57 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0,
|
2014-12-02 04:48:57 +00:00
|
|
|
t.p1, t.start, t.start);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(load);
|
|
|
|
t.Lower();
|
2015-11-13 08:11:59 +00:00
|
|
|
CHECK_EQ(IrOpcode::kLoadElement, load->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(t.p0, load->InputAt(0));
|
2015-11-13 08:11:59 +00:00
|
|
|
CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p1, load->InputAt(1));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangeForStoreElementIndex) {
|
2014-09-24 09:28:56 +00:00
|
|
|
// StoreElement(obj: Tagged, index: kTypeInt32 | kRepTagged, length, val) =>
|
2014-08-11 09:40:02 +00:00
|
|
|
// Store(obj, Int32Add(Int32Mul(ChangeTaggedToInt32(index), #k), #k), val)
|
2014-12-02 04:48:57 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::AnyTagged(), kFullWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Node* store =
|
2014-12-02 04:48:57 +00:00
|
|
|
t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, t.p1,
|
2014-08-11 09:40:02 +00:00
|
|
|
t.jsgraph.TrueConstant(), t.start, t.start);
|
|
|
|
t.Effect(store);
|
|
|
|
t.Lower();
|
2015-11-13 08:11:59 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStoreElement, store->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(t.p0, store->InputAt(0));
|
2015-11-13 08:11:59 +00:00
|
|
|
CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p1, store->InputAt(1));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangeForLoadElement) {
|
|
|
|
// TODO(titzer): test all load/store representation change insertions.
|
2014-09-24 09:28:56 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32(), Type::Any());
|
2016-06-06 09:16:46 +00:00
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Type::Number(), MachineType::Float64(),
|
|
|
|
kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0,
|
2014-12-02 04:48:57 +00:00
|
|
|
t.p1, t.start, t.start);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(load);
|
|
|
|
t.Lower();
|
2015-11-13 08:11:59 +00:00
|
|
|
CHECK_EQ(IrOpcode::kLoadElement, load->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(t.p0, load->InputAt(0));
|
|
|
|
CheckChangeOf(IrOpcode::kChangeFloat64ToTagged, load, t.ret->InputAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangeForLoadField) {
|
|
|
|
// TODO(titzer): test all load/store representation change insertions.
|
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {
|
2016-06-06 09:16:46 +00:00
|
|
|
kTaggedBase, FixedArrayBase::kHeaderSize, Handle<Name>::null(),
|
|
|
|
Type::Number(), MachineType::Float64(), kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* load = t.graph()->NewNode(t.simplified()->LoadField(access), t.p0,
|
|
|
|
t.start, t.start);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Return(load);
|
|
|
|
t.Lower();
|
2015-11-13 08:11:59 +00:00
|
|
|
CHECK_EQ(IrOpcode::kLoadField, load->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(t.p0, load->InputAt(0));
|
|
|
|
CheckChangeOf(IrOpcode::kChangeFloat64ToTagged, load, t.ret->InputAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangeForStoreElement) {
|
|
|
|
// TODO(titzer): test all load/store representation change insertions.
|
2014-12-02 04:48:57 +00:00
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(),
|
2016-05-06 10:20:01 +00:00
|
|
|
MachineType::Float64(), kFullWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
Node* store =
|
|
|
|
t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0,
|
|
|
|
t.jsgraph.Int32Constant(0), t.p1, t.start, t.start);
|
2014-08-11 09:40:02 +00:00
|
|
|
t.Effect(store);
|
|
|
|
t.Lower();
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStoreElement, store->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(t.p0, store->InputAt(0));
|
|
|
|
CheckChangeOf(IrOpcode::kChangeTaggedToFloat64, t.p1, store->InputAt(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(InsertChangeForStoreField) {
|
|
|
|
// TODO(titzer): test all load/store representation change insertions.
|
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {
|
|
|
|
kTaggedBase, FixedArrayBase::kHeaderSize, Handle<Name>::null(),
|
|
|
|
Type::Any(), MachineType::Float64(), kNoWriteBarrier};
|
2014-08-11 09:40:02 +00:00
|
|
|
|
|
|
|
Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0,
|
|
|
|
t.p1, t.start, t.start);
|
|
|
|
t.Effect(store);
|
|
|
|
t.Lower();
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
CHECK_EQ(IrOpcode::kStoreField, store->opcode());
|
2014-08-11 09:40:02 +00:00
|
|
|
CHECK_EQ(t.p0, store->InputAt(0));
|
2015-11-13 08:11:59 +00:00
|
|
|
CheckChangeOf(IrOpcode::kChangeTaggedToFloat64, t.p1, store->InputAt(1));
|
2014-08-11 09:40:02 +00:00
|
|
|
}
|
2014-09-05 11:44:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(UpdatePhi) {
|
|
|
|
TestingGraph t(Type::Any(), Type::Signed32());
|
2015-12-10 09:03:30 +00:00
|
|
|
static const MachineType kMachineTypes[] = {
|
|
|
|
MachineType::Int32(), MachineType::Uint32(), MachineType::Float64()};
|
2014-10-15 11:38:04 +00:00
|
|
|
Type* kTypes[] = {Type::Signed32(), Type::Unsigned32(), Type::Number()};
|
2014-09-05 11:44:31 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(kMachineTypes); i++) {
|
2016-05-06 10:20:01 +00:00
|
|
|
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Handle<Name>::null(), kTypes[i],
|
|
|
|
kMachineTypes[i], kFullWriteBarrier};
|
2014-09-05 11:44:31 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* load0 = t.graph()->NewNode(t.simplified()->LoadField(access), t.p0,
|
|
|
|
t.start, t.start);
|
|
|
|
Node* load1 = t.graph()->NewNode(t.simplified()->LoadField(access), t.p1,
|
|
|
|
t.start, t.start);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi =
|
|
|
|
t.graph()->NewNode(t.common()->Phi(MachineRepresentation::kTagged, 2),
|
|
|
|
load0, load1, t.start);
|
2014-09-05 11:44:31 +00:00
|
|
|
t.Return(t.Use(phi, kMachineTypes[i]));
|
|
|
|
t.Lower();
|
|
|
|
|
|
|
|
CHECK_EQ(IrOpcode::kPhi, phi->opcode());
|
2015-12-10 09:03:30 +00:00
|
|
|
CHECK_EQ(kMachineTypes[i].representation(), PhiRepresentationOf(phi->op()));
|
2014-09-05 11:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-07 12:18:39 +00:00
|
|
|
|
|
|
|
|
2014-10-08 10:53:46 +00:00
|
|
|
TEST(NumberMultiply_ConstantOutOfRange) {
|
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* k = t.jsgraph.Constant(1000000023);
|
|
|
|
Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k);
|
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul);
|
|
|
|
t.Return(trunc);
|
|
|
|
t.Lower();
|
|
|
|
|
|
|
|
CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberMultiply_NonTruncating) {
|
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* k = t.jsgraph.Constant(111);
|
|
|
|
Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k);
|
|
|
|
t.Return(mul);
|
|
|
|
t.Lower();
|
|
|
|
|
|
|
|
CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberDivide_TruncatingToInt32) {
|
|
|
|
int32_t constants[] = {-100, -10, 1, 4, 100, 1000};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(constants); i++) {
|
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* k = t.jsgraph.Constant(constants[i]);
|
|
|
|
Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(div, MachineType::Int32());
|
2014-10-28 13:56:26 +00:00
|
|
|
t.Return(use);
|
2014-10-08 10:53:46 +00:00
|
|
|
t.Lower();
|
|
|
|
|
2014-10-28 13:56:26 +00:00
|
|
|
CHECK_EQ(IrOpcode::kInt32Div, use->InputAt(0)->opcode());
|
2014-10-08 10:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberDivide_TruncatingToUint32) {
|
|
|
|
double constants[] = {1, 3, 100, 1000, 100998348};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(constants); i++) {
|
|
|
|
TestingGraph t(Type::Unsigned32());
|
|
|
|
Node* k = t.jsgraph.Constant(constants[i]);
|
|
|
|
Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(div, MachineType::Uint32());
|
2014-10-28 13:56:26 +00:00
|
|
|
t.Return(use);
|
2014-10-08 10:53:46 +00:00
|
|
|
t.Lower();
|
|
|
|
|
2014-10-28 13:56:26 +00:00
|
|
|
CHECK_EQ(IrOpcode::kUint32Div, use->InputAt(0)->opcode());
|
2014-10-08 10:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberDivide_BadConstants) {
|
2014-10-28 13:56:26 +00:00
|
|
|
{
|
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* k = t.jsgraph.Constant(-1);
|
|
|
|
Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(div, MachineType::Int32());
|
2014-10-28 13:56:26 +00:00
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
2014-10-08 10:53:46 +00:00
|
|
|
|
2014-10-28 13:56:26 +00:00
|
|
|
CHECK_EQ(IrOpcode::kInt32Sub, use->InputAt(0)->opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2014-10-08 10:53:46 +00:00
|
|
|
TestingGraph t(Type::Signed32());
|
2014-10-28 13:56:26 +00:00
|
|
|
Node* k = t.jsgraph.Constant(0);
|
2014-10-08 10:53:46 +00:00
|
|
|
Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(div, MachineType::Int32());
|
2014-10-28 13:56:26 +00:00
|
|
|
t.Return(use);
|
2014-10-08 10:53:46 +00:00
|
|
|
t.Lower();
|
|
|
|
|
2014-10-28 13:56:26 +00:00
|
|
|
CHECK_EQ(IrOpcode::kInt32Constant, use->InputAt(0)->opcode());
|
|
|
|
CHECK_EQ(0, OpParameter<int32_t>(use->InputAt(0)));
|
2014-10-08 10:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
TestingGraph t(Type::Unsigned32());
|
|
|
|
Node* k = t.jsgraph.Constant(0);
|
|
|
|
Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(div, MachineType::Uint32());
|
2014-10-28 13:56:26 +00:00
|
|
|
t.Return(use);
|
2014-10-08 10:53:46 +00:00
|
|
|
t.Lower();
|
|
|
|
|
2014-10-28 13:56:26 +00:00
|
|
|
CHECK_EQ(IrOpcode::kInt32Constant, use->InputAt(0)->opcode());
|
|
|
|
CHECK_EQ(0, OpParameter<int32_t>(use->InputAt(0)));
|
2014-10-08 10:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberModulus_TruncatingToInt32) {
|
|
|
|
int32_t constants[] = {-100, -10, 1, 4, 100, 1000};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(constants); i++) {
|
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* k = t.jsgraph.Constant(constants[i]);
|
|
|
|
Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* use = t.Use(mod, MachineType::Int32());
|
2014-10-28 13:56:26 +00:00
|
|
|
t.Return(use);
|
2014-10-08 10:53:46 +00:00
|
|
|
t.Lower();
|
|
|
|
|
2014-10-28 13:56:26 +00:00
|
|
|
CHECK_EQ(IrOpcode::kInt32Mod, use->InputAt(0)->opcode());
|
2014-10-08 10:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberModulus_TruncatingToUint32) {
|
|
|
|
double constants[] = {1, 3, 100, 1000, 100998348};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(constants); i++) {
|
|
|
|
TestingGraph t(Type::Unsigned32());
|
|
|
|
Node* k = t.jsgraph.Constant(constants[i]);
|
|
|
|
Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
|
|
|
Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod);
|
2015-02-27 09:37:37 +00:00
|
|
|
t.Return(trunc);
|
2014-10-08 10:53:46 +00:00
|
|
|
t.Lower();
|
|
|
|
|
2015-02-27 09:37:37 +00:00
|
|
|
CHECK_EQ(IrOpcode::kUint32Mod, t.ret->InputAt(0)->InputAt(0)->opcode());
|
2014-10-08 10:53:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberModulus_Int32) {
|
|
|
|
int32_t constants[] = {-100, -10, 1, 4, 100, 1000};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(constants); i++) {
|
|
|
|
TestingGraph t(Type::Signed32());
|
|
|
|
Node* k = t.jsgraph.Constant(constants[i]);
|
|
|
|
Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
|
|
|
t.Return(mod);
|
|
|
|
t.Lower();
|
|
|
|
|
|
|
|
CHECK_EQ(IrOpcode::kFloat64Mod, mod->opcode()); // Pesky -0 behavior.
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 07:58:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(NumberModulus_Uint32) {
|
|
|
|
const double kConstants[] = {2, 100, 1000, 1024, 2048};
|
2015-12-10 09:03:30 +00:00
|
|
|
const MachineType kTypes[] = {MachineType::Int32(), MachineType::Uint32()};
|
2014-10-31 07:58:49 +00:00
|
|
|
|
|
|
|
for (auto const type : kTypes) {
|
|
|
|
for (auto const c : kConstants) {
|
|
|
|
TestingGraph t(Type::Unsigned32());
|
|
|
|
Node* k = t.jsgraph.Constant(c);
|
|
|
|
Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
|
|
|
Node* use = t.Use(mod, type);
|
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
|
|
|
|
|
|
|
CHECK_EQ(IrOpcode::kUint32Mod, use->InputAt(0)->opcode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 19:53:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(PhiRepresentation) {
|
|
|
|
HandleAndZoneScope scope;
|
|
|
|
Zone* z = scope.main_zone();
|
|
|
|
|
|
|
|
struct TestData {
|
|
|
|
Type* arg1;
|
|
|
|
Type* arg2;
|
|
|
|
MachineType use;
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineRepresentation expected;
|
2014-10-31 19:53:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TestData test_data[] = {
|
2015-12-10 09:03:30 +00:00
|
|
|
{Type::Signed32(), Type::Unsigned32(), MachineType::Int32(),
|
|
|
|
MachineRepresentation::kWord32},
|
|
|
|
{Type::Signed32(), Type::Unsigned32(), MachineType::Uint32(),
|
|
|
|
MachineRepresentation::kWord32},
|
|
|
|
{Type::Signed32(), Type::Signed32(), MachineType::Int32(),
|
|
|
|
MachineRepresentation::kWord32},
|
|
|
|
{Type::Unsigned32(), Type::Unsigned32(), MachineType::Int32(),
|
|
|
|
MachineRepresentation::kWord32},
|
|
|
|
{Type::Number(), Type::Signed32(), MachineType::Int32(),
|
|
|
|
MachineRepresentation::kWord32}};
|
2014-10-31 19:53:28 +00:00
|
|
|
|
|
|
|
for (auto const d : test_data) {
|
|
|
|
TestingGraph t(d.arg1, d.arg2, Type::Boolean());
|
|
|
|
|
|
|
|
Node* br = t.graph()->NewNode(t.common()->Branch(), t.p2, t.start);
|
|
|
|
Node* tb = t.graph()->NewNode(t.common()->IfTrue(), br);
|
|
|
|
Node* fb = t.graph()->NewNode(t.common()->IfFalse(), br);
|
|
|
|
Node* m = t.graph()->NewNode(t.common()->Merge(2), tb, fb);
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi = t.graph()->NewNode(
|
|
|
|
t.common()->Phi(MachineRepresentation::kTagged, 2), t.p0, t.p1, m);
|
2014-10-31 19:53:28 +00:00
|
|
|
|
2015-09-16 11:55:27 +00:00
|
|
|
Type* phi_type = Type::Union(d.arg1, d.arg2, z);
|
|
|
|
NodeProperties::SetType(phi, phi_type);
|
2014-10-31 19:53:28 +00:00
|
|
|
|
|
|
|
Node* use = t.Use(phi, d.use);
|
|
|
|
t.Return(use);
|
|
|
|
t.Lower();
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
CHECK_EQ(d.expected, PhiRepresentationOf(phi->op()));
|
2014-10-31 19:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|