Re-apply my liveintervalanalysis changes. Now with PR1207 fixes.
[oota-llvm.git] / lib / Target / MRegisterInfo.cpp
1 //===- MRegisterInfo.cpp - Target Register Information Implementation -----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the MRegisterInfo interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/Target/MRegisterInfo.h"
16 #include "llvm/Target/TargetFrameInfo.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineFrameInfo.h"
19 #include "llvm/CodeGen/MachineLocation.h"
20 #include "llvm/ADT/BitVector.h"
21
22 using namespace llvm;
23
24 MRegisterInfo::MRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
25                              regclass_iterator RCB, regclass_iterator RCE,
26                              int CFSO, int CFDO)
27   : Desc(D), NumRegs(NR), RegClassBegin(RCB), RegClassEnd(RCE) {
28   assert(NumRegs < FirstVirtualRegister &&
29          "Target has too many physical registers!");
30
31   CallFrameSetupOpcode   = CFSO;
32   CallFrameDestroyOpcode = CFDO;
33 }
34
35 MRegisterInfo::~MRegisterInfo() {}
36
37 BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF) const {
38   BitVector Allocatable(NumRegs);
39   for (MRegisterInfo::regclass_iterator I = regclass_begin(),
40          E = regclass_end(); I != E; ++I) {
41     const TargetRegisterClass *RC = *I;
42     for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
43            E = RC->allocation_order_end(MF); I != E; ++I)
44       Allocatable.set(*I);
45   }
46   return Allocatable;
47 }
48
49 /// getLocation - This method should return the actual location of a frame
50 /// variable given the frame index.  The location is returned in ML.
51 /// Subclasses should override this method for special handling of frame
52 /// variables and then call MRegisterInfo::getLocation for the default action.
53 void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index,
54                         MachineLocation &ML) const {
55   const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
56   MachineFrameInfo *MFI = MF.getFrameInfo();
57   ML.set(getFrameRegister(MF),
58          MFI->getObjectOffset(Index) +
59          MFI->getStackSize() -
60          TFI.getOffsetOfLocalArea() +
61          MFI->getOffsetAdjustment());
62 }
63
64 /// getInitialFrameState - Returns a list of machine moves that are assumed
65 /// on entry to a function.
66 void
67 MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
68   // Default is to do nothing.
69 }
70