]> granicus.if.org Git - clang/commitdiff
[AArch64] Add support for a MinGW AArch64 target
authorMartin Storsjo <martin@martin.st>
Sun, 13 Aug 2017 19:42:17 +0000 (19:42 +0000)
committerMartin Storsjo <martin@martin.st>
Sun, 13 Aug 2017 19:42:17 +0000 (19:42 +0000)
Differential Revision: https://reviews.llvm.org/D36364

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310798 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Targets.cpp
lib/Basic/Targets/AArch64.cpp
lib/Basic/Targets/AArch64.h
lib/Driver/ToolChains/CrossWindows.cpp
lib/Driver/ToolChains/MinGW.cpp
test/Preprocessor/predefined-macros.c

index 9946f82405ee9fb76c669f99cd7f0129b7f1d5c9..3c1c08bb0571f39fccff3a4d2210fb04ec1d4a99 100644 (file)
@@ -142,7 +142,13 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
     case llvm::Triple::OpenBSD:
       return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
     case llvm::Triple::Win32:
-      return new MicrosoftARM64TargetInfo(Triple, Opts);
+      switch (Triple.getEnvironment()) {
+      case llvm::Triple::GNU:
+        return new MinGWARM64TargetInfo(Triple, Opts);
+      case llvm::Triple::MSVC:
+      default: // Assume MSVC for unknown environments
+        return new MicrosoftARM64TargetInfo(Triple, Opts);
+      }
     default:
       return new AArch64leTargetInfo(Triple, Opts);
     }
index af2e35bb866dffcc02fe0a94df15a1a8db476ffd..0de8727a1a37579201104f6b220cc4d977b07198 100644 (file)
@@ -414,8 +414,8 @@ void AArch64beTargetInfo::setDataLayout() {
   resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
 }
 
-MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
-                                                   const TargetOptions &Opts)
+WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,
+                                               const TargetOptions &Opts)
     : WindowsTargetInfo<AArch64leTargetInfo>(Triple, Opts), Triple(Triple) {
 
   // This is an LLP64 platform.
@@ -431,35 +431,19 @@ MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
   SizeType = UnsignedLongLong;
   PtrDiffType = SignedLongLong;
   IntPtrType = SignedLongLong;
-
-  TheCXXABI.set(TargetCXXABI::Microsoft);
 }
 
-void MicrosoftARM64TargetInfo::setDataLayout() {
+void WindowsARM64TargetInfo::setDataLayout() {
   resetDataLayout("e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128");
 }
 
-void MicrosoftARM64TargetInfo::getVisualStudioDefines(
-    const LangOptions &Opts, MacroBuilder &Builder) const {
-  WindowsTargetInfo<AArch64leTargetInfo>::getVisualStudioDefines(Opts, Builder);
-  Builder.defineMacro("_WIN32", "1");
-  Builder.defineMacro("_WIN64", "1");
-  Builder.defineMacro("_M_ARM64", "1");
-}
-
-void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
-                                                MacroBuilder &Builder) const {
-  WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  getVisualStudioDefines(Opts, Builder);
-}
-
 TargetInfo::BuiltinVaListKind
-MicrosoftARM64TargetInfo::getBuiltinVaListKind() const {
+WindowsARM64TargetInfo::getBuiltinVaListKind() const {
   return TargetInfo::CharPtrBuiltinVaList;
 }
 
 TargetInfo::CallingConvCheckResult
-MicrosoftARM64TargetInfo::checkCallingConvention(CallingConv CC) const {
+WindowsARM64TargetInfo::checkCallingConvention(CallingConv CC) const {
   switch (CC) {
   case CC_X86StdCall:
   case CC_X86ThisCall:
@@ -475,6 +459,43 @@ MicrosoftARM64TargetInfo::checkCallingConvention(CallingConv CC) const {
   }
 }
 
+MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
+                                                   const TargetOptions &Opts)
+    : WindowsARM64TargetInfo(Triple, Opts) {
+  TheCXXABI.set(TargetCXXABI::Microsoft);
+}
+
+void MicrosoftARM64TargetInfo::getVisualStudioDefines(
+    const LangOptions &Opts, MacroBuilder &Builder) const {
+  WindowsTargetInfo<AArch64leTargetInfo>::getVisualStudioDefines(Opts, Builder);
+  Builder.defineMacro("_WIN32", "1");
+  Builder.defineMacro("_WIN64", "1");
+  Builder.defineMacro("_M_ARM64", "1");
+}
+
+void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
+                                                MacroBuilder &Builder) const {
+  WindowsTargetInfo::getTargetDefines(Opts, Builder);
+  getVisualStudioDefines(Opts, Builder);
+}
+
+MinGWARM64TargetInfo::MinGWARM64TargetInfo(const llvm::Triple &Triple,
+                                           const TargetOptions &Opts)
+    : WindowsARM64TargetInfo(Triple, Opts) {
+  TheCXXABI.set(TargetCXXABI::GenericAArch64);
+}
+
+void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
+                                            MacroBuilder &Builder) const {
+  WindowsTargetInfo::getTargetDefines(Opts, Builder);
+  Builder.defineMacro("_WIN32", "1");
+  Builder.defineMacro("_WIN64", "1");
+  Builder.defineMacro("WIN32", "1");
+  Builder.defineMacro("WIN64", "1");
+  addMinGWDefines(Opts, Builder);
+}
+
+
 DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple,
                                                  const TargetOptions &Opts)
     : DarwinTargetInfo<AArch64leTargetInfo>(Triple, Opts) {
index a720791a91b4a321032f98f61ff0e6bb83583eb6..8391b7367a2941bb8626e23736cd68b6c4853158 100644 (file)
@@ -89,24 +89,42 @@ private:
   void setDataLayout() override;
 };
 
-class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
+class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
     : public WindowsTargetInfo<AArch64leTargetInfo> {
   const llvm::Triple Triple;
 
 public:
-  MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
-                           const TargetOptions &Opts);
+  WindowsARM64TargetInfo(const llvm::Triple &Triple,
+                         const TargetOptions &Opts);
 
   void setDataLayout() override;
 
+  BuiltinVaListKind getBuiltinVaListKind() const override;
+
+  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
+};
+
+// Windows ARM, MS (C++) ABI
+class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
+    : public WindowsARM64TargetInfo {
+public:
+  MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
+                           const TargetOptions &Opts);
+
   void getVisualStudioDefines(const LangOptions &Opts,
                               MacroBuilder &Builder) const;
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override;
+};
 
-  BuiltinVaListKind getBuiltinVaListKind() const override;
+// ARM64 MinGW target
+class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo
+    : public WindowsARM64TargetInfo {
+public:
+  MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
 
-  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
+  void getTargetDefines(const LangOptions &Opts,
+                        MacroBuilder &Builder) const override;
 };
 
 class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
index 67ce08f9a7e8051c5eeaeac06bb0efa38bba6179..944a0896e7a1f0a04fe7a0e94273b47306ab7d18 100644 (file)
@@ -36,6 +36,7 @@ void tools::CrossWindows::Assembler::ConstructJob(
     llvm_unreachable("unsupported architecture");
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
+  case llvm::Triple::aarch64:
     break;
   case llvm::Triple::x86:
     CmdArgs.push_back("--32");
@@ -98,6 +99,9 @@ void tools::CrossWindows::Linker::ConstructJob(
     // FIXME: this is incorrect for WinCE
     CmdArgs.push_back("thumb2pe");
     break;
+  case llvm::Triple::aarch64:
+    CmdArgs.push_back("arm64pe");
+    break;
   case llvm::Triple::x86:
     CmdArgs.push_back("i386pe");
     EntryPoint.append("_");
@@ -111,6 +115,7 @@ void tools::CrossWindows::Linker::ConstructJob(
     switch (T.getArch()) {
     default:
       llvm_unreachable("unsupported architecture");
+    case llvm::Triple::aarch64:
     case llvm::Triple::arm:
     case llvm::Triple::thumb:
     case llvm::Triple::x86_64:
index b84c6ee89bb451ad547cbf308190bfd33415f300..46e2289219c9fe56f7f7505a772c03a3bb00b1e0 100644 (file)
@@ -119,12 +119,24 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-s");
 
   CmdArgs.push_back("-m");
-  if (TC.getArch() == llvm::Triple::x86)
+  switch (TC.getArch()) {
+  case llvm::Triple::x86:
     CmdArgs.push_back("i386pe");
-  if (TC.getArch() == llvm::Triple::x86_64)
+    break;
+  case llvm::Triple::x86_64:
     CmdArgs.push_back("i386pep");
-  if (TC.getArch() == llvm::Triple::arm)
+    break;
+  case llvm::Triple::arm:
+  case llvm::Triple::thumb:
+    // FIXME: this is incorrect for WinCE
     CmdArgs.push_back("thumb2pe");
+    break;
+  case llvm::Triple::aarch64:
+    CmdArgs.push_back("arm64pe");
+    break;
+  default:
+    llvm_unreachable("Unsupported target architecture.");
+  }
 
   if (Args.hasArg(options::OPT_mwindows)) {
     CmdArgs.push_back("--subsystem");
index e135549f8a741981092f5048d942ac904936c4de..94b0b30b445bab80d22150f5db320388574e99ef 100644 (file)
 // CHECK-ARM64-WIN: #define _M_ARM64 1
 // CHECK-ARM64-WIN: #define _WIN32 1
 // CHECK-ARM64-WIN: #define _WIN64 1
+
+// RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
+
+// CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
+// CHECK-ARM64-MINGW: #define WIN32 1
+// CHECK-ARM64-MINGW: #define WIN64 1
+// CHECK-ARM64-MINGW: #define _WIN32 1
+// CHECK-ARM64-MINGW: #define _WIN64 1
+// CHECK-ARM64-MINGW: #define __aarch64__ 1