Index: include/llvm/CodeGen/Passes.h =================================================================== --- include/llvm/CodeGen/Passes.h +++ include/llvm/CodeGen/Passes.h @@ -120,9 +120,6 @@ /// Default setting for -enable-tail-merge on this target. bool EnableTailMerge; - /// Default setting for -enable-shrink-wrap on this target. - bool EnableShrinkWrap; - public: TargetPassConfig(TargetMachine *tm, PassManagerBase &pm); // Dummy constructor. Index: include/llvm/Target/TargetFrameLowering.h =================================================================== --- include/llvm/Target/TargetFrameLowering.h +++ include/llvm/Target/TargetFrameLowering.h @@ -141,6 +141,12 @@ return false; } + /// targetHandlesShrinkWrapping - Returns true if the target will correctly + /// handle shrink wrapping. + virtual bool targetSupportsShrinkWrapping(const MachineFunction &MF) const { + return false; + } + /// emitProlog/emitEpilog - These methods insert prolog and epilog code into /// the function. virtual void emitPrologue(MachineFunction &MF, Index: lib/CodeGen/Passes.cpp =================================================================== --- lib/CodeGen/Passes.cpp +++ lib/CodeGen/Passes.cpp @@ -56,9 +56,6 @@ cl::desc("Disable Machine LICM")); static cl::opt DisableMachineCSE("disable-machine-cse", cl::Hidden, cl::desc("Disable Machine Common Subexpression Elimination")); -static cl::opt - EnableShrinkWrapOpt("enable-shrink-wrap", cl::Hidden, - cl::desc("enable the shrink-wrapping pass")); static cl::opt OptimizeRegAlloc( "optimize-regalloc", cl::Hidden, cl::desc("Enable optimized register allocation compilation path.")); @@ -221,7 +218,7 @@ : ImmutablePass(ID), PM(&pm), StartBefore(nullptr), StartAfter(nullptr), StopAfter(nullptr), Started(true), Stopped(false), AddingMachinePasses(false), TM(tm), Impl(nullptr), Initialized(false), - DisableVerify(false), EnableTailMerge(true), EnableShrinkWrap(false) { + DisableVerify(false), EnableTailMerge(true) { Impl = new PassConfigImpl(); @@ -543,8 +540,9 @@ addPostRegAlloc(); // Insert prolog/epilog code. Eliminate abstract frame index references... - if (getEnableShrinkWrap()) + if (getOptLevel() != CodeGenOpt::None) addPass(&ShrinkWrapID); + addPass(&PrologEpilogCodeInserterID); /// Add passes that optimize machine instructions after register allocation. @@ -623,21 +621,6 @@ addPass(&DeadMachineInstructionElimID); } -bool TargetPassConfig::getEnableShrinkWrap() const { - switch (EnableShrinkWrapOpt) { - case cl::BOU_UNSET: - return EnableShrinkWrap && getOptLevel() != CodeGenOpt::None; - // If EnableShrinkWrap is set, it takes precedence on whatever the - // target sets. The rational is that we assume we want to test - // something related to shrink-wrapping. - case cl::BOU_TRUE: - return true; - case cl::BOU_FALSE: - return false; - } - llvm_unreachable("Invalid shrink-wrapping state"); -} - //===---------------------------------------------------------------------===// /// Register Allocation Pass Configuration //===---------------------------------------------------------------------===// Index: lib/CodeGen/ShrinkWrap.cpp =================================================================== --- lib/CodeGen/ShrinkWrap.cpp +++ lib/CodeGen/ShrinkWrap.cpp @@ -78,6 +78,10 @@ STATISTIC(NumCandidatesDropped, "Number of shrink-wrapping candidates dropped because of frequency"); +static cl::opt + EnableShrinkWrapOpt("enable-shrink-wrap", cl::Hidden, + cl::desc("enable the shrink-wrapping pass")); + namespace { /// \brief Class to determine where the safe point to insert the /// prologue and epilogue are. @@ -148,6 +152,9 @@ /// shrink-wrapping. bool ArePointsInteresting() const { return Save != Entry && Save && Restore; } + /// \brief Check if shrink wrapping is enabled for this target and function + bool isShrinkWrapEnabled(const MachineFunction &MF) const; + public: static char ID; @@ -321,6 +328,10 @@ bool ShrinkWrap::runOnMachineFunction(MachineFunction &MF) { if (MF.empty()) return false; + + if (! isShrinkWrapEnabled(MF)) + return false; + DEBUG(dbgs() << "**** Analysing " << MF.getName() << '\n'); init(MF); @@ -404,3 +415,20 @@ ++NumCandidates; return false; } + +bool ShrinkWrap::isShrinkWrapEnabled(const MachineFunction &MF) const { + const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); + + switch (EnableShrinkWrapOpt) { + case cl::BOU_UNSET: + return TFI->targetSupportsShrinkWrapping(MF); + // If EnableShrinkWrap is set, it takes precedence on whatever the + // target sets. The rational is that we assume we want to test + // something related to shrink-wrapping. + case cl::BOU_TRUE: + return true; + case cl::BOU_FALSE: + return false; + } + llvm_unreachable("Invalid shrink-wrapping state"); +}