mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
9aa29a4c23
The order of this container was needed at one point - so, at that point create a temporary array of pointers, sort those, then iterate them. This keeps lookup efficient (& the lesser issue, of allowing the use of emplace... ), object identity preserved, and ordered iteration in the one place that requires it. While this has no functional change, I realize it does mean allocating an extra data structure and performing a sort - so if this looks suspect to anyone regarding perf characteristics, I'm all ears. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231189 91177308-0d34-0410-b5e6-96231b3b80d8
101 lines
3.4 KiB
C++
101 lines
3.4 KiB
C++
//===-- 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_LIVESTACKANALYSIS_H
|
|
#define LLVM_CODEGEN_LIVESTACKANALYSIS_H
|
|
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
#include "llvm/Support/Allocator.h"
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
#include <map>
|
|
#include <unordered_map>
|
|
|
|
namespace llvm {
|
|
|
|
class LiveStacks : public MachineFunctionPass {
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
/// Special pool allocator for VNInfo's (LiveInterval val#).
|
|
///
|
|
VNInfo::Allocator VNInfoAllocator;
|
|
|
|
/// S2IMap - Stack slot indices to live interval mapping.
|
|
///
|
|
typedef std::unordered_map<int, LiveInterval> SS2IntervalMap;
|
|
SS2IntervalMap S2IMap;
|
|
|
|
/// S2RCMap - Stack slot indices to register class mapping.
|
|
std::map<int, const TargetRegisterClass*> S2RCMap;
|
|
|
|
public:
|
|
static char ID; // Pass identification, replacement for typeid
|
|
LiveStacks() : MachineFunctionPass(ID) {
|
|
initializeLiveStacksPass(*PassRegistry::getPassRegistry());
|
|
}
|
|
|
|
typedef SS2IntervalMap::iterator iterator;
|
|
typedef SS2IntervalMap::const_iterator const_iterator;
|
|
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(); }
|
|
|
|
LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
|
|
|
|
LiveInterval &getInterval(int Slot) {
|
|
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");
|
|
return I->second;
|
|
}
|
|
|
|
const LiveInterval &getInterval(int Slot) const {
|
|
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");
|
|
return I->second;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
void releaseMemory() override;
|
|
|
|
/// runOnMachineFunction - pass entry point
|
|
bool runOnMachineFunction(MachineFunction&) override;
|
|
|
|
/// print - Implement the dump method.
|
|
void print(raw_ostream &O, const Module* = nullptr) const override;
|
|
};
|
|
}
|
|
|
|
#endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */
|