1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_COMPILER_DEAD_CODE_ELIMINATION_H 17 #define ECMASCRIPT_COMPILER_DEAD_CODE_ELIMINATION_H 18 19 #include "ecmascript/compiler/combined_pass_visitor.h" 20 21 namespace panda::ecmascript::kungfu { 22 23 class DeadCodeElimination : public PassVisitor { 24 public: DeadCodeElimination(Circuit* circuit, RPOVisitor* visitor, Chunk* chunk)25 DeadCodeElimination(Circuit* circuit, RPOVisitor* visitor, Chunk* chunk) 26 : PassVisitor(circuit, chunk, visitor) 27 { 28 deadGate_ = circuit->DeadGate(); 29 } 30 GateRef VisitGate(GateRef gate) override; 31 32 private: 33 GateRef StateIsDead(GateRef gate); 34 GateRef EliminateMergeAndLoopBegin(GateRef gate); 35 GateRef EliminateBranch(GateRef gate); 36 GateRef EliminateReturn(GateRef gate); 37 GateRef EliminateIfException(GateRef gate); 38 GateRef EliminateLoopExit(GateRef gate); 39 GateRef EliminateDependSelector(GateRef gate); 40 GateRef EliminateValueSelector(GateRef gate); 41 GateRef EliminateGate(GateRef gate); 42 GateRef DeleteLoopExit(GateRef gate); 43 void TryFindAndDeleteLoopExit(GateRef gate); 44 void DecreaseAllSelectors(GateRef gate, size_t count); 45 GateRef deadGate_; 46 }; 47 } 48 49 #endif