[llvm] r324324 - [ARM][AArch64] Add CSDB speculation barrier instruction

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 01:24:48 PST 2018


Author: olista01
Date: Tue Feb  6 01:24:47 2018
New Revision: 324324

URL: http://llvm.org/viewvc/llvm-project?rev=324324&view=rev
Log:
[ARM][AArch64] Add CSDB speculation barrier instruction

This adds the CSDB instruction, which is a new barrier instruction
described by the whitepaper at [1].

This is in encoding space which was previously executed as a NOP, so it is
available for all targets that have the relevant NOP encoding space. This
matches the binutils behaviour for these instructions [2][3].

[1] https://developer.arm.com/support/security-update
[2] https://sourceware.org/ml/binutils/2018-01/msg00116.html
[3] https://sourceware.org/ml/binutils/2018-01/msg00120.html


Added:
    llvm/trunk/test/MC/AArch64/csdb.s
    llvm/trunk/test/MC/ARM/csdb-errors.s
    llvm/trunk/test/MC/ARM/csdb.s
    llvm/trunk/test/MC/Disassembler/AArch64/csdb.txt
    llvm/trunk/test/MC/Disassembler/ARM/csdb-arm.txt
    llvm/trunk/test/MC/Disassembler/ARM/csdb-thumb.txt
Modified:
    llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.td
    llvm/trunk/lib/Target/ARM/ARMInstrInfo.td
    llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.td?rev=324324&r1=324323&r2=324324&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.td (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.td Tue Feb  6 01:24:47 2018
@@ -420,6 +420,7 @@ def : InstAlias<"wfi",  (HINT 0b011)>;
 def : InstAlias<"sev",  (HINT 0b100)>;
 def : InstAlias<"sevl", (HINT 0b101)>;
 def : InstAlias<"esb",  (HINT 0b10000)>, Requires<[HasRAS]>;
+def : InstAlias<"csdb", (HINT 20)>;
 
 // v8.2a Statistical Profiling extension
 def : InstAlias<"psb $op",  (HINT psbhint_op:$op)>, Requires<[HasSPE]>;

Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.td?rev=324324&r1=324323&r2=324324&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMInstrInfo.td (original)
+++ llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Tue Feb  6 01:24:47 2018
@@ -2004,6 +2004,7 @@ def : InstAlias<"wfi$p", (HINT 3, pred:$
 def : InstAlias<"sev$p", (HINT 4, pred:$p)>, Requires<[IsARM, HasV6K]>;
 def : InstAlias<"sevl$p", (HINT 5, pred:$p)>, Requires<[IsARM, HasV8]>;
 def : InstAlias<"esb$p", (HINT 16, pred:$p)>, Requires<[IsARM, HasRAS]>;
+def : InstAlias<"csdb$p", (HINT 20, pred:$p)>, Requires<[IsARM, HasV6K]>;
 
 def SEL : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm, NoItinerary, "sel",
              "\t$Rd, $Rn, $Rm",

Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=324324&r1=324323&r2=324324&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original)
+++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Tue Feb  6 01:24:47 2018
@@ -3700,6 +3700,8 @@ def : t2InstAlias<"esb$p.w", (t2HINT 16,
 def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
   let Predicates = [IsThumb2, HasRAS];
 }
+def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
+def : t2InstAlias<"csdb$p",   (t2HINT 20, pred:$p), 1>;
 
 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
                 [(int_arm_dbg imm0_15:$opt)]> {

Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=324324&r1=324323&r2=324324&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Feb  6 01:24:47 2018
@@ -6616,19 +6616,22 @@ bool ARMAsmParser::validateInstruction(M
     break;
   }
   case ARM::HINT:
-  case ARM::t2HINT:
-    if (hasRAS()) {
-      // ESB is not predicable (pred must be AL)
-      unsigned Imm8 = Inst.getOperand(0).getImm();
-      unsigned Pred = Inst.getOperand(1).getImm();
-      if (Imm8 == 0x10 && Pred != ARMCC::AL)
-        return Error(Operands[1]->getStartLoc(), "instruction 'esb' is not "
-                                                 "predicable, but condition "
-                                                 "code specified");
-    }
-    // Without the RAS extension, this behaves as any other unallocated hint.
+  case ARM::t2HINT: {
+    unsigned Imm8 = Inst.getOperand(0).getImm();
+    unsigned Pred = Inst.getOperand(1).getImm();
+    // ESB is not predicable (pred must be AL). Without the RAS extension, this
+    // behaves as any other unallocated hint.
+    if (Imm8 == 0x10 && Pred != ARMCC::AL && hasRAS())
+      return Error(Operands[1]->getStartLoc(), "instruction 'esb' is not "
+                                               "predicable, but condition "
+                                               "code specified");
+    if (Imm8 == 0x14 && Pred != ARMCC::AL)
+      return Error(Operands[1]->getStartLoc(), "instruction 'csdb' is not "
+                                               "predicable, but condition "
+                                               "code specified");
     break;
   }
+  }
 
   return false;
 }

Added: llvm/trunk/test/MC/AArch64/csdb.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/csdb.s?rev=324324&view=auto
==============================================================================
--- llvm/trunk/test/MC/AArch64/csdb.s (added)
+++ llvm/trunk/test/MC/AArch64/csdb.s Tue Feb  6 01:24:47 2018
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple aarch64-none-linux-gnu -show-encoding < %s | FileCheck %s
+
+  csdb
+// CHECK: csdb   // encoding: [0x9f,0x22,0x03,0xd5]

Added: llvm/trunk/test/MC/ARM/csdb-errors.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/csdb-errors.s?rev=324324&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/csdb-errors.s (added)
+++ llvm/trunk/test/MC/ARM/csdb-errors.s Tue Feb  6 01:24:47 2018
@@ -0,0 +1,6 @@
+// RUN: not llvm-mc -triple   armv8a-none-eabi %s 2>&1 | FileCheck %s
+// RUN: not llvm-mc -triple thumbv8a-none-eabi %s 2>&1 | FileCheck %s
+
+  it eq
+  csdbeq
+// CHECK: error: instruction 'csdb' is not predicable, but condition code specified

Added: llvm/trunk/test/MC/ARM/csdb.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/csdb.s?rev=324324&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/csdb.s (added)
+++ llvm/trunk/test/MC/ARM/csdb.s Tue Feb  6 01:24:47 2018
@@ -0,0 +1,8 @@
+@ RUN:     llvm-mc -triple   armv8a-none-eabi -show-encoding %s      | FileCheck %s --check-prefix=ARM
+@ RUN:     llvm-mc -triple thumbv8a-none-eabi -show-encoding %s      | FileCheck %s --check-prefix=THUMB
+@ RUN: not llvm-mc -triple thumbv6m-none-eabi -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR
+
+  csdb
+@ ARM:   csdb   @ encoding: [0x14,0xf0,0x20,0xe3]
+@ THUMB: csdb   @ encoding: [0xaf,0xf3,0x14,0x80]
+@ ERROR: error: instruction requires: thumb2

Added: llvm/trunk/test/MC/Disassembler/AArch64/csdb.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/AArch64/csdb.txt?rev=324324&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/AArch64/csdb.txt (added)
+++ llvm/trunk/test/MC/Disassembler/AArch64/csdb.txt Tue Feb  6 01:24:47 2018
@@ -0,0 +1,4 @@
+# RUN: llvm-mc -triple aarch64-none-linux-gnu --disassemble < %s | FileCheck %s
+
+[0x9f,0x22,0x03,0xd5]
+# CHECK: csdb

Added: llvm/trunk/test/MC/Disassembler/ARM/csdb-arm.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/ARM/csdb-arm.txt?rev=324324&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/ARM/csdb-arm.txt (added)
+++ llvm/trunk/test/MC/Disassembler/ARM/csdb-arm.txt Tue Feb  6 01:24:47 2018
@@ -0,0 +1,4 @@
+# RUN: llvm-mc < %s -triple armv8a-none-eabi -disassemble | FileCheck %s
+
+[0x14,0xf0,0x20,0xe3]
+# CHECK: csdb

Added: llvm/trunk/test/MC/Disassembler/ARM/csdb-thumb.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/ARM/csdb-thumb.txt?rev=324324&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/ARM/csdb-thumb.txt (added)
+++ llvm/trunk/test/MC/Disassembler/ARM/csdb-thumb.txt Tue Feb  6 01:24:47 2018
@@ -0,0 +1,4 @@
+# RUN: llvm-mc < %s -triple thumbv8a-none-eabi -disassemble | FileCheck %s
+
+[0xaf,0xf3,0x14,0x80]
+# CHECK: csdb




More information about the llvm-commits mailing list