[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Nate Begeman natebegeman at mac.com
Wed Jul 26 18:13:21 PDT 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAGISel.cpp updated: 1.259 -> 1.260
---
Log message:

Support jump tables when in PIC relocation model


---
Diffs of the changes:  (+10 -4)

 SelectionDAGISel.cpp |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.259 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.260
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.259	Thu Jul 20 14:02:21 2006
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Jul 26 20:13:04 2006
@@ -850,9 +850,15 @@
   SDOperand Copy = DAG.getCopyFromReg(getRoot(), JT.Reg, PTy);
   SDOperand IDX = DAG.getNode(ISD::MUL, PTy, Copy,
                               DAG.getConstant(PTyBytes, PTy));
-  SDOperand ADD = DAG.getNode(ISD::ADD, PTy, IDX, DAG.getJumpTable(JT.JTI,PTy));
+  SDOperand TAB = DAG.getJumpTable(JT.JTI,PTy);
+  SDOperand ADD = DAG.getNode(ISD::ADD, PTy, IDX, TAB);
   SDOperand LD  = DAG.getLoad(PTy, Copy.getValue(1), ADD, DAG.getSrcValue(0));
-  DAG.setRoot(DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), LD));
+  if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    ADD = DAG.getNode(ISD::ADD, PTy, LD.getValue(0), TAB);
+    DAG.setRoot(DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), ADD));
+  } else {
+    DAG.setRoot(DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), LD));
+  }
 }
 
 void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
@@ -896,20 +902,20 @@
   // to represent the switch.
   MachineFunction *CurMF = CurMBB->getParent();
   const BasicBlock *LLVMBB = CurMBB->getBasicBlock();
-  Reloc::Model Relocs = TLI.getTargetMachine().getRelocationModel();
 
   // If the switch has more than 5 blocks, and at least 31.25% dense, and the 
   // target supports indirect branches, then emit a jump table rather than 
   // lowering the switch to a binary tree of conditional branches.
   // FIXME: Make this work with PIC code
   if (TLI.isOperationLegal(ISD::BRIND, TLI.getPointerTy()) &&
-      (Relocs == Reloc::Static || Relocs == Reloc::DynamicNoPIC) &&
       Cases.size() > 5) {
     uint64_t First = cast<ConstantIntegral>(Cases.front().first)->getRawValue();
     uint64_t Last  = cast<ConstantIntegral>(Cases.back().first)->getRawValue();
     double Density = (double)Cases.size() / (double)((Last - First) + 1ULL);
     
     if (Density >= 0.3125) {
+      Reloc::Model Relocs = TLI.getTargetMachine().getRelocationModel();
+      
       // Create a new basic block to hold the code for loading the address
       // of the jump table, and jumping to it.  Update successor information;
       // we will either branch to the default case for the switch, or the jump






More information about the llvm-commits mailing list