1 // Copyright 2018 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 #include "src/compiler/machine-graph.h"
6
7 #include "src/compiler/node-properties.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace compiler {
12
Int32Constant(int32_t value)13 Node* MachineGraph::Int32Constant(int32_t value) {
14 Node** loc = cache_.FindInt32Constant(value);
15 if (*loc == nullptr) {
16 *loc = graph()->NewNode(common()->Int32Constant(value));
17 }
18 return *loc;
19 }
20
Int64Constant(int64_t value)21 Node* MachineGraph::Int64Constant(int64_t value) {
22 Node** loc = cache_.FindInt64Constant(value);
23 if (*loc == nullptr) {
24 *loc = graph()->NewNode(common()->Int64Constant(value));
25 }
26 return *loc;
27 }
28
IntPtrConstant(intptr_t value)29 Node* MachineGraph::IntPtrConstant(intptr_t value) {
30 return machine()->Is32() ? Int32Constant(static_cast<int32_t>(value))
31 : Int64Constant(static_cast<int64_t>(value));
32 }
33
RelocatableInt32Constant(int32_t value,RelocInfo::Mode rmode)34 Node* MachineGraph::RelocatableInt32Constant(int32_t value,
35 RelocInfo::Mode rmode) {
36 Node** loc = cache_.FindRelocatableInt32Constant(
37 value, static_cast<RelocInfoMode>(rmode));
38 if (*loc == nullptr) {
39 *loc = graph()->NewNode(common()->RelocatableInt32Constant(value, rmode));
40 }
41 return *loc;
42 }
43
RelocatableInt64Constant(int64_t value,RelocInfo::Mode rmode)44 Node* MachineGraph::RelocatableInt64Constant(int64_t value,
45 RelocInfo::Mode rmode) {
46 Node** loc = cache_.FindRelocatableInt64Constant(
47 value, static_cast<RelocInfoMode>(rmode));
48 if (*loc == nullptr) {
49 *loc = graph()->NewNode(common()->RelocatableInt64Constant(value, rmode));
50 }
51 return *loc;
52 }
53
RelocatableIntPtrConstant(intptr_t value,RelocInfo::Mode rmode)54 Node* MachineGraph::RelocatableIntPtrConstant(intptr_t value,
55 RelocInfo::Mode rmode) {
56 return kPointerSize == 8
57 ? RelocatableInt64Constant(value, rmode)
58 : RelocatableInt32Constant(static_cast<int>(value), rmode);
59 }
60
Float32Constant(float value)61 Node* MachineGraph::Float32Constant(float value) {
62 Node** loc = cache_.FindFloat32Constant(value);
63 if (*loc == nullptr) {
64 *loc = graph()->NewNode(common()->Float32Constant(value));
65 }
66 return *loc;
67 }
68
Float64Constant(double value)69 Node* MachineGraph::Float64Constant(double value) {
70 Node** loc = cache_.FindFloat64Constant(value);
71 if (*loc == nullptr) {
72 *loc = graph()->NewNode(common()->Float64Constant(value));
73 }
74 return *loc;
75 }
76
PointerConstant(intptr_t value)77 Node* MachineGraph::PointerConstant(intptr_t value) {
78 Node** loc = cache_.FindPointerConstant(value);
79 if (*loc == nullptr) {
80 *loc = graph()->NewNode(common()->PointerConstant(value));
81 }
82 return *loc;
83 }
84
ExternalConstant(ExternalReference reference)85 Node* MachineGraph::ExternalConstant(ExternalReference reference) {
86 Node** loc = cache_.FindExternalConstant(reference);
87 if (*loc == nullptr) {
88 *loc = graph()->NewNode(common()->ExternalConstant(reference));
89 }
90 return *loc;
91 }
92
ExternalConstant(Runtime::FunctionId function_id)93 Node* MachineGraph::ExternalConstant(Runtime::FunctionId function_id) {
94 return ExternalConstant(ExternalReference::Create(function_id));
95 }
96
97 } // namespace compiler
98 } // namespace internal
99 } // namespace v8
100