[LLVMdev] ARM backend playing with alternative jump table implementations
Evan Cheng
echeng at apple.com
Wed Feb 18 22:36:25 PST 2009
On Feb 17, 2009, at 2:04 PM, robert muth wrote:
> Hi list:
>
> I have been trying to get my feet wet with the ARM backend.
Welcome.
>
> As a warmup exercise I wanted to be able to move
> jumptables especially large ones out of the code section.
> Currently the idiom for jump tables loooks like this
>
> // .set PCRELV0, (.LJTI9_0_0-(.LPCRELL0+8))
> // .LPCRELL0:
> // add r3, pc, #PCRELV0
> // ldr pc, [r3, +r0, lsl #2]
> // .LJTI9_0_0:
> // .long .LBB9_2
> // .long .LBB9_5
> // .long .LBB9_7
> // .long .LBB9_4
> // .long .LBB9_8
>
> I would like to be able to change this to something like:
>
> ldr r3, .POOL_ADDR
> ldr pc, [r3, +r0, lsl #2
>
> .POOL_ADDR:
> .text .LJTI9_0_0:
>
> .data
> .LJTI9_0_0:
> .long .LBB9_2
> .long .LBB9_5
> .long .LBB9_7
> .long .LBB9_4
> .long .LBB9_8
> .text
Ok. I think it's a worthwhile alternative jumptable codegen scheme.
>
>
> The code for the lowering lives mostly in SDValue
> ARMTargetLowering::LowerBR_JT
> with some more heavy lifting done by ARMISD::WrapperJT
> My attempts at this are marked in the code below.
> My problem is to come up with the right item/value to put into the
> constant pool.
Off the top of my head, I think you need to enhance
ARMConstantPoolValue. Perhaps add a new ARMCPKind for jumptable base
address. You also have to encode the jumptable id in
ARMConstantPoolValue.
Evan
>
> SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) {
> SDValue Chain = Op.getOperand(0);
> SDValue Table = Op.getOperand(1);
> SDValue Index = Op.getOperand(2);
> DebugLoc dl = Op.getDebugLoc();
>
> MVT PTy = getPointerTy();
> JumpTableSDNode *JT = cast<JumpTableSDNode>(Table);
> ARMFunctionInfo *AFI =
> DAG.getMachineFunction().getInfo<ARMFunctionInfo>();
> SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy);
> SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy);
>
> #if 1
> // @@ GET TABLE BASE: current code
> Table = DAG.getNode(ARMISD::WrapperJT, MVT::i32, JTI, UId);
> #else
> // @ MY ATTEMPT AT MOVING THIS OUT
> ARMConstantPoolValue *CPV = new
> ARMConstantPoolValue("a_jump_table", 666);
> SDValue TableValue = DAG.getTargetConstantPool(CPV, PTy, 2);
> SDValue CPAddr = DAG.getNode(ARMISD::Wrapper, MVT::i32, TableValue);
> Table = DAG.getLoad(PTy, dl, DAG.getEntryNode(), CPAddr, NULL, 0);
> #endif
>
> Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4,
> PTy));
> //Index = DAG.getNode(ISD::MUL, dl, PTy, TableAddress,
> DAG.getConstant(4, PTy));
> SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index,
> Table);SDValue APTy, Index, Table);
>
>
>
> Any help would be greatly appreciated.
>
> Robert
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list