https://github.com/RossComputerGuy updated 
https://github.com/llvm/llvm-project/pull/120632

>From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.r...@midstall.com>
Date: Thu, 19 Dec 2024 10:54:58 -0800
Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64

---
 clang/lib/Basic/Targets/AArch64.cpp | 3 +++
 clang/lib/Basic/Targets/X86.h       | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 53e102bbe44687..dd5d033afd8763 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() {
       resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-"
                       "n32:64-S128-Fn32",
                       "_");
+  } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) {
+    resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-"
+                    "i64:64-i128:128-n32:64-S128-Fn32");
   } else
     resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
                     "i64:64-i128:128-n32:64-S128-Fn32");
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 3ed36c8fa724b5..1d6fe468af3be1 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
       : X86TargetInfo(Triple, Opts) {
     const bool IsX32 = getTriple().isX32();
-    bool IsWinCOFF =
-        getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+    bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) &&
+                     getTriple().isOSBinFormatCOFF();
     LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64;
     LongDoubleWidth = 128;
     LongDoubleAlign = 128;

>From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.r...@midstall.com>
Date: Thu, 19 Dec 2024 08:37:46 -0800
Subject: [PATCH 2/5] [clang] add __uefi__ define

---
 clang/lib/Basic/Targets/OSTargets.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index cd9b3760ca5874..24ffd542d664c7 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -790,7 +790,9 @@ template <typename Target>
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-                    MacroBuilder &Builder) const override {}
+                    MacroBuilder &Builder) const override {
+    DefineStd(Builder, "uefi", Opts);
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 370366fdcfa3f905a855e9f53e35014a15166150 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.r...@midstall.com>
Date: Thu, 19 Dec 2024 13:40:50 -0800
Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64

---
 clang/test/Preprocessor/init.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 05225c120b13de..8708b12e6cf0c5 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2742,3 +2742,10 @@
 // RISCV64-LINUX: #define __unix__ 1
 // RISCV64-LINUX: #define linux 1
 // RISCV64-LINUX: #define unix 1
+//
+// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck 
-match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck 
-match-full-lines -check-prefix UEFI %s
+//
+// UEFI: #define __uefi 1
+// UEFI: #define __uefi__ 1
+// UEFI: #define uefi 1

>From c7a6fcd9c8c99bcba6689d5dab270cd16f001764 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.r...@midstall.com>
Date: Thu, 19 Dec 2024 13:52:26 -0800
Subject: [PATCH 4/5] [clang] add uefi to target os macros

---
 clang/include/clang/Basic/TargetOSMacros.def | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
index 58dce330f9c8fd..f4f3276ad1c256 100644
--- a/clang/include/clang/Basic/TargetOSMacros.def
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
 TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
 TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
 
+// UEFI target.
+TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI())
+
 #undef TARGET_OS

>From 81cd003aac395e00e306623f45444052ec810e22 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.r...@midstall.com>
Date: Thu, 19 Dec 2024 14:13:09 -0800
Subject: [PATCH 5/5] [clang] use mixin for aarch64 and x86_64 uefi

---
 clang/lib/Basic/Targets.cpp         |  6 ++++-
 clang/lib/Basic/Targets/OSTargets.h | 13 +++++++++-
 clang/lib/Basic/Targets/X86.h       | 37 -----------------------------
 3 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 706a391023b3a3..1820e489c4446e 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -165,6 +165,10 @@ std::unique_ptr<TargetInfo> AllocateTarget(const 
llvm::Triple &Triple,
     case llvm::Triple::OpenBSD:
       return std::make_unique<OpenBSDTargetInfo<AArch64leTargetInfo>>(Triple,
                                                                       Opts);
+    case llvm::Triple::UEFI:
+      return std::make_unique<UEFITargetInfo<AArch64leTargetInfo>>(Triple,
+                                                                   Opts);
+
     case llvm::Triple::Win32:
       switch (Triple.getEnvironment()) {
       case llvm::Triple::GNU:
@@ -614,7 +618,7 @@ std::unique_ptr<TargetInfo> AllocateTarget(const 
llvm::Triple &Triple,
       return std::make_unique<SolarisTargetInfo<X86_64TargetInfo>>(Triple,
                                                                    Opts);
     case llvm::Triple::UEFI:
-      return std::make_unique<UEFIX86_64TargetInfo>(Triple, Opts);
+      return std::make_unique<UEFITargetInfo<X86_64TargetInfo>>(Triple, Opts);
 
     case llvm::Triple::Win32: {
       switch (Triple.getEnvironment()) {
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 24ffd542d664c7..eb6d557ccb45f6 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -13,6 +13,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
 
 #include "Targets.h"
+#include "clang/Basic/TargetInfo.h"
 
 namespace clang {
 namespace targets {
@@ -788,6 +789,8 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo<Target> {
 // UEFI target
 template <typename Target>
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
+  llvm::Triple Triple;
+
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     MacroBuilder &Builder) const override {
@@ -796,10 +799,18 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public 
OSTargetInfo<Target> {
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-      : OSTargetInfo<Target>(Triple, Opts) {
+      : OSTargetInfo<Target>(Triple, Opts), Triple(Triple) {
     this->WCharType = TargetInfo::UnsignedShort;
     this->WIntType = TargetInfo::UnsignedShort;
   }
+
+  TargetInfo::CallingConvKind
+  getCallingConvKind(bool ClangABICompat4) const override {
+    if (Triple.getArch() == llvm::Triple::x86_64)
+      return TargetInfo::CallingConvKind::CCK_MicrosoftWin64;
+
+    return Target::getCallingConvKind(ClangABICompat4);
+  }
 };
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1d6fe468af3be1..430254cbff57f1 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   }
 };
 
-// x86-64 UEFI target
-class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
-    : public UEFITargetInfo<X86_64TargetInfo> {
-public:
-  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
-      : UEFITargetInfo<X86_64TargetInfo>(Triple, Opts) {
-    this->TheCXXABI.set(TargetCXXABI::Microsoft);
-    this->MaxTLSAlign = 8192u * this->getCharWidth();
-    this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
-                          "i64:64-i128:128-f80:128-n8:16:32:64-S128");
-  }
-
-  void getTargetDefines(const LangOptions &Opts,
-                        MacroBuilder &Builder) const override {
-    getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
-  }
-
-  BuiltinVaListKind getBuiltinVaListKind() const override {
-    return TargetInfo::CharPtrBuiltinVaList;
-  }
-
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override 
{
-    switch (CC) {
-    case CC_C:
-    case CC_Win64:
-      return CCCR_OK;
-    default:
-      return CCCR_Warning;
-    }
-  }
-
-  TargetInfo::CallingConvKind
-  getCallingConvKind(bool ClangABICompat4) const override {
-    return CCK_MicrosoftWin64;
-  }
-};
-
 // x86-64 Windows target
 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
     : public WindowsTargetInfo<X86_64TargetInfo> {

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to