LLVM  6.0.0svn
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/MC/MCRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <limits>
#include <string>
#include <utility>
Include dependency graph for RegisterScavenging.cpp:

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. More...
 
static unsigned getFrameIndexOperandNum (MachineInstr &MI)
 
static unsigned scavengeVReg (MachineRegisterInfo &MRI, RegScavenger &RS, unsigned 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

◆ DEBUG_TYPE

#define DEBUG_TYPE   "reg-scavenging"

Definition at line 49 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 379 of file RegisterScavenging.cpp.

References llvm::LiveRegUnits::accumulate(), llvm::LiveRegUnits::available(), llvm::MachineBasicBlock::begin(), llvm::MachineBasicBlock::end(), llvm::MachineRegisterInfo::getTargetRegisterInfo(), I, InstrLimit, llvm::MachineRegisterInfo::isReserved(), llvm::TargetRegisterInfo::isVirtualRegister(), MI, and llvm::MachineInstr::operands().

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

◆ getFrameIndexOperandNum()

static unsigned getFrameIndexOperandNum ( MachineInstr MI)
static

◆ scavengeFrameVirtualRegsInBlock()

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

◆ scavengeVReg()

static unsigned scavengeVReg ( MachineRegisterInfo MRI,
RegScavenger RS,
unsigned  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 614 of file RegisterScavenging.cpp.

References assert(), llvm::MachineRegisterInfo::def_begin(), llvm::MachineRegisterInfo::def_end(), DefMI, llvm::find_if(), llvm::MachineBasicBlock::getParent(), llvm::MachineOperand::getParent(), llvm::MachineRegisterInfo::getRegClass(), llvm::MachineRegisterInfo::getTargetRegisterInfo(), MI, llvm::MachineInstr::readsRegister(), llvm::MachineRegisterInfo::reg_nodbg_operands(), llvm::MachineRegisterInfo::replaceRegWith(), and llvm::RegScavenger::scavengeRegisterBackwards().

Referenced by scavengeFrameVirtualRegsInBlock().

◆ STATISTIC()

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