• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--- RDFDeadCode.h ----------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // RDF-based generic dead code elimination.
11 //
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.
23 
24 #ifndef RDF_DEADCODE_H
25 #define RDF_DEADCODE_H
26 
27 #include "RDFGraph.h"
28 #include "RDFLiveness.h"
29 #include "llvm/ADT/SetVector.h"
30 
31 namespace llvm {
32   class MachineRegisterInfo;
33 
34 namespace rdf {
35   struct DeadCodeElimination {
DeadCodeEliminationDeadCodeElimination36     DeadCodeElimination(DataFlowGraph &dfg, MachineRegisterInfo &mri)
37       : Trace(false), DFG(dfg), MRI(mri), LV(mri, dfg) {}
38 
39     bool collect();
40     bool erase(const SetVector<NodeId> &Nodes);
traceDeadCodeElimination41     void trace(bool On) { Trace = On; }
traceDeadCodeElimination42     bool trace() const { return Trace; }
43 
getDeadNodesDeadCodeElimination44     SetVector<NodeId> getDeadNodes() { return DeadNodes; }
getDeadInstrsDeadCodeElimination45     SetVector<NodeId> getDeadInstrs() { return DeadInstrs; }
getDFGDeadCodeElimination46     DataFlowGraph &getDFG() { return DFG; }
47 
48   private:
49     bool Trace;
50     SetVector<NodeId> LiveNodes;
51     SetVector<NodeId> DeadNodes;
52     SetVector<NodeId> DeadInstrs;
53     DataFlowGraph &DFG;
54     MachineRegisterInfo &MRI;
55     Liveness LV;
56 
57     template<typename T> struct SetQueue;
58 
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);
63   };
64 } // namespace rdf
65 } // namespace llvm
66 
67 #endif
68