2007-06-08 17:18:56 +00:00
|
|
|
//===-- SimpleRegisterCoalescing.h - Register Coalescing --------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-08 17:18:56 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a simple register copy coalescing phase.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_SIMPLE_REGISTER_COALESCING_H
|
|
|
|
#define LLVM_CODEGEN_SIMPLE_REGISTER_COALESCING_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
2007-09-06 16:18:45 +00:00
|
|
|
#include "llvm/CodeGen/RegisterCoalescer.h"
|
2011-06-02 02:19:35 +00:00
|
|
|
#include "RegisterClassInfo.h"
|
2007-06-08 17:18:56 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2007-11-06 08:52:21 +00:00
|
|
|
class SimpleRegisterCoalescing;
|
2010-12-02 00:37:37 +00:00
|
|
|
class LiveDebugVariables;
|
2008-02-10 18:45:23 +00:00
|
|
|
class TargetRegisterInfo;
|
2007-06-08 17:18:56 +00:00
|
|
|
class TargetInstrInfo;
|
|
|
|
class VirtRegMap;
|
2007-12-11 02:09:15 +00:00
|
|
|
class MachineLoopInfo;
|
2007-11-06 08:52:21 +00:00
|
|
|
|
|
|
|
/// CopyRec - Representation for copy instructions in coalescer queue.
|
|
|
|
///
|
|
|
|
struct CopyRec {
|
|
|
|
MachineInstr *MI;
|
|
|
|
unsigned LoopDepth;
|
2009-09-12 02:14:41 +00:00
|
|
|
CopyRec(MachineInstr *mi, unsigned depth)
|
2009-12-19 07:05:23 +00:00
|
|
|
: MI(mi), LoopDepth(depth) {}
|
2007-11-06 08:52:21 +00:00
|
|
|
};
|
2007-06-08 17:18:56 +00:00
|
|
|
|
2007-09-06 16:18:45 +00:00
|
|
|
class SimpleRegisterCoalescing : public MachineFunctionPass,
|
|
|
|
public RegisterCoalescer {
|
2007-06-08 17:18:56 +00:00
|
|
|
MachineFunction* mf_;
|
2008-02-15 18:24:29 +00:00
|
|
|
MachineRegisterInfo* mri_;
|
2007-06-08 17:18:56 +00:00
|
|
|
const TargetMachine* tm_;
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo* tri_;
|
2007-06-08 17:18:56 +00:00
|
|
|
const TargetInstrInfo* tii_;
|
|
|
|
LiveIntervals *li_;
|
2010-12-02 00:37:37 +00:00
|
|
|
LiveDebugVariables *ldv_;
|
2007-12-11 02:09:15 +00:00
|
|
|
const MachineLoopInfo* loopInfo;
|
2009-10-09 23:27:56 +00:00
|
|
|
AliasAnalysis *AA;
|
2011-06-02 02:19:35 +00:00
|
|
|
RegisterClassInfo RegClassInfo;
|
2007-06-08 17:18:56 +00:00
|
|
|
|
2007-11-05 17:41:38 +00:00
|
|
|
/// JoinedCopies - Keep track of copies eliminated due to coalescing.
|
|
|
|
///
|
|
|
|
SmallPtrSet<MachineInstr*, 32> JoinedCopies;
|
|
|
|
|
2008-08-30 09:09:33 +00:00
|
|
|
/// ReMatCopies - Keep track of copies eliminated due to remat.
|
|
|
|
///
|
|
|
|
SmallPtrSet<MachineInstr*, 32> ReMatCopies;
|
|
|
|
|
2008-09-19 17:38:47 +00:00
|
|
|
/// ReMatDefs - Keep track of definition instructions which have
|
|
|
|
/// been remat'ed.
|
|
|
|
SmallPtrSet<MachineInstr*, 8> ReMatDefs;
|
|
|
|
|
2007-06-08 17:18:56 +00:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identifcation, replacement for typeid
|
2010-10-19 17:21:58 +00:00
|
|
|
SimpleRegisterCoalescing() : MachineFunctionPass(ID) {
|
|
|
|
initializeSimpleRegisterCoalescingPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2007-06-08 17:18:56 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
|
|
|
/// runOnMachineFunction - pass entry point
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction&);
|
|
|
|
|
2007-09-06 16:18:45 +00:00
|
|
|
bool coalesceFunction(MachineFunction &mf, RegallocQuery &) {
|
|
|
|
// This runs as an independent pass, so don't do anything.
|
2007-11-06 08:52:21 +00:00
|
|
|
return false;
|
2009-12-19 07:05:23 +00:00
|
|
|
}
|
2007-09-06 16:18:45 +00:00
|
|
|
|
2007-06-08 17:18:56 +00:00
|
|
|
/// print - Implement the dump method.
|
2009-08-23 06:03:38 +00:00
|
|
|
virtual void print(raw_ostream &O, const Module* = 0) const;
|
2007-06-08 17:18:56 +00:00
|
|
|
|
2007-11-06 08:52:21 +00:00
|
|
|
private:
|
2007-06-08 17:18:56 +00:00
|
|
|
/// joinIntervals - join compatible live intervals
|
|
|
|
void joinIntervals();
|
|
|
|
|
2007-07-09 12:20:30 +00:00
|
|
|
/// CopyCoalesceInMBB - Coalesce copies in the specified MBB, putting
|
2007-07-09 12:00:59 +00:00
|
|
|
/// copies that cannot yet be coalesced into the "TryAgain" list.
|
|
|
|
void CopyCoalesceInMBB(MachineBasicBlock *MBB,
|
2007-10-16 08:04:24 +00:00
|
|
|
std::vector<CopyRec> &TryAgain);
|
2007-06-08 17:18:56 +00:00
|
|
|
|
|
|
|
/// JoinCopy - Attempt to join intervals corresponding to SrcReg/DstReg,
|
|
|
|
/// which are the src/dst of the copy instruction CopyMI. This returns true
|
2007-11-01 06:22:48 +00:00
|
|
|
/// if the copy was successfully coalesced away. If it is not currently
|
|
|
|
/// possible to coalesce this interval, but it may be possible if other
|
|
|
|
/// things get coalesced, then it returns true by reference in 'Again'.
|
2008-02-13 03:01:43 +00:00
|
|
|
bool JoinCopy(CopyRec &TheCopy, bool &Again);
|
2010-06-24 18:15:01 +00:00
|
|
|
|
2007-06-08 17:18:56 +00:00
|
|
|
/// JoinIntervals - Attempt to join these two intervals. On failure, this
|
2010-06-24 18:15:01 +00:00
|
|
|
/// returns false. The output "SrcInt" will not have been modified, so we can
|
|
|
|
/// use this information below to update aliases.
|
|
|
|
bool JoinIntervals(CoalescerPair &CP);
|
2010-06-22 16:13:57 +00:00
|
|
|
|
2008-02-15 18:24:29 +00:00
|
|
|
/// AdjustCopiesBackFrom - We found a non-trivially-coalescable copy. If
|
|
|
|
/// the source value number is defined by a copy from the destination reg
|
|
|
|
/// see if we can merge these two destination reg valno# into a single
|
|
|
|
/// value number, eliminating a copy.
|
2010-06-24 20:16:00 +00:00
|
|
|
bool AdjustCopiesBackFrom(const CoalescerPair &CP, MachineInstr *CopyMI);
|
2007-06-08 17:18:56 +00:00
|
|
|
|
2008-02-16 02:32:17 +00:00
|
|
|
/// HasOtherReachingDefs - Return true if there are definitions of IntB
|
|
|
|
/// other than BValNo val# that can reach uses of AValno val# of IntA.
|
|
|
|
bool HasOtherReachingDefs(LiveInterval &IntA, LiveInterval &IntB,
|
|
|
|
VNInfo *AValNo, VNInfo *BValNo);
|
|
|
|
|
2008-02-15 18:24:29 +00:00
|
|
|
/// RemoveCopyByCommutingDef - We found a non-trivially-coalescable copy.
|
|
|
|
/// If the source value number is defined by a commutable instruction and
|
|
|
|
/// its other operand is coalesced to the copy dest register, see if we
|
|
|
|
/// can transform the copy into a noop by commuting the definition.
|
2010-07-06 20:31:51 +00:00
|
|
|
bool RemoveCopyByCommutingDef(const CoalescerPair &CP,MachineInstr *CopyMI);
|
2008-02-13 03:01:43 +00:00
|
|
|
|
2009-02-05 08:45:04 +00:00
|
|
|
/// ReMaterializeTrivialDef - If the source of a copy is defined by a trivial
|
|
|
|
/// computation, replace the copy by rematerialize the definition.
|
2011-02-08 00:03:05 +00:00
|
|
|
/// If PreserveSrcInt is true, make sure SrcInt is valid after the call.
|
|
|
|
bool ReMaterializeTrivialDef(LiveInterval &SrcInt, bool PreserveSrcInt,
|
|
|
|
unsigned DstReg, unsigned DstSubIdx,
|
|
|
|
MachineInstr *CopyMI);
|
2008-08-30 09:09:33 +00:00
|
|
|
|
2011-04-04 20:59:59 +00:00
|
|
|
/// shouldJoinPhys - Return true if a physreg copy should be joined.
|
|
|
|
bool shouldJoinPhys(CoalescerPair &CP);
|
|
|
|
|
2009-01-23 02:15:19 +00:00
|
|
|
/// isWinToJoinCrossClass - Return true if it's profitable to coalesce
|
|
|
|
/// two virtual registers from different register classes.
|
2010-04-21 00:44:22 +00:00
|
|
|
bool isWinToJoinCrossClass(unsigned SrcReg,
|
|
|
|
unsigned DstReg,
|
|
|
|
const TargetRegisterClass *SrcRC,
|
|
|
|
const TargetRegisterClass *DstRC,
|
|
|
|
const TargetRegisterClass *NewRC);
|
2008-06-19 01:39:21 +00:00
|
|
|
|
2008-02-15 18:24:29 +00:00
|
|
|
/// UpdateRegDefsUses - Replace all defs and uses of SrcReg to DstReg and
|
|
|
|
/// update the subregister number if it is not zero. If DstReg is a
|
|
|
|
/// physical register and the existing subregister number of the def / use
|
|
|
|
/// being updated is not zero, make sure to set it to the correct physical
|
|
|
|
/// subregister.
|
2010-06-24 18:15:01 +00:00
|
|
|
void UpdateRegDefsUses(const CoalescerPair &CP);
|
2008-02-15 18:24:29 +00:00
|
|
|
|
2008-10-27 23:21:01 +00:00
|
|
|
/// RemoveDeadDef - If a def of a live interval is now determined dead,
|
|
|
|
/// remove the val# it defines. If the live interval becomes empty, remove
|
|
|
|
/// it as well.
|
|
|
|
bool RemoveDeadDef(LiveInterval &li, MachineInstr *DefMI);
|
|
|
|
|
2010-06-24 18:15:01 +00:00
|
|
|
/// RemoveCopyFlag - If DstReg is no longer defined by CopyMI, clear the
|
|
|
|
/// VNInfo copy flag for DstReg and all aliases.
|
|
|
|
void RemoveCopyFlag(unsigned DstReg, const MachineInstr *CopyMI);
|
|
|
|
|
2011-03-31 17:23:25 +00:00
|
|
|
/// markAsJoined - Remember that CopyMI has already been joined.
|
|
|
|
void markAsJoined(MachineInstr *CopyMI);
|
2007-06-08 17:18:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|