From a99791886d5d4af2b900cd8cc1c9ed1677b6f0f4 Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Tue, 28 Mar 2006 13:48:33 +0000 Subject: [PATCH] Expose base register for DwarfWriter. Refactor code accordingly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27225 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/MRegisterInfo.h | 12 +++++++++++- lib/Target/Alpha/AlphaRegisterInfo.cpp | 12 ++---------- lib/Target/Alpha/AlphaRegisterInfo.h | 4 ++-- lib/Target/IA64/IA64RegisterInfo.cpp | 13 ++----------- lib/Target/IA64/IA64RegisterInfo.h | 3 ++- lib/Target/MRegisterInfo.cpp | 16 ++++++++++++++++ lib/Target/PowerPC/PPCRegisterInfo.cpp | 11 ++--------- lib/Target/PowerPC/PPCRegisterInfo.h | 4 ++-- lib/Target/Sparc/SparcRegisterInfo.cpp | 11 ++--------- lib/Target/Sparc/SparcRegisterInfo.h | 4 ++-- lib/Target/SparcV9/SparcV9RegisterInfo.cpp | 4 ++-- lib/Target/SparcV9/SparcV9RegisterInfo.h | 5 +++-- lib/Target/X86/X86RegisterInfo.cpp | 11 ++--------- lib/Target/X86/X86RegisterInfo.h | 4 ++-- 14 files changed, 52 insertions(+), 62 deletions(-) diff --git a/include/llvm/Target/MRegisterInfo.h b/include/llvm/Target/MRegisterInfo.h index 21fc41795a2..e69661b2282 100644 --- a/include/llvm/Target/MRegisterInfo.h +++ b/include/llvm/Target/MRegisterInfo.h @@ -343,10 +343,20 @@ public: virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const = 0; + //===--------------------------------------------------------------------===// + /// Debug information queries. + + /// getFrameRegister - This method should return the register used as a base + /// for values allocated in the current stack frame. This value should be + /// returned as a dwarf register number (getDwarfRegNum.) + virtual unsigned getFrameRegister(MachineFunction &MF) const = 0; + /// getLocation - This method should return the actual location of a frame /// variable given the frame index. The location is returned in ML. + /// Subclasses should override this method for special handling of frame + /// variables and call MRegisterInfo::getLocation for the default action. virtual void getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const = 0; + MachineLocation &ML) const; }; // This is useful when building DenseMaps keyed on virtual registers diff --git a/lib/Target/Alpha/AlphaRegisterInfo.cpp b/lib/Target/Alpha/AlphaRegisterInfo.cpp index fee062f84c1..d2a398465b0 100644 --- a/lib/Target/Alpha/AlphaRegisterInfo.cpp +++ b/lib/Target/Alpha/AlphaRegisterInfo.cpp @@ -354,16 +354,8 @@ void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF, } } -void AlphaRegisterInfo::getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const { - assert(0 && "Needs to be defined for target"); - MachineFrameInfo *MFI = MF.getFrameInfo(); - bool FP = hasFP(MF); - - // FIXME - Needs to handle register variables. - // FIXME - Faking that llvm number is same as gcc numbering. - ML.set(getDwarfRegNum(FP ? Alpha::R15 : Alpha::R30), - MFI->getObjectOffset(Index) + MFI->getStackSize()); +unsigned AlphaRegisterInfo::getFrameRegister(MachineFunction &MF) const { + return getDwarfRegNum(hasFP(MF) ? Alpha::R15 : Alpha::R30); } #include "AlphaGenRegisterInfo.inc" diff --git a/lib/Target/Alpha/AlphaRegisterInfo.h b/lib/Target/Alpha/AlphaRegisterInfo.h index d07ee9006a9..161a8268568 100644 --- a/lib/Target/Alpha/AlphaRegisterInfo.h +++ b/lib/Target/Alpha/AlphaRegisterInfo.h @@ -53,8 +53,8 @@ struct AlphaRegisterInfo : public AlphaGenRegisterInfo { void emitPrologue(MachineFunction &MF) const; void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; - void getLocation(MachineFunction &MF, unsigned Index, MachineLocation &ML) const; - + // Debug information queries. + unsigned getFrameRegister(MachineFunction &MF) const; static std::string getPrettyName(unsigned reg); }; diff --git a/lib/Target/IA64/IA64RegisterInfo.cpp b/lib/Target/IA64/IA64RegisterInfo.cpp index c8d6f0fdf5f..b1e681d9b43 100644 --- a/lib/Target/IA64/IA64RegisterInfo.cpp +++ b/lib/Target/IA64/IA64RegisterInfo.cpp @@ -329,18 +329,9 @@ void IA64RegisterInfo::emitEpilogue(MachineFunction &MF, } -void IA64RegisterInfo::getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const { - assert(0 && "Needs to be defined for target"); - MachineFrameInfo *MFI = MF.getFrameInfo(); - bool FP = hasFP(MF); - - // FIXME - Needs to handle register variables. - // FIXME - Faking that llvm number is same as gcc numbering. - ML.set(getDwarfRegNum(FP ? IA64::r5 : IA64::r12), - MFI->getObjectOffset(Index) + MFI->getStackSize()); +unsigned IA64RegisterInfo::getFrameRegister(MachineFunction &MF) const { + return getDwarfRegNum(hasFP(MF) ? IA64::r5 : IA64::r12); } - #include "IA64GenRegisterInfo.inc" diff --git a/lib/Target/IA64/IA64RegisterInfo.h b/lib/Target/IA64/IA64RegisterInfo.h index d33a9e6c1d3..328b4155737 100644 --- a/lib/Target/IA64/IA64RegisterInfo.h +++ b/lib/Target/IA64/IA64RegisterInfo.h @@ -49,7 +49,8 @@ struct IA64RegisterInfo : public IA64GenRegisterInfo { void emitPrologue(MachineFunction &MF) const; void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; - void getLocation(MachineFunction &MF, unsigned Index, MachineLocation &ML) const; + // Debug information queries. + unsigned getFrameRegister(MachineFunction &MF) const; }; } // End llvm namespace diff --git a/lib/Target/MRegisterInfo.cpp b/lib/Target/MRegisterInfo.cpp index 790f95f081b..558783aedc4 100644 --- a/lib/Target/MRegisterInfo.cpp +++ b/lib/Target/MRegisterInfo.cpp @@ -12,6 +12,11 @@ //===----------------------------------------------------------------------===// #include "llvm/Target/MRegisterInfo.h" + +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFrameInfo.h" +#include "llvm/CodeGen/MachineLocation.h" + using namespace llvm; MRegisterInfo::MRegisterInfo(const TargetRegisterDesc *D, unsigned NR, @@ -38,3 +43,14 @@ std::vector MRegisterInfo::getAllocatableSet(MachineFunction &MF) const { } return Allocatable; } + +/// getLocation - This method should return the actual location of a frame +/// variable given the frame index. The location is returned in ML. +/// Subclasses should override this method for special handling of frame +/// variables and then call MRegisterInfo::getLocation for the default action. +void MRegisterInfo::getLocation(MachineFunction &MF, unsigned Index, + MachineLocation &ML) const { + MachineFrameInfo *MFI = MF.getFrameInfo(); + ML.set(getFrameRegister(MF), + MFI->getObjectOffset(Index) + MFI->getStackSize()); +} diff --git a/lib/Target/PowerPC/PPCRegisterInfo.cpp b/lib/Target/PowerPC/PPCRegisterInfo.cpp index 984d5e23fd8..679b233bc68 100644 --- a/lib/Target/PowerPC/PPCRegisterInfo.cpp +++ b/lib/Target/PowerPC/PPCRegisterInfo.cpp @@ -447,15 +447,8 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF, } } -void PPCRegisterInfo::getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const { - MachineFrameInfo *MFI = MF.getFrameInfo(); - bool FP = hasFP(MF); - - // FIXME - Needs to handle register variables. - // FIXME - Faking that llvm number is same as gcc numbering. - ML.set(getDwarfRegNum(FP ? PPC::R31 : PPC::R1), - MFI->getObjectOffset(Index) + MFI->getStackSize()); +unsigned PPCRegisterInfo::getFrameRegister(MachineFunction &MF) const { + return getDwarfRegNum(hasFP(MF) ? PPC::R31 : PPC::R1); } #include "PPCGenRegisterInfo.inc" diff --git a/lib/Target/PowerPC/PPCRegisterInfo.h b/lib/Target/PowerPC/PPCRegisterInfo.h index dce149bffce..d05bc70c11d 100644 --- a/lib/Target/PowerPC/PPCRegisterInfo.h +++ b/lib/Target/PowerPC/PPCRegisterInfo.h @@ -56,8 +56,8 @@ public: void emitPrologue(MachineFunction &MF) const; void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; - void getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const; + // Debug information queries. + unsigned getFrameRegister(MachineFunction &MF) const; }; } // end namespace llvm diff --git a/lib/Target/Sparc/SparcRegisterInfo.cpp b/lib/Target/Sparc/SparcRegisterInfo.cpp index cbeb87fa54e..44f3adce043 100644 --- a/lib/Target/Sparc/SparcRegisterInfo.cpp +++ b/lib/Target/Sparc/SparcRegisterInfo.cpp @@ -200,15 +200,8 @@ void SparcRegisterInfo::emitEpilogue(MachineFunction &MF, BuildMI(MBB, MBBI, SP::RESTORErr, 2, SP::G0).addReg(SP::G0).addReg(SP::G0); } -void SparcRegisterInfo::getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const { - assert(0 && "Needs to be defined for target"); - MachineFrameInfo *MFI = MF.getFrameInfo(); - - // FIXME - Needs to handle register variables. - // FIXME - Faking that llvm number is same as gcc numbering. - ML.set(getDwarfRegNum(SP::G1), - MFI->getObjectOffset(Index) + MFI->getStackSize()); +unsigned SparcRegisterInfo::getFrameRegister(MachineFunction &MF) const { + return getDwarfRegNum(SP::G1); } #include "SparcGenRegisterInfo.inc" diff --git a/lib/Target/Sparc/SparcRegisterInfo.h b/lib/Target/Sparc/SparcRegisterInfo.h index 53d3e6fdba0..d36b3c1eed0 100644 --- a/lib/Target/Sparc/SparcRegisterInfo.h +++ b/lib/Target/Sparc/SparcRegisterInfo.h @@ -57,8 +57,8 @@ struct SparcRegisterInfo : public SparcGenRegisterInfo { void emitPrologue(MachineFunction &MF) const; void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; - void getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const; + // Debug information queries. + unsigned getFrameRegister(MachineFunction &MF) const; }; } // end namespace llvm diff --git a/lib/Target/SparcV9/SparcV9RegisterInfo.cpp b/lib/Target/SparcV9/SparcV9RegisterInfo.cpp index db0b9fd95c7..267d69a4f76 100644 --- a/lib/Target/SparcV9/SparcV9RegisterInfo.cpp +++ b/lib/Target/SparcV9/SparcV9RegisterInfo.cpp @@ -318,7 +318,7 @@ void SparcV9RegisterInfo::emitEpilogue(MachineFunction &MF, } -void SparcV9RegisterInfo::getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const { +unsigned SparcV9RegisterInfo::getFrameRegister(MachineFunction &MF) const { abort (); + return 0; } diff --git a/lib/Target/SparcV9/SparcV9RegisterInfo.h b/lib/Target/SparcV9/SparcV9RegisterInfo.h index 4144b84dc57..6de47cbb629 100644 --- a/lib/Target/SparcV9/SparcV9RegisterInfo.h +++ b/lib/Target/SparcV9/SparcV9RegisterInfo.h @@ -44,8 +44,9 @@ struct SparcV9RegisterInfo : public MRegisterInfo { void eliminateFrameIndex (MachineBasicBlock::iterator MI) const; void emitPrologue (MachineFunction &MF) const; void emitEpilogue (MachineFunction &MF, MachineBasicBlock &MBB) const; - void getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const; + + // Debug information queries. + unsigned getFrameRegister(MachineFunction &MF) const; }; } // End llvm namespace diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 99e36eb3690..97d73cf05cf 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -686,15 +686,8 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, } } -void X86RegisterInfo::getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const { - MachineFrameInfo *MFI = MF.getFrameInfo(); - bool FP = hasFP(MF); - - // FIXME - Needs to handle register variables. - // FIXME - Hardcoding gcc numbering. - ML.set(getDwarfRegNum(FP ? X86::EBP : X86::ESP), - MFI->getObjectOffset(Index) + MFI->getStackSize()); +unsigned X86RegisterInfo::getFrameRegister(MachineFunction &MF) const { + return getDwarfRegNum(hasFP(MF) ? X86::EBP : X86::ESP); } #include "X86GenRegisterInfo.inc" diff --git a/lib/Target/X86/X86RegisterInfo.h b/lib/Target/X86/X86RegisterInfo.h index db0fbbb3aa3..998fb398d91 100644 --- a/lib/Target/X86/X86RegisterInfo.h +++ b/lib/Target/X86/X86RegisterInfo.h @@ -63,8 +63,8 @@ struct X86RegisterInfo : public X86GenRegisterInfo { void emitPrologue(MachineFunction &MF) const; void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; - void getLocation(MachineFunction &MF, unsigned Index, - MachineLocation &ML) const; + // Debug information queries. + unsigned getFrameRegister(MachineFunction &MF) const; }; } // End llvm namespace