2010-10-15 01:49:52 +02:00
|
|
|
//===---- LiveRangeEdit.h - Basic tools for split and spill -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LiveRangeEdit class represents changes done to a virtual register when it
|
|
|
|
// is spilled or split.
|
|
|
|
//
|
|
|
|
// The parent register is never changed. Instead, a number of new virtual
|
|
|
|
// registers are created and added to the newRegs vector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_LIVERANGEEDIT_H
|
|
|
|
#define LLVM_CODEGEN_LIVERANGEEDIT_H
|
|
|
|
|
2011-05-06 20:00:02 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2010-10-21 00:00:51 +02:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2011-05-06 20:00:02 +02:00
|
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
2010-10-15 01:49:52 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2010-10-21 00:00:51 +02:00
|
|
|
class AliasAnalysis;
|
2010-10-15 01:49:52 +02:00
|
|
|
class LiveIntervals;
|
2011-03-29 23:20:19 +02:00
|
|
|
class MachineLoopInfo;
|
2010-10-15 01:49:52 +02:00
|
|
|
class MachineRegisterInfo;
|
|
|
|
class VirtRegMap;
|
|
|
|
|
|
|
|
class LiveRangeEdit {
|
2011-03-09 01:57:29 +01:00
|
|
|
public:
|
|
|
|
/// Callback methods for LiveRangeEdit owners.
|
|
|
|
struct Delegate {
|
|
|
|
/// Called immediately before erasing a dead machine instruction.
|
|
|
|
virtual void LRE_WillEraseInstruction(MachineInstr *MI) {}
|
2011-03-13 02:23:11 +01:00
|
|
|
|
|
|
|
/// Called when a virtual register is no longer used. Return false to defer
|
|
|
|
/// its deletion from LiveIntervals.
|
|
|
|
virtual bool LRE_CanEraseVirtReg(unsigned) { return true; }
|
|
|
|
|
2011-03-16 23:56:16 +01:00
|
|
|
/// Called before shrinking the live range of a virtual register.
|
|
|
|
virtual void LRE_WillShrinkVirtReg(unsigned) {}
|
2011-03-30 04:52:39 +02:00
|
|
|
|
|
|
|
/// Called after cloning a virtual register.
|
|
|
|
/// This is used for new registers representing connected components of Old.
|
|
|
|
virtual void LRE_DidCloneVirtReg(unsigned New, unsigned Old) {}
|
2011-03-16 23:56:16 +01:00
|
|
|
|
2011-03-09 05:02:15 +01:00
|
|
|
virtual ~Delegate() {}
|
2011-03-09 01:57:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2010-10-15 01:49:52 +02:00
|
|
|
LiveInterval &parent_;
|
|
|
|
SmallVectorImpl<LiveInterval*> &newRegs_;
|
2011-03-09 01:57:29 +01:00
|
|
|
Delegate *const delegate_;
|
2011-03-07 23:42:16 +01:00
|
|
|
const SmallVectorImpl<LiveInterval*> *uselessRegs_;
|
2010-10-15 01:49:52 +02:00
|
|
|
|
|
|
|
/// firstNew_ - Index of the first register added to newRegs_.
|
|
|
|
const unsigned firstNew_;
|
|
|
|
|
2010-10-21 00:00:51 +02:00
|
|
|
/// scannedRemattable_ - true when remattable values have been identified.
|
|
|
|
bool scannedRemattable_;
|
|
|
|
|
|
|
|
/// remattable_ - Values defined by remattable instructions as identified by
|
|
|
|
/// tii.isTriviallyReMaterializable().
|
2011-03-03 00:05:19 +01:00
|
|
|
SmallPtrSet<const VNInfo*,4> remattable_;
|
2010-10-21 00:00:51 +02:00
|
|
|
|
|
|
|
/// rematted_ - Values that were actually rematted, and so need to have their
|
|
|
|
/// live range trimmed or entirely removed.
|
2011-03-03 00:05:19 +01:00
|
|
|
SmallPtrSet<const VNInfo*,4> rematted_;
|
2010-10-21 00:00:51 +02:00
|
|
|
|
|
|
|
/// scanRemattable - Identify the parent_ values that may rematerialize.
|
|
|
|
void scanRemattable(LiveIntervals &lis,
|
|
|
|
const TargetInstrInfo &tii,
|
|
|
|
AliasAnalysis *aa);
|
|
|
|
|
|
|
|
/// allUsesAvailableAt - Return true if all registers used by OrigMI at
|
|
|
|
/// OrigIdx are also available with the same value at UseIdx.
|
|
|
|
bool allUsesAvailableAt(const MachineInstr *OrigMI, SlotIndex OrigIdx,
|
|
|
|
SlotIndex UseIdx, LiveIntervals &lis);
|
|
|
|
|
2011-04-05 22:20:26 +02:00
|
|
|
/// foldAsLoad - If LI has a single use and a single def that can be folded as
|
|
|
|
/// a load, eliminate the register by folding the def into the use.
|
|
|
|
bool foldAsLoad(LiveInterval *LI, SmallVectorImpl<MachineInstr*> &Dead,
|
|
|
|
MachineRegisterInfo&, LiveIntervals&, const TargetInstrInfo&);
|
|
|
|
|
2010-10-15 01:49:52 +02:00
|
|
|
public:
|
|
|
|
/// Create a LiveRangeEdit for breaking down parent into smaller pieces.
|
|
|
|
/// @param parent The register being spilled or split.
|
|
|
|
/// @param newRegs List to receive any new registers created. This needn't be
|
|
|
|
/// empty initially, any existing registers are ignored.
|
|
|
|
/// @param uselessRegs List of registers that can't be used when
|
|
|
|
/// rematerializing values because they are about to be removed.
|
|
|
|
LiveRangeEdit(LiveInterval &parent,
|
|
|
|
SmallVectorImpl<LiveInterval*> &newRegs,
|
2011-03-10 02:51:42 +01:00
|
|
|
Delegate *delegate = 0,
|
2011-03-07 23:42:16 +01:00
|
|
|
const SmallVectorImpl<LiveInterval*> *uselessRegs = 0)
|
2011-03-09 01:57:29 +01:00
|
|
|
: parent_(parent), newRegs_(newRegs),
|
|
|
|
delegate_(delegate),
|
|
|
|
uselessRegs_(uselessRegs),
|
|
|
|
firstNew_(newRegs.size()),
|
|
|
|
scannedRemattable_(false) {}
|
2010-10-15 01:49:52 +02:00
|
|
|
|
|
|
|
LiveInterval &getParent() const { return parent_; }
|
|
|
|
unsigned getReg() const { return parent_.reg; }
|
|
|
|
|
|
|
|
/// Iterator for accessing the new registers added by this edit.
|
|
|
|
typedef SmallVectorImpl<LiveInterval*>::const_iterator iterator;
|
|
|
|
iterator begin() const { return newRegs_.begin()+firstNew_; }
|
|
|
|
iterator end() const { return newRegs_.end(); }
|
2010-10-27 00:36:09 +02:00
|
|
|
unsigned size() const { return newRegs_.size()-firstNew_; }
|
2011-02-03 07:18:29 +01:00
|
|
|
bool empty() const { return size() == 0; }
|
2010-10-29 20:21:18 +02:00
|
|
|
LiveInterval *get(unsigned idx) const { return newRegs_[idx+firstNew_]; }
|
2010-10-15 01:49:52 +02:00
|
|
|
|
2011-05-06 20:00:02 +02:00
|
|
|
ArrayRef<LiveInterval*> regs() const {
|
|
|
|
return ArrayRef<LiveInterval*>(newRegs_).slice(firstNew_);
|
|
|
|
}
|
|
|
|
|
2011-03-10 02:51:42 +01:00
|
|
|
/// FIXME: Temporary accessors until we can get rid of
|
|
|
|
/// LiveIntervals::AddIntervalsForSpills
|
|
|
|
SmallVectorImpl<LiveInterval*> *getNewVRegs() { return &newRegs_; }
|
|
|
|
const SmallVectorImpl<LiveInterval*> *getUselessVRegs() {
|
|
|
|
return uselessRegs_;
|
|
|
|
}
|
|
|
|
|
2011-03-26 23:16:41 +01:00
|
|
|
/// createFrom - Create a new virtual register based on OldReg.
|
|
|
|
LiveInterval &createFrom(unsigned OldReg, LiveIntervals&, VirtRegMap&);
|
|
|
|
|
2011-03-17 21:37:07 +01:00
|
|
|
/// create - Create a new register with the same class and original slot as
|
2010-10-15 02:16:55 +02:00
|
|
|
/// parent.
|
2011-03-17 21:37:07 +01:00
|
|
|
LiveInterval &create(LiveIntervals &LIS, VirtRegMap &VRM) {
|
|
|
|
return createFrom(getReg(), LIS, VRM);
|
|
|
|
}
|
2010-10-15 01:49:52 +02:00
|
|
|
|
2010-10-21 00:00:51 +02:00
|
|
|
/// anyRematerializable - Return true if any parent values may be
|
|
|
|
/// rematerializable.
|
2011-03-07 23:42:16 +01:00
|
|
|
/// This function must be called before any rematerialization is attempted.
|
2010-10-21 00:00:51 +02:00
|
|
|
bool anyRematerializable(LiveIntervals&, const TargetInstrInfo&,
|
|
|
|
AliasAnalysis*);
|
|
|
|
|
2011-03-29 05:12:02 +02:00
|
|
|
/// checkRematerializable - Manually add VNI to the list of rematerializable
|
|
|
|
/// values if DefMI may be rematerializable.
|
2011-04-21 00:14:20 +02:00
|
|
|
bool checkRematerializable(VNInfo *VNI, const MachineInstr *DefMI,
|
2011-03-29 05:12:02 +02:00
|
|
|
const TargetInstrInfo&, AliasAnalysis*);
|
|
|
|
|
2010-10-21 00:00:51 +02:00
|
|
|
/// Remat - Information needed to rematerialize at a specific location.
|
|
|
|
struct Remat {
|
|
|
|
VNInfo *ParentVNI; // parent_'s value at the remat location.
|
|
|
|
MachineInstr *OrigMI; // Instruction defining ParentVNI.
|
2010-11-10 02:05:12 +01:00
|
|
|
explicit Remat(VNInfo *ParentVNI) : ParentVNI(ParentVNI), OrigMI(0) {}
|
2010-10-21 00:00:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// canRematerializeAt - Determine if ParentVNI can be rematerialized at
|
|
|
|
/// UseIdx. It is assumed that parent_.getVNINfoAt(UseIdx) == ParentVNI.
|
|
|
|
/// When cheapAsAMove is set, only cheap remats are allowed.
|
2010-11-10 02:05:12 +01:00
|
|
|
bool canRematerializeAt(Remat &RM,
|
|
|
|
SlotIndex UseIdx,
|
|
|
|
bool cheapAsAMove,
|
|
|
|
LiveIntervals &lis);
|
2010-10-21 00:00:51 +02:00
|
|
|
|
|
|
|
/// rematerializeAt - Rematerialize RM.ParentVNI into DestReg by inserting an
|
|
|
|
/// instruction into MBB before MI. The new instruction is mapped, but
|
|
|
|
/// liveness is not updated.
|
|
|
|
/// Return the SlotIndex of the new instruction.
|
|
|
|
SlotIndex rematerializeAt(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg,
|
|
|
|
const Remat &RM,
|
|
|
|
LiveIntervals&,
|
|
|
|
const TargetInstrInfo&,
|
2011-05-02 07:29:58 +02:00
|
|
|
const TargetRegisterInfo&,
|
|
|
|
bool Late = false);
|
2010-10-15 01:49:52 +02:00
|
|
|
|
2010-12-18 04:04:14 +01:00
|
|
|
/// markRematerialized - explicitly mark a value as rematerialized after doing
|
|
|
|
/// it manually.
|
2011-03-03 00:05:19 +01:00
|
|
|
void markRematerialized(const VNInfo *ParentVNI) {
|
2010-12-18 04:04:14 +01:00
|
|
|
rematted_.insert(ParentVNI);
|
|
|
|
}
|
|
|
|
|
2010-10-21 00:00:51 +02:00
|
|
|
/// didRematerialize - Return true if ParentVNI was rematerialized anywhere.
|
2011-03-03 00:05:19 +01:00
|
|
|
bool didRematerialize(const VNInfo *ParentVNI) const {
|
2010-10-21 00:00:51 +02:00
|
|
|
return rematted_.count(ParentVNI);
|
|
|
|
}
|
2011-03-08 23:46:11 +01:00
|
|
|
|
2011-03-13 02:23:11 +01:00
|
|
|
/// eraseVirtReg - Notify the delegate that Reg is no longer in use, and try
|
|
|
|
/// to erase it from LIS.
|
|
|
|
void eraseVirtReg(unsigned Reg, LiveIntervals &LIS);
|
|
|
|
|
2011-03-08 23:46:11 +01:00
|
|
|
/// eliminateDeadDefs - Try to delete machine instructions that are now dead
|
|
|
|
/// (allDefsAreDead returns true). This may cause live intervals to be trimmed
|
|
|
|
/// and further dead efs to be eliminated.
|
|
|
|
void eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead,
|
2011-03-17 21:37:07 +01:00
|
|
|
LiveIntervals&, VirtRegMap&,
|
2011-03-08 23:46:11 +01:00
|
|
|
const TargetInstrInfo&);
|
|
|
|
|
2011-03-29 23:20:19 +02:00
|
|
|
/// calculateRegClassAndHint - Recompute register class and hint for each new
|
|
|
|
/// register.
|
|
|
|
void calculateRegClassAndHint(MachineFunction&, LiveIntervals&,
|
|
|
|
const MachineLoopInfo&);
|
2010-10-15 01:49:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|