LiveStackAnalysis.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //===-- LiveStackAnalysis.h - Live Stack Slot Analysis ----------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the live stack slot analysis pass. It is analogous to
  11. // live interval analysis except it's analyzing liveness of stack slots rather
  12. // than registers.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_CODEGEN_LIVESTACKANALYSIS_H
  16. #define LLVM_CODEGEN_LIVESTACKANALYSIS_H
  17. #include "llvm/CodeGen/LiveInterval.h"
  18. #include "llvm/CodeGen/MachineFunctionPass.h"
  19. #include "llvm/Support/Allocator.h"
  20. #include "llvm/Target/TargetRegisterInfo.h"
  21. #include <map>
  22. #include <unordered_map>
  23. namespace llvm {
  24. class LiveStacks : public MachineFunctionPass {
  25. const TargetRegisterInfo *TRI;
  26. /// Special pool allocator for VNInfo's (LiveInterval val#).
  27. ///
  28. VNInfo::Allocator VNInfoAllocator;
  29. /// S2IMap - Stack slot indices to live interval mapping.
  30. ///
  31. typedef std::unordered_map<int, LiveInterval> SS2IntervalMap;
  32. SS2IntervalMap S2IMap;
  33. /// S2RCMap - Stack slot indices to register class mapping.
  34. std::map<int, const TargetRegisterClass*> S2RCMap;
  35. public:
  36. static char ID; // Pass identification, replacement for typeid
  37. LiveStacks() : MachineFunctionPass(ID) {
  38. initializeLiveStacksPass(*PassRegistry::getPassRegistry());
  39. }
  40. typedef SS2IntervalMap::iterator iterator;
  41. typedef SS2IntervalMap::const_iterator const_iterator;
  42. const_iterator begin() const { return S2IMap.begin(); }
  43. const_iterator end() const { return S2IMap.end(); }
  44. iterator begin() { return S2IMap.begin(); }
  45. iterator end() { return S2IMap.end(); }
  46. unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
  47. LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
  48. LiveInterval &getInterval(int Slot) {
  49. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  50. SS2IntervalMap::iterator I = S2IMap.find(Slot);
  51. assert(I != S2IMap.end() && "Interval does not exist for stack slot");
  52. return I->second;
  53. }
  54. const LiveInterval &getInterval(int Slot) const {
  55. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  56. SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
  57. assert(I != S2IMap.end() && "Interval does not exist for stack slot");
  58. return I->second;
  59. }
  60. bool hasInterval(int Slot) const {
  61. return S2IMap.count(Slot);
  62. }
  63. const TargetRegisterClass *getIntervalRegClass(int Slot) const {
  64. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  65. std::map<int, const TargetRegisterClass*>::const_iterator
  66. I = S2RCMap.find(Slot);
  67. assert(I != S2RCMap.end() &&
  68. "Register class info does not exist for stack slot");
  69. return I->second;
  70. }
  71. VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
  72. void getAnalysisUsage(AnalysisUsage &AU) const override;
  73. void releaseMemory() override;
  74. /// runOnMachineFunction - pass entry point
  75. bool runOnMachineFunction(MachineFunction&) override;
  76. /// print - Implement the dump method.
  77. void print(raw_ostream &O, const Module* = nullptr) const override;
  78. };
  79. }
  80. #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */