2007-02-23 01:01:19 +00:00
|
|
|
//===-- RegisterScavenging.h - Machine register scavenging ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-02-23 01:01:19 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the machine register scavenger class. It can provide
|
|
|
|
// information such as unused register at any point in a machine basic block.
|
|
|
|
// It also provides a mechanism to make registers availbale by evicting them
|
|
|
|
// to spill slots.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_REGISTER_SCAVENGING_H
|
|
|
|
#define LLVM_CODEGEN_REGISTER_SCAVENGING_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/ADT/BitVector.h"
|
2008-11-20 02:32:35 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-02-23 01:01:19 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2008-04-05 02:17:58 +00:00
|
|
|
class MachineRegisterInfo;
|
2008-02-10 18:45:23 +00:00
|
|
|
class TargetRegisterInfo;
|
2007-03-06 10:01:25 +00:00
|
|
|
class TargetInstrInfo;
|
2007-02-23 01:01:19 +00:00
|
|
|
class TargetRegisterClass;
|
|
|
|
|
|
|
|
class RegScavenger {
|
2008-11-20 02:32:35 +00:00
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
MachineRegisterInfo* MRI;
|
2007-02-23 01:01:19 +00:00
|
|
|
MachineBasicBlock *MBB;
|
|
|
|
MachineBasicBlock::iterator MBBI;
|
|
|
|
unsigned NumPhysRegs;
|
|
|
|
|
2007-02-27 22:58:43 +00:00
|
|
|
/// Tracking - True if RegScavenger is currently tracking the liveness of
|
|
|
|
/// registers.
|
|
|
|
bool Tracking;
|
2007-02-27 21:09:48 +00:00
|
|
|
|
2007-03-06 10:01:25 +00:00
|
|
|
/// ScavengingFrameIndex - Special spill slot used for scavenging a register
|
|
|
|
/// post register allocation.
|
|
|
|
int ScavengingFrameIndex;
|
|
|
|
|
|
|
|
/// ScavengedReg - If none zero, the specific register is currently being
|
|
|
|
/// scavenged. That is, it is spilled to the special scavenging stack slot.
|
|
|
|
unsigned ScavengedReg;
|
|
|
|
|
|
|
|
/// ScavengedRC - Register class of the scavenged register.
|
|
|
|
///
|
|
|
|
const TargetRegisterClass *ScavengedRC;
|
|
|
|
|
2008-11-20 02:32:35 +00:00
|
|
|
/// ScavengeRestore - Instruction that restores the scavenged register from
|
|
|
|
/// stack.
|
|
|
|
const MachineInstr *ScavengeRestore;
|
|
|
|
|
|
|
|
/// CalleeSavedrRegs - A bitvector of callee saved registers for the target.
|
|
|
|
///
|
|
|
|
BitVector CalleeSavedRegs;
|
|
|
|
|
|
|
|
/// ReservedRegs - A bitvector of reserved registers.
|
|
|
|
///
|
|
|
|
BitVector ReservedRegs;
|
|
|
|
|
2007-03-26 22:23:54 +00:00
|
|
|
/// RegsAvailable - The current state of all the physical registers immediately
|
2007-02-23 01:01:19 +00:00
|
|
|
/// before MBBI. One bit per physical register. If bit is set that means it's
|
|
|
|
/// available, unset means the register is currently being used.
|
2007-03-26 22:23:54 +00:00
|
|
|
BitVector RegsAvailable;
|
2007-02-23 01:01:19 +00:00
|
|
|
|
2008-11-20 02:32:35 +00:00
|
|
|
/// CurrDist - Distance from MBB entry to the current instruction MBBI.
|
|
|
|
///
|
|
|
|
unsigned CurrDist;
|
|
|
|
|
|
|
|
/// DistanceMap - Keep track the distance of a MI from the start of the
|
|
|
|
/// current basic block.
|
|
|
|
DenseMap<MachineInstr*, unsigned> DistanceMap;
|
|
|
|
|
2007-02-23 01:01:19 +00:00
|
|
|
public:
|
2007-02-27 21:09:48 +00:00
|
|
|
RegScavenger()
|
2007-03-06 10:01:25 +00:00
|
|
|
: MBB(NULL), NumPhysRegs(0), Tracking(false),
|
2007-08-27 14:50:10 +00:00
|
|
|
ScavengingFrameIndex(-1), ScavengedReg(0), ScavengedRC(NULL) {}
|
2007-02-27 21:09:48 +00:00
|
|
|
|
2007-03-01 02:18:06 +00:00
|
|
|
/// enterBasicBlock - Start tracking liveness from the begin of the specific
|
|
|
|
/// basic block.
|
|
|
|
void enterBasicBlock(MachineBasicBlock *mbb);
|
2007-02-23 01:01:19 +00:00
|
|
|
|
|
|
|
/// forward / backward - Move the internal MBB iterator and update register
|
|
|
|
/// states.
|
|
|
|
void forward();
|
|
|
|
void backward();
|
|
|
|
|
2007-02-27 01:58:48 +00:00
|
|
|
/// forward / backward - Move the internal MBB iterator and update register
|
2007-03-18 03:26:04 +00:00
|
|
|
/// states until it has processed the specific iterator.
|
2007-02-27 21:09:48 +00:00
|
|
|
void forward(MachineBasicBlock::iterator I) {
|
2008-12-19 00:45:13 +00:00
|
|
|
if (!Tracking && MBB->begin() != I) forward();
|
2007-02-27 21:09:48 +00:00
|
|
|
while (MBBI != I) forward();
|
|
|
|
}
|
|
|
|
void backward(MachineBasicBlock::iterator I) {
|
|
|
|
while (MBBI != I) backward();
|
|
|
|
}
|
2007-02-27 01:58:48 +00:00
|
|
|
|
2007-03-07 02:36:16 +00:00
|
|
|
/// skipTo - Move the internal MBB iterator but do not update register states.
|
|
|
|
///
|
|
|
|
void skipTo(MachineBasicBlock::iterator I) { MBBI = I; }
|
|
|
|
|
2007-02-23 01:01:19 +00:00
|
|
|
/// isReserved - Returns true if a register is reserved. It is never "unused".
|
|
|
|
bool isReserved(unsigned Reg) const { return ReservedRegs[Reg]; }
|
|
|
|
|
|
|
|
/// isUsed / isUsed - Test if a register is currently being used.
|
|
|
|
///
|
2007-03-26 22:23:54 +00:00
|
|
|
bool isUsed(unsigned Reg) const { return !RegsAvailable[Reg]; }
|
|
|
|
bool isUnused(unsigned Reg) const { return RegsAvailable[Reg]; }
|
2007-02-23 01:01:19 +00:00
|
|
|
|
2007-03-20 21:35:06 +00:00
|
|
|
/// getRegsUsed - return all registers currently in use in used.
|
|
|
|
void getRegsUsed(BitVector &used, bool includeReserved);
|
|
|
|
|
2007-02-23 01:01:19 +00:00
|
|
|
/// setUsed / setUnused - Mark the state of one or a number of registers.
|
|
|
|
///
|
2009-07-01 08:19:36 +00:00
|
|
|
void setUsed(unsigned Reg);
|
|
|
|
void setUsed(BitVector &Regs) {
|
2008-04-10 23:47:53 +00:00
|
|
|
RegsAvailable &= ~Regs;
|
|
|
|
}
|
2008-03-06 23:22:43 +00:00
|
|
|
void setUnused(unsigned Reg, const MachineInstr *MI);
|
2009-02-06 09:16:15 +00:00
|
|
|
void setUnused(BitVector &Regs) {
|
2008-04-10 23:47:53 +00:00
|
|
|
RegsAvailable |= Regs;
|
|
|
|
}
|
2007-02-23 01:01:19 +00:00
|
|
|
|
2007-03-01 08:56:24 +00:00
|
|
|
/// FindUnusedReg - Find a unused register of the specified register class
|
|
|
|
/// from the specified set of registers. It return 0 is none is found.
|
|
|
|
unsigned FindUnusedReg(const TargetRegisterClass *RegClass,
|
|
|
|
const BitVector &Candidates) const;
|
|
|
|
|
2007-02-23 01:01:19 +00:00
|
|
|
/// FindUnusedReg - Find a unused register of the specified register class.
|
|
|
|
/// Exclude callee saved registers if directed. It return 0 is none is found.
|
|
|
|
unsigned FindUnusedReg(const TargetRegisterClass *RegClass,
|
|
|
|
bool ExCalleeSaved = false) const;
|
|
|
|
|
2007-03-06 10:01:25 +00:00
|
|
|
/// setScavengingFrameIndex / getScavengingFrameIndex - accessor and setter of
|
|
|
|
/// ScavengingFrameIndex.
|
|
|
|
void setScavengingFrameIndex(int FI) { ScavengingFrameIndex = FI; }
|
|
|
|
int getScavengingFrameIndex() const { return ScavengingFrameIndex; }
|
|
|
|
|
|
|
|
/// scavengeRegister - Make a register of the specific register class
|
2007-05-01 08:59:18 +00:00
|
|
|
/// available and do the appropriate bookkeeping. SPAdj is the stack
|
|
|
|
/// adjustment due to call frame, it's passed along to eliminateFrameIndex().
|
|
|
|
/// Returns the scavenged register.
|
2007-03-06 10:01:25 +00:00
|
|
|
unsigned scavengeRegister(const TargetRegisterClass *RegClass,
|
2007-05-01 08:59:18 +00:00
|
|
|
MachineBasicBlock::iterator I, int SPAdj);
|
|
|
|
unsigned scavengeRegister(const TargetRegisterClass *RegClass, int SPAdj) {
|
|
|
|
return scavengeRegister(RegClass, MBBI, SPAdj);
|
2007-03-06 10:01:25 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 01:01:19 +00:00
|
|
|
private:
|
2007-03-06 10:01:25 +00:00
|
|
|
/// restoreScavengedReg - Restore scavenged by loading it back from the
|
|
|
|
/// emergency spill slot. Mark it used.
|
|
|
|
void restoreScavengedReg();
|
2008-11-20 02:32:35 +00:00
|
|
|
|
|
|
|
MachineInstr *findFirstUse(MachineBasicBlock *MBB,
|
|
|
|
MachineBasicBlock::iterator I, unsigned Reg,
|
|
|
|
unsigned &Dist);
|
2007-02-23 01:01:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|