Skip to content

Commit 1c729d7

Browse files
committed
[NVPTX] Use align attribute for kernel pointer arg alignment
Instead of determining the alignment based on the pointer element type (which is incompatible with opaque pointers), make use of alignment annotations added by the frontend. In particular, clang will add alignment attributes to OpenCL kernels since D118894. Other frontends might need to be adjusted to add the attribute as well. Differential Revision: https://reviews.llvm.org/D119247
1 parent ac0f329 commit 1c729d7

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,34 +1335,6 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar,
13351335
}
13361336
}
13371337

1338-
static unsigned int getOpenCLAlignment(const DataLayout &DL, Type *Ty) {
1339-
if (Ty->isSingleValueType())
1340-
return DL.getPrefTypeAlignment(Ty);
1341-
1342-
auto *ATy = dyn_cast<ArrayType>(Ty);
1343-
if (ATy)
1344-
return getOpenCLAlignment(DL, ATy->getElementType());
1345-
1346-
auto *STy = dyn_cast<StructType>(Ty);
1347-
if (STy) {
1348-
unsigned int alignStruct = 1;
1349-
// Go through each element of the struct and find the
1350-
// largest alignment.
1351-
for (unsigned i = 0, e = STy->getNumElements(); i != e; i++) {
1352-
Type *ETy = STy->getElementType(i);
1353-
unsigned int align = getOpenCLAlignment(DL, ETy);
1354-
if (align > alignStruct)
1355-
alignStruct = align;
1356-
}
1357-
return alignStruct;
1358-
}
1359-
1360-
auto *FTy = dyn_cast<FunctionType>(Ty);
1361-
if (FTy)
1362-
return DL.getPointerPrefAlignment().value();
1363-
return DL.getPrefTypeAlignment(Ty);
1364-
}
1365-
13661338
void NVPTXAsmPrinter::printParamName(Function::const_arg_iterator I,
13671339
int paramIndex, raw_ostream &O) {
13681340
getSymbol(I->getParent())->print(O, MAI);
@@ -1454,7 +1426,6 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) {
14541426

14551427
if (static_cast<NVPTXTargetMachine &>(TM).getDrvInterface() !=
14561428
NVPTX::CUDA) {
1457-
Type *ETy = PTy->getPointerElementType();
14581429
int addrSpace = PTy->getAddressSpace();
14591430
switch (addrSpace) {
14601431
default:
@@ -1470,7 +1441,8 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) {
14701441
O << ".ptr .global ";
14711442
break;
14721443
}
1473-
O << ".align " << (int)getOpenCLAlignment(DL, ETy) << " ";
1444+
Align ParamAlign = I->getParamAlign().valueOrOne();
1445+
O << ".align " << ParamAlign.value() << " ";
14741446
}
14751447
printParamName(I, paramIndex, O);
14761448
continue;

llvm/test/CodeGen/NVPTX/nvcl-param-align.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
target triple = "nvptx-unknown-nvcl"
44

5+
define void @foo(i64 %img, i64 %sampler, <5 x float>* align 32 %v1, i32* %v2) {
6+
; The parameter alignment is determined by the align attribute (default 1).
57
; CHECK-LABEL: .entry foo(
6-
define void @foo(i64 %img, i64 %sampler, <5 x float>* %v) {
7-
; The parameter alignment should be the next power of 2 of 5xsizeof(float),
8-
; which is 32.
98
; CHECK: .param .u32 .ptr .align 32 foo_param_2
9+
; CHECK: .param .u32 .ptr .align 1 foo_param_3
1010
ret void
1111
}
1212

1313
!nvvm.annotations = !{!1, !2, !3}
14-
!1 = !{void (i64, i64, <5 x float>*)* @foo, !"kernel", i32 1}
15-
!2 = !{void (i64, i64, <5 x float>*)* @foo, !"rdoimage", i32 0}
16-
!3 = !{void (i64, i64, <5 x float>*)* @foo, !"sampler", i32 1}
14+
!1 = !{void (i64, i64, <5 x float>*, i32*)* @foo, !"kernel", i32 1}
15+
!2 = !{void (i64, i64, <5 x float>*, i32*)* @foo, !"rdoimage", i32 0}
16+
!3 = !{void (i64, i64, <5 x float>*, i32*)* @foo, !"sampler", i32 1}

0 commit comments

Comments
 (0)