11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/compiler/machine-graph.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "src/codegen/external-reference.h" 81cb0ef41Sopenharmony_ci#include "src/compiler/node-properties.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace v8 { 111cb0ef41Sopenharmony_cinamespace internal { 121cb0ef41Sopenharmony_cinamespace compiler { 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciNode* MachineGraph::Int32Constant(int32_t value) { 151cb0ef41Sopenharmony_ci Node** loc = cache_.FindInt32Constant(value); 161cb0ef41Sopenharmony_ci if (*loc == nullptr) { 171cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->Int32Constant(value)); 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci return *loc; 201cb0ef41Sopenharmony_ci} 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciNode* MachineGraph::Int64Constant(int64_t value) { 231cb0ef41Sopenharmony_ci Node** loc = cache_.FindInt64Constant(value); 241cb0ef41Sopenharmony_ci if (*loc == nullptr) { 251cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->Int64Constant(value)); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci return *loc; 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciNode* MachineGraph::IntPtrConstant(intptr_t value) { 311cb0ef41Sopenharmony_ci return machine()->Is32() ? Int32Constant(static_cast<int32_t>(value)) 321cb0ef41Sopenharmony_ci : Int64Constant(static_cast<int64_t>(value)); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciNode* MachineGraph::UintPtrConstant(uintptr_t value) { 361cb0ef41Sopenharmony_ci return machine()->Is32() ? Uint32Constant(static_cast<uint32_t>(value)) 371cb0ef41Sopenharmony_ci : Uint64Constant(static_cast<uint64_t>(value)); 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciNode* MachineGraph::TaggedIndexConstant(intptr_t value) { 411cb0ef41Sopenharmony_ci int32_t value32 = static_cast<int32_t>(value); 421cb0ef41Sopenharmony_ci Node** loc = cache_.FindTaggedIndexConstant(value32); 431cb0ef41Sopenharmony_ci if (*loc == nullptr) { 441cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->TaggedIndexConstant(value32)); 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci return *loc; 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciNode* MachineGraph::RelocatableInt32Constant(int32_t value, 501cb0ef41Sopenharmony_ci RelocInfo::Mode rmode) { 511cb0ef41Sopenharmony_ci Node** loc = cache_.FindRelocatableInt32Constant( 521cb0ef41Sopenharmony_ci value, static_cast<RelocInfoMode>(rmode)); 531cb0ef41Sopenharmony_ci if (*loc == nullptr) { 541cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->RelocatableInt32Constant(value, rmode)); 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci return *loc; 571cb0ef41Sopenharmony_ci} 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciNode* MachineGraph::RelocatableInt64Constant(int64_t value, 601cb0ef41Sopenharmony_ci RelocInfo::Mode rmode) { 611cb0ef41Sopenharmony_ci Node** loc = cache_.FindRelocatableInt64Constant( 621cb0ef41Sopenharmony_ci value, static_cast<RelocInfoMode>(rmode)); 631cb0ef41Sopenharmony_ci if (*loc == nullptr) { 641cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->RelocatableInt64Constant(value, rmode)); 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci return *loc; 671cb0ef41Sopenharmony_ci} 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ciNode* MachineGraph::RelocatableIntPtrConstant(intptr_t value, 701cb0ef41Sopenharmony_ci RelocInfo::Mode rmode) { 711cb0ef41Sopenharmony_ci return kSystemPointerSize == 8 721cb0ef41Sopenharmony_ci ? RelocatableInt64Constant(value, rmode) 731cb0ef41Sopenharmony_ci : RelocatableInt32Constant(static_cast<int>(value), rmode); 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ciNode* MachineGraph::Float32Constant(float value) { 771cb0ef41Sopenharmony_ci Node** loc = cache_.FindFloat32Constant(value); 781cb0ef41Sopenharmony_ci if (*loc == nullptr) { 791cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->Float32Constant(value)); 801cb0ef41Sopenharmony_ci } 811cb0ef41Sopenharmony_ci return *loc; 821cb0ef41Sopenharmony_ci} 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ciNode* MachineGraph::Float64Constant(double value) { 851cb0ef41Sopenharmony_ci Node** loc = cache_.FindFloat64Constant(value); 861cb0ef41Sopenharmony_ci if (*loc == nullptr) { 871cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->Float64Constant(value)); 881cb0ef41Sopenharmony_ci } 891cb0ef41Sopenharmony_ci return *loc; 901cb0ef41Sopenharmony_ci} 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ciNode* MachineGraph::PointerConstant(intptr_t value) { 931cb0ef41Sopenharmony_ci Node** loc = cache_.FindPointerConstant(value); 941cb0ef41Sopenharmony_ci if (*loc == nullptr) { 951cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->PointerConstant(value)); 961cb0ef41Sopenharmony_ci } 971cb0ef41Sopenharmony_ci return *loc; 981cb0ef41Sopenharmony_ci} 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ciNode* MachineGraph::ExternalConstant(ExternalReference reference) { 1011cb0ef41Sopenharmony_ci Node** loc = cache_.FindExternalConstant(reference); 1021cb0ef41Sopenharmony_ci if (*loc == nullptr) { 1031cb0ef41Sopenharmony_ci *loc = graph()->NewNode(common()->ExternalConstant(reference)); 1041cb0ef41Sopenharmony_ci } 1051cb0ef41Sopenharmony_ci return *loc; 1061cb0ef41Sopenharmony_ci} 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ciNode* MachineGraph::ExternalConstant(Runtime::FunctionId function_id) { 1091cb0ef41Sopenharmony_ci return ExternalConstant(ExternalReference::Create(function_id)); 1101cb0ef41Sopenharmony_ci} 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci} // namespace compiler 1131cb0ef41Sopenharmony_ci} // namespace internal 1141cb0ef41Sopenharmony_ci} // namespace v8 115