11cb0ef41Sopenharmony_ci// Copyright 2015 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_NODE_MARKER_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_NODE_MARKER_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/compiler/node.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace v8 { 111cb0ef41Sopenharmony_cinamespace internal { 121cb0ef41Sopenharmony_cinamespace compiler { 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci// Forward declarations. 151cb0ef41Sopenharmony_ciclass Graph; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci// Base class for templatized NodeMarkers. 191cb0ef41Sopenharmony_ciclass NodeMarkerBase { 201cb0ef41Sopenharmony_ci public: 211cb0ef41Sopenharmony_ci NodeMarkerBase(Graph* graph, uint32_t num_states); 221cb0ef41Sopenharmony_ci NodeMarkerBase(const NodeMarkerBase&) = delete; 231cb0ef41Sopenharmony_ci NodeMarkerBase& operator=(const NodeMarkerBase&) = delete; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci V8_INLINE Mark Get(const Node* node) { 261cb0ef41Sopenharmony_ci Mark mark = node->mark(); 271cb0ef41Sopenharmony_ci if (mark < mark_min_) { 281cb0ef41Sopenharmony_ci return 0; 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci DCHECK_LT(mark, mark_max_); 311cb0ef41Sopenharmony_ci return mark - mark_min_; 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci V8_INLINE void Set(Node* node, Mark mark) { 341cb0ef41Sopenharmony_ci DCHECK_LT(mark, mark_max_ - mark_min_); 351cb0ef41Sopenharmony_ci DCHECK_LT(node->mark(), mark_max_); 361cb0ef41Sopenharmony_ci node->set_mark(mark + mark_min_); 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci private: 401cb0ef41Sopenharmony_ci Mark const mark_min_; 411cb0ef41Sopenharmony_ci Mark const mark_max_; 421cb0ef41Sopenharmony_ci}; 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci// A NodeMarker assigns a local "state" to every node of a graph in constant 451cb0ef41Sopenharmony_ci// memory. Only one NodeMarker per graph is valid at a given time, that is, 461cb0ef41Sopenharmony_ci// after you create a NodeMarker you should no longer use NodeMarkers that 471cb0ef41Sopenharmony_ci// were created earlier. Internally, the local state is stored in the Node 481cb0ef41Sopenharmony_ci// structure. 491cb0ef41Sopenharmony_ci// 501cb0ef41Sopenharmony_ci// When you initialize a NodeMarker, all the local states are conceptually 511cb0ef41Sopenharmony_ci// set to State(0) in constant time. 521cb0ef41Sopenharmony_ci// 531cb0ef41Sopenharmony_ci// In its current implementation, in debug mode NodeMarker will try to 541cb0ef41Sopenharmony_ci// (efficiently) detect invalid use of an older NodeMarker. Namely, if you set a 551cb0ef41Sopenharmony_ci// node with a NodeMarker, and then get or set that node with an older 561cb0ef41Sopenharmony_ci// NodeMarker you will get a crash. 571cb0ef41Sopenharmony_ci// 581cb0ef41Sopenharmony_ci// GraphReducer uses a NodeMarker, so individual Reducers cannot use a 591cb0ef41Sopenharmony_ci// NodeMarker. 601cb0ef41Sopenharmony_citemplate <typename State> 611cb0ef41Sopenharmony_ciclass NodeMarker : public NodeMarkerBase { 621cb0ef41Sopenharmony_ci public: 631cb0ef41Sopenharmony_ci V8_INLINE NodeMarker(Graph* graph, uint32_t num_states) 641cb0ef41Sopenharmony_ci : NodeMarkerBase(graph, num_states) {} 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci V8_INLINE State Get(const Node* node) { 671cb0ef41Sopenharmony_ci return static_cast<State>(NodeMarkerBase::Get(node)); 681cb0ef41Sopenharmony_ci } 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci V8_INLINE void Set(Node* node, State state) { 711cb0ef41Sopenharmony_ci NodeMarkerBase::Set(node, static_cast<Mark>(state)); 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci}; 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci} // namespace compiler 761cb0ef41Sopenharmony_ci} // namespace internal 771cb0ef41Sopenharmony_ci} // namespace v8 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci#endif // V8_COMPILER_NODE_MARKER_H_ 80