Add support for other relocation bases to jump tables, as well as custom asm directives
authorAndrew Lenharth <andrewl@lenharth.org>
Sun, 24 Sep 2006 19:45:58 +0000 (19:45 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Sun, 24 Sep 2006 19:45:58 +0000 (19:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30593 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAGNodes.h
include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/AsmPrinter.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Target/TargetAsmInfo.cpp

index b830dc3d845519685ff8633a5c697375e8607b16..99fd5917b7ab352a72bd7a5664570cd74b6a6ff2 100644 (file)
@@ -82,6 +82,9 @@ namespace ISD {
     Constant, ConstantFP,
     GlobalAddress, FrameIndex, JumpTable, ConstantPool, ExternalSymbol,
 
+    // The relocation value to add to the value loaded from a jump table
+    JumpTableRelocBase,
+
     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
     // simplification of the constant.
     TargetConstant,
index 6f63ba3a31ab40ea2dce55380205d8a23f60d03c..d3941ad61d2e179b2ed4c79385791d35159becfc 100644 (file)
@@ -108,6 +108,7 @@ namespace llvm {
     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
+    const char *JumpTableDirective;       // if used, the jump table reloc flag
 
     //===--- Alignment Information ----------------------------------------===//
 
@@ -323,6 +324,9 @@ namespace llvm {
     const char *getData64bitsDirective() const {
       return Data64bitsDirective;
     }
+    const char *getJumpTableDirective() const {
+      return JumpTableDirective;
+    }
     const char *getAlignDirective() const {
       return AlignDirective;
     }
index f6b4bfcbfe357a520f9c8417fd61503e36619827..bcdb393c239724e72c9a503e3f68eb54c9b54c0d 100644 (file)
@@ -187,7 +187,10 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
   // JTEntryDirective is a string to print sizeof(ptr) for non-PIC jump tables,
   // and 32 bits for PIC since PIC jump table entries are differences, not
   // pointers to blocks.
-  const char *JTEntryDirective = TAI->getData32bitsDirective();
+  // Use the architecture specific relocation directive, if it is set
+  const char *JTEntryDirective = TAI->getJumpTableDirective();
+  if (!JTEntryDirective)
+    JTEntryDirective = TAI->getData32bitsDirective();
   
   // Pick the directive to use to print the jump table entries, and switch to 
   // the appropriate section.
@@ -227,8 +230,10 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
           << '_' << i << "_set_" << JTBBs[ii]->getNumber();
       } else if (TM.getRelocationModel() == Reloc::PIC_) {
         printBasicBlockLabel(JTBBs[ii], false, false);
-        O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
-          << getFunctionNumber() << '_' << i;
+       //If the arch uses custom Jump Table directives, don't calc relative to JT
+       if (!TAI->getJumpTableDirective()) 
+         O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
+           << getFunctionNumber() << '_' << i;
       } else {
         printBasicBlockLabel(JTBBs[ii], false, false);
       }
index cb8588c0318af7653e80d8d2b1bd35bf175df3fa..9507e4be844aeef1efe07ada37e92a73b11a4cfe 100644 (file)
@@ -558,6 +558,17 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
 #endif
     assert(0 && "Do not know how to legalize this operator!");
     abort();
+  case ISD::JumpTableRelocBase:
+    switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
+    case TargetLowering::Custom:
+      Tmp1 = TLI.LowerOperation(Op, DAG);
+      if (Tmp1.Val) Result = Tmp1;
+      break;
+    default:
+      Result = LegalizeOp(Node->getOperand(0));
+      break;
+    }
+    break;
   case ISD::GlobalAddress:
   case ISD::ExternalSymbol:
   case ISD::ConstantPool:
index cf26eb2951271ded772830705a17ee5db6f2b4bb..27a45a1d5227bf431cc48f7e5830c9a38637369e 100644 (file)
@@ -868,8 +868,9 @@ void SelectionDAGLowering::visitJumpTable(SelectionDAGISel::JumpTable &JT) {
   SDOperand LD  = DAG.getLoad(isPIC ? MVT::i32 : PTy, Copy.getValue(1), ADD,
                               DAG.getSrcValue(0));
   if (isPIC) {
+    SDOperand Reloc = DAG.getNode(ISD::JumpTableRelocBase, PTy, TAB);
     ADD = DAG.getNode(ISD::ADD, PTy,
-        ((PTy != MVT::i32) ? DAG.getNode(ISD::SIGN_EXTEND, PTy, LD) : LD), TAB);
+        ((PTy != MVT::i32) ? DAG.getNode(ISD::SIGN_EXTEND, PTy, LD) : LD), Reloc);
     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));
index e5fc26ecb057f1853a7877d4c73e1fbc90087b13..6efcf4be2455242740ba020baf6c0b6d9fc1b005 100644 (file)
@@ -47,6 +47,7 @@ TargetAsmInfo::TargetAsmInfo() :
   ConstantPoolSection("\t.section .rodata\n"),
   JumpTableDataSection("\t.section .rodata\n"),
   JumpTableTextSection("\t.text\n"),
+  JumpTableDirective(0),
   StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
   StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
   FourByteConstantSection(0),