1 // Copyright 2014 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_JS_GRAPH_H_ 6 #define V8_COMPILER_JS_GRAPH_H_ 7 8 #include "src/common/globals.h" 9 #include "src/compiler/common-operator.h" 10 #include "src/compiler/graph.h" 11 #include "src/compiler/js-operator.h" 12 #include "src/compiler/machine-graph.h" 13 #include "src/compiler/node-properties.h" 14 #include "src/execution/isolate.h" 15 16 namespace v8 { 17 namespace internal { 18 namespace compiler { 19 20 class SimplifiedOperatorBuilder; 21 class Typer; 22 23 // Implements a facade on a Graph, enhancing the graph with JS-specific 24 // notions, including various builders for operators, canonicalized global 25 // constants, and various helper methods. 26 class V8_EXPORT_PRIVATE JSGraph : public MachineGraph { 27 public: JSGraph(Isolate * isolate,Graph * graph,CommonOperatorBuilder * common,JSOperatorBuilder * javascript,SimplifiedOperatorBuilder * simplified,MachineOperatorBuilder * machine)28 JSGraph(Isolate* isolate, Graph* graph, CommonOperatorBuilder* common, 29 JSOperatorBuilder* javascript, SimplifiedOperatorBuilder* simplified, 30 MachineOperatorBuilder* machine) 31 : MachineGraph(graph, common, machine), 32 isolate_(isolate), 33 javascript_(javascript), 34 simplified_(simplified) { 35 } 36 37 JSGraph(const JSGraph&) = delete; 38 JSGraph& operator=(const JSGraph&) = delete; 39 40 // CEntryStubs are cached depending on the result size and other flags. 41 Node* CEntryStubConstant( 42 int result_size, SaveFPRegsMode save_doubles = SaveFPRegsMode::kIgnore, 43 ArgvMode argv_mode = ArgvMode::kStack, bool builtin_exit_frame = false); 44 45 // Used for padding frames. (alias: the hole) PaddingConstant()46 Node* PaddingConstant() { return TheHoleConstant(); } 47 48 // Used for stubs and runtime functions with no context. (alias: SMI zero) NoContextConstant()49 Node* NoContextConstant() { return ZeroConstant(); } 50 51 // Creates a HeapConstant node, possibly canonicalized. 52 Node* HeapConstant(Handle<HeapObject> value); 53 54 // Creates a Constant node of the appropriate type for the given object. 55 // Inspect the (serialized) object and determine whether one of the 56 // canonicalized globals or a number constant should be returned. 57 Node* Constant(const ObjectRef& value); 58 59 // Creates a NumberConstant node, usually canonicalized. 60 Node* Constant(double value); 61 62 // Creates a HeapConstant node for either true or false. BooleanConstant(bool is_true)63 Node* BooleanConstant(bool is_true) { 64 return is_true ? TrueConstant() : FalseConstant(); 65 } 66 SmiConstant(int32_t immediate)67 Node* SmiConstant(int32_t immediate) { 68 DCHECK(Smi::IsValid(immediate)); 69 return Constant(immediate); 70 } 71 javascript()72 JSOperatorBuilder* javascript() const { return javascript_; } simplified()73 SimplifiedOperatorBuilder* simplified() const { return simplified_; } isolate()74 Isolate* isolate() const { return isolate_; } factory()75 Factory* factory() const { return isolate()->factory(); } 76 77 // Adds all the cached nodes to the given list. 78 void GetCachedNodes(NodeVector* nodes); 79 80 // Cached global nodes. 81 #define CACHED_GLOBAL_LIST(V) \ 82 V(AllocateInYoungGenerationStubConstant) \ 83 V(AllocateRegularInYoungGenerationStubConstant) \ 84 V(AllocateInOldGenerationStubConstant) \ 85 V(AllocateRegularInOldGenerationStubConstant) \ 86 V(ArrayConstructorStubConstant) \ 87 V(BigIntMapConstant) \ 88 V(BooleanMapConstant) \ 89 V(ToNumberBuiltinConstant) \ 90 V(PlainPrimitiveToNumberBuiltinConstant) \ 91 V(EmptyFixedArrayConstant) \ 92 V(EmptyStringConstant) \ 93 V(FixedArrayMapConstant) \ 94 V(PropertyArrayMapConstant) \ 95 V(FixedDoubleArrayMapConstant) \ 96 V(WeakFixedArrayMapConstant) \ 97 V(HeapNumberMapConstant) \ 98 V(OptimizedOutConstant) \ 99 V(StaleRegisterConstant) \ 100 V(UndefinedConstant) \ 101 V(TheHoleConstant) \ 102 V(TrueConstant) \ 103 V(FalseConstant) \ 104 V(NullConstant) \ 105 V(ZeroConstant) \ 106 V(MinusZeroConstant) \ 107 V(OneConstant) \ 108 V(MinusOneConstant) \ 109 V(NaNConstant) \ 110 V(EmptyStateValues) \ 111 V(SingleDeadTypedStateValues) 112 113 // Cached global node accessor methods. 114 #define DECLARE_GETTER(name) Node* name(); 115 CACHED_GLOBAL_LIST(DECLARE_GETTER) 116 #undef DECLARE_FIELD 117 118 private: 119 Isolate* isolate_; 120 JSOperatorBuilder* javascript_; 121 SimplifiedOperatorBuilder* simplified_; 122 123 #define CACHED_CENTRY_LIST(V) \ 124 V(CEntryStub1Constant) \ 125 V(CEntryStub2Constant) \ 126 V(CEntryStub3Constant) \ 127 V(CEntryStub1WithBuiltinExitFrameConstant) 128 129 // Canonicalized global node fields. 130 #define DECLARE_FIELD(name) Node* name##_ = nullptr; 131 CACHED_GLOBAL_LIST(DECLARE_FIELD) 132 CACHED_CENTRY_LIST(DECLARE_FIELD) 133 #undef DECLARE_FIELD 134 135 // Internal helper to canonicalize a number constant. 136 Node* NumberConstant(double value); 137 }; 138 139 } // namespace compiler 140 } // namespace internal 141 } // namespace v8 142 143 #endif // V8_COMPILER_JS_GRAPH_H_ 144