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(int result_size, 42 SaveFPRegsMode save_doubles = kDontSaveFPRegs, 43 ArgvMode argv_mode = kArgvOnStack, 44 bool builtin_exit_frame = false); 45 46 // Used for padding frames. (alias: the hole) PaddingConstant()47 Node* PaddingConstant() { return TheHoleConstant(); } 48 49 // Used for stubs and runtime functions with no context. (alias: SMI zero) NoContextConstant()50 Node* NoContextConstant() { return ZeroConstant(); } 51 52 // Creates a HeapConstant node, possibly canonicalized. 53 Node* HeapConstant(Handle<HeapObject> value); 54 55 // Creates a Constant node of the appropriate type for the given object. 56 // Inspect the (serialized) object and determine whether one of the 57 // canonicalized globals or a number constant should be returned. 58 Node* Constant(const ObjectRef& value); 59 60 // Creates a NumberConstant node, usually canonicalized. 61 Node* Constant(double value); 62 63 // Creates a HeapConstant node for either true or false. BooleanConstant(bool is_true)64 Node* BooleanConstant(bool is_true) { 65 return is_true ? TrueConstant() : FalseConstant(); 66 } 67 SmiConstant(int32_t immediate)68 Node* SmiConstant(int32_t immediate) { 69 DCHECK(Smi::IsValid(immediate)); 70 return Constant(immediate); 71 } 72 javascript()73 JSOperatorBuilder* javascript() const { return javascript_; } simplified()74 SimplifiedOperatorBuilder* simplified() const { return simplified_; } isolate()75 Isolate* isolate() const { return isolate_; } factory()76 Factory* factory() const { return isolate()->factory(); } 77 78 // Adds all the cached nodes to the given list. 79 void GetCachedNodes(NodeVector* nodes); 80 81 // Cached global nodes. 82 #define CACHED_GLOBAL_LIST(V) \ 83 V(AllocateInYoungGenerationStubConstant) \ 84 V(AllocateRegularInYoungGenerationStubConstant) \ 85 V(AllocateInOldGenerationStubConstant) \ 86 V(AllocateRegularInOldGenerationStubConstant) \ 87 V(ArrayConstructorStubConstant) \ 88 V(BigIntMapConstant) \ 89 V(BooleanMapConstant) \ 90 V(ToNumberBuiltinConstant) \ 91 V(PlainPrimitiveToNumberBuiltinConstant) \ 92 V(EmptyFixedArrayConstant) \ 93 V(EmptyStringConstant) \ 94 V(FixedArrayMapConstant) \ 95 V(PropertyArrayMapConstant) \ 96 V(FixedDoubleArrayMapConstant) \ 97 V(WeakFixedArrayMapConstant) \ 98 V(HeapNumberMapConstant) \ 99 V(OptimizedOutConstant) \ 100 V(StaleRegisterConstant) \ 101 V(UndefinedConstant) \ 102 V(TheHoleConstant) \ 103 V(TrueConstant) \ 104 V(FalseConstant) \ 105 V(NullConstant) \ 106 V(ZeroConstant) \ 107 V(MinusZeroConstant) \ 108 V(OneConstant) \ 109 V(MinusOneConstant) \ 110 V(NaNConstant) \ 111 V(EmptyStateValues) \ 112 V(SingleDeadTypedStateValues) 113 114 // Cached global node accessor methods. 115 #define DECLARE_GETTER(name) Node* name(); 116 CACHED_GLOBAL_LIST(DECLARE_GETTER) 117 #undef DECLARE_FIELD 118 119 private: 120 Isolate* isolate_; 121 JSOperatorBuilder* javascript_; 122 SimplifiedOperatorBuilder* simplified_; 123 124 #define CACHED_CENTRY_LIST(V) \ 125 V(CEntryStub1Constant) \ 126 V(CEntryStub2Constant) \ 127 V(CEntryStub3Constant) \ 128 V(CEntryStub1WithBuiltinExitFrameConstant) 129 130 // Canonicalized global node fields. 131 #define DECLARE_FIELD(name) Node* name##_ = nullptr; 132 CACHED_GLOBAL_LIST(DECLARE_FIELD) 133 CACHED_CENTRY_LIST(DECLARE_FIELD) 134 #undef DECLARE_FIELD 135 136 // Internal helper to canonicalize a number constant. 137 Node* NumberConstant(double value); 138 }; 139 140 } // namespace compiler 141 } // namespace internal 142 } // namespace v8 143 144 #endif // V8_COMPILER_JS_GRAPH_H_ 145