llvm.org GIT mirror llvm / d85ac4d
Thumb jumptable support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33568 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
3 changed file(s) with 32 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
646646 << getFunctionNumber() << '_' << JTI << '_' << MO2.getImmedValue();
647647 } else
648648 printBasicBlockLabel(MBB, false, false);
649 O << '\n';
649 if (i != e-1)
650 O << '\n';
650651 }
651652 }
652653
351351 return MI->getOperand(2).getImm();
352352 case ARM::BR_JTr:
353353 case ARM::BR_JTm:
354 case ARM::BR_JTadd: {
354 case ARM::BR_JTadd:
355 case ARM::tBR_JTr: {
355356 // These are jumptable branches, i.e. a branch followed by an inlined
356357 // jumptable. The size is 4 + 4 * number of entries.
357358 unsigned JTI = MI->getOperand(MI->getNumOperands()-2).getJumpTableIndex();
359360 MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
360361 const std::vector &JT = MJTI->getJumpTables();
361362 assert(JTI < JT.size());
363 // Thumb instructions are 2 byte aligned, but JT entries are 4 byte
364 // 4 aligned. The assembler / linker may add 2 byte padding just before
365 // the JT entries. Use + 4 even for tBR_JTr to purposely over-estimate
366 // the size the jumptable.
367 // FIXME: If we know the size of the function is less than (1 << 16) *2
368 // bytes, we can use 16-bit entries instead. Then there won't be an
369 // alignment issue.
362370 return getNumJTEntries(JT, JTI) * 4 + 4;
363371 }
364372 default:
5454 // BL, BLX(1) are translated by assembler into two instructions
5555 class TIx2 pattern>
5656 : ThumbI;
57
58 // BR_JT instructions
59 class TJTI pattern>
60 : ThumbI;
5761
5862 def imm_neg_XFORM : SDNodeXForm
5963 return CurDAG->getTargetConstant(-(int)N->getValue(), MVT::i32);
187191 [(ARMcall_nolink GPR:$dst)]>;
188192 }
189193
190 let isBranch = 1, isTerminator = 1, isBarrier = 1 in
194 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
191195 def tB : TI<(ops brtarget:$dst), "b $dst", [(br bb:$dst)]>;
196
197 def tBR_JTr : TJTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
198 "cpy pc, $dst \n\t.align\t2\n$jt",
199 [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
200 }
192201
193202 let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
194203 def tBcc : TI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
476485 "add $dst, pc, #PCRELV${:uid}")),
477486 []>;
478487
488 def tLEApcrelJT : TI<(ops GPR:$dst, i32imm:$label, i32imm:$id),
489 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
490 "${:private}PCRELL${:uid}+4))\n"),
491 !strconcat("${:private}PCRELL${:uid}:\n\t",
492 "add $dst, pc, #PCRELV${:uid}")),
493 []>;
494
479495 //===----------------------------------------------------------------------===//
480496 // Non-Instruction Patterns
481497 //
487503 (tLEApcrelCall tglobaladdr :$dst)>;
488504 def : ThumbPat<(ARMWrapperCall texternalsym:$dst),
489505 (tLEApcrelCall texternalsym:$dst)>;
506
507 // JumpTable
508 def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
509 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
490510
491511 // Direct calls
492512 def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;