11cb0ef41Sopenharmony_ci// Copyright 2016 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_STORE_STORE_ELIMINATION_H_
61cb0ef41Sopenharmony_ci#define V8_COMPILER_STORE_STORE_ELIMINATION_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/common/globals.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_cinamespace internal {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciclass TickCounter;
141cb0ef41Sopenharmony_ciclass Zone;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cinamespace compiler {
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciclass JSGraph;
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci// Store-store elimination.
211cb0ef41Sopenharmony_ci//
221cb0ef41Sopenharmony_ci// The aim of this optimization is to detect the following pattern in the
231cb0ef41Sopenharmony_ci// effect graph:
241cb0ef41Sopenharmony_ci//
251cb0ef41Sopenharmony_ci// - StoreField[+24, kRepTagged](263, ...)
261cb0ef41Sopenharmony_ci//
271cb0ef41Sopenharmony_ci//   ... lots of nodes from which the field at offset 24 of the object
281cb0ef41Sopenharmony_ci//       returned by node #263 cannot be observed ...
291cb0ef41Sopenharmony_ci//
301cb0ef41Sopenharmony_ci// - StoreField[+24, kRepTagged](263, ...)
311cb0ef41Sopenharmony_ci//
321cb0ef41Sopenharmony_ci// In such situations, the earlier StoreField cannot be observed, and can be
331cb0ef41Sopenharmony_ci// eliminated. This optimization should work for any offset and input node, of
341cb0ef41Sopenharmony_ci// course.
351cb0ef41Sopenharmony_ci//
361cb0ef41Sopenharmony_ci// The optimization also works across splits. It currently does not work for
371cb0ef41Sopenharmony_ci// loops, because we tend to put a stack check in loops, and like deopts,
381cb0ef41Sopenharmony_ci// stack checks can observe anything.
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci// Assumption: every byte of a JS object is only ever accessed through one
411cb0ef41Sopenharmony_ci// offset. For instance, byte 15 of a given object may be accessed using a
421cb0ef41Sopenharmony_ci// two-byte read at offset 14, or a four-byte read at offset 12, but never
431cb0ef41Sopenharmony_ci// both in the same program.
441cb0ef41Sopenharmony_ci//
451cb0ef41Sopenharmony_ci// This implementation needs all dead nodes removed from the graph, and the
461cb0ef41Sopenharmony_ci// graph should be trimmed.
471cb0ef41Sopenharmony_ciclass StoreStoreElimination final : public AllStatic {
481cb0ef41Sopenharmony_ci public:
491cb0ef41Sopenharmony_ci  static void Run(JSGraph* js_graph, TickCounter* tick_counter,
501cb0ef41Sopenharmony_ci                  Zone* temp_zone);
511cb0ef41Sopenharmony_ci};
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci}  // namespace compiler
541cb0ef41Sopenharmony_ci}  // namespace internal
551cb0ef41Sopenharmony_ci}  // namespace v8
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci#endif  // V8_COMPILER_STORE_STORE_ELIMINATION_H_
58