mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-23 06:35:25 +00:00
JumpTable support! What this represents is working asm and jit support for
x86 and ppc for 100% dense switch statements when relocations are non-PIC. This support will be extended and enhanced in the coming days to support PIC, and less dense forms of jump tables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/CodeGen/MachineConstantPool.h"
|
||||
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
||||
#include "llvm/Support/Mangler.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
@@ -46,6 +47,7 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
|
||||
AlignmentIsInBytes(true),
|
||||
SwitchToSectionDirective("\t.section\t"),
|
||||
ConstantPoolSection("\t.section .rodata\n"),
|
||||
JumpTableSection("\t.section .rodata\n"),
|
||||
StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
|
||||
StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
|
||||
LCOMMDirective(0),
|
||||
@@ -127,6 +129,33 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
|
||||
}
|
||||
}
|
||||
|
||||
/// EmitJumpTableInfo - Print assembly representations of the jump tables used
|
||||
/// by the current function to the current output stream.
|
||||
///
|
||||
void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
|
||||
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
||||
if (JT.empty()) return;
|
||||
const TargetData &TD = TM.getTargetData();
|
||||
|
||||
// FIXME: someday we need to handle PIC jump tables
|
||||
assert((TM.getRelocationModel() == Reloc::Static ||
|
||||
TM.getRelocationModel() == Reloc::DynamicNoPIC) &&
|
||||
"Unhandled relocation model emitting jump table information!");
|
||||
|
||||
SwitchSection(JumpTableSection, 0);
|
||||
EmitAlignment(Log2_32(TD.getPointerAlignment()));
|
||||
for (unsigned i = 0, e = JT.size(); i != e; ++i) {
|
||||
O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i
|
||||
<< ":\n";
|
||||
const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
|
||||
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
|
||||
O << Data32bitsDirective << ' ';
|
||||
printBasicBlockLabel(JTBBs[ii]);
|
||||
O << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
|
||||
/// special global used by LLVM. If so, emit it and return true, otherwise
|
||||
/// do nothing and return false.
|
||||
@@ -654,3 +683,12 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
// Target doesn't support this yet!
|
||||
return true;
|
||||
}
|
||||
|
||||
/// printBasicBlockLabel - This method prints the label for the specified
|
||||
/// MachineBasicBlock
|
||||
void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB) const {
|
||||
O << PrivateGlobalPrefix << "LBB"
|
||||
<< Mang->getValueName(MBB->getParent()->getFunction())
|
||||
<< "_" << MBB->getNumber() << '\t' << CommentString
|
||||
<< MBB->getBasicBlock()->getName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user