V8 Project
js-graph.cc
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 
7 #include "src/compiler/typer.h"
8 
9 namespace v8 {
10 namespace internal {
11 namespace compiler {
12 
15  return NewNode(common()->HeapConstant(unique));
16 }
17 
18 
19 Node* JSGraph::NewNode(const Operator* op) {
20  Node* node = graph()->NewNode(op);
21  typer_->Init(node);
22  return node;
23 }
24 
25 
29  ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode()));
30  }
31  return c_entry_stub_constant_.get();
32 }
33 
34 
36  if (!undefined_constant_.is_set()) {
38  ImmovableHeapConstant(factory()->undefined_value()));
39  }
40  return undefined_constant_.get();
41 }
42 
43 
45  if (!the_hole_constant_.is_set()) {
47  }
48  return the_hole_constant_.get();
49 }
50 
51 
53  if (!true_constant_.is_set()) {
55  }
56  return true_constant_.get();
57 }
58 
59 
61  if (!false_constant_.is_set()) {
63  }
64  return false_constant_.get();
65 }
66 
67 
69  if (!null_constant_.is_set()) {
71  }
72  return null_constant_.get();
73 }
74 
75 
78  return zero_constant_.get();
79 }
80 
81 
84  return one_constant_.get();
85 }
86 
87 
89  if (!nan_constant_.is_set()) {
91  }
92  return nan_constant_.get();
93 }
94 
95 
97  // TODO(turbofan): canonicalize heap constants using Unique<T>
98  return NewNode(common()->HeapConstant(value));
99 }
100 
101 
103  // TODO(titzer): We could also match against the addresses of immortable
104  // immovables here, even without access to the heap, thus always
105  // canonicalizing references to them.
106  // return HeapConstant(Unique<Object>::CreateUninitialized(value));
107  // TODO(turbofan): This is a work-around to make Unique::HashCode() work for
108  // value numbering. We need some sane way to compute a unique hash code for
109  // arbitrary handles here.
110  Unique<Object> unique(reinterpret_cast<Address>(*value.location()), value);
111  return HeapConstant(unique);
112 }
113 
114 
116  // Dereference the handle to determine if a number constant or other
117  // canonicalized node can be used.
118  if (value->IsNumber()) {
119  return Constant(value->Number());
120  } else if (value->IsUndefined()) {
121  return UndefinedConstant();
122  } else if (value->IsTrue()) {
123  return TrueConstant();
124  } else if (value->IsFalse()) {
125  return FalseConstant();
126  } else if (value->IsNull()) {
127  return NullConstant();
128  } else if (value->IsTheHole()) {
129  return TheHoleConstant();
130  } else {
131  return HeapConstant(value);
132  }
133 }
134 
135 
136 Node* JSGraph::Constant(double value) {
137  if (bit_cast<int64_t>(value) == bit_cast<int64_t>(0.0)) return ZeroConstant();
138  if (bit_cast<int64_t>(value) == bit_cast<int64_t>(1.0)) return OneConstant();
139  return NumberConstant(value);
140 }
141 
142 
144  if (value == 0) return ZeroConstant();
145  if (value == 1) return OneConstant();
146  return NumberConstant(value);
147 }
148 
149 
151  Node** loc = cache_.FindInt32Constant(value);
152  if (*loc == NULL) {
153  *loc = NewNode(common()->Int32Constant(value));
154  }
155  return *loc;
156 }
157 
158 
159 Node* JSGraph::NumberConstant(double value) {
160  Node** loc = cache_.FindNumberConstant(value);
161  if (*loc == NULL) {
162  *loc = NewNode(common()->NumberConstant(value));
163  }
164  return *loc;
165 }
166 
167 
168 Node* JSGraph::Float32Constant(float value) {
169  // TODO(turbofan): cache float32 constants.
170  return NewNode(common()->Float32Constant(value));
171 }
172 
173 
174 Node* JSGraph::Float64Constant(double value) {
175  Node** loc = cache_.FindFloat64Constant(value);
176  if (*loc == NULL) {
177  *loc = NewNode(common()->Float64Constant(value));
178  }
179  return *loc;
180 }
181 
182 
183 Node* JSGraph::ExternalConstant(ExternalReference reference) {
184  Node** loc = cache_.FindExternalConstant(reference);
185  if (*loc == NULL) {
186  *loc = NewNode(common()->ExternalConstant(reference));
187  }
188  return *loc;
189 }
190 } // namespace compiler
191 } // namespace internal
192 } // namespace v8
static double nan_value()
void set(T *value)
Definition: utils.h:417
static Unique< T > CreateImmovable(Handle< T > handle)
Definition: unique.h:116
Node * NewNode(const Operator *op, int input_count, Node **inputs)
Definition: graph.cc:24
SetOncePointer< Node > false_constant_
Definition: js-graph.h:104
Node * Float32Constant(float value)
Definition: js-graph.cc:168
Node * ExternalConstant(ExternalReference ref)
Definition: js-graph.cc:183
Node * NumberConstant(double value)
Definition: js-graph.cc:159
Node * ImmovableHeapConstant(Handle< Object > value)
Definition: js-graph.cc:13
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:87
Node * Constant(Handle< Object > value)
Definition: js-graph.cc:115
Node * Int32Constant(int32_t value)
Definition: js-graph.cc:150
Node * HeapConstant(Unique< Object > value)
Definition: js-graph.cc:96
void Init(Node *node)
Definition: typer.cc:229
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
int int32_t
Definition: unicode.cc:24
byte * Address
Definition: globals.h:101
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20