forked from OSchip/llvm-project
Add X86 Maximal Stack Alignment Calculator Pass before RA
llvm-svn: 50166
This commit is contained in:
parent
7e859dd7f0
commit
2659011b70
|
@ -51,6 +51,11 @@ FunctionPass *createX86CodeEmitterPass(X86TargetMachine &TM,
|
||||||
///
|
///
|
||||||
FunctionPass *createEmitX86CodeToMemory();
|
FunctionPass *createEmitX86CodeToMemory();
|
||||||
|
|
||||||
|
/// createX86MaxStackAlignmentCalculatorPass - This function returns a pass which
|
||||||
|
/// calculates maximal stack alignment required for function
|
||||||
|
///
|
||||||
|
FunctionPass *createX86MaxStackAlignmentCalculatorPass();
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
// Defines symbolic names for X86 registers. This defines a mapping from
|
// Defines symbolic names for X86 registers. This defines a mapping from
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
#include "llvm/ADT/BitVector.h"
|
#include "llvm/ADT/BitVector.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
|
#include "llvm/Support/Compiler.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
X86RegisterInfo::X86RegisterInfo(X86TargetMachine &tm,
|
X86RegisterInfo::X86RegisterInfo(X86TargetMachine &tm,
|
||||||
|
@ -280,16 +281,10 @@ bool X86RegisterInfo::hasFP(const MachineFunction &MF) const {
|
||||||
bool X86RegisterInfo::needsStackRealignment(const MachineFunction &MF) const {
|
bool X86RegisterInfo::needsStackRealignment(const MachineFunction &MF) const {
|
||||||
MachineFrameInfo *MFI = MF.getFrameInfo();;
|
MachineFrameInfo *MFI = MF.getFrameInfo();;
|
||||||
|
|
||||||
// FIXME: This is really really ugly, but it seems we need to decide, whether
|
|
||||||
// we will need stack realignment or not too early (during RA stage).
|
|
||||||
unsigned MaxAlign = MFI->getMaxAlignment();
|
|
||||||
if (!MaxAlign)
|
|
||||||
MaxAlign = calculateMaxStackAlignment(MFI);
|
|
||||||
|
|
||||||
// FIXME: Currently we don't support stack realignment for functions with
|
// FIXME: Currently we don't support stack realignment for functions with
|
||||||
// variable-sized allocas
|
// variable-sized allocas
|
||||||
return (RealignStack &&
|
return (MFI->getMaxAlignment() &&
|
||||||
(MaxAlign > StackAlign &&
|
(MFI->getMaxAlignment() > StackAlign &&
|
||||||
!MFI->hasVarSizedObjects()));
|
!MFI->hasVarSizedObjects()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1118,3 +1113,31 @@ unsigned getX86SubSuperRegister(unsigned Reg, MVT::ValueType VT, bool High) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "X86GenRegisterInfo.inc"
|
#include "X86GenRegisterInfo.inc"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct VISIBILITY_HIDDEN MSAC : public MachineFunctionPass {
|
||||||
|
static char ID;
|
||||||
|
MSAC() : MachineFunctionPass((intptr_t)&ID) {}
|
||||||
|
|
||||||
|
virtual bool runOnMachineFunction(MachineFunction &MF) {
|
||||||
|
MachineFrameInfo *FFI = MF.getFrameInfo();
|
||||||
|
|
||||||
|
// Calculate and set max stack object alignment early, so we can decide
|
||||||
|
// whether we will need stack realignment (and thus FP).
|
||||||
|
unsigned MaxAlign = calculateMaxStackAlignment(FFI);
|
||||||
|
|
||||||
|
FFI->setMaxAlignment(MaxAlign);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const char *getPassName() const {
|
||||||
|
return "X86 Maximal Stack Alignment Calculator";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
char MSAC::ID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionPass*
|
||||||
|
llvm::createX86MaxStackAlignmentCalculatorPass() { return new MSAC(); }
|
||||||
|
|
|
@ -161,6 +161,11 @@ bool X86TargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool X86TargetMachine::addPreRegAlloc(PassManagerBase &PM, bool Fast) {
|
||||||
|
PM.add(createX86MaxStackAlignmentCalculatorPass());
|
||||||
|
return false; // -print-machineinstr shouldn't print after this.
|
||||||
|
}
|
||||||
|
|
||||||
bool X86TargetMachine::addPostRegAlloc(PassManagerBase &PM, bool Fast) {
|
bool X86TargetMachine::addPostRegAlloc(PassManagerBase &PM, bool Fast) {
|
||||||
PM.add(createX86FloatingPointStackifierPass());
|
PM.add(createX86FloatingPointStackifierPass());
|
||||||
return true; // -print-machineinstr should print after this.
|
return true; // -print-machineinstr should print after this.
|
||||||
|
|
|
@ -61,7 +61,8 @@ public:
|
||||||
static unsigned getJITMatchQuality();
|
static unsigned getJITMatchQuality();
|
||||||
|
|
||||||
// Set up the pass pipeline.
|
// Set up the pass pipeline.
|
||||||
virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
|
virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
|
||||||
|
virtual bool addPreRegAlloc(PassManagerBase &PM, bool Fast);
|
||||||
virtual bool addPostRegAlloc(PassManagerBase &PM, bool Fast);
|
virtual bool addPostRegAlloc(PassManagerBase &PM, bool Fast);
|
||||||
virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
|
virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
|
||||||
std::ostream &Out);
|
std::ostream &Out);
|
||||||
|
|
Loading…
Reference in New Issue