[PATCH] D12453: [CUDA] Allow function overloads based on host/device attributes.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 1 16:22:38 PDT 2015


rsmith added inline comments.

================
Comment at: include/clang/Basic/Builtins.h:85
@@ +84,3 @@
+  /// \brief Return true if this function is a target-specific builtin
+  bool isTSBuiltin(unsigned ID) const {
+    return ID >= Builtin::FirstTSBuiltin;
----------------
I would prefer the more verbose `isTargetBuiltin` or `isTargetSpecificBuiltin` -- I don't think it will be obvious at call sites what this does if we use this abbreviation in the public interface.

================
Comment at: lib/Sema/SemaExprCXX.cpp:2259
@@ -2258,1 +2258,3 @@
 
+  // Filter out unsuitable CUDA functions.
+  if (getLangOpts().CUDA) {
----------------
I don't see any test coverage for this; please add some tests that declare usual deallocation functions with CUDA host/device attributes and check that they behave as expected.

================
Comment at: lib/Sema/SemaExprCXX.cpp:2276
@@ +2275,3 @@
+        Matches[I] = Matches[--N];
+        Matches.set_size(N);
+      } else {
----------------
Use `resize`, not `set_size`.

================
Comment at: lib/Sema/SemaOverload.cpp:10119-10143
@@ -10102,1 +10118,27 @@
 
+  void EliminateSuboptimalCudaMatches() {
+    assert(S.getLangOpts().CUDATargetOverloads &&
+           "Should not be called w/o enabled target overloads.");
+
+    // Find the best call preference among the functions in Matches.
+    FunctionDecl *Caller = dyn_cast<FunctionDecl>(S.CurContext);
+    Sema::CUDAFunctionPreference BestCFP = Sema::CFP_Never;
+    for (auto const& Match: Matches) {
+      Sema::CUDAFunctionPreference P =
+          S.IdentifyCUDAPreference(Caller, Match.second);
+      if (P > BestCFP)
+        BestCFP = P;
+    }
+
+    assert(BestCFP != Sema::CFP_Never && "No usable CUDA functions.");
+    // If any suitable functions found, remove all items that are
+    // *not* suitable.
+    for (unsigned I = 0, N = Matches.size(); I != N;)
+      if (S.IdentifyCUDAPreference(Caller, Matches[I].second) != BestCFP) {
+        Matches[I] = Matches[--N];
+        Matches.set_size(N);
+      } else {
+        ++I;
+      }
+  }
+
----------------
Please factor out the common code shared by this and `FindUsualDeallocationFunction`.


http://reviews.llvm.org/D12453





More information about the cfe-commits mailing list