V8 Project
js-graph.h
Go to the documentation of this file.
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 
10 #include "src/compiler/graph.h"
14 
15 namespace v8 {
16 namespace internal {
17 namespace compiler {
18 
19 class Typer;
20 
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 {
25  public:
26  JSGraph(Graph* graph, CommonOperatorBuilder* common,
28  MachineOperatorBuilder* machine)
29  : graph_(graph),
30  common_(common),
32  typer_(typer),
34  cache_(zone()) {}
35 
36  // Canonicalized global constants.
37  Node* CEntryStubConstant();
38  Node* UndefinedConstant();
39  Node* TheHoleConstant();
40  Node* TrueConstant();
41  Node* FalseConstant();
42  Node* NullConstant();
43  Node* ZeroConstant();
44  Node* OneConstant();
45  Node* NaNConstant();
46 
47  // Creates a HeapConstant node, possibly canonicalized, without inspecting the
48  // object.
49  Node* HeapConstant(Unique<Object> value);
50 
51  // Creates a HeapConstant node, possibly canonicalized, and may access the
52  // heap to inspect the object.
53  Node* HeapConstant(Handle<Object> value);
54 
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);
59 
60  // Creates a NumberConstant node, usually canonicalized.
61  Node* Constant(double value);
62 
63  // Creates a NumberConstant node, usually canonicalized.
64  Node* Constant(int32_t value);
65 
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));
70  }
71 
72  // Creates a Float32Constant node, usually canonicalized.
73  Node* Float32Constant(float value);
74 
75  // Creates a Float64Constant node, usually canonicalized.
76  Node* Float64Constant(double value);
77 
78  // Creates an ExternalConstant node, usually canonicalized.
79  Node* ExternalConstant(ExternalReference ref);
80 
81  Node* SmiConstant(int32_t immediate) {
82  DCHECK(Smi::IsValid(immediate));
83  return Constant(immediate);
84  }
85 
87  CommonOperatorBuilder* common() { return common_; }
88  MachineOperatorBuilder* machine() { return machine_; }
89  Graph* graph() { return graph_; }
90  Zone* zone() { return graph()->zone(); }
91  Isolate* isolate() { return zone()->isolate(); }
92 
93  private:
95  CommonOperatorBuilder* common_;
98  MachineOperatorBuilder* machine_;
99 
109 
110  CommonNodeCache cache_;
111 
113  Node* NumberConstant(double value);
114  Node* NewNode(const Operator* op);
115 
116  Factory* factory() { return isolate()->factory(); }
117 };
118 
119 } // namespace compiler
120 } // namespace internal
121 } // namespace v8
122 
123 #endif
Factory * factory()
Definition: isolate.h:982
static bool IsValid(intptr_t value)
Definition: objects-inl.h:1334
Isolate * isolate() const
Definition: zone.h:68
SetOncePointer< Node > false_constant_
Definition: js-graph.h:104
Node * Float32Constant(float value)
Definition: js-graph.cc:168
Node * SmiConstant(int32_t immediate)
Definition: js-graph.h:81
JSGraph(Graph *graph, CommonOperatorBuilder *common, JSOperatorBuilder *javascript, Typer *typer, MachineOperatorBuilder *machine)
Definition: js-graph.h:26
Node * ExternalConstant(ExternalReference ref)
Definition: js-graph.cc:183
JSOperatorBuilder * javascript()
Definition: js-graph.h:86
Node * NumberConstant(double value)
Definition: js-graph.cc:159
JSOperatorBuilder * javascript_
Definition: js-graph.h:96
Node * ImmovableHeapConstant(Handle< Object > value)
Definition: js-graph.cc:13
MachineOperatorBuilder * machine()
Definition: js-graph.h:88
SetOncePointer< Node > zero_constant_
Definition: js-graph.h:106
Node * Float64Constant(double value)
Definition: js-graph.cc:174
SetOncePointer< Node > true_constant_
Definition: js-graph.h:103
SetOncePointer< Node > one_constant_
Definition: js-graph.h:107
SetOncePointer< Node > null_constant_
Definition: js-graph.h:105
SetOncePointer< Node > c_entry_stub_constant_
Definition: js-graph.h:100
SetOncePointer< Node > nan_constant_
Definition: js-graph.h:108
SetOncePointer< Node > the_hole_constant_
Definition: js-graph.h:102
Node * NewNode(const Operator *op)
Definition: js-graph.cc:19
SetOncePointer< Node > undefined_constant_
Definition: js-graph.h:101
CommonOperatorBuilder * common_
Definition: js-graph.h:95
CommonOperatorBuilder * common()
Definition: js-graph.h:87
Node * Constant(Handle< Object > value)
Definition: js-graph.cc:115
Node * Uint32Constant(uint32_t value)
Definition: js-graph.h:68
Node * Int32Constant(int32_t value)
Definition: js-graph.cc:150
MachineOperatorBuilder * machine_
Definition: js-graph.h:98
Node * HeapConstant(Unique< Object > value)
Definition: js-graph.cc:96
#define DCHECK(condition)
Definition: logging.h:205
int int32_t
Definition: unicode.cc:24
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20