1 //===- MRegisterInfo.cpp - Target Register Information Implementation -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the MRegisterInfo interface.
12 //===----------------------------------------------------------------------===//
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"
24 MRegisterInfo::MRegisterInfo(const TargetRegisterDesc
*D
, unsigned NR
,
25 regclass_iterator RCB
, regclass_iterator RCE
,
27 : Desc(D
), NumRegs(NR
), RegClassBegin(RCB
), RegClassEnd(RCE
) {
28 assert(NumRegs
< FirstVirtualRegister
&&
29 "Target has too many physical registers!");
31 CallFrameSetupOpcode
= CFSO
;
32 CallFrameDestroyOpcode
= CFDO
;
35 MRegisterInfo::~MRegisterInfo() {}
37 /// getPhysicalRegisterRegClass - Returns the Register Class of a physical
39 const TargetRegisterClass
*
40 MRegisterInfo::getPhysicalRegisterRegClass(MVT::ValueType VT
,
42 assert(isPhysicalRegister(reg
) && "reg must be a physical register");
43 // Pick the register class of the right type that contains this physreg.
44 for (regclass_iterator I
= regclass_begin(), E
= regclass_end(); I
!= E
; ++I
)
45 if ((*I
)->hasType(VT
) && (*I
)->contains(reg
))
47 assert(false && "Couldn't find the register class");
52 /// getAllocatableSetForRC - Toggle the bits that represent allocatable
53 /// registers for the specific register class.
54 static void getAllocatableSetForRC(MachineFunction
&MF
,
55 const TargetRegisterClass
*RC
, BitVector
&R
){
56 for (TargetRegisterClass::iterator I
= RC
->allocation_order_begin(MF
),
57 E
= RC
->allocation_order_end(MF
); I
!= E
; ++I
)
61 BitVector
MRegisterInfo::getAllocatableSet(MachineFunction
&MF
,
62 const TargetRegisterClass
*RC
) const {
63 BitVector
Allocatable(NumRegs
);
65 getAllocatableSetForRC(MF
, RC
, Allocatable
);
69 for (MRegisterInfo::regclass_iterator I
= regclass_begin(),
70 E
= regclass_end(); I
!= E
; ++I
)
71 getAllocatableSetForRC(MF
, *I
, Allocatable
);
75 /// getLocation - This method should return the actual location of a frame
76 /// variable given the frame index. The location is returned in ML.
77 /// Subclasses should override this method for special handling of frame
78 /// variables and then call MRegisterInfo::getLocation for the default action.
79 void MRegisterInfo::getLocation(MachineFunction
&MF
, unsigned Index
,
80 MachineLocation
&ML
) const {
81 const TargetFrameInfo
&TFI
= *MF
.getTarget().getFrameInfo();
82 MachineFrameInfo
*MFI
= MF
.getFrameInfo();
83 ML
.set(getFrameRegister(MF
),
84 MFI
->getObjectOffset(Index
) +
86 TFI
.getOffsetOfLocalArea() +
87 MFI
->getOffsetAdjustment());
90 /// getInitialFrameState - Returns a list of machine moves that are assumed
91 /// on entry to a function.
93 MRegisterInfo::getInitialFrameState(std::vector
<MachineMove
> &Moves
) const {
94 // Default is to do nothing.