[HIPIFY][CUB][#1460] Add "using namespace cub" translation support

+ Add cub_03.cu
This commit is contained in:
Evgeny Mankov
2019-10-18 18:51:40 +03:00
orang tua f0ed210b19
melakukan 98874c0e7f
3 mengubah file dengan 57 tambahan dan 0 penghapusan
+19
Melihat File
@@ -63,6 +63,7 @@ const StringRef sCudaHostFuncCall = "cudaHostFuncCall";
const StringRef sCudaDeviceFuncCall = "cudaDeviceFuncCall";
const StringRef sCubNamespacePrefix = "cubNamespacePrefix";
const StringRef sCubFunctionTemplateDecl = "cubFunctionTemplateDecl";
const StringRef sCubUsingNamespaceDecl = "cubUsingNamespaceDecl";
std::set<std::string> DeviceSymbolFunctions0 {
{sCudaMemcpyToSymbol},
@@ -472,6 +473,16 @@ bool HipifyAction::cubNamespacePrefix(const mat::MatchFinder::MatchResult &Resul
return false;
}
bool HipifyAction::cubUsingNamespaceDecl(const mat::MatchFinder::MatchResult &Result) {
if (auto *decl = Result.Nodes.getNodeAs<clang::UsingDirectiveDecl>(sCubUsingNamespaceDecl)) {
if (auto nsd = decl->getNominatedNamespace()) {
FindAndReplace(nsd->getDeclName().getAsString(), decl->getIdentLocation(), CUDA_CUB_TYPE_NAME_MAP);
return true;
}
}
return false;
}
bool HipifyAction::cubFunctionTemplateDecl(const mat::MatchFinder::MatchResult &Result) {
if (auto *decl = Result.Nodes.getNodeAs<clang::FunctionTemplateDecl>(sCubFunctionTemplateDecl)) {
auto *Tparams = decl->getTemplateParameters();
@@ -611,6 +622,13 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
).bind(sCubFunctionTemplateDecl),
this
);
// TODO: Maybe worth to make it more concrete
Finder->addMatcher(
mat::usingDirectiveDecl(
mat::isExpansionInMainFile()
).bind(sCubUsingNamespaceDecl),
this
);
// Ownership is transferred to the caller.
return Finder->newASTConsumer();
}
@@ -725,4 +743,5 @@ void HipifyAction::run(const mat::MatchFinder::MatchResult &Result) {
if (cudaDeviceFuncCall(Result)) return;
if (cubNamespacePrefix(Result)) return;
if (cubFunctionTemplateDecl(Result)) return;
if (cubUsingNamespaceDecl(Result)) return;
}