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/compiler/common-operator.h" 9 #include "src/compiler/graph.h" 10 #include "src/compiler/js-operator.h" 11 #include "src/compiler/machine-graph.h" 12 #include "src/compiler/node-properties.h" 13 #include "src/globals.h" 14 #include "src/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 // CEntryStubs are cached depending on the result size and other flags. 38 Node* CEntryStubConstant(int result_size, 39 SaveFPRegsMode save_doubles = kDontSaveFPRegs, 40 ArgvMode argv_mode = kArgvOnStack, 41 bool builtin_exit_frame = false); 42 43 // Used for padding frames. (alias: the hole) PaddingConstant()44 Node* PaddingConstant() { return TheHoleConstant(); } 45 46 // Used for stubs and runtime functions with no context. (alias: SMI zero) NoContextConstant()47 Node* NoContextConstant() { return ZeroConstant(); } 48 49 // Creates a HeapConstant node, possibly canonicalized, and may access the 50 // heap to inspect the object. 51 Node* HeapConstant(Handle<HeapObject> value); 52 53 // Creates a Constant node of the appropriate type for the given object. 54 // Accesses the heap to inspect the object and determine whether one of the 55 // canonicalized globals or a number constant should be returned. 56 Node* Constant(Handle<Object> value); 57 58 // Like above, but doesn't access the heap directly. 59 Node* Constant(const ObjectRef& value); 60 61 // Creates a NumberConstant node, usually canonicalized. 62 Node* Constant(double value); 63 64 // Creates a NumberConstant node, usually canonicalized. 65 Node* Constant(int32_t value); 66 67 // Creates a NumberConstant node, usually canonicalized. 68 Node* Constant(uint32_t value); 69 70 // Creates a HeapConstant node for either true or false. BooleanConstant(bool is_true)71 Node* BooleanConstant(bool is_true) { 72 return is_true ? TrueConstant() : FalseConstant(); 73 } 74 SmiConstant(int32_t immediate)75 Node* SmiConstant(int32_t immediate) { 76 DCHECK(Smi::IsValid(immediate)); 77 return Constant(immediate); 78 } 79 javascript()80 JSOperatorBuilder* javascript() const { return javascript_; } simplified()81 SimplifiedOperatorBuilder* simplified() const { return simplified_; } isolate()82 Isolate* isolate() const { return isolate_; } factory()83 Factory* factory() const { return isolate()->factory(); } 84 85 // Adds all the cached nodes to the given list. 86 void GetCachedNodes(NodeVector* nodes); 87 88 // Cached global nodes. 89 #define CACHED_GLOBAL_LIST(V) \ 90 V(AllocateInNewSpaceStubConstant) \ 91 V(AllocateInOldSpaceStubConstant) \ 92 V(ArrayConstructorStubConstant) \ 93 V(ToNumberBuiltinConstant) \ 94 V(EmptyFixedArrayConstant) \ 95 V(EmptyStringConstant) \ 96 V(FixedArrayMapConstant) \ 97 V(PropertyArrayMapConstant) \ 98 V(FixedDoubleArrayMapConstant) \ 99 V(HeapNumberMapConstant) \ 100 V(OptimizedOutConstant) \ 101 V(StaleRegisterConstant) \ 102 V(UndefinedConstant) \ 103 V(TheHoleConstant) \ 104 V(TrueConstant) \ 105 V(FalseConstant) \ 106 V(NullConstant) \ 107 V(ZeroConstant) \ 108 V(OneConstant) \ 109 V(NaNConstant) \ 110 V(MinusOneConstant) \ 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 DISALLOW_COPY_AND_ASSIGN(JSGraph); 140 }; 141 142 } // namespace compiler 143 } // namespace internal 144 } // namespace v8 145 146 #endif // V8_COMPILER_JS_GRAPH_H_ 147