blob: 80ecfdb7a507ef0a7ac044cb354ebd9555f48157 [file] [log] [blame]
Matthias Braun209f0482017-12-18 23:19:44 +00001//===-- LiveStacks.cpp - Live Stack Slot Analysis -------------------------===//
Evan Cheng3f32d652008-06-04 09:18:41 +00002//
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
Matthias Braun209f0482017-12-18 23:19:44 +000016#include "llvm/CodeGen/LiveStacks.h"
Matthias Braunfa621d22017-12-13 02:51:04 +000017#include "llvm/CodeGen/LiveIntervals.h"
Evan Cheng3f32d652008-06-04 09:18:41 +000018#include "llvm/CodeGen/Passes.h"
David Blaikiee3a9b4c2017-11-17 01:07:10 +000019#include "llvm/CodeGen/TargetRegisterInfo.h"
20#include "llvm/CodeGen/TargetSubtargetInfo.h"
Evan Cheng3f32d652008-06-04 09:18:41 +000021#include "llvm/Support/Debug.h"
Chris Lattnerc02497f2009-08-23 03:47:42 +000022#include "llvm/Support/raw_ostream.h"
Evan Cheng3f32d652008-06-04 09:18:41 +000023using namespace llvm;
24
Chandler Carruth8677f2f2014-04-22 02:02:50 +000025#define DEBUG_TYPE "livestacks"
26
Evan Cheng3f32d652008-06-04 09:18:41 +000027char LiveStacks::ID = 0;
Matthias Braun94c49042017-05-25 21:26:32 +000028INITIALIZE_PASS_BEGIN(LiveStacks, DEBUG_TYPE,
Evan Chengbb36a432012-09-21 20:04:28 +000029 "Live Stack Slot Analysis", false, false)
30INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
Matthias Braun94c49042017-05-25 21:26:32 +000031INITIALIZE_PASS_END(LiveStacks, DEBUG_TYPE,
Owen Andersonce665bd2010-10-07 22:25:06 +000032 "Live Stack Slot Analysis", false, false)
Evan Cheng3f32d652008-06-04 09:18:41 +000033
Jakob Stoklund Olesen2d172932010-10-26 00:11:33 +000034char &llvm::LiveStacksID = LiveStacks::ID;
35
Evan Cheng3f32d652008-06-04 09:18:41 +000036void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const {
Evan Chengef901c52008-09-22 22:26:15 +000037 AU.setPreservesAll();
Lang Hames233a60e2009-11-03 23:52:08 +000038 AU.addPreserved<SlotIndexes>();
39 AU.addRequiredTransitive<SlotIndexes>();
Evan Chengbbeeb2a2008-09-22 20:58:04 +000040 MachineFunctionPass::getAnalysisUsage(AU);
Evan Cheng3f32d652008-06-04 09:18:41 +000041}
42
43void LiveStacks::releaseMemory() {
Benjamin Kramerce9a20b2010-06-26 11:30:59 +000044 // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
45 VNInfoAllocator.Reset();
Evan Chengc781a242009-05-03 18:32:42 +000046 S2IMap.clear();
47 S2RCMap.clear();
Evan Cheng3f32d652008-06-04 09:18:41 +000048}
49
Jakob Stoklund Olesene27e1ca2011-09-30 22:18:51 +000050bool LiveStacks::runOnMachineFunction(MachineFunction &MF) {
Eric Christopher60355182014-08-05 02:39:49 +000051 TRI = MF.getSubtarget().getRegisterInfo();
Evan Cheng3f32d652008-06-04 09:18:41 +000052 // FIXME: No analysis is being done right now. We are relying on the
53 // register allocators to provide the information.
54 return false;
55}
56
Jakob Stoklund Olesenbe97e902011-01-09 21:17:37 +000057LiveInterval &
58LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) {
59 assert(Slot >= 0 && "Spill slot indice must be >= 0");
60 SS2IntervalMap::iterator I = S2IMap.find(Slot);
61 if (I == S2IMap.end()) {
David Blaikie41cf4632015-03-04 01:20:33 +000062 I = S2IMap.emplace(std::piecewise_construct, std::forward_as_tuple(Slot),
63 std::forward_as_tuple(
64 TargetRegisterInfo::index2StackSlot(Slot), 0.0F))
65 .first;
Jakob Stoklund Olesenbe97e902011-01-09 21:17:37 +000066 S2RCMap.insert(std::make_pair(Slot, RC));
67 } else {
68 // Use the largest common subclass register class.
69 const TargetRegisterClass *OldRC = S2RCMap[Slot];
Jakob Stoklund Olesene27e1ca2011-09-30 22:18:51 +000070 S2RCMap[Slot] = TRI->getCommonSubClass(OldRC, RC);
Jakob Stoklund Olesenbe97e902011-01-09 21:17:37 +000071 }
72 return I->second;
73}
74
Evan Cheng3f32d652008-06-04 09:18:41 +000075/// print - Implement the dump method.
Chris Lattner45cfe542009-08-23 06:03:38 +000076void LiveStacks::print(raw_ostream &OS, const Module*) const {
Chris Lattnerc02497f2009-08-23 03:47:42 +000077
78 OS << "********** INTERVALS **********\n";
Evan Cheng3f32d652008-06-04 09:18:41 +000079 for (const_iterator I = begin(), E = end(); I != E; ++I) {
Chris Lattnerc02497f2009-08-23 03:47:42 +000080 I->second.print(OS);
Evan Chengc781a242009-05-03 18:32:42 +000081 int Slot = I->first;
82 const TargetRegisterClass *RC = getIntervalRegClass(Slot);
83 if (RC)
Craig Toppera5babc82014-11-17 05:50:14 +000084 OS << " [" << TRI->getRegClassName(RC) << "]\n";
Evan Chengc781a242009-05-03 18:32:42 +000085 else
Chris Lattnerc02497f2009-08-23 03:47:42 +000086 OS << " [Unknown]\n";
Evan Cheng3f32d652008-06-04 09:18:41 +000087 }
88}