xref: /aosp_15_r20/external/llvm/lib/Target/Hexagon/RDFDeadCode.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===--- RDFDeadCode.h ----------------------------------------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // RDF-based generic dead code elimination.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker // The main interface of this class are functions "collect" and "erase".
13*9880d681SAndroid Build Coastguard Worker // This allows custom processing of the function being optimized by a
14*9880d681SAndroid Build Coastguard Worker // particular consumer. The simplest way to use this class would be to
15*9880d681SAndroid Build Coastguard Worker // instantiate an object, and then simply call "collect" and "erase",
16*9880d681SAndroid Build Coastguard Worker // passing the result of "getDeadInstrs()" to it.
17*9880d681SAndroid Build Coastguard Worker // A more complex scenario would be to call "collect" first, then visit
18*9880d681SAndroid Build Coastguard Worker // all post-increment instructions to see if the address update is dead
19*9880d681SAndroid Build Coastguard Worker // or not, and if it is, convert the instruction to a non-updating form.
20*9880d681SAndroid Build Coastguard Worker // After that "erase" can be called with the set of nodes including both,
21*9880d681SAndroid Build Coastguard Worker // dead defs from the updating instructions and the nodes corresponding
22*9880d681SAndroid Build Coastguard Worker // to the dead instructions.
23*9880d681SAndroid Build Coastguard Worker 
24*9880d681SAndroid Build Coastguard Worker #ifndef RDF_DEADCODE_H
25*9880d681SAndroid Build Coastguard Worker #define RDF_DEADCODE_H
26*9880d681SAndroid Build Coastguard Worker 
27*9880d681SAndroid Build Coastguard Worker #include "RDFGraph.h"
28*9880d681SAndroid Build Coastguard Worker #include "RDFLiveness.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SetVector.h"
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker namespace llvm {
32*9880d681SAndroid Build Coastguard Worker   class MachineRegisterInfo;
33*9880d681SAndroid Build Coastguard Worker 
34*9880d681SAndroid Build Coastguard Worker namespace rdf {
35*9880d681SAndroid Build Coastguard Worker   struct DeadCodeElimination {
DeadCodeEliminationDeadCodeElimination36*9880d681SAndroid Build Coastguard Worker     DeadCodeElimination(DataFlowGraph &dfg, MachineRegisterInfo &mri)
37*9880d681SAndroid Build Coastguard Worker       : Trace(false), DFG(dfg), MRI(mri), LV(mri, dfg) {}
38*9880d681SAndroid Build Coastguard Worker 
39*9880d681SAndroid Build Coastguard Worker     bool collect();
40*9880d681SAndroid Build Coastguard Worker     bool erase(const SetVector<NodeId> &Nodes);
traceDeadCodeElimination41*9880d681SAndroid Build Coastguard Worker     void trace(bool On) { Trace = On; }
traceDeadCodeElimination42*9880d681SAndroid Build Coastguard Worker     bool trace() const { return Trace; }
43*9880d681SAndroid Build Coastguard Worker 
getDeadNodesDeadCodeElimination44*9880d681SAndroid Build Coastguard Worker     SetVector<NodeId> getDeadNodes() { return DeadNodes; }
getDeadInstrsDeadCodeElimination45*9880d681SAndroid Build Coastguard Worker     SetVector<NodeId> getDeadInstrs() { return DeadInstrs; }
getDFGDeadCodeElimination46*9880d681SAndroid Build Coastguard Worker     DataFlowGraph &getDFG() { return DFG; }
47*9880d681SAndroid Build Coastguard Worker 
48*9880d681SAndroid Build Coastguard Worker   private:
49*9880d681SAndroid Build Coastguard Worker     bool Trace;
50*9880d681SAndroid Build Coastguard Worker     SetVector<NodeId> LiveNodes;
51*9880d681SAndroid Build Coastguard Worker     SetVector<NodeId> DeadNodes;
52*9880d681SAndroid Build Coastguard Worker     SetVector<NodeId> DeadInstrs;
53*9880d681SAndroid Build Coastguard Worker     DataFlowGraph &DFG;
54*9880d681SAndroid Build Coastguard Worker     MachineRegisterInfo &MRI;
55*9880d681SAndroid Build Coastguard Worker     Liveness LV;
56*9880d681SAndroid Build Coastguard Worker 
57*9880d681SAndroid Build Coastguard Worker     template<typename T> struct SetQueue;
58*9880d681SAndroid Build Coastguard Worker 
59*9880d681SAndroid Build Coastguard Worker     bool isLiveInstr(const MachineInstr *MI) const;
60*9880d681SAndroid Build Coastguard Worker     void scanInstr(NodeAddr<InstrNode*> IA, SetQueue<NodeId> &WorkQ);
61*9880d681SAndroid Build Coastguard Worker     void processDef(NodeAddr<DefNode*> DA, SetQueue<NodeId> &WorkQ);
62*9880d681SAndroid Build Coastguard Worker     void processUse(NodeAddr<UseNode*> UA, SetQueue<NodeId> &WorkQ);
63*9880d681SAndroid Build Coastguard Worker   };
64*9880d681SAndroid Build Coastguard Worker } // namespace rdf
65*9880d681SAndroid Build Coastguard Worker } // namespace llvm
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker #endif
68