Skip to content

Commit 6d208a4

Browse files
authored
[SYCLomatic] Don't migrate API defined by user and refine unresolved decl API migration (#2781)
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent f762d91 commit 6d208a4

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

clang/lib/DPCT/RuleInfra/CallExprRewriterCommon.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,16 @@ class IsDefinedInCUDA {
21322132
return isFromCUDA(FD);
21332133
}
21342134
};
2135+
class IsDefinedByUser {
2136+
public:
2137+
IsDefinedByUser() {}
2138+
bool operator()(const CallExpr *C) {
2139+
auto FD = C->getDirectCallee();
2140+
if (!FD)
2141+
return false;
2142+
return DpctGlobalInfo::isInRoot(FD->getLocation());
2143+
}
2144+
};
21352145
} // namespace math
21362146
} // namespace dpct
21372147

clang/lib/DPCT/RulesLang/Math/CallExprRewriterMath.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -388,29 +388,29 @@ class MathRewriterFactory final : public CallExprRewriterFactoryBase {
388388
return Rewriter.value();
389389
}
390390
}
391-
if (math::IsUnresolvedLookupExpr(C)) {
392-
if (math::IsDirectCallerPureDevice(C)) {
393-
if (Rewriter = getDeviceRewriter(C))
394-
return Rewriter.value();
395-
}
396-
}
397391
if (math::IsDefinedInCUDA()(C)) {
398392
if (Rewriter = getDeviceRewriter(C))
399393
return Rewriter.value();
400394
}
401395
}
402-
403-
// Host and device
404-
if (HostDeviceRewriter && HostDeviceRewriter.value().first(C))
405-
return HostDeviceRewriter.value().second.second->create(C);
406-
407-
if (EmulationRewriter && EmulationRewriter.value().first(C))
408-
return EmulationRewriter.value().second.second->create(C);
409-
410-
if (UnsupportedWarningRewriter &&
411-
UnsupportedWarningRewriter.value().first(C))
412-
return UnsupportedWarningRewriter.value().second.second->create(C);
413-
396+
if (math::IsUnresolvedLookupExpr(C)) {
397+
if (math::IsDirectCallerPureDevice(C)) {
398+
if (auto Rewriter = getDeviceRewriter(C))
399+
return Rewriter.value();
400+
} else if (math::IsDirectCallerPureHost(C)) {
401+
return NoRewriteRewriter.value().second.second->create(C);
402+
}
403+
}
404+
if (!math::IsDefinedByUser()(C)) {
405+
// Host and device
406+
if (HostDeviceRewriter && HostDeviceRewriter.value().first(C))
407+
return HostDeviceRewriter.value().second.second->create(C);
408+
if (EmulationRewriter && EmulationRewriter.value().first(C))
409+
return EmulationRewriter.value().second.second->create(C);
410+
if (UnsupportedWarningRewriter &&
411+
UnsupportedWarningRewriter.value().first(C))
412+
return UnsupportedWarningRewriter.value().second.second->create(C);
413+
}
414414
return NoRewriteRewriter.value().second.second->create(C);
415415
}
416416
};

clang/test/dpct/math/cuda-math-intrinsics.cu

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,3 +3550,36 @@ __global__ void foo9(float aa) {
35503550
::cospif(aa);
35513551
}
35523552

3553+
inline __host__ __device__ float4 operator-(float b, float4 a) {
3554+
return make_float4(b - a.x, b - a.y, b - a.z, b - a.w);
3555+
}
3556+
3557+
inline __host__ __device__ float4 fabs(float4 v) {
3558+
return make_float4(fabs(v.x), fabs(v.y), fabs(v.z), fabs(v.w));
3559+
}
3560+
3561+
__device__ void foo10(float4 a, float b) {
3562+
// CHECK: sycl::float4 c = fabs(dpct_operator_overloading::operator-(b , a));
3563+
float4 c = fabs(b - a);
3564+
}
3565+
3566+
// CHECK: template <typename T> class AAA_st {
3567+
// CHECK-NEXT: struct BBB_st {
3568+
// CHECK-NEXT: float f;
3569+
// CHECK-NEXT: };
3570+
// CHECK-NEXT: int foo() {
3571+
// CHECK-NEXT: BBB_st *ptr = new BBB_st;
3572+
// CHECK-NEXT: fabs(ptr->f);
3573+
// CHECK-NEXT: return 0;
3574+
// CHECK-NEXT: }
3575+
// CHECK-NEXT: };
3576+
template <typename T> class AAA_st {
3577+
struct BBB_st {
3578+
float f;
3579+
};
3580+
int foo() {
3581+
BBB_st *ptr = new BBB_st;
3582+
fabs(ptr->f);
3583+
return 0;
3584+
}
3585+
};

0 commit comments

Comments
 (0)