diff --git a/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h b/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h index d37a5b25fab99d9f947bd1ff22124742d80996cd..7d47714fd24fe6cd766b5b3782275653f6678c6e 100644 --- a/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h +++ b/llvm/include/llvm/CodeGen/MachineJumpTableInfo.h @@ -60,7 +60,11 @@ public: /// If the .set directive is supported, this is emitted as: /// .set L4_5_set_123, LBB123 - LJTI1_2 /// .word L4_5_set_123 - EK_LabelDifference32 + EK_LabelDifference32, + + /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the + /// TargetLowering::LowerCustomJumpTableEntry hook. + EK_Custom32 }; private: JTEntryKind EntryKind; diff --git a/llvm/include/llvm/Target/TargetLowering.h b/llvm/include/llvm/Target/TargetLowering.h index 662d65db63f0d6aaca3a0e3e17218ddaba3f8f5a..ab1c241542b8694c3de92aa8dce340db932a8cff 100644 --- a/llvm/include/llvm/Target/TargetLowering.h +++ b/llvm/include/llvm/Target/TargetLowering.h @@ -46,7 +46,10 @@ namespace llvm { class MachineFunction; class MachineFrameInfo; class MachineInstr; + class MachineJumpTableInfo; class MachineModuleInfo; + class MCContext; + class MCExpr; class DwarfWriter; class SDNode; class SDValue; @@ -757,10 +760,17 @@ public: /// MachineJumpTableInfo::JTEntryKind enum. virtual unsigned getJumpTableEncoding() const; + virtual const MCExpr * + LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, + const MachineBasicBlock *MBB, unsigned uid, + MCContext &Ctx) { + assert(0 && "Need to implement this hook if target has custom JTIs"); + } + /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC /// jumptable. virtual SDValue getPICJumpTableRelocBase(SDValue Table, - SelectionDAG &DAG) const; + SelectionDAG &DAG) const; /// isOffsetFoldingLegal - Return true if folding a constant offset /// with the given GlobalAddress is legal. It is frequently not legal in diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 28937797a81b94857ddad5baef0c126f65d325d9..fd6d182702bb4d5b168cc1f91d806c04dee22ce8 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -479,12 +479,10 @@ void AsmPrinter::EmitJumpTableInfo(MachineFunction &MF) { // Pick the directive to use to print the jump table entries, and switch to // the appropriate section. - TargetLowering *LoweringInfo = TM.getTargetLowering(); - const Function *F = MF.getFunction(); bool JTInDiffSection = false; if (F->isWeakForLinker() || - (IsPic && !LoweringInfo->usesGlobalOffsetTable())) { + (IsPic && !TM.getTargetLowering()->usesGlobalOffsetTable())) { // In PIC mode, we need to emit the jump table to the same section as the // function body itself, otherwise the label differences won't make sense. // We should also do if the section name is NULL or function is declared in @@ -546,12 +544,15 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, unsigned uid) const { const MCExpr *Value = 0; switch (MJTI->getEntryKind()) { + case MachineJumpTableInfo::EK_Custom32: + Value = TM.getTargetLowering()->LowerCustomJumpTableEntry(MJTI, MBB, uid, + OutContext); + break; case MachineJumpTableInfo::EK_BlockAddress: // EK_BlockAddress - Each entry is a plain address of block, e.g.: // .word LBB123 Value = MCSymbolRefExpr::Create(GetMBBSymbol(MBB->getNumber()), OutContext); break; - case MachineJumpTableInfo::EK_GPRel32BlockAddress: { // EK_GPRel32BlockAddress - Each entry is an address of block, encoded // with a relocation as gp-relative, e.g.: @@ -560,7 +561,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, OutStreamer.EmitGPRel32Value(MCSymbolRefExpr::Create(MBBSym, OutContext)); return; } - + case MachineJumpTableInfo::EK_LabelDifference32: { // EK_LabelDifference32 - Each entry is the address of the block minus // the address of the jump table. This is used for PIC jump tables where diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index bea0445b154f45f200c22614d900a8af5e14df53..cf3b8f056ad1318d3ac580c786d53809761ac579 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -544,6 +544,7 @@ unsigned MachineJumpTableInfo::getEntrySize(const TargetData &TD) const { return TD.getPointerSize(); case MachineJumpTableInfo::EK_GPRel32BlockAddress: case MachineJumpTableInfo::EK_LabelDifference32: + case MachineJumpTableInfo::EK_Custom32: return 4; } assert(0 && "Unknown jump table encoding!"); @@ -560,6 +561,7 @@ unsigned MachineJumpTableInfo::getEntryAlignment(const TargetData &TD) const { return TD.getPointerABIAlignment(); case MachineJumpTableInfo::EK_GPRel32BlockAddress: case MachineJumpTableInfo::EK_LabelDifference32: + case MachineJumpTableInfo::EK_Custom32: return TD.getABIIntegerTypeAlignment(32); } assert(0 && "Unknown jump table encoding!"); diff --git a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp index 291655353d48e34be314bb2c21f0b3f42cfcb813..4d5857414b924ebb19ade83dc3b3c7e15b899b17 100644 --- a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -1445,6 +1445,7 @@ void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI) { break; } + case MachineJumpTableInfo::EK_Custom32: case MachineJumpTableInfo::EK_GPRel32BlockAddress: case MachineJumpTableInfo::EK_LabelDifference32: { assert(MJTI->getEntrySize(*TheJIT->getTargetData()) == 4&&"Cross JIT'ing?");