1//===--- RDFCopy.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#ifndef RDF_COPY_H
11#define RDF_COPY_H
12
13#include "RDFGraph.h"
14#include <map>
15#include <vector>
16
17namespace llvm {
18  class MachineBasicBlock;
19  class MachineDominatorTree;
20  class MachineInstr;
21
22namespace rdf {
23  struct CopyPropagation {
24    CopyPropagation(DataFlowGraph &dfg) : MDT(dfg.getDT()), DFG(dfg),
25        Trace(false) {}
26    virtual ~CopyPropagation() {}
27
28    bool run();
29    void trace(bool On) { Trace = On; }
30    bool trace() const { return Trace; }
31
32    typedef std::map<RegisterRef, RegisterRef> EqualityMap;
33    virtual bool interpretAsCopy(const MachineInstr *MI, EqualityMap &EM);
34
35  private:
36    const MachineDominatorTree &MDT;
37    DataFlowGraph &DFG;
38    DataFlowGraph::DefStackMap DefM;
39    bool Trace;
40
41    // map: register -> (map: stmt -> reaching def)
42    std::map<RegisterRef,std::map<NodeId,NodeId>> RDefMap;
43    // map: statement -> (map: dst reg -> src reg)
44    std::map<NodeId, EqualityMap> CopyMap;
45    std::vector<NodeId> Copies;
46
47    void recordCopy(NodeAddr<StmtNode*> SA, EqualityMap &EM);
48    void updateMap(NodeAddr<InstrNode*> IA);
49    bool scanBlock(MachineBasicBlock *B);
50  };
51} // namespace rdf
52} // namespace llvm
53
54#endif
55