@@ -156,13 +156,13 @@ void IncludesCallbacks::insertCudaArchRepl(
156156 return;
157157}
158158
159- void IncludesCallbacks::ReplaceCuMacro(const Token &MacroNameTok) {
159+ bool IncludesCallbacks::ReplaceCuMacro(const Token &MacroNameTok) {
160160 bool IsInAnalysisScope = isInAnalysisScope(MacroNameTok.getLocation());
161161 if (!IsInAnalysisScope) {
162- return;
162+ return false ;
163163 }
164164 if (!MacroNameTok.getIdentifierInfo()) {
165- return;
165+ return false ;
166166 }
167167 std::string MacroName = MacroNameTok.getIdentifierInfo()->getName().str();
168168 auto Iter = MapNames::MacrosMap.find(MacroName);
@@ -175,14 +175,17 @@ void IncludesCallbacks::ReplaceCuMacro(const Token &MacroNameTok) {
175175 requestFeature(HelperFeatureEnum::Dpct_dpct_compatibility_temp,
176176 MacroNameTok.getLocation());
177177 insertCudaArchRepl(Repl->getReplacement(DpctGlobalInfo::getContext()));
178+ return true;
178179 }
179- return;
180+ return false ;
180181 }
181182 if (MacroName == "__CUDACC__" &&
182183 !MacroNameTok.getIdentifierInfo()->hasMacroDefinition())
183- return;
184+ return false ;
184185 TransformSet.emplace_back(Repl);
186+ return true;
185187 }
188+ return false;
186189}
187190
188191void IncludesCallbacks::MacroDefined(const Token &MacroNameTok,
@@ -396,29 +399,9 @@ void IncludesCallbacks::MacroExpands(const Token &MacroNameTok,
396399 if (!IsInAnalysisScope) {
397400 return;
398401 }
399-
400- if (MacroNameTok.getIdentifierInfo() &&
401- MacroNameTok.getIdentifierInfo()->getName() == "__CUDA_ARCH__") {
402- if (DpctGlobalInfo::getInstance().getContext().getLangOpts().CUDA) {
403- requestFeature(HelperFeatureEnum::Dpct_dpct_compatibility_temp,
404- Range.getBegin());
405- auto Repl = std::make_shared<ReplaceText>(Range.getBegin(), 13,
406- "DPCT_COMPATIBILITY_TEMP");
407- insertCudaArchRepl(Repl->getReplacement(DpctGlobalInfo::getContext()));
408- }
409- return;
410- }
411- // CUFFT_FORWARD and CUFFT_INVERSE are migrated to integer literal in all
412- // places except in cufftExec call.
413- // CUFFT_FORWARD and CUFFT_INVERSE in cufftExec call are migrated with
414- // FFTDirExpr and longer replacement will overlap shorter replacement, so the
415- // migration is expected.
416- else if (MacroNameTok.getIdentifierInfo() &&
417- MacroNameTok.getIdentifierInfo()->getName() == "CUFFT_FORWARD") {
418- TransformSet.emplace_back(new ReplaceText(Range.getBegin(), 13, "-1"));
419- } else if (MacroNameTok.getIdentifierInfo() &&
420- MacroNameTok.getIdentifierInfo()->getName() == "CUFFT_INVERSE") {
421- TransformSet.emplace_back(new ReplaceText(Range.getBegin(), 13, "1"));
402+
403+ if (ReplaceCuMacro(MacroNameTok)){
404+ return ;
422405 }
423406
424407 // For the un-specialized struct, there is no AST for the extern function
0 commit comments