[wasm] Move WasmCompilationUnit to .h file.

Removed wrapper functions.

BUG=

Review-Url: https://codereview.chromium.org/1994963002
Cr-Commit-Position: refs/heads/master@{#36372}
This commit is contained in:
mtrofin 2016-05-19 08:51:26 -07:00 committed by Commit bot
parent a2956f4243
commit d94fbbe0f7
3 changed files with 159 additions and 184 deletions

View File

@ -2939,11 +2939,11 @@ std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
return std::make_pair(jsgraph, source_position_table);
}
class WasmCompilationUnit {
public:
WasmCompilationUnit(wasm::ErrorThrower* thrower, Isolate* isolate,
WasmCompilationUnit::WasmCompilationUnit(wasm::ErrorThrower* thrower,
Isolate* isolate,
wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function, uint32_t index)
const wasm::WasmFunction* function,
uint32_t index)
: thrower_(thrower),
isolate_(isolate),
module_env_(module_env),
@ -2952,8 +2952,7 @@ class WasmCompilationUnit {
jsgraph_(new (graph_zone()) JSGraph(
isolate, new (graph_zone()) Graph(graph_zone()),
new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr,
nullptr,
new (graph_zone()) MachineOperatorBuilder(
nullptr, new (graph_zone()) MachineOperatorBuilder(
graph_zone(), MachineType::PointerRepresentation(),
InstructionSelector::SupportedMachineOperatorFlags()))),
compilation_zone_(isolate->allocator()),
@ -2968,11 +2967,9 @@ class WasmCompilationUnit {
ok_(true) {
// Create and cache this node in the main thread.
jsgraph_->CEntryStubConstant(1);
}
}
Zone* graph_zone() { return graph_zone_.get(); }
void ExecuteCompilation() {
void WasmCompilationUnit::ExecuteCompilation() {
// TODO(ahaas): The counters are not thread-safe at the moment.
// HistogramTimerScope wasm_compile_function_time_scope(
// isolate_->counters()->wasm_compile_function_time());
@ -3029,9 +3026,9 @@ class WasmCompilationUnit {
function_->code_start_offset),
decode_ms, node_count, pipeline_ms);
}
}
}
Handle<Code> FinishCompilation() {
Handle<Code> WasmCompilationUnit::FinishCompilation() {
if (!ok_) {
return Handle<Code>::null();
}
@ -3069,50 +3066,6 @@ class WasmCompilationUnit {
}
return code;
}
wasm::ErrorThrower* thrower_;
Isolate* isolate_;
wasm::ModuleEnv* module_env_;
const wasm::WasmFunction* function_;
// The graph zone is deallocated at the end of ExecuteCompilation.
base::SmartPointer<Zone> graph_zone_;
JSGraph* jsgraph_;
Zone compilation_zone_;
CompilationInfo info_;
base::SmartPointer<CompilationJob> job_;
uint32_t index_;
bool ok_;
};
WasmCompilationUnit* CreateWasmCompilationUnit(
wasm::ErrorThrower* thrower, Isolate* isolate, wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function, uint32_t index) {
return new WasmCompilationUnit(thrower, isolate, module_env, function, index);
}
void ExecuteCompilation(WasmCompilationUnit* unit) {
unit->ExecuteCompilation();
}
uint32_t GetIndexOfWasmCompilationUnit(WasmCompilationUnit* unit) {
return unit->index_;
}
Handle<Code> FinishCompilation(WasmCompilationUnit* unit) {
Handle<Code> result = unit->FinishCompilation();
delete unit;
return result;
}
// Helper function to compile a single function.
Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower, Isolate* isolate,
wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function) {
WasmCompilationUnit* unit =
CreateWasmCompilationUnit(thrower, isolate, module_env, function, 0);
ExecuteCompilation(unit);
return FinishCompilation(unit);
}
} // namespace compiler

View File

@ -7,6 +7,7 @@
// Clients of this interface shouldn't depend on lots of compiler internals.
// Do not include anything from src/compiler here!
#include "src/compiler.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/zone.h"
@ -20,7 +21,6 @@ class JSGraph;
class Graph;
class Operator;
class SourcePositionTable;
class WasmCompilationUnit;
}
namespace wasm {
@ -35,10 +35,41 @@ typedef compiler::JSGraph TFGraph;
}
namespace compiler {
// Compiles a single function, producing a code object.
Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower, Isolate* isolate,
class WasmCompilationUnit final {
public:
WasmCompilationUnit(wasm::ErrorThrower* thrower, Isolate* isolate,
wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function);
const wasm::WasmFunction* function, uint32_t index);
Zone* graph_zone() { return graph_zone_.get(); }
int index() const { return index_; }
void ExecuteCompilation();
Handle<Code> FinishCompilation();
static Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower,
Isolate* isolate,
wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function) {
WasmCompilationUnit unit(thrower, isolate, module_env, function, 0);
unit.ExecuteCompilation();
return unit.FinishCompilation();
}
private:
wasm::ErrorThrower* thrower_;
Isolate* isolate_;
wasm::ModuleEnv* module_env_;
const wasm::WasmFunction* function_;
// The graph zone is deallocated at the end of ExecuteCompilation.
base::SmartPointer<Zone> graph_zone_;
JSGraph* jsgraph_;
Zone compilation_zone_;
CompilationInfo info_;
base::SmartPointer<CompilationJob> job_;
uint32_t index_;
bool ok_;
};
// Wraps a JS function, producing a code object that can be called from WASM.
Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
@ -53,16 +84,6 @@ Handle<JSFunction> CompileJSToWasmWrapper(
Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name,
Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index);
WasmCompilationUnit* CreateWasmCompilationUnit(
wasm::ErrorThrower* thrower, Isolate* isolate, wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function, uint32_t index);
void ExecuteCompilation(WasmCompilationUnit* unit);
Handle<Code> FinishCompilation(WasmCompilationUnit* unit);
uint32_t GetIndexOfWasmCompilationUnit(WasmCompilationUnit* unit);
// Abstracts details of building TurboFan graph nodes for WASM to separate
// the WASM decoder from the internal details of TurboFan.
class WasmTrapHelper;

View File

@ -411,7 +411,7 @@ bool FetchAndExecuteCompilationUnit(
compiler::WasmCompilationUnit* unit = compilation_units->at(index);
if (unit != nullptr) {
compiler::ExecuteCompilation(unit);
unit->ExecuteCompilation();
{
base::LockGuard<base::Mutex> guard(result_mutex);
executed_units->push(unit);
@ -498,7 +498,7 @@ void InitializeParallelCompilation(
}
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) {
compilation_units[i] = compiler::CreateWasmCompilationUnit(
compilation_units[i] = new compiler::WasmCompilationUnit(
&thrower, isolate, &module_env, &functions[i], i);
}
}
@ -553,8 +553,9 @@ void FinishCompilationUnits(
unit = executed_units.front();
executed_units.pop();
}
int j = compiler::GetIndexOfWasmCompilationUnit(unit);
results[j] = compiler::FinishCompilation(unit);
int j = unit->index();
results[j] = unit->FinishCompilation();
delete unit;
}
}
@ -580,8 +581,8 @@ bool FinishCompilation(Isolate* isolate, WasmModule* module,
code = results[i];
} else {
// Compile the function.
code =
compiler::CompileWasmFunction(&thrower, isolate, &module_env, &func);
code = compiler::WasmCompilationUnit::CompileWasmFunction(
&thrower, isolate, &module_env, &func);
}
if (code.is_null()) {
thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(),
@ -772,7 +773,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
if (!FinishCompilation(isolate, this, ffi, results, instance, code_table,
thrower, factory, module_env, total_code_size,
desc)) {
return MaybeHandle<JSObject>();
instance.js_object = Handle<JSObject>::null();
}
// Patch all direct call sites.
@ -930,8 +931,8 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module) {
for (const WasmFunction& func : module->functions) {
DCHECK_EQ(index, func.func_index);
// Compile the function and install it in the code table.
Handle<Code> code =
compiler::CompileWasmFunction(&thrower, isolate, &module_env, &func);
Handle<Code> code = compiler::WasmCompilationUnit::CompileWasmFunction(
&thrower, isolate, &module_env, &func);
if (!code.is_null()) {
if (func.exported) {
main_code = code;