Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 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 | |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/LiveStackAnalysis.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Statistic.h" |
Lang Hames | fc968ef | 2009-06-02 16:53:25 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/Passes.h" |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Chris Lattner | d99f1c6 | 2009-08-23 03:47:42 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetRegisterInfo.h" |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetSubtargetInfo.h" |
Lang Hames | fc968ef | 2009-06-02 16:53:25 +0000 | [diff] [blame] | 24 | #include <limits> |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 27 | #define DEBUG_TYPE "livestacks" |
| 28 | |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 29 | char LiveStacks::ID = 0; |
Evan Cheng | b53825b | 2012-09-21 20:04:28 +0000 | [diff] [blame] | 30 | INITIALIZE_PASS_BEGIN(LiveStacks, "livestacks", |
| 31 | "Live Stack Slot Analysis", false, false) |
| 32 | INITIALIZE_PASS_DEPENDENCY(SlotIndexes) |
| 33 | INITIALIZE_PASS_END(LiveStacks, "livestacks", |
Owen Anderson | df7a4f2 | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 34 | "Live Stack Slot Analysis", false, false) |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 35 | |
Jakob Stoklund Olesen | 7cdc1e5 | 2010-10-26 00:11:33 +0000 | [diff] [blame] | 36 | char &llvm::LiveStacksID = LiveStacks::ID; |
| 37 | |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 38 | void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const { |
Evan Cheng | bab5988 | 2008-09-22 22:26:15 +0000 | [diff] [blame] | 39 | AU.setPreservesAll(); |
Lang Hames | 05fb963 | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 40 | AU.addPreserved<SlotIndexes>(); |
| 41 | AU.addRequiredTransitive<SlotIndexes>(); |
Evan Cheng | 168f8f3 | 2008-09-22 20:58:04 +0000 | [diff] [blame] | 42 | MachineFunctionPass::getAnalysisUsage(AU); |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void LiveStacks::releaseMemory() { |
Benjamin Kramer | a000002 | 2010-06-26 11:30:59 +0000 | [diff] [blame] | 46 | // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd. |
| 47 | VNInfoAllocator.Reset(); |
Evan Cheng | 210fc62 | 2009-05-03 18:32:42 +0000 | [diff] [blame] | 48 | S2IMap.clear(); |
| 49 | S2RCMap.clear(); |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Jakob Stoklund Olesen | 1352be2 | 2011-09-30 22:18:51 +0000 | [diff] [blame] | 52 | bool LiveStacks::runOnMachineFunction(MachineFunction &MF) { |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 53 | TRI = MF.getSubtarget().getRegisterInfo(); |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 54 | // FIXME: No analysis is being done right now. We are relying on the |
| 55 | // register allocators to provide the information. |
| 56 | return false; |
| 57 | } |
| 58 | |
Jakob Stoklund Olesen | b83a6b2 | 2011-01-09 21:17:37 +0000 | [diff] [blame] | 59 | LiveInterval & |
| 60 | LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) { |
| 61 | assert(Slot >= 0 && "Spill slot indice must be >= 0"); |
| 62 | SS2IntervalMap::iterator I = S2IMap.find(Slot); |
| 63 | if (I == S2IMap.end()) { |
David Blaikie | ed40025 | 2015-03-04 01:20:33 +0000 | [diff] [blame] | 64 | I = S2IMap.emplace(std::piecewise_construct, std::forward_as_tuple(Slot), |
| 65 | std::forward_as_tuple( |
| 66 | TargetRegisterInfo::index2StackSlot(Slot), 0.0F)) |
| 67 | .first; |
Jakob Stoklund Olesen | b83a6b2 | 2011-01-09 21:17:37 +0000 | [diff] [blame] | 68 | S2RCMap.insert(std::make_pair(Slot, RC)); |
| 69 | } else { |
| 70 | // Use the largest common subclass register class. |
| 71 | const TargetRegisterClass *OldRC = S2RCMap[Slot]; |
Jakob Stoklund Olesen | 1352be2 | 2011-09-30 22:18:51 +0000 | [diff] [blame] | 72 | S2RCMap[Slot] = TRI->getCommonSubClass(OldRC, RC); |
Jakob Stoklund Olesen | b83a6b2 | 2011-01-09 21:17:37 +0000 | [diff] [blame] | 73 | } |
| 74 | return I->second; |
| 75 | } |
| 76 | |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 77 | /// print - Implement the dump method. |
Chris Lattner | 1362602 | 2009-08-23 06:03:38 +0000 | [diff] [blame] | 78 | void LiveStacks::print(raw_ostream &OS, const Module*) const { |
Chris Lattner | d99f1c6 | 2009-08-23 03:47:42 +0000 | [diff] [blame] | 79 | |
| 80 | OS << "********** INTERVALS **********\n"; |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 81 | for (const_iterator I = begin(), E = end(); I != E; ++I) { |
Chris Lattner | d99f1c6 | 2009-08-23 03:47:42 +0000 | [diff] [blame] | 82 | I->second.print(OS); |
Evan Cheng | 210fc62 | 2009-05-03 18:32:42 +0000 | [diff] [blame] | 83 | int Slot = I->first; |
| 84 | const TargetRegisterClass *RC = getIntervalRegClass(Slot); |
| 85 | if (RC) |
Craig Topper | cf0444b | 2014-11-17 05:50:14 +0000 | [diff] [blame] | 86 | OS << " [" << TRI->getRegClassName(RC) << "]\n"; |
Evan Cheng | 210fc62 | 2009-05-03 18:32:42 +0000 | [diff] [blame] | 87 | else |
Chris Lattner | d99f1c6 | 2009-08-23 03:47:42 +0000 | [diff] [blame] | 88 | OS << " [Unknown]\n"; |
Evan Cheng | 12a0222 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 89 | } |
| 90 | } |