Chris Lattner | 9208bbf | 2002-12-17 04:03:08 +0000 | [diff] [blame] | 1 | //===- MRegisterInfo.cpp - Target Register Information Implementation -----===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // 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 Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9208bbf | 2002-12-17 04:03:08 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements the MRegisterInfo interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jim Laskey | 6b59a36 | 2006-08-03 17:27:09 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 9208bbf | 2002-12-17 04:03:08 +0000 | [diff] [blame] | 15 | #include "llvm/Target/MRegisterInfo.h" |
Jim Laskey | 6b59a36 | 2006-08-03 17:27:09 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetFrameInfo.h" |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFunction.h" |
| 18 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 19 | #include "llvm/CodeGen/MachineLocation.h" |
Evan Cheng | 61de82d | 2007-02-15 05:59:24 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/BitVector.h" |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 20ea062 | 2006-02-01 18:10:56 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 0f21fd5 | 2005-09-30 17:49:27 +0000 | [diff] [blame] | 24 | MRegisterInfo::MRegisterInfo(const TargetRegisterDesc *D, unsigned NR, |
Chris Lattner | 3ad7642 | 2002-12-28 20:34:18 +0000 | [diff] [blame] | 25 | regclass_iterator RCB, regclass_iterator RCE, |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 26 | int CFSO, int CFDO) |
Chris Lattner | 9208bbf | 2002-12-17 04:03:08 +0000 | [diff] [blame] | 27 | : Desc(D), NumRegs(NR), RegClassBegin(RCB), RegClassEnd(RCE) { |
| 28 | assert(NumRegs < FirstVirtualRegister && |
| 29 | "Target has too many physical registers!"); |
| 30 | |
Chris Lattner | 3ad7642 | 2002-12-28 20:34:18 +0000 | [diff] [blame] | 31 | CallFrameSetupOpcode = CFSO; |
| 32 | CallFrameDestroyOpcode = CFDO; |
Chris Lattner | 9208bbf | 2002-12-17 04:03:08 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Nate Begeman | 0aafc32 | 2004-10-27 06:00:53 +0000 | [diff] [blame] | 35 | MRegisterInfo::~MRegisterInfo() {} |
| 36 | |
Evan Cheng | eff03db | 2007-04-17 20:23:34 +0000 | [diff] [blame^] | 37 | BitVector MRegisterInfo::getAllocatableSet(MachineFunction &MF, |
| 38 | const TargetRegisterClass *RC) const { |
Evan Cheng | 61de82d | 2007-02-15 05:59:24 +0000 | [diff] [blame] | 39 | BitVector Allocatable(NumRegs); |
Alkis Evlogimenos | bb4bdf4 | 2004-08-26 22:21:04 +0000 | [diff] [blame] | 40 | for (MRegisterInfo::regclass_iterator I = regclass_begin(), |
| 41 | E = regclass_end(); I != E; ++I) { |
Evan Cheng | eff03db | 2007-04-17 20:23:34 +0000 | [diff] [blame^] | 42 | 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 Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 47 | Allocatable.set(*I); |
Alkis Evlogimenos | bb4bdf4 | 2004-08-26 22:21:04 +0000 | [diff] [blame] | 48 | } |
| 49 | return Allocatable; |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 50 | } |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 51 | |
| 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. |
| 56 | void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index, |
| 57 | MachineLocation &ML) const { |
Jim Laskey | 6b59a36 | 2006-08-03 17:27:09 +0000 | [diff] [blame] | 58 | const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo(); |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 59 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 60 | ML.set(getFrameRegister(MF), |
Jim Laskey | 6b59a36 | 2006-08-03 17:27:09 +0000 | [diff] [blame] | 61 | MFI->getObjectOffset(Index) + |
| 62 | MFI->getStackSize() - |
Jim Laskey | 9dea41d | 2006-11-17 21:19:15 +0000 | [diff] [blame] | 63 | TFI.getOffsetOfLocalArea() + |
| 64 | MFI->getOffsetAdjustment()); |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 65 | } |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 66 | |
| 67 | /// getInitialFrameState - Returns a list of machine moves that are assumed |
| 68 | /// on entry to a function. |
| 69 | void |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 70 | MRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const { |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 71 | // Default is to do nothing. |
| 72 | } |
| 73 | |