LLVM API Documentation

LiveStackAnalysis.cpp
Go to the documentation of this file.
00001 //===-- LiveStackAnalysis.cpp - Live Stack Slot Analysis ------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the live stack slot analysis pass. It is analogous to
00011 // live interval analysis except it's analyzing liveness of stack slots rather
00012 // than registers.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #include "llvm/CodeGen/LiveStackAnalysis.h"
00017 #include "llvm/ADT/Statistic.h"
00018 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
00019 #include "llvm/CodeGen/Passes.h"
00020 #include "llvm/Support/Debug.h"
00021 #include "llvm/Support/raw_ostream.h"
00022 #include "llvm/Target/TargetRegisterInfo.h"
00023 #include "llvm/Target/TargetSubtargetInfo.h"
00024 #include <limits>
00025 using namespace llvm;
00026 
00027 #define DEBUG_TYPE "livestacks"
00028 
00029 char LiveStacks::ID = 0;
00030 INITIALIZE_PASS_BEGIN(LiveStacks, "livestacks",
00031                 "Live Stack Slot Analysis", false, false)
00032 INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
00033 INITIALIZE_PASS_END(LiveStacks, "livestacks",
00034                 "Live Stack Slot Analysis", false, false)
00035 
00036 char &llvm::LiveStacksID = LiveStacks::ID;
00037 
00038 void LiveStacks::getAnalysisUsage(AnalysisUsage &AU) const {
00039   AU.setPreservesAll();
00040   AU.addPreserved<SlotIndexes>();
00041   AU.addRequiredTransitive<SlotIndexes>();
00042   MachineFunctionPass::getAnalysisUsage(AU);
00043 }
00044 
00045 void LiveStacks::releaseMemory() {
00046   // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
00047   VNInfoAllocator.Reset();
00048   S2IMap.clear();
00049   S2RCMap.clear();
00050 }
00051 
00052 bool LiveStacks::runOnMachineFunction(MachineFunction &MF) {
00053   TRI = MF.getSubtarget().getRegisterInfo();
00054   // FIXME: No analysis is being done right now. We are relying on the
00055   // register allocators to provide the information.
00056   return false;
00057 }
00058 
00059 LiveInterval &
00060 LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) {
00061   assert(Slot >= 0 && "Spill slot indice must be >= 0");
00062   SS2IntervalMap::iterator I = S2IMap.find(Slot);
00063   if (I == S2IMap.end()) {
00064     I = S2IMap.insert(I, std::make_pair(Slot,
00065             LiveInterval(TargetRegisterInfo::index2StackSlot(Slot), 0.0F)));
00066     S2RCMap.insert(std::make_pair(Slot, RC));
00067   } else {
00068     // Use the largest common subclass register class.
00069     const TargetRegisterClass *OldRC = S2RCMap[Slot];
00070     S2RCMap[Slot] = TRI->getCommonSubClass(OldRC, RC);
00071   }
00072   return I->second;
00073 }
00074 
00075 /// print - Implement the dump method.
00076 void LiveStacks::print(raw_ostream &OS, const Module*) const {
00077 
00078   OS << "********** INTERVALS **********\n";
00079   for (const_iterator I = begin(), E = end(); I != E; ++I) {
00080     I->second.print(OS);
00081     int Slot = I->first;
00082     const TargetRegisterClass *RC = getIntervalRegClass(Slot);
00083     if (RC)
00084       OS << " [" << RC->getName() << "]\n";
00085     else
00086       OS << " [Unknown]\n";
00087   }
00088 }