Skip to content

Commit 96fb121

Browse files
authored
[SYCLomatic] Do not migrate user-defined API which has the same name as CUDA texture API (#2802)
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent 09cb6ea commit 96fb121

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

clang/lib/DPCT/RuleInfra/CallExprRewriterCommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ class IsDefinedByUser {
21412141
auto FD = C->getDirectCallee();
21422142
if (!FD)
21432143
return false;
2144-
return DpctGlobalInfo::isInRoot(FD->getLocation());
2144+
return isUserDefinedDecl(FD);
21452145
}
21462146
};
21472147
} // namespace math

clang/lib/DPCT/RulesLang/RulesLangTexture.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,12 @@ bool TextureRule::processTexVarDeclInDevice(const VarDecl *VD) {
780780
}
781781

782782
void TextureRule::runRule(const MatchFinder::MatchResult &Result) {
783-
784783
if (getAssistNodeAsType<UnresolvedLookupExpr>(Result,
785784
"unresolvedLookupExpr")) {
786785
const CallExpr *CE = getAssistNodeAsType<CallExpr>(Result, "callExpr");
786+
if (const auto *FD = CE->getDirectCallee())
787+
if (isUserDefinedDecl(FD))
788+
return;
787789
ExprAnalysis A;
788790
A.analyze(CE);
789791
emplaceTransformation(A.getReplacement());
@@ -932,7 +934,10 @@ void TextureRule::runRule(const MatchFinder::MatchResult &Result) {
932934
if (!ReplType.empty())
933935
emplaceTransformation(new ReplaceToken(TL->getBeginLoc(), TL->getEndLoc(),
934936
std::string(ReplType)));
935-
} else if (auto CE = getNodeAsType<CallExpr>(Result, "call")) {
937+
} else if (const auto *CE = getNodeAsType<CallExpr>(Result, "call")) {
938+
if (const auto *FD = CE->getDirectCallee())
939+
if (isUserDefinedDecl(FD))
940+
return;
936941
auto Name = CE->getDirectCallee()->getNameAsString();
937942
if (DpctGlobalInfo::useSYCLCompat()) {
938943
report(CE->getBeginLoc(), Diagnostics::UNSUPPORT_SYCLCOMPAT, false, Name);

clang/test/dpct/user_api/user_api.cu

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
// RUN: dpct --process-all -in-root %S --format-range=none -out-root %T/user_api %s --cuda-include-path="%cuda-path/include" --sycl-named-lambda -- -x cuda --cuda-host-only
2-
// RUN: FileCheck --match-full-lines --input-file %T/user_api/user_api.dp.cpp %s
3-
// RUN: %if build_lit %{icpx -c -fsycl %T/user_api/user_api.dp.cpp -o %T/user_api/user_api.dp.o %}
1+
// RUN: dpct --in-root %S --format-range=none --out-root %T %s --cuda-include-path="%cuda-path/include"
2+
// RUN: FileCheck --match-full-lines --input-file %T/user_api.dp.cpp %s
3+
// RUN: %if build_lit %{icpx -c -fsycl %T/user_api.dp.cpp -o %T/user_api.dp.o %}
44

55
// CHECK: #include <sycl/sycl.hpp>
66
// CHECK-NEXT: #include <dpct/dpct.hpp>
7-
// CHECK-NEXT: void create_maxpool_cudnn_tensors(){}
8-
// CHECK-NEXT: void foo(){
7+
#include <cuda.h>
8+
9+
// CHECK: void create_maxpool_cudnn_tensors() {}
10+
// CHECK-NEXT: void foo1() {
911
// CHECK-NEXT: create_maxpool_cudnn_tensors();
1012
// CHECK-NEXT: }
11-
#include <cuda.h>
12-
void create_maxpool_cudnn_tensors(){}
13-
void foo(){
13+
void create_maxpool_cudnn_tensors() {}
14+
void foo1() {
1415
create_maxpool_cudnn_tensors();
1516
}
1617

18+
void tex2D(int a, int b) {}
19+
void tex2D(int a, int b, int c) {}
20+
void tex3D(int a, int b, int c) {}
21+
22+
// CHECK: void foo2() {
23+
// CHECK-NEXT: tex2D(0, 0);
24+
// CHECK-NEXT: tex2D(0, 0, 0);
25+
// CHECK-NEXT: tex3D(0, 0, 0);
26+
// CHECK-NEXT: }
27+
void foo2() {
28+
tex2D(0, 0);
29+
tex2D(0, 0, 0);
30+
tex3D(0, 0, 0);
31+
}

0 commit comments

Comments
 (0)