1 //===--- RDFDeadCode.h ----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // RDF-based generic dead code elimination.
12 // The main interface of this class are functions "collect" and "erase".
13 // This allows custom processing of the function being optimized by a
14 // particular consumer. The simplest way to use this class would be to
15 // instantiate an object, and then simply call "collect" and "erase",
16 // passing the result of "getDeadInstrs()" to it.
17 // A more complex scenario would be to call "collect" first, then visit
18 // all post-increment instructions to see if the address update is dead
19 // or not, and if it is, convert the instruction to a non-updating form.
20 // After that "erase" can be called with the set of nodes including both,
21 // dead defs from the updating instructions and the nodes corresponding
22 // to the dead instructions.
24 #ifndef RDF_DEADCODE_H
25 #define RDF_DEADCODE_H
28 #include "RDFLiveness.h"
29 #include "llvm/ADT/SetVector.h"
32 class MachineRegisterInfo;
36 struct DeadCodeElimination {
37 DeadCodeElimination(DataFlowGraph &dfg, MachineRegisterInfo &mri)
38 : Trace(false), DFG(dfg), MRI(mri), LV(mri, dfg) {}
41 bool erase(const SetVector<NodeId> &Nodes);
42 void trace(bool On) { Trace = On; }
43 bool trace() const { return Trace; }
45 SetVector<NodeId> getDeadNodes() { return DeadNodes; }
46 SetVector<NodeId> getDeadInstrs() { return DeadInstrs; }
47 DataFlowGraph &getDFG() { return DFG; }
51 SetVector<NodeId> LiveNodes;
52 SetVector<NodeId> DeadNodes;
53 SetVector<NodeId> DeadInstrs;
55 MachineRegisterInfo &MRI;
58 bool isLiveInstr(const MachineInstr *MI) const;
59 void scanInstr(NodeAddr<InstrNode*> IA, SetVector<NodeId> &WorkQ);
60 void processDef(NodeAddr<DefNode*> DA, SetVector<NodeId> &WorkQ);
61 void processUse(NodeAddr<UseNode*> UA, SetVector<NodeId> &WorkQ);