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

Unified Diff: test/cctest/compiler/test-bytecode-graph-builder.cc

Issue 1291693004: [Interpreter] Bytecode graph builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes/progress from rmcilroy to enable turbofan to process graphs from bytecode. Created 5 years, 3 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
Index: test/cctest/compiler/test-bytecode-graph-builder.cc
diff --git a/test/cctest/compiler/test-bytecode-graph-builder.cc b/test/cctest/compiler/test-bytecode-graph-builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3c710242d20ac769b844cd8ab6758ed20f7be7d9
--- /dev/null
+++ b/test/cctest/compiler/test-bytecode-graph-builder.cc
@@ -0,0 +1,126 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <iostream>
+
+#include "src/compiler/bytecode-graph-builder.h"
+#include "src/compiler/common-operator.h"
+#include "src/compiler/graph-visualizer.h"
+#include "src/compiler/instruction.h"
+#include "src/compiler/instruction-selector.h"
+#include "src/compiler/js-graph.h"
+#include "src/compiler/js-operator.h"
+#include "src/interpreter/bytecodes.h"
+#include "src/parser.h"
+#include "test/cctest/cctest.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+
+struct BytecodeSnippet {
+ const char* body;
+ int frame_size;
+ int parameter_count;
+ int bytecode_length;
+ const uint8_t bytecode[16];
+};
+
+
+// Helper macros for handcrafting bytecode sequences.
+#define B(x) static_cast<uint8_t>(interpreter::Bytecode::k##x)
+#define U8(x) static_cast<uint8_t>((x)&0xff)
+#define R(x) static_cast<uint8_t>(-(x)&0xff)
+
+
+static const int kLastParamIndex =
+ -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
+
+
+const BytecodeSnippet kBytecodeSnippets[] = {
+ {"var x = 0; return x;",
+ kPointerSize,
+ 0,
+ 6,
+ {
+ B(LdaZero), //
+ B(Star), R(0), //
+ B(Ldar), R(0), //
+ B(Return) //
+ }},
+ {"var x = 0; return x + 3;",
+ 2 * kPointerSize,
+ 0,
+ 12,
+ {
+ B(LdaZero), //
+ B(Star), R(0), //
+ B(Ldar), R(0), // Easy to spot r1 not really needed here.
+ B(Star), R(1), // Dead store.
+ B(LdaSmi8), U8(3), //
+ B(Add), R(1), //
+ B(Return) //
+ }},
+ {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }",
+ 0,
+ 8,
+ 3,
+ {
+ B(Ldar), //
+ R(kLastParamIndex - 3), //
+ B(Return) //
+ }},
+};
+
+
+TEST(BytecodeGraphBuilder) {
+ i::FLAG_ignition = true;
+ i::FLAG_always_opt = true;
+
+ HandleAndZoneScope test_scope;
+
+ size_t snippet_count =
+ sizeof(kBytecodeSnippets) / sizeof(kBytecodeSnippets[0]);
+ for (size_t i = 0; i < snippet_count; i++) {
+ Graph* graph = new (test_scope.main_zone()) Graph(test_scope.main_zone());
+ MachineOperatorBuilder* machine =
+ new (test_scope.main_zone()) MachineOperatorBuilder(
+ test_scope.main_zone(), kMachPtr,
+ InstructionSelector::SupportedMachineOperatorFlags());
+ CommonOperatorBuilder* common = new (test_scope.main_zone())
+ CommonOperatorBuilder(test_scope.main_zone());
+ JSOperatorBuilder* javascript =
+ new (test_scope.main_zone()) JSOperatorBuilder(test_scope.main_zone());
+ JSGraph* jsgraph = new (test_scope.main_zone())
+ JSGraph(test_scope.main_isolate(), graph, common, javascript, machine);
+
+ const BytecodeSnippet& snippet = kBytecodeSnippets[i];
+ Handle<FixedArray> constant_pool =
+ test_scope.main_isolate()->factory()->NewFixedArray(0);
+ Handle<BytecodeArray> bytecode_array =
+ test_scope.main_isolate()->factory()->NewBytecodeArray(
+ snippet.bytecode_length, snippet.bytecode, snippet.frame_size,
+ snippet.parameter_count, constant_pool);
+ MaybeHandle<Code> no_code;
+
+ Handle<String> name =
+ test_scope.main_isolate()->factory()->NewStringFromStaticChars("test");
+ Handle<SharedFunctionInfo> shared_info =
+ test_scope.main_isolate()->factory()->NewSharedFunctionInfo(name,
+ no_code);
+
+ ParseInfo parse_info(test_scope.main_zone(), shared_info);
+ CompilationInfo info(&parse_info);
+ info.shared_info()->set_function_data(*bytecode_array);
+ BytecodeGraphBuilder builder(test_scope.main_zone(), &info, jsgraph);
+ builder.CreateGraph();
+ std::cout << AsDOT(*builder.graph()) << std::endl;
+ }
+}
+
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698