2017-08-01 23:20:10 +02:00
|
|
|
//===- RDFLiveness.h --------------------------------------------*- C++ -*-===//
|
2016-01-12 16:56:33 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-01-12 16:56:33 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Recalculate the liveness information given a data flow graph.
|
|
|
|
// This includes block live-ins and kill flags.
|
|
|
|
|
2017-08-01 23:20:10 +02:00
|
|
|
#ifndef LLVM_LIB_TARGET_HEXAGON_RDFLIVENESS_H
|
|
|
|
#define LLVM_LIB_TARGET_HEXAGON_RDFLIVENESS_H
|
2016-01-12 16:56:33 +01:00
|
|
|
|
|
|
|
#include "RDFGraph.h"
|
2017-08-01 23:20:10 +02:00
|
|
|
#include "RDFRegisters.h"
|
2016-01-12 16:56:33 +01:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2017-08-01 23:20:10 +02:00
|
|
|
#include "llvm/MC/LaneBitmask.h"
|
2016-01-12 16:56:33 +01:00
|
|
|
#include <map>
|
2017-08-01 23:20:10 +02:00
|
|
|
#include <set>
|
|
|
|
#include <utility>
|
2016-01-12 16:56:33 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-08-01 23:20:10 +02:00
|
|
|
|
|
|
|
class MachineBasicBlock;
|
|
|
|
class MachineDominanceFrontier;
|
|
|
|
class MachineDominatorTree;
|
|
|
|
class MachineRegisterInfo;
|
|
|
|
class TargetRegisterInfo;
|
2016-01-12 16:56:33 +01:00
|
|
|
|
|
|
|
namespace rdf {
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-01-12 16:56:33 +01:00
|
|
|
struct Liveness {
|
|
|
|
public:
|
2016-10-19 18:30:56 +02:00
|
|
|
// This is really a std::map, except that it provides a non-trivial
|
|
|
|
// default constructor to the element accessed via [].
|
|
|
|
struct LiveMapType {
|
2017-01-30 18:46:56 +01:00
|
|
|
LiveMapType(const PhysicalRegisterInfo &pri) : Empty(pri) {}
|
2016-10-19 18:30:56 +02:00
|
|
|
|
|
|
|
RegisterAggr &operator[] (MachineBasicBlock *B) {
|
|
|
|
return Map.emplace(B, Empty).first->second;
|
|
|
|
}
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-10-19 18:30:56 +02:00
|
|
|
private:
|
|
|
|
RegisterAggr Empty;
|
|
|
|
std::map<MachineBasicBlock*,RegisterAggr> Map;
|
|
|
|
};
|
|
|
|
|
2017-08-01 23:20:10 +02:00
|
|
|
using NodeRef = std::pair<NodeId, LaneBitmask>;
|
|
|
|
using NodeRefSet = std::set<NodeRef>;
|
2016-10-19 18:30:56 +02:00
|
|
|
// RegisterId in RefMap must be normalized.
|
2017-08-01 23:20:10 +02:00
|
|
|
using RefMap = std::map<RegisterId, NodeRefSet>;
|
2016-01-12 16:56:33 +01:00
|
|
|
|
|
|
|
Liveness(MachineRegisterInfo &mri, const DataFlowGraph &g)
|
2018-03-12 15:40:48 +01:00
|
|
|
: DFG(g), TRI(g.getTRI()), PRI(g.getPRI()), MDT(g.getDT()),
|
|
|
|
MDF(g.getDF()), LiveMap(g.getPRI()), Empty(), NoRegs(g.getPRI()) {}
|
2016-01-12 16:56:33 +01:00
|
|
|
|
|
|
|
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode*> RefA,
|
2017-02-16 20:28:06 +01:00
|
|
|
bool TopShadows, bool FullChain, const RegisterAggr &DefRRs);
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-10-03 19:14:48 +02:00
|
|
|
NodeList getAllReachingDefs(NodeAddr<RefNode*> RefA) {
|
2017-02-16 20:28:06 +01:00
|
|
|
return getAllReachingDefs(RefA.Addr->getRegRef(DFG), RefA, false,
|
|
|
|
false, NoRegs);
|
2016-10-03 19:14:48 +02:00
|
|
|
}
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-10-03 19:14:48 +02:00
|
|
|
NodeList getAllReachingDefs(RegisterRef RefRR, NodeAddr<RefNode*> RefA) {
|
2017-02-16 20:28:06 +01:00
|
|
|
return getAllReachingDefs(RefRR, RefA, false, false, NoRegs);
|
2016-10-03 19:14:48 +02:00
|
|
|
}
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-04-29 17:49:13 +02:00
|
|
|
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr<DefNode*> DefA,
|
2016-10-03 19:14:48 +02:00
|
|
|
const RegisterAggr &DefRRs);
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-10-03 19:14:48 +02:00
|
|
|
NodeSet getAllReachedUses(RegisterRef RefRR, NodeAddr<DefNode*> DefA) {
|
|
|
|
return getAllReachedUses(RefRR, DefA, NoRegs);
|
|
|
|
}
|
2016-01-12 16:56:33 +01:00
|
|
|
|
2017-03-01 20:30:42 +01:00
|
|
|
std::pair<NodeSet,bool> getAllReachingDefsRec(RegisterRef RefRR,
|
|
|
|
NodeAddr<RefNode*> RefA, NodeSet &Visited, const NodeSet &Defs);
|
|
|
|
|
2017-03-10 23:42:17 +01:00
|
|
|
NodeAddr<RefNode*> getNearestAliasedRef(RegisterRef RefRR,
|
|
|
|
NodeAddr<InstrNode*> IA);
|
|
|
|
|
2016-01-12 16:56:33 +01:00
|
|
|
LiveMapType &getLiveMap() { return LiveMap; }
|
|
|
|
const LiveMapType &getLiveMap() const { return LiveMap; }
|
2017-08-01 23:20:10 +02:00
|
|
|
|
2016-01-12 16:56:33 +01:00
|
|
|
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;
|
2017-01-30 18:46:56 +01:00
|
|
|
const PhysicalRegisterInfo &PRI;
|
2016-01-12 16:56:33 +01:00
|
|
|
const MachineDominatorTree &MDT;
|
|
|
|
const MachineDominanceFrontier &MDF;
|
|
|
|
LiveMapType LiveMap;
|
|
|
|
const RefMap Empty;
|
2016-10-03 19:14:48 +02:00
|
|
|
const RegisterAggr NoRegs;
|
2017-08-01 23:20:10 +02:00
|
|
|
bool Trace = false;
|
2016-01-12 16:56:33 +01:00
|
|
|
|
|
|
|
// Cache of mapping from node ids (for RefNodes) to the containing
|
|
|
|
// basic blocks. Not computing it each time for each node reduces
|
|
|
|
// the liveness calculation time by a large fraction.
|
2017-08-01 23:20:10 +02:00
|
|
|
using NodeBlockMap = DenseMap<NodeId, MachineBasicBlock *>;
|
2016-01-12 16:56:33 +01:00
|
|
|
NodeBlockMap NBMap;
|
|
|
|
|
|
|
|
// Phi information:
|
|
|
|
//
|
2016-10-21 21:12:13 +02:00
|
|
|
// RealUseMap
|
|
|
|
// map: NodeId -> (map: RegisterId -> NodeRefSet)
|
2016-01-12 16:56:33 +01:00
|
|
|
// phi id -> (map: register -> set of reached non-phi uses)
|
|
|
|
std::map<NodeId, RefMap> RealUseMap;
|
|
|
|
|
|
|
|
// Inverse iterated dominance frontier.
|
|
|
|
std::map<MachineBasicBlock*,std::set<MachineBasicBlock*>> IIDF;
|
|
|
|
|
|
|
|
// Live on entry.
|
|
|
|
std::map<MachineBasicBlock*,RefMap> PhiLON;
|
|
|
|
|
|
|
|
// Phi uses are considered to be located at the end of the block that
|
|
|
|
// they are associated with. The reaching def of a phi use dominates the
|
|
|
|
// block that the use corresponds to, but not the block that contains
|
|
|
|
// the phi itself. To include these uses in the liveness propagation (up
|
|
|
|
// the dominator tree), create a map: block -> set of uses live on exit.
|
|
|
|
std::map<MachineBasicBlock*,RefMap> PhiLOX;
|
|
|
|
|
|
|
|
MachineBasicBlock *getBlockWithRef(NodeId RN) const;
|
|
|
|
void traverse(MachineBasicBlock *B, RefMap &LiveIn);
|
|
|
|
void emptify(RefMap &M);
|
2017-03-01 20:30:42 +01:00
|
|
|
|
|
|
|
std::pair<NodeSet,bool> getAllReachingDefsRecImpl(RegisterRef RefRR,
|
|
|
|
NodeAddr<RefNode*> RefA, NodeSet &Visited, const NodeSet &Defs,
|
|
|
|
unsigned Nest, unsigned MaxNest);
|
2016-01-12 16:56:33 +01:00
|
|
|
};
|
|
|
|
|
2017-08-01 23:20:10 +02:00
|
|
|
} // end namespace rdf
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_LIB_TARGET_HEXAGON_RDFLIVENESS_H
|