Mercurial > hg > CbC > CbC_llvm
diff lib/CodeGen/ShrinkWrap.cpp @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children | 3a76565eade5 |
line wrap: on
line diff
--- a/lib/CodeGen/ShrinkWrap.cpp Fri Nov 25 19:14:25 2016 +0900 +++ b/lib/CodeGen/ShrinkWrap.cpp Fri Oct 27 17:07:41 2017 +0900 @@ -1,4 +1,4 @@ -//===-- ShrinkWrap.cpp - Compute safe point for prolog/epilog insertion ---===// +//===- ShrinkWrap.cpp - Compute safe point for prolog/epilog insertion ----===// // // The LLVM Compiler Infrastructure // @@ -45,50 +45,58 @@ // // If this pass found points matching all these properties, then // MachineFrameInfo is updated with this information. +// //===----------------------------------------------------------------------===// + #include "llvm/ADT/BitVector.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" -// To check for profitability. +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" -// For property #1 for Save. #include "llvm/CodeGen/MachineDominators.h" +#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" -// To record the result of the analysis. #include "llvm/CodeGen/MachineFrameInfo.h" -// For property #2. +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineLoopInfo.h" -// For property #1 for Restore. +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachinePostDominators.h" -#include "llvm/CodeGen/Passes.h" -// To know about callee-saved. #include "llvm/CodeGen/RegisterClassInfo.h" #include "llvm/CodeGen/RegisterScavenging.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Function.h" #include "llvm/MC/MCAsmInfo.h" +#include "llvm/Pass.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -// To query the target about frame lowering. +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetFrameLowering.h" -// To know about frame setup operation. #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetMachine.h" -// To access TargetInstrInfo. +#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" +#include <cassert> +#include <cstdint> +#include <memory> + +using namespace llvm; #define DEBUG_TYPE "shrink-wrap" -using namespace llvm; - STATISTIC(NumFunc, "Number of functions"); STATISTIC(NumCandidates, "Number of shrink-wrapping candidates"); STATISTIC(NumCandidatesDropped, "Number of shrink-wrapping candidates dropped because of frequency"); static cl::opt<cl::boolOrDefault> - EnableShrinkWrapOpt("enable-shrink-wrap", cl::Hidden, - cl::desc("enable the shrink-wrapping pass")); +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. /// Unlike the paper from Fred C. Chow, PLDI'88, that introduces the @@ -101,31 +109,42 @@ RegisterClassInfo RCI; MachineDominatorTree *MDT; MachinePostDominatorTree *MPDT; + /// Current safe point found for the prologue. /// The prologue will be inserted before the first instruction /// in this basic block. MachineBasicBlock *Save; + /// Current safe point found for the epilogue. /// The epilogue will be inserted before the first terminator instruction /// in this basic block. MachineBasicBlock *Restore; + /// Hold the information of the basic block frequency. /// Use to check the profitability of the new points. MachineBlockFrequencyInfo *MBFI; + /// Hold the loop information. Used to determine if Save and Restore /// are in the same loop. MachineLoopInfo *MLI; + /// Frequency of the Entry block. uint64_t EntryFreq; + /// Current opcode for frame setup. unsigned FrameSetupOpcode; + /// Current opcode for frame destroy. unsigned FrameDestroyOpcode; + /// Entry block. const MachineBasicBlock *Entry; - typedef SmallSetVector<unsigned, 16> SetOfRegs; + + using SetOfRegs = SmallSetVector<unsigned, 16>; + /// Registers that need to be saved for the current function. mutable SetOfRegs CurrentCSRs; + /// Current MachineFunction. MachineFunction *MachineFunc; @@ -205,18 +224,19 @@ /// the MachineFrameInfo attached to \p MF with the results. bool runOnMachineFunction(MachineFunction &MF) override; }; -} // End anonymous namespace. + +} // end anonymous namespace char ShrinkWrap::ID = 0; + char &llvm::ShrinkWrapID = ShrinkWrap::ID; -INITIALIZE_PASS_BEGIN(ShrinkWrap, "shrink-wrap", "Shrink Wrap Pass", false, - false) +INITIALIZE_PASS_BEGIN(ShrinkWrap, DEBUG_TYPE, "Shrink Wrap Pass", false, false) INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfo) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree) INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) -INITIALIZE_PASS_END(ShrinkWrap, "shrink-wrap", "Shrink Wrap Pass", false, false) +INITIALIZE_PASS_END(ShrinkWrap, DEBUG_TYPE, "Shrink Wrap Pass", false, false) bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS) const { @@ -282,8 +302,14 @@ if (!Restore) Restore = &MBB; + else if (MPDT->getNode(&MBB)) // If the block is not in the post dom tree, it + // means the block never returns. If that's the + // case, we don't want to call + // `findNearestCommonDominator`, which will + // return `Restore`. + Restore = MPDT->findNearestCommonDominator(Restore, &MBB); else - Restore = MPDT->findNearestCommonDominator(Restore, &MBB); + Restore = nullptr; // Abort, we can't find a restore point in this case. // Make sure we would be able to insert the restore code before the // terminator. @@ -293,7 +319,7 @@ continue; // One of the terminator needs to happen before the restore point. if (MBB.succ_empty()) { - Restore = nullptr; + Restore = nullptr; // Abort, we can't find a restore point in this case. break; } // Look for a restore point that post-dominates all the successors. @@ -419,7 +445,7 @@ } bool ShrinkWrap::runOnMachineFunction(MachineFunction &MF) { - if (MF.empty() || !isShrinkWrapEnabled(MF)) + if (skipFunction(*MF.getFunction()) || MF.empty() || !isShrinkWrapEnabled(MF)) return false; DEBUG(dbgs() << "**** Analysing " << MF.getName() << '\n');