diff options
Diffstat (limited to 'clang/lib/Sema/SemaCUDA.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCUDA.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index d6c0606674e..827eb02bcd6 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -158,6 +158,34 @@ Sema::IdentifyCUDAPreference(const FunctionDecl *Caller, llvm_unreachable("All cases should've been handled by now."); } +void Sema::EraseUnwantedCUDAMatches(const FunctionDecl *Caller, + LookupResult &R) { + if (R.isSingleResult()) + return; + + // Gets the CUDA function preference for a call from Caller to Match. + auto GetCFP = [&](const NamedDecl *D) { + if (auto *Callee = dyn_cast<FunctionDecl>(D->getUnderlyingDecl())) + return IdentifyCUDAPreference(Caller, Callee); + return CFP_Never; + }; + + // Find the best call preference among the functions in R. + CUDAFunctionPreference BestCFP = GetCFP(*std::max_element( + R.begin(), R.end(), [&](const NamedDecl *D1, const NamedDecl *D2) { + return GetCFP(D1) < GetCFP(D2); + })); + + // Erase all functions with lower priority. + auto Filter = R.makeFilter(); + while (Filter.hasNext()) { + auto *Callee = dyn_cast<FunctionDecl>(Filter.next()->getUnderlyingDecl()); + if (Callee && GetCFP(Callee) < BestCFP) + Filter.erase(); + } + Filter.done(); +} + template <typename T> static void EraseUnwantedCUDAMatchesImpl( Sema &S, const FunctionDecl *Caller, llvm::SmallVectorImpl<T> &Matches, |