summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Carter <jcarter@mips.com>2012-09-06 00:43:26 +0000
committerJack Carter <jcarter@mips.com>2012-09-06 00:43:26 +0000
commitad51a4a5984a365d671ddfe9eaa23d2e12ee4281 (patch)
tree4f2d1ccc1aca0385f91e569939add84ddc0ba2fe
parent30eac71f3b16e068d5ae38668a5219b988db07ae (diff)
downloadllvm-ad51a4a5984a365d671ddfe9eaa23d2e12ee4281.tar.gz
llvm-ad51a4a5984a365d671ddfe9eaa23d2e12ee4281.tar.bz2
llvm-ad51a4a5984a365d671ddfe9eaa23d2e12ee4281.tar.xz
Mips specific llvm assembler support for branch and jump instructions.
Test case included. Contributer: Vladimir Medic git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163277 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp11
-rw-r--r--test/MC/Mips/mips-jump-instructions.s64
2 files changed, 73 insertions, 2 deletions
diff --git a/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp b/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
index 8dab62d518..1d7370a04f 100644
--- a/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
+++ b/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
@@ -143,7 +143,11 @@ getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
SmallVectorImpl<MCFixup> &Fixups) const {
const MCOperand &MO = MI.getOperand(OpNo);
- assert(MO.isExpr() && "getBranchTargetOpValue expects only expressions");
+
+ // If the destination is an immediate, we have nothing to do.
+ if (MO.isImm()) return MO.getImm();
+ assert(MO.isExpr() &&
+ "getBranchTargetOpValue expects only expressions or immediates");
const MCExpr *Expr = MO.getExpr();
Fixups.push_back(MCFixup::Create(0, Expr,
@@ -159,7 +163,10 @@ getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
SmallVectorImpl<MCFixup> &Fixups) const {
const MCOperand &MO = MI.getOperand(OpNo);
- assert(MO.isExpr() && "getJumpTargetOpValue expects only expressions");
+ // If the destination is an immediate, we have nothing to do.
+ if (MO.isImm()) return MO.getImm();
+ assert(MO.isExpr() &&
+ "getJumpTargetOpValue expects only expressions or an immediate");
const MCExpr *Expr = MO.getExpr();
Fixups.push_back(MCFixup::Create(0, Expr,
diff --git a/test/MC/Mips/mips-jump-instructions.s b/test/MC/Mips/mips-jump-instructions.s
new file mode 100644
index 0000000000..5188751fe8
--- /dev/null
+++ b/test/MC/Mips/mips-jump-instructions.s
@@ -0,0 +1,64 @@
+# RUN: llvm-mc %s -triple=mipsel-unknown-linux -show-encoding -mcpu=mips32r2 | FileCheck %s
+# Check that the assembler can handle the documented syntax
+# for jumps and branches.
+# CHECK: .section __TEXT,__text,regular,pure_instructions
+#------------------------------------------------------------------------------
+# Branch instructions
+#------------------------------------------------------------------------------
+# CHECK: b 1332 # encoding: [0x34,0x05,0x00,0x10]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: bc1f 1332 # encoding: [0x34,0x05,0x00,0x45]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: bc1t 1332 # encoding: [0x34,0x05,0x01,0x45]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: beq $9, $6, 1332 # encoding: [0x34,0x05,0x26,0x11]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: bgez $6, 1332 # encoding: [0x34,0x05,0xc1,0x04]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: bgezal $6, 1332 # encoding: [0x34,0x05,0xd1,0x04]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: bgtz $6, 1332 # encoding: [0x34,0x05,0xc0,0x1c]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: blez $6, 1332 # encoding: [0x34,0x05,0xc0,0x18]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: bne $9, $6, 1332 # encoding: [0x34,0x05,0x26,0x15]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+ b 1332
+ nop
+ bc1f 1332
+ nop
+ bc1t 1332
+ nop
+ beq $9,$6,1332
+ nop
+ bgez $6,1332
+ nop
+ bgezal $6,1332
+ nop
+ bgtz $6,1332
+ nop
+ blez $6,1332
+ nop
+ bne $9,$6,1332
+ nop
+
+end_of_code:
+#------------------------------------------------------------------------------
+# Jump instructions
+#------------------------------------------------------------------------------
+# CHECK: j 1328 # encoding: [0x30,0x05,0x00,0x08]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: jal 1328 # encoding: [0x30,0x05,0x00,0x0c]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: jalr $6 # encoding: [0x09,0xf8,0xc0,0x00]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: jr $7 # encoding: [0x08,0x00,0xe0,0x00]
+
+
+ j 1328
+ nop
+ jal 1328
+ nop
+ jalr $6
+ nop
+ jr $7