From 31dfd8bb1fdfd66a56119feeb79ba75b077349ff Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Mon, 13 Feb 2017 18:13:49 +0300 Subject: [PATCH] [HIPIFY] Minor refactoring + insertHipHeaders function is added to Cuda2Hip class; + fix replacement ending for hip header. [ROCm/hip commit: c3ab4d5c5eb0ba90171154d4972b8be1737c6a27] --- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 468b42297c..cf9eae51b7 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -1711,6 +1711,17 @@ protected: // llvm::outs() << " [HIPIFY] expansion line num: " << fullSL.getExpansionLineNumber() << " for replacement '" << rep.getReplacementText() << "'\n"; } } + void insertHipHeaders(Cuda2Hip *owner, const SourceManager &SM) { + if (owner->countReps[CONV_INCLUDE_CUDA_MAIN_H] == 0 && countReps[CONV_INCLUDE_CUDA_MAIN_H] == 0 && Replace->size() > 0) { + std::string repName = "#include "; + hipCounter counter = { repName, CONV_INCLUDE_CUDA_MAIN_H, API_RUNTIME }; + updateCounters(counter, repName); + SourceLocation sl = SM.getLocForStartOfFile(SM.getMainFileID()); + FullSourceLoc fullSL(sl, SM); + Replacement Rep(SM, sl, 0, repName + "\n"); + insertReplacement(Rep, fullSL); + } + } void updateCountersExt(const hipCounter &counter, const std::string &cudaName) { std::map *map = &cuda2hipConverted; @@ -2464,17 +2475,7 @@ public: if (unresolvedTemplateName(Result)) break; break; } while (false); - if (PP->countReps[CONV_INCLUDE_CUDA_MAIN_H] == 0 && - countReps[CONV_INCLUDE_CUDA_MAIN_H] == 0 && Replace->size() > 0) { - StringRef repName = "#include \n"; - SourceManager *SM = Result.SourceManager; - SourceLocation sl = SM->getLocForStartOfFile(SM->getMainFileID()); - Replacement Rep(*SM, sl, 0, repName); - FullSourceLoc fullSL(sl, *SM); - insertReplacement(Rep, fullSL); - hipCounter counter = { repName, CONV_INCLUDE_CUDA_MAIN_H, API_RUNTIME }; - updateCounters(counter, repName); - } + insertHipHeaders(PP, *Result.SourceManager); } private: @@ -2483,16 +2484,7 @@ private: }; void HipifyPPCallbacks::handleEndSource() { - if (Match->countReps[CONV_INCLUDE_CUDA_MAIN_H] == 0 && - countReps[CONV_INCLUDE_CUDA_MAIN_H] == 0 && Replace->size() > 0) { - StringRef repName = "#include \n"; - SourceLocation sl = _sm->getLocForStartOfFile(_sm->getMainFileID()); - Replacement Rep(*_sm, sl, 0, repName); - FullSourceLoc fullSL(sl, *_sm); - insertReplacement(Rep, fullSL); - hipCounter counter = { repName, CONV_INCLUDE_CUDA_MAIN_H, API_RUNTIME }; - updateCounters(counter, repName); - } + insertHipHeaders(Match, *_sm); } } // end anonymous namespace