2008-06-04 11:18:41 +02: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 20:32:42 +02:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2008-06-04 11:18:41 +02:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class LiveStacks : public MachineFunctionPass {
|
2011-10-01 00:18:51 +02:00
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
|
2008-06-04 11:18:41 +02:00
|
|
|
/// Special pool allocator for VNInfo's (LiveInterval val#).
|
|
|
|
///
|
2010-03-30 22:16:45 +02:00
|
|
|
VNInfo::Allocator VNInfoAllocator;
|
2008-06-04 11:18:41 +02:00
|
|
|
|
2009-05-03 20:32:42 +02:00
|
|
|
/// S2IMap - Stack slot indices to live interval mapping.
|
2008-06-04 11:18:41 +02:00
|
|
|
///
|
|
|
|
typedef std::map<int, LiveInterval> SS2IntervalMap;
|
2009-05-03 20:32:42 +02:00
|
|
|
SS2IntervalMap S2IMap;
|
2008-06-04 11:18:41 +02:00
|
|
|
|
2009-05-03 20:32:42 +02:00
|
|
|
/// S2RCMap - Stack slot indices to register class mapping.
|
|
|
|
std::map<int, const TargetRegisterClass*> S2RCMap;
|
|
|
|
|
2008-06-04 11:18:41 +02:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2010-10-19 19:21:58 +02:00
|
|
|
LiveStacks() : MachineFunctionPass(ID) {
|
|
|
|
initializeLiveStacksPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2008-06-04 11:18:41 +02:00
|
|
|
|
|
|
|
typedef SS2IntervalMap::iterator iterator;
|
|
|
|
typedef SS2IntervalMap::const_iterator const_iterator;
|
2009-05-03 20:32:42 +02: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 22:17:37 +01:00
|
|
|
LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
|
2008-06-04 11:18:41 +02:00
|
|
|
|
2008-10-29 06:06:14 +01:00
|
|
|
LiveInterval &getInterval(int Slot) {
|
2009-05-03 20:32:42 +02: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 06:06:14 +01:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LiveInterval &getInterval(int Slot) const {
|
2009-05-03 20:32:42 +02: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 06:06:14 +01:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2009-05-03 20:32:42 +02: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 06:06:14 +01:00
|
|
|
}
|
|
|
|
|
2010-03-30 22:16:45 +02:00
|
|
|
VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
|
2008-06-04 11:18:41 +02: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 08:03:38 +02:00
|
|
|
virtual void print(raw_ostream &O, const Module* = 0) const;
|
2008-06-04 11:18:41 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */
|