blob: d7e161107edafe4f53ee9723d5ba68d641dffde6 [file] [log] [blame]
Chris Lattner9208bbf2002-12-17 04:03:08 +00001//===- MRegisterInfo.cpp - Target Register Information Implementation -----===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner9208bbf2002-12-17 04:03:08 +00009//
10// This file implements the MRegisterInfo interface.
11//
12//===----------------------------------------------------------------------===//
13
Jim Laskey6b59a362006-08-03 17:27:09 +000014#include "llvm/Target/TargetMachine.h"
Chris Lattner9208bbf2002-12-17 04:03:08 +000015#include "llvm/Target/MRegisterInfo.h"
Jim Laskey6b59a362006-08-03 17:27:09 +000016#include "llvm/Target/TargetFrameInfo.h"
Jim Laskeya9979182006-03-28 13:48:33 +000017#include "llvm/CodeGen/MachineFunction.h"
18#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineLocation.h"
Evan Cheng61de82d2007-02-15 05:59:24 +000020#include "llvm/ADT/BitVector.h"
Jim Laskeya9979182006-03-28 13:48:33 +000021
Chris Lattner20ea0622006-02-01 18:10:56 +000022using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000023
Chris Lattner0f21fd52005-09-30 17:49:27 +000024MRegisterInfo::MRegisterInfo(const TargetRegisterDesc *D, unsigned NR,
Chris Lattner3ad76422002-12-28 20:34:18 +000025 regclass_iterator RCB, regclass_iterator RCE,
Misha Brukman7847fca2005-04-22 17:54:37 +000026 int CFSO, int CFDO)
Chris Lattner9208bbf2002-12-17 04:03:08 +000027 : Desc(D), NumRegs(NR), RegClassBegin(RCB), RegClassEnd(RCE) {
28 assert(NumRegs < FirstVirtualRegister &&
29 "Target has too many physical registers!");
30
Chris Lattner3ad76422002-12-28 20:34:18 +000031 CallFrameSetupOpcode = CFSO;
32 CallFrameDestroyOpcode = CFDO;
Chris Lattner9208bbf2002-12-17 04:03:08 +000033}
34
Nate Begeman0aafc322004-10-27 06:00:53 +000035MRegisterInfo::~MRegisterInfo() {}
36
Evan Cheng42d60272007-09-26 21:36:17 +000037/// getPhysicalRegisterRegClass - Returns the Register Class of a physical
38/// register.
39const TargetRegisterClass *
40MRegisterInfo::getPhysicalRegisterRegClass(MVT::ValueType VT,
41 unsigned reg) const {
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))
46 return *I;
47 assert(false && "Couldn't find the register class");
48 return 0;
49}
50
51
Evan Cheng7be63682007-04-17 23:33:39 +000052/// getAllocatableSetForRC - Toggle the bits that represent allocatable
53/// registers for the specific register class.
54static 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)
58 R.set(*I);
59}
60
Evan Chengeff03db2007-04-17 20:23:34 +000061BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF,
62 const TargetRegisterClass *RC) const {
Evan Cheng61de82d2007-02-15 05:59:24 +000063 BitVector Allocatable(NumRegs);
Evan Cheng7be63682007-04-17 23:33:39 +000064 if (RC) {
65 getAllocatableSetForRC(MF, RC, Allocatable);
66 return Allocatable;
Alkis Evlogimenosbb4bdf42004-08-26 22:21:04 +000067 }
Evan Cheng7be63682007-04-17 23:33:39 +000068
69 for (MRegisterInfo::regclass_iterator I = regclass_begin(),
70 E = regclass_end(); I != E; ++I)
71 getAllocatableSetForRC(MF, *I, Allocatable);
Alkis Evlogimenosbb4bdf42004-08-26 22:21:04 +000072 return Allocatable;
Misha Brukmanf976c852005-04-21 22:55:34 +000073}
Jim Laskeya9979182006-03-28 13:48:33 +000074
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.
79void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index,
80 MachineLocation &ML) const {
Jim Laskey6b59a362006-08-03 17:27:09 +000081 const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
Jim Laskeya9979182006-03-28 13:48:33 +000082 MachineFrameInfo *MFI = MF.getFrameInfo();
83 ML.set(getFrameRegister(MF),
Jim Laskey6b59a362006-08-03 17:27:09 +000084 MFI->getObjectOffset(Index) +
85 MFI->getStackSize() -
Jim Laskey9dea41d2006-11-17 21:19:15 +000086 TFI.getOffsetOfLocalArea() +
87 MFI->getOffsetAdjustment());
Jim Laskeya9979182006-03-28 13:48:33 +000088}
Jim Laskey41886992006-04-07 16:34:46 +000089
90/// getInitialFrameState - Returns a list of machine moves that are assumed
91/// on entry to a function.
92void
Jim Laskey5e73d5b2007-01-24 18:45:13 +000093MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
Jim Laskey41886992006-04-07 16:34:46 +000094 // Default is to do nothing.
95}
96