#ifndef RDF_LIVENESS_H
#define RDF_LIVENESS_H
#include "RDFGraph.h"
#include "llvm/ADT/DenseMap.h"
#include <map>
using namespace llvm;
namespace llvm {
class MachineBasicBlock;
class MachineFunction;
class MachineRegisterInfo;
class TargetRegisterInfo;
class MachineDominatorTree;
class MachineDominanceFrontier;
}
namespace rdf {
struct Liveness {
public:
typedef std::map<MachineBasicBlock*,RegisterSet> LiveMapType;
typedef std::map<RegisterRef,NodeSet> RefMap;
Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
: DFG(g), TRI(g.getTRI()), MDT(g.getDT()), MDF(g.getDF()),
RAI(g.getRAI()), MRI(mri), Empty(), Trace(false) {}
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
bool FullChain = false, const RegisterSet &DefRRs = RegisterSet());
NodeList getAllReachingDefs(NodeAddr<RefNode*> RefA);
LiveMapType &getLiveMap() { return LiveMap; }
const LiveMapType &getLiveMap() const { return LiveMap; }
const RefMap &getRealUses(NodeId P) const {
auto F = RealUseMap.find(P);
return F == RealUseMap.end() ? Empty : F->second;
}
void computePhiInfo();
void computeLiveIns();
void resetLiveIns();
void resetKills();
void resetKills(MachineBasicBlock *B);
void trace(bool T) { Trace = T; }
private:
const DataFlowGraph &DFG;
const TargetRegisterInfo &TRI;
const MachineDominatorTree &MDT;
const MachineDominanceFrontier &MDF;
const RegisterAliasInfo &RAI;
MachineRegisterInfo &MRI;
LiveMapType LiveMap;
const RefMap Empty;
bool Trace;
typedef DenseMap<NodeId,MachineBasicBlock*> NodeBlockMap;
NodeBlockMap NBMap;
std::map<NodeId, RefMap> RealUseMap;
std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
std::map<MachineBasicBlock*,RefMap> PhiLON;
std::map<MachineBasicBlock*,RefMap> PhiLOX;
bool isRestricted(NodeAddr<InstrNode*> IA, NodeAddr<RefNode*> RA,
RegisterRef RR) const;
RegisterRef getRestrictedRegRef(NodeAddr<RefNode*> RA) const;
unsigned getPhysReg(RegisterRef RR) const;
MachineBasicBlock *getBlockWithRef(NodeId RN) const;
void traverse(MachineBasicBlock *B, RefMap &LiveIn);
void emptify(RefMap &M);
};
}
#endif // RDF_LIVENESS_H