From 0d50c7620d92762eaa5c9dedd07c94f5a6a19935 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 8 Mar 2010 23:58:37 +0000 Subject: [PATCH] move .set generation out of DwarfPrinter into AsmPrinter and MCize it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98010 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 8 +++++++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 29 ++++++++++++++++++++++++- lib/CodeGen/AsmPrinter/DwarfPrinter.cpp | 25 ++++----------------- lib/CodeGen/AsmPrinter/DwarfPrinter.h | 3 --- test/CodeGen/X86/aliases.ll | 2 +- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 8ade1bd64af..6187447597c 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -136,6 +136,7 @@ namespace llvm { mutable const MachineInstr *LastMI; mutable const Function *LastFn; mutable unsigned Counter; + mutable unsigned SetCounter; // Private state for processDebugLoc() mutable const MDNode *PrevDLT; @@ -275,6 +276,13 @@ namespace llvm { /// EmitInt64 - Emit a long long directive and value. /// void EmitInt64(uint64_t Value) const; + + + /// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size + /// in bytes of the directive is specified by Size and Hi/Lo specify the + /// labels. This implicitly uses .set if it is available. + void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, + unsigned Size) const; //===------------------------------------------------------------------===// diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index c0d92ffbbbc..5db2b0749d5 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -61,7 +61,7 @@ AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm, : MachineFunctionPass(&ID), O(o), TM(tm), MAI(T), TRI(tm.getRegisterInfo()), OutContext(Ctx), OutStreamer(Streamer), - LastMI(0), LastFn(0), Counter(~0U), PrevDLT(NULL) { + LastMI(0), LastFn(0), Counter(~0U), SetCounter(0), PrevDLT(NULL) { DW = 0; MMI = 0; VerboseAsm = Streamer.isVerboseAsm(); } @@ -893,6 +893,33 @@ void AsmPrinter::EmitInt64(uint64_t Value) const { OutStreamer.EmitIntValue(Value, 8, 0/*addrspace*/); } +/// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size +/// in bytes of the directive is specified by Size and Hi/Lo specify the +/// labels. This implicitly uses .set if it is available. +void AsmPrinter::EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, + unsigned Size) const { + // Get the Hi-Lo expression. + const MCExpr *Diff = + MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(Hi, OutContext), + MCSymbolRefExpr::Create(Lo, OutContext), + OutContext); + + if (!MAI->hasSetDirective()) { + OutStreamer.EmitValue(Diff, Size, 0/*AddrSpace*/); + return; + } + + // Otherwise, emit with .set (aka assignment). + MCSymbol *SetLabel = + OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "set" + + Twine(SetCounter++)); + OutStreamer.EmitAssignment(SetLabel, Diff); + + OutStreamer.EmitValue(MCSymbolRefExpr::Create(SetLabel, OutContext), + Size, 0/*AddrSpace*/); +} + + //===----------------------------------------------------------------------===// // EmitAlignment - Emit an alignment directive to the specified power of diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp index 52a4055d157..0f68c58b8d8 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp @@ -35,7 +35,7 @@ DwarfPrinter::DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T, const char *flavor) : O(OS), Asm(A), MAI(T), TD(Asm->TM.getTargetData()), RI(Asm->TM.getRegisterInfo()), M(NULL), MF(NULL), MMI(NULL), - SubprogramCount(0), Flavor(flavor), SetCounter(1) {} + SubprogramCount(0), Flavor(flavor) {} /// getDWLabel - Return the MCSymbol corresponding to the assembler temporary @@ -243,7 +243,7 @@ void DwarfPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const { O << *TLOF.getSymbolForDwarfReference(Sym, Asm->MMI, Encoding);; } -void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const { +void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const{ const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); PrintRelDirective(Encoding); @@ -255,25 +255,8 @@ void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const /// supports .set, we emit a .set of a temporary and then use it in the .word. void DwarfPrinter::EmitDifference(const MCSymbol *TagHi, const MCSymbol *TagLo, bool IsSmall) { - if (MAI->hasSetDirective()) { - // FIXME: switch to OutStreamer.EmitAssignment. - O << "\t.set\t"; - PrintLabelName("set", SetCounter, Flavor); - O << ","; - PrintLabelName(TagHi); - O << "-"; - PrintLabelName(TagLo); - O << "\n"; - - PrintRelDirective(IsSmall); - PrintLabelName("set", SetCounter, Flavor); - ++SetCounter; - } else { - PrintRelDirective(IsSmall); - PrintLabelName(TagHi); - O << "-"; - PrintLabelName(TagLo); - } + unsigned Size = IsSmall ? 4 : TD->getPointerSize(); + Asm->EmitLabelDifference(TagHi, TagLo, Size); } void DwarfPrinter::EmitSectionOffset(const MCSymbol *Label, diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.h b/lib/CodeGen/AsmPrinter/DwarfPrinter.h index 5228ca53032..237501cfeff 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.h +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.h @@ -70,9 +70,6 @@ protected: /// unique labels. const char * const Flavor; - /// SetCounter - A unique number for each '.set' directive. - unsigned SetCounter; - DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T, const char *flavor); public: diff --git a/test/CodeGen/X86/aliases.ll b/test/CodeGen/X86/aliases.ll index 753d5d9f6ce..3ed3bd67cef 100644 --- a/test/CodeGen/X86/aliases.ll +++ b/test/CodeGen/X86/aliases.ll @@ -1,5 +1,5 @@ ; RUN: llc < %s -mtriple=i686-pc-linux-gnu -asm-verbose=false -o %t -; RUN: grep { = } %t | count 7 +; RUN: grep { = } %t | count 16 ; RUN: grep set %t | count 18 ; RUN: grep globl %t | count 6 ; RUN: grep weak %t | count 1 -- 2.34.1