From de2a14c72483d77aa6d2744720005c82832144f3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 22 Jan 2010 23:18:42 +0000 Subject: [PATCH] move uleb printing from asmprinter to dwarfprinter, mcize, cleanup and eliminate a bunch more uses of "EOL". llvm-svn: 94250 --- include/llvm/CodeGen/AsmPrinter.h | 11 ----- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 29 ----------- lib/CodeGen/AsmPrinter/DIE.cpp | 28 ++++++----- lib/CodeGen/AsmPrinter/DIE.h | 2 +- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 39 ++++++--------- lib/CodeGen/AsmPrinter/DwarfException.cpp | 43 +++++------------ lib/CodeGen/AsmPrinter/DwarfPrinter.cpp | 59 +++++++++++++---------- lib/CodeGen/AsmPrinter/DwarfPrinter.h | 7 ++- 8 files changed, 83 insertions(+), 135 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 1f5e153d7d9..7dc89d228fa 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -245,13 +245,6 @@ namespace llvm { bool EmitSpecialLLVMGlobal(const GlobalVariable *GV); public: - //===------------------------------------------------------------------===// - /// LEB 128 number encoding. - - /// PrintULEB128 - Print a series of hexidecimal values(separated by commas) - /// representing an unsigned leb128 value. - void PrintULEB128(unsigned Value) const; - //===------------------------------------------------------------------===// // Emission and print routines // @@ -260,10 +253,6 @@ namespace llvm { /// then it will be printed first. Comments should not contain '\n'. void EOL(const Twine &Comment) const; - /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an - /// unsigned leb128 value. - void EmitULEB128Bytes(unsigned Value) const; - /// EmitInt8 - Emit a byte directive and value. /// void EmitInt8(int Value) const; diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index bf3d4241e3b..d8f89034e5e 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -655,24 +655,6 @@ void AsmPrinter::EmitXXStructorList(Constant *List) { } } - -//===----------------------------------------------------------------------===// -/// LEB 128 number encoding. - -/// PrintULEB128 - Print a series of hexadecimal values (separated by commas) -/// representing an unsigned leb128 value. -void AsmPrinter::PrintULEB128(unsigned Value) const { - do { - unsigned char Byte = static_cast(Value & 0x7f); - Value >>= 7; - if (Value) Byte |= 0x80; - O << "0x"; - O.write_hex(Byte); - if (Value) O << ", "; - } while (Value); -} - - //===--------------------------------------------------------------------===// // Emission and print routines // @@ -687,17 +669,6 @@ void AsmPrinter::EOL(const Twine &Comment) const { O << '\n'; } -/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an -/// unsigned leb128 value. -void AsmPrinter::EmitULEB128Bytes(unsigned Value) const { - if (MAI->hasLEB128()) { - O << "\t.uleb128\t" << Value; - } else { - O << MAI->getData8bitsDirective(); - PrintULEB128(Value); - } -} - /// EmitInt8 - Emit a byte directive and value. /// void AsmPrinter::EmitInt8(int Value) const { diff --git a/lib/CodeGen/AsmPrinter/DIE.cpp b/lib/CodeGen/AsmPrinter/DIE.cpp index 131aa087ca2..3bdc50d8939 100644 --- a/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/lib/CodeGen/AsmPrinter/DIE.cpp @@ -53,31 +53,33 @@ void DIEAbbrev::Profile(FoldingSetNodeID &ID) const { /// Emit - Print the abbreviation using the specified asm printer. /// -void DIEAbbrev::Emit(const AsmPrinter *Asm) const { +void DIEAbbrev::Emit(const DwarfPrinter *DP) const { // Emit its Dwarf tag type. - Asm->EmitULEB128Bytes(Tag); - Asm->EOL(dwarf::TagString(Tag)); + // FIXME: Doing work even in non-asm-verbose runs. + DP->EmitULEB128(Tag, dwarf::TagString(Tag)); // Emit whether it has children DIEs. - Asm->EmitULEB128Bytes(ChildrenFlag); - Asm->EOL(dwarf::ChildrenString(ChildrenFlag)); + // FIXME: Doing work even in non-asm-verbose runs. + DP->EmitULEB128(ChildrenFlag, dwarf::ChildrenString(ChildrenFlag)); // For each attribute description. for (unsigned i = 0, N = Data.size(); i < N; ++i) { const DIEAbbrevData &AttrData = Data[i]; // Emit attribute type. - Asm->EmitULEB128Bytes(AttrData.getAttribute()); - Asm->EOL(dwarf::AttributeString(AttrData.getAttribute())); + // FIXME: Doing work even in non-asm-verbose runs. + DP->EmitULEB128(AttrData.getAttribute(), + dwarf::AttributeString(AttrData.getAttribute())); // Emit form type. - Asm->EmitULEB128Bytes(AttrData.getForm()); - Asm->EOL(dwarf::FormEncodingString(AttrData.getForm())); + // FIXME: Doing work even in non-asm-verbose runs. + DP->EmitULEB128(AttrData.getForm(), + dwarf::FormEncodingString(AttrData.getForm())); } // Mark end of abbreviation. - Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(1)"); - Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(2)"); + DP->EmitULEB128(0, "EOM(1)"); + DP->EmitULEB128(0, "EOM(2)"); } #ifndef NDEBUG @@ -199,7 +201,7 @@ void DIEInteger::EmitValue(DwarfPrinter *D, unsigned Form) const { case dwarf::DW_FORM_data4: Size = 4; break; case dwarf::DW_FORM_ref8: // Fall thru case dwarf::DW_FORM_data8: Size = 8; break; - case dwarf::DW_FORM_udata: Asm->EmitULEB128Bytes(Integer); return; + case dwarf::DW_FORM_udata: D->EmitULEB128(Integer); return; case dwarf::DW_FORM_sdata: D->EmitSLEB128(Integer, ""); return; default: llvm_unreachable("DIE Value form not supported yet"); } @@ -395,7 +397,7 @@ void DIEBlock::EmitValue(DwarfPrinter *D, unsigned Form) const { case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break; case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break; case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break; - case dwarf::DW_FORM_block: Asm->EmitULEB128Bytes(Size); break; + case dwarf::DW_FORM_block: D->EmitULEB128(Size); break; default: llvm_unreachable("Improper form for block"); break; } diff --git a/lib/CodeGen/AsmPrinter/DIE.h b/lib/CodeGen/AsmPrinter/DIE.h index 2a03dee4b1d..323286ded18 100644 --- a/lib/CodeGen/AsmPrinter/DIE.h +++ b/lib/CodeGen/AsmPrinter/DIE.h @@ -101,7 +101,7 @@ namespace llvm { /// Emit - Print the abbreviation using the specified asm printer. /// - void Emit(const AsmPrinter *Asm) const; + void Emit(const DwarfPrinter *Asm) const; #ifndef NDEBUG void print(raw_ostream &O); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index a9045bd5d2b..86f6adee181 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2350,12 +2350,12 @@ void DwarfDebug::emitDIE(DIE *Die) { Asm->O << '\n'; // Emit the code (index) for the abbreviation. - Asm->EmitULEB128Bytes(AbbrevNumber); - - Asm->EOL("Abbrev [" + Twine(AbbrevNumber) + "] 0x" + - Twine::utohexstr(Die->getOffset()) + ":0x" + - Twine::utohexstr(Die->getSize()) + " " + - dwarf::TagString(Abbrev->getTag())); + if (Asm->VerboseAsm) + Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" + + Twine::utohexstr(Die->getOffset()) + ":0x" + + Twine::utohexstr(Die->getSize()) + " " + + dwarf::TagString(Abbrev->getTag())); + EmitULEB128(AbbrevNumber); SmallVector &Values = Die->getValues(); const SmallVector &AbbrevData = Abbrev->getData(); @@ -2448,16 +2448,15 @@ void DwarfDebug::emitAbbreviations() const { const DIEAbbrev *Abbrev = Abbreviations[i]; // Emit the abbrevations code (base 1 index.) - Asm->EmitULEB128Bytes(Abbrev->getNumber()); - Asm->EOL("Abbreviation Code"); + EmitULEB128(Abbrev->getNumber(), "Abbreviation Code"); // Emit the abbreviations data. - Abbrev->Emit(Asm); + Abbrev->Emit(this); Asm->O << '\n'; } // Mark end of abbreviations. - Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)"); + EmitULEB128(0, "EOM(3)"); EmitLabel("abbrev_end", 0); Asm->O << '\n'; @@ -2476,10 +2475,8 @@ void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { // Mark end of matrix. Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence"); - Asm->EmitULEB128Bytes(1); - Asm->O << '\n'; Asm->EmitInt8(1); - Asm->O << '\n'; + Asm->EmitInt8(1); } /// emitDebugLines - Emit source line information. @@ -2545,12 +2542,9 @@ void DwarfDebug::emitDebugLines() { std::pair Id = getSourceDirectoryAndFileIds(SI); Asm->EmitString(getSourceFileName(Id.second)); Asm->EOL("Source"); - Asm->EmitULEB128Bytes(Id.first); - Asm->EOL("Directory #"); - Asm->EmitULEB128Bytes(0); - Asm->EOL("Mod date"); - Asm->EmitULEB128Bytes(0); - Asm->EOL("File size"); + EmitULEB128(Id.first, "Directory #"); + EmitULEB128(0, "Mod date"); + EmitULEB128(0, "File size"); } Asm->EmitInt8(0); Asm->EOL("End of files"); @@ -2604,7 +2598,7 @@ void DwarfDebug::emitDebugLines() { if (Source != LineInfo.getSourceID()) { Source = LineInfo.getSourceID(); Asm->EmitInt8(dwarf::DW_LNS_set_file); Asm->EOL("DW_LNS_set_file"); - Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source"); + EmitULEB128(Source, "New Source"); } // If change of line. @@ -2673,8 +2667,7 @@ void DwarfDebug::emitCommonDebugFrame() { Asm->EOL("CIE Version"); Asm->EmitString(""); Asm->EOL("CIE Augmentation"); - Asm->EmitULEB128Bytes(1); - Asm->EOL("CIE Code Alignment Factor"); + EmitULEB128(1, "CIE Code Alignment Factor"); EmitSLEB128(stackGrowth, "CIE Data Alignment Factor"); Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false)); Asm->EOL("CIE RA Column"); @@ -2941,7 +2934,7 @@ void DwarfDebug::emitDebugInlineInfo() { EmitSectionOffset("string", "section_str", StringPool.idFor(Name), false, true); Asm->EOL("Function name"); - Asm->EmitULEB128Bytes(Labels.size()); Asm->EOL("Inline count"); + EmitULEB128(Labels.size(), "Inline count"); for (SmallVector::iterator LI = Labels.begin(), LE = Labels.end(); LI != LE; ++LI) { diff --git a/lib/CodeGen/AsmPrinter/DwarfException.cpp b/lib/CodeGen/AsmPrinter/DwarfException.cpp index 0dfb6b6d79c..d1ad4d88f1f 100644 --- a/lib/CodeGen/AsmPrinter/DwarfException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfException.cpp @@ -175,15 +175,12 @@ void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { Asm->EOL("CIE Augmentation"); // Round out reader. - Asm->EmitULEB128Bytes(1); - Asm->EOL("CIE Code Alignment Factor"); + EmitULEB128(1, "CIE Code Alignment Factor"); EmitSLEB128(stackGrowth, "CIE Data Alignment Factor"); Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true)); Asm->EOL("CIE Return Address Column"); - Asm->EmitULEB128Bytes(AugmentationSize); - Asm->EOL("Augmentation Size"); - + EmitULEB128(AugmentationSize, "Augmentation Size"); EmitEncodingByte(PerEncoding, "Personality"); // If there is a personality, we need to indicate the function's location. @@ -277,16 +274,14 @@ void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) { if (MMI->getPersonalities()[0] != NULL) { if (Asm->TM.getLSDAEncoding() != DwarfLSDAEncoding::EightByte) { - Asm->EmitULEB128Bytes(4); - Asm->EOL("Augmentation size"); + EmitULEB128(4, "Augmentation size"); if (EHFrameInfo.hasLandingPads) EmitReference("exception", EHFrameInfo.Number, true, true); else Asm->OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); } else { - Asm->EmitULEB128Bytes(TD->getPointerSize()); - Asm->EOL("Augmentation size"); + EmitULEB128(TD->getPointerSize(), "Augmentation size"); if (EHFrameInfo.hasLandingPads) { EmitReference("exception", EHFrameInfo.Number, true, false); @@ -298,8 +293,7 @@ void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) { Asm->EOL("Language Specific Data Area"); } else { - Asm->EmitULEB128Bytes(0); - Asm->EOL("Augmentation size"); + EmitULEB128(0, "Augmentation size"); } // Indicate locations of function specific callee saved registers in frame. @@ -782,16 +776,13 @@ void DwarfException::EmitExceptionTable() { EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart"); EmitEncodingByte(TTypeFormat, "@TType"); - if (HaveTTData) { - Asm->EmitULEB128Bytes(TyOffset); - Asm->EOL("@TType base offset"); - } + if (HaveTTData) + EmitULEB128(TyOffset, "@TType base offset"); // SjLj Exception handling if (IsSJLJ) { EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); - Asm->EmitULEB128Bytes(SizeSites); - Asm->EOL("Call site table length"); + EmitULEB128(SizeSites, "Call site table length"); // Emit the landing pad site information. unsigned idx = 0; @@ -801,14 +792,12 @@ void DwarfException::EmitExceptionTable() { // Offset of the landing pad, counted in 16-byte bundles relative to the // @LPStart address. - Asm->EmitULEB128Bytes(idx); - Asm->EOL("Landing pad"); + EmitULEB128(idx, "Landing pad"); // Offset of the first associated action record, relative to the start of // the action table. This value is biased by 1 (1 indicates the start of // the action table), and 0 indicates that there are no actions. - Asm->EmitULEB128Bytes(S.Action); - Asm->EOL("Action"); + EmitULEB128(S.Action, "Action"); } } else { // DWARF Exception handling @@ -834,8 +823,7 @@ void DwarfException::EmitExceptionTable() { // Emit the landing pad call site table. EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); - Asm->EmitULEB128Bytes(SizeSites); - Asm->EOL("Call site table size"); + EmitULEB128(SizeSites, "Call site table size"); for (SmallVectorImpl::const_iterator I = CallSites.begin(), E = CallSites.end(); I != E; ++I) { @@ -879,8 +867,7 @@ void DwarfException::EmitExceptionTable() { // Offset of the first associated action record, relative to the start of // the action table. This value is biased by 1 (1 indicates the start of // the action table), and 0 indicates that there are no actions. - Asm->EmitULEB128Bytes(S.Action); - Asm->EOL("Action"); + EmitULEB128(S.Action, "Action"); } } @@ -921,11 +908,7 @@ void DwarfException::EmitExceptionTable() { for (std::vector::const_iterator I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) { unsigned TypeID = *I; - Asm->EmitULEB128Bytes(TypeID); - if (TypeID != 0) - Asm->EOL("Exception specification"); - else - Asm->O << '\n'; + EmitULEB128(TypeID, TypeID != 0 ? "Exception specification" : 0); } Asm->EmitAlignment(2, 0, 0, false); diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp index df8b2d2425f..0f6636217a2 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp @@ -85,9 +85,18 @@ void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) { Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/); } -/// PrintSLEB128 - Print a series of hexadecimal values (separated by commas) -/// representing a signed leb128 value. -static void PrintSLEB128(MCStreamer &O, int Value) { +/// EmitSLEB128 - emit the specified signed leb128 value. +void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const { + if (Asm->VerboseAsm && Desc) + Asm->OutStreamer.AddComment(Desc); + + if (MAI->hasLEB128()) { + O << "\t.sleb128\t" << Value; + Asm->OutStreamer.AddBlankLine(); + return; + } + + // If we don't have .sleb128, emit as .bytes. int Sign = Value >> (8 * sizeof(Value) - 1); bool IsMore; @@ -97,25 +106,31 @@ static void PrintSLEB128(MCStreamer &O, int Value) { IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; if (IsMore) Byte |= 0x80; - O.EmitIntValue(Byte, 1, /*addrspace*/0); + Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0); } while (IsMore); } -/// EmitSLEB128 - print the specified signed leb128 value. -void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const { +/// EmitULEB128 - emit the specified signed leb128 value. +void DwarfPrinter::EmitULEB128(unsigned Value, const char *Desc) const { if (Asm->VerboseAsm && Desc) Asm->OutStreamer.AddComment(Desc); - + if (MAI->hasLEB128()) { - O << "\t.sleb128\t" << Value; + O << "\t.uleb128\t" << Value; Asm->OutStreamer.AddBlankLine(); - } else { - PrintSLEB128(Asm->OutStreamer, Value); + return; } + + // If we don't have .uleb128, emit as .bytes. + do { + unsigned char Byte = static_cast(Value & 0x7f); + Value >>= 7; + if (Value) Byte |= 0x80; + Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0); + } while (Value); } - /// PrintLabelName - Print label name in form used by Dwarf writer. /// void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number) const { @@ -267,14 +282,11 @@ void DwarfPrinter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, } else { Asm->EmitInt8(dwarf::DW_CFA_def_cfa); Asm->EOL("DW_CFA_def_cfa"); - Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), isEH)); - Asm->EOL("Register"); + EmitULEB128(RI->getDwarfRegNum(Src.getReg(), isEH), "Register"); } int Offset = -Src.getOffset(); - - Asm->EmitULEB128Bytes(Offset); - Asm->EOL("Offset"); + EmitULEB128(Offset, "Offset"); } else { llvm_unreachable("Machine move not supported yet."); } @@ -283,8 +295,7 @@ void DwarfPrinter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, if (Dst.isReg()) { Asm->EmitInt8(dwarf::DW_CFA_def_cfa_register); Asm->EOL("DW_CFA_def_cfa_register"); - Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), isEH)); - Asm->EOL("Register"); + EmitULEB128(RI->getDwarfRegNum(Dst.getReg(), isEH), "Register"); } else { llvm_unreachable("Machine move not supported yet."); } @@ -295,21 +306,17 @@ void DwarfPrinter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, if (Offset < 0) { Asm->EmitInt8(dwarf::DW_CFA_offset_extended_sf); Asm->EOL("DW_CFA_offset_extended_sf"); - Asm->EmitULEB128Bytes(Reg); - Asm->EOL("Reg"); + EmitULEB128(Reg, "Reg"); EmitSLEB128(Offset, "Offset"); } else if (Reg < 64) { Asm->EmitInt8(dwarf::DW_CFA_offset + Reg); Asm->EOL("DW_CFA_offset + Reg (" + Twine(Reg) + ")"); - Asm->EmitULEB128Bytes(Offset); - Asm->EOL("Offset"); + EmitULEB128(Offset, "Offset"); } else { Asm->EmitInt8(dwarf::DW_CFA_offset_extended); Asm->EOL("DW_CFA_offset_extended"); - Asm->EmitULEB128Bytes(Reg); - Asm->EOL("Reg"); - Asm->EmitULEB128Bytes(Offset); - Asm->EOL("Offset"); + EmitULEB128(Reg, "Reg"); + EmitULEB128(Offset, "Offset"); } } } diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.h b/lib/CodeGen/AsmPrinter/DwarfPrinter.h index bc285c7cad5..2d4564531f1 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.h +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.h @@ -91,9 +91,12 @@ public: /// specifying (e.g. "LSDA"). void EmitEncodingByte(unsigned Val, const char *Desc); - /// EmitSLEB128 - print the specified signed leb128 value. + /// EmitSLEB128 - emit the specified signed leb128 value. void EmitSLEB128(int Value, const char *Desc) const; - + + /// EmitULEB128 - emit the specified unsigned leb128 value. + void EmitULEB128(unsigned Value, const char *Desc = 0) const; + /// PrintLabelName - Print label name in form used by Dwarf writer. ///