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

Side by Side Diff: src/compiler/wasm-compiler.h

Issue 1504713014: Initial import of v8-native WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « src/DEPS ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef V8_COMPILER_WASM_COMPILER_H_
6 #define V8_COMPILER_WASM_COMPILER_H_
7
8 // Clients of this interface shouldn't depend on lots of compiler internals.
9 // Do not include anything from src/compiler here!
10 #include "src/wasm/wasm-opcodes.h"
11 #include "src/zone.h"
12
13 namespace v8 {
14 namespace internal {
15
16 namespace compiler {
17 // Forward declarations for some compiler data structures.
18 class Node;
19 class JSGraph;
20 class Graph;
21 }
22
23 namespace wasm {
24 // Forward declarations for some WASM data structures.
25 struct ModuleEnv;
26 struct WasmFunction;
27 class ErrorThrower;
28
29 // Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}.
30 typedef compiler::Node TFNode;
31 typedef compiler::JSGraph TFGraph;
32 }
33
34 namespace compiler {
35 // Compiles a single function, producing a code object.
36 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
37 wasm::ModuleEnv* module_env,
38 const wasm::WasmFunction& function, int index);
39
40 // Wraps a JS function, producing a code object that can be called from WASM.
41 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
42 Handle<JSFunction> function,
43 uint32_t index);
44
45 // Wraps a given wasm code object, producing a JSFunction that can be called
46 // from JavaScript.
47 Handle<JSFunction> CompileJSToWasmWrapper(Isolate* isolate,
48 wasm::ModuleEnv* module,
49 Handle<String> name,
50 Handle<Code> wasm_code,
51 uint32_t index);
52
53 // Abstracts details of building TurboFan graph nodes for WASM to separate
54 // the WASM decoder from the internal details of TurboFan.
55 class WasmTrapHelper;
56 class WasmGraphBuilder {
57 public:
58 WasmGraphBuilder(Zone* z, JSGraph* g);
59
60 Node** Buffer(size_t count) {
61 if (count > cur_bufsize_) {
62 size_t new_size = count + cur_bufsize_ + 5;
63 cur_buffer_ =
64 reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*)));
65 cur_bufsize_ = new_size;
66 }
67 return cur_buffer_;
68 }
69
70 //-----------------------------------------------------------------------
71 // Operations independent of {control} or {effect}.
72 //-----------------------------------------------------------------------
73 Node* Error();
74 Node* Start(unsigned params);
75 Node* Param(unsigned index, wasm::LocalType type);
76 Node* Loop(Node* entry);
77 Node* Terminate(Node* effect, Node* control);
78 Node* Merge(unsigned count, Node** controls);
79 Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control);
80 Node* EffectPhi(unsigned count, Node** effects, Node* control);
81 Node* Int32Constant(int32_t value);
82 Node* Int64Constant(int64_t value);
83 Node* Float32Constant(float value);
84 Node* Float64Constant(double value);
85 Node* Constant(Handle<Object> value);
86 Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right);
87 Node* Unop(wasm::WasmOpcode opcode, Node* input);
88 unsigned InputCount(Node* node);
89 bool IsPhiWithMerge(Node* phi, Node* merge);
90 void AppendToMerge(Node* merge, Node* from);
91 void AppendToPhi(Node* merge, Node* phi, Node* from);
92
93 //-----------------------------------------------------------------------
94 // Operations that read and/or write {control} and {effect}.
95 //-----------------------------------------------------------------------
96 Node* Branch(Node* cond, Node** true_node, Node** false_node);
97 Node* Switch(unsigned count, Node* key);
98 Node* IfValue(int32_t value, Node* sw);
99 Node* IfDefault(Node* sw);
100 Node* Return(unsigned count, Node** vals);
101 Node* ReturnVoid();
102 Node* Unreachable();
103
104 Node* CallDirect(uint32_t index, Node** args);
105 Node* CallIndirect(uint32_t index, Node** args);
106 void BuildJSToWasmWrapper(Handle<Code> wasm_code, wasm::FunctionSig* sig);
107 void BuildWasmToJSWrapper(Handle<JSFunction> function,
108 wasm::FunctionSig* sig);
109 Node* ToJS(Node* node, Node* context, wasm::LocalType type);
110 Node* FromJS(Node* node, Node* context, wasm::LocalType type);
111 Node* Invert(Node* node);
112 Node* FunctionTable();
113
114 //-----------------------------------------------------------------------
115 // Operations that concern the linear memory.
116 //-----------------------------------------------------------------------
117 Node* MemSize(uint32_t offset);
118 Node* LoadGlobal(uint32_t index);
119 Node* StoreGlobal(uint32_t index, Node* val);
120 Node* LoadMem(wasm::LocalType type, MachineType memtype, Node* index,
121 uint32_t offset);
122 Node* StoreMem(MachineType type, Node* index, uint32_t offset, Node* val);
123
124 static void PrintDebugName(Node* node);
125
126 Node* Control() { return *control_; }
127 Node* Effect() { return *effect_; }
128
129 void set_module(wasm::ModuleEnv* module) { this->module_ = module; }
130
131 void set_control_ptr(Node** control) { this->control_ = control; }
132
133 void set_effect_ptr(Node** effect) { this->effect_ = effect; }
134
135 private:
136 static const int kDefaultBufferSize = 16;
137 friend class WasmTrapHelper;
138
139 Zone* zone_;
140 JSGraph* jsgraph_;
141 wasm::ModuleEnv* module_;
142 Node* mem_buffer_;
143 Node* mem_size_;
144 Node* function_table_;
145 Node** control_;
146 Node** effect_;
147 Node** cur_buffer_;
148 size_t cur_bufsize_;
149 Node* def_buffer_[kDefaultBufferSize];
150
151 WasmTrapHelper* trap_;
152
153 // Internal helper methods.
154 JSGraph* jsgraph() { return jsgraph_; }
155 Graph* graph();
156
157 Node* String(const char* string);
158 Node* MemBuffer(uint32_t offset);
159 void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset);
160
161 Node* BuildWasmCall(wasm::FunctionSig* sig, Node** args);
162 Node* BuildF32CopySign(Node* left, Node* right);
163 Node* BuildF64CopySign(Node* left, Node* right);
164 Node* BuildI32Ctz(Node* input);
165 Node* BuildI32Popcnt(Node* input);
166 Node* BuildI64Ctz(Node* input);
167 Node* BuildI64Popcnt(Node* input);
168
169 Node** Realloc(Node** buffer, size_t count) {
170 Node** buf = Buffer(count);
171 if (buf != buffer) memcpy(buf, buffer, count * sizeof(Node*));
172 return buf;
173 }
174 };
175 } // namespace compiler
176 } // namespace internal
177 } // namespace v8
178
179 #endif // V8_COMPILER_WASM_COMPILER_H_
OLDNEW
« no previous file with comments | « src/DEPS ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698