LLVM
8.0.1
|
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/CodeGen/WinEHFuncInfo.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <limits>
#include <utility>
#include <vector>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "prologepilog" |
Typedefs | |
using | MBBVector = SmallVector< MachineBasicBlock *, 4 > |
using | StackObjSet = SmallSetVector< int, 8 > |
StackObjSet - A set of stack object indexes. More... | |
Functions | |
STATISTIC (NumLeafFuncWithSpills, "Number of leaf functions with CSRs") | |
STATISTIC (NumFuncSeen, "Number of functions seen in PEI") | |
INITIALIZE_PASS_BEGIN (PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false, false) INITIALIZE_PASS_END(PEI | |
STATISTIC (NumBytesStackSpace, "Number of bytes used for stack in all functions") | |
static void | assignCalleeSavedSpillSlots (MachineFunction &F, const BitVector &SavedRegs, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) |
static void | updateLiveness (MachineFunction &MF) |
Helper function to update the liveness information for the callee-saved registers. More... | |
static void | insertCSRSaves (MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI) |
Insert restore code for the callee-saved registers used in the function. More... | |
static void | insertCSRRestores (MachineBasicBlock &RestoreBlock, std::vector< CalleeSavedInfo > &CSI) |
Insert restore code for the callee-saved registers used in the function. More... | |
static void | AdjustStackOffset (MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign, unsigned Skew) |
AdjustStackOffset - Helper function used to adjust the stack frame offset. More... | |
static void | computeFreeStackSlots (MachineFrameInfo &MFI, bool StackGrowsDown, unsigned MinCSFrameIndex, unsigned MaxCSFrameIndex, int64_t FixedCSEnd, BitVector &StackBytesFree) |
Compute which bytes of fixed and callee-save stack area are unused and keep track of them in StackBytesFree. More... | |
static bool | scavengeStackSlot (MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, unsigned MaxAlign, BitVector &StackBytesFree) |
Assign frame object to an unused portion of the stack in the fixed stack object range. More... | |
static void | AssignProtectedObjSet (const StackObjSet &UnassignedObjs, SmallSet< int, 16 > &ProtectedObjs, MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign, unsigned Skew) |
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be close to the Stack Protector) to stack offsets. More... | |
Variables | |
static cl::opt< unsigned > | WarnStackSize ("warn-stack-size", cl::Hidden, cl::init((unsigned) -1), cl::desc("Warn for stack size bigger than the given" " number")) |
DEBUG_TYPE | |
Prologue Epilogue Insertion &Frame | Finalization |
Prologue Epilogue Insertion &Frame | false |
#define DEBUG_TYPE "prologepilog" |
Definition at line 74 of file PrologEpilogInserter.cpp.
using MBBVector = SmallVector<MachineBasicBlock *, 4> |
Definition at line 76 of file PrologEpilogInserter.cpp.
using StackObjSet = SmallSetVector<int, 8> |
StackObjSet - A set of stack object indexes.
Definition at line 170 of file PrologEpilogInserter.cpp.
|
inlinestatic |
AdjustStackOffset - Helper function used to adjust the stack frame offset.
Definition at line 575 of file PrologEpilogInserter.cpp.
References llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Align, llvm::alignTo(), llvm::dbgs(), llvm::MachineFrameInfo::getObjectAlignment(), llvm::MachineFrameInfo::getObjectSize(), LLVM_DEBUG, llvm::max(), and llvm::MachineFrameInfo::setObjectOffset().
Referenced by AssignProtectedObjSet(), and INITIALIZE_PASS().
|
static |
Definition at line 333 of file PrologEpilogInserter.cpp.
References llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Align, llvm::TargetFrameLowering::assignCalleeSavedSpillSlots(), llvm::MachineFrameInfo::CreateFixedSpillStackObject(), llvm::MachineFrameInfo::CreateStackObject(), llvm::BitVector::empty(), llvm::MachineRegisterInfo::getCalleeSavedRegs(), llvm::TargetFrameLowering::getCalleeSavedSpillSlots(), llvm::MachineFunction::getFrameInfo(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::TargetRegisterInfo::getMinimalPhysRegClass(), llvm::MachineFunction::getRegInfo(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::TargetRegisterInfo::getSpillAlignment(), llvm::TargetRegisterInfo::getSpillSize(), llvm::TargetFrameLowering::getStackAlignment(), llvm::MachineFunction::getSubtarget(), llvm::TargetRegisterInfo::hasReservedSpillSlot(), llvm::TargetFrameLowering::SpillSlot::Offset, llvm::TargetFrameLowering::SpillSlot::Reg, Reg, llvm::MachineFrameInfo::setCalleeSavedInfo(), Size, and llvm::BitVector::test().
Referenced by insertCSRRestores().
|
static |
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be close to the Stack Protector) to stack offsets.
Definition at line 706 of file PrologEpilogInserter.cpp.
References llvm::TargetFrameLowering::adjustForHiPEPrologue(), llvm::TargetFrameLowering::adjustForSegmentedStacks(), llvm::MachineFrameInfo::adjustsStack(), AdjustStackOffset(), llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Align, llvm::alignTo(), assert(), llvm::SetVector< T, Vector, Set >::begin(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::MachineBasicBlock::begin(), llvm::MachineOperand::ChangeToRegister(), computeFreeStackSlots(), llvm::SmallPtrSetImpl< NodeRef >::count(), llvm::dbgs(), llvm::df_ext_begin(), llvm::df_ext_end(), E, llvm::TargetFrameLowering::eliminateCallFramePseudoInstr(), llvm::TargetRegisterInfo::eliminateFrameIndex(), llvm::TargetFrameLowering::emitEpilogue(), llvm::TargetFrameLowering::emitPrologue(), llvm::SmallVectorBase::empty(), llvm::TargetFrameLowering::enableStackSlotScavenging(), llvm::SetVector< T, Vector, Set >::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::MachineBasicBlock::end(), llvm::Function::getCallingConv(), llvm::MachineInstr::getDebugExpression(), llvm::TargetFrameLowering::getFrameIndexReference(), llvm::TargetFrameLowering::getFrameIndexReferencePreferSP(), llvm::MachineFunction::getFrameInfo(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::MachineFunction::getFunction(), llvm::MachineOperand::getImm(), llvm::MachineOperand::getIndex(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MachineFrameInfo::getLocalFrameMaxAlign(), llvm::MachineFrameInfo::getLocalFrameObjectCount(), llvm::MachineFrameInfo::getLocalFrameObjectMap(), llvm::MachineFrameInfo::getLocalFrameSize(), llvm::MachineFrameInfo::getMaxAlignment(), llvm::MachineFrameInfo::getMaxCallFrameSize(), llvm::MachineFunction::getMMI(), llvm::MachineBasicBlock::getNumber(), llvm::MachineFunction::getNumBlockIDs(), llvm::MachineInstr::getNumOperands(), llvm::MachineFrameInfo::getObjectAlignment(), llvm::MachineFrameInfo::getObjectIndexBegin(), llvm::MachineFrameInfo::getObjectIndexEnd(), llvm::MachineFrameInfo::getObjectOffset(), llvm::MachineFrameInfo::getObjectSize(), llvm::MachineFrameInfo::getObjectSSPLayout(), llvm::TargetFrameLowering::getOffsetOfLocalArea(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::TargetMachine::getOptLevel(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::TargetFrameLowering::getStackAlignment(), llvm::TargetFrameLowering::getStackAlignmentSkew(), llvm::TargetFrameLowering::getStackGrowthDirection(), llvm::MachineFrameInfo::getStackProtectorIndex(), llvm::MachineFunction::getSubtarget(), llvm::MachineFunction::getTarget(), llvm::TargetFrameLowering::getTransientStackAlignment(), llvm::MachineFrameInfo::getUseLocalStackAllocationBlock(), llvm::MachineFunction::getWinEHFuncInfo(), llvm::TargetFrameLowering::hasFP(), llvm::TargetFrameLowering::hasReservedCallFrame(), llvm::MachineFrameInfo::hasVarSizedObjects(), llvm::CallingConv::HiPE, I, llvm::ARM_PROC::IE, if(), llvm::TargetFrameLowering::inlineStackProbe(), llvm::SetVector< T, Vector, Set >::insert(), llvm::SmallSet< T, N, C >::insert(), llvm::MachineFrameInfo::isDeadObjectIndex(), llvm::MachineInstr::isDebugValue(), llvm::MachineOperand::isFI(), llvm::TargetFrameLowering::isFPCloseToIncomingSP(), llvm::MachineFrameInfo::isObjectPreAllocated(), LLVM_DEBUG, llvm_unreachable, llvm::max(), MI, llvm::TargetFrameLowering::needsFrameIndexResolution(), llvm::TargetRegisterInfo::needsStackRealignment(), llvm::DIExpression::NoDeref, llvm::CodeGenOpt::None, llvm::TargetMachine::Options, llvm::TargetFrameLowering::orderFrameObjects(), llvm::DIExpression::prepend(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), Reg, llvm::SmallVectorImpl< T >::resize(), scavengeStackSlot(), llvm::MachineModuleInfo::setHasNosplitStack(), llvm::MachineModuleInfo::setHasSplitStack(), llvm::MachineOperand::setImm(), llvm::MachineOperand::setIsDebug(), llvm::MachineOperand::setMetadata(), llvm::MachineFrameInfo::setObjectOffset(), llvm::MachineFrameInfo::setStackSize(), llvm::MachineFunction::shouldSplitStack(), llvm::MachineFrameInfo::SSPLK_AddrOf, llvm::MachineFrameInfo::SSPLK_LargeArray, llvm::MachineFrameInfo::SSPLK_None, llvm::MachineFrameInfo::SSPLK_SmallArray, llvm::TargetFrameLowering::StackGrowsDown, llvm::TargetOptions::StackSymbolOrdering, llvm::TargetFrameLowering::targetHandlesStackFrameRounding(), TII, TRI, and llvm::TargetRegisterInfo::useFPForScavengingIndex().
Referenced by INITIALIZE_PASS().
|
inlinestatic |
Compute which bytes of fixed and callee-save stack area are unused and keep track of them in StackBytesFree.
Definition at line 606 of file PrologEpilogInserter.cpp.
References llvm::MachineFrameInfo::getObjectIndexBegin(), llvm::MachineFrameInfo::getObjectOffset(), llvm::MachineFrameInfo::getObjectSize(), llvm::max(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::BitVector::reset(), and llvm::BitVector::resize().
Referenced by AssignProtectedObjSet().
INITIALIZE_PASS_BEGIN | ( | PEI | , |
DEBUG_TYPE | , | ||
"Prologue/Epilogue Insertion" | , | ||
false | , | ||
false | |||
) |
|
static |
Insert restore code for the callee-saved registers used in the function.
Definition at line 506 of file PrologEpilogInserter.cpp.
References assert(), assignCalleeSavedSpillSlots(), llvm::MachineBasicBlock::begin(), llvm::TargetFrameLowering::determineCalleeSaves(), F(), llvm::MachineFrameInfo::getCalleeSavedInfo(), llvm::MachineBasicBlock::getFirstTerminator(), llvm::MachineFunction::getFrameInfo(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::MachineFunction::getFunction(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::TargetRegisterInfo::getMinimalPhysRegClass(), llvm::MachineBasicBlock::getParent(), llvm::MachineFunction::getProperties(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), llvm::MachineFrameInfo::hasCalls(), llvm::MachineFunctionProperties::hasProperty(), I, insertCSRSaves(), llvm::TargetInstrInfo::loadRegFromStackSlot(), llvm::max(), llvm::Attribute::Naked, llvm::MachineFunctionProperties::NoVRegs, Reg, llvm::TargetFrameLowering::restoreCalleeSavedRegisters(), llvm::reverse(), llvm::MachineFrameInfo::setCalleeSavedInfoValid(), TII, TRI, and updateLiveness().
|
static |
Insert restore code for the callee-saved registers used in the function.
Definition at line 486 of file PrologEpilogInserter.cpp.
References llvm::MachineBasicBlock::begin(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::TargetRegisterInfo::getMinimalPhysRegClass(), llvm::MachineBasicBlock::getParent(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), I, Reg, llvm::TargetFrameLowering::spillCalleeSavedRegisters(), llvm::TargetInstrInfo::storeRegToStackSlot(), TII, and TRI.
Referenced by insertCSRRestores().
|
inlinestatic |
Assign frame object to an unused portion of the stack in the fixed stack object range.
Return true if the allocation was successful.
Definition at line 645 of file PrologEpilogInserter.cpp.
References llvm::alignTo(), llvm::BitVector::clear(), llvm::dbgs(), llvm::BitVector::find_first(), llvm::BitVector::find_next(), llvm::MachineFrameInfo::getObjectAlignment(), llvm::MachineFrameInfo::getObjectSize(), llvm::MachineFrameInfo::isVariableSizedObjectIndex(), LLVM_DEBUG, llvm::BitVector::none(), llvm::BitVector::reset(), llvm::MachineFrameInfo::setObjectOffset(), llvm::BitVector::size(), and llvm::BitVector::test().
Referenced by AssignProtectedObjSet().
STATISTIC | ( | NumLeafFuncWithSpills | , |
"Number of leaf functions with CSRs" | |||
) |
STATISTIC | ( | NumFuncSeen | , |
"Number of functions seen in PEI" | |||
) |
|
static |
Helper function to update the liveness information for the callee-saved registers.
Definition at line 413 of file PrologEpilogInserter.cpp.
References llvm::SmallVectorBase::empty(), llvm::MachineFunction::front(), llvm::MachineFrameInfo::getCalleeSavedInfo(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getRegInfo(), llvm::MachineFrameInfo::getRestorePoint(), llvm::MachineFrameInfo::getSavePoint(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::MachineRegisterInfo::isReserved(), MRI, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T >::push_back(), Reg, and llvm::MachineBasicBlock::successors().
Referenced by insertCSRRestores().
DEBUG_TYPE |
Definition at line 150 of file PrologEpilogInserter.cpp.
Prologue Epilogue Insertion& Frame false |
Definition at line 150 of file PrologEpilogInserter.cpp.
Prologue Epilogue Insertion& Frame Finalization |
Definition at line 150 of file PrologEpilogInserter.cpp.