[llvm-commits] [llvm] r42779 - in /llvm/trunk/lib/Target/Mips: MipsAsmPrinter.cpp MipsMachineFunction.h MipsTargetMachine.cpp
Bruno Cardoso Lopes
bruno.cardoso at gmail.com
Mon Oct 8 20:01:20 PDT 2007
Author: bruno
Date: Mon Oct 8 22:01:19 2007
New Revision: 42779
URL: http://llvm.org/viewvc/llvm-project?rev=42779&view=rev
Log:
Position Independent Code (PIC) support [2]
- Added a function to hold the stack location
where GP must be stored during LowerCALL
- AsmPrinter now emits directives based on
relocation type
- PIC_ set to default relocation type (same as GCC)
Modified:
llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
llvm/trunk/lib/Target/Mips/MipsMachineFunction.h
llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp
Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=42779&r1=42778&r2=42779&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Mon Oct 8 22:01:19 2007
@@ -67,7 +67,7 @@
void printHex32(unsigned int Value);
void emitFunctionStart(MachineFunction &MF);
- void emitFunctionEnd();
+ void emitFunctionEnd(MachineFunction &MF);
void emitFrameDirective(MachineFunction &MF);
void emitMaskDirective(MachineFunction &MF);
void emitFMaskDirective(MachineFunction &MF);
@@ -209,10 +209,12 @@
Bitmask |= (1 << MipsRegisterInfo::getRegisterNumbering(CSI[i].getReg()));
if (RI.hasFP(MF))
- Bitmask |= (1 << MipsRegisterInfo::getRegisterNumbering(RI.getFrameRegister(MF)));
+ Bitmask |= (1 << MipsRegisterInfo::
+ getRegisterNumbering(RI.getFrameRegister(MF)));
if (MF.getFrameInfo()->hasCalls())
- Bitmask |= (1 << MipsRegisterInfo::getRegisterNumbering(RI.getRARegister()));
+ Bitmask |= (1 << MipsRegisterInfo::
+ getRegisterNumbering(RI.getRARegister()));
return Bitmask;
}
@@ -247,16 +249,24 @@
emitFrameDirective(MF);
emitMaskDirective(MF);
emitFMaskDirective(MF);
- emitSetDirective(NOREORDER);
- emitSetDirective(NOMACRO);
+
+ if (MF.getTarget().getRelocationModel() == Reloc::Static) {
+ emitSetDirective(NOREORDER);
+ emitSetDirective(NOMACRO);
+ }
+
O << "\n";
}
/// Emit the directives used by GAS on the end of functions
void MipsAsmPrinter::
-emitFunctionEnd() {
- emitSetDirective(MACRO);
- emitSetDirective(REORDER);
+emitFunctionEnd(MachineFunction &MF)
+{
+ if (MF.getTarget().getRelocationModel() == Reloc::Static) {
+ emitSetDirective(MACRO);
+ emitSetDirective(REORDER);
+ }
+
O << "\t.end\t" << CurrentFnName << "\n";
}
@@ -298,7 +308,7 @@
}
// Emit function end directives
- emitFunctionEnd();
+ emitFunctionEnd(MF);
// We didn't modify anything.
return false;
Modified: llvm/trunk/lib/Target/Mips/MipsMachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsMachineFunction.h?rev=42779&r1=42778&r2=42779&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsMachineFunction.h (original)
+++ llvm/trunk/lib/Target/Mips/MipsMachineFunction.h Mon Oct 8 22:01:19 2007
@@ -33,6 +33,11 @@
/// the Return Address must be saved
int RAStackOffset;
+ /// When PIC is used the GP must be saved on the stack
+ /// on the function prologue, so a reference to its stack
+ /// location must be kept.
+ int GPStackOffset;
+
/// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
struct MipsFIHolder {
@@ -69,6 +74,9 @@
int getRAStackOffset() const { return RAStackOffset; }
void setRAStackOffset(int Off) { RAStackOffset = Off; }
+ int getGPStackOffset() const { return GPStackOffset; }
+ void setGPStackOffset(int Off) { GPStackOffset = Off; }
+
int getTopSavedRegOffset() const {
return (RAStackOffset > FPStackOffset) ?
(RAStackOffset) : (FPStackOffset);
Modified: llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp?rev=42779&r1=42778&r2=42779&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp Mon Oct 8 22:01:19 2007
@@ -39,7 +39,11 @@
MipsTargetMachine(const Module &M, const std::string &FS):
Subtarget(*this, M, FS), DataLayout("E-p:32:32:32"),
InstrInfo(*this), FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
- TLInfo(*this) {}
+ TLInfo(*this)
+{
+ if (getRelocationModel() != Reloc::Static)
+ setRelocationModel(Reloc::PIC_);
+}
// return 0 and must specify -march to gen MIPS code.
unsigned MipsTargetMachine::
More information about the llvm-commits
mailing list