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

Side by Side Diff: src/wasm/encoder.h

Issue 2280063002: [asm.js] (Re)use temporaries in asm->wasm conversion. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [asm.js] (Re)use temporaries in asm->wasm conversion. Created 4 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
« no previous file with comments | « src/asmjs/asm-wasm-builder.cc ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_WASM_ENCODER_H_ 5 #ifndef V8_WASM_ENCODER_H_
6 #define V8_WASM_ENCODER_H_ 6 #define V8_WASM_ENCODER_H_
7 7
8 #include "src/signature.h" 8 #include "src/signature.h"
9 #include "src/zone-containers.h" 9 #include "src/zone-containers.h"
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 bool exported() { return exported_; } 129 bool exported() { return exported_; }
130 130
131 // Writing methods. 131 // Writing methods.
132 void WriteSignature(ZoneBuffer& buffer) const; 132 void WriteSignature(ZoneBuffer& buffer) const;
133 void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const; 133 void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const;
134 void WriteBody(ZoneBuffer& buffer) const; 134 void WriteBody(ZoneBuffer& buffer) const;
135 135
136 private: 136 private:
137 explicit WasmFunctionBuilder(WasmModuleBuilder* builder); 137 explicit WasmFunctionBuilder(WasmModuleBuilder* builder);
138 friend class WasmModuleBuilder; 138 friend class WasmModuleBuilder;
139 friend class WasmTemporary;
139 WasmModuleBuilder* builder_; 140 WasmModuleBuilder* builder_;
140 LocalDeclEncoder locals_; 141 LocalDeclEncoder locals_;
141 uint32_t signature_index_; 142 uint32_t signature_index_;
142 bool exported_; 143 bool exported_;
143 ZoneVector<uint8_t> body_; 144 ZoneVector<uint8_t> body_;
144 ZoneVector<char> name_; 145 ZoneVector<char> name_;
146 ZoneVector<uint32_t> i32_temps_;
147 ZoneVector<uint32_t> i64_temps_;
148 ZoneVector<uint32_t> f32_temps_;
149 ZoneVector<uint32_t> f64_temps_;
150 };
151
152 class WasmTemporary {
153 public:
154 WasmTemporary(WasmFunctionBuilder* builder, LocalType type) {
155 switch (type) {
156 case kAstI32:
157 temporary_ = &builder->i32_temps_;
158 break;
159 case kAstI64:
160 temporary_ = &builder->i64_temps_;
161 break;
162 case kAstF32:
163 temporary_ = &builder->f32_temps_;
164 break;
165 case kAstF64:
166 temporary_ = &builder->f64_temps_;
167 break;
168 default:
169 UNREACHABLE();
170 temporary_ = nullptr;
171 }
172 if (temporary_->size() == 0) {
173 // Allocate a new temporary.
174 index_ = builder->AddLocal(type);
175 } else {
176 // Reuse a previous temporary.
177 index_ = temporary_->back();
178 temporary_->pop_back();
179 }
180 }
181 ~WasmTemporary() {
182 temporary_->push_back(index_); // return the temporary to the list.
183 }
184 uint32_t index() { return index_; }
185
186 private:
187 ZoneVector<uint32_t>* temporary_;
188 uint32_t index_;
145 }; 189 };
146 190
147 // TODO(titzer): kill! 191 // TODO(titzer): kill!
148 class WasmDataSegmentEncoder : public ZoneObject { 192 class WasmDataSegmentEncoder : public ZoneObject {
149 public: 193 public:
150 WasmDataSegmentEncoder(Zone* zone, const byte* data, uint32_t size, 194 WasmDataSegmentEncoder(Zone* zone, const byte* data, uint32_t size,
151 uint32_t dest); 195 uint32_t dest);
152 void Write(ZoneBuffer& buffer) const; 196 void Write(ZoneBuffer& buffer) const;
153 197
154 private: 198 private:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ZoneVector<std::pair<LocalType, bool>> globals_; 240 ZoneVector<std::pair<LocalType, bool>> globals_;
197 SignatureMap signature_map_; 241 SignatureMap signature_map_;
198 int start_function_index_; 242 int start_function_index_;
199 }; 243 };
200 244
201 } // namespace wasm 245 } // namespace wasm
202 } // namespace internal 246 } // namespace internal
203 } // namespace v8 247 } // namespace v8
204 248
205 #endif // V8_WASM_ENCODER_H_ 249 #endif // V8_WASM_ENCODER_H_
OLDNEW
« no previous file with comments | « src/asmjs/asm-wasm-builder.cc ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698