[clang] [NFC][clang][Driver] Move normalizeForBundler to OffloadBundler for r… (PR #225049)

Aditya Sinha via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 21 02:09:35 PDT 2026


https://github.com/AdityaSinha149 created https://github.com/llvm/llvm-project/pull/225049

This PR is a prerequisite for #218337. It moved the function `normaliseForBundler` from `HIPUtility.cpp` to `OffloadBundler` so that it can be shared by both AOT compiler and clang-repl. There are no functional changes.

>From fd688877b4c24747ad5e69d8ae2ebf442046ecb9 Mon Sep 17 00:00:00 2001
From: AdityaSinha149 <adsinha at amd.com>
Date: Mon, 21 Sep 2026 14:33:02 +0530
Subject: [PATCH] [NFC][clang][Driver] Move normalizeForBundler to
 OffloadBundler for reuse

---
 clang/include/clang/Driver/OffloadBundler.h |  2 ++
 clang/lib/Driver/OffloadBundler.cpp         |  8 ++++++++
 clang/lib/Driver/ToolChains/HIPUtility.cpp  | 10 +---------
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Driver/OffloadBundler.h b/clang/include/clang/Driver/OffloadBundler.h
index 96839240543af..8cc93e051320c 100644
--- a/clang/include/clang/Driver/OffloadBundler.h
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -96,6 +96,8 @@ struct OffloadTargetInfo {
 /// <kind>-<triple>[-<target id>[:target features]]
 /// <triple> := <arch>-<vendor>-<os>-<env>
 bool checkOffloadBundleID(const llvm::StringRef Str);
+/// Constructs the normalized triple string used in an offload bundle entry ID.
+std::string normalizeForBundler(const llvm::Triple &T, bool HasTargetID);
 } // namespace clang
 
 #endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index b397ee4c5b075..2f69b45ede9ff 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -1750,3 +1750,11 @@ bool clang::checkOffloadBundleID(const llvm::StringRef Str) {
   Str.split(Components, '-', /*MaxSplit=*/5);
   return Components.size() == 5 || Components.size() == 6;
 }
+
+std::string clang::normalizeForBundler(const llvm::Triple &T,
+                                       bool HasTargetID) {
+  return HasTargetID ? (T.getArchName() + "-" + T.getVendorName() + "-" +
+                        T.getOSName() + "-" + T.getEnvironmentName())
+                           .str()
+                     : T.normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
+}
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 001f9f3400a06..6a0c20ffe1257 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -9,6 +9,7 @@
 #include "HIPUtility.h"
 #include "clang/Driver/CommonArgs.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "clang/Options/Options.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -38,15 +39,6 @@ namespace {
 const unsigned HIPCodeObjectAlign = 4096;
 } // namespace
 
-// Constructs a triple string for clang offload bundler.
-static std::string normalizeForBundler(const llvm::Triple &T,
-                                       bool HasTargetID) {
-  return HasTargetID ? (T.getArchName() + "-" + T.getVendorName() + "-" +
-                        T.getOSName() + "-" + T.getEnvironmentName())
-                           .str()
-                     : T.normalize(llvm::Triple::CanonicalForm::FOUR_IDENT);
-}
-
 // Collect undefined __hip_fatbin* and __hip_gpubin_handle* symbols from all
 // input object or archive files.
 class HIPUndefinedFatBinSymbols {



More information about the cfe-commits mailing list