blob: 3131c5a41f27d4efce983afa8bbf4b618b44e557 [file] [log] [blame]
Krzysztof Parzyszek6f4000e2016-01-12 17:01:16 +00001//===--- 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
31namespace llvm {
32 class MachineRegisterInfo;
33}
34
35namespace rdf {
36 struct DeadCodeElimination {
37 DeadCodeElimination(DataFlowGraph &dfg, MachineRegisterInfo &mri)
38 : Trace(false), DFG(dfg), MRI(mri), LV(mri, dfg) {}
39
40 bool collect();
41 bool erase(const SetVector<NodeId> &Nodes);
42 void trace(bool On) { Trace = On; }
43 bool trace() const { return Trace; }
44
45 SetVector<NodeId> getDeadNodes() { return DeadNodes; }
46 SetVector<NodeId> getDeadInstrs() { return DeadInstrs; }
47 DataFlowGraph &getDFG() { return DFG; }
48
49 private:
50 bool Trace;
51 SetVector<NodeId> LiveNodes;
52 SetVector<NodeId> DeadNodes;
53 SetVector<NodeId> DeadInstrs;
54 DataFlowGraph &DFG;
55 MachineRegisterInfo &MRI;
56 Liveness LV;
57
Krzysztof Parzyszeke6b06622016-01-18 20:42:47 +000058 template<typename T> struct SetQueue;
59
Krzysztof Parzyszek6f4000e2016-01-12 17:01:16 +000060 bool isLiveInstr(const MachineInstr *MI) const;
Krzysztof Parzyszeke6b06622016-01-18 20:42:47 +000061 void scanInstr(NodeAddr<InstrNode*> IA, SetQueue<NodeId> &WorkQ);
62 void processDef(NodeAddr<DefNode*> DA, SetQueue<NodeId> &WorkQ);
63 void processUse(NodeAddr<UseNode*> UA, SetQueue<NodeId> &WorkQ);
Krzysztof Parzyszek6f4000e2016-01-12 17:01:16 +000064 };
65}
66
67#endif