LiveStacks.cpp 2.8 KB

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