blob: ae9f20372fc80e42c3e3cf0086862d114942d40e [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 Chengeff03db2007-04-17 20:23:34 +000037BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF,
38 const TargetRegisterClass *RC) const {
Evan Cheng61de82d2007-02-15 05:59:24 +000039 BitVector Allocatable(NumRegs);
Alkis Evlogimenosbb4bdf42004-08-26 22:21:04 +000040 for (MRegisterInfo::regclass_iterator I = regclass_begin(),
41 E = regclass_end(); I != E; ++I) {
Evan Chengeff03db2007-04-17 20:23:34 +000042 const TargetRegisterClass *TRC = *I;
43 if (RC && TRC != RC)
44 continue;
45 for (TargetRegisterClass::iterator I = TRC->allocation_order_begin(MF),
46 E = TRC->allocation_order_end(MF); I != E; ++I)
Evan Chengb371f452007-02-19 21:49:54 +000047 Allocatable.set(*I);
Alkis Evlogimenosbb4bdf42004-08-26 22:21:04 +000048 }
49 return Allocatable;
Misha Brukmanf976c852005-04-21 22:55:34 +000050}
Jim Laskeya9979182006-03-28 13:48:33 +000051
52/// getLocation - This method should return the actual location of a frame
53/// variable given the frame index. The location is returned in ML.
54/// Subclasses should override this method for special handling of frame
55/// variables and then call MRegisterInfo::getLocation for the default action.
56void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index,
57 MachineLocation &ML) const {
Jim Laskey6b59a362006-08-03 17:27:09 +000058 const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
Jim Laskeya9979182006-03-28 13:48:33 +000059 MachineFrameInfo *MFI = MF.getFrameInfo();
60 ML.set(getFrameRegister(MF),
Jim Laskey6b59a362006-08-03 17:27:09 +000061 MFI->getObjectOffset(Index) +
62 MFI->getStackSize() -
Jim Laskey9dea41d2006-11-17 21:19:15 +000063 TFI.getOffsetOfLocalArea() +
64 MFI->getOffsetAdjustment());
Jim Laskeya9979182006-03-28 13:48:33 +000065}
Jim Laskey41886992006-04-07 16:34:46 +000066
67/// getInitialFrameState - Returns a list of machine moves that are assumed
68/// on entry to a function.
69void
Jim Laskey5e73d5b2007-01-24 18:45:13 +000070MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
Jim Laskey41886992006-04-07 16:34:46 +000071 // Default is to do nothing.
72}
73