172bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain/*
272bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * Copyright (C) 2014 The Android Open Source Project
372bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain *
472bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * Licensed under the Apache License, Version 2.0 (the "License");
572bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * you may not use this file except in compliance with the License.
672bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * You may obtain a copy of the License at
772bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain *
872bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain *      http://www.apache.org/licenses/LICENSE-2.0
972bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain *
1072bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * Unless required by applicable law or agreed to in writing, software
1172bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * distributed under the License is distributed on an "AS IS" BASIS,
1272bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1372bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * See the License for the specific language governing permissions and
1472bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * limitations under the License.
1572bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain */
1672bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
1772bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain#ifndef ART_COMPILER_OPTIMIZING_DEAD_CODE_ELIMINATION_H_
1872bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain#define ART_COMPILER_OPTIMIZING_DEAD_CODE_ELIMINATION_H_
1972bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
2072bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain#include "nodes.h"
2175be28332b278cff9039b54bfb228ac72f539cccRoland Levillain#include "optimization.h"
228f20bdb9d3b7516e75a7845e610105d87ce25ae6Calin Juravle#include "optimizing_compiler_stats.h"
2372bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
2472bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillainnamespace art {
2572bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
2672bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain/**
2772bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * Optimization pass performing dead code elimination (removal of
2872bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain * unused variables/instructions) on the SSA form.
2972bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain */
3075be28332b278cff9039b54bfb228ac72f539cccRoland Levillainclass HDeadCodeElimination : public HOptimization {
3172bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain public:
32862aaefdd63d8058b54a7d956a0229eec9dcbde6Calin Juravle  HDeadCodeElimination(HGraph* graph,
33862aaefdd63d8058b54a7d956a0229eec9dcbde6Calin Juravle                       OptimizingCompilerStats* stats = nullptr,
34a4b8c21dae70ae34aee13628632c39a675c06022David Brazdil                       const char* name = kInitialDeadCodeEliminationPassName)
3569ba7b7112c2277ac225615b37e6df74c055740dDavid Brazdil      : HOptimization(graph, name, stats) {}
3672bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
375e6916cea259897baaca019c5c7a5d05746306edNicolas Geoffray  void Run() OVERRIDE;
3872bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
39a4b8c21dae70ae34aee13628632c39a675c06022David Brazdil  static constexpr const char* kInitialDeadCodeEliminationPassName = "dead_code_elimination";
40a4b8c21dae70ae34aee13628632c39a675c06022David Brazdil  static constexpr const char* kFinalDeadCodeEliminationPassName = "dead_code_elimination_final";
411ddbf6d4b37979a9f11a203c12befd5ae8b65df4Nicolas Geoffray
4275be28332b278cff9039b54bfb228ac72f539cccRoland Levillain private:
432d7352ba5311b8f57427b91b7a891e61497373c1David Brazdil  void MaybeRecordDeadBlock(HBasicBlock* block);
442d7352ba5311b8f57427b91b7a891e61497373c1David Brazdil  void RemoveDeadBlocks();
452d7352ba5311b8f57427b91b7a891e61497373c1David Brazdil  void RemoveDeadInstructions();
462d7352ba5311b8f57427b91b7a891e61497373c1David Brazdil
4775be28332b278cff9039b54bfb228ac72f539cccRoland Levillain  DISALLOW_COPY_AND_ASSIGN(HDeadCodeElimination);
4872bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain};
4972bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
5072bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain}  // namespace art
5172bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain
5272bceff11a98cc1ecdb64a6fae16c521f99ec6a7Roland Levillain#endif  // ART_COMPILER_OPTIMIZING_DEAD_CODE_ELIMINATION_H_
53