1 // Copyright 2017 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_PROPERTY_ACCESS_BUILDER_H_
6 #define V8_COMPILER_PROPERTY_ACCESS_BUILDER_H_
7 
8 #include <vector>
9 
10 #include "src/handles.h"
11 #include "src/objects/map.h"
12 #include "src/zone/zone-containers.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class CompilationDependencies;
18 
19 namespace compiler {
20 
21 class CommonOperatorBuilder;
22 class Graph;
23 class JSGraph;
24 class Node;
25 class PropertyAccessInfo;
26 class SimplifiedOperatorBuilder;
27 
28 class PropertyAccessBuilder {
29  public:
PropertyAccessBuilder(JSGraph * jsgraph,CompilationDependencies * dependencies)30   PropertyAccessBuilder(JSGraph* jsgraph, CompilationDependencies* dependencies)
31       : jsgraph_(jsgraph), dependencies_(dependencies) {}
32 
33   // Builds the appropriate string check if the maps are only string
34   // maps.
35   bool TryBuildStringCheck(MapHandles const& maps, Node** receiver,
36                            Node** effect, Node* control);
37   // Builds a number check if all maps are number maps.
38   bool TryBuildNumberCheck(MapHandles const& maps, Node** receiver,
39                            Node** effect, Node* control);
40 
41   Node* BuildCheckHeapObject(Node* receiver, Node** effect, Node* control);
42   void BuildCheckMaps(Node* receiver, Node** effect, Node* control,
43                       std::vector<Handle<Map>> const& receiver_maps);
44   Node* BuildCheckValue(Node* receiver, Node** effect, Node* control,
45                         Handle<HeapObject> value);
46 
47   // Adds stability dependencies on all prototypes of every class in
48   // {receiver_type} up to (and including) the {holder}.
49   void AssumePrototypesStable(Handle<Context> native_context,
50                               std::vector<Handle<Map>> const& receiver_maps,
51                               Handle<JSObject> holder);
52 
53   // Builds the actual load for data-field and data-constant-field
54   // properties (without heap-object or map checks).
55   Node* BuildLoadDataField(Handle<Name> name,
56                            PropertyAccessInfo const& access_info,
57                            Node* receiver, Node** effect, Node** control);
58 
59  private:
jsgraph()60   JSGraph* jsgraph() const { return jsgraph_; }
dependencies()61   CompilationDependencies* dependencies() const { return dependencies_; }
62   Graph* graph() const;
63   Isolate* isolate() const;
64   CommonOperatorBuilder* common() const;
65   SimplifiedOperatorBuilder* simplified() const;
66 
67   Node* TryBuildLoadConstantDataField(Handle<Name> name,
68                                       PropertyAccessInfo const& access_info,
69                                       Node* receiver);
70   // Returns a node with the holder for the property access described by
71   // {access_info}.
72   Node* ResolveHolder(PropertyAccessInfo const& access_info, Node* receiver);
73 
74   JSGraph* jsgraph_;
75   CompilationDependencies* dependencies_;
76 };
77 
78 bool HasOnlyStringMaps(MapHandles const& maps);
79 
80 }  // namespace compiler
81 }  // namespace internal
82 }  // namespace v8
83 
84 #endif  // V8_COMPILER_PROPERTY_ACCESS_BUILDER_H_
85