aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/AsmPrinter.cpp
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2006-04-22 18:53:45 +0000
committerNate Begeman <natebegeman@mac.com>2006-04-22 18:53:45 +0000
commit37efe6764568a3829fee26aba532283131d1a104 (patch)
tree5729b1d1477bb72a5a4f83494638aab63e54f522 /lib/CodeGen/AsmPrinter.cpp
parent1900c012f5f15063a9349f6646d7dd1654df38f9 (diff)
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
Diffstat (limited to 'lib/CodeGen/AsmPrinter.cpp')
-rw-r--r--lib/CodeGen/AsmPrinter.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 11c6f231b9..48d4a20a83 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -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();
+}