diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -233,12 +233,13 @@ MuslX32, MSVC, + MSVC_Arm64EC, Itanium, Cygnus, CoreCLR, Simulator, // Simulator variants of other systems, e.g., Apple's iOS - MacABI, // Mac Catalyst variant of Apple's iOS deployment target. - + MacABI, // Mac Catalyst variant of Apple's iOS deployment target. + // Shader Stages Pixel, Vertex, @@ -566,7 +567,8 @@ /// Checks if the environment is MSVC. bool isKnownWindowsMSVCEnvironment() const { - return isOSWindows() && getEnvironment() == Triple::MSVC; + return isOSWindows() && (getEnvironment() == Triple::MSVC || + getEnvironment() == Triple::MSVC_Arm64EC); } /// Checks if the environment could be MSVC. @@ -575,6 +577,11 @@ (isOSWindows() && getEnvironment() == Triple::UnknownEnvironment); } + // Checks if we're using the Windows Arm64EC ABI. + bool isWindowsArm64EC() const { + return getEnvironment() == Triple::MSVC_Arm64EC; + } + bool isWindowsCoreCLREnvironment() const { return isOSWindows() && getEnvironment() == Triple::CoreCLR; } diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -263,6 +263,7 @@ case GNUILP32: return "gnu_ilp32"; case Itanium: return "itanium"; case MSVC: return "msvc"; + case MSVC_Arm64EC: return "msvc_arm64ec"; case MacABI: return "macabi"; case Musl: return "musl"; case MuslEABI: return "musleabi"; @@ -605,6 +606,7 @@ .StartsWith("musleabi", Triple::MuslEABI) .StartsWith("muslx32", Triple::MuslX32) .StartsWith("musl", Triple::Musl) + .StartsWith("msvc_arm64ec", Triple::MSVC_Arm64EC) .StartsWith("msvc", Triple::MSVC) .StartsWith("itanium", Triple::Itanium) .StartsWith("cygnus", Triple::Cygnus) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -745,7 +745,7 @@ std::unique_ptr createObjectTargetWriter() const override { - return createAArch64WinCOFFObjectWriter(); + return createAArch64WinCOFFObjectWriter(TheTriple); } }; } diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h @@ -32,6 +32,7 @@ class MCTargetOptions; class MCTargetStreamer; class Target; +class Triple; MCCodeEmitter *createAArch64MCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx); @@ -51,7 +52,8 @@ createAArch64MachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype, bool IsILP32); -std::unique_ptr createAArch64WinCOFFObjectWriter(); +std::unique_ptr +createAArch64WinCOFFObjectWriter(const Triple &TheTriple); MCTargetStreamer *createAArch64AsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp @@ -30,8 +30,10 @@ class AArch64WinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter { public: - AArch64WinCOFFObjectWriter() - : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARM64) {} + AArch64WinCOFFObjectWriter(const Triple &TheTriple) + : MCWinCOFFObjectTargetWriter(TheTriple.isWindowsArm64EC() + ? COFF::IMAGE_FILE_MACHINE_ARM64EC + : COFF::IMAGE_FILE_MACHINE_ARM64) {} ~AArch64WinCOFFObjectWriter() override = default; @@ -159,6 +161,7 @@ return true; } -std::unique_ptr llvm::createAArch64WinCOFFObjectWriter() { - return std::make_unique(); +std::unique_ptr +llvm::createAArch64WinCOFFObjectWriter(const Triple &TheTriple) { + return std::make_unique(TheTriple); } diff --git a/llvm/test/MC/AArch64/arm64ec.s b/llvm/test/MC/AArch64/arm64ec.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/AArch64/arm64ec.s @@ -0,0 +1,4 @@ +// RUN: llvm-mc -triple aarch64-pc-windows-msvc_arm64ec -filetype=obj %s -o - | llvm-objdump -d -r - | FileCheck %s +// CHECK: file format coff-arm64ec +// CHECK: add x0, x1, x2 +add x0, x1, x2