memopv16i8 had wrong alignment requirement, would have broken pabsb
[oota-llvm.git] / lib / Target / MRegisterInfo.cpp
1 //===- MRegisterInfo.cpp - Target Register Information Implementation -----===//
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 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/ADT/BitVector.h"
20
21 using namespace llvm;
22
23 MRegisterInfo::MRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
24                              regclass_iterator RCB, regclass_iterator RCE,
25                              int CFSO, int CFDO)
26   : Desc(D), NumRegs(NR), RegClassBegin(RCB), RegClassEnd(RCE) {
27   assert(NumRegs < FirstVirtualRegister &&
28          "Target has too many physical registers!");
29
30   CallFrameSetupOpcode   = CFSO;
31   CallFrameDestroyOpcode = CFDO;
32 }
33
34 MRegisterInfo::~MRegisterInfo() {}
35
36 /// getPhysicalRegisterRegClass - Returns the Register Class of a physical
37 /// register.
38 const TargetRegisterClass *
39 MRegisterInfo::getPhysicalRegisterRegClass(MVT::ValueType VT,
40                                            unsigned reg) const {
41   assert(isPhysicalRegister(reg) && "reg must be a physical register");
42   // Pick the register class of the right type that contains this physreg.
43   for (regclass_iterator I = regclass_begin(), E = regclass_end(); I != E; ++I)
44     if ((*I)->hasType(VT) && (*I)->contains(reg))
45       return *I;
46   assert(false && "Couldn't find the register class");
47   return 0;
48 }
49
50
51 /// getAllocatableSetForRC - Toggle the bits that represent allocatable
52 /// registers for the specific register class.
53 static void getAllocatableSetForRC(MachineFunction &MF,
54                                    const TargetRegisterClass *RC, BitVector &R){  
55   for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
56          E = RC->allocation_order_end(MF); I != E; ++I)
57     R.set(*I);
58 }
59
60 BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF,
61                                            const TargetRegisterClass *RC) const {
62   BitVector Allocatable(NumRegs);
63   if (RC) {
64     getAllocatableSetForRC(MF, RC, Allocatable);
65     return Allocatable;
66   }
67
68   for (MRegisterInfo::regclass_iterator I = regclass_begin(),
69          E = regclass_end(); I != E; ++I)
70     getAllocatableSetForRC(MF, *I, Allocatable);
71   return Allocatable;
72 }
73
74 /// getFrameIndexOffset - Returns the displacement from the frame register to
75 /// the stack frame of the specified index. This is the default implementation
76 /// which is likely incorrect for the target.
77 int MRegisterInfo::getFrameIndexOffset(MachineFunction &MF, int FI) const {
78   const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
79   MachineFrameInfo *MFI = MF.getFrameInfo();
80   return MFI->getObjectOffset(FI) + MFI->getStackSize() -
81     TFI.getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
82 }
83
84 /// getInitialFrameState - Returns a list of machine moves that are assumed
85 /// on entry to a function.
86 void
87 MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
88   // Default is to do nothing.
89 }
90