Commit 973ec26e authored by neis's avatar neis Committed by Commit bot

[modules] Factor out cell load into helper function.

This is just a refactoring, no changes in behavior.

BUG=v8:1569

Review-Url: https://codereview.chromium.org/2839623003
Cr-Commit-Position: refs/heads/master@{#45071}
parent ce5ffd93
...@@ -1391,35 +1391,41 @@ Reduction JSTypedLowering::ReduceJSStoreContext(Node* node) { ...@@ -1391,35 +1391,41 @@ Reduction JSTypedLowering::ReduceJSStoreContext(Node* node) {
return Changed(node); return Changed(node);
} }
Reduction JSTypedLowering::ReduceJSLoadModule(Node* node) { Node* JSTypedLowering::BuildGetModuleCell(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadModule, node->opcode()); DCHECK(node->opcode() == IrOpcode::kJSLoadModule ||
node->opcode() == IrOpcode::kJSStoreModule);
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node); Node* control = NodeProperties::GetControlInput(node);
int32_t cell_index = OpParameter<int32_t>(node); int32_t cell_index = OpParameter<int32_t>(node);
Node* module = NodeProperties::GetValueInput(node, 0); Node* module = NodeProperties::GetValueInput(node, 0);
Node* array; FieldAccess field_access;
int index; int index;
if (ModuleDescriptor::GetCellIndexKind(cell_index) == if (ModuleDescriptor::GetCellIndexKind(cell_index) ==
ModuleDescriptor::kExport) { ModuleDescriptor::kExport) {
array = effect = graph()->NewNode( field_access = AccessBuilder::ForModuleRegularExports();
simplified()->LoadField(AccessBuilder::ForModuleRegularExports()),
module, effect, control);
index = cell_index - 1; index = cell_index - 1;
} else { } else {
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index), DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kImport); ModuleDescriptor::kImport);
array = effect = graph()->NewNode( field_access = AccessBuilder::ForModuleRegularImports();
simplified()->LoadField(AccessBuilder::ForModuleRegularImports()),
module, effect, control);
index = -cell_index - 1; index = -cell_index - 1;
} }
Node* array = effect = graph()->NewNode(simplified()->LoadField(field_access),
Node* cell = effect = graph()->NewNode( module, effect, control);
return graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForFixedArraySlot(index)), array, simplified()->LoadField(AccessBuilder::ForFixedArraySlot(index)), array,
effect, control); effect, control);
}
Reduction JSTypedLowering::ReduceJSLoadModule(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadModule, node->opcode());
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
Node* cell = BuildGetModuleCell(node);
if (cell->op()->EffectOutputCount() > 0) effect = cell;
Node* value = effect = Node* value = effect =
graph()->NewNode(simplified()->LoadField(AccessBuilder::ForCellValue()), graph()->NewNode(simplified()->LoadField(AccessBuilder::ForCellValue()),
cell, effect, control); cell, effect, control);
...@@ -1432,32 +1438,12 @@ Reduction JSTypedLowering::ReduceJSStoreModule(Node* node) { ...@@ -1432,32 +1438,12 @@ Reduction JSTypedLowering::ReduceJSStoreModule(Node* node) {
DCHECK_EQ(IrOpcode::kJSStoreModule, node->opcode()); DCHECK_EQ(IrOpcode::kJSStoreModule, node->opcode());
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node); Node* control = NodeProperties::GetControlInput(node);
int32_t cell_index = OpParameter<int32_t>(node);
Node* module = NodeProperties::GetValueInput(node, 0);
Node* value = NodeProperties::GetValueInput(node, 1); Node* value = NodeProperties::GetValueInput(node, 1);
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(OpParameter<int32_t>(node)),
ModuleDescriptor::kExport);
Node* array; Node* cell = BuildGetModuleCell(node);
int index; if (cell->op()->EffectOutputCount() > 0) effect = cell;
if (ModuleDescriptor::GetCellIndexKind(cell_index) ==
ModuleDescriptor::kExport) {
array = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForModuleRegularExports()),
module, effect, control);
index = cell_index - 1;
} else {
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kImport);
array = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForModuleRegularImports()),
module, effect, control);
index = -cell_index - 1;
}
Node* cell = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForFixedArraySlot(index)), array,
effect, control);
effect = effect =
graph()->NewNode(simplified()->StoreField(AccessBuilder::ForCellValue()), graph()->NewNode(simplified()->StoreField(AccessBuilder::ForCellValue()),
cell, value, effect, control); cell, value, effect, control);
......
...@@ -88,6 +88,9 @@ class V8_EXPORT_PRIVATE JSTypedLowering final ...@@ -88,6 +88,9 @@ class V8_EXPORT_PRIVATE JSTypedLowering final
Reduction ReduceSpeculativeNumberBinop(Node* node); Reduction ReduceSpeculativeNumberBinop(Node* node);
Reduction ReduceSpeculativeNumberComparison(Node* node); Reduction ReduceSpeculativeNumberComparison(Node* node);
// Helper for ReduceJSLoadModule and ReduceJSStoreModule.
Node* BuildGetModuleCell(Node* node);
Factory* factory() const; Factory* factory() const;
Graph* graph() const; Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; } JSGraph* jsgraph() const { return jsgraph_; }
......
...@@ -20141,33 +20141,34 @@ void Module::CreateExport(Handle<Module> module, int cell_index, ...@@ -20141,33 +20141,34 @@ void Module::CreateExport(Handle<Module> module, int cell_index,
module->set_exports(*exports); module->set_exports(*exports);
} }
Handle<Object> Module::LoadVariable(Handle<Module> module, int cell_index) { Cell* Module::GetCell(int cell_index) {
Isolate* isolate = module->GetIsolate(); DisallowHeapAllocation no_gc;
Handle<Object> object; Object* cell;
switch (ModuleDescriptor::GetCellIndexKind(cell_index)) { switch (ModuleDescriptor::GetCellIndexKind(cell_index)) {
case ModuleDescriptor::kImport: case ModuleDescriptor::kImport:
object = handle(module->regular_imports()->get(ImportIndex(cell_index)), cell = regular_imports()->get(ImportIndex(cell_index));
isolate);
break; break;
case ModuleDescriptor::kExport: case ModuleDescriptor::kExport:
object = handle(module->regular_exports()->get(ExportIndex(cell_index)), cell = regular_exports()->get(ExportIndex(cell_index));
isolate);
break; break;
case ModuleDescriptor::kInvalid: case ModuleDescriptor::kInvalid:
UNREACHABLE(); UNREACHABLE();
cell = nullptr;
break; break;
} }
return handle(Handle<Cell>::cast(object)->value(), isolate); return Cell::cast(cell);
}
Handle<Object> Module::LoadVariable(Handle<Module> module, int cell_index) {
Isolate* isolate = module->GetIsolate();
return handle(module->GetCell(cell_index)->value(), isolate);
} }
void Module::StoreVariable(Handle<Module> module, int cell_index, void Module::StoreVariable(Handle<Module> module, int cell_index,
Handle<Object> value) { Handle<Object> value) {
Isolate* isolate = module->GetIsolate();
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index), DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kExport); ModuleDescriptor::kExport);
Handle<Object> object(module->regular_exports()->get(ExportIndex(cell_index)), module->GetCell(cell_index)->set_value(*value);
isolate);
Handle<Cell>::cast(object)->set_value(*value);
} }
MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module, MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module,
......
...@@ -6751,6 +6751,7 @@ class Module : public Struct { ...@@ -6751,6 +6751,7 @@ class Module : public Struct {
// Implementation of spec operation ModuleEvaluation. // Implementation of spec operation ModuleEvaluation.
static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module); static MUST_USE_RESULT MaybeHandle<Object> Evaluate(Handle<Module> module);
Cell* GetCell(int cell_index);
static Handle<Object> LoadVariable(Handle<Module> module, int cell_index); static Handle<Object> LoadVariable(Handle<Module> module, int cell_index);
static void StoreVariable(Handle<Module> module, int cell_index, static void StoreVariable(Handle<Module> module, int cell_index,
Handle<Object> value); Handle<Object> value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment