1 /* 2 * Copyright (c) 2024 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_USELESS_GATE_ELIMINATION_H 17 #define ECMASCRIPT_COMPILER_USELESS_GATE_ELIMINATION_H 18 19 #include "ecmascript/compiler/circuit.h" 20 #include "ecmascript/compiler/gate_accessor.h" 21 22 namespace panda::ecmascript::kungfu { 23 24 class UselessGateElimination { 25 public: UselessGateElimination(Circuit * circuit,bool enableLog,std::string name)26 UselessGateElimination(Circuit* circuit, bool enableLog, std::string name) 27 : enableLog_(enableLog), methodName_(name), circuit_(circuit), 28 acc_(circuit) {} 29 void Run(); 30 private: 31 void PushGate(GateRef gate); 32 void InitList(); 33 void MarkGate(); 34 void ReplaceDead(GateRef gate); 35 void EliminateUnmarkedGate(); 36 std::string GetMethodName(); 37 bool enableLog_; 38 std::string methodName_; 39 Circuit* circuit_; 40 GateAccessor acc_; 41 std::vector<GateRef> workList_; 42 std::vector<GateRef> gateList_; 43 }; 44 45 } 46 #endif