Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.4 KiB

  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. namespace llvm {
  23. class LiveStacks : public MachineFunctionPass {
  24. const TargetRegisterInfo *TRI;
  25. /// Special pool allocator for VNInfo's (LiveInterval val#).
  26. ///
  27. VNInfo::Allocator VNInfoAllocator;
  28. /// S2IMap - Stack slot indices to live interval mapping.
  29. ///
  30. typedef std::map<int, LiveInterval> SS2IntervalMap;
  31. SS2IntervalMap S2IMap;
  32. /// S2RCMap - Stack slot indices to register class mapping.
  33. std::map<int, const TargetRegisterClass*> S2RCMap;
  34. public:
  35. static char ID; // Pass identification, replacement for typeid
  36. LiveStacks() : MachineFunctionPass(ID) {
  37. initializeLiveStacksPass(*PassRegistry::getPassRegistry());
  38. }
  39. typedef SS2IntervalMap::iterator iterator;
  40. typedef SS2IntervalMap::const_iterator const_iterator;
  41. const_iterator begin() const { return S2IMap.begin(); }
  42. const_iterator end() const { return S2IMap.end(); }
  43. iterator begin() { return S2IMap.begin(); }
  44. iterator end() { return S2IMap.end(); }
  45. unsigned getNumIntervals() const { return (unsigned)S2IMap.size(); }
  46. LiveInterval &getOrCreateInterval(int Slot, const TargetRegisterClass *RC);
  47. LiveInterval &getInterval(int Slot) {
  48. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  49. SS2IntervalMap::iterator I = S2IMap.find(Slot);
  50. assert(I != S2IMap.end() && "Interval does not exist for stack slot");
  51. return I->second;
  52. }
  53. const LiveInterval &getInterval(int Slot) const {
  54. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  55. SS2IntervalMap::const_iterator I = S2IMap.find(Slot);
  56. assert(I != S2IMap.end() && "Interval does not exist for stack slot");
  57. return I->second;
  58. }
  59. bool hasInterval(int Slot) const {
  60. return S2IMap.count(Slot);
  61. }
  62. const TargetRegisterClass *getIntervalRegClass(int Slot) const {
  63. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  64. std::map<int, const TargetRegisterClass*>::const_iterator
  65. I = S2RCMap.find(Slot);
  66. assert(I != S2RCMap.end() &&
  67. "Register class info does not exist for stack slot");
  68. return I->second;
  69. }
  70. VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; }
  71. virtual void getAnalysisUsage(AnalysisUsage &AU) const;
  72. virtual void releaseMemory();
  73. /// runOnMachineFunction - pass entry point
  74. virtual bool runOnMachineFunction(MachineFunction&);
  75. /// print - Implement the dump method.
  76. virtual void print(raw_ostream &O, const Module* = 0) const;
  77. };
  78. }
  79. #endif /* LLVM_CODEGEN_LIVESTACK_ANALYSIS_H */