[mips] Fix assembler temporary expansion and add associated warnings about the use...
authorDaniel Sanders <daniel.sanders@imgtec.com>
Tue, 25 Mar 2014 10:57:07 +0000 (10:57 +0000)
committerDaniel Sanders <daniel.sanders@imgtec.com>
Tue, 25 Mar 2014 10:57:07 +0000 (10:57 +0000)
Summary:
The assembler temporary is normally $at ($1) but can be reassigned using
'.set at=$reg'. Regardless of which register is nominated as the assembler
temporary, $at remains $1 when written by the user.

Adds warnings under the following conditions:
* The register nominated as the assembler temporary is used by the user.
* '.set noat' is in effect and $at is used by the user.
Both of these only work for named registers. I have a follow up commit that makes it work for numeric registers as well.

XFAIL set-at-directive.s since it incorrectly tests that $at is redefined by
'.set at=$reg'. Testcases will follow in a separate commit.

Patch by David Chisnall
His work was sponsored by: DARPA, AFRL

Differential Revision: http://llvm-reviews.chandlerc.com/D3167

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

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
test/MC/Mips/set-at-directive.s

index f54a62b666cf754c8235c504c0f921cae190fe0b..0a6aee4bcee84547e6ee062ef84fadd6c9259436 100644 (file)
@@ -985,8 +985,13 @@ bool MipsAsmParser::MatchAndEmitInstruction(
 int MipsAsmParser::matchCPURegisterName(StringRef Name) {
   int CC;
 
-  if (Name == "at")
-    return getATReg();
+  if (Name == "at") {
+    // If noat is set then the at register is 0, otherwise it's defined as a
+    // specific register.  Warn if the assembler is free to use it.
+    if (Options.getATRegNum() != 0)
+      Warning(getLexer().getLoc(), "Used $at without \".set noat\"");
+    return 1;
+  }
 
   CC = StringSwitch<unsigned>(Name)
            .Case("zero", 0)
@@ -1039,6 +1044,10 @@ int MipsAsmParser::matchCPURegisterName(StringRef Name) {
              .Case("s8", 30)
              .Default(-1);
 
+  if ((CC != 0) && ((int)Options.getATRegNum() == CC))
+      Warning(getLexer().getLoc(), Twine("Used $") + Name + " with \".set at=$"
+          + Name + "\"");
+
   return CC;
 }
 
index 828175a223a7fb93bfc0e5884f63394b1d26a217..be528c977e9d3e2d7fe965fbd658adacc5bcadb9 100644 (file)
@@ -2,7 +2,7 @@
 # RUN: FileCheck %s
 # Check that the assembler can handle the documented syntax
 # for ".set at" and set the correct value.
-
+# XFAIL:
     .text
 foo:
 # CHECK:   jr    $1                      # encoding: [0x08,0x00,0x20,0x00]