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.
5 #ifndef V8_COMPILER_JS_GRAPH_H_
6 #define V8_COMPILER_JS_GRAPH_H_
8 #include "src/compiler/common-node-cache.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-operator.h"
13 #include "src/compiler/node-properties.h"
21 // Implements a facade on a Graph, enhancing the graph with JS-specific
22 // notions, including a builder for for JS* operators, canonicalized global
23 // constants, and various helper methods.
24 class JSGraph : public ZoneObject {
26 JSGraph(Graph* graph, CommonOperatorBuilder* common,
27 JSOperatorBuilder* javascript, Typer* typer,
28 MachineOperatorBuilder* machine)
31 javascript_(javascript),
36 // Canonicalized global constants.
37 Node* CEntryStubConstant();
38 Node* UndefinedConstant();
39 Node* TheHoleConstant();
41 Node* FalseConstant();
47 // Creates a HeapConstant node, possibly canonicalized, without inspecting the
49 Node* HeapConstant(Unique<Object> value);
51 // Creates a HeapConstant node, possibly canonicalized, and may access the
52 // heap to inspect the object.
53 Node* HeapConstant(Handle<Object> value);
55 // Creates a Constant node of the appropriate type for the given object.
56 // Accesses the heap to inspect the object and determine whether one of the
57 // canonicalized globals or a number constant should be returned.
58 Node* Constant(Handle<Object> value);
60 // Creates a NumberConstant node, usually canonicalized.
61 Node* Constant(double value);
63 // Creates a NumberConstant node, usually canonicalized.
64 Node* Constant(int32_t value);
66 // Creates a Int32Constant node, usually canonicalized.
67 Node* Int32Constant(int32_t value);
68 Node* Uint32Constant(uint32_t value) {
69 return Int32Constant(bit_cast<int32_t>(value));
72 // Creates a Float64Constant node, usually canonicalized.
73 Node* Float64Constant(double value);
75 // Creates an ExternalConstant node, usually canonicalized.
76 Node* ExternalConstant(ExternalReference ref);
78 Node* SmiConstant(int32_t immediate) {
79 DCHECK(Smi::IsValid(immediate));
80 return Constant(immediate);
83 JSOperatorBuilder* javascript() { return javascript_; }
84 CommonOperatorBuilder* common() { return common_; }
85 MachineOperatorBuilder* machine() { return machine_; }
86 Graph* graph() { return graph_; }
87 Zone* zone() { return graph()->zone(); }
88 Isolate* isolate() { return zone()->isolate(); }
92 CommonOperatorBuilder* common_;
93 JSOperatorBuilder* javascript_;
95 MachineOperatorBuilder* machine_;
97 SetOncePointer<Node> c_entry_stub_constant_;
98 SetOncePointer<Node> undefined_constant_;
99 SetOncePointer<Node> the_hole_constant_;
100 SetOncePointer<Node> true_constant_;
101 SetOncePointer<Node> false_constant_;
102 SetOncePointer<Node> null_constant_;
103 SetOncePointer<Node> zero_constant_;
104 SetOncePointer<Node> one_constant_;
105 SetOncePointer<Node> nan_constant_;
107 CommonNodeCache cache_;
109 Node* ImmovableHeapConstant(Handle<Object> value);
110 Node* NumberConstant(double value);
111 Node* NewNode(const Operator* op);
113 Factory* factory() { return isolate()->factory(); }
116 } // namespace compiler
117 } // namespace internal