Add TargetInfo::getABI(), and base ARM APCS vs AAPCS choice on that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81735 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h
index ee742aa..64692ba 100644
--- a/include/clang/Basic/TargetInfo.h
+++ b/include/clang/Basic/TargetInfo.h
@@ -352,6 +352,11 @@
                                   llvm::StringMap<bool> &Features) const {
   }
 
+  /// getABI - Get the ABI in use.
+  virtual const char *getABI() const {
+    return "";
+  }
+
   /// setABI - Use the specific ABI.
   ///
   /// \return - False on error (invalid ABI name).
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index c9a3dea..eed9e2c 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -991,8 +991,13 @@
     Armv7a,
     XScale
   } ArmArch;
+
+  std::string ABI;
+
 public:
-  ARMTargetInfo(const std::string& triple) : TargetInfo(triple) {
+  ARMTargetInfo(const std::string& triple)
+    : TargetInfo(triple), ABI("aapcs-linux")
+  {
     // FIXME: Are the defaults correct for ARM?
     DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
                          "i64:32:32-f32:32:32-f64:32:32-"
@@ -1016,7 +1021,10 @@
       ArmArch = Armv6;
     }
   }
+  virtual const char *getABI() const { return ABI.c_str(); }
   virtual bool setABI(const std::string &Name) {
+    ABI = Name;
+
     // The defaults (above) are for AAPCS, check if we need to change them.
     //
     // FIXME: We need support for -meabi... we could just mangle it into the
diff --git a/lib/CodeGen/TargetABIInfo.cpp b/lib/CodeGen/TargetABIInfo.cpp
index 892994a..6d95ada 100644
--- a/lib/CodeGen/TargetABIInfo.cpp
+++ b/lib/CodeGen/TargetABIInfo.cpp
@@ -1682,11 +1682,8 @@
 
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
-    // FIXME: We should get this from the target, we also need a -target-abi
-    // because the user should have some control over this.
-    //
     // FIXME: We want to know the float calling convention as well.
-    if (Triple.getOS() == llvm::Triple::Darwin)
+    if (strcmp(getContext().Target.getABI(), "apcs-gnu") == 0)
       return *(TheABIInfo = new ARMABIInfo(ARMABIInfo::APCS));
 
     return *(TheABIInfo = new ARMABIInfo(ARMABIInfo::AAPCS));
diff --git a/test/CodeGen/arm-apcs-arguments.c b/test/CodeGen/arm-apcs-arguments.c
index d427dd1..db985d7 100644
--- a/test/CodeGen/arm-apcs-arguments.c
+++ b/test/CodeGen/arm-apcs-arguments.c
@@ -1,5 +1,5 @@
 // RUX: iphone-llvm-gcc -arch armv7 -flto -S -o - %s | FileCheck %s
-// RUN: clang-cc -triple armv7-apple-darwin9 -emit-llvm -w -o - %s | FileCheck %s
+// RUN: clang-cc -triple armv7-apple-darwin9 -target-abi=apcs-gnu -emit-llvm -w -o - %s | FileCheck %s
 
 // CHECK: define arm_apcscc signext i8 @f0()
 char f0(void) {