v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
pair-load-store-reducer.cc
Go to the documentation of this file.
1// Copyright 2023 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <optional>
8
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15namespace {
16
17std::optional<std::tuple<int, const Operator*>> CanBePaired(
18 Node* node1, Node* node2, MachineOperatorBuilder* machine,
19 Isolate* isolate) {
20 DCHECK(node1->opcode() == IrOpcode::kStore &&
21 node1->opcode() == IrOpcode::kStore);
22
23 Node* base1 = node1->InputAt(0);
24 Node* base2 = node2->InputAt(0);
25 if (base1 != base2) return {};
26
27 auto rep1 = StoreRepresentationOf(node1->op());
28 auto rep2 = StoreRepresentationOf(node2->op());
29 auto combo = machine->TryStorePair(rep1, rep2);
30 if (!combo) return {};
31
32 Node* index1 = node1->InputAt(1);
33 Node* index2 = node2->InputAt(1);
34
35 int idx1, idx2;
36 if (index1->opcode() == IrOpcode::kInt64Constant) {
37 idx1 = static_cast<int>(OpParameter<int64_t>(index1->op()));
38 } else {
39 return {};
40 }
41 if (index2->opcode() == IrOpcode::kInt64Constant) {
42 idx2 = static_cast<int>(OpParameter<int64_t>(index2->op()));
43 } else {
44 return {};
45 }
46
47 int bytesize = 1 << ElementSizeLog2Of(rep1.representation());
48 int diff = idx2 - idx1;
49 if (diff != bytesize && diff != -bytesize) {
50 return {};
51 }
52
53 return {{diff, *combo}};
54}
55
56} // namespace
57
59 MachineGraph* mcgraph,
60 Isolate* isolate)
61 : AdvancedReducer(editor), mcgraph_(mcgraph), isolate_(isolate) {}
62
64 if (cur->opcode() != IrOpcode::kStore) {
65 return Reduction();
66 }
67
69 if (prev->opcode() != IrOpcode::kStore) {
70 return Reduction();
71 }
72
73 if (!prev->OwnedBy(cur)) {
74 return Reduction();
75 }
76
77 auto pairing = CanBePaired(prev, cur, mcgraph_->machine(), isolate_);
78 if (!pairing) return Reduction();
79
80 if (std::get<int>(*pairing) > 0) {
81 prev->InsertInput(mcgraph_->zone(), 3, cur->InputAt(2));
82 } else {
84 prev->InsertInput(mcgraph_->zone(), 2, cur->InputAt(2));
85 }
86 NodeProperties::ChangeOp(prev, std::get<const Operator*>(*pairing));
87 Replace(cur, prev);
88 cur->Kill();
89 return Reduction(prev);
90}
91
92} // namespace compiler
93} // namespace internal
94} // namespace v8
Isolate * isolate_
MachineOperatorBuilder * machine() const
static void ChangeOp(Node *node, const Operator *new_op)
static Node * GetEffectInput(Node *node, int index=0)
static void ReplaceValueInput(Node *node, Node *value, int index)
constexpr IrOpcode::Value opcode() const
Definition node.h:52
Node * InputAt(int index) const
Definition node.h:70
bool OwnedBy(Node const *owner) const
Definition node.cc:325
void InsertInput(Zone *zone, int index, Node *new_to)
Definition node.cc:203
PairLoadStoreReducer(Editor *editor, MachineGraph *mcgraph, Isolate *isolate_)
StoreRepresentation const & StoreRepresentationOf(Operator const *op)
T const & OpParameter(const Operator *op)
Definition operator.h:214
V8_EXPORT_PRIVATE constexpr int ElementSizeLog2Of(MachineRepresentation)
#define DCHECK(condition)
Definition logging.h:482
MachineGraph * mcgraph_