Author: quic-k
Date: 2026-05-08T09:48:46-05:00
New Revision: b9d50a8e952a6e9c48f884c41ea0c5d4aae854aa

URL: 
https://github.com/llvm/llvm-project/commit/b9d50a8e952a6e9c48f884c41ea0c5d4aae854aa
DIFF: 
https://github.com/llvm/llvm-project/commit/b9d50a8e952a6e9c48f884c41ea0c5d4aae854aa.diff

LOG: [Clang][Hexagon] Add H2 as recognized OS in target triple (#195621)

H2 (Hexagon Hypervisor) is an open-source lightweight OS/hypervisor
for the Qualcomm Hexagon processor family that supports running
multiple guest operating systems concurrently via hardware
virtualization. It is available at:
  https://github.com/qualcomm/hexagon-hypervisor

Since there is currently no open-source toolchain for Hexagon, H2
provides a path toward building one — making Clang/LLVM support
for H2 an important step in enabling an open-source Hexagon
development ecosystem.

Signed-off-by: Kushal Pal <[email protected]>

Added: 
    

Modified: 
    clang/lib/Basic/Targets.cpp
    clang/lib/Basic/Targets/OSTargets.h
    clang/test/Preprocessor/hexagon-predefines.c
    llvm/include/llvm/TargetParser/Triple.h
    llvm/lib/TargetParser/Triple.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 4c6d900d88980..ed88ae7173bad 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 235004d69c5cc..0fc387c90b280 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -1099,6 +1099,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);
 }
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to