2008-06-04 09:18:41 +00:00
|
|
|
//===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the live stack slot analysis pass. It is analogous to
|
|
|
|
// live interval analysis except it's analyzing liveness of stack slots rather
|
|
|
|
// than registers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
|
|
|
|
#define LLVM_CODEGEN_LIVESTACK_ANALYSIS_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
2009-05-03 18:32:42 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2008-06-04 09:18:41 +00:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class LiveStacks : public MachineFunctionPass {
|
|
|
|
/// Special pool allocator for VNInfo's (LiveInterval val#).
|
|
|
|
///
|
2010-03-30 20:16:45 +00:00
|
|
|
VNInfo::Allocator VNInfoAllocator;
|
2008-06-04 09:18:41 +00:00
|
|
|
|
2009-05-03 18:32:42 +00:00
|
|
|
/// S2IMap - Stack slot indices to live interval mapping.
|
2008-06-04 09:18:41 +00:00
|
|
|
///
|
|
|
|
typedef std::map<int, LiveInterval> SS2IntervalMap;
|
2009-05-03 18:32:42 +00:00
|
|
|
SS2IntervalMap S2IMap;
|
2008-06-04 09:18:41 +00:00
|
|
|
|
2009-05-03 18:32:42 +00:00
|
|
|
/// S2RCMap - Stack slot indices to register class mapping.
|
|
|
|
std::map<int, const TargetRegisterClass*> S2RCMap;
|
|
|
|
|
2008-06-04 09:18:41 +00:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2010-10-19 17:21:58 +00:00
|
|
|
LiveStacks() : MachineFunctionPass(ID) {
|
|
|
|
initializeLiveStacksPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2008-06-04 09:18:41 +00:00
|
|
|
|
|
|
|
typedef SS2IntervalMap::iterator iterator;
|
|
|
|
typedef SS2IntervalMap::const_iterator const_iterator;
|
2009-05-03 18:32:42 +00:00
|
|
|
const_iterator begin() const { return S2IMap.begin(); }
|
|
|
|
const_iterator end() const { return S2IMap.end(); }
|
|
|
|
iterator begin() { return S2IMap.begin(); }
|
|
|
|
iterator end() { return S2IMap.end(); }
|
|
|
|
|
|
|
|
unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
|
|
|
|
|
2011-01-09 21:17:37 +00:00
|
|
|
LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
|
2008-06-04 09:18:41 +00:00
|
|
|
|
2008-10-29 05:06:14 +00:00
|
|
|
LiveInterval &getInterval(int Slot) {
|
2009-05-03 18:32:42 +00:00
|
|
|
assert(Slot >= 0 && "Spill slot indice must be >= 0");
|
|
|
|
SS2IntervalMap::iterator I = S2IMap.find(Slot);
|
|
|
|
assert(I != S2IMap.end() && "Interval does not exist for stack slot");
|
2008-10-29 05:06:14 +00:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LiveInterval &getInterval(int Slot) const {
|
2009-05-03 18:32:42 +00:00
|
|
|
assert(Slot >= 0 && "Spill slot indice must be >= 0");
|
|
|
|
SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
|
|
|
|
assert(I != S2IMap.end() && "Interval does not exist for stack slot");
|
2008-10-29 05:06:14 +00:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2009-05-03 18:32:42 +00:00
|
|
|
bool hasInterval(int Slot) const {
|
|
|
|
return S2IMap.count(Slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
const TargetRegisterClass *getIntervalRegClass(int Slot) const {
|
|
|
|
assert(Slot >= 0 && "Spill slot indice must be >= 0");
|
|
|
|
std::map<int, const TargetRegisterClass*>::const_iterator
|
|
|
|
I = S2RCMap.find(Slot);
|
|
|
|
assert(I != S2RCMap.end() &&
|
|
|
|
"Register class info does not exist for stack slot");
|
|
|
|
return I->second;
|
2008-10-29 05:06:14 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 20:16:45 +00:00
|
|
|
VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
|
2008-06-04 09:18:41 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
virtual void releaseMemory();
|
|
|
|
|
|
|
|
/// runOnMachineFunction - pass entry point
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction&);
|
|
|
|
|
|
|
|
/// print - Implement the dump method.
|
2009-08-23 06:03:38 +00:00
|
|
|
virtual void print(raw_ostream &O, const Module* = 0) const;
|
2008-06-04 09:18:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */
|