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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <iostream>
6
7 #include "src/compiler/bytecode-graph-builder.h"
8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/graph-visualizer.h"
10 #include "src/compiler/instruction.h"
11 #include "src/compiler/instruction-selector.h"
12 #include "src/compiler/js-graph.h"
13 #include "src/compiler/js-operator.h"
14 #include "src/interpreter/bytecodes.h"
15 #include "src/parser.h"
16 #include "test/cctest/cctest.h"
17
18 namespace v8 {
19 namespace internal {
20 namespace compiler {
21
22
23 struct BytecodeSnippet {
24 const char* body;
25 int frame_size;
26 int parameter_count;
27 int bytecode_length;
28 const uint8_t bytecode[16];
29 };
30
31
32 // Helper macros for handcrafting bytecode sequences.
33 #define B(x) static_cast<uint8_t>(interpreter::Bytecode::k##x)
34 #define U8(x) static_cast<uint8_t>((x)&0xff)
35 #define R(x) static_cast<uint8_t>(-(x)&0xff)
36
37
38 static const int kLastParamIndex =
39 -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
40
41
42 const BytecodeSnippet kBytecodeSnippets[] = {
43 {"var x = 0; return x;",
44 kPointerSize,
45 0,
46 6,
47 {
48 B(LdaZero), //
49 B(Star), R(0), //
50 B(Ldar), R(0), //
51 B(Return) //
52 }},
53 {"var x = 0; return x + 3;",
54 2 * kPointerSize,
55 0,
56 12,
57 {
58 B(LdaZero), //
59 B(Star), R(0), //
60 B(Ldar), R(0), // Easy to spot r1 not really needed here.
61 B(Star), R(1), // Dead store.
62 B(LdaSmi8), U8(3), //
63 B(Add), R(1), //
64 B(Return) //
65 }},
66 {"function f(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { return arg4; }",
67 0,
68 8,
69 3,
70 {
71 B(Ldar), //
72 R(kLastParamIndex - 3), //
73 B(Return) //
74 }},
75 };
76
77
78 TEST(BytecodeGraphBuilder) {
79 i::FLAG_ignition = true;
80 i::FLAG_always_opt = true;
81
82 HandleAndZoneScope test_scope;
83
84 size_t snippet_count =
85 sizeof(kBytecodeSnippets) / sizeof(kBytecodeSnippets[0]);
86 for (size_t i = 0; i < snippet_count; i++) {
87 Graph* graph = new (test_scope.main_zone()) Graph(test_scope.main_zone());
88 MachineOperatorBuilder* machine =
89 new (test_scope.main_zone()) MachineOperatorBuilder(
90 test_scope.main_zone(), kMachPtr,
91 InstructionSelector::SupportedMachineOperatorFlags());
92 CommonOperatorBuilder* common = new (test_scope.main_zone())
93 CommonOperatorBuilder(test_scope.main_zone());
94 JSOperatorBuilder* javascript =
95 new (test_scope.main_zone()) JSOperatorBuilder(test_scope.main_zone());
96 JSGraph* jsgraph = new (test_scope.main_zone())
97 JSGraph(test_scope.main_isolate(), graph, common, javascript, machine);
98
99 const BytecodeSnippet& snippet = kBytecodeSnippets[i];
100 Handle<FixedArray> constant_pool =
101 test_scope.main_isolate()->factory()->NewFixedArray(0);
102 Handle<BytecodeArray> bytecode_array =
103 test_scope.main_isolate()->factory()->NewBytecodeArray(
104 snippet.bytecode_length, snippet.bytecode, snippet.frame_size,
105 snippet.parameter_count, constant_pool);
106 MaybeHandle<Code> no_code;
107
108 Handle<String> name =
109 test_scope.main_isolate()->factory()->NewStringFromStaticChars("test");
110 Handle<SharedFunctionInfo> shared_info =
111 test_scope.main_isolate()->factory()->NewSharedFunctionInfo(name,
112 no_code);
113
114 ParseInfo parse_info(test_scope.main_zone(), shared_info);
115 CompilationInfo info(&parse_info);
116 info.shared_info()->set_function_data(*bytecode_array);
117 BytecodeGraphBuilder builder(test_scope.main_zone(), &info, jsgraph);
118 builder.CreateGraph();
119 std::cout << AsDOT(*builder.graph()) << std::endl;
120 }
121 }
122
123
124 } // namespace compiler
125 } // namespace internal
126 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698