robert muth
2009-Feb-17 22:04 UTC
[LLVMdev] ARM backend playing with alternative jump table implementations
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>
Evan Cheng
2009-Feb-19 06:36 UTC
[LLVMdev] ARM backend playing with alternative jump table implementations
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 > .textOk. 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
Maybe Matching Threads
- [LLVMdev] patch for llc/ARM: added mechanism to move switch tables from .text -> .data; also cleanup and documentation
- [LLVMdev] patch for llc/ARM: added mechanism to move switch tables from .text -> .data; also cleanup and documentation
- [LLVMdev] patch for llc/ARM: added mechanism to move switch tables from .text -> .data; also cleanup and documentation
- [LLVMdev] patch for llc/ARM: added mechanism to move switch tables from .text -> .data; also cleanup and documentation
- [LLVMdev] jump table x constant pool