[llvm-commits] [llvm] r98010 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/AsmPrinter/DwarfPrinter.cpp lib/CodeGen/AsmPrinter/DwarfPrinter.h test/CodeGen/X86/aliases.ll

Chris Lattner sabre at nondot.org
Mon Mar 8 15:58:37 PST 2010


Author: lattner
Date: Mon Mar  8 17:58:37 2010
New Revision: 98010

URL: http://llvm.org/viewvc/llvm-project?rev=98010&view=rev
Log:
move .set generation out of DwarfPrinter into AsmPrinter and 
MCize it.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.h
    llvm/trunk/test/CodeGen/X86/aliases.ll

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=98010&r1=98009&r2=98010&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Mar  8 17:58:37 2010
@@ -136,6 +136,7 @@
     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 @@
     /// 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;
 
     //===------------------------------------------------------------------===//
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=98010&r1=98009&r2=98010&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Mar  8 17:58:37 2010
@@ -61,7 +61,7 @@
   : 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 @@
   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

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp?rev=98010&r1=98009&r2=98010&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp Mon Mar  8 17:58:37 2010
@@ -35,7 +35,7 @@
                            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 @@
   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 @@
 /// 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,

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.h?rev=98010&r1=98009&r2=98010&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfPrinter.h Mon Mar  8 17:58:37 2010
@@ -70,9 +70,6 @@
   /// 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:

Modified: llvm/trunk/test/CodeGen/X86/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/aliases.ll?rev=98010&r1=98009&r2=98010&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/aliases.ll (original)
+++ llvm/trunk/test/CodeGen/X86/aliases.ll Mon Mar  8 17:58:37 2010
@@ -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





More information about the llvm-commits mailing list