================
@@ -219,10 +219,17 @@ void NVPTXABIInfo::computeInfo(CGFunctionInfo &FI) const {
   if (!getCXXABI().classifyReturnType(FI))
     FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
 
-  for (auto &&[ArgumentsCount, I] : llvm::enumerate(FI.arguments()))
-    I.info = ArgumentsCount < FI.getNumRequiredArgs()
-                 ? classifyArgumentType(I.type)
-                 : ABIArgInfo::getDirect();
+  for (auto &&[ArgumentsCount, I] : llvm::enumerate(FI.arguments())) {
+    if (FI.isGridConstantArg(ArgumentsCount))
+      // NVVM represents grid-constant parameter objects as byval pointers,
+      // even when their source type is a scalar or vector.
+      I.info = getNaturalAlignIndirect(
+          I.type, getDataLayout().getAllocaAddrSpace(), /*byval=*/true);
+    else
+      I.info = ArgumentsCount < FI.getNumRequiredArgs()
+                   ? classifyArgumentType(I.type)
+                   : ABIArgInfo::getDirect();
+  }
----------------
Artem-B wrote:

Two things here:

1. Bypassing `classifyArgumentType()` skips the 
`isCUDADeviceBuiltinSurfaceType()` / `isCUDADeviceBuiltinTextureType()` 
handling in `classifyArgumentType()`, which needs to keep those types as direct 
`i64` device handles rather than `byval` structs. Passing `bool IsGridConstant 
= false` into `classifyArgumentType()` keeps all argument classification in one 
place and preserves `tex`/`surf` lowering:

```cpp
if (isAggregateTypeForABI(Ty) || IsGridConstant) {
  if (getContext().getLangOpts().CUDAIsDevice) {
    if (Ty->isCUDADeviceBuiltinSurfaceType())
      return ABIArgInfo::getDirect(
          CGInfo.getCUDADeviceBuiltinSurfaceDeviceType());
    if (Ty->isCUDADeviceBuiltinTextureType())
      return ABIArgInfo::getDirect(
          CGInfo.getCUDADeviceBuiltinTextureDeviceType());
  }
  return getNaturalAlignIndirect(
      Ty, /* AddrSpace */ getDataLayout().getAllocaAddrSpace(),
      /* byval */ true);
}
```

2. Please drop the mention of NVVM in the comment—NVVM is NVCC's IR, not why 
Clang/NVPTX makes this choice. The comment should explain it in terms of the 
parameter's properties, e.g.:

```cpp
// Grid-constant kernel parameters must keep their parameter-space address
// instead of being copied to a local alloca, so pass them as byval pointers
// even for scalar and vector types.
```

https://github.com/llvm/llvm-project/pull/231567
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to