Commit e3d4d9b4 authored by Nico Hartmann's avatar Nico Hartmann Committed by Commit Bot

[wasm] Remove a copy of all nodes in loop unrolling

Bug: v8:11298
Change-Id: I99d36812aabd99fd92a20f743705aee193914381
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2731530Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73158}
parent 88bf5914
......@@ -658,34 +658,6 @@ void NodeCopier::Insert(Node* original, Node* copy) {
copies_->push_back(copy);
}
void NodeCopier::CopyNodes(Graph* graph, Zone* tmp_zone_, Node* dead,
NodeRange nodes,
SourcePositionTable* source_positions,
NodeOriginTable* node_origins) {
// Copy all the nodes first.
for (Node* original : nodes) {
SourcePositionTable::Scope position(
source_positions, source_positions->GetSourcePosition(original));
NodeOriginTable::Scope origin_scope(node_origins, "copy nodes", original);
node_map_.Set(original, copies_->size() + 1);
copies_->push_back(original);
for (uint32_t copy_index = 0; copy_index < copy_count_; copy_index++) {
Node* copy = graph->CloneNode(original);
copies_->push_back(copy);
}
}
// Fix inputs of the copies.
for (Node* original : nodes) {
for (uint32_t copy_index = 0; copy_index < copy_count_; copy_index++) {
Node* copy = map(original, copy_index);
for (int i = 0; i < copy->InputCount(); i++) {
copy->ReplaceInput(i, map(original->InputAt(i), copy_index));
}
}
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -216,9 +216,34 @@ class NodeCopier {
// Helper version of {Insert} for one copy.
void Insert(Node* original, Node* copy);
void CopyNodes(Graph* graph, Zone* tmp_zone_, Node* dead, NodeRange nodes,
template <typename InputIterator>
void CopyNodes(Graph* graph, Zone* tmp_zone_, Node* dead,
base::iterator_range<InputIterator> nodes,
SourcePositionTable* source_positions,
NodeOriginTable* node_origins);
NodeOriginTable* node_origins) {
// Copy all the nodes first.
for (Node* original : nodes) {
SourcePositionTable::Scope position(
source_positions, source_positions->GetSourcePosition(original));
NodeOriginTable::Scope origin_scope(node_origins, "copy nodes", original);
node_map_.Set(original, copies_->size() + 1);
copies_->push_back(original);
for (uint32_t copy_index = 0; copy_index < copy_count_; copy_index++) {
Node* copy = graph->CloneNode(original);
copies_->push_back(copy);
}
}
// Fix inputs of the copies.
for (Node* original : nodes) {
for (uint32_t copy_index = 0; copy_index < copy_count_; copy_index++) {
Node* copy = map(original, copy_index);
for (int i = 0; i < copy->InputCount(); i++) {
copy->ReplaceInput(i, map(original->InputAt(i), copy_index));
}
}
}
}
bool Marked(Node* node) { return node_map_.Get(node) > 0; }
......
......@@ -36,11 +36,9 @@ void UnrollLoop(Node* loop_node, ZoneUnorderedSet<Node*>* loop, uint32_t depth,
NodeCopier copier(graph, copied_size, &copies, unrolling_count);
{
std::vector<Node*> loop_nodes(loop->begin(), loop->end());
copier.CopyNodes(
graph, tmp_zone, graph->NewNode(common->Dead()),
NodeRange(loop_nodes.data(), loop_nodes.data() + loop_nodes.size()),
source_positions, node_origins);
copier.CopyNodes(graph, tmp_zone, graph->NewNode(common->Dead()),
base::make_iterator_range(loop->begin(), loop->end()),
source_positions, node_origins);
}
#define COPY(node, n) copier.map(node, n)
......
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