From 0744c47856ed6d7b772fdd2055d0fd51f4789388 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 4 Apr 2010 23:41:46 +0000 Subject: [PATCH] Move EmitFrameMoves into AsmPrinter. llvm-svn: 100371 --- include/llvm/CodeGen/AsmPrinter.h | 12 +++- lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp | 82 +++++++++++++++++++++- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 4 +- lib/CodeGen/AsmPrinter/DwarfException.cpp | 4 +- lib/CodeGen/AsmPrinter/DwarfPrinter.cpp | 70 ------------------ lib/CodeGen/AsmPrinter/DwarfPrinter.h | 4 -- 6 files changed, 96 insertions(+), 80 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 06c2f7546a8..92a9a08dbe7 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -41,6 +41,7 @@ namespace llvm { class MachineConstantPoolValue; class MachineJumpTableInfo; class MachineModuleInfo; + class MachineMove; class MCInst; class MCContext; class MCSection; @@ -341,7 +342,7 @@ namespace llvm { /// encoding. If verbose assembly output is enabled, we output comments /// describing the encoding. Desc is a string saying what the encoding is /// specifying (e.g. "LSDA"). - void EmitEncodingByte(unsigned Val, const char *Desc = 0); + void EmitEncodingByte(unsigned Val, const char *Desc = 0) const; /// GetSizeOfEncodedValue - Return the size of the encoding in bytes. unsigned GetSizeOfEncodedValue(unsigned Encoding) const; @@ -361,6 +362,15 @@ namespace llvm { void EmitSectionOffset(const MCSymbol *Label, const MCSymbol *SectionLabel) const; + //===------------------------------------------------------------------===// + // Dwarf Lowering Routines + //===------------------------------------------------------------------===// + + /// EmitFrameMoves - Emit frame instructions to describe the layout of the + /// frame. + void EmitFrameMoves(const std::vector &Moves, + MCSymbol *BaseLabel, bool isEH) const; + //===------------------------------------------------------------------===// // Inline Asm Support diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp index 9e7f182d821..b310578584b 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp @@ -13,17 +13,24 @@ #define DEBUG_TYPE "asm-printer" #include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/MachineLocation.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetFrameInfo.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Dwarf.h" using namespace llvm; +//===----------------------------------------------------------------------===// +// Dwarf Emission Helper Routines +//===----------------------------------------------------------------------===// + /// EmitSLEB128 - emit the specified signed leb128 value. void AsmPrinter::EmitSLEB128(int Value, const char *Desc) const { if (isVerbose() && Desc) @@ -118,7 +125,7 @@ static const char *DecodeDWARFEncoding(unsigned Encoding) { /// encoding. If verbose assembly output is enabled, we output comments /// describing the encoding. Desc is an optional string saying what the /// encoding is specifying (e.g. "LSDA"). -void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) { +void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const { if (isVerbose()) { if (Desc != 0) OutStreamer.AddComment(Twine(Desc)+" Encoding = " + @@ -196,4 +203,77 @@ void AsmPrinter::EmitSectionOffset(const MCSymbol *Label, EmitLabelDifference(Label, SectionLabel, 4); } +//===----------------------------------------------------------------------===// +// Dwarf Lowering Routines +//===----------------------------------------------------------------------===// + +/// EmitFrameMoves - Emit frame instructions to describe the layout of the +/// frame. +void AsmPrinter::EmitFrameMoves(const std::vector &Moves, + MCSymbol *BaseLabel, bool isEH) const { + const TargetRegisterInfo *RI = TM.getRegisterInfo(); + + int stackGrowth = TM.getTargetData()->getPointerSize(); + if (TM.getFrameInfo()->getStackGrowthDirection() != + TargetFrameInfo::StackGrowsUp) + stackGrowth *= -1; + + for (unsigned i = 0, N = Moves.size(); i < N; ++i) { + const MachineMove &Move = Moves[i]; + MCSymbol *Label = Move.getLabel(); + // Throw out move if the label is invalid. + if (Label && !Label->isDefined()) continue; // Not emitted, in dead code. + + const MachineLocation &Dst = Move.getDestination(); + const MachineLocation &Src = Move.getSource(); + + // Advance row if new location. + if (BaseLabel && Label) { + MCSymbol *ThisSym = Label; + if (ThisSym != BaseLabel) { + EmitCFAByte(dwarf::DW_CFA_advance_loc4); + EmitLabelDifference(ThisSym, BaseLabel, 4); + BaseLabel = ThisSym; + } + } + + // If advancing cfa. + if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) { + assert(!Src.isReg() && "Machine move not supported yet."); + + if (Src.getReg() == MachineLocation::VirtualFP) { + EmitCFAByte(dwarf::DW_CFA_def_cfa_offset); + } else { + EmitCFAByte(dwarf::DW_CFA_def_cfa); + EmitULEB128(RI->getDwarfRegNum(Src.getReg(), isEH), "Register"); + } + + EmitULEB128(-Src.getOffset(), "Offset"); + continue; + } + + if (Src.isReg() && Src.getReg() == MachineLocation::VirtualFP) { + assert(Dst.isReg() && "Machine move not supported yet."); + EmitCFAByte(dwarf::DW_CFA_def_cfa_register); + EmitULEB128(RI->getDwarfRegNum(Dst.getReg(), isEH), "Register"); + continue; + } + + unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH); + int Offset = Dst.getOffset() / stackGrowth; + + if (Offset < 0) { + EmitCFAByte(dwarf::DW_CFA_offset_extended_sf); + EmitULEB128(Reg, "Reg"); + EmitSLEB128(Offset, "Offset"); + } else if (Reg < 64) { + EmitCFAByte(dwarf::DW_CFA_offset + Reg); + EmitULEB128(Offset, "Offset"); + } else { + EmitCFAByte(dwarf::DW_CFA_offset_extended); + EmitULEB128(Reg, "Reg"); + EmitULEB128(Offset, "Offset"); + } + } +} diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index aae643776bd..29239d1505a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2852,7 +2852,7 @@ void DwarfDebug::emitCommonDebugFrame() { std::vector Moves; RI->getInitialFrameState(Moves); - EmitFrameMoves(0, Moves, false); + Asm->EmitFrameMoves(Moves, 0, false); Asm->EmitAlignment(2, 0, 0, false); Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_end")); @@ -2893,7 +2893,7 @@ emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) { Asm->EmitLabelDifference(Asm->GetTempSymbol("func_end",DebugFrameInfo.Number), FuncBeginSym, TD->getPointerSize()); - EmitFrameMoves(FuncBeginSym, DebugFrameInfo.Moves, false); + Asm->EmitFrameMoves(DebugFrameInfo.Moves, FuncBeginSym, false); Asm->EmitAlignment(2, 0, 0, false); Asm->OutStreamer.EmitLabel(DebugFrameEnd); diff --git a/lib/CodeGen/AsmPrinter/DwarfException.cpp b/lib/CodeGen/AsmPrinter/DwarfException.cpp index b29e675afaa..114dbc9b1f9 100644 --- a/lib/CodeGen/AsmPrinter/DwarfException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfException.cpp @@ -151,7 +151,7 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { // Indicate locations of general callee saved registers in frame. std::vector Moves; RI->getInitialFrameState(Moves); - EmitFrameMoves(0, Moves, true); + Asm->EmitFrameMoves(Moves, 0, true); // On Darwin the linker honors the alignment of eh_frame, which means it must // be 8-byte on 64-bit targets to match what gcc does. Otherwise you get @@ -253,7 +253,7 @@ void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) { } // Indicate locations of function specific callee saved registers in frame. - EmitFrameMoves(EHFuncBeginSym, EHFrameInfo.Moves, true); + Asm->EmitFrameMoves(EHFrameInfo.Moves, EHFuncBeginSym, true); // On Darwin the linker honors the alignment of eh_frame, which means it // must be 8-byte on 64-bit targets to match what gcc does. Otherwise you diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp index 870dab78d07..1d7926a633a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp @@ -37,73 +37,3 @@ DwarfPrinter::DwarfPrinter(AsmPrinter *A) RI(Asm->TM.getRegisterInfo()), M(NULL), MF(NULL), MMI(NULL), SubprogramCount(0) { } - - -/// EmitFrameMoves - Emit frame instructions to describe the layout of the -/// frame. -void DwarfPrinter::EmitFrameMoves(MCSymbol *BaseLabel, - const std::vector &Moves, - bool isEH) { - int stackGrowth = TD->getPointerSize(); - if (Asm->TM.getFrameInfo()->getStackGrowthDirection() != - TargetFrameInfo::StackGrowsUp) - stackGrowth *= -1; - - for (unsigned i = 0, N = Moves.size(); i < N; ++i) { - const MachineMove &Move = Moves[i]; - MCSymbol *Label = Move.getLabel(); - // Throw out move if the label is invalid. - if (Label && !Label->isDefined()) continue; // Not emitted, in dead code. - - const MachineLocation &Dst = Move.getDestination(); - const MachineLocation &Src = Move.getSource(); - - // Advance row if new location. - if (BaseLabel && Label) { - MCSymbol *ThisSym = Label; - if (ThisSym != BaseLabel) { - Asm->EmitCFAByte(dwarf::DW_CFA_advance_loc4); - Asm->EmitLabelDifference(ThisSym, BaseLabel, 4); - BaseLabel = ThisSym; - } - } - - // If advancing cfa. - if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) { - assert(!Src.isReg() && "Machine move not supported yet."); - - if (Src.getReg() == MachineLocation::VirtualFP) { - Asm->EmitCFAByte(dwarf::DW_CFA_def_cfa_offset); - } else { - Asm->EmitCFAByte(dwarf::DW_CFA_def_cfa); - Asm->EmitULEB128(RI->getDwarfRegNum(Src.getReg(), isEH), "Register"); - } - - Asm->EmitULEB128(-Src.getOffset(), "Offset"); - continue; - } - - if (Src.isReg() && Src.getReg() == MachineLocation::VirtualFP) { - assert(Dst.isReg() && "Machine move not supported yet."); - Asm->EmitCFAByte(dwarf::DW_CFA_def_cfa_register); - Asm->EmitULEB128(RI->getDwarfRegNum(Dst.getReg(), isEH), "Register"); - continue; - } - - unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH); - int Offset = Dst.getOffset() / stackGrowth; - - if (Offset < 0) { - Asm->EmitCFAByte(dwarf::DW_CFA_offset_extended_sf); - Asm->EmitULEB128(Reg, "Reg"); - Asm->EmitSLEB128(Offset, "Offset"); - } else if (Reg < 64) { - Asm->EmitCFAByte(dwarf::DW_CFA_offset + Reg); - Asm->EmitULEB128(Offset, "Offset"); - } else { - Asm->EmitCFAByte(dwarf::DW_CFA_offset_extended); - Asm->EmitULEB128(Reg, "Reg"); - Asm->EmitULEB128(Offset, "Offset"); - } - } -} diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.h b/lib/CodeGen/AsmPrinter/DwarfPrinter.h index 3b379807217..2ddb6742805 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.h +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.h @@ -74,10 +74,6 @@ public: const MCAsmInfo *getMCAsmInfo() const { return MAI; } const TargetData *getTargetData() const { return TD; } - /// EmitFrameMoves - Emit frame instructions to describe the layout of the - /// frame. - void EmitFrameMoves(MCSymbol *BaseLabel, - const std::vector &Moves, bool isEH); }; } // end llvm namespace