LiveStacks.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //===-- LiveStacks.cpp - Live Stack Slot Analysis -------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the live stack slot analysis pass. It is analogous to
  10. // live interval analysis except it's analyzing liveness of stack slots rather
  11. // than registers.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/CodeGen/LiveStacks.h"
  15. #include "llvm/CodeGen/LiveIntervals.h"
  16. #include "llvm/CodeGen/Passes.h"
  17. #include "llvm/CodeGen/TargetRegisterInfo.h"
  18. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  19. #include "llvm/Support/Debug.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. using namespace llvm;
  22. #define DEBUG_TYPE "livestacks"
  23. char LiveStacks::ID = 0;
  24. INITIALIZE_PASS_BEGIN(LiveStacks, DEBUG_TYPE,
  25. "Live Stack Slot Analysis", false, false)
  26. INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
  27. INITIALIZE_PASS_END(LiveStacks, DEBUG_TYPE,
  28. "Live Stack Slot Analysis", false, false)
  29. char &llvm::LiveStacksID = LiveStacks::ID;
  30. void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const {
  31. AU.setPreservesAll();
  32. AU.addPreserved<SlotIndexes>();
  33. AU.addRequiredTransitive<SlotIndexes>();
  34. MachineFunctionPass::getAnalysisUsage(AU);
  35. }
  36. void LiveStacks::releaseMemory() {
  37. // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
  38. VNInfoAllocator.Reset();
  39. S2IMap.clear();
  40. S2RCMap.clear();
  41. }
  42. bool LiveStacks::runOnMachineFunction(MachineFunction &MF) {
  43. TRI = MF.getSubtarget().getRegisterInfo();
  44. // FIXME: No analysis is being done right now. We are relying on the
  45. // register allocators to provide the information.
  46. return false;
  47. }
  48. LiveInterval &
  49. LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) {
  50. assert(Slot >= 0 && "Spill slot indice must be >= 0");
  51. SS2IntervalMap::iterator I = S2IMap.find(Slot);
  52. if (I == S2IMap.end()) {
  53. I = S2IMap
  54. .emplace(
  55. std::piecewise_construct, std::forward_as_tuple(Slot),
  56. std::forward_as_tuple(Register::index2StackSlot(Slot), 0.0F))
  57. .first;
  58. S2RCMap.insert(std::make_pair(Slot, RC));
  59. } else {
  60. // Use the largest common subclass register class.
  61. const TargetRegisterClass *OldRC = S2RCMap[Slot];
  62. S2RCMap[Slot] = TRI->getCommonSubClass(OldRC, RC);
  63. }
  64. return I->second;
  65. }
  66. /// print - Implement the dump method.
  67. void LiveStacks::print(raw_ostream &OS, const Module*) const {
  68. OS << "********** INTERVALS **********\n";
  69. for (const_iterator I = begin(), E = end(); I != E; ++I) {
  70. I->second.print(OS);
  71. int Slot = I->first;
  72. const TargetRegisterClass *RC = getIntervalRegClass(Slot);
  73. if (RC)
  74. OS << " [" << TRI->getRegClassName(RC) << "]\n";
  75. else
  76. OS << " [Unknown]\n";
  77. }
  78. }