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;
35 struct DeadCodeElimination {
36 DeadCodeElimination(DataFlowGraph &dfg, MachineRegisterInfo &mri)
37 : Trace(false), DFG(dfg), MRI(mri), LV(mri, dfg) {}
40 bool erase(const SetVector<NodeId> &Nodes);
41 void trace(bool On) { Trace = On; }
42 bool trace() const { return Trace; }
44 SetVector<NodeId> getDeadNodes() { return DeadNodes; }
45 SetVector<NodeId> getDeadInstrs() { return DeadInstrs; }
46 DataFlowGraph &getDFG() { return DFG; }
50 SetVector<NodeId> LiveNodes;
51 SetVector<NodeId> DeadNodes;
52 SetVector<NodeId> DeadInstrs;
54 MachineRegisterInfo &MRI;
57 template<typename T> struct SetQueue;
59 bool isLiveInstr(const MachineInstr *MI) const;
60 void scanInstr(NodeAddr<InstrNode*> IA, SetQueue<NodeId> &WorkQ);
61 void processDef(NodeAddr<DefNode*> DA, SetQueue<NodeId> &WorkQ);
62 void processUse(NodeAddr<UseNode*> UA, SetQueue<NodeId> &WorkQ);