================
@@ -1100,3 +1101,49 @@ std::string SemaCUDA::getConfigureFuncName() const {
   // Legacy CUDA kernel configuration call
   return "cudaConfigureCall";
 }
+
+// Record any local constexpr variables that are passed one way on the host
+// and another on the device.
+void SemaCUDA::recordPotentialODRUsedVariable(
+    MultiExprArg Arguments, OverloadCandidateSet &Candidates) {
+  sema::LambdaScopeInfo *LambdaInfo = SemaRef.getCurLambda();
+  if (!LambdaInfo)
+    return;
+
+  for (unsigned I = 0; I < Arguments.size(); ++I) {
+    auto *DeclRef = dyn_cast<DeclRefExpr>(Arguments[I]);
+    if (!DeclRef)
+      continue;
+    auto *Variable = dyn_cast<VarDecl>(DeclRef->getDecl());
+    if (!Variable || !Variable->isLocalVarDecl() || !Variable->isConstexpr())
+      continue;
+
+    bool HostByValue = false, HostByRef = false;
+    bool DeviceByValue = false, DeviceByRef = false;
+
+    for (OverloadCandidate &Candidate : Candidates) {
+      FunctionDecl *Callee = Candidate.Function;
+      if (!Callee || I >= Callee->getNumParams())
+        continue;
+
+      CUDAFunctionTarget Target = IdentifyTarget(Callee);
+      if (Target == CUDAFunctionTarget::InvalidTarget ||
+          Target == CUDAFunctionTarget::Global)
+        continue;
+
+      bool CoversHost = (Target == CUDAFunctionTarget::Host ||
+                         Target == CUDAFunctionTarget::HostDevice);
+      bool CoversDevice = (Target == CUDAFunctionTarget::Device ||
+                           Target == CUDAFunctionTarget::HostDevice);
+
+      bool IsRef = Callee->getParamDecl(I)->getType()->isReferenceType();
+      if (CoversHost)
+        IsRef ? HostByRef = true : HostByValue = true;
+      if (CoversDevice)
+        IsRef ? DeviceByRef = true : DeviceByValue = true;
----------------
Artem-B wrote:

Can't say I'm a big fan of assignments inside of a ternary. 

In this case, i'd bypass all the conditionals altogether and just initialize 
all variables:
```
bool HostByValue = CoversHost && !IsRef, 
bool HostByRef = CoversHost && IsRef;
bool DeviceByValue = CoversDevice && !IsRef;
bool DeviceByRef = CoversDevice && IsRef;
```

https://github.com/llvm/llvm-project/pull/136645
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to