Skip to content

Commit 6355985

Browse files
authored
[SYCLomatic][BUG] Migrate "cuda::std::" namespace to "std::" (#2823)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com>
1 parent 9d716ba commit 6355985

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

clang/lib/DPCT/RuleInfra/ExprAnalysis.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,16 @@ bool isCGAPI(std::string Name) {
495495
return MapNamesLang::CooperativeGroupsAPISet.count(Name);
496496
}
497497

498+
void ExprAnalysis::analyzeExpr(const DependentScopeDeclRefExpr *DRE) {
499+
std::string Result;
500+
llvm::raw_string_ostream OS(Result);
501+
DRE->getQualifier()->dump(OS);
502+
std::string cuda_std_prefix = "cuda::std::";
503+
if (Result.find(cuda_std_prefix) == 0) {
504+
addReplacement(DRE->getBeginLoc(), cuda_std_prefix.length(), "std::");
505+
}
506+
}
507+
498508
void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
499509
std::string CTSName;
500510
auto Qualifier = DRE->getQualifier();

clang/lib/DPCT/RuleInfra/ExprAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ class ExprAnalysis {
621621
}
622622

623623
inline void analyzeExpr(const DeclRefExpr *DRE);
624-
624+
inline void analyzeExpr(const DependentScopeDeclRefExpr *DRE);
625625
inline void analyzeExpr(const ParenExpr *PE) { dispatch(PE->getSubExpr()); }
626626

627627
inline void analyzeExpr(const ArraySubscriptExpr *ASE) {

clang/lib/DPCT/RulesLangLib/LIBCUAPIMigration.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ void LIBCURule::registerMatcher(ast_matchers::MatchFinder &MF) {
4848
.bind("MemberCall"),
4949
this);
5050
}
51-
51+
{
52+
MF.addMatcher(dependentScopeDeclRefExpr().bind("DependentScope"),
53+
this);
54+
}
5255
{
5356
auto LIBCUTypesNames = [&]() {
5457
return hasAnyName("atomic", "cuda::std::complex", "cuda::std::array",
@@ -76,6 +79,12 @@ void LIBCURule::registerMatcher(ast_matchers::MatchFinder &MF) {
7679

7780
void LIBCURule::runRule(const ast_matchers::MatchFinder::MatchResult &Result) {
7881
ExprAnalysis EA;
82+
if (const auto *DSDRE =
83+
getNodeAsType<DependentScopeDeclRefExpr>(Result, "DependentScope")) {
84+
EA.analyze(DSDRE);
85+
emplaceTransformation(EA.getReplacement());
86+
EA.applyAllSubExprRepl();
87+
}
7988
if (const CXXMemberCallExpr *MC =
8089
getNodeAsType<CXXMemberCallExpr>(Result, "MemberCall")) {
8190
EA.analyze(MC);

clang/test/dpct/LibCU/libcu_num.cu

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// UNSUPPORTED: v7.0, v7.5, v8.0, v9.0, v9.2, v10.0
2+
// UNSUPPORTED: cuda-7.0, cuda-7.5, cuda-8.0, cuda-9.0, cuda-9.2, cuda-10.0
3+
// RUN: dpct --format-range=none -in-root %S -out-root %T/Libcu %S/libcu_num.cu --cuda-include-path="%cuda-path/include" -- -std=c++14 -x cuda --cuda-host-only
4+
// RUN: FileCheck --input-file %T/Libcu/libcu_num.dp.cpp --match-full-lines %s
5+
// RUN: %if build_lit %{icpx -c -fsycl %T/Libcu/libcu_num.dp.cpp -o %T/Libcu/libcu_num.dp.o %}
6+
7+
#include <cuda/std/climits>
8+
#include <cuda/std/type_traits>
9+
#include <cuda/std/limits>
10+
#include <cuda/std/tuple>
11+
12+
#include <iostream>
13+
template <typename T> T init_value() {
14+
//CHECK: return -std::numeric_limits<T>::infinity();
15+
return -cuda::std::numeric_limits<T>::infinity();
16+
}
17+
//CHECK: template <typename T> constexpr T terminate_value() { return std::numeric_limits<T>::infinity(); }
18+
template <typename T> constexpr T terminate_value() { return cuda::std::numeric_limits<T>::infinity(); }
19+
20+
template <class T> bool is_complete(const T &result) { return result != init_value<T>(); }
21+
22+
23+
int main() {
24+
std::cout << init_value<int>();
25+
return 0;
26+
}

0 commit comments

Comments
 (0)