LLVM  12.0.0git
Macros | Typedefs | Functions | Variables
PrologEpilogInserter.cpp File Reference
#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/MachineInstrBuilder.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/InitializePasses.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...
 
using SavedDbgValuesMap = SmallDenseMap< MachineBasicBlock *, SmallVector< MachineInstr *, 4 >, 4 >
 

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 stashEntryDbgValues (MachineBasicBlock &MBB, SavedDbgValuesMap &EntryDbgValues)
 Stash DBG_VALUEs that describe parameters and which are placed at the start of the block. More...
 
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, Align &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, Align 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, Align &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< unsignedWarnStackSize ("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
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "prologepilog"

Definition at line 75 of file PrologEpilogInserter.cpp.

Referenced by stashEntryDbgValues().

Typedef Documentation

◆ MBBVector

Definition at line 77 of file PrologEpilogInserter.cpp.

◆ SavedDbgValuesMap

Definition at line 174 of file PrologEpilogInserter.cpp.

◆ StackObjSet

using StackObjSet = SmallSetVector<int, 8>

StackObjSet - A set of stack object indexes.

Definition at line 171 of file PrologEpilogInserter.cpp.

Function Documentation

◆ AdjustStackOffset()

static void AdjustStackOffset ( MachineFrameInfo MFI,
int  FrameIdx,
bool  StackGrowsDown,
int64_t &  Offset,
Align MaxAlign,
unsigned  Skew 
)
inlinestatic

AdjustStackOffset - Helper function used to adjust the stack frame offset.

Definition at line 636 of file PrologEpilogInserter.cpp.

References llvm::alignTo(), llvm::dbgs(), llvm::MachineFrameInfo::getObjectAlign(), llvm::MachineFrameInfo::getObjectSize(), LLVM_DEBUG, llvm::max(), and llvm::MachineFrameInfo::setObjectOffset().

Referenced by AssignProtectedObjSet(), and INITIALIZE_PASS().

◆ assignCalleeSavedSpillSlots()

static void assignCalleeSavedSpillSlots ( MachineFunction F,
const BitVector SavedRegs,
unsigned MinCSFrameIndex,
unsigned MaxCSFrameIndex 
)
static

◆ AssignProtectedObjSet()

static void AssignProtectedObjSet ( const StackObjSet UnassignedObjs,
SmallSet< int, 16 > &  ProtectedObjs,
MachineFrameInfo MFI,
bool  StackGrowsDown,
int64_t &  Offset,
Align MaxAlign,
unsigned  Skew 
)
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 769 of file PrologEpilogInserter.cpp.

References AdjustStackOffset(), llvm::alignTo(), assert(), llvm::SetVector< T, Vector, Set >::begin(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::dbgs(), llvm::TargetStackID::Default, llvm::numbers::e, E, llvm::SetVector< T, Vector, Set >::end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::MachineFunction::getFrameInfo(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::MachineFrameInfo::getLocalFrameMaxAlign(), llvm::MachineFrameInfo::getLocalFrameObjectCount(), llvm::MachineFrameInfo::getMaxAlign(), llvm::MachineFrameInfo::getObjectAlign(), llvm::MachineFrameInfo::getObjectIndexBegin(), llvm::MachineFrameInfo::getObjectIndexEnd(), llvm::MachineFrameInfo::getObjectOffset(), llvm::MachineFrameInfo::getObjectSize(), llvm::TargetFrameLowering::getOffsetOfLocalArea(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::TargetFrameLowering::getStackAlignmentSkew(), llvm::TargetFrameLowering::getStackGrowthDirection(), llvm::MachineFrameInfo::getStackID(), llvm::MachineFunction::getSubtarget(), llvm::MachineFrameInfo::getUseLocalStackAllocationBlock(), llvm::TargetFrameLowering::hasFP(), I, llvm::ARM_PROC::IE, llvm::SmallSet< T, N, C >::insert(), llvm::MachineFrameInfo::isDeadObjectIndex(), llvm::TargetFrameLowering::isFPCloseToIncomingSP(), LLVM_DEBUG, llvm::TargetRegisterInfo::needsStackRealignment(), llvm::MachineFrameInfo::setObjectOffset(), llvm::TargetFrameLowering::StackGrowsDown, and llvm::TargetRegisterInfo::useFPForScavengingIndex().

Referenced by INITIALIZE_PASS().

◆ computeFreeStackSlots()

static void computeFreeStackSlots ( MachineFrameInfo MFI,
bool  StackGrowsDown,
unsigned  MinCSFrameIndex,
unsigned  MaxCSFrameIndex,
int64_t  FixedCSEnd,
BitVector StackBytesFree 
)
inlinestatic

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( PEI  ,
DEBUG_TYPE  ,
"Prologue/Epilogue Insertion"  ,
false  ,
false   
)

◆ insertCSRRestores()

static void insertCSRRestores ( MachineBasicBlock RestoreBlock,
std::vector< CalleeSavedInfo > &  CSI 
)
static

◆ insertCSRSaves()

static void insertCSRSaves ( MachineBasicBlock SaveBlock,
ArrayRef< CalleeSavedInfo CSI 
)
static

◆ scavengeStackSlot()

static bool scavengeStackSlot ( MachineFrameInfo MFI,
int  FrameIdx,
bool  StackGrowsDown,
Align  MaxAlign,
BitVector StackBytesFree 
)
inlinestatic

◆ stashEntryDbgValues()

static void stashEntryDbgValues ( MachineBasicBlock MBB,
SavedDbgValuesMap EntryDbgValues 
)
static

Stash DBG_VALUEs that describe parameters and which are placed at the start of the block.

Later on, after the prologue code has been emitted, the stashed DBG_VALUEs will be reinserted at the start of the block.

Definition at line 179 of file PrologEpilogInserter.cpp.

References llvm::MachineFrameInfo::adjustsStack(), assert(), llvm::MachineFunction::begin(), llvm::TargetFrameLowering::canSimplifyCallFramePseudos(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(), DEBUG_TYPE, llvm::LLVMContext::diagnose(), llvm::numbers::e, E, llvm::TargetFrameLowering::eliminateCallFramePseudoInstr(), llvm::MachineFunction::end(), llvm::InlineAsm::Extra_IsAlignStack, F(), llvm::DIExpression::fragmentsOverlap(), llvm::MachineFunction::front(), llvm::TargetInstrInfo::getCallFrameDestroyOpcode(), llvm::TargetInstrInfo::getCallFrameSetupOpcode(), llvm::Function::getContext(), llvm::MachineFunction::getFrameInfo(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::TargetInstrInfo::getFrameSize(), llvm::MachineFunction::getFunction(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MachineFrameInfo::getMaxCallFrameSize(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFrameInfo::getRestorePoint(), llvm::MachineFrameInfo::getSavePoint(), llvm::MachineFrameInfo::getStackSize(), llvm::Function::getSubprogram(), llvm::MachineFunction::getSubtarget(), llvm::MachineFunction::getTarget(), llvm::Function::hasFnAttribute(), I, llvm::MachineBasicBlock::isEHFuncletEntry(), llvm::TargetInstrInfo::isFrameInstr(), llvm::MachineFrameInfo::isMaxCallFrameSizeComputed(), llvm::MachineBasicBlock::isReturnBlock(), MBB, MI, llvm::InlineAsm::MIOp_ExtraInfo, llvm::none_of(), llvm::TargetFrameLowering::processFunctionBeforeFrameFinalized(), llvm::TargetFrameLowering::processFunctionBeforeFrameIndicesReplaced(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::MachineBasicBlock::push_back(), llvm::TargetRegisterInfo::requiresFrameIndexScavenging(), llvm::TargetRegisterInfo::requiresRegisterScavenging(), llvm::scavengeFrameVirtualRegs(), llvm::MachineFrameInfo::setAdjustsStack(), llvm::MachineFrameInfo::setMaxCallFrameSize(), llvm::MachineFrameInfo::setRestorePoint(), llvm::MachineFrameInfo::setSavePoint(), Size, TII, TRI, llvm::LLVMTargetMachine::usesPhysRegsForValues(), and WarnStackSize.

◆ STATISTIC() [1/3]

STATISTIC ( NumLeafFuncWithSpills  ,
"Number of leaf functions with CSRs"   
)

◆ STATISTIC() [2/3]

STATISTIC ( NumFuncSeen  ,
"Number of functions seen in PEI"   
)

◆ STATISTIC() [3/3]

STATISTIC ( NumBytesStackSpace  ,
"Number of bytes used for stack in all functions  
)

◆ updateLiveness()

static void updateLiveness ( MachineFunction MF)
static

Helper function to update the liveness information for the callee-saved registers.

Definition at line 463 of file PrologEpilogInserter.cpp.

References llvm::MachineFunction::getFrameInfo().

Referenced by insertCSRRestores().

Variable Documentation

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 151 of file PrologEpilogInserter.cpp.

◆ false

Prologue Epilogue Insertion& Frame false

Definition at line 151 of file PrologEpilogInserter.cpp.

◆ Finalization

Prologue Epilogue Insertion& Frame Finalization

Definition at line 151 of file PrologEpilogInserter.cpp.

◆ WarnStackSize

cl::opt<unsigned> WarnStackSize("warn-stack-size", cl::Hidden, cl::init((unsigned) -1), cl::desc("Warn for stack size bigger than the given" " number"))
static

Referenced by stashEntryDbgValues().