v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
map-inference.cc
Go to the documentation of this file.
1// Copyright 2019 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
11#include "src/objects/map-inl.h"
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
26
28
30
37
39
40bool MapInference::HaveMaps() const { return !maps_.is_empty(); }
41
44 static_cast<bool (*)(InstanceType)>(&InstanceTypeChecker::IsJSReceiver));
45}
46
48 CHECK(!InstanceTypeChecker::IsString(type));
50 [type](InstanceType other) { return type == other; });
51}
52
54 CHECK(!InstanceTypeChecker::IsString(type));
56 [type](InstanceType other) { return type == other; });
57}
58
63
65 std::function<bool(InstanceType)> f) const {
66 CHECK(HaveMaps());
67
68 auto instance_type = [f](MapRef map) { return f(map.instance_type()); };
69 return std::all_of(maps_.begin(), maps_.end(), instance_type);
70}
71
73 std::function<bool(InstanceType)> f) const {
74 CHECK(HaveMaps());
75
76 auto instance_type = [f](MapRef map) { return f(map.instance_type()); };
77
78 return std::any_of(maps_.begin(), maps_.end(), instance_type);
79}
80
85
86bool MapInference::Is(MapRef expected_map) {
87 if (!HaveMaps()) return false;
88 if (maps_.size() != 1) return false;
89 return maps_.at(0).equals(expected_map);
90}
91
93 Control control,
94 const FeedbackSource& feedback) {
95 CHECK(HaveMaps());
96 CHECK(feedback.IsValid());
97 *effect = jsgraph->graph()->NewNode(
98 jsgraph->simplified()->CheckMaps(CheckMapsFlag::kNone, maps_, feedback),
99 object_, *effect, control);
100 SetGuarded();
101}
102
104 CompilationDependencies* dependencies) {
105 CHECK(HaveMaps());
106 return RelyOnMapsHelper(dependencies, nullptr, nullptr, Control{nullptr}, {});
107}
108
110 CompilationDependencies* dependencies, JSGraph* jsgraph, Effect* effect,
111 Control control, const FeedbackSource& feedback) {
112 CHECK(HaveMaps());
113 if (Safe()) return false;
114 if (RelyOnMapsViaStability(dependencies)) return true;
115 CHECK(RelyOnMapsHelper(nullptr, jsgraph, effect, control, feedback));
116 return false;
117}
118
120 JSGraph* jsgraph, Effect* effect,
121 Control control,
122 const FeedbackSource& feedback) {
123 if (Safe()) return true;
124
125 auto is_stable = [](MapRef map) { return map.is_stable(); };
126 if (dependencies != nullptr &&
127 std::all_of(maps_.begin(), maps_.end(), is_stable)) {
128 for (MapRef map : maps_) {
129 dependencies->DependOnStableMap(map);
130 }
131 SetGuarded();
132 return true;
133 } else if (feedback.IsValid()) {
134 InsertMapChecks(jsgraph, effect, control, feedback);
135 return true;
136 } else {
137 return false;
138 }
139}
140
142 SetGuarded();
143 maps_.clear(); // Just to make some CHECKs fail if {this} gets used after.
144 return Reducer::NoChange();
145}
146
147} // namespace compiler
148} // namespace internal
149} // namespace v8
JSGraph * jsgraph
V8_WARN_UNUSED_RESULT bool Is(MapRef expected_map)
bool RelyOnMapsPreferStability(CompilationDependencies *dependencies, JSGraph *jsgraph, Effect *effect, Control control, const FeedbackSource &feedback)
enum v8::internal::compiler::MapInference::@47 maps_state_
V8_WARN_UNUSED_RESULT bool AllOfInstanceTypesUnsafe(std::function< bool(InstanceType)> f) const
V8_WARN_UNUSED_RESULT bool RelyOnMapsViaStability(CompilationDependencies *dependencies)
V8_WARN_UNUSED_RESULT ZoneRefSet< Map > const & GetMaps()
V8_WARN_UNUSED_RESULT bool AllOfInstanceTypesAre(InstanceType type) const
MapInference(JSHeapBroker *broker, Node *object, Effect effect)
V8_WARN_UNUSED_RESULT Reduction NoChange()
void InsertMapChecks(JSGraph *jsgraph, Effect *effect, Control control, const FeedbackSource &feedback)
V8_WARN_UNUSED_RESULT bool RelyOnMapsHelper(CompilationDependencies *dependencies, JSGraph *jsgraph, Effect *effect, Control control, const FeedbackSource &feedback)
V8_WARN_UNUSED_RESULT bool AnyOfInstanceTypesUnsafe(std::function< bool(InstanceType)> f) const
V8_WARN_UNUSED_RESULT bool HaveMaps() const
V8_WARN_UNUSED_RESULT bool AllOfInstanceTypesAreJSReceiver() const
V8_WARN_UNUSED_RESULT bool AnyOfInstanceTypesAre(InstanceType type) const
V8_WARN_UNUSED_RESULT bool AllOfInstanceTypes(std::function< bool(InstanceType)> f)
static InferMapsResult InferMapsUnsafe(JSHeapBroker *broker, Node *receiver, Effect effect, ZoneRefSet< Map > *maps_out)
Register const object_
JSHeapBroker *const broker_
JSHeapBroker * broker
std::map< const std::string, const std::string > map
ZoneVector< RpoNumber > & result
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_EQ(v1, v2)
Definition logging.h:485