Add X86 Maximal Stack Alignment Calculator Pass before RA

llvm-svn: 50166
This commit is contained in:
Anton Korobeynikov 2008-04-23 18:23:05 +00:00
parent 7e859dd7f0
commit 2659011b70
4 changed files with 43 additions and 9 deletions

View File

@ -51,6 +51,11 @@ FunctionPass *createX86CodeEmitterPass(X86TargetMachine &TM,
///
FunctionPass *createEmitX86CodeToMemory();
/// createX86MaxStackAlignmentCalculatorPass - This function returns a pass which
/// calculates maximal stack alignment required for function
///
FunctionPass *createX86MaxStackAlignmentCalculatorPass();
} // End llvm namespace
// Defines symbolic names for X86 registers. This defines a mapping from

View File

@ -36,6 +36,7 @@
#include "llvm/Target/TargetOptions.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
using namespace llvm;
X86RegisterInfo::X86RegisterInfo(X86TargetMachine &tm,
@ -280,16 +281,10 @@ bool X86RegisterInfo::hasFP(const MachineFunction &MF) const {
bool X86RegisterInfo::needsStackRealignment(const MachineFunction &MF) const {
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
// variable-sized allocas
return (RealignStack &&
(MaxAlign > StackAlign &&
return (MFI->getMaxAlignment() &&
(MFI->getMaxAlignment() > StackAlign &&
!MFI->hasVarSizedObjects()));
}
@ -1118,3 +1113,31 @@ unsigned getX86SubSuperRegister(unsigned Reg, MVT::ValueType VT, bool High) {
}
#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(); }

View File

@ -161,6 +161,11 @@ bool X86TargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
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) {
PM.add(createX86FloatingPointStackifierPass());
return true; // -print-machineinstr should print after this.

View File

@ -61,7 +61,8 @@ public:
static unsigned getJITMatchQuality();
// 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 addAssemblyEmitter(PassManagerBase &PM, bool Fast,
std::ostream &Out);