summaryrefslogtreecommitdiff
path: root/lib/Target/Hexagon/RDFGraph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/Hexagon/RDFGraph.cpp')
-rw-r--r--lib/Target/Hexagon/RDFGraph.cpp77
1 files changed, 28 insertions, 49 deletions
diff --git a/lib/Target/Hexagon/RDFGraph.cpp b/lib/Target/Hexagon/RDFGraph.cpp
index 8d1272370899..d1f6e5a4c8ef 100644
--- a/lib/Target/Hexagon/RDFGraph.cpp
+++ b/lib/Target/Hexagon/RDFGraph.cpp
@@ -1,4 +1,4 @@
-//===--- RDFGraph.cpp -----------------------------------------------------===//
+//===- RDFGraph.cpp -------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,6 +10,8 @@
// Target-independent, SSA-based data flow graph for register data flow (RDF).
//
#include "RDFGraph.h"
+#include "RDFRegisters.h"
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
@@ -19,20 +21,23 @@
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/CodeGen/TargetLowering.h"
+#include "llvm/CodeGen/TargetRegisterInfo.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/MC/LaneBitmask.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/TargetInstrInfo.h"
-#include "llvm/Target/TargetLowering.h"
-#include "llvm/Target/TargetRegisterInfo.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <iterator>
+#include <set>
#include <utility>
#include <vector>
@@ -201,7 +206,7 @@ namespace {
struct PrintListV {
PrintListV(const NodeList &L, const DataFlowGraph &G) : List(L), G(G) {}
- typedef T Type;
+ using Type = T;
const NodeList &List;
const DataFlowGraph &G;
};
@@ -242,7 +247,7 @@ raw_ostream &operator<< (raw_ostream &OS,
if (T != MI.operands_end()) {
OS << ' ';
if (T->isMBB())
- OS << "BB#" << T->getMBB()->getNumber();
+ OS << printMBBReference(*T->getMBB());
else if (T->isGlobal())
OS << T->getGlobal()->getName();
else if (T->isSymbol())
@@ -279,13 +284,13 @@ raw_ostream &operator<< (raw_ostream &OS,
auto PrintBBs = [&OS] (std::vector<int> Ns) -> void {
unsigned N = Ns.size();
for (int I : Ns) {
- OS << "BB#" << I;
+ OS << "%bb." << I;
if (--N)
OS << ", ";
}
};
- OS << Print<NodeId>(P.Obj.Id, P.G) << ": --- BB#" << BB->getNumber()
+ OS << Print<NodeId>(P.Obj.Id, P.G) << ": --- " << printMBBReference(*BB)
<< " --- preds(" << NP << "): ";
for (MachineBasicBlock *B : BB->predecessors())
Ns.push_back(B->getNumber());
@@ -761,7 +766,7 @@ unsigned DataFlowGraph::DefStack::nextDown(unsigned P) const {
RegisterSet DataFlowGraph::getLandingPadLiveIns() const {
RegisterSet LR;
- const Function &F = *MF.getFunction();
+ const Function &F = MF.getFunction();
const Constant *PF = F.hasPersonalityFn() ? F.getPersonalityFn()
: nullptr;
const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering();
@@ -898,15 +903,18 @@ void DataFlowGraph::build(unsigned Options) {
NodeList Blocks = Func.Addr->members(*this);
// Collect information about block references.
- BlockRefsMap RefM;
- buildBlockRefs(EA, RefM);
+ RegisterSet AllRefs;
+ for (NodeAddr<BlockNode*> BA : Blocks)
+ for (NodeAddr<InstrNode*> IA : BA.Addr->members(*this))
+ for (NodeAddr<RefNode*> RA : IA.Addr->members(*this))
+ AllRefs.insert(RA.Addr->getRegRef(*this));
// Collect function live-ins and entry block live-ins.
MachineRegisterInfo &MRI = MF.getRegInfo();
MachineBasicBlock &EntryB = *EA.Addr->getCode();
assert(EntryB.pred_empty() && "Function entry block has predecessors");
- for (auto I = MRI.livein_begin(), E = MRI.livein_end(); I != E; ++I)
- LiveIns.insert(RegisterRef(I->first));
+ for (std::pair<unsigned,unsigned> P : MRI.liveins())
+ LiveIns.insert(RegisterRef(P.first));
if (MRI.tracksLiveness()) {
for (auto I : EntryB.liveins())
LiveIns.insert(RegisterRef(I.PhysReg, I.LaneMask));
@@ -959,9 +967,9 @@ void DataFlowGraph::build(unsigned Options) {
// of references that will require phi definitions in that block.
BlockRefsMap PhiM;
for (NodeAddr<BlockNode*> BA : Blocks)
- recordDefsForDF(PhiM, RefM, BA);
+ recordDefsForDF(PhiM, BA);
for (NodeAddr<BlockNode*> BA : Blocks)
- buildPhis(PhiM, RefM, BA);
+ buildPhis(PhiM, AllRefs, BA);
// Link all the refs. This will recursively traverse the dominator tree.
DefStackMap DM;
@@ -1115,8 +1123,8 @@ void DataFlowGraph::pushDefs(NodeAddr<InstrNode*> IA, DefStackMap &DefM) {
if (!Defined.insert(RR.Reg).second) {
MachineInstr *MI = NodeAddr<StmtNode*>(IA).Addr->getCode();
dbgs() << "Multiple definitions of register: "
- << Print<RegisterRef>(RR, *this) << " in\n " << *MI
- << "in BB#" << MI->getParent()->getNumber() << '\n';
+ << Print<RegisterRef>(RR, *this) << " in\n " << *MI << "in "
+ << printMBBReference(*MI->getParent()) << '\n';
llvm_unreachable(nullptr);
}
#endif
@@ -1389,29 +1397,9 @@ void DataFlowGraph::buildStmt(NodeAddr<BlockNode*> BA, MachineInstr &In) {
}
}
-// Build a map that for each block will have the set of all references from
-// that block, and from all blocks dominated by it.
-void DataFlowGraph::buildBlockRefs(NodeAddr<BlockNode*> BA,
- BlockRefsMap &RefM) {
- RegisterSet &Refs = RefM[BA.Id];
- MachineDomTreeNode *N = MDT.getNode(BA.Addr->getCode());
- assert(N);
- for (auto I : *N) {
- MachineBasicBlock *SB = I->getBlock();
- NodeAddr<BlockNode*> SBA = findBlock(SB);
- buildBlockRefs(SBA, RefM);
- const RegisterSet &RefsS = RefM[SBA.Id];
- Refs.insert(RefsS.begin(), RefsS.end());
- }
-
- for (NodeAddr<InstrNode*> IA : BA.Addr->members(*this))
- for (NodeAddr<RefNode*> RA : IA.Addr->members(*this))
- Refs.insert(RA.Addr->getRegRef(*this));
-}
-
// Scan all defs in the block node BA and record in PhiM the locations of
// phi nodes corresponding to these defs.
-void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, BlockRefsMap &RefM,
+void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM,
NodeAddr<BlockNode*> BA) {
// Check all defs from block BA and record them in each block in BA's
// iterated dominance frontier. This information will later be used to
@@ -1441,14 +1429,6 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, BlockRefsMap &RefM,
IDF.insert(F->second.begin(), F->second.end());
}
- // Get the register references that are reachable from this block.
- RegisterSet &Refs = RefM[BA.Id];
- for (auto DB : IDF) {
- NodeAddr<BlockNode*> DBA = findBlock(DB);
- const RegisterSet &RefsD = RefM[DBA.Id];
- Refs.insert(RefsD.begin(), RefsD.end());
- }
-
// Finally, add the set of defs to each block in the iterated dominance
// frontier.
for (auto DB : IDF) {
@@ -1459,7 +1439,7 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, BlockRefsMap &RefM,
// Given the locations of phi nodes in the map PhiM, create the phi nodes
// that are located in the block node BA.
-void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, BlockRefsMap &RefM,
+void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs,
NodeAddr<BlockNode*> BA) {
// Check if this blocks has any DF defs, i.e. if there are any defs
// that this block is in the iterated dominance frontier of.
@@ -1483,9 +1463,8 @@ void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, BlockRefsMap &RefM,
MaxDF.insert(MaxCoverIn(I, HasDF->second));
std::vector<RegisterRef> MaxRefs;
- RegisterSet &RefB = RefM[BA.Id];
for (RegisterRef I : MaxDF)
- MaxRefs.push_back(MaxCoverIn(I, RefB));
+ MaxRefs.push_back(MaxCoverIn(I, AllRefs));
// Now, for each R in MaxRefs, get the alias closure of R. If the closure
// only has R in it, create a phi a def for R. Otherwise, create a phi,