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) {
return Changed(node);
}
Reduction JSTypedLowering::ReduceJSLoadModule(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadModule, node->opcode());
Node* JSTypedLowering::BuildGetModuleCell(Node* node) {
DCHECK(node->opcode() == IrOpcode::kJSLoadModule ||
node->opcode() == IrOpcode::kJSStoreModule);
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
int32_t cell_index = OpParameter<int32_t>(node);
Node* module = NodeProperties::GetValueInput(node, 0);
Node* array;
FieldAccess field_access;
int index;
if (ModuleDescriptor::GetCellIndexKind(cell_index) ==
ModuleDescriptor::kExport) {
array = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForModuleRegularExports()),
module, effect, control);
field_access = AccessBuilder::ForModuleRegularExports();
index = cell_index - 1;
} else {
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kImport);
array = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForModuleRegularImports()),
module, effect, control);
field_access = AccessBuilder::ForModuleRegularImports();
index = -cell_index - 1;
}
Node* cell = effect = graph()->NewNode(
Node* array = effect = graph()->NewNode(simplified()->LoadField(field_access),
module, effect, control);
return graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForFixedArraySlot(index)), array,
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 =
graph()->NewNode(simplified()->LoadField(AccessBuilder::ForCellValue()),
cell, effect, control);
......@@ -1432,32 +1438,12 @@ Reduction JSTypedLowering::ReduceJSStoreModule(Node* node) {
DCHECK_EQ(IrOpcode::kJSStoreModule, node->opcode());
Node* effect = NodeProperties::GetEffectInput(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);
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(OpParameter<int32_t>(node)),
ModuleDescriptor::kExport);
Node* array;
int index;
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);
Node* cell = BuildGetModuleCell(node);
if (cell->op()->EffectOutputCount() > 0) effect = cell;
effect =
graph()->NewNode(simplified()->StoreField(AccessBuilder::ForCellValue()),
cell, value, effect, control);
......
......@@ -88,6 +88,9 @@ class V8_EXPORT_PRIVATE JSTypedLowering final
Reduction ReduceSpeculativeNumberBinop(Node* node);
Reduction ReduceSpeculativeNumberComparison(Node* node);
// Helper for ReduceJSLoadModule and ReduceJSStoreModule.
Node* BuildGetModuleCell(Node* node);
Factory* factory() const;
Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; }
......
......@@ -20141,33 +20141,34 @@ void Module::CreateExport(Handle<Module> module, int cell_index,
module->set_exports(*exports);
}
Handle<Object> Module::LoadVariable(Handle<Module> module, int cell_index) {
Isolate* isolate = module->GetIsolate();
Handle<Object> object;
Cell* Module::GetCell(int cell_index) {
DisallowHeapAllocation no_gc;
Object* cell;
switch (ModuleDescriptor::GetCellIndexKind(cell_index)) {
case ModuleDescriptor::kImport:
object = handle(module->regular_imports()->get(ImportIndex(cell_index)),
isolate);
cell = regular_imports()->get(ImportIndex(cell_index));
break;
case ModuleDescriptor::kExport:
object = handle(module->regular_exports()->get(ExportIndex(cell_index)),
isolate);
cell = regular_exports()->get(ExportIndex(cell_index));
break;
case ModuleDescriptor::kInvalid:
UNREACHABLE();
cell = nullptr;
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,
Handle<Object> value) {
Isolate* isolate = module->GetIsolate();
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kExport);
Handle<Object> object(module->regular_exports()->get(ExportIndex(cell_index)),
isolate);
Handle<Cell>::cast(object)->set_value(*value);
module->GetCell(cell_index)->set_value(*value);
}
MaybeHandle<Cell> Module::ResolveImport(Handle<Module> module,
......
......@@ -6751,6 +6751,7 @@ class Module : public Struct {
// Implementation of spec operation ModuleEvaluation.
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 void StoreVariable(Handle<Module> module, int cell_index,
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