This revision was automatically updated to reflect the committed changes.
Closed by commit rL284869: [CUDA] Use FunctionDeclAndLoc for the 
Sema::LocsWithCUDACallDiags hashtable. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D25797?vs=75231&id=75474#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25797

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaCUDA.cpp


Index: cfe/trunk/include/clang/Sema/Sema.h
===================================================================
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9250,18 +9250,18 @@
                  std::vector<PartialDiagnosticAt>>
       CUDADeferredDiags;
 
-  /// FunctionDecls plus raw encodings of SourceLocations for which
-  /// CheckCUDACall has emitted a (maybe deferred) "bad call" diagnostic.  We
-  /// use this to avoid emitting the same deferred diag twice.
-  llvm::DenseSet<std::pair<CanonicalDeclPtr<FunctionDecl>, unsigned>>
-      LocsWithCUDACallDiags;
-
-  /// A pair of a canonical FunctionDecl and a SourceLocation.
+  /// A pair of a canonical FunctionDecl and a SourceLocation.  When used as 
the
+  /// key in a hashtable, both the FD and location are hashed.
   struct FunctionDeclAndLoc {
     CanonicalDeclPtr<FunctionDecl> FD;
     SourceLocation Loc;
   };
 
+  /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a
+  /// (maybe deferred) "bad call" diagnostic.  We use this to avoid emitting 
the
+  /// same deferred diag twice.
+  llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags;
+
   /// An inverse call graph, mapping known-emitted functions to one of their
   /// known-emitted callers (plus the location of the call).
   ///
@@ -10035,4 +10035,31 @@
 
 } // end namespace clang
 
+namespace llvm {
+// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its
+// SourceLocation.
+template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> {
+  using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc;
+  using FDBaseInfo = 
DenseMapInfo<clang::CanonicalDeclPtr<clang::FunctionDecl>>;
+
+  static FunctionDeclAndLoc getEmptyKey() {
+    return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()};
+  }
+
+  static FunctionDeclAndLoc getTombstoneKey() {
+    return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()};
+  }
+
+  static unsigned getHashValue(const FunctionDeclAndLoc &FDL) {
+    return hash_combine(FDBaseInfo::getHashValue(FDL.FD),
+                        FDL.Loc.getRawEncoding());
+  }
+
+  static bool isEqual(const FunctionDeclAndLoc &LHS,
+                      const FunctionDeclAndLoc &RHS) {
+    return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc;
+  }
+};
+} // namespace llvm
+
 #endif
Index: cfe/trunk/lib/Sema/SemaCUDA.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCUDA.cpp
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp
@@ -774,7 +774,7 @@
   // like this is unfortunate, but because we must continue parsing as normal
   // after encountering a deferred error, it's otherwise very tricky for us to
   // ensure that we only emit this deferred error once.
-  if (!LocsWithCUDACallDiags.insert({Caller, Loc.getRawEncoding()}).second)
+  if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second)
     return true;
 
   CUDADiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this)


Index: cfe/trunk/include/clang/Sema/Sema.h
===================================================================
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9250,18 +9250,18 @@
                  std::vector<PartialDiagnosticAt>>
       CUDADeferredDiags;
 
-  /// FunctionDecls plus raw encodings of SourceLocations for which
-  /// CheckCUDACall has emitted a (maybe deferred) "bad call" diagnostic.  We
-  /// use this to avoid emitting the same deferred diag twice.
-  llvm::DenseSet<std::pair<CanonicalDeclPtr<FunctionDecl>, unsigned>>
-      LocsWithCUDACallDiags;
-
-  /// A pair of a canonical FunctionDecl and a SourceLocation.
+  /// A pair of a canonical FunctionDecl and a SourceLocation.  When used as the
+  /// key in a hashtable, both the FD and location are hashed.
   struct FunctionDeclAndLoc {
     CanonicalDeclPtr<FunctionDecl> FD;
     SourceLocation Loc;
   };
 
+  /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a
+  /// (maybe deferred) "bad call" diagnostic.  We use this to avoid emitting the
+  /// same deferred diag twice.
+  llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags;
+
   /// An inverse call graph, mapping known-emitted functions to one of their
   /// known-emitted callers (plus the location of the call).
   ///
@@ -10035,4 +10035,31 @@
 
 } // end namespace clang
 
+namespace llvm {
+// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its
+// SourceLocation.
+template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> {
+  using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc;
+  using FDBaseInfo = DenseMapInfo<clang::CanonicalDeclPtr<clang::FunctionDecl>>;
+
+  static FunctionDeclAndLoc getEmptyKey() {
+    return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()};
+  }
+
+  static FunctionDeclAndLoc getTombstoneKey() {
+    return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()};
+  }
+
+  static unsigned getHashValue(const FunctionDeclAndLoc &FDL) {
+    return hash_combine(FDBaseInfo::getHashValue(FDL.FD),
+                        FDL.Loc.getRawEncoding());
+  }
+
+  static bool isEqual(const FunctionDeclAndLoc &LHS,
+                      const FunctionDeclAndLoc &RHS) {
+    return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc;
+  }
+};
+} // namespace llvm
+
 #endif
Index: cfe/trunk/lib/Sema/SemaCUDA.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCUDA.cpp
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp
@@ -774,7 +774,7 @@
   // like this is unfortunate, but because we must continue parsing as normal
   // after encountering a deferred error, it's otherwise very tricky for us to
   // ensure that we only emit this deferred error once.
-  if (!LocsWithCUDACallDiags.insert({Caller, Loc.getRawEncoding()}).second)
+  if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second)
     return true;
 
   CUDADiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to