Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1495)

Unified Diff: test/cctest/compiler/test-changes-lowering.cc

Issue 1942733002: Revert of [turbofan] Remove left-over change bits from ChangeLowering. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/compiler/graph-builder-tester.h ('k') | test/cctest/compiler/test-representation-change.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/compiler/test-changes-lowering.cc
diff --git a/test/cctest/compiler/test-changes-lowering.cc b/test/cctest/compiler/test-changes-lowering.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a39cb03d6e4864777d8d3a138d62eb3de2eb403
--- /dev/null
+++ b/test/cctest/compiler/test-changes-lowering.cc
@@ -0,0 +1,183 @@
+// 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>
+
+#include "src/ast/scopes.h"
+#include "src/compiler/change-lowering.h"
+#include "src/compiler/control-builders.h"
+#include "src/compiler/js-graph.h"
+#include "src/compiler/node-properties.h"
+#include "src/compiler/pipeline.h"
+#include "src/compiler/select-lowering.h"
+#include "src/compiler/simplified-lowering.h"
+#include "src/compiler/typer.h"
+#include "src/compiler/verifier.h"
+#include "src/execution.h"
+#include "src/globals.h"
+#include "src/parsing/parser.h"
+#include "src/parsing/rewriter.h"
+#include "test/cctest/cctest.h"
+#include "test/cctest/compiler/codegen-tester.h"
+#include "test/cctest/compiler/function-tester.h"
+#include "test/cctest/compiler/graph-builder-tester.h"
+#include "test/cctest/compiler/value-helper.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+template <typename ReturnType>
+class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
+ public:
+ explicit ChangesLoweringTester(MachineType p0 = MachineType::None())
+ : GraphBuilderTester<ReturnType>(p0),
+ javascript(this->zone()),
+ jsgraph(this->isolate(), this->graph(), this->common(), &javascript,
+ nullptr, this->machine()),
+ function(Handle<JSFunction>::null()) {}
+
+ JSOperatorBuilder javascript;
+ JSGraph jsgraph;
+ Handle<JSFunction> function;
+
+ Node* start() { return this->graph()->start(); }
+
+ 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.
+ if (function.is_null()) {
+ function = FunctionTester::ForMachineGraph(this->graph());
+ }
+ Handle<Object>* args = NULL;
+ MaybeHandle<Object> result =
+ Execution::Call(this->isolate(), function, factory()->undefined_value(),
+ 0, args, false);
+ return T::cast(*result.ToHandleChecked());
+ }
+
+ void StoreFloat64(Node* node, double* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ this->Store(MachineType::Float64(), ptr_node, node);
+ }
+
+ Node* LoadInt32(int32_t* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ return this->Load(MachineType::Int32(), ptr_node);
+ }
+
+ Node* LoadUint32(uint32_t* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ return this->Load(MachineType::Uint32(), ptr_node);
+ }
+
+ Node* LoadFloat64(double* ptr) {
+ Node* ptr_node = this->PointerConstant(ptr);
+ return this->Load(MachineType::Float64(), ptr_node);
+ }
+
+ void CheckNumber(double expected, Object* number) {
+ CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number));
+ }
+
+ void BuildAndLower(const Operator* op) {
+ // We build a graph by hand here, because the raw machine assembler
+ // does not add the correct control and effect nodes.
+ Node* p0 = this->Parameter(0);
+ Node* change = this->graph()->NewNode(op, p0);
+ Node* ret = this->graph()->NewNode(this->common()->Return(), change,
+ this->start(), this->start());
+ Node* end = this->graph()->NewNode(this->common()->End(1), ret);
+ this->graph()->SetEnd(end);
+ LowerChange(change);
+ }
+
+ void BuildStoreAndLower(const Operator* op, const Operator* store_op,
+ void* location) {
+ // We build a graph by hand here, because the raw machine assembler
+ // does not add the correct control and effect nodes.
+ Node* p0 = this->Parameter(0);
+ Node* change = this->graph()->NewNode(op, p0);
+ Node* store = this->graph()->NewNode(
+ store_op, this->PointerConstant(location), this->Int32Constant(0),
+ change, this->start(), this->start());
+ Node* ret = this->graph()->NewNode(
+ this->common()->Return(), this->Int32Constant(0), store, this->start());
+ Node* end = this->graph()->NewNode(this->common()->End(1), ret);
+ this->graph()->SetEnd(end);
+ LowerChange(change);
+ }
+
+ void BuildLoadAndLower(const Operator* op, const Operator* load_op,
+ void* location) {
+ // We build a graph by hand here, because the raw machine assembler
+ // does not add the correct control and effect nodes.
+ Node* load = this->graph()->NewNode(
+ load_op, this->PointerConstant(location), this->Int32Constant(0),
+ this->start(), this->start());
+ Node* change = this->graph()->NewNode(op, load);
+ Node* ret = this->graph()->NewNode(this->common()->Return(), change,
+ this->start(), this->start());
+ Node* end = this->graph()->NewNode(this->common()->End(1), ret);
+ this->graph()->SetEnd(end);
+ LowerChange(change);
+ }
+
+ void LowerChange(Node* change) {
+ // Run the graph reducer with changes lowering on a single node.
+ Typer typer(this->isolate(), this->graph());
+ typer.Run();
+ ChangeLowering change_lowering(&jsgraph);
+ SelectLowering select_lowering(this->graph(), this->common());
+ GraphReducer reducer(this->zone(), this->graph());
+ reducer.AddReducer(&change_lowering);
+ reducer.AddReducer(&select_lowering);
+ reducer.ReduceNode(change);
+ Verifier::Run(this->graph(), Verifier::UNTYPED);
+ }
+
+ Factory* factory() { return this->isolate()->factory(); }
+ Heap* heap() { return this->isolate()->heap(); }
+};
+
+
+TEST(RunChangeBoolToBit) {
+ ChangesLoweringTester<int32_t> t(MachineType::AnyTagged());
+ t.BuildAndLower(t.simplified()->ChangeBoolToBit());
+
+ {
+ 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) {
+ ChangesLoweringTester<Object*> t(MachineType::Int32());
+ t.BuildAndLower(t.simplified()->ChangeBitToBool());
+
+ {
+ 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);
+ }
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/cctest/compiler/graph-builder-tester.h ('k') | test/cctest/compiler/test-representation-change.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698