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 "src/base/optional.h" 9#include "src/codegen/machine-type.h" 10#include "src/compiler/js-heap-broker.h" 11#include "src/compiler/node.h" 12#include "src/handles/handles.h" 13#include "src/objects/map.h" 14#include "src/zone/zone-containers.h" 15 16namespace v8 { 17namespace internal { 18namespace compiler { 19 20class CommonOperatorBuilder; 21class CompilationDependencies; 22class Graph; 23class JSGraph; 24class JSHeapBroker; 25class PropertyAccessInfo; 26class SimplifiedOperatorBuilder; 27struct FieldAccess; 28 29class PropertyAccessBuilder { 30 public: 31 PropertyAccessBuilder(JSGraph* jsgraph, JSHeapBroker* broker, 32 CompilationDependencies* dependencies) 33 : jsgraph_(jsgraph), broker_(broker), dependencies_(dependencies) {} 34 35 // Builds the appropriate string check if the maps are only string 36 // maps. 37 bool TryBuildStringCheck(JSHeapBroker* broker, ZoneVector<MapRef> const& maps, 38 Node** receiver, Effect* effect, Control control); 39 // Builds a number check if all maps are number maps. 40 bool TryBuildNumberCheck(JSHeapBroker* broker, ZoneVector<MapRef> const& maps, 41 Node** receiver, Effect* effect, Control control); 42 43 void BuildCheckMaps(Node* object, Effect* effect, Control control, 44 ZoneVector<MapRef> const& maps); 45 46 Node* BuildCheckValue(Node* receiver, Effect* effect, Control control, 47 Handle<HeapObject> value); 48 49 // Builds the actual load for data-field and data-constant-field 50 // properties (without heap-object or map checks). 51 Node* BuildLoadDataField(NameRef const& name, 52 PropertyAccessInfo const& access_info, 53 Node* lookup_start_object, Node** effect, 54 Node** control); 55 56 // Tries to load a constant value from a prototype object in dictionary mode 57 // and constant-folds it. Returns {} if the constant couldn't be safely 58 // retrieved. 59 base::Optional<Node*> FoldLoadDictPrototypeConstant( 60 PropertyAccessInfo const& access_info); 61 62 static MachineRepresentation ConvertRepresentation( 63 Representation representation); 64 65 private: 66 JSGraph* jsgraph() const { return jsgraph_; } 67 JSHeapBroker* broker() const { return broker_; } 68 CompilationDependencies* dependencies() const { return dependencies_; } 69 Graph* graph() const; 70 Isolate* isolate() const; 71 CommonOperatorBuilder* common() const; 72 SimplifiedOperatorBuilder* simplified() const; 73 74 Node* TryFoldLoadConstantDataField(NameRef const& name, 75 PropertyAccessInfo const& access_info, 76 Node* lookup_start_object); 77 // Returns a node with the holder for the property access described by 78 // {access_info}. 79 Node* ResolveHolder(PropertyAccessInfo const& access_info, 80 Node* lookup_start_object); 81 82 Node* BuildLoadDataField(NameRef const& name, Node* holder, 83 FieldAccess& field_access, bool is_inobject, 84 Node** effect, Node** control); 85 86 JSGraph* jsgraph_; 87 JSHeapBroker* broker_; 88 CompilationDependencies* dependencies_; 89}; 90 91bool HasOnlyStringMaps(JSHeapBroker* broker, ZoneVector<MapRef> const& maps); 92 93} // namespace compiler 94} // namespace internal 95} // namespace v8 96 97#endif // V8_COMPILER_PROPERTY_ACCESS_BUILDER_H_ 98