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_GRAPH_EDITOR_H 17 #define ECMASCRIPT_COMPILER_GRAPH_EDITOR_H 18 19 #include "ecmascript/compiler/circuit_builder.h" 20 #include "ecmascript/compiler/gate_accessor.h" 21 #include "ecmascript/mem/chunk_containers.h" 22 23 namespace panda::ecmascript::kungfu { 24 25 class GraphEditor { 26 public: GraphEditor(Circuit * circuit)27 GraphEditor(Circuit *circuit) 28 : circuit_(circuit), acc_(circuit), 29 chunk_(circuit->chunk()), workList_(circuit->chunk()) {} 30 31 ~GraphEditor() = default; 32 33 static void RemoveDeadState(Circuit* circuit, GateRef gate); 34 static void EliminateRedundantPhi(Circuit* circuit, bool enableLog, const std::string& methodName); 35 private: 36 void ReplaceGate(GateRef gate); 37 void RemoveGate(); 38 void PropagateGate(const Edge& edge); 39 void PropagateMerge(const Edge& edge); 40 void EliminatePhi(); 41 42 Circuit *circuit_ {nullptr}; 43 GateAccessor acc_; 44 Chunk* chunk_ {nullptr}; 45 ChunkVector<Edge> workList_; 46 }; 47 } // panda::ecmascript::kungfu 48 #endif // ECMASCRIPT_COMPILER_GRAPH_EDITOR_H 49