[mips] [IAS] Enforce .set nomacro.
authorToma Tabacu <toma.tabacu@imgtec.com>
Thu, 14 May 2015 14:51:32 +0000 (14:51 +0000)
committerToma Tabacu <toma.tabacu@imgtec.com>
Thu, 14 May 2015 14:51:32 +0000 (14:51 +0000)
Summary: When used, ".set nomacro" causes warning messages to be reported when we expand pseudo-instructions to multiple machine instructions.

Reviewers: dsanders

Reviewed By: dsanders

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9564

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

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
test/MC/Mips/set-nomacro-micromips.s [new file with mode: 0644]
test/MC/Mips/set-nomacro.s [new file with mode: 0644]

index c503083028aed1c91ee4513c83abcbd19c7c17a8..6a006caffd878869998062b20225367b4ffbfc87 100644 (file)
@@ -1759,6 +1759,9 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
     tmpInst.addOperand(MCOperand::createImm(ImmValue));
     Instructions.push_back(tmpInst);
   } else if ((ImmValue & 0xffffffff) == ImmValue) {
+    if (!AssemblerOptions.back()->isMacro())
+      Warning(IDLoc, "macro instruction expanded into multiple instructions");
+
     // For all other values which are representable as a 32-bit integer:
     // li d,j => lui d,hi16(j)
     //           ori d,d,lo16(j)
@@ -1779,6 +1782,8 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
       Error(IDLoc, "instruction requires a 32-bit immediate");
       return true;
     }
+    if (!AssemblerOptions.back()->isMacro())
+      Warning(IDLoc, "macro instruction expanded into multiple instructions");
 
     //            <-------  lo32 ------>
     // <-------  hi32 ------>
@@ -1812,6 +1817,8 @@ bool MipsAsmParser::loadImmediate(int64_t ImmValue, unsigned DstReg,
       Error(IDLoc, "instruction requires a 32-bit immediate");
       return true;
     }
+    if (!AssemblerOptions.back()->isMacro())
+      Warning(IDLoc, "macro instruction expanded into multiple instructions");
 
     // <-------  hi32 ------> <-------  lo32 ------>
     // <- hi16 ->                        <- lo16 ->
@@ -1914,6 +1921,9 @@ MipsAsmParser::expandLoadAddressImm(MCInst &Inst, bool Is32BitImm, SMLoc IDLoc,
 void MipsAsmParser::expandLoadAddressSym(
     const MCOperand &DstRegOp, const MCOperand &SymOp, bool Is32BitSym,
     SMLoc IDLoc, SmallVectorImpl<MCInst> &Instructions) {
+  if (!AssemblerOptions.back()->isMacro())
+    Warning(IDLoc, "macro instruction expanded into multiple instructions");
+
   if (Is32BitSym && isABI_N64())
     Warning(IDLoc, "instruction loads the 32-bit address of a 64-bit symbol");
 
diff --git a/test/MC/Mips/set-nomacro-micromips.s b/test/MC/Mips/set-nomacro-micromips.s
new file mode 100644 (file)
index 0000000..c4d8b7c
--- /dev/null
@@ -0,0 +1,33 @@
+# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=micromips 2>&1 | FileCheck %s
+
+  .text
+  .type main, @function
+  .set micromips
+main:
+# CHECK-NOT: warning: macro instruction expanded into multiple instructions
+  .set macro
+  b 132
+  b 1332
+  b bar
+
+  lwm $16, $17, 8($sp)
+  swm $16, $17, 8($sp)
+
+  add $4, $5, $6
+
+  .set noreorder
+  .set nomacro
+  b 132
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  b 1332
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  b bar
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+
+  lwm $16, $17, 8($sp)
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  swm $16, $17, 8($sp)
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+
+  add $4, $5, $6
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
diff --git a/test/MC/Mips/set-nomacro.s b/test/MC/Mips/set-nomacro.s
new file mode 100644 (file)
index 0000000..d81048f
--- /dev/null
@@ -0,0 +1,46 @@
+# RUN: llvm-mc %s -arch=mips -mcpu=mips32 2>&1 | FileCheck %s
+
+# CHECK-NOT: warning: macro instruction expanded into multiple instructions
+  .set macro
+  li  $8, -16
+  li  $8, 16
+  li  $8, 161616
+
+  la  $8, 16
+  la  $8, 161616
+  la  $8, 16($9)
+  la  $8, 161616($9)
+  la  $8, symbol
+
+  jal $25
+  jal $4, $25
+
+  add $4, $5, $6
+
+  .set noreorder
+  .set nomacro
+  li  $8, -16
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  li  $8, 16
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  li  $8, 161616
+# CHECK: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+
+  la  $8, 16
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  la  $8, 161616
+# CHECK: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  la  $8, 16($9)
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  la  $8, 161616($9)
+# CHECK: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  la  $8, symbol
+# CHECK: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+
+  jal $25
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+  jal $4, $25
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions
+
+  add $4, $5, $6
+# CHECK-NOT: [[@LINE-1]]:3: warning: macro instruction expanded into multiple instructions