[clang] [llvm] [Clang][Hexagon] Add H2 as recognized OS in target triple (PR #195621)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 4 02:26:36 PDT 2026
https://github.com/quic-k created https://github.com/llvm/llvm-project/pull/195621
similar to https://github.com/llvm/llvm-project/pull/183622
>From 3e393b467d01786c2048fcaccfbb28a3e0f00a06 Mon Sep 17 00:00:00 2001
From: Kushal Pal <kushpal at qti.qualcomm.com>
Date: Mon, 4 May 2026 14:54:20 +0530
Subject: [PATCH] [Clang][Hexagon] Add H2 as recognized OS in target triple
Add support for the H2 as a recognized OS type in the LLVM triple
system, and define the __h2__ predefined macro when targeting it.
Signed-off-by: Kushal Pal <kushpal at qti.qualcomm.com>
---
clang/lib/Basic/Targets.cpp | 2 ++
clang/lib/Basic/Targets/OSTargets.h | 13 +++++++++++++
clang/test/Preprocessor/hexagon-predefines.c | 6 ++++++
llvm/include/llvm/TargetParser/Triple.h | 6 +++++-
llvm/lib/TargetParser/Triple.cpp | 3 +++
5 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index d9cac93fd2906..6fab36b88067a 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -128,6 +128,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<LinuxTargetInfo<HexagonTargetInfo>>(Triple, Opts);
if (Triple.isOSQurt())
return std::make_unique<QURTTargetInfo<HexagonTargetInfo>>(Triple, Opts);
+ if (Triple.isOSH2())
+ return std::make_unique<H2TargetInfo<HexagonTargetInfo>>(Triple, Opts);
return std::make_unique<HexagonTargetInfo>(Triple, Opts);
case llvm::Triple::lanai:
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 9e2916eace079..28e3de2e7d20f 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -1104,6 +1104,19 @@ class LLVM_LIBRARY_VISIBILITY QURTTargetInfo : public OSTargetInfo<Target> {
using OSTargetInfo<Target>::OSTargetInfo;
};
+// H2 Target
+template <typename Target>
+class LLVM_LIBRARY_VISIBILITY H2TargetInfo : public OSTargetInfo<Target> {
+protected:
+ void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+ MacroBuilder &Builder) const override {
+ Builder.defineMacro("__h2__");
+ }
+
+public:
+ using OSTargetInfo<Target>::OSTargetInfo;
+};
+
// SerenityOS target
template <typename Target>
class LLVM_LIBRARY_VISIBILITY SerenityTargetInfo : public OSTargetInfo<Target> {
diff --git a/clang/test/Preprocessor/hexagon-predefines.c b/clang/test/Preprocessor/hexagon-predefines.c
index 7652e4169a63c..cb3e9492ea07e 100644
--- a/clang/test/Preprocessor/hexagon-predefines.c
+++ b/clang/test/Preprocessor/hexagon-predefines.c
@@ -255,3 +255,9 @@
// CHECK-QURT: #define __hexagon__ 1
// CHECK-QURT: #define __qurt__ 1
// CHECK-QURT-NOT: #define __linux__
+
+// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-h2 %s | FileCheck \
+// RUN: %s -check-prefix CHECK-H2
+// CHECK-H2: #define __h2__ 1
+// CHECK-H2: #define __hexagon__ 1
+// CHECK-H2-NOT: #define __linux__
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 6e26f14ab8448..d5a42d9646c18 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -260,7 +260,8 @@ class Triple {
ChipStar,
Firmware,
QURT,
- LastOSType = QURT
+ H2,
+ LastOSType = H2
};
enum EnvironmentType {
UnknownEnvironment,
@@ -774,6 +775,9 @@ class Triple {
/// Tests whether the OS is QURT.
bool isOSQurt() const { return getOS() == Triple::QURT; }
+ /// Tests whether the OS is H2.
+ bool isOSH2() const { return getOS() == Triple::H2; }
+
/// Tests whether the OS uses the ELF binary format.
bool isOSBinFormatELF() const { return getObjectFormat() == Triple::ELF; }
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 80f7ef063c908..c6515425b7eb5 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -495,6 +495,8 @@ StringRef Triple::getOSTypeName(OSType Kind) {
return "firmware";
case QURT:
return "qurt";
+ case H2:
+ return "h2";
}
llvm_unreachable("Invalid OSType");
@@ -965,6 +967,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("chipstar", Triple::ChipStar)
.StartsWith("firmware", Triple::Firmware)
.StartsWith("qurt", Triple::QURT)
+ .StartsWith("h2", Triple::H2)
.Default(Triple::UnknownOS);
}
More information about the llvm-commits
mailing list