[LLVMdev] ARM backend playing with alternative jump table implementations
robert muth
robert at muth.org
Tue Feb 17 14:04:04 PST 2009
Hi list:
I have been trying to get my feet wet with the ARM backend.
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
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.
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090217/664f8ae8/attachment.html>
More information about the llvm-dev
mailing list