2004-07-23 17:56:30 +00:00
|
|
|
//===-- LiveIntervalAnalysis.h - Live Interval Analysis ---------*- C++ -*-===//
|
2003-11-20 03:32:25 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-07-19 02:13:59 +00:00
|
|
|
// This file implements the LiveInterval analysis pass. Given some numbering of
|
|
|
|
// each the machine instructions (in this implemention depth-first order) an
|
|
|
|
// interval [i, j) is said to be a live interval for register v if there is no
|
|
|
|
// instruction with number j' > j such that v is live at j' abd there is no
|
|
|
|
// instruction with number i' < i such that v is live at i'. In this
|
|
|
|
// implementation intervals can have holes, i.e. an interval might look like
|
|
|
|
// [1,20), [50,65), [1000,1001).
|
2003-11-20 03:32:25 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-07-23 17:56:30 +00:00
|
|
|
#ifndef LLVM_CODEGEN_LIVEINTERVAL_ANALYSIS_H
|
|
|
|
#define LLVM_CODEGEN_LIVEINTERVAL_ANALYSIS_H
|
2003-11-20 03:32:25 +00:00
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2005-09-21 04:18:25 +00:00
|
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
2007-02-15 05:59:24 +00:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2007-04-17 20:32:26 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-02-01 05:32:05 +00:00
|
|
|
#include "llvm/ADT/IndexedMap.h"
|
2003-11-20 03:32:25 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
class LiveVariables;
|
|
|
|
class MRegisterInfo;
|
Allow the live interval analysis pass to be a bit more aggressive about
numbering values in live ranges for physical registers.
The alpha backend currently generates code that looks like this:
vreg = preg
...
preg = vreg
use preg
...
preg = vreg
use preg
etc. Because vreg contains the value of preg coming in, each of the
copies back into preg contain that initial value as well.
In the case of the Alpha, this allows this testcase:
void "foo"(int %blah) {
store int 5, int *%MyVar
store int 12, int* %MyVar2
ret void
}
to compile to:
foo:
ldgp $29, 0($27)
ldiq $0,5
stl $0,MyVar
ldiq $0,12
stl $0,MyVar2
ret $31,($26),1
instead of:
foo:
ldgp $29, 0($27)
bis $29,$29,$0
ldiq $1,5
bis $0,$0,$29
stl $1,MyVar
ldiq $1,12
bis $0,$0,$29
stl $1,MyVar2
ret $31,($26),1
This does not seem to have any noticable effect on X86 code.
This fixes PR535.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20536 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-09 23:05:19 +00:00
|
|
|
class TargetInstrInfo;
|
2007-04-17 20:32:26 +00:00
|
|
|
class TargetRegisterClass;
|
2004-08-04 09:46:26 +00:00
|
|
|
class VirtRegMap;
|
|
|
|
|
|
|
|
class LiveIntervals : public MachineFunctionPass {
|
|
|
|
MachineFunction* mf_;
|
|
|
|
const TargetMachine* tm_;
|
|
|
|
const MRegisterInfo* mri_;
|
Allow the live interval analysis pass to be a bit more aggressive about
numbering values in live ranges for physical registers.
The alpha backend currently generates code that looks like this:
vreg = preg
...
preg = vreg
use preg
...
preg = vreg
use preg
etc. Because vreg contains the value of preg coming in, each of the
copies back into preg contain that initial value as well.
In the case of the Alpha, this allows this testcase:
void "foo"(int %blah) {
store int 5, int *%MyVar
store int 12, int* %MyVar2
ret void
}
to compile to:
foo:
ldgp $29, 0($27)
ldiq $0,5
stl $0,MyVar
ldiq $0,12
stl $0,MyVar2
ret $31,($26),1
instead of:
foo:
ldgp $29, 0($27)
bis $29,$29,$0
ldiq $1,5
bis $0,$0,$29
stl $1,MyVar
ldiq $1,12
bis $0,$0,$29
stl $1,MyVar2
ret $31,($26),1
This does not seem to have any noticable effect on X86 code.
This fixes PR535.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20536 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-09 23:05:19 +00:00
|
|
|
const TargetInstrInfo* tii_;
|
2004-08-04 09:46:26 +00:00
|
|
|
LiveVariables* lv_;
|
|
|
|
|
2006-09-15 03:57:23 +00:00
|
|
|
/// MBB2IdxMap - The index of the first instruction in the specified basic
|
|
|
|
/// block.
|
|
|
|
std::vector<unsigned> MBB2IdxMap;
|
2007-06-08 17:18:56 +00:00
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
typedef std::map<MachineInstr*, unsigned> Mi2IndexMap;
|
|
|
|
Mi2IndexMap mi2iMap_;
|
|
|
|
|
|
|
|
typedef std::vector<MachineInstr*> Index2MiMap;
|
|
|
|
Index2MiMap i2miMap_;
|
|
|
|
|
|
|
|
typedef std::map<unsigned, LiveInterval> Reg2IntervalMap;
|
|
|
|
Reg2IntervalMap r2iMap_;
|
|
|
|
|
2007-02-15 05:59:24 +00:00
|
|
|
BitVector allocatableRegs_;
|
2007-03-01 02:03:03 +00:00
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
public:
|
2007-05-06 13:37:16 +00:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2007-05-01 21:15:47 +00:00
|
|
|
LiveIntervals() : MachineFunctionPass((intptr_t)&ID) {}
|
|
|
|
|
2006-08-24 22:43:55 +00:00
|
|
|
struct InstrSlots {
|
2004-08-04 09:46:26 +00:00
|
|
|
enum {
|
|
|
|
LOAD = 0,
|
|
|
|
USE = 1,
|
|
|
|
DEF = 2,
|
|
|
|
STORE = 3,
|
2006-02-22 16:23:43 +00:00
|
|
|
NUM = 4
|
2004-08-04 09:46:26 +00:00
|
|
|
};
|
2003-11-20 03:32:25 +00:00
|
|
|
};
|
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
static unsigned getBaseIndex(unsigned index) {
|
|
|
|
return index - (index % InstrSlots::NUM);
|
|
|
|
}
|
|
|
|
static unsigned getBoundaryIndex(unsigned index) {
|
|
|
|
return getBaseIndex(index + InstrSlots::NUM - 1);
|
|
|
|
}
|
|
|
|
static unsigned getLoadIndex(unsigned index) {
|
|
|
|
return getBaseIndex(index) + InstrSlots::LOAD;
|
|
|
|
}
|
|
|
|
static unsigned getUseIndex(unsigned index) {
|
|
|
|
return getBaseIndex(index) + InstrSlots::USE;
|
|
|
|
}
|
|
|
|
static unsigned getDefIndex(unsigned index) {
|
|
|
|
return getBaseIndex(index) + InstrSlots::DEF;
|
|
|
|
}
|
|
|
|
static unsigned getStoreIndex(unsigned index) {
|
|
|
|
return getBaseIndex(index) + InstrSlots::STORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef Reg2IntervalMap::iterator iterator;
|
2004-09-30 15:59:17 +00:00
|
|
|
typedef Reg2IntervalMap::const_iterator const_iterator;
|
|
|
|
const_iterator begin() const { return r2iMap_.begin(); }
|
|
|
|
const_iterator end() const { return r2iMap_.end(); }
|
2004-08-04 09:46:26 +00:00
|
|
|
iterator begin() { return r2iMap_.begin(); }
|
|
|
|
iterator end() { return r2iMap_.end(); }
|
|
|
|
unsigned getNumIntervals() const { return r2iMap_.size(); }
|
|
|
|
|
|
|
|
LiveInterval &getInterval(unsigned reg) {
|
|
|
|
Reg2IntervalMap::iterator I = r2iMap_.find(reg);
|
|
|
|
assert(I != r2iMap_.end() && "Interval does not exist for register");
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LiveInterval &getInterval(unsigned reg) const {
|
|
|
|
Reg2IntervalMap::const_iterator I = r2iMap_.find(reg);
|
|
|
|
assert(I != r2iMap_.end() && "Interval does not exist for register");
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
bool hasInterval(unsigned reg) const {
|
2007-03-01 02:03:03 +00:00
|
|
|
return r2iMap_.count(reg);
|
2007-02-19 21:49:54 +00:00
|
|
|
}
|
|
|
|
|
2006-09-15 03:57:23 +00:00
|
|
|
/// getMBBStartIdx - Return the base index of the first instruction in the
|
|
|
|
/// specified MachineBasicBlock.
|
|
|
|
unsigned getMBBStartIdx(MachineBasicBlock *MBB) const {
|
|
|
|
return getMBBStartIdx(MBB->getNumber());
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getMBBStartIdx(unsigned MBBNo) const {
|
|
|
|
assert(MBBNo < MBB2IdxMap.size() && "Invalid MBB number!");
|
|
|
|
return MBB2IdxMap[MBBNo];
|
|
|
|
}
|
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
/// getInstructionIndex - returns the base index of instr
|
|
|
|
unsigned getInstructionIndex(MachineInstr* instr) const {
|
|
|
|
Mi2IndexMap::const_iterator it = mi2iMap_.find(instr);
|
|
|
|
assert(it != mi2iMap_.end() && "Invalid instruction!");
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getInstructionFromIndex - given an index in any slot of an
|
|
|
|
/// instruction return a pointer the instruction
|
|
|
|
MachineInstr* getInstructionFromIndex(unsigned index) const {
|
|
|
|
index /= InstrSlots::NUM; // convert index to vector index
|
|
|
|
assert(index < i2miMap_.size() &&
|
|
|
|
"index does not correspond to an instruction");
|
|
|
|
return i2miMap_[index];
|
|
|
|
}
|
2007-06-08 17:18:56 +00:00
|
|
|
|
|
|
|
// Interval creation
|
|
|
|
|
|
|
|
LiveInterval &getOrCreateInterval(unsigned reg) {
|
|
|
|
Reg2IntervalMap::iterator I = r2iMap_.find(reg);
|
|
|
|
if (I == r2iMap_.end())
|
|
|
|
I = r2iMap_.insert(I, std::make_pair(reg, createInterval(reg)));
|
|
|
|
return I->second;
|
|
|
|
}
|
2004-08-04 09:46:26 +00:00
|
|
|
|
2006-11-16 02:41:50 +00:00
|
|
|
/// CreateNewLiveInterval - Create a new live interval with the given live
|
|
|
|
/// ranges. The new live interval will have an infinite spill weight.
|
|
|
|
LiveInterval &CreateNewLiveInterval(const LiveInterval *LI,
|
|
|
|
const std::vector<LiveRange> &LRs);
|
|
|
|
|
2007-06-08 17:18:56 +00:00
|
|
|
std::vector<LiveInterval*> addIntervalsForSpills(const LiveInterval& i,
|
|
|
|
VirtRegMap& vrm,
|
|
|
|
int slot);
|
2004-08-04 09:46:26 +00:00
|
|
|
|
2007-06-08 17:18:56 +00:00
|
|
|
// Interval removal
|
2004-08-04 09:46:26 +00:00
|
|
|
|
2007-06-08 17:18:56 +00:00
|
|
|
void removeInterval(unsigned Reg) {
|
|
|
|
r2iMap_.erase(Reg);
|
2006-12-17 05:15:13 +00:00
|
|
|
}
|
2004-09-30 15:59:17 +00:00
|
|
|
|
2007-02-22 23:03:39 +00:00
|
|
|
/// isRemoved - returns true if the specified machine instr has been
|
|
|
|
/// removed.
|
|
|
|
bool isRemoved(MachineInstr* instr) const {
|
2007-02-22 23:52:23 +00:00
|
|
|
return !mi2iMap_.count(instr);
|
2007-02-22 23:03:39 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 22:43:55 +00:00
|
|
|
/// RemoveMachineInstrFromMaps - This marks the specified machine instr as
|
|
|
|
/// deleted.
|
|
|
|
void RemoveMachineInstrFromMaps(MachineInstr *MI) {
|
|
|
|
// remove index -> MachineInstr and
|
|
|
|
// MachineInstr -> index mappings
|
|
|
|
Mi2IndexMap::iterator mi2i = mi2iMap_.find(MI);
|
|
|
|
if (mi2i != mi2iMap_.end()) {
|
|
|
|
i2miMap_[mi2i->second/InstrSlots::NUM] = 0;
|
|
|
|
mi2iMap_.erase(mi2i);
|
|
|
|
}
|
|
|
|
}
|
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&);
|
|
|
|
|
|
|
|
/// print - Implement the dump method.
|
|
|
|
virtual void print(std::ostream &O, const Module* = 0) const;
|
|
|
|
void print(std::ostream *O, const Module* M = 0) const {
|
|
|
|
if (O) print(*O, M);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2006-09-15 03:57:23 +00:00
|
|
|
/// computeIntervals - Compute live intervals.
|
2006-09-14 06:42:17 +00:00
|
|
|
void computeIntervals();
|
2006-09-02 05:26:01 +00:00
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
/// handleRegisterDef - update intervals for a register def
|
|
|
|
/// (calls handlePhysicalRegisterDef and
|
|
|
|
/// handleVirtualRegisterDef)
|
2006-09-03 08:07:11 +00:00
|
|
|
void handleRegisterDef(MachineBasicBlock *MBB,
|
|
|
|
MachineBasicBlock::iterator MI, unsigned MIIdx,
|
2006-01-29 07:59:37 +00:00
|
|
|
unsigned reg);
|
2004-08-04 09:46:26 +00:00
|
|
|
|
|
|
|
/// handleVirtualRegisterDef - update intervals for a virtual
|
|
|
|
/// register def
|
2006-09-03 08:07:11 +00:00
|
|
|
void handleVirtualRegisterDef(MachineBasicBlock *MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned MIIdx,
|
2004-08-04 09:46:26 +00:00
|
|
|
LiveInterval& interval);
|
|
|
|
|
Allow the live interval analysis pass to be a bit more aggressive about
numbering values in live ranges for physical registers.
The alpha backend currently generates code that looks like this:
vreg = preg
...
preg = vreg
use preg
...
preg = vreg
use preg
etc. Because vreg contains the value of preg coming in, each of the
copies back into preg contain that initial value as well.
In the case of the Alpha, this allows this testcase:
void "foo"(int %blah) {
store int 5, int *%MyVar
store int 12, int* %MyVar2
ret void
}
to compile to:
foo:
ldgp $29, 0($27)
ldiq $0,5
stl $0,MyVar
ldiq $0,12
stl $0,MyVar2
ret $31,($26),1
instead of:
foo:
ldgp $29, 0($27)
bis $29,$29,$0
ldiq $1,5
bis $0,$0,$29
stl $1,MyVar
ldiq $1,12
bis $0,$0,$29
stl $1,MyVar2
ret $31,($26),1
This does not seem to have any noticable effect on X86 code.
This fixes PR535.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20536 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-09 23:05:19 +00:00
|
|
|
/// handlePhysicalRegisterDef - update intervals for a physical register
|
2006-08-24 22:43:55 +00:00
|
|
|
/// def.
|
2004-08-04 09:46:26 +00:00
|
|
|
void handlePhysicalRegisterDef(MachineBasicBlock* mbb,
|
|
|
|
MachineBasicBlock::iterator mi,
|
2006-09-03 08:07:11 +00:00
|
|
|
unsigned MIIdx,
|
2006-08-31 05:54:43 +00:00
|
|
|
LiveInterval &interval,
|
|
|
|
unsigned SrcReg);
|
2004-08-04 09:46:26 +00:00
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
/// handleLiveInRegister - Create interval for a livein register.
|
2007-02-21 22:41:17 +00:00
|
|
|
void handleLiveInRegister(MachineBasicBlock* mbb,
|
|
|
|
unsigned MIIdx,
|
2007-04-25 07:30:23 +00:00
|
|
|
LiveInterval &interval, bool isAlias = false);
|
2007-02-19 21:49:54 +00:00
|
|
|
|
2004-08-04 09:46:26 +00:00
|
|
|
static LiveInterval createInterval(unsigned Reg);
|
|
|
|
|
|
|
|
void printRegName(unsigned reg) const;
|
|
|
|
};
|
|
|
|
|
2003-11-20 03:32:25 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|