10b57cec5SDimitry Andric //===--- RDFDeadCode.h ----------------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // RDF-based generic dead code elimination. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric // The main interface of this class are functions "collect" and "erase". 120b57cec5SDimitry Andric // This allows custom processing of the function being optimized by a 130b57cec5SDimitry Andric // particular consumer. The simplest way to use this class would be to 140b57cec5SDimitry Andric // instantiate an object, and then simply call "collect" and "erase", 150b57cec5SDimitry Andric // passing the result of "getDeadInstrs()" to it. 160b57cec5SDimitry Andric // A more complex scenario would be to call "collect" first, then visit 170b57cec5SDimitry Andric // all post-increment instructions to see if the address update is dead 180b57cec5SDimitry Andric // or not, and if it is, convert the instruction to a non-updating form. 190b57cec5SDimitry Andric // After that "erase" can be called with the set of nodes including both, 200b57cec5SDimitry Andric // dead defs from the updating instructions and the nodes corresponding 210b57cec5SDimitry Andric // to the dead instructions. 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric #ifndef RDF_DEADCODE_H 240b57cec5SDimitry Andric #define RDF_DEADCODE_H 250b57cec5SDimitry Andric 260946e70aSDimitry Andric #include "llvm/CodeGen/RDFGraph.h" 270946e70aSDimitry Andric #include "llvm/CodeGen/RDFLiveness.h" 280b57cec5SDimitry Andric #include "llvm/ADT/SetVector.h" 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric namespace llvm { 310b57cec5SDimitry Andric class MachineRegisterInfo; 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric namespace rdf { 340b57cec5SDimitry Andric struct DeadCodeElimination { DeadCodeEliminationDeadCodeElimination350b57cec5SDimitry Andric DeadCodeElimination(DataFlowGraph &dfg, MachineRegisterInfo &mri) 360b57cec5SDimitry Andric : Trace(false), DFG(dfg), MRI(mri), LV(mri, dfg) {} 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric bool collect(); 390b57cec5SDimitry Andric bool erase(const SetVector<NodeId> &Nodes); traceDeadCodeElimination400b57cec5SDimitry Andric void trace(bool On) { Trace = On; } traceDeadCodeElimination410b57cec5SDimitry Andric bool trace() const { return Trace; } 420b57cec5SDimitry Andric getDeadNodesDeadCodeElimination430b57cec5SDimitry Andric SetVector<NodeId> getDeadNodes() { return DeadNodes; } getDeadInstrsDeadCodeElimination440b57cec5SDimitry Andric SetVector<NodeId> getDeadInstrs() { return DeadInstrs; } getDFGDeadCodeElimination450b57cec5SDimitry Andric DataFlowGraph &getDFG() { return DFG; } 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric private: 480b57cec5SDimitry Andric bool Trace; 490b57cec5SDimitry Andric SetVector<NodeId> LiveNodes; 500b57cec5SDimitry Andric SetVector<NodeId> DeadNodes; 510b57cec5SDimitry Andric SetVector<NodeId> DeadInstrs; 520b57cec5SDimitry Andric DataFlowGraph &DFG; 530b57cec5SDimitry Andric MachineRegisterInfo &MRI; 540b57cec5SDimitry Andric Liveness LV; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric template<typename T> struct SetQueue; 570b57cec5SDimitry Andric 58*06c3fb27SDimitry Andric bool isLiveInstr(NodeAddr<StmtNode*> S) const; 590b57cec5SDimitry Andric void scanInstr(NodeAddr<InstrNode*> IA, SetQueue<NodeId> &WorkQ); 600b57cec5SDimitry Andric void processDef(NodeAddr<DefNode*> DA, SetQueue<NodeId> &WorkQ); 610b57cec5SDimitry Andric void processUse(NodeAddr<UseNode*> UA, SetQueue<NodeId> &WorkQ); 620b57cec5SDimitry Andric }; 630b57cec5SDimitry Andric } // namespace rdf 640b57cec5SDimitry Andric } // namespace llvm 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric #endif 67