[llvm] [OpenMPOpt] Initialize OpenMPIRBuilderConfig::IsGPU flag (PR #104456)

Sergio Afonso via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 03:28:31 PDT 2024


https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/104456

>From 57fc2335361f8d958527d1b02c6f120c0f7298ef Mon Sep 17 00:00:00 2001
From: Sergio Afonso <safonsof at amd.com>
Date: Thu, 15 Aug 2024 15:56:50 +0100
Subject: [PATCH] [OpenMPOpt] Initialize OpenMPIRBuilderConfig::IsGPU flag

This patch ensures the `IsGPU` flag is set by the OpenMPOpt pass, so that it
can be relied upon by `OpenMPIRBuilder` methods when called by that pass as
well.

Since currently there are very limited callers for the
`OpenMPIRBuilder::isGPU()` method, no assertions are being triggered by the
lack of initialization of this flag. However, when more offloading-related
features are implemented, it will eventually start happening.
---
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 7c1489f37049f0..cd94661bbe07f7 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -286,6 +286,19 @@ struct OMPInformationCache : public InformationCache {
         OpenMPPostLink(OpenMPPostLink) {
 
     OMPBuilder.Config.IsTargetDevice = isOpenMPDevice(OMPBuilder.M);
+    const Triple T(OMPBuilder.M.getTargetTriple());
+    switch (T.getArch()) {
+    case llvm::Triple::nvptx:
+    case llvm::Triple::nvptx64:
+    case llvm::Triple::amdgcn:
+      assert(OMPBuilder.Config.IsTargetDevice &&
+             "OpenMP AMDGPU/NVPTX is only prepared to deal with device code.");
+      OMPBuilder.Config.IsGPU = true;
+      break;
+    default:
+      OMPBuilder.Config.IsGPU = false;
+      break;
+    }
     OMPBuilder.initialize();
     initializeRuntimeFunctions(M);
     initializeInternalControlVars();



More information about the llvm-commits mailing list