LLVM  8.0.1
Macros | Functions | Variables
StackColoring.cpp File Reference
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/CodeGen/LiveInterval.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/WinEHFuncInfo.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <limits>
#include <memory>
#include <utility>
Include dependency graph for StackColoring.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "stack-coloring"
 

Functions

 STATISTIC (NumMarkerSeen, "Number of lifetime markers found.")
 
 STATISTIC (StackSpaceSaved, "Number of bytes saved due to merging slots.")
 
 STATISTIC (StackSlotMerged, "Number of stack slot merged.")
 
 STATISTIC (EscapedAllocas, "Number of allocas that escaped the lifetime region")
 
 INITIALIZE_PASS_BEGIN (StackColoring, DEBUG_TYPE, "Merge disjoint stack slots", false, false) INITIALIZE_PASS_END(StackColoring
 
static int getStartOrEndSlot (const MachineInstr &MI)
 

Variables

static cl::opt< boolDisableColoring ("no-stack-coloring", cl::init(false), cl::Hidden, cl::desc("Disable stack coloring"))
 
static cl::opt< boolProtectFromEscapedAllocas ("protect-from-escaped-allocas", cl::init(false), cl::Hidden, cl::desc("Do not optimize lifetime zones that " "are broken"))
 The user may write code that uses allocas outside of the declared lifetime zone. More...
 
static cl::opt< boolLifetimeStartOnFirstUse ("stackcoloring-lifetime-start-on-first-use", cl::init(true), cl::Hidden, cl::desc("Treat stack lifetimes as starting on first use, not on START marker."))
 Enable enhanced dataflow scheme for lifetime analysis (treat first use of stack slot as start of slot lifetime, as opposed to looking for LIFETIME_START marker). More...
 
 DEBUG_TYPE
 
Merge disjoint stack slots
 
Merge disjoint stack false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "stack-coloring"

Definition at line 66 of file StackColoring.cpp.

Function Documentation

◆ getStartOrEndSlot()

static int getStartOrEndSlot ( const MachineInstr MI)
inlinestatic

Definition at line 567 of file StackColoring.cpp.

References assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::WinEHHandlerType::CatchObj, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::LiveRange::clear(), llvm::SmallVectorImpl< T >::clear(), llvm::BitVector::clear(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::depth_first(), DisableColoring, llvm::dump(), llvm::SmallVectorBase::empty(), llvm::empty(), llvm::LiveRange::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::LiveRange::end(), llvm::MachineInstr::eraseFromParent(), llvm::LiveRange::find(), llvm::WinEHHandlerType::FrameIndex, From, llvm::Use::get(), llvm::UndefValue::get(), llvm::MachineFunction::getFunction(), llvm::MachineOperand::getIndex(), llvm::SlotIndexes::getInstructionIndex(), llvm::SlotIndexes::getMBBEndIdx(), llvm::SlotIndexes::getMBBStartIdx(), llvm::Value::getName(), llvm::MachineFunction::getName(), llvm::MachineFrameInfo::getObjectAlignment(), llvm::MachineFrameInfo::getObjectAllocation(), llvm::MachineFrameInfo::getObjectIndexEnd(), llvm::MachineFrameInfo::getObjectSize(), llvm::MachineFrameInfo::getObjectSSPLayout(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getOperand(), llvm::AllocaInst::getType(), llvm::getUnderlyingObjectsForCodeGen(), llvm::LiveRange::getValNumInfo(), llvm::MachineFunction::getVariableDbgInfo(), llvm::SlotIndexes::getZeroIndex(), H, llvm::WinEHTryBlockMapEntry::HandlerArray, llvm::ValueAsMetadata::handleRAUW(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::insertAfter(), llvm::MachineInstr::isDebugInstr(), llvm::LiveRange::isLiveAtIndexes(), llvm::Value::isUsedByMetadata(), llvm::ISD::LIFETIME_END, llvm::ISD::LIFETIME_START, LifetimeStartOnFirstUse, LLVM_DEBUG, llvm::max(), llvm::LiveRange::MergeSegmentsInAsValue(), MI, llvm::MachineInstr::operands(), llvm::MachineBasicBlock::pred_begin(), llvm::MachineBasicBlock::pred_end(), llvm::SlotIndex::print(), llvm::printMBBReference(), ProtectFromEscapedAllocas, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::MachineFrameInfo::RemoveStackObject(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::reserve(), llvm::BumpPtrAllocatorImpl< AllocatorT, SlabSize, SizeThreshold >::Reset(), llvm::BitVector::reset(), llvm::SmallVectorImpl< T >::resize(), llvm::BitVector::resize(), llvm::BitVector::set(), llvm::MachineFrameInfo::setObjectAlignment(), llvm::MachineFrameInfo::setObjectSSPLayout(), SI, llvm::SmallVectorBase::size(), slots, llvm::sort(), llvm::MachineFrameInfo::SSPLK_AddrOf, llvm::MachineFrameInfo::SSPLK_LargeArray, llvm::MachineFrameInfo::SSPLK_None, llvm::BitVector::test(), llvm::Value::uses(), and VI.

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( StackColoring  ,
DEBUG_TYPE  ,
"Merge disjoint stack slots ,
false  ,
false   
)

◆ STATISTIC() [1/4]

STATISTIC ( NumMarkerSeen  ,
"Number of lifetime markers found."   
)

◆ STATISTIC() [2/4]

STATISTIC ( StackSpaceSaved  ,
"Number of bytes saved due to merging slots."   
)

◆ STATISTIC() [3/4]

STATISTIC ( StackSlotMerged  ,
"Number of stack slot merged."   
)

◆ STATISTIC() [4/4]

STATISTIC ( EscapedAllocas  ,
"Number of allocas that escaped the lifetime region"   
)

Variable Documentation

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 523 of file StackColoring.cpp.

◆ DisableColoring

cl::opt<bool> DisableColoring("no-stack-coloring", cl::init(false), cl::Hidden, cl::desc("Disable stack coloring"))
static

Referenced by getStartOrEndSlot().

◆ false

Merge disjoint stack false

Definition at line 523 of file StackColoring.cpp.

◆ LifetimeStartOnFirstUse

cl::opt<bool> LifetimeStartOnFirstUse("stackcoloring-lifetime-start-on-first-use", cl::init(true), cl::Hidden, cl::desc("Treat stack lifetimes as starting on first use, not on START marker."))
static

Enable enhanced dataflow scheme for lifetime analysis (treat first use of stack slot as start of slot lifetime, as opposed to looking for LIFETIME_START marker).

See "Implementation notes" below for more info.

Referenced by getStartOrEndSlot().

◆ ProtectFromEscapedAllocas

cl::opt<bool> ProtectFromEscapedAllocas("protect-from-escaped-allocas", cl::init(false), cl::Hidden, cl::desc("Do not optimize lifetime zones that " "are broken"))
static

The user may write code that uses allocas outside of the declared lifetime zone.

This can happen when the user returns a reference to a local data-structure. We can detect these cases and decide not to optimize the code. If this flag is enabled, we try to save the user. This option is treated as overriding LifetimeStartOnFirstUse below.

Referenced by getStartOrEndSlot().

◆ slots

Merge disjoint stack slots

Definition at line 523 of file StackColoring.cpp.

Referenced by getStartOrEndSlot().