[llvm] fc3ad14 - [RDF] Use RegisterAggr instead of RegisterSet in few places
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 11:08:30 PDT 2023
Author: Krzysztof Parzyszek
Date: 2023-06-08T11:07:57-07:00
New Revision: fc3ad148cdf8158e07b59f16c1f124143e6edfbf
URL: https://github.com/llvm/llvm-project/commit/fc3ad148cdf8158e07b59f16c1f124143e6edfbf
DIFF: https://github.com/llvm/llvm-project/commit/fc3ad148cdf8158e07b59f16c1f124143e6edfbf.diff
LOG: [RDF] Use RegisterAggr instead of RegisterSet in few places
This shouldn't change any functionality.
Added:
Modified:
llvm/include/llvm/CodeGen/RDFGraph.h
llvm/include/llvm/CodeGen/RDFLiveness.h
llvm/include/llvm/CodeGen/RDFRegisters.h
llvm/lib/CodeGen/RDFGraph.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/RDFGraph.h b/llvm/include/llvm/CodeGen/RDFGraph.h
index 6fb4963b3c5c9..97673a249237c 100644
--- a/llvm/include/llvm/CodeGen/RDFGraph.h
+++ b/llvm/include/llvm/CodeGen/RDFGraph.h
@@ -806,7 +806,7 @@ struct DataFlowGraph {
private:
void reset();
- RegisterSet getLandingPadLiveIns() const;
+ RegisterAggr getLandingPadLiveIns() const;
NodeAddr<NodeBase *> newNode(uint16_t Attrs);
NodeAddr<NodeBase *> cloneNode(const NodeAddr<NodeBase *> B);
@@ -830,7 +830,7 @@ struct DataFlowGraph {
locateNextRef(NodeAddr<InstrNode *> IA, NodeAddr<RefNode *> RA,
Predicate P) const;
- using BlockRefsMap = std::map<NodeId, RegisterSet>;
+ using BlockRefsMap = RegisterAggrMap<NodeId>;
void buildStmt(NodeAddr<BlockNode *> BA, MachineInstr &In);
void recordDefsForDF(BlockRefsMap &PhiM, NodeAddr<BlockNode *> BA);
diff --git a/llvm/include/llvm/CodeGen/RDFLiveness.h b/llvm/include/llvm/CodeGen/RDFLiveness.h
index f2c4bec54c670..2ef36cd97fb0a 100644
--- a/llvm/include/llvm/CodeGen/RDFLiveness.h
+++ b/llvm/include/llvm/CodeGen/RDFLiveness.h
@@ -58,20 +58,7 @@ namespace rdf {
struct Liveness {
public:
- // This is really a std::map, except that it provides a non-trivial
- // default constructor to the element accessed via [].
- struct LiveMapType {
- LiveMapType(const PhysicalRegisterInfo &pri) : Empty(pri) {}
-
- RegisterAggr &operator[](MachineBasicBlock *B) {
- return Map.emplace(B, Empty).first->second;
- }
-
- private:
- RegisterAggr Empty;
- std::map<MachineBasicBlock *, RegisterAggr> Map;
- };
-
+ using LiveMapType = RegisterAggrMap<MachineBasicBlock *>;
using NodeRef = detail::NodeRef;
using NodeRefSet = std::unordered_set<NodeRef>;
using RefMap = std::unordered_map<RegisterId, NodeRefSet>;
diff --git a/llvm/include/llvm/CodeGen/RDFRegisters.h b/llvm/include/llvm/CodeGen/RDFRegisters.h
index 790bd39c7b588..c1fc79246949e 100644
--- a/llvm/include/llvm/CodeGen/RDFRegisters.h
+++ b/llvm/include/llvm/CodeGen/RDFRegisters.h
@@ -162,7 +162,7 @@ struct RegisterAggr {
: Units(pri.getTRI().getNumRegUnits()), PRI(pri) {}
RegisterAggr(const RegisterAggr &RG) = default;
- unsigned count() const { return Units.count(); }
+ unsigned size() const { return Units.count(); }
bool empty() const { return Units.none(); }
bool hasAliasOf(RegisterRef RR) const;
bool hasCoverOf(RegisterRef RR) const;
@@ -230,6 +230,31 @@ struct RegisterAggr {
const PhysicalRegisterInfo &PRI;
};
+// This is really a std::map, except that it provides a non-trivial
+// default constructor to the element accessed via [].
+template <typename KeyType> struct RegisterAggrMap {
+ RegisterAggrMap(const PhysicalRegisterInfo &pri) : Empty(pri) {}
+
+ RegisterAggr &operator[](KeyType Key) {
+ return Map.emplace(Key, Empty).first->second;
+ }
+
+ auto begin() { return Map.begin(); }
+ auto end() { return Map.end(); }
+ auto begin() const { return Map.begin(); }
+ auto end() const { return Map.end(); }
+ auto find(const KeyType &Key) const { return Map.find(Key); }
+
+private:
+ RegisterAggr Empty;
+ std::map<KeyType, RegisterAggr> Map;
+
+public:
+ using key_type = typename decltype(Map)::key_type;
+ using mapped_type = typename decltype(Map)::mapped_type;
+ using value_type = typename decltype(Map)::value_type;
+};
+
// Optionally print the lane mask, if it is not ~0.
struct PrintLaneMaskOpt {
PrintLaneMaskOpt(LaneBitmask M) : Mask(M) {}
diff --git a/llvm/lib/CodeGen/RDFGraph.cpp b/llvm/lib/CodeGen/RDFGraph.cpp
index 46de878c442b6..14f9c1167bb43 100644
--- a/llvm/lib/CodeGen/RDFGraph.cpp
+++ b/llvm/lib/CodeGen/RDFGraph.cpp
@@ -764,8 +764,8 @@ unsigned DataFlowGraph::DefStack::nextDown(unsigned P) const {
// Register information.
-RegisterSet DataFlowGraph::getLandingPadLiveIns() const {
- RegisterSet LR;
+RegisterAggr DataFlowGraph::getLandingPadLiveIns() const {
+ RegisterAggr LR(getPRI());
const Function &F = MF.getFunction();
const Constant *PF = F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr;
const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering();
@@ -924,7 +924,6 @@ void DataFlowGraph::build(unsigned Options) {
}
// Add function-entry phi nodes for the live-in registers.
- // for (std::pair<RegisterId,LaneBitmask> P : LiveIns) {
for (auto I = LiveIns.rr_begin(), E = LiveIns.rr_end(); I != E; ++I) {
RegisterRef RR = *I;
NodeAddr<PhiNode *> PA = newPhi(EA);
@@ -938,7 +937,7 @@ void DataFlowGraph::build(unsigned Options) {
// branches in the program, or fall-throughs from other blocks. They
// are entered from the exception handling runtime and target's ABI
// may define certain registers as defined on entry to such a block.
- RegisterSet EHRegs = getLandingPadLiveIns();
+ RegisterAggr EHRegs = getLandingPadLiveIns();
if (!EHRegs.empty()) {
for (NodeAddr<BlockNode *> BA : Blocks) {
const MachineBasicBlock &B = *BA.Addr->getCode();
@@ -951,7 +950,8 @@ void DataFlowGraph::build(unsigned Options) {
Preds.push_back(findBlock(PB));
// Build phi nodes for each live-in.
- for (RegisterRef RR : EHRegs) {
+ for (auto I = EHRegs.rr_begin(), E = EHRegs.rr_end(); I != E; ++I) {
+ RegisterRef RR = *I;
NodeAddr<PhiNode *> PA = newPhi(BA);
uint16_t PhiFlags = NodeAttrs::PhiRef | NodeAttrs::Preserving;
// Add def:
@@ -968,7 +968,7 @@ void DataFlowGraph::build(unsigned Options) {
// Build a map "PhiM" which will contain, for each block, the set
// of references that will require phi definitions in that block.
- BlockRefsMap PhiM;
+ BlockRefsMap PhiM(getPRI());
for (NodeAddr<BlockNode *> BA : Blocks)
recordDefsForDF(PhiM, BA);
for (NodeAddr<BlockNode *> BA : Blocks)
@@ -1401,7 +1401,7 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM,
// in the block's iterated dominance frontier.
// This is done to make sure that each defined reference gets only one
// phi node, even if it is defined multiple times.
- RegisterSet Defs;
+ RegisterAggr Defs(getPRI());
for (NodeAddr<InstrNode *> IA : BA.Addr->members(*this))
for (NodeAddr<RefNode *> RA : IA.Addr->members_if(IsDef, *this))
Defs.insert(RA.Addr->getRegRef(*this));
@@ -1419,7 +1419,7 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM,
// frontier.
for (auto *DB : IDF) {
NodeAddr<BlockNode *> DBA = findBlock(DB);
- PhiM[DBA.Id].insert(Defs.begin(), Defs.end());
+ PhiM[DBA.Id].insert(Defs);
}
}
@@ -1444,9 +1444,13 @@ void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs,
return RR;
};
- RegisterSet MaxDF;
- for (RegisterRef I : HasDF->second)
- MaxDF.insert(MaxCoverIn(I, HasDF->second));
+ RegisterSet MaxDF, DefsDF;
+ for (auto I = HasDF->second.rr_begin(), E = HasDF->second.rr_end(); I != E;
+ ++I) {
+ DefsDF.insert(*I);
+ }
+ for (RegisterRef I : DefsDF)
+ MaxDF.insert(MaxCoverIn(I, DefsDF));
std::vector<RegisterRef> MaxRefs;
for (RegisterRef I : MaxDF)
@@ -1694,7 +1698,7 @@ void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, NodeAddr<BlockNode *> BA) {
return PUA.Addr->getPredecessor() == BA.Id;
};
- RegisterSet EHLiveIns = getLandingPadLiveIns();
+ RegisterAggr EHLiveIns = getLandingPadLiveIns();
MachineBasicBlock *MBB = BA.Addr->getCode();
for (MachineBasicBlock *SB : MBB->successors()) {
@@ -1706,7 +1710,7 @@ void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, NodeAddr<BlockNode *> BA) {
// Find what register this phi is for.
NodeAddr<RefNode *> RA = IA.Addr->getFirstMember(*this);
assert(RA.Id != 0);
- if (EHLiveIns.count(RA.Addr->getRegRef(*this)))
+ if (EHLiveIns.hasCoverOf(RA.Addr->getRegRef(*this)))
continue;
}
// Go over each phi use associated with MBB, and link it.
More information about the llvm-commits
mailing list