Index: test/cctest/compiler/test-simplified-lowering.cc |
diff --git a/test/cctest/compiler/test-simplified-lowering.cc b/test/cctest/compiler/test-simplified-lowering.cc |
index f1d95707635d67ce96b8bab777056d0b9074b9e0..43a6594e609747eacd0787c94f2b8817445a63d3 100644 |
--- a/test/cctest/compiler/test-simplified-lowering.cc |
+++ b/test/cctest/compiler/test-simplified-lowering.cc |
@@ -5,6 +5,7 @@ |
#include <limits> |
#include "src/compiler/control-builders.h" |
+#include "src/compiler/generic-node-inl.h" |
#include "src/compiler/node-properties-inl.h" |
#include "src/compiler/pipeline.h" |
#include "src/compiler/simplified-lowering.h" |
@@ -23,6 +24,7 @@ |
using namespace v8::internal; |
using namespace v8::internal::compiler; |
+// TODO(titzer): rename this to VMLoweringTester |
template <typename ReturnType> |
class SimplifiedGraphBuilderTester : public GraphBuilderTester<ReturnType> { |
public: |
@@ -31,16 +33,20 @@ class SimplifiedGraphBuilderTester : public GraphBuilderTester<ReturnType> { |
MachineRepresentation p2 = kMachineLast, |
MachineRepresentation p3 = kMachineLast, |
MachineRepresentation p4 = kMachineLast) |
- : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4) {} |
+ : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), |
+ typer(this->zone()), |
+ source_positions(this->graph()), |
+ jsgraph(this->graph(), this->common(), &typer), |
+ lowering(&jsgraph, &source_positions) {} |
+ |
+ Typer typer; |
+ SourcePositionTable source_positions; |
+ JSGraph jsgraph; |
+ SimplifiedLowering lowering; |
// Close graph and lower one node. |
void Lower(Node* node) { |
this->End(); |
- Typer typer(this->zone()); |
- CommonOperatorBuilder common(this->zone()); |
- SourcePositionTable source_positions(this->graph()); |
- JSGraph jsgraph(this->graph(), &common, &typer); |
- SimplifiedLowering lowering(&jsgraph, &source_positions); |
if (node == NULL) { |
lowering.LowerAllNodes(); |
} else { |
@@ -76,313 +82,6 @@ class SimplifiedGraphBuilderTester : public GraphBuilderTester<ReturnType> { |
}; |
-class SimplifiedGraphBuilderJSTester |
- : public SimplifiedGraphBuilderTester<Object*> { |
- public: |
- SimplifiedGraphBuilderJSTester() |
- : SimplifiedGraphBuilderTester<Object*>(), |
- f_(v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast(CompileRun( |
- "(function() { 'use strict'; return 2.7123; })")))), |
- swapped_(false) { |
- set_current_context(HeapConstant(handle(f_->context()))); |
- } |
- |
- template <typename T> |
- T* CallJS() { |
- if (!swapped_) { |
- Compile(); |
- } |
- Handle<Object>* args = NULL; |
- MaybeHandle<Object> result = Execution::Call( |
- isolate(), f_, factory()->undefined_value(), 0, args, false); |
- return T::cast(*result.ToHandleChecked()); |
- } |
- |
- private: |
- void Compile() { |
- CompilationInfoWithZone info(f_); |
- CHECK(Parser::Parse(&info)); |
- StrictMode strict_mode = info.function()->strict_mode(); |
- info.SetStrictMode(strict_mode); |
- info.SetOptimizing(BailoutId::None(), Handle<Code>(f_->code())); |
- CHECK(Rewriter::Rewrite(&info)); |
- CHECK(Scope::Analyze(&info)); |
- CHECK_NE(NULL, info.scope()); |
- Pipeline pipeline(&info); |
- Linkage linkage(&info); |
- Handle<Code> code = pipeline.GenerateCodeForMachineGraph(&linkage, graph()); |
- CHECK(!code.is_null()); |
- f_->ReplaceCode(*code); |
- swapped_ = true; |
- } |
- |
- Handle<JSFunction> f_; |
- bool swapped_; |
-}; |
- |
- |
-TEST(RunChangeTaggedToInt32) { |
- SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged); |
- Node* x = t.ChangeTaggedToInt32(t.Parameter(0)); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- FOR_INT32_INPUTS(i) { |
- int32_t input = *i; |
- |
- if (Smi::IsValid(input)) { |
- int32_t result = t.Call(Smi::FromInt(input)); |
- CHECK_EQ(input, result); |
- } |
- |
- { |
- Handle<Object> number = t.factory()->NewNumber(input); |
- int32_t result = t.Call(*number); |
- CHECK_EQ(input, result); |
- } |
- |
- { |
- Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
- int32_t result = t.Call(*number); |
- CHECK_EQ(input, result); |
- } |
- } |
-} |
- |
- |
-TEST(RunChangeTaggedToUint32) { |
- SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged); |
- Node* x = t.ChangeTaggedToUint32(t.Parameter(0)); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- FOR_UINT32_INPUTS(i) { |
- uint32_t input = *i; |
- |
- if (Smi::IsValid(input)) { |
- int32_t result = t.Call(Smi::FromInt(input)); |
- CHECK_EQ(static_cast<int32_t>(input), result); |
- } |
- |
- { |
- Handle<Object> number = t.factory()->NewNumber(input); |
- int32_t result = t.Call(*number); |
- CHECK_EQ(static_cast<int32_t>(input), result); |
- } |
- |
- { |
- Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
- int32_t result = t.Call(*number); |
- CHECK_EQ(static_cast<int32_t>(input), result); |
- } |
- } |
-} |
- |
- |
-TEST(RunChangeTaggedToFloat64) { |
- SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged); |
- double result; |
- Node* x = t.ChangeTaggedToFloat64(t.Parameter(0)); |
- t.StoreFloat64(x, &result); |
- t.Return(t.Int32Constant(0)); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- { |
- FOR_INT32_INPUTS(i) { |
- int32_t input = *i; |
- |
- if (Smi::IsValid(input)) { |
- t.Call(Smi::FromInt(input)); |
- CHECK_EQ(input, static_cast<int32_t>(result)); |
- } |
- |
- { |
- Handle<Object> number = t.factory()->NewNumber(input); |
- t.Call(*number); |
- CHECK_EQ(input, static_cast<int32_t>(result)); |
- } |
- |
- { |
- Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
- t.Call(*number); |
- CHECK_EQ(input, static_cast<int32_t>(result)); |
- } |
- } |
- } |
- |
- { |
- FOR_FLOAT64_INPUTS(i) { |
- double input = *i; |
- { |
- Handle<Object> number = t.factory()->NewNumber(input); |
- t.Call(*number); |
- CHECK_EQ(input, result); |
- } |
- |
- { |
- Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
- t.Call(*number); |
- CHECK_EQ(input, result); |
- } |
- } |
- } |
-} |
- |
- |
-TEST(RunChangeBoolToBit) { |
- SimplifiedGraphBuilderTester<int32_t> t(kMachineTagged); |
- Node* x = t.ChangeBoolToBit(t.Parameter(0)); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- if (!Pipeline::SupportedTarget()) return; |
- |
- { |
- Object* true_obj = t.heap()->true_value(); |
- int32_t result = t.Call(true_obj); |
- CHECK_EQ(1, result); |
- } |
- |
- { |
- Object* false_obj = t.heap()->false_value(); |
- int32_t result = t.Call(false_obj); |
- CHECK_EQ(0, result); |
- } |
-} |
- |
- |
-TEST(RunChangeBitToBool) { |
- SimplifiedGraphBuilderTester<Object*> t(kMachineTagged); |
- Node* x = t.ChangeBitToBool(t.Parameter(0)); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- { |
- Object* result = t.Call(1); |
- Object* true_obj = t.heap()->true_value(); |
- CHECK_EQ(true_obj, result); |
- } |
- |
- { |
- Object* result = t.Call(0); |
- Object* false_obj = t.heap()->false_value(); |
- CHECK_EQ(false_obj, result); |
- } |
-} |
- |
- |
-TEST(RunChangeInt32ToTagged) { |
- SimplifiedGraphBuilderJSTester t; |
- int32_t input; |
- Node* load = t.LoadInt32(&input); |
- Node* x = t.ChangeInt32ToTagged(load); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- |
- { |
- FOR_INT32_INPUTS(i) { |
- input = *i; |
- HeapNumber* result = t.CallJS<HeapNumber>(); |
- CHECK_EQ(static_cast<double>(input), result->value()); |
- } |
- } |
- |
- { |
- FOR_INT32_INPUTS(i) { |
- input = *i; |
- SimulateFullSpace(CcTest::heap()->new_space()); |
- HeapNumber* result = t.CallJS<HeapNumber>(); |
- CHECK_EQ(static_cast<double>(input), result->value()); |
- } |
- } |
-} |
- |
- |
-TEST(RunChangeUint32ToTagged) { |
- SimplifiedGraphBuilderJSTester t; |
- uint32_t input; |
- Node* load = t.LoadUint32(&input); |
- Node* x = t.ChangeUint32ToTagged(load); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- { |
- FOR_UINT32_INPUTS(i) { |
- input = *i; |
- HeapNumber* result = t.CallJS<HeapNumber>(); |
- double expected = static_cast<double>(input); |
- CHECK_EQ(expected, result->value()); |
- } |
- } |
- |
- { |
- FOR_UINT32_INPUTS(i) { |
- input = *i; |
- SimulateFullSpace(CcTest::heap()->new_space()); |
- HeapNumber* result = t.CallJS<HeapNumber>(); |
- double expected = static_cast<double>(static_cast<uint32_t>(input)); |
- CHECK_EQ(expected, result->value()); |
- } |
- } |
-} |
- |
- |
-TEST(RunChangeFloat64ToTagged) { |
- SimplifiedGraphBuilderJSTester t; |
- double input; |
- Node* load = t.LoadFloat64(&input); |
- Node* x = t.ChangeFloat64ToTagged(load); |
- t.Return(x); |
- |
- t.Lower(x); |
- |
- // TODO(titzer): remove me. |
- return; |
- |
- { |
- FOR_FLOAT64_INPUTS(i) { |
- input = *i; |
- HeapNumber* result = t.CallJS<HeapNumber>(); |
- CHECK_EQ(input, result->value()); |
- } |
- } |
- { |
- FOR_FLOAT64_INPUTS(i) { |
- input = *i; |
- SimulateFullSpace(CcTest::heap()->new_space()); |
- HeapNumber* result = t.CallJS<HeapNumber>(); |
- CHECK_EQ(input, result->value()); |
- } |
- } |
-} |
- |
- |
// TODO(dcarney): find a home for these functions. |
namespace { |