carwil updated this revision to Diff 183114.
carwil added a comment.

More tests, and better handling of argument combination errors.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56003/new/

https://reviews.llvm.org/D56003

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/ARM.h
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-reserved-reg-options.c
  test/Sema/arm-global-regs.c

Index: test/Sema/arm-global-regs.c
===================================================================
--- /dev/null
+++ test/Sema/arm-global-regs.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify -triple arm %s
+
+// Check a small subset of valid and invalid global register variable declarations.
+
+register unsigned arm_r3 __asm("r3");   //expected-error {{register 'r3' unsuitable for global register variables on this target}}
+
+register unsigned arm_r12 __asm("r12"); //expected-error {{register 'r12' unsuitable for global register variables on this target}}
+
+register unsigned arm_r5 __asm("r5");
+
+register unsigned arm_r9 __asm("r9");
+
+register unsigned arm_sp __asm("sp");
\ No newline at end of file
Index: test/Driver/arm-reserved-reg-options.c
===================================================================
--- /dev/null
+++ test/Driver/arm-reserved-reg-options.c
@@ -0,0 +1,68 @@
+// ## FP ARM + Thumb
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITHOUT-OMIT %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITH-NO-OMIT %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -fno-omit-frame-pointer -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -fomit-frame-pointer -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITH-NO-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -mthumb -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITHOUT-OMIT %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -mthumb -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -mthumb -fno-omit-frame-pointer -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -mthumb -fomit-frame-pointer -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -mthumb -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST %s
+
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -fomit-frame-pointer -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r7 -fno-omit-frame-pointer -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -mthumb -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -mthumb -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -mthumb -fomit-frame-pointer -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r11 -mthumb -fno-omit-frame-pointer -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// RUN: %clang -target thumbv6m-none-eabi -### -ffixed-r7 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITHOUT-OMIT %s
+// RUN: %clang -target thumbv6m-none-eabi -### -ffixed-r7 -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT %s
+// RUN: %clang -target thumbv6m-none-eabi -### -ffixed-r7 -fomit-frame-pointer -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT-LAST %s
+// RUN: %clang -target thumbv6m-none-eabi -### -ffixed-r7 -fno-omit-frame-pointer -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST %s
+// RUN: %clang -target thumbv6m-none-eabi -### -ffixed-r11 -fomit-frame-pointer -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target thumbv6m-none-eabi -### -ffixed-r11 -fno-omit-frame-pointer -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// ## FP Darwin (R7)
+// RUN: %clang -target armv6-apple-darwin9 -### -ffixed-r7 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITHOUT-OMIT %s
+// RUN: %clang -target armv6-apple-darwin9 -### -ffixed-r7 -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST %s
+// RUN: %clang -target armv6-apple-darwin9 -### -ffixed-r7 -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT %s
+// RUN: %clang -target armv6-apple-darwin9 -### -ffixed-r11 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// RUN: %clang -target armv6-apple-ios3 -### -ffixed-r7 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITHOUT-OMIT %s
+// RUN: %clang -target armv6-apple-ios3 -### -ffixed-r7 -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT %s
+// RUN: %clang -target armv6-apple-ios3 -### -ffixed-r7 -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST %s
+// RUN: %clang -target armv6-apple-ios3 -### -ffixed-r11 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// RUN: %clang -target armv7s-apple-darwin10 -### -ffixed-r7 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITHOUT-OMIT %s
+// RUN: %clang -target armv7s-apple-darwin10 -### -ffixed-r7 -fno-omit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-NO-OMIT %s
+// RUN: %clang -target armv7s-apple-darwin10 -### -ffixed-r7 -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST %s
+// RUN: %clang -target armv7s-apple-darwin10 -### -ffixed-r11 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// ## FP Windows (R11)
+// RUN: %clang -target armv7-windows -### -ffixed-r11 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITHOUT-OMIT %s
+// RUN: %clang -target armv7-windows -### -ffixed-r11 -fomit-frame-pointer -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+// RUN: %clang -target armv7-windows -### -ffixed-r7 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-R7-WITH-OMIT-LAST -check-prefix=CHECK-RESERVED-R11-WITH-OMIT-LAST %s
+
+// ## FRWPI (R9)
+// RUN: %clang -target arm-arm-none-eabi -### -frwpi -ffixed-r9 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-FRWPI-CONFLICT %s
+// RUN: %clang -target arm-arm-none-eabi -### -ffixed-r9 -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-FRWPI-VALID %s
+// RUN: %clang -target arm-arm-none-eabi -### -frwpi -c %s 2>&1 | FileCheck -check-prefix=CHECK-RESERVED-FRWPI-VALID %s
+
+// CHECK-RESERVED-R7-WITH-NO-OMIT: option '-ffixed-r7' cannot be specified with '-fno-omit-frame-pointer'
+// CHECK-RESERVED-R7-WITHOUT-OMIT: option '-ffixed-r7' cannot be specified without '-fomit-frame-pointer'
+// CHECK-RESERVED-R7-WITH-OMIT-LAST-NOT: option '-ffixed-r7' cannot be specified with '-fno-omit-frame-pointer'
+// CHECK-RESERVED-R7-WITH-OMIT-LAST-NOT: option '-ffixed-r7' cannot be specified without '-fomit-frame-pointer'
+// CHECK-RESERVED-R7-WITH-NO-OMIT-LAST: option '-ffixed-r7' cannot be specified with '-fno-omit-frame-pointer'
+// CHECK-RESERVED-R11-WITH-NO-OMIT: option '-ffixed-r11' cannot be specified with '-fno-omit-frame-pointer'
+// CHECK-RESERVED-R11-WITHOUT-OMIT: option '-ffixed-r11' cannot be specified without '-fomit-frame-pointer'
+// CHECK-RESERVED-R11-WITH-OMIT-LAST-NOT: option '-ffixed-r11' cannot be specified with '-fno-omit-frame-pointer'
+// CHECK-RESERVED-R11-WITH-OMIT-LAST-NOT: option '-ffixed-r11' cannot be specified without '-fomit-frame-pointer'
+// CHECK-RESERVED-R11-WITH-NO-OMIT-LAST: option '-ffixed-r11' cannot be specified with '-fno-omit-frame-pointer'
+// CHECK-RESERVED-FRWPI-CONFLICT: option '-ffixed-r9' cannot be specified with '-frwpi'
+// CHECK-RESERVED-FRWPI-VALID-NOT: option '-ffixed-r9' cannot be specified with '-frwpi'
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===================================================================
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -547,11 +547,48 @@
       Features.push_back("+strict-align");
   }
 
-  // llvm does not support reserving registers in general. There is support
-  // for reserving r9 on ARM though (defined as a platform-specific register
-  // in ARM EABI).
-  if (Args.hasArg(options::OPT_ffixed_r9))
-    Features.push_back("+reserve-r9");
+  // Do not allow r9 reservation with -frwpi.
+  if (Args.hasArg(options::OPT_ffixed_r9) && Args.hasArg(options::OPT_frwpi)) {
+    Arg *A = Args.getLastArg(options::OPT_ffixed_r9);
+    Arg *B = Args.getLastArg(options::OPT_frwpi);
+    D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args);
+  }
+
+  // Disallow FP reservation unless it has been explicitly omitted.
+  // Windows and Arm Instruction Set uses R11 as the FP.
+  // iOS and Thumb Instruction Set for Non-windows use R7 as the FP.
+  const llvm::opt::OptSpecifier RestrictFPOpt =
+      (Triple.isOSDarwin() || (!Triple.isOSWindows() && Triple.isThumb()))
+          ? options::OPT_ffixed_r7
+          : options::OPT_ffixed_r11;
+  if (Args.hasArg(RestrictFPOpt)) {
+    Arg *OmitFPLastArg = Args.getLastArg(options::OPT_fomit_frame_pointer,
+                                         options::OPT_fno_omit_frame_pointer);
+    if (OmitFPLastArg) {
+      if (OmitFPLastArg->getOption().matches(
+              options::OPT_fno_omit_frame_pointer)) {
+        D.Diag(diag::err_opt_not_valid_with_opt)
+            << Args.getLastArg(RestrictFPOpt)->getAsString(Args)
+            << "-fno-omit-frame-pointer";
+      } // An OmitFP preference is fine.
+    } else {
+      D.Diag(diag::err_opt_not_valid_without_opt)
+          << Args.getLastArg(RestrictFPOpt)->getAsString(Args)
+          << "-fomit-frame-pointer";
+    }
+  }
+
+// Reservation of general purpose registers.
+#define HANDLE_FFIXED_R(n) \
+  if (Args.hasArg(options::OPT_ffixed_r##n)) \
+    Features.push_back("+reserve-r" #n)
+  HANDLE_FFIXED_R(5);
+  HANDLE_FFIXED_R(6);
+  HANDLE_FFIXED_R(7);
+  HANDLE_FFIXED_R(8);
+  HANDLE_FFIXED_R(9);
+  HANDLE_FFIXED_R(10);
+  HANDLE_FFIXED_R(11);
 
   // The kext linker doesn't know how to deal with movw/movt.
   if (KernelOrKext || Args.hasArg(options::OPT_mno_movt))
Index: lib/Basic/Targets/ARM.h
===================================================================
--- lib/Basic/Targets/ARM.h
+++ lib/Basic/Targets/ARM.h
@@ -147,6 +147,9 @@
 
   ArrayRef<const char *> getGCCRegNames() const override;
   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
+  bool validateGlobalRegisterVariable(StringRef RegName,
+                                      unsigned RegSize,
+                                      bool &HasSizeMismatch) const override;
   bool validateAsmConstraint(const char *&Name,
                              TargetInfo::ConstraintInfo &Info) const override;
   std::string convertConstraint(const char *&Constraint) const override;
Index: lib/Basic/Targets/ARM.cpp
===================================================================
--- lib/Basic/Targets/ARM.cpp
+++ lib/Basic/Targets/ARM.cpp
@@ -822,6 +822,22 @@
   return llvm::makeArrayRef(GCCRegAliases);
 }
 
+bool ARMTargetInfo::validateGlobalRegisterVariable(
+    StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const {
+  if (RegName.equals("r5") ||
+      RegName.equals("r6") ||
+      RegName.equals("r7") ||
+      RegName.equals("r8") ||
+      RegName.equals("r9") ||
+      RegName.equals("r10") ||
+      RegName.equals("r11") ||
+      RegName.equals("sp")) {
+    HasSizeMismatch = false;
+    return true;
+  }
+  return false;
+}
+
 bool ARMTargetInfo::validateAsmConstraint(
     const char *&Name, TargetInfo::ConstraintInfo &Info) const {
   switch (*Name) {
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -2112,8 +2112,9 @@
 def mno_restrict_it: Flag<["-"], "mno-restrict-it">, Group<m_arm_Features_Group>,
   HelpText<"Allow generation of deprecated IT blocks for ARMv8. It is off by default for ARMv8 Thumb mode">;
 def marm : Flag<["-"], "marm">, Alias<mno_thumb>;
-def ffixed_r9 : Flag<["-"], "ffixed-r9">, Group<m_arm_Features_Group>,
-  HelpText<"Reserve the r9 register (ARM only)">;
+foreach i = {5-11} in
+  def ffixed_r#i : Flag<["-"], "ffixed-r"#i>, Group<m_arm_Features_Group>,
+    HelpText<"Reserve the r"#i#" register (ARM only)">;
 def mno_movt : Flag<["-"], "mno-movt">, Group<m_arm_Features_Group>,
   HelpText<"Disallow use of movt/movw pairs (ARM only)">;
 def mcrc : Flag<["-"], "mcrc">, Group<m_Group>,
Index: docs/ClangCommandLineReference.rst
===================================================================
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -2402,10 +2402,34 @@
 
 ARM
 ---
+.. option:: -ffixed-r5
+
+Reserve the r5 register (ARM only)
+
+.. option:: -ffixed-r6
+
+Reserve the r6 register (ARM only)
+
+.. option:: -ffixed-r7
+
+Reserve the r7 register (ARM only)
+
+.. option:: -ffixed-r8
+
+Reserve the r8 register (ARM only)
+
 .. option:: -ffixed-r9
 
 Reserve the r9 register (ARM only)
 
+.. option:: -ffixed-r10
+
+Reserve the r10 register (ARM only)
+
+.. option:: -ffixed-r11
+
+Reserve the r11 register (ARM only)
+
 .. option:: -mexecute-only, -mno-execute-only, -mpure-code
 
 Disallow generation of data access to code sections (ARM only)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to