LLVM 22.0.0git
ShrinkWrap.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "shrink-wrap"

Functions

 STATISTIC (NumFunc, "Number of functions")
 STATISTIC (NumCandidates, "Number of shrink-wrapping candidates")
 STATISTIC (NumCandidatesDropped, "Number of shrink-wrapping candidates dropped because of frequency")
 INITIALIZE_PASS_BEGIN (ShrinkWrapLegacy, DEBUG_TYPE, "Shrink Wrap Pass", false, false) INITIALIZE_PASS_END(ShrinkWrapLegacy
template<typename ListOfBBs, typename DominanceAnalysis>
static MachineBasicBlockFindIDom (MachineBasicBlock &Block, ListOfBBs BBs, DominanceAnalysis &Dom, bool Strict=true)
 Helper function to find the immediate (post) dominator.
static bool isAnalyzableBB (const TargetInstrInfo &TII, MachineBasicBlock &Entry)
static bool hasDirtyPred (const DenseSet< const MachineBasicBlock * > &ReachableByDirty, const MachineBasicBlock &MBB)
 Determines if any predecessor of MBB is on the path from block that has use or def of CSRs/FI to MBB.
static void markAllReachable (DenseSet< const MachineBasicBlock * > &Visited, const MachineBasicBlock &MBB)
 Derives the list of all the basic blocks reachable from MBB.
static void collectBlocksReachableByDirty (const DenseSet< const MachineBasicBlock * > &DirtyBBs, DenseSet< const MachineBasicBlock * > &ReachableByDirty)
 Collect blocks reachable by use or def of CSRs/FI.
static bool isSaveReachableThroughClean (const MachineBasicBlock *SavePoint, ArrayRef< MachineBasicBlock * > CleanPreds)
static void updateTerminator (MachineBasicBlock *BBToUpdate, MachineBasicBlock *NMBB, const TargetInstrInfo *TII)
 This function updates the branches post restore point split.
static MachineBasicBlocktryToSplitRestore (MachineBasicBlock *MBB, ArrayRef< MachineBasicBlock * > DirtyPreds, const TargetInstrInfo *TII)
 This function splits the restore point and returns new restore point/BB.
static void rollbackRestoreSplit (MachineFunction &MF, MachineBasicBlock *NMBB, MachineBasicBlock *MBB, ArrayRef< MachineBasicBlock * > DirtyPreds, const TargetInstrInfo *TII)
 This function undoes the restore point split done earlier.
static bool giveUpWithRemarks (MachineOptimizationRemarkEmitter *ORE, StringRef RemarkName, StringRef RemarkMessage, const DiagnosticLocation &Loc, const MachineBasicBlock *MBB)

Variables

static cl::opt< cl::boolOrDefaultEnableShrinkWrapOpt ("enable-shrink-wrap", cl::Hidden, cl::desc("enable the shrink-wrapping pass"))
static cl::opt< boolEnablePostShrinkWrapOpt ("enable-shrink-wrap-region-split", cl::init(true), cl::Hidden, cl::desc("enable splitting of the restore block if possible"))
 DEBUG_TYPE
Shrink Wrap Pass
Shrink Wrap false

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "shrink-wrap"

Definition at line 91 of file ShrinkWrap.cpp.

Function Documentation

◆ collectBlocksReachableByDirty()

void collectBlocksReachableByDirty ( const DenseSet< const MachineBasicBlock * > & DirtyBBs,
DenseSet< const MachineBasicBlock * > & ReachableByDirty )
static

Collect blocks reachable by use or def of CSRs/FI.

Definition at line 430 of file ShrinkWrap.cpp.

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), markAllReachable(), and MBB.

◆ FindIDom()

template<typename ListOfBBs, typename DominanceAnalysis>
MachineBasicBlock * FindIDom ( MachineBasicBlock & Block,
ListOfBBs BBs,
DominanceAnalysis & Dom,
bool Strict = true )
static

Helper function to find the immediate (post) dominator.

Definition at line 387 of file ShrinkWrap.cpp.

References llvm::Block, and llvm::iterator_range().

◆ giveUpWithRemarks()

bool giveUpWithRemarks ( MachineOptimizationRemarkEmitter * ORE,
StringRef RemarkName,
StringRef RemarkMessage,
const DiagnosticLocation & Loc,
const MachineBasicBlock * MBB )
static

◆ hasDirtyPred()

bool hasDirtyPred ( const DenseSet< const MachineBasicBlock * > & ReachableByDirty,
const MachineBasicBlock & MBB )
static

Determines if any predecessor of MBB is on the path from block that has use or def of CSRs/FI to MBB.

ReachableByDirty: All blocks reachable from block that has use or def of CSR/FI.

Definition at line 408 of file ShrinkWrap.cpp.

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), and MBB.

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( ShrinkWrapLegacy ,
DEBUG_TYPE ,
"Shrink Wrap Pass" ,
false ,
false  )

◆ isAnalyzableBB()

bool isAnalyzableBB ( const TargetInstrInfo & TII,
MachineBasicBlock & Entry )
static

Definition at line 395 of file ShrinkWrap.cpp.

References Cond, TBB, and TII.

◆ isSaveReachableThroughClean()

◆ markAllReachable()

◆ rollbackRestoreSplit()

void rollbackRestoreSplit ( MachineFunction & MF,
MachineBasicBlock * NMBB,
MachineBasicBlock * MBB,
ArrayRef< MachineBasicBlock * > DirtyPreds,
const TargetInstrInfo * TII )
static

This function undoes the restore point split done earlier.

DirtyPreds: All predecessors of NMBB that are ReachableByDirty.

Restore point was split and the change needs to be unrolled. Make necessary changes to reset restore point from NMBB to MBB.

Definition at line 533 of file ShrinkWrap.cpp.

References llvm::MachineBasicBlock::begin(), llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::erase(), llvm::MachineBasicBlock::eraseFromParent(), llvm::SmallPtrSetImpl< PtrType >::insert(), MBB, llvm::MachineBasicBlock::removeSuccessor(), TII, and updateTerminator().

◆ STATISTIC() [1/3]

STATISTIC ( NumCandidates ,
"Number of shrink-wrapping candidates"  )

◆ STATISTIC() [2/3]

STATISTIC ( NumCandidatesDropped ,
"Number of shrink-wrapping candidates dropped because of frequency"  )

◆ STATISTIC() [3/3]

STATISTIC ( NumFunc ,
"Number of functions"  )

◆ tryToSplitRestore()

MachineBasicBlock * tryToSplitRestore ( MachineBasicBlock * MBB,
ArrayRef< MachineBasicBlock * > DirtyPreds,
const TargetInstrInfo * TII )
static

This function splits the restore point and returns new restore point/BB.

DirtyPreds: Predessors of MBB that are ReachableByDirty

Decision has been made to split the restore point. old restore point: MBB new restore point: NMBB This function makes the necessary block layout changes so that

  1. NMBB points to MBB unconditionally
  2. All dirtyPreds that previously pointed to MBB point to NMBB

Definition at line 490 of file ShrinkWrap.cpp.

References llvm::MachineBasicBlock::addLiveIn(), llvm::MachineBasicBlock::addSuccessor(), llvm::MachineFunction::CreateMachineBasicBlock(), llvm::dwarf_linker::DebugLoc, llvm::MachineFunction::end(), llvm::MachineFunction::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), MBB, TII, and updateTerminator().

◆ updateTerminator()

void updateTerminator ( MachineBasicBlock * BBToUpdate,
MachineBasicBlock * NMBB,
const TargetInstrInfo * TII )
static

This function updates the branches post restore point split.

Restore point has been split. Old restore point: MBB New restore point: NMBB Any basic block(say BBToUpdate) which had a fallthrough to MBB previously should

  1. Fallthrough to NMBB iff NMBB is inserted immediately above MBB in the block layout OR
  2. Branch unconditionally to NMBB iff NMBB is inserted at any other place.

Definition at line 469 of file ShrinkWrap.cpp.

References DL, llvm::MachineBasicBlock::findBranchDebugLoc(), llvm::MachineBasicBlock::isLayoutSuccessor(), and TII.

Referenced by rollbackRestoreSplit(), and tryToSplitRestore().

Variable Documentation

◆ DEBUG_TYPE

DEBUG_TYPE

Definition at line 301 of file ShrinkWrap.cpp.

◆ EnablePostShrinkWrapOpt

cl::opt< bool > EnablePostShrinkWrapOpt("enable-shrink-wrap-region-split", cl::init(true), cl::Hidden, cl::desc("enable splitting of the restore block if possible")) ( "enable-shrink-wrap-region-split" ,
cl::init(true) ,
cl::Hidden ,
cl::desc("enable splitting of the restore block if possible")  )
static

◆ EnableShrinkWrapOpt

cl::opt< cl::boolOrDefault > EnableShrinkWrapOpt("enable-shrink-wrap", cl::Hidden, cl::desc("enable the shrink-wrapping pass")) ( "enable-shrink-wrap" ,
cl::Hidden ,
cl::desc("enable the shrink-wrapping pass")  )
static

◆ false

Shrink Wrap false

Definition at line 301 of file ShrinkWrap.cpp.

◆ Pass

Shrink Wrap Pass

Definition at line 301 of file ShrinkWrap.cpp.

Referenced by analyzeFunction(), and llvm::SanitizerBinaryMetadataPass::run().