LLVM  16.0.0git
Macros | Functions
RegisterScavenging.cpp File Reference
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/LiveRegUnits.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/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <iterator>
#include <limits>
#include <utility>
Include dependency graph for RegisterScavenging.cpp:

Go to the source code of this file.


#define DEBUG_TYPE   "reg-scavenging"


 STATISTIC (NumScavengedRegs, "Number of frame index regs scavenged")
static std::pair< MCPhysReg, MachineBasicBlock::iteratorfindSurvivorBackwards (const MachineRegisterInfo &MRI, MachineBasicBlock::iterator From, MachineBasicBlock::iterator To, const LiveRegUnits &LiveOut, ArrayRef< MCPhysReg > AllocationOrder, bool RestoreAfter)
 Given the bitvector Available of free register units at position From. More...
static unsigned getFrameIndexOperandNum (MachineInstr &MI)
static Register scavengeVReg (MachineRegisterInfo &MRI, RegScavenger &RS, Register VReg, bool ReserveAfter)
 Allocate a register for the virtual register VReg. More...
static bool scavengeFrameVirtualRegsInBlock (MachineRegisterInfo &MRI, RegScavenger &RS, MachineBasicBlock &MBB)
 Allocate (scavenge) vregs inside a single basic block. More...

Detailed Description

This file implements the machine register scavenger. It can provide information, such as unused registers, at any point in a machine basic block. It also provides a mechanism to make registers available by evicting them to spill slots.

Definition in file RegisterScavenging.cpp.

Macro Definition Documentation


#define DEBUG_TYPE   "reg-scavenging"

Definition at line 47 of file RegisterScavenging.cpp.

Function Documentation

◆ findSurvivorBackwards()

static std::pair<MCPhysReg, MachineBasicBlock::iterator> findSurvivorBackwards ( const MachineRegisterInfo MRI,
MachineBasicBlock::iterator  From,
MachineBasicBlock::iterator  To,
const LiveRegUnits LiveOut,
ArrayRef< MCPhysReg >  AllocationOrder,
bool  RestoreAfter 

Given the bitvector Available of free register units at position From.

Search backwards to find a register that is part of Candidates and not used/clobbered until the point To. If there is multiple candidates continue searching and pick the one that is not used/ clobbered for the longest time. Returns the register and the earliest position we know it to be free or the position MBB.end() if no register is available.

Definition at line 357 of file RegisterScavenging.cpp.

References assert(), llvm::LiveRegUnits::available(), llvm::MachineBasicBlock::begin(), llvm::MachineBasicBlock::end(), llvm::MachineInstr::FrameSetup, From, llvm::MachineRegisterInfo::getTargetRegisterInfo(), I, InstrLimit, llvm::MachineRegisterInfo::isReserved(), llvm::Register::isVirtualRegister(), MBB, MI, MRI, and TRI.

Referenced by llvm::RegScavenger::scavengeRegisterBackwards().

◆ getFrameIndexOperandNum()

static unsigned getFrameIndexOperandNum ( MachineInstr MI)

Definition at line 442 of file RegisterScavenging.cpp.

References assert(), i, and MI.

◆ scavengeFrameVirtualRegsInBlock()

static bool scavengeFrameVirtualRegsInBlock ( MachineRegisterInfo MRI,
RegScavenger RS,
MachineBasicBlock MBB 

◆ scavengeVReg()

static Register scavengeVReg ( MachineRegisterInfo MRI,
RegScavenger RS,
Register  VReg,
bool  ReserveAfter 

Allocate a register for the virtual register VReg.

The last use of VReg is around the current position of the register scavenger RS. ReserveAfter controls whether the scavenged register needs to be reserved after the current instruction, otherwise it will only be reserved before the current instruction.

Definition at line 637 of file RegisterScavenging.cpp.

References assert(), llvm::MachineRegisterInfo::def_end(), llvm::MachineRegisterInfo::def_operands(), DefMI, llvm::find_if(), llvm::MachineOperand::getParent(), llvm::MachineBasicBlock::getParent(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineRegisterInfo::getTargetRegisterInfo(), MBB, MI, MRI, llvm::MachineRegisterInfo::reg_nodbg_operands(), llvm::MachineRegisterInfo::replaceRegWith(), llvm::RegScavenger::scavengeRegisterBackwards(), and TRI.

Referenced by scavengeFrameVirtualRegsInBlock().


STATISTIC ( NumScavengedRegs  ,
"Number of frame index regs scavenged"