blob: 08039208fe80edbc1f0aef3bb87c1a0231af22be [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//
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.
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 Cheng61de82d2007-02-15 05:59:24 +000037BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF) const {
38 BitVector Allocatable(NumRegs);
Alkis Evlogimenosbb4bdf42004-08-26 22:21:04 +000039 for (MRegisterInfo::regclass_iterator I = regclass_begin(),
40 E = regclass_end(); I != E; ++I) {
41 const TargetRegisterClass *RC = *I;
42 for (TargetRegisterClass::iterator I = RC->allocation_order_begin(MF),
43 E = RC->allocation_order_end(MF); I != E; ++I)
Evan Chengb371f452007-02-19 21:49:54 +000044 Allocatable.set(*I);
Alkis Evlogimenosbb4bdf42004-08-26 22:21:04 +000045 }
46 return Allocatable;
Misha Brukmanf976c852005-04-21 22:55:34 +000047}
Jim Laskeya9979182006-03-28 13:48:33 +000048
49/// getLocation - This method should return the actual location of a frame
50/// variable given the frame index. The location is returned in ML.
51/// Subclasses should override this method for special handling of frame
52/// variables and then call MRegisterInfo::getLocation for the default action.
53void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index,
54 MachineLocation &ML) const {
Jim Laskey6b59a362006-08-03 17:27:09 +000055 const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
Jim Laskeya9979182006-03-28 13:48:33 +000056 MachineFrameInfo *MFI = MF.getFrameInfo();
57 ML.set(getFrameRegister(MF),
Jim Laskey6b59a362006-08-03 17:27:09 +000058 MFI->getObjectOffset(Index) +
59 MFI->getStackSize() -
Jim Laskey9dea41d2006-11-17 21:19:15 +000060 TFI.getOffsetOfLocalArea() +
61 MFI->getOffsetAdjustment());
Jim Laskeya9979182006-03-28 13:48:33 +000062}
Jim Laskey41886992006-04-07 16:34:46 +000063
64/// getInitialFrameState - Returns a list of machine moves that are assumed
65/// on entry to a function.
66void
Jim Laskey5e73d5b2007-01-24 18:45:13 +000067MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
Jim Laskey41886992006-04-07 16:34:46 +000068 // Default is to do nothing.
69}
70