From 4fe40d82f8df672e374871dc8c09cb8128f9dc1e Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Sun, 13 Aug 2017 19:42:17 +0000 Subject: [PATCH] [AArch64] Add support for a MinGW AArch64 target 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 | 8 +++- lib/Basic/Targets/AArch64.cpp | 63 +++++++++++++++++--------- lib/Basic/Targets/AArch64.h | 28 ++++++++++-- lib/Driver/ToolChains/CrossWindows.cpp | 5 ++ lib/Driver/ToolChains/MinGW.cpp | 18 ++++++-- test/Preprocessor/predefined-macros.c | 10 ++++ 6 files changed, 102 insertions(+), 30 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 9946f82405..3c1c08bb05 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -142,7 +142,13 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return new OpenBSDTargetInfo(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); } diff --git a/lib/Basic/Targets/AArch64.cpp b/lib/Basic/Targets/AArch64.cpp index af2e35bb86..0de8727a1a 100644 --- a/lib/Basic/Targets/AArch64.cpp +++ b/lib/Basic/Targets/AArch64.cpp @@ -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(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::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::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(Triple, Opts) { diff --git a/lib/Basic/Targets/AArch64.h b/lib/Basic/Targets/AArch64.h index a720791a91..8391b7367a 100644 --- a/lib/Basic/Targets/AArch64.h +++ b/lib/Basic/Targets/AArch64.h @@ -89,24 +89,42 @@ private: void setDataLayout() override; }; -class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo +class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo : public WindowsTargetInfo { 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 { diff --git a/lib/Driver/ToolChains/CrossWindows.cpp b/lib/Driver/ToolChains/CrossWindows.cpp index 67ce08f9a7..944a0896e7 100644 --- a/lib/Driver/ToolChains/CrossWindows.cpp +++ b/lib/Driver/ToolChains/CrossWindows.cpp @@ -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: diff --git a/lib/Driver/ToolChains/MinGW.cpp b/lib/Driver/ToolChains/MinGW.cpp index b84c6ee89b..46e2289219 100644 --- a/lib/Driver/ToolChains/MinGW.cpp +++ b/lib/Driver/ToolChains/MinGW.cpp @@ -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"); diff --git a/test/Preprocessor/predefined-macros.c b/test/Preprocessor/predefined-macros.c index e135549f8a..94b0b30b44 100644 --- a/test/Preprocessor/predefined-macros.c +++ b/test/Preprocessor/predefined-macros.c @@ -199,3 +199,13 @@ // 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 -- 2.40.0