[llvm] r266608 - [mips][ias] Prevent double-filling of delay slots by generating '.set noreorder' regions.

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 18 05:35:39 PDT 2016


Author: dsanders
Date: Mon Apr 18 07:35:36 2016
New Revision: 266608

URL: http://llvm.org/viewvc/llvm-project?rev=266608&view=rev
Log:
[mips][ias] Prevent double-filling of delay slots by generating '.set noreorder' regions.

Summary:
When clang is given -save-temps or -via-file-asm, any inline assembly in
the source is parsed twice. Once by the compiler, and again by the
assembler. We must take care to ensure that this doesn't lead to
double-filling delay slots.

Reviewers: sdardis, vkalintiris

Subscribers: dsanders, sdardis, llvm-commits

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

Added:
    llvm/trunk/test/MC/Mips/double-expand.s
Modified:
    llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=266608&r1=266607&r2=266608&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Mon Apr 18 07:35:36 2016
@@ -1930,6 +1930,11 @@ bool MipsAsmParser::processInstruction(M
     }
   }
 
+  bool FillDelaySlot =
+      MCID.hasDelaySlot() && AssemblerOptions.back()->isReorder();
+  if (FillDelaySlot)
+    getTargetStreamer().emitDirectiveSetNoReorder();
+
   MacroExpanderResultTy ExpandResult =
       tryExpandInstruction(Inst, IDLoc, Out, STI);
   switch (ExpandResult) {
@@ -1944,8 +1949,10 @@ bool MipsAsmParser::processInstruction(M
 
   // If this instruction has a delay slot and .set reorder is active,
   // emit a NOP after it.
-  if (MCID.hasDelaySlot() && AssemblerOptions.back()->isReorder())
+  if (FillDelaySlot) {
     createNop(hasShortDelaySlot(Inst.getOpcode()), IDLoc, Out, STI);
+    getTargetStreamer().emitDirectiveSetReorder();
+  }
 
   if ((Inst.getOpcode() == Mips::JalOneReg ||
        Inst.getOpcode() == Mips::JalTwoReg || ExpandedJalSym) &&

Added: llvm/trunk/test/MC/Mips/double-expand.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/double-expand.s?rev=266608&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/double-expand.s (added)
+++ llvm/trunk/test/MC/Mips/double-expand.s Mon Apr 18 07:35:36 2016
@@ -0,0 +1,10 @@
+# RUN: llvm-mc -triple=mipsel-unknown-linux < %s | FileCheck %s
+# RUN: llvm-mc -triple=mipsel-unknown-linux < %s | \
+# RUN:     llvm-mc -triple=mipsel-unknown-linux | FileCheck %s
+
+# CHECK: bnez $2, foo
+# CHECK: nop
+# CHECK-NOT: nop
+
+        .text
+	bnez $2, foo




More information about the llvm-commits mailing list