LiveStackAnalysis.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //===-- LiveStackAnalysis.cpp - Live Stack Slot Analysis ------------------===//
  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. #define DEBUG_TYPE "livestacks"
  16. #include "llvm/CodeGen/LiveStackAnalysis.h"
  17. #include "llvm/CodeGen/LiveIntervalAnalysis.h"
  18. #include "llvm/CodeGen/Passes.h"
  19. #include "llvm/Target/TargetRegisterInfo.h"
  20. #include "llvm/Support/Debug.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. #include "llvm/ADT/Statistic.h"
  23. #include <limits>
  24. using namespace llvm;
  25. char LiveStacks::ID = 0;
  26. INITIALIZE_PASS(LiveStacks, "livestacks",
  27. "Live Stack Slot Analysis", false, false)
  28. char &llvm::LiveStacksID = LiveStacks::ID;
  29. void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const {
  30. AU.setPreservesAll();
  31. AU.addPreserved<SlotIndexes>();
  32. AU.addRequiredTransitive<SlotIndexes>();
  33. MachineFunctionPass::getAnalysisUsage(AU);
  34. }
  35. void LiveStacks::releaseMemory() {
  36. // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
  37. VNInfoAllocator.Reset();
  38. S2IMap.clear();
  39. S2RCMap.clear();
  40. }
  41. bool LiveStacks::runOnMachineFunction(MachineFunction &) {
  42. // FIXME: No analysis is being done right now. We are relying on the
  43. // register allocators to provide the information.
  44. return false;
  45. }
  46. LiveInterval &
  47. LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) {
  48. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  49. SS2IntervalMap::iterator I = S2IMap.find(Slot);
  50. if (I == S2IMap.end()) {
  51. I = S2IMap.insert(I, std::make_pair(Slot,
  52. LiveInterval(TargetRegisterInfo::index2StackSlot(Slot), 0.0F)));
  53. S2RCMap.insert(std::make_pair(Slot, RC));
  54. } else {
  55. // Use the largest common subclass register class.
  56. const TargetRegisterClass *OldRC = S2RCMap[Slot];
  57. S2RCMap[Slot] = getCommonSubClass(OldRC, RC);
  58. }
  59. return I->second;
  60. }
  61. /// print - Implement the dump method.
  62. void LiveStacks::print(raw_ostream &OS, const Module*) const {
  63. OS << "********** INTERVALS **********\n";
  64. for (const_iterator I = begin(), E = end(); I != E; ++I) {
  65. I->second.print(OS);
  66. int Slot = I->first;
  67. const TargetRegisterClass *RC = getIntervalRegClass(Slot);
  68. if (RC)
  69. OS << " [" << RC->getName() << "]\n";
  70. else
  71. OS << " [Unknown]\n";
  72. }
  73. }