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_JS_GRAPH_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_JS_GRAPH_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/common/globals.h" 91cb0ef41Sopenharmony_ci#include "src/compiler/common-operator.h" 101cb0ef41Sopenharmony_ci#include "src/compiler/graph.h" 111cb0ef41Sopenharmony_ci#include "src/compiler/js-operator.h" 121cb0ef41Sopenharmony_ci#include "src/compiler/machine-graph.h" 131cb0ef41Sopenharmony_ci#include "src/compiler/node-properties.h" 141cb0ef41Sopenharmony_ci#include "src/execution/isolate.h" 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cinamespace v8 { 171cb0ef41Sopenharmony_cinamespace internal { 181cb0ef41Sopenharmony_cinamespace compiler { 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciclass SimplifiedOperatorBuilder; 211cb0ef41Sopenharmony_ciclass Typer; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci// Implements a facade on a Graph, enhancing the graph with JS-specific 241cb0ef41Sopenharmony_ci// notions, including various builders for operators, canonicalized global 251cb0ef41Sopenharmony_ci// constants, and various helper methods. 261cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE JSGraph : public MachineGraph { 271cb0ef41Sopenharmony_ci public: 281cb0ef41Sopenharmony_ci JSGraph(Isolate* isolate, Graph* graph, CommonOperatorBuilder* common, 291cb0ef41Sopenharmony_ci JSOperatorBuilder* javascript, SimplifiedOperatorBuilder* simplified, 301cb0ef41Sopenharmony_ci MachineOperatorBuilder* machine) 311cb0ef41Sopenharmony_ci : MachineGraph(graph, common, machine), 321cb0ef41Sopenharmony_ci isolate_(isolate), 331cb0ef41Sopenharmony_ci javascript_(javascript), 341cb0ef41Sopenharmony_ci simplified_(simplified) { 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci JSGraph(const JSGraph&) = delete; 381cb0ef41Sopenharmony_ci JSGraph& operator=(const JSGraph&) = delete; 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci // CEntryStubs are cached depending on the result size and other flags. 411cb0ef41Sopenharmony_ci Node* CEntryStubConstant( 421cb0ef41Sopenharmony_ci int result_size, SaveFPRegsMode save_doubles = SaveFPRegsMode::kIgnore, 431cb0ef41Sopenharmony_ci ArgvMode argv_mode = ArgvMode::kStack, bool builtin_exit_frame = false); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci // Used for padding frames. (alias: the hole) 461cb0ef41Sopenharmony_ci Node* PaddingConstant() { return TheHoleConstant(); } 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci // Used for stubs and runtime functions with no context. (alias: SMI zero) 491cb0ef41Sopenharmony_ci Node* NoContextConstant() { return ZeroConstant(); } 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci // Creates a HeapConstant node, possibly canonicalized. 521cb0ef41Sopenharmony_ci Node* HeapConstant(Handle<HeapObject> value); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci // Creates a Constant node of the appropriate type for the given object. 551cb0ef41Sopenharmony_ci // Inspect the (serialized) object and determine whether one of the 561cb0ef41Sopenharmony_ci // canonicalized globals or a number constant should be returned. 571cb0ef41Sopenharmony_ci Node* Constant(const ObjectRef& value); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci // Creates a NumberConstant node, usually canonicalized. 601cb0ef41Sopenharmony_ci Node* Constant(double value); 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci // Creates a HeapConstant node for either true or false. 631cb0ef41Sopenharmony_ci Node* BooleanConstant(bool is_true) { 641cb0ef41Sopenharmony_ci return is_true ? TrueConstant() : FalseConstant(); 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci Node* SmiConstant(int32_t immediate) { 681cb0ef41Sopenharmony_ci DCHECK(Smi::IsValid(immediate)); 691cb0ef41Sopenharmony_ci return Constant(immediate); 701cb0ef41Sopenharmony_ci } 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci JSOperatorBuilder* javascript() const { return javascript_; } 731cb0ef41Sopenharmony_ci SimplifiedOperatorBuilder* simplified() const { return simplified_; } 741cb0ef41Sopenharmony_ci Isolate* isolate() const { return isolate_; } 751cb0ef41Sopenharmony_ci Factory* factory() const { return isolate()->factory(); } 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci // Adds all the cached nodes to the given list. 781cb0ef41Sopenharmony_ci void GetCachedNodes(NodeVector* nodes); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci// Cached global nodes. 811cb0ef41Sopenharmony_ci#define CACHED_GLOBAL_LIST(V) \ 821cb0ef41Sopenharmony_ci V(AllocateInYoungGenerationStubConstant) \ 831cb0ef41Sopenharmony_ci V(AllocateRegularInYoungGenerationStubConstant) \ 841cb0ef41Sopenharmony_ci V(AllocateInOldGenerationStubConstant) \ 851cb0ef41Sopenharmony_ci V(AllocateRegularInOldGenerationStubConstant) \ 861cb0ef41Sopenharmony_ci V(ArrayConstructorStubConstant) \ 871cb0ef41Sopenharmony_ci V(BigIntMapConstant) \ 881cb0ef41Sopenharmony_ci V(BooleanMapConstant) \ 891cb0ef41Sopenharmony_ci V(ToNumberBuiltinConstant) \ 901cb0ef41Sopenharmony_ci V(PlainPrimitiveToNumberBuiltinConstant) \ 911cb0ef41Sopenharmony_ci V(EmptyFixedArrayConstant) \ 921cb0ef41Sopenharmony_ci V(EmptyStringConstant) \ 931cb0ef41Sopenharmony_ci V(FixedArrayMapConstant) \ 941cb0ef41Sopenharmony_ci V(PropertyArrayMapConstant) \ 951cb0ef41Sopenharmony_ci V(FixedDoubleArrayMapConstant) \ 961cb0ef41Sopenharmony_ci V(WeakFixedArrayMapConstant) \ 971cb0ef41Sopenharmony_ci V(HeapNumberMapConstant) \ 981cb0ef41Sopenharmony_ci V(OptimizedOutConstant) \ 991cb0ef41Sopenharmony_ci V(StaleRegisterConstant) \ 1001cb0ef41Sopenharmony_ci V(UndefinedConstant) \ 1011cb0ef41Sopenharmony_ci V(TheHoleConstant) \ 1021cb0ef41Sopenharmony_ci V(TrueConstant) \ 1031cb0ef41Sopenharmony_ci V(FalseConstant) \ 1041cb0ef41Sopenharmony_ci V(NullConstant) \ 1051cb0ef41Sopenharmony_ci V(ZeroConstant) \ 1061cb0ef41Sopenharmony_ci V(MinusZeroConstant) \ 1071cb0ef41Sopenharmony_ci V(OneConstant) \ 1081cb0ef41Sopenharmony_ci V(MinusOneConstant) \ 1091cb0ef41Sopenharmony_ci V(NaNConstant) \ 1101cb0ef41Sopenharmony_ci V(EmptyStateValues) \ 1111cb0ef41Sopenharmony_ci V(SingleDeadTypedStateValues) 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ci// Cached global node accessor methods. 1141cb0ef41Sopenharmony_ci#define DECLARE_GETTER(name) Node* name(); 1151cb0ef41Sopenharmony_ci CACHED_GLOBAL_LIST(DECLARE_GETTER) 1161cb0ef41Sopenharmony_ci#undef DECLARE_FIELD 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ci private: 1191cb0ef41Sopenharmony_ci Isolate* isolate_; 1201cb0ef41Sopenharmony_ci JSOperatorBuilder* javascript_; 1211cb0ef41Sopenharmony_ci SimplifiedOperatorBuilder* simplified_; 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci#define CACHED_CENTRY_LIST(V) \ 1241cb0ef41Sopenharmony_ci V(CEntryStub1Constant) \ 1251cb0ef41Sopenharmony_ci V(CEntryStub2Constant) \ 1261cb0ef41Sopenharmony_ci V(CEntryStub3Constant) \ 1271cb0ef41Sopenharmony_ci V(CEntryStub1WithBuiltinExitFrameConstant) 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci// Canonicalized global node fields. 1301cb0ef41Sopenharmony_ci#define DECLARE_FIELD(name) Node* name##_ = nullptr; 1311cb0ef41Sopenharmony_ci CACHED_GLOBAL_LIST(DECLARE_FIELD) 1321cb0ef41Sopenharmony_ci CACHED_CENTRY_LIST(DECLARE_FIELD) 1331cb0ef41Sopenharmony_ci#undef DECLARE_FIELD 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci // Internal helper to canonicalize a number constant. 1361cb0ef41Sopenharmony_ci Node* NumberConstant(double value); 1371cb0ef41Sopenharmony_ci}; 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_ci} // namespace compiler 1401cb0ef41Sopenharmony_ci} // namespace internal 1411cb0ef41Sopenharmony_ci} // namespace v8 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci#endif // V8_COMPILER_JS_GRAPH_H_ 144