mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
Cygwin support. Patch by Anton Korobeynikov!
llvm-svn: 28672
This commit is contained in:
parent
67d357bb6b
commit
696779cea0
@ -129,6 +129,8 @@ namespace {
|
||||
SDOperand &Base, SDOperand &Scale,
|
||||
SDOperand &Index, SDOperand &Disp);
|
||||
|
||||
void EmitSpecialCodeForMain(MachineBasicBlock *BB, MachineFrameInfo *MFI);
|
||||
|
||||
inline void getAddressOperands(X86ISelAddressMode &AM, SDOperand &Base,
|
||||
SDOperand &Scale, SDOperand &Index,
|
||||
SDOperand &Disp) {
|
||||
@ -250,8 +252,11 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
||||
|
||||
/// EmitSpecialCodeForMain - Emit any code that needs to be executed only in
|
||||
/// the main function.
|
||||
static void EmitSpecialCodeForMain(MachineBasicBlock *BB,
|
||||
void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB,
|
||||
MachineFrameInfo *MFI) {
|
||||
if (Subtarget->TargetType == X86Subtarget::isCygwin)
|
||||
BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("__main");
|
||||
|
||||
// Switch the FPU to 64-bit precision mode for better compatibility and speed.
|
||||
int CWFrameIdx = MFI->CreateStackObject(2, 2);
|
||||
addFrameReference(BuildMI(BB, X86::FNSTCW16m, 4), CWFrameIdx);
|
||||
|
@ -14,9 +14,12 @@
|
||||
|
||||
#include "X86.h"
|
||||
#include "X86RegisterInfo.h"
|
||||
#include "X86Subtarget.h"
|
||||
#include "X86TargetMachine.h"
|
||||
#include "X86InstrBuilder.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/Type.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/CodeGen/ValueTypes.h"
|
||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||
#include "llvm/CodeGen/MachineFunction.h"
|
||||
@ -635,7 +638,14 @@ X86RegisterInfo::getCalleeSaveRegClasses() const {
|
||||
// if frame pointer elimination is disabled.
|
||||
//
|
||||
static bool hasFP(MachineFunction &MF) {
|
||||
return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
|
||||
const Function* Fn = MF.getFunction();
|
||||
const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>();
|
||||
|
||||
return (NoFramePointerElim ||
|
||||
MF.getFrameInfo()->hasVarSizedObjects() ||
|
||||
(Fn->hasExternalLinkage() &&
|
||||
Fn->getName() == "main" &&
|
||||
Subtarget->TargetType == X86Subtarget::isCygwin));
|
||||
}
|
||||
|
||||
void X86RegisterInfo::
|
||||
@ -730,6 +740,9 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
|
||||
MachineBasicBlock::iterator MBBI = MBB.begin();
|
||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
|
||||
const Function* Fn = MF.getFunction();
|
||||
const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>();
|
||||
MachineInstr *MI;
|
||||
|
||||
// Get the number of bytes to allocate from the FrameInfo
|
||||
@ -744,7 +757,6 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||
|
||||
// Round the size to a multiple of the alignment (don't forget the 4 byte
|
||||
// offset though).
|
||||
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
|
||||
NumBytes = ((NumBytes+4)+Align-1)/Align*Align - 4;
|
||||
}
|
||||
|
||||
@ -775,6 +787,13 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||
|
||||
MBB.insert(MBBI, MI);
|
||||
}
|
||||
|
||||
// If it's main() on Cygwin\Mingw32 we should align stack as well
|
||||
if (Fn->hasExternalLinkage() && Fn->getName() == "main" &&
|
||||
Subtarget->TargetType == X86Subtarget::isCygwin) {
|
||||
MI = BuildMI(X86::AND32ri, 2, X86::ESP).addImm(-Align);
|
||||
MBB.insert(MBBI, MI);
|
||||
}
|
||||
}
|
||||
|
||||
void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||
|
Loading…
Reference in New Issue
Block a user