2012-02-17 17:35:10 +00:00
|
|
|
//===-- RegisterCoalescer.h - Register Coalescing Interface -----*- C++ -*-===//
|
2007-09-06 16:18:45 +00:00
|
|
|
//
|
|
|
|
// 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-09-06 16:18:45 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2012-02-17 17:35:10 +00:00
|
|
|
// This file contains the abstract interface for register coalescers,
|
2007-09-06 16:18:45 +00:00
|
|
|
// allowing them to interact with and query register allocators.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_REGISTER_COALESCER_H
|
|
|
|
#define LLVM_CODEGEN_REGISTER_COALESCER_H
|
|
|
|
|
2009-01-05 17:59:02 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2007-09-06 16:18:45 +00:00
|
|
|
class MachineInstr;
|
2010-06-15 16:04:21 +00:00
|
|
|
class TargetRegisterInfo;
|
|
|
|
class TargetRegisterClass;
|
|
|
|
class TargetInstrInfo;
|
2007-09-06 16:18:45 +00:00
|
|
|
|
2010-06-15 16:04:21 +00:00
|
|
|
/// CoalescerPair - A helper class for register coalescers. When deciding if
|
|
|
|
/// two registers can be coalesced, CoalescerPair can determine if a copy
|
|
|
|
/// instruction would become an identity copy after coalescing.
|
|
|
|
class CoalescerPair {
|
2011-08-09 01:01:27 +00:00
|
|
|
const TargetRegisterInfo &TRI;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// DstReg - The register that will be left after coalescing. It can be a
|
2010-06-15 16:04:21 +00:00
|
|
|
/// virtual or physical register.
|
2011-08-09 01:01:27 +00:00
|
|
|
unsigned DstReg;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// SrcReg - the virtual register that will be coalesced into dstReg.
|
|
|
|
unsigned SrcReg;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2012-05-15 20:09:43 +00:00
|
|
|
/// DstIdx - The sub-register index of the old DstReg in the new coalesced
|
|
|
|
/// register.
|
|
|
|
unsigned DstIdx;
|
|
|
|
|
|
|
|
/// SrcIdx - The sub-register index of the old SrcReg in the new coalesced
|
|
|
|
/// register.
|
|
|
|
unsigned SrcIdx;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// Partial - True when the original copy was a partial subregister copy.
|
|
|
|
bool Partial;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// CrossClass - True when both regs are virtual, and newRC is constrained.
|
|
|
|
bool CrossClass;
|
2010-06-24 16:19:28 +00:00
|
|
|
|
2012-03-13 05:43:30 +00:00
|
|
|
/// Flipped - True when DstReg and SrcReg are reversed from the original
|
2011-08-09 01:01:27 +00:00
|
|
|
/// copy instruction.
|
|
|
|
bool Flipped;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// NewRC - The register class of the coalesced register, or NULL if DstReg
|
2012-05-15 20:09:43 +00:00
|
|
|
/// is a physreg. This register class may be a super-register of both
|
|
|
|
/// SrcReg and DstReg.
|
2011-08-09 01:01:27 +00:00
|
|
|
const TargetRegisterClass *NewRC;
|
2010-06-15 16:04:21 +00:00
|
|
|
|
|
|
|
public:
|
2012-06-06 18:25:08 +00:00
|
|
|
CoalescerPair(const TargetRegisterInfo &tri)
|
|
|
|
: TRI(tri), DstReg(0), SrcReg(0), DstIdx(0), SrcIdx(0),
|
2011-08-09 01:01:27 +00:00
|
|
|
Partial(false), CrossClass(false), Flipped(false), NewRC(0) {}
|
2010-06-15 16:04:21 +00:00
|
|
|
|
|
|
|
/// setRegisters - set registers to match the copy instruction MI. Return
|
|
|
|
/// false if MI is not a coalescable copy instruction.
|
|
|
|
bool setRegisters(const MachineInstr*);
|
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// flip - Swap SrcReg and DstReg. Return false if swapping is impossible
|
|
|
|
/// because DstReg is a physical register, or SubIdx is set.
|
2010-06-15 16:04:21 +00:00
|
|
|
bool flip();
|
|
|
|
|
|
|
|
/// isCoalescable - Return true if MI is a copy instruction that will become
|
|
|
|
/// an identity copy after coalescing.
|
|
|
|
bool isCoalescable(const MachineInstr*) const;
|
|
|
|
|
|
|
|
/// isPhys - Return true if DstReg is a physical register.
|
2011-08-09 01:01:27 +00:00
|
|
|
bool isPhys() const { return !NewRC; }
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// isPartial - Return true if the original copy instruction did not copy
|
|
|
|
/// the full register, but was a subreg operation.
|
|
|
|
bool isPartial() const { return Partial; }
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2011-08-09 01:01:27 +00:00
|
|
|
/// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller
|
|
|
|
/// register class than DstReg's.
|
|
|
|
bool isCrossClass() const { return CrossClass; }
|
2010-06-24 16:19:28 +00:00
|
|
|
|
2010-06-15 16:04:21 +00:00
|
|
|
/// isFlipped - Return true when getSrcReg is the register being defined by
|
|
|
|
/// the original copy instruction.
|
2011-08-09 01:01:27 +00:00
|
|
|
bool isFlipped() const { return Flipped; }
|
2010-06-15 16:04:21 +00:00
|
|
|
|
|
|
|
/// getDstReg - Return the register (virtual or physical) that will remain
|
|
|
|
/// after coalescing.
|
2011-08-09 01:01:27 +00:00
|
|
|
unsigned getDstReg() const { return DstReg; }
|
2010-06-15 16:04:21 +00:00
|
|
|
|
|
|
|
/// getSrcReg - Return the virtual register that will be coalesced away.
|
2011-08-09 01:01:27 +00:00
|
|
|
unsigned getSrcReg() const { return SrcReg; }
|
2010-06-15 16:04:21 +00:00
|
|
|
|
2012-05-15 20:09:43 +00:00
|
|
|
/// getDstIdx - Return the subregister index that DstReg will be coalesced
|
|
|
|
/// into, or 0.
|
|
|
|
unsigned getDstIdx() const { return DstIdx; }
|
|
|
|
|
|
|
|
/// getSrcIdx - Return the subregister index that SrcReg will be coalesced
|
|
|
|
/// into, or 0.
|
|
|
|
unsigned getSrcIdx() const { return SrcIdx; }
|
2010-06-15 16:04:21 +00:00
|
|
|
|
|
|
|
/// getNewRC - Return the register class of the coalesced register.
|
2011-08-09 01:01:27 +00:00
|
|
|
const TargetRegisterClass *getNewRC() const { return NewRC; }
|
2010-06-15 16:04:21 +00:00
|
|
|
};
|
2011-06-26 21:54:28 +00:00
|
|
|
} // End llvm namespace
|
2007-09-06 16:18:45 +00:00
|
|
|
|
|
|
|
#endif
|