LLVM 19.0.0git
Macros | Functions
RegisterScavenging.cpp File Reference

This file implements the machine register scavenger. More...

#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>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "reg-scavenging"
 

Functions

 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.
 
static unsigned getFrameIndexOperandNum (MachineInstr &MI)
 
static Register scavengeVReg (MachineRegisterInfo &MRI, RegScavenger &RS, Register VReg, bool ReserveAfter)
 Allocate a register for the virtual register VReg.
 
static bool scavengeFrameVirtualRegsInBlock (MachineRegisterInfo &MRI, RegScavenger &RS, MachineBasicBlock &MBB)
 Allocate (scavenge) vregs inside a single basic block.
 

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

◆ DEBUG_TYPE

#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 
)
static

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 128 of file RegisterScavenging.cpp.

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

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

◆ getFrameIndexOperandNum()

static unsigned getFrameIndexOperandNum ( MachineInstr MI)
static

Definition at line 213 of file RegisterScavenging.cpp.

References assert(), and MI.

◆ scavengeFrameVirtualRegsInBlock()

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

Allocate (scavenge) vregs inside a single basic block.

Returns true if the target spill callback created new vregs and a 2nd pass is necessary.

Definition at line 392 of file RegisterScavenging.cpp.

References assert(), llvm::RegScavenger::backward(), llvm::MachineBasicBlock::begin(), llvm::MachineBasicBlock::end(), llvm::RegScavenger::enterBasicBlockEnd(), llvm::MachineBasicBlock::front(), I, MBB, MI, MRI, N, llvm::MachineInstr::operands(), scavengeVReg(), llvm::RegScavenger::setRegUsed(), TRI, and llvm::Register::virtReg2Index().

Referenced by llvm::scavengeFrameVirtualRegs().

◆ scavengeVReg()

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

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 339 of file RegisterScavenging.cpp.

References assert(), DefMI, llvm::find_if(), llvm::MachineOperand::getParent(), llvm::MachineBasicBlock::getParent(), MBB, MI, MRI, llvm::RegScavenger::scavengeRegisterBackwards(), and TRI.

Referenced by scavengeFrameVirtualRegsInBlock().

◆ STATISTIC()

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