[clang] [flang] [FLANG][MLIR][OpenMP] add MathToNVVM conversion pass to NVPTX MLIR (PR #180060)

Tarun Prabhu via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 08:46:51 PDT 2026


================
@@ -519,6 +520,41 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
   TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);
 }
 
+void Flang::AddNVPTXTargetArgs(const ArgList &Args,
+                               ArgStringList &CmdArgs) const {
+
+  // we cannot use addClangTargetOptions, as it appends unsupported args for
+  // flang: -fcuda-is-device, -fno-threadsafe-statics,
+  // -fcuda-allow-variadic-functions and -target-sdk-version Instead we manually
+  // detect the CUDA installation and link libdevice
+  const ToolChain &TC = getToolChain();
+  const Driver &D = TC.getDriver();
+  const llvm::Triple &Triple = TC.getEffectiveTriple();
+
+  if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true))
+    return;
+
+  // Detect CUDA installation and link libdevice
+  CudaInstallationDetector CudaInstallation(D, Triple, Args);
+  if (!CudaInstallation.isValid())
+    return;
----------------
tarunprabhu wrote:

What happens here is a valid cuda installation is not detected? Is there a failure later in the process, or does it gracefully fall back to some other behavior? If the former, we should probably raise an explicit error here. Something [like this](https://github.com/llvm/llvm-project/blob/ce227964cc4de126c43f3458498ac70315809ce8/clang/lib/Driver/ToolChains/Cuda.cpp#L311) perhaps?

https://github.com/llvm/llvm-project/pull/180060


More information about the cfe-commits mailing list