[llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp AsmPrinter.cpp
Jim Laskey
jlaskey at apple.com
Thu Dec 14 11:17:52 PST 2006
Changes in directory llvm/lib/CodeGen:
MachineFunction.cpp updated: 1.105 -> 1.106
AsmPrinter.cpp updated: 1.124 -> 1.125
---
Log message:
1. Tidy up jump table info.
2. Allow the jit to handle PIC relocable jump tables.
---
Diffs of the changes: (+32 -37)
AsmPrinter.cpp | 51 +++++++++++++++++++++++----------------------------
MachineFunction.cpp | 18 +++++++++---------
2 files changed, 32 insertions(+), 37 deletions(-)
Index: llvm/lib/CodeGen/MachineFunction.cpp
diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.105 llvm/lib/CodeGen/MachineFunction.cpp:1.106
--- llvm/lib/CodeGen/MachineFunction.cpp:1.105 Thu Dec 7 14:28:15 2006
+++ llvm/lib/CodeGen/MachineFunction.cpp Thu Dec 14 13:17:33 2006
@@ -21,6 +21,7 @@
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Function.h"
@@ -117,7 +118,14 @@
MFInfo = 0;
FrameInfo = new MachineFrameInfo();
ConstantPool = new MachineConstantPool(TM.getTargetData());
- JumpTableInfo = new MachineJumpTableInfo(TM.getTargetData());
+
+ // Set up jump table.
+ const TargetData &TD = *TM.getTargetData();
+ bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
+ unsigned EntrySize = IsPic ? 4 : TD.getPointerSize();
+ unsigned Alignment = IsPic ? TD.getIntAlignment() : TD.getPointerAlignment();
+ JumpTableInfo = new MachineJumpTableInfo(EntrySize, Alignment);
+
BasicBlocks.Parent = this;
}
@@ -380,14 +388,6 @@
}
}
-unsigned MachineJumpTableInfo::getEntrySize() const {
- return TD->getPointerSize();
-}
-
-unsigned MachineJumpTableInfo::getAlignment() const {
- return TD->getPointerAlignment();
-}
-
void MachineJumpTableInfo::dump() const { print(*cerr.stream()); }
Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.124 llvm/lib/CodeGen/AsmPrinter.cpp:1.125
--- llvm/lib/CodeGen/AsmPrinter.cpp:1.124 Mon Dec 11 23:18:19 2006
+++ llvm/lib/CodeGen/AsmPrinter.cpp Thu Dec 14 13:17:33 2006
@@ -188,36 +188,31 @@
MachineFunction &MF) {
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
if (JT.empty()) return;
- const TargetData *TD = TM.getTargetData();
+ bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
- // 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.
- // Use the architecture specific relocation directive, if it is set
+ // Use JumpTableDirective otherwise honor the entry size from the jump table
+ // info.
const char *JTEntryDirective = TAI->getJumpTableDirective();
- if (!JTEntryDirective)
- JTEntryDirective = TAI->getData32bitsDirective();
+ bool HadJTEntryDirective = JTEntryDirective != NULL;
+ if (!HadJTEntryDirective) {
+ JTEntryDirective = MJTI->getEntrySize() == 4 ?
+ TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
+ }
// Pick the directive to use to print the jump table entries, and switch to
// the appropriate section.
- if (TM.getRelocationModel() == Reloc::PIC_) {
- TargetLowering *LoweringInfo = TM.getTargetLowering();
- if (LoweringInfo && LoweringInfo->usesGlobalOffsetTable()) {
- SwitchToDataSection(TAI->getJumpTableDataSection());
- if (TD->getPointerSize() == 8 && !JTEntryDirective)
- JTEntryDirective = TAI->getData64bitsDirective();
- } else {
- // 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.
- const Function *F = MF.getFunction();
- SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
- }
+ TargetLowering *LoweringInfo = TM.getTargetLowering();
+
+ if (IsPic && !(LoweringInfo && LoweringInfo->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.
+ const Function *F = MF.getFunction();
+ SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
} else {
SwitchToDataSection(TAI->getJumpTableDataSection());
- if (TD->getPointerSize() == 8)
- JTEntryDirective = TAI->getData64bitsDirective();
}
- EmitAlignment(Log2_32(TD->getPointerAlignment()));
+
+ EmitAlignment(Log2_32(MJTI->getAlignment()));
for (unsigned i = 0, e = JT.size(); i != e; ++i) {
const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
@@ -229,7 +224,7 @@
// the number of relocations the assembler will generate for the jump table.
// Set directives are all printed before the jump table itself.
std::set<MachineBasicBlock*> EmittedSets;
- if (TAI->getSetDirective() && TM.getRelocationModel() == Reloc::PIC_)
+ if (TAI->getSetDirective() && IsPic)
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
if (EmittedSets.insert(JTBBs[ii]).second)
printSetLabel(i, JTBBs[ii]);
@@ -247,12 +242,12 @@
if (!EmittedSets.empty()) {
O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
<< '_' << i << "_set_" << JTBBs[ii]->getNumber();
- } else if (TM.getRelocationModel() == Reloc::PIC_) {
+ } else if (IsPic) {
printBasicBlockLabel(JTBBs[ii], false, false);
- //If the arch uses custom Jump Table directives, don't calc relative to JT
- if (!TAI->getJumpTableDirective())
- O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
- << getFunctionNumber() << '_' << i;
+ //If the arch uses custom Jump Table directives, don't calc relative to JT
+ if (!HadJTEntryDirective)
+ O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
+ << getFunctionNumber() << '_' << i;
} else {
printBasicBlockLabel(JTBBs[ii], false, false);
}
More information about the llvm-commits
mailing list