Skip to content

Commit 0bdd896

Browse files
committed
Revert "[CIR][HIP] Use CUDA attributes for HIP global functions (#1333)"
Broke CI jobs This reverts commit db307ce.
1 parent db307ce commit 0bdd896

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,9 +2357,8 @@ cir::FuncOp CIRGenModule::GetAddrOfFunction(clang::GlobalDecl GD, mlir::Type Ty,
23572357
// As __global__ functions (kernels) always reside on device,
23582358
// when we access them from host, we must refer to the kernel handle.
23592359
// For CUDA, it's just the device stub. For HIP, it's something different.
2360-
if ((langOpts.CUDA || langOpts.HIP) && !langOpts.CUDAIsDevice &&
2361-
cast<FunctionDecl>(GD.getDecl())->hasAttr<CUDAGlobalAttr>() &&
2362-
cast<FunctionDecl>(GD.getDecl())->isThisDeclarationADefinition()) {
2360+
if (langOpts.CUDA && !langOpts.CUDAIsDevice && langOpts.HIP &&
2361+
cast<FunctionDecl>(GD.getDecl())->hasAttr<CUDAGlobalAttr>()) {
23632362
llvm_unreachable("NYI");
23642363
}
23652364

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "../Inputs/cuda.h"
2+
3+
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip -fcuda-is-device \
4+
// RUN: -fclangir -emit-cir -o - %s | FileCheck %s
5+
6+
// This shouldn't emit.
7+
__host__ void host_fn(int *a, int *b, int *c) {}
8+
9+
// CHECK-NOT: cir.func @_Z7host_fnPiS_S_
10+
11+
// This should emit as a normal C++ function.
12+
__device__ void device_fn(int* a, double b, float c) {}
13+
14+
// CIR: cir.func @_Z9device_fnPidf

clang/test/CIR/CodeGen/HIP/simple.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
#include "../Inputs/cuda.h"
22

3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \
4-
// RUN: -x hip -emit-cir %s -o %t.cir
5-
// RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip -fclangir \
4+
// RUN: -emit-cir %s -o %t.cir
5+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
66

7-
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip \
8-
// RUN: -fcuda-is-device -emit-cir %s -o %t.cir
9-
// RUN: FileCheck --check-prefix=CIR-DEVICE --input-file=%t.cir %s
10-
11-
// Attribute for global_fn
12-
// CIR-HOST: [[Kernel:#[a-zA-Z_0-9]+]] = {{.*}}#cir.cuda_kernel_name<_Z9global_fnv>{{.*}}
137

8+
// This should emit as a normal C++ function.
149
__host__ void host_fn(int *a, int *b, int *c) {}
15-
// CIR-HOST: cir.func @_Z7host_fnPiS_S_
16-
// CIR-DEVICE-NOT: cir.func @_Z7host_fnPiS_S_
1710

18-
__device__ void device_fn(int *a, double b, float c) {}
19-
// CIR-HOST-NOT: cir.func @_Z9device_fnPidf
20-
// CIR-DEVICE: cir.func @_Z9device_fnPidf
11+
// CIR: cir.func @_Z7host_fnPiS_S_
2112

22-
#ifdef __AMDGPU__
23-
__global__ void global_fn() {}
24-
#else
25-
__global__ void global_fn();
26-
#endif
27-
// CIR-HOST: @_Z24__device_stub__global_fnv(){{.*}}extra([[Kernel]])
28-
// CIR-DEVICE: @_Z9global_fnv
13+
// This shouldn't emit.
14+
__device__ void device_fn(int* a, double b, float c) {}
2915

30-
// Make sure `global_fn` indeed gets emitted
31-
__host__ void x() { auto v = global_fn; }
16+
// CHECK-NOT: cir.func @_Z9device_fnPidf

0 commit comments

Comments
 (0)