v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
simplified-lowering-verifier.h
Go to the documentation of this file.
1// Copyright 2022 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
5#ifndef V8_COMPILER_SIMPLIFIED_LOWERING_VERIFIER_H_
6#define V8_COMPILER_SIMPLIFIED_LOWERING_VERIFIER_H_
7
8#include <optional>
9
13
14namespace v8 {
15namespace internal {
16namespace compiler {
17
18class OperationTyper;
19
21 public:
22 struct PerNodeData {
23 std::optional<Type> type = std::nullopt;
25 };
26
28 : hints_(zone),
30 data_(zone),
31 graph_(graph),
32 zone_(zone) {}
33
34 void VisitNode(Node* node, OperationTyper& op_typer);
35
36 void RecordHint(Node* node) {
37 DCHECK_EQ(node->opcode(), IrOpcode::kSLVerifierHint);
38 hints_.push_back(node);
39 }
40 const ZoneVector<Node*>& inserted_hints() const { return hints_; }
42 DCHECK(IrOpcode::IsMachineConstantOpcode(constant->opcode()));
43 auto it = machine_uses_of_constants_.find(constant);
44 if (it == machine_uses_of_constants_.end()) {
45 it =
47 .first;
48 }
49 base::vector_append(it->second, uses);
50 }
55
56 std::optional<Type> GetType(Node* node) const {
57 if (NodeProperties::IsTyped(node)) {
58 Type type = NodeProperties::GetType(node);
59 // We do not use the static type for constants, even if we have one,
60 // because those are cached in the graph and shared between machine
61 // and non-machine subgraphs. The former might have assigned
62 // Type::Machine() to them.
63 if (IrOpcode::IsMachineConstantOpcode(node->opcode())) {
64 DCHECK(type.Is(Type::Machine()));
65 } else {
66 return type;
67 }
68 }
69 // For nodes that have not been typed before SL, we use the type that has
70 // been inferred by the verifier.
71 if (node->id() < data_.size()) {
72 return data_[node->id()].type;
73 }
74 return std::nullopt;
75 }
76
77 private:
79 if (data_.size() <= node->id()) {
80 data_.resize(node->id() + 1);
81 }
82 DCHECK_EQ(data_[node->id()].truncation,
84 }
85
86 void SetType(Node* node, const Type& type) {
88 data_[node->id()].type = type;
89 }
90
91 Type InputType(Node* node, int input_index) const {
92 // TODO(nicohartmann): Check that inputs are typed, once all operators are
93 // supported.
94 auto type_opt = GetType(node->InputAt(input_index));
95 return type_opt.has_value() ? *type_opt : Type::None();
96 }
97
98 void SetTruncation(Node* node, const Truncation& truncation) {
100 data_[node->id()].truncation = truncation;
101 }
102
103 Truncation InputTruncation(Node* node, int input_index) const {
104 static const Truncation any_truncation =
106
107 Node* input = node->InputAt(input_index);
108 if (input->id() < data_.size()) {
109 return data_[input->id()].truncation;
110 }
111 return any_truncation;
112 }
113
114 void CheckType(Node* node, const Type& type);
115 void CheckAndSet(Node* node, const Type& type, const Truncation& trunc);
116 void ReportInvalidTypeCombination(Node* node, const std::vector<Type>& types);
117
118 // Generalize to a less strict truncation in the context of a given type. For
119 // example, a Truncation::kWord32[kIdentifyZeros] does not have any effect on
120 // a type Range(0, 100), because all equivalence classes are singleton, for
121 // the values of the given type. We can use Truncation::Any[kDistinguishZeros]
122 // instead to avoid a combinatorial explosion of occurring type-truncation-
123 // pairs.
125 const Type& type) const;
126 Truncation JoinTruncation(const Truncation& t1, const Truncation& t2);
128 const Truncation& t3) {
129 return JoinTruncation(JoinTruncation(t1, t2), t3);
130 }
131
132 Zone* graph_zone() const { return graph_->zone(); }
133
139};
140
141} // namespace compiler
142} // namespace internal
143} // namespace v8
144
145#endif // V8_COMPILER_SIMPLIFIED_LOWERING_VERIFIER_H_
void push_back(const T &value)
static bool IsMachineConstantOpcode(Value value)
Definition opcodes.h:1374
static Type GetType(const Node *node)
static bool IsTyped(const Node *node)
Node * InputAt(int index) const
Definition node.h:70
const ZoneUnorderedMap< Node *, ZoneVector< Node * > > & machine_uses_of_constants() const
void RecordMachineUsesOfConstant(Node *constant, Node::Uses uses)
Truncation GeneralizeTruncation(const Truncation &truncation, const Type &type) const
ZoneUnorderedMap< Node *, ZoneVector< Node * > > machine_uses_of_constants_
void ReportInvalidTypeCombination(Node *node, const std::vector< Type > &types)
Truncation InputTruncation(Node *node, int input_index) const
Truncation JoinTruncation(const Truncation &t1, const Truncation &t2, const Truncation &t3)
void SetTruncation(Node *node, const Truncation &truncation)
Truncation JoinTruncation(const Truncation &t1, const Truncation &t2)
void CheckAndSet(Node *node, const Type &type, const Truncation &trunc)
static Truncation Any(IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:46
void vector_append(V &v, const C &container)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
wasm::ValueType type