]> granicus.if.org Git - llvm/commitdiff
Unified logic for computing target ABI in backend and front end by moving this common...
authorEric Christopher <echristo@gmail.com>
Fri, 30 Jun 2017 00:03:54 +0000 (00:03 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 30 Jun 2017 00:03:54 +0000 (00:03 +0000)
Modeled Triple::GNU after front end code (aapcs abi) and  updated tests that expect apcs abi.

Based heavily on a patch by Ana Pazos!

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

include/llvm/Support/TargetParser.h
lib/Support/TargetParser.cpp
lib/Target/ARM/ARMTargetMachine.cpp
test/CodeGen/ARM/alloca.ll
test/CodeGen/ARM/arm-abi-attr.ll
test/CodeGen/ARM/ctor_order.ll
test/CodeGen/ARM/ctors_dtors.ll
test/CodeGen/ARM/ssp-data-layout.ll
test/CodeGen/ARM/str_pre-2.ll

index f29cc40ffdd5537922ef5da146fc8ea5ef473a4a..72c28865ac575e0a2b55a0bd62347151cfeba4db 100644 (file)
@@ -17,6 +17,7 @@
 
 // FIXME: vector is used because that's what clang uses for subtarget feature
 // lists, but SmallVector would probably be better
+#include "llvm/ADT/Triple.h"
 #include <vector>
 
 namespace llvm {
@@ -140,6 +141,8 @@ unsigned parseArchEndian(StringRef Arch);
 unsigned parseArchProfile(StringRef Arch);
 unsigned parseArchVersion(StringRef Arch);
 
+StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
+
 } // namespace ARM
 
 // FIXME:This should be made into class design,to avoid dupplication.
index b16351906a4c4dade1c86eaa7b8179dac250d21f..13bb6f23bc83f153663b6ade84ffc10f962d5876 100644 (file)
@@ -784,6 +784,42 @@ unsigned llvm::ARM::parseArchVersion(StringRef Arch) {
   return 0;
 }
 
+StringRef llvm::ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) {
+  StringRef ArchName =
+      CPU.empty() ? TT.getArchName() : ARM::getArchName(ARM::parseCPUArch(CPU));
+
+  if (TT.isOSBinFormatMachO()) {
+    if (TT.getEnvironment() == Triple::EABI ||
+        TT.getOS() == Triple::UnknownOS ||
+        llvm::ARM::parseArchProfile(ArchName) == ARM::PK_M)
+      return "aapcs";
+    if (TT.isWatchABI())
+      return "aapcs16";
+    return "apcs-gnu";
+  } else if (TT.isOSWindows())
+    // FIXME: this is invalid for WindowsCE.
+    return "aapcs";
+
+  // Select the default based on the platform.
+  switch (TT.getEnvironment()) {
+  case Triple::Android:
+  case Triple::GNUEABI:
+  case Triple::GNUEABIHF:
+  case Triple::MuslEABI:
+  case Triple::MuslEABIHF:
+    return "aapcs-linux";
+  case Triple::EABIHF:
+  case Triple::EABI:
+    return "aapcs";
+  default:
+    if (TT.isOSNetBSD())
+      return "apcs-gnu";
+    if (TT.isOSOpenBSD())
+      return "aapcs-linux";
+    return "aapcs";
+  }
+}
+
 StringRef llvm::AArch64::getCanonicalArchName(StringRef Arch) {
   return ARM::getCanonicalArchName(Arch);
 }
index eb71e557ec9176665df4b405e83d65f4beb1b285..4eb244a13c158f022ccfd315fecc3f766a20f80c 100644 (file)
@@ -110,60 +110,20 @@ static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
 static ARMBaseTargetMachine::ARMABI
 computeTargetABI(const Triple &TT, StringRef CPU,
                  const TargetOptions &Options) {
-  if (Options.MCOptions.getABIName() == "aapcs16")
+  StringRef ABIName = Options.MCOptions.getABIName();
+
+  if (ABIName.empty())
+    ABIName = ARM::computeDefaultTargetABI(TT, CPU);
+
+  if (ABIName == "aapcs16")
     return ARMBaseTargetMachine::ARM_ABI_AAPCS16;
-  else if (Options.MCOptions.getABIName().startswith("aapcs"))
+  else if (ABIName.startswith("aapcs"))
     return ARMBaseTargetMachine::ARM_ABI_AAPCS;
-  else if (Options.MCOptions.getABIName().startswith("apcs"))
+  else if (ABIName.startswith("apcs"))
     return ARMBaseTargetMachine::ARM_ABI_APCS;
 
-  assert(Options.MCOptions.getABIName().empty() &&
-         "Unknown target-abi option!");
-
-  ARMBaseTargetMachine::ARMABI TargetABI =
-      ARMBaseTargetMachine::ARM_ABI_UNKNOWN;
-
-  unsigned ArchKind = ARM::parseCPUArch(CPU);
-  StringRef ArchName = ARM::getArchName(ArchKind);
-  // FIXME: This is duplicated code from the front end and should be unified.
-  if (TT.isOSBinFormatMachO()) {
-    if (TT.getEnvironment() == Triple::EABI ||
-        (TT.getOS() == Triple::UnknownOS && TT.isOSBinFormatMachO()) ||
-        ARM::parseArchProfile(ArchName) == ARM::PK_M) {
-      TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
-    } else if (TT.isWatchABI()) {
-      TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS16;
-    } else {
-      TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
-    }
-  } else if (TT.isOSWindows()) {
-    // FIXME: this is invalid for WindowsCE
-    TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
-  } else {
-    // Select the default based on the platform.
-    switch (TT.getEnvironment()) {
-    case Triple::Android:
-    case Triple::GNUEABI:
-    case Triple::GNUEABIHF:
-    case Triple::MuslEABI:
-    case Triple::MuslEABIHF:
-    case Triple::EABIHF:
-    case Triple::EABI:
-      TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
-      break;
-    case Triple::GNU:
-      TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
-      break;
-    default:
-      if (TT.isOSNetBSD())
-        TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS;
-      else
-        TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
-      break;
-    }
-  }
-
-  return TargetABI;
+  llvm_unreachable("Unhandled/unknown ABI Name!");
+  return ARMBaseTargetMachine::ARM_ABI_UNKNOWN;
 }
 
 static std::string computeDataLayout(const Triple &TT, StringRef CPU,
index 4a0835a2c0cafd36cbbadef858baa2b5db8c8719..82b6b11ea4b2b6b2b92c638fb713a3bdde0382d2 100644 (file)
@@ -2,11 +2,11 @@
 
 define void @f(i32 %a) {
 entry:
-; CHECK: add  r11, sp, #4
+; CHECK: add  r11, sp, #8
         %tmp = alloca i8, i32 %a                ; <i8*> [#uses=1]
         call void @g( i8* %tmp, i32 %a, i32 1, i32 2, i32 3 )
         ret void
-; CHECK: sub  sp, r11, #4
+; CHECK: sub  sp, r11, #8
 }
 
 declare void @g(i8*, i32, i32, i32, i32)
index 61cb6cefa170a4f4930d9302b26808d36414fc24..f05e6e788d6fc51088878fc03b6395f6f78daa20 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=arm-linux-gnu < %s | FileCheck %s --check-prefix=APCS
+; RUN: llc -mtriple=arm-linux-gnu < %s | FileCheck %s --check-prefix=AAPCS
 ; RUN: llc -mtriple=arm-linux-gnu -target-abi=apcs < %s | \
 ; RUN: FileCheck %s --check-prefix=APCS
 ; RUN: llc -mtriple=arm-linux-gnueabi -target-abi=apcs < %s | \
index 7fcc8cba0c8f3df53dd91d7c760772116c7e0fdf..0cf87d7a97b7752963765bd3e4df398a5ac3062a 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -mtriple=arm-apple-darwin  | FileCheck %s -check-prefix=DARWIN
 ; RUN: llc < %s -mtriple=arm-apple-darwin -relocation-model=dynamic-no-pic  | FileCheck %s --check-prefix=DARWIN
 ; RUN: llc < %s -mtriple=arm-apple-darwin -relocation-model=static  | FileCheck %s -check-prefix=DARWIN-STATIC
-; RUN: llc < %s -mtriple=arm-linux-gnu     | FileCheck %s -check-prefix=ELF
+; RUN: llc < %s -mtriple=arm-linux-gnu -target-abi=apcs  | FileCheck %s -check-prefix=ELF
 ; RUN: llc < %s -mtriple=arm-linux-gnueabi | FileCheck %s -check-prefix=GNUEABI
 
 ; DARWIN:      .section        __DATA,__mod_init_func,mod_init_funcs
index fb94626ab7dd03487583f5a2a6a0a7933de7a023..c097ade3c846c2452d1d396d22557f35592a6b46 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llc < %s -mtriple=arm-apple-darwin  | FileCheck %s -check-prefix=DARWIN
-; RUN: llc < %s -mtriple=arm-linux-gnu     | FileCheck %s -check-prefix=ELF
+; RUN: llc < %s -mtriple=arm-linux-gnu -target-abi=apcs  | FileCheck %s -check-prefix=ELF
 ; RUN: llc < %s -mtriple=arm-linux-gnueabi | FileCheck %s -check-prefix=GNUEABI
 
 ; DARWIN: .section     __DATA,__mod_init_func,mod_init_funcs
index 92fa0809ed2df47e22eefffcbe8b34a393a3bbd7..39c279eb90d475391fb4688c87c72725735b6cac 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -disable-fp-elim -march=arm -mcpu=cortex-a8 -mtriple arm-linux-gnu -o - | FileCheck %s
+; RUN: llc < %s -disable-fp-elim -march=arm -mcpu=cortex-a8 -mtriple arm-linux-gnu -target-abi=apcs -o - | FileCheck %s
 ;  This test is fairly fragile.  The goal is to ensure that "large" stack
 ;  objects are allocated closest to the stack protector (i.e., farthest away 
 ;  from the Stack Pointer.)  In standard SSP mode this means that large (>=
index 4b8b4c6bca72403ef22d86239b7e3bed442c8528..1c6c05de2579d96abc499179b481e0554b0e73d8 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=armv6-linux-gnu | FileCheck %s
+; RUN: llc < %s -mtriple=armv6-linux-gnu -target-abi=apcs | FileCheck %s
 
 @b = external global i64*