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_BACKEND_MOVE_OPTIMIZER_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_BACKEND_MOVE_OPTIMIZER_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/common/globals.h" 91cb0ef41Sopenharmony_ci#include "src/compiler/backend/instruction.h" 101cb0ef41Sopenharmony_ci#include "src/zone/zone-containers.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cinamespace v8 { 131cb0ef41Sopenharmony_cinamespace internal { 141cb0ef41Sopenharmony_cinamespace compiler { 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE MoveOptimizer final { 171cb0ef41Sopenharmony_ci public: 181cb0ef41Sopenharmony_ci MoveOptimizer(Zone* local_zone, InstructionSequence* code); 191cb0ef41Sopenharmony_ci MoveOptimizer(const MoveOptimizer&) = delete; 201cb0ef41Sopenharmony_ci MoveOptimizer& operator=(const MoveOptimizer&) = delete; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci void Run(); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci private: 251cb0ef41Sopenharmony_ci using MoveOpVector = ZoneVector<MoveOperands*>; 261cb0ef41Sopenharmony_ci using Instructions = ZoneVector<Instruction*>; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci InstructionSequence* code() const { return code_; } 291cb0ef41Sopenharmony_ci Zone* local_zone() const { return local_zone_; } 301cb0ef41Sopenharmony_ci Zone* code_zone() const { return code()->zone(); } 311cb0ef41Sopenharmony_ci MoveOpVector& local_vector() { return local_vector_; } 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci // Consolidate moves into the first gap. 341cb0ef41Sopenharmony_ci void CompressGaps(Instruction* instr); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci // Attempt to push down to the last instruction those moves that can. 371cb0ef41Sopenharmony_ci void CompressBlock(InstructionBlock* block); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci // Consolidate moves into the first gap. 401cb0ef41Sopenharmony_ci void CompressMoves(ParallelMove* left, MoveOpVector* right); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci // Push down those moves in the gap of from that do not change the 431cb0ef41Sopenharmony_ci // semantics of the from instruction, nor the semantics of the moves 441cb0ef41Sopenharmony_ci // that remain behind. 451cb0ef41Sopenharmony_ci void MigrateMoves(Instruction* to, Instruction* from); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci void RemoveClobberedDestinations(Instruction* instruction); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci const Instruction* LastInstruction(const InstructionBlock* block) const; 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci // Consolidate common moves appearing across all predecessors of a block. 521cb0ef41Sopenharmony_ci void OptimizeMerge(InstructionBlock* block); 531cb0ef41Sopenharmony_ci void FinalizeMoves(Instruction* instr); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci Zone* const local_zone_; 561cb0ef41Sopenharmony_ci InstructionSequence* const code_; 571cb0ef41Sopenharmony_ci MoveOpVector local_vector_; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci // Reusable buffers for storing operand sets. We need at most two sets 601cb0ef41Sopenharmony_ci // at any given time, so we create two buffers. 611cb0ef41Sopenharmony_ci ZoneVector<InstructionOperand> operand_buffer1; 621cb0ef41Sopenharmony_ci ZoneVector<InstructionOperand> operand_buffer2; 631cb0ef41Sopenharmony_ci}; 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci} // namespace compiler 661cb0ef41Sopenharmony_ci} // namespace internal 671cb0ef41Sopenharmony_ci} // namespace v8 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci#endif // V8_COMPILER_BACKEND_MOVE_OPTIMIZER_H_ 70