ARM Pseudo-ize tBR_JTr.
authorJim Grosbach <grosbach@apple.com>
Mon, 29 Nov 2010 19:32:47 +0000 (19:32 +0000)
committerJim Grosbach <grosbach@apple.com>
Mon, 29 Nov 2010 19:32:47 +0000 (19:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120310 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMInstrFormats.td
lib/Target/ARM/ARMInstrInfo.td
lib/Target/ARM/ARMInstrThumb.td
lib/Target/ARM/InstPrinter/ARMInstPrinter.h

index 84ddab99aaa370385a62a210f8b6ba80addb1cf9..da1c087c7fe35f8188a8cc229604f9a4e19b903e 100644 (file)
@@ -936,23 +936,13 @@ void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
     EmitJump2Table(MI);
     return;
   }
-  case ARM::tBR_JTr: {
-    // Lower and emit the instruction itself, then the jump table following it.
-    MCInst TmpInst;
-    // FIXME: The branch instruction is really a pseudo. We should xform it
-    // explicitly.
-    LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
-    OutStreamer.EmitInstruction(TmpInst);
-
-    // Output the data for the jump table itself
-    EmitJumpTable(MI);
-    return;
-  }
+  case ARM::tBR_JTr:
   case ARM::BR_JTr: {
     // Lower and emit the instruction itself, then the jump table following it.
     // mov pc, target
     MCInst TmpInst;
-    TmpInst.setOpcode(ARM::MOVr);
+    unsigned Opc = MI->getOpcode() == ARM::BR_JTr ? ARM::MOVr : ARM::tMOVr;
+    TmpInst.setOpcode(Opc);
     TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
     TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
     // Add predicate operands.
@@ -960,6 +950,10 @@ void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
     TmpInst.addOperand(MCOperand::CreateReg(0));
     OutStreamer.EmitInstruction(TmpInst);
 
+    // Make sure the Thumb jump table is 4-byte aligned.
+    if (Opc == ARM::tMOVr)
+      EmitAlignment(2);
+
     // Output the data for the jump table itself
     EmitJumpTable(MI);
     return;
index a5f89d6e49f9677ffba5aa03fa1a8a4830063a77..04c9b0e52af3ec76fd6fc1fc1362267727d0f160 100644 (file)
@@ -255,6 +255,13 @@ class ARMPseudoInst<dag oops, dag iops, InstrItinClass itin,
   list<Predicate> Predicates = [IsARM];
 }
 
+// PseudoInst that's Thumb-mode only.
+class tPseudoInst<dag oops, dag iops, SizeFlagVal sz, InstrItinClass itin,
+                    list<dag> pattern>
+  : PseudoInst<oops, iops, itin, pattern> {
+  let SZ = sz;
+  list<Predicate> Predicates = [IsThumb];
+}
 
 // Almost all ARM instructions are predicable.
 class I<dag oops, dag iops, AddrMode am, SizeFlagVal sz,
@@ -816,9 +823,6 @@ class T1I<dag oops, dag iops, InstrItinClass itin,
 class T1Ix2<dag oops, dag iops, InstrItinClass itin,
             string asm, list<dag> pattern>
   : Thumb1I<oops, iops, AddrModeNone, Size4Bytes, itin, asm, "", pattern>;
-class T1JTI<dag oops, dag iops, InstrItinClass itin,
-            string asm, list<dag> pattern>
-  : Thumb1I<oops, iops, AddrModeNone, SizeSpecial, itin, asm, "", pattern>;
 
 // Two-address instructions
 class T1It<dag oops, dag iops, InstrItinClass itin,
index e09170f631af8cb7117ffc0ba07007d93c4434c2..61ab5496e6e83894949aa125f1538aeadde71b7c 100644 (file)
@@ -333,9 +333,6 @@ def cpinst_operand : Operand<i32> {
   let PrintMethod = "printCPInstOperand";
 }
 
-def jtblock_operand : Operand<i32> {
-  let PrintMethod = "printJTBlockOperand";
-}
 def jt2block_operand : Operand<i32> {
   let PrintMethod = "printJT2BlockOperand";
 }
index 3af893411963dd354ec2156e7433e5ba257951f3..568cbc6c6c694da21c4640e711aa79f76238ea39 100644 (file)
@@ -439,14 +439,11 @@ let isBranch = 1, isTerminator = 1 in {
   def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
                     "bl\t$target",[]>;
 
-  let isCodeGenOnly = 1 in
-  def tBR_JTr : T1JTI<(outs),
-                      (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id),
-                      IIC_Br, "mov\tpc, $target\n\t.align\t2$jt",
-                      [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>,
-                Encoding16 {
-    let Inst{15-7} = 0b010001101;
-    let Inst{2-0} = 0b111;
+  def tBR_JTr : tPseudoInst<(outs),
+                      (ins tGPR:$target, i32imm:$jt, i32imm:$id),
+                      Size2Bytes, IIC_Br,
+                      [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
+    list<Predicate> Predicates = [IsThumb, IsThumb1Only];
   }
   }
 }
index e69a0e0d8f70469526c1c5bb7eecaa65bad32d7a..55605ead0678e64cd65ac7b9092204221b233f17 100644 (file)
@@ -96,7 +96,6 @@ public:
   void printRegisterList(const MCInst *MI, unsigned OpNum, raw_ostream &O);
   // The jump table instructions have custom handling in ARMAsmPrinter
   // to output the jump table. Nothing further is necessary here.
-  void printJTBlockOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O) {}
   void printJT2BlockOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O) {}
   void printTBAddrMode(const MCInst *MI, unsigned OpNum, raw_ostream &O);
   void printNoHashImmediate(const MCInst *MI, unsigned OpNum, raw_ostream &O);