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

Sergio Afonso via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 08:12:04 PDT 2024


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

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.

>From b223e08da93fa3f454b9214a0d58c2335f6eea63 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 798bcb77328fc8..8c2e8e50395108 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