11cb0ef41Sopenharmony_ci// Copyright 2014 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#ifndef V8_COMPILER_COMMON_NODE_CACHE_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_COMMON_NODE_CACHE_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/compiler/node-cache.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace v8 { 111cb0ef41Sopenharmony_cinamespace internal { 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// Forward declarations. 141cb0ef41Sopenharmony_ciclass ExternalReference; 151cb0ef41Sopenharmony_ciclass HeapObject; 161cb0ef41Sopenharmony_citemplate <typename> 171cb0ef41Sopenharmony_ciclass Handle; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cinamespace compiler { 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci// Bundles various caches for common nodes. 231cb0ef41Sopenharmony_ciclass CommonNodeCache final { 241cb0ef41Sopenharmony_ci public: 251cb0ef41Sopenharmony_ci explicit CommonNodeCache(Zone* zone) 261cb0ef41Sopenharmony_ci : int32_constants_(zone), 271cb0ef41Sopenharmony_ci int64_constants_(zone), 281cb0ef41Sopenharmony_ci tagged_index_constants_(zone), 291cb0ef41Sopenharmony_ci float32_constants_(zone), 301cb0ef41Sopenharmony_ci float64_constants_(zone), 311cb0ef41Sopenharmony_ci external_constants_(zone), 321cb0ef41Sopenharmony_ci pointer_constants_(zone), 331cb0ef41Sopenharmony_ci number_constants_(zone), 341cb0ef41Sopenharmony_ci heap_constants_(zone), 351cb0ef41Sopenharmony_ci relocatable_int32_constants_(zone), 361cb0ef41Sopenharmony_ci relocatable_int64_constants_(zone) {} 371cb0ef41Sopenharmony_ci ~CommonNodeCache() = default; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci CommonNodeCache(const CommonNodeCache&) = delete; 401cb0ef41Sopenharmony_ci CommonNodeCache& operator=(const CommonNodeCache&) = delete; 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci Node** FindInt32Constant(int32_t value) { 431cb0ef41Sopenharmony_ci return int32_constants_.Find(value); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci Node** FindInt64Constant(int64_t value) { 471cb0ef41Sopenharmony_ci return int64_constants_.Find(value); 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci Node** FindTaggedIndexConstant(int32_t value) { 511cb0ef41Sopenharmony_ci return tagged_index_constants_.Find(value); 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci Node** FindFloat32Constant(float value) { 551cb0ef41Sopenharmony_ci // We canonicalize float constants at the bit representation level. 561cb0ef41Sopenharmony_ci return float32_constants_.Find(bit_cast<int32_t>(value)); 571cb0ef41Sopenharmony_ci } 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci Node** FindFloat64Constant(double value) { 601cb0ef41Sopenharmony_ci // We canonicalize double constants at the bit representation level. 611cb0ef41Sopenharmony_ci return float64_constants_.Find(bit_cast<int64_t>(value)); 621cb0ef41Sopenharmony_ci } 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci Node** FindExternalConstant(ExternalReference value); 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci Node** FindPointerConstant(intptr_t value) { 671cb0ef41Sopenharmony_ci return pointer_constants_.Find(value); 681cb0ef41Sopenharmony_ci } 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci Node** FindNumberConstant(double value) { 711cb0ef41Sopenharmony_ci // We canonicalize double constants at the bit representation level. 721cb0ef41Sopenharmony_ci return number_constants_.Find(bit_cast<int64_t>(value)); 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci Node** FindHeapConstant(Handle<HeapObject> value); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci Node** FindRelocatableInt32Constant(int32_t value, RelocInfoMode rmode) { 781cb0ef41Sopenharmony_ci return relocatable_int32_constants_.Find(std::make_pair(value, rmode)); 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci Node** FindRelocatableInt64Constant(int64_t value, RelocInfoMode rmode) { 821cb0ef41Sopenharmony_ci return relocatable_int64_constants_.Find(std::make_pair(value, rmode)); 831cb0ef41Sopenharmony_ci } 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci // Return all nodes from the cache. 861cb0ef41Sopenharmony_ci void GetCachedNodes(ZoneVector<Node*>* nodes); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci private: 891cb0ef41Sopenharmony_ci Int32NodeCache int32_constants_; 901cb0ef41Sopenharmony_ci Int64NodeCache int64_constants_; 911cb0ef41Sopenharmony_ci Int32NodeCache tagged_index_constants_; 921cb0ef41Sopenharmony_ci Int32NodeCache float32_constants_; 931cb0ef41Sopenharmony_ci Int64NodeCache float64_constants_; 941cb0ef41Sopenharmony_ci IntPtrNodeCache external_constants_; 951cb0ef41Sopenharmony_ci IntPtrNodeCache pointer_constants_; 961cb0ef41Sopenharmony_ci Int64NodeCache number_constants_; 971cb0ef41Sopenharmony_ci IntPtrNodeCache heap_constants_; 981cb0ef41Sopenharmony_ci RelocInt32NodeCache relocatable_int32_constants_; 991cb0ef41Sopenharmony_ci RelocInt64NodeCache relocatable_int64_constants_; 1001cb0ef41Sopenharmony_ci}; 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci} // namespace compiler 1031cb0ef41Sopenharmony_ci} // namespace internal 1041cb0ef41Sopenharmony_ci} // namespace v8 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci#endif // V8_COMPILER_COMMON_NODE_CACHE_H_ 107