1 //===- MRegisterInfo.cpp - Target Register Information Implementation -----===//
3 // The LLVM Compiler Infrastructure
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.
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 /// 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)
46 BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF,
47 const TargetRegisterClass *RC) const {
48 BitVector Allocatable(NumRegs);
50 getAllocatableSetForRC(MF, RC, Allocatable);
54 for (MRegisterInfo::regclass_iterator I = regclass_begin(),
55 E = regclass_end(); I != E; ++I)
56 getAllocatableSetForRC(MF, *I, Allocatable);
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) +
71 TFI.getOffsetOfLocalArea() +
72 MFI->getOffsetAdjustment());
75 /// getInitialFrameState - Returns a list of machine moves that are assumed
76 /// on entry to a function.
78 MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
79 // Default is to do nothing.