Merge pull request #307 from emankov/issue_306

[HIPIFY][FIX][#306] Eliminate second cuda main include directive
This commit is contained in:
Evgeny Mankov
2018-01-10 22:50:44 +03:00
zatwierdzone przez GitHub
3 zmienionych plików z 25 dodań i 10 usunięć
+13 -10
Wyświetl plik
@@ -157,11 +157,11 @@ void HipifyAction::InclusionDirective(clang::SourceLocation hash_loc,
} }
// Special-casing to avoid duplication of the hip_runtime include. // Special-casing to avoid duplication of the hip_runtime include.
bool secondMainInclude = false;
if (found->second.hipName == "hip/hip_runtime.h") { if (found->second.hipName == "hip/hip_runtime.h") {
if (insertedRuntimeHeader) { if (insertedRuntimeHeader) {
return; secondMainInclude = true;
} }
insertedRuntimeHeader = true; insertedRuntimeHeader = true;
} }
@@ -169,24 +169,27 @@ void HipifyAction::InclusionDirective(clang::SourceLocation hash_loc,
clang::SourceLocation sl = filename_range.getBegin(); clang::SourceLocation sl = filename_range.getBegin();
if (found->second.unsupported) { if (found->second.unsupported) {
// An unsupported CUDA header? Oh dear. Print a warning.
clang::DiagnosticsEngine& DE = getCompilerInstance().getDiagnostics(); clang::DiagnosticsEngine& DE = getCompilerInstance().getDiagnostics();
DE.Report(sl, DE.getCustomDiagID(clang::DiagnosticsEngine::Warning, "Unsupported CUDA header")); DE.Report(sl, DE.getCustomDiagID(clang::DiagnosticsEngine::Warning, "Unsupported CUDA header"));
return; return;
} }
const char *B = SM.getCharacterData(sl);
const char *E = SM.getCharacterData(filename_range.getEnd());
clang::SmallString<128> includeBuffer;
clang::StringRef newInclude; clang::StringRef newInclude;
// Keep the same include type that the user gave. // Keep the same include type that the user gave.
if (is_angled) { if (!secondMainInclude) {
newInclude = llvm::Twine("<" + found->second.hipName + ">").toStringRef(includeBuffer); clang::SmallString<128> includeBuffer;
if (is_angled) {
newInclude = llvm::Twine("<" + found->second.hipName + ">").toStringRef(includeBuffer);
} else {
newInclude = llvm::Twine("\"" + found->second.hipName + "\"").toStringRef(includeBuffer);
}
} else { } else {
newInclude = llvm::Twine("\"" + found->second.hipName + "\"").toStringRef(includeBuffer); // hashLoc is location of the '#', thus replacing the whole include directive by empty newInclude starting with '#'.
sl = hash_loc;
} }
const char *B = SM.getCharacterData(sl);
const char *E = SM.getCharacterData(filename_range.getEnd());
ct::Replacement Rep(SM, sl, E - B, newInclude); ct::Replacement Rep(SM, sl, E - B, newInclude);
insertReplacement(Rep, clang::FullSourceLoc{sl, SM}); insertReplacement(Rep, clang::FullSourceLoc{sl, SM});
} }
@@ -0,0 +1,6 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include <hip/hip_runtime.h>
#include <cuda.h>
// CHECK-NOT: #include<cuda_runtime.h>
#include <cuda_runtime.h>
@@ -0,0 +1,6 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include <hip/hip_runtime.h>
#include <cuda_runtime.h>
// CHECK-NOT: #include<cuda.h>
#include <cuda.h>