From 1cec99f6d53d442d8a8c9d2ed9f4a58f8fdc6412 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Thu, 18 Feb 2016 08:30:07 +0100
Subject: [PATCH 1/3] Add Musl, MuslEABI and Musl EABIHF triples

---
 include/llvm/ADT/Triple.h           | 11 +++++++++++
 lib/Support/Triple.cpp              |  7 +++++++
 lib/Target/ARM/ARMSubtarget.h       |  3 +++
 lib/Target/ARM/ARMTargetMachine.cpp |  2 ++
 4 files changed, 23 insertions(+)

--- a/include/llvm/ADT/Triple.h
+++ b/include/llvm/ADT/Triple.h
@@ -167,6 +167,10 @@
     EABIHF,
     Android,
 
+    Musl,
+    MuslEABI,
+    MuslEABIHF,
+
     MSVC,
     Itanium,
     Cygnus,
@@ -548,6 +552,13 @@
   /// setOSAndEnvironmentName - Set the operating system and optional
   /// environment components with a single string.
   void setOSAndEnvironmentName(StringRef Str);
+
+  /// Tests whether the target is musl libc
+  bool isMusl() const {
+    return getEnvironment() == Triple::Musl ||
+           getEnvironment() == Triple::MuslEABI ||
+           getEnvironment() == Triple::MuslEABIHF;
+  }
 
   /// @}
   /// @name Helpers to build variants of a particular triple.
--- a/lib/Support/Triple.cpp
+++ b/lib/Support/Triple.cpp
@@ -192,6 +192,9 @@
   case CODE16: return "code16";
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
+  case Musl: return "musl";
+  case MuslEABIHF: return "muslgnueabihf";
+  case MuslEABI: return "muslgnueabi";
   case Android: return "android";
   case MSVC: return "msvc";
   case Itanium: return "itanium";
@@ -427,6 +430,9 @@
     .StartsWith("code16", Triple::CODE16)
     .StartsWith("gnu", Triple::GNU)
     .StartsWith("android", Triple::Android)
+    .StartsWith("muslgnueabihf", Triple::MuslEABIHF)
+    .StartsWith("muslgnueabi", Triple::MuslEABI)
+    .StartsWith("musl", Triple::Musl)
     .StartsWith("msvc", Triple::MSVC)
     .StartsWith("itanium", Triple::Itanium)
     .StartsWith("cygnus", Triple::Cygnus)
@@ -1326,6 +1332,7 @@
     switch (getEnvironment()) {
     case llvm::Triple::EABIHF:
     case llvm::Triple::GNUEABIHF:
+    case llvm::Triple::MuslEABIHF:
       return "arm1176jzf-s";
     default:
       return "arm7tdmi";
--- a/lib/Target/ARM/ARMSubtarget.h
+++ b/lib/Target/ARM/ARMSubtarget.h
@@ -381,8 +381,10 @@
   bool isTargetEHABICompatible() const {
     return (TargetTriple.getEnvironment() == Triple::EABI ||
             TargetTriple.getEnvironment() == Triple::GNUEABI ||
+             TargetTriple.getEnvironment() == Triple::MuslEABI ||
             TargetTriple.getEnvironment() == Triple::EABIHF ||
             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
+             TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
             TargetTriple.getEnvironment() == Triple::Android) &&
            !isTargetDarwin() && !isTargetWindows();
   }
@@ -391,6 +393,7 @@
     // FIXME: this is invalid for WindowsCE
     return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
            TargetTriple.getEnvironment() == Triple::EABIHF ||
+            TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
            isTargetWindows();
   }
   bool isTargetAndroid() const {
--- a/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/lib/Target/ARM/ARMTargetMachine.cpp
@@ -97,6 +97,8 @@
     case llvm::Triple::GNUEABIHF:
     case llvm::Triple::EABIHF:
     case llvm::Triple::EABI:
+    case llvm::Triple::MuslEABI:
+    case llvm::Triple::MuslEABIHF:
       TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
       break;
     case llvm::Triple::GNU:
