Simplify ReachingDefs::RDMap() accessor

This commit is contained in:
Jon Siwek 2021-02-04 15:37:05 -08:00
parent 5f79cb7668
commit 2c04054975
2 changed files with 10 additions and 13 deletions

View file

@ -65,7 +65,7 @@ RDPtr ReachingDefs::Intersect(const RDPtr& r) const
auto res = make_intrusive<ReachingDefs>(); auto res = make_intrusive<ReachingDefs>();
for ( const auto& i : *RDMapRef() ) for ( const auto& i : *RDMap() )
for ( const auto& dp : *i.second ) for ( const auto& dp : *i.second )
{ {
if ( r->HasPair(i.first, dp) ) if ( r->HasPair(i.first, dp) )
@ -87,7 +87,7 @@ RDPtr ReachingDefs::Union(const RDPtr& r) const
res->AddRDs(r); res->AddRDs(r);
for ( const auto& i : *RDMapRef() ) for ( const auto& i : *RDMap() )
for ( const auto& dp : *i.second ) for ( const auto& dp : *i.second )
res->AddRD(i.first, dp); res->AddRD(i.first, dp);
@ -102,7 +102,7 @@ RDPtr ReachingDefs::IntersectWithConsolidation(const RDPtr& r,
auto res = make_intrusive<ReachingDefs>(); auto res = make_intrusive<ReachingDefs>();
for ( const auto& i : *RDMapRef() ) for ( const auto& i : *RDMap() )
for ( const auto& dp : *i.second ) for ( const auto& dp : *i.second )
{ {
if ( r->HasPair(i.first, dp) ) if ( r->HasPair(i.first, dp) )
@ -122,7 +122,7 @@ RDPtr ReachingDefs::IntersectWithConsolidation(const RDPtr& r,
bool ReachingDefs::HasPair(const DefinitionItem* di, const DefinitionPoint& dp) bool ReachingDefs::HasPair(const DefinitionItem* di, const DefinitionPoint& dp)
const const
{ {
const auto& map = RDMapRef(); const auto& map = RDMap();
auto l = map->find(di); auto l = map->find(di);
if ( l == map->end() ) if ( l == map->end() )
@ -155,7 +155,7 @@ void ReachingDefs::CopyMapIfNeeded()
void ReachingDefs::Dump() const void ReachingDefs::Dump() const
{ {
DumpMap(RDMapRef()); DumpMap(RDMap());
} }
void ReachingDefs::DumpMap(const std::shared_ptr<ReachingDefsMap>& map) const void ReachingDefs::DumpMap(const std::shared_ptr<ReachingDefsMap>& map) const

View file

@ -45,7 +45,7 @@ public:
// Add in all the definition points from rd into our set, if // Add in all the definition points from rd into our set, if
// we don't already have them. // we don't already have them.
void AddRDs(const RDPtr& rd) { AddRDs(rd->RDMapRef()); } void AddRDs(const RDPtr& rd) { AddRDs(rd->RDMap()); }
// Add in a single definition pair, creating the entry for // Add in a single definition pair, creating the entry for
// the item if necessary. // the item if necessary.
@ -59,7 +59,7 @@ public:
// True if the given definition item is present in our RDs. // True if the given definition item is present in our RDs.
bool HasDI(const DefinitionItem* di) const bool HasDI(const DefinitionItem* di) const
{ {
const auto& map = RDMapRef(); const auto& map = RDMap();
return map->find(di) != map->end(); return map->find(di) != map->end();
} }
@ -67,7 +67,7 @@ public:
// points at our location in the AST. // points at our location in the AST.
DefPoints* GetDefPoints(const DefinitionItem* di) DefPoints* GetDefPoints(const DefinitionItem* di)
{ {
const auto& map = RDMapRef(); const auto& map = RDMap();
auto dps = map->find(di); auto dps = map->find(di);
return dps == map->end() ? nullptr : dps->second.get(); return dps == map->end() ? nullptr : dps->second.get();
} }
@ -115,7 +115,7 @@ public:
RDPtr IntersectWithConsolidation(const RDPtr& r, RDPtr IntersectWithConsolidation(const RDPtr& r,
const DefinitionPoint& di) const; const DefinitionPoint& di) const;
int Size() const { return RDMapRef()->size(); } int Size() const { return RDMap()->size(); }
// Print out the RDs, for debugging purposes. // Print out the RDs, for debugging purposes.
void Dump() const; void Dump() const;
@ -129,10 +129,7 @@ protected:
// Adds in the given RDs if we don't already have them. // Adds in the given RDs if we don't already have them.
void AddRDs(const std::shared_ptr<ReachingDefsMap>& rd_m); void AddRDs(const std::shared_ptr<ReachingDefsMap>& rd_m);
std::shared_ptr<ReachingDefsMap> RDMap() const const std::shared_ptr<ReachingDefsMap>& RDMap() const
{ return my_rd_map ? my_rd_map : const_rd_map; }
const std::shared_ptr<ReachingDefsMap>& RDMapRef() const
{ return my_rd_map ? my_rd_map : const_rd_map; } { return my_rd_map ? my_rd_map : const_rd_map; }
// If we don't already have our own map, copy the one we're using // If we don't already have our own map, copy the one we're using