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