Mac OS X X86-64 ABI is same as the standard.
[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 /// getAllocatableSetForRC - Toggle the bits that represent allocatable
38 /// registers for the specific register class.
39 static void getAllocatableSetForRC(MachineFunction &MF,
40                                    const TargetRegisterClass *RC, BitVector &R){  
41   for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
42          E = RC->allocation_order_end(MF); I != E; ++I)
43     R.set(*I);
44 }
45
46 BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF,
47                                            const TargetRegisterClass *RC) const {
48   BitVector Allocatable(NumRegs);
49   if (RC) {
50     getAllocatableSetForRC(MF, RC, Allocatable);
51     return Allocatable;
52   }
53
54   for (MRegisterInfo::regclass_iterator I = regclass_begin(),
55          E = regclass_end(); I != E; ++I)
56     getAllocatableSetForRC(MF, *I, Allocatable);
57   return Allocatable;
58 }
59
60 /// getLocation - This method should return the actual location of a frame
61 /// variable given the frame index.  The location is returned in ML.
62 /// Subclasses should override this method for special handling of frame
63 /// variables and then call MRegisterInfo::getLocation for the default action.
64 void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index,
65                         MachineLocation &ML) const {
66   const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
67   MachineFrameInfo *MFI = MF.getFrameInfo();
68   ML.set(getFrameRegister(MF),
69          MFI->getObjectOffset(Index) +
70          MFI->getStackSize() -
71          TFI.getOffsetOfLocalArea() +
72          MFI->getOffsetAdjustment());
73 }
74
75 /// getInitialFrameState - Returns a list of machine moves that are assumed
76 /// on entry to a function.
77 void
78 MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
79   // Default is to do nothing.
80 }
81