Skip to content

Commit

Permalink
[clang][NFC] refactor GlobalMethodPool to encapsulate its map
Browse files Browse the repository at this point in the history
This refactor changes the GlobalMethodPool to a class that contains
the DenseMap of methods. This is to allow for the addition of a
separate DenseSet in a follow-up diff that will handle method
de-duplication when inserting methods into the global method pool.

Changes:
  - the `GlobalMethods` pair becomes `GlobalMethodPool::Lists`
  - the `GlobalMethodPool` becomes a class containing the `DenseMap` of methods
  - pass through methods are added to maintain most of the existing code without changing `MethodPool` -> `MethodPool.Methods` everywhere

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D109898
  • Loading branch information
rmaz authored and drodriguez committed Sep 16, 2021
1 parent 2aa8474 commit e6020b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
18 changes: 16 additions & 2 deletions clang/include/clang/Sema/Sema.h
Expand Up @@ -1419,8 +1419,22 @@ class Sema final {
const llvm::MapVector<FieldDecl *, DeleteLocs> &
getMismatchingDeleteExpressions() const;

typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
class GlobalMethodPool {
public:
using Lists = std::pair<ObjCMethodList, ObjCMethodList>;
using iterator = llvm::DenseMap<Selector, Lists>::iterator;
iterator begin() { return Methods.begin(); }
iterator end() { return Methods.end(); }
iterator find(Selector Sel) { return Methods.find(Sel); }
std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) {
return Methods.insert(Val);
}
int count(Selector Sel) const { return Methods.count(Sel); }
bool empty() const { return Methods.empty(); }

private:
llvm::DenseMap<Selector, Lists> Methods;
};

/// Method Pool - allows efficient lookup when typechecking messages to "id".
/// We need to maintain a list, since selectors can have differing signatures
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/Sema/SemaDeclObjC.cpp
Expand Up @@ -3427,8 +3427,10 @@ void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl,

GlobalMethodPool::iterator Pos = MethodPool.find(Method->getSelector());
if (Pos == MethodPool.end())
Pos = MethodPool.insert(std::make_pair(Method->getSelector(),
GlobalMethods())).first;
Pos = MethodPool
.insert(std::make_pair(Method->getSelector(),
GlobalMethodPool::Lists()))
.first;

Method->setDefined(impl);

Expand Down Expand Up @@ -3636,7 +3638,7 @@ ObjCMethodDecl *Sema::LookupImplementedMethodInGlobalPool(Selector Sel) {
if (Pos == MethodPool.end())
return nullptr;

GlobalMethods &Methods = Pos->second;
GlobalMethodPool::Lists &Methods = Pos->second;
for (const ObjCMethodList *Method = &Methods.first; Method;
Method = Method->getNext())
if (Method->getMethod() &&
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Serialization/ASTReader.cpp
Expand Up @@ -8208,8 +8208,9 @@ void ASTReader::ReadMethodPool(Selector Sel) {
return;

Sema &S = *getSema();
Sema::GlobalMethodPool::iterator Pos
= S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first;
Sema::GlobalMethodPool::iterator Pos =
S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethodPool::Lists()))
.first;

Pos->second.first.setBits(Visitor.getInstanceBits());
Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl());
Expand Down

0 comments on commit e6020b2

Please sign in to comment.