move .set generation out of DwarfPrinter into AsmPrinter and
authorChris Lattner <sabre@nondot.org>
Mon, 8 Mar 2010 23:58:37 +0000 (23:58 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Mar 2010 23:58:37 +0000 (23:58 +0000)
MCize it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98010 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8ade1bd64af66d7f977ba5feaa576abb24c987ab..6187447597c96e366c3fa451e9a9a8d4e78f4f00 100644 (file)
@@ -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;
 
     //===------------------------------------------------------------------===//
 
index c0d92ffbbbc9764f387ff28f2db14c4c771d954f..5db2b0749d566fd857150c694031940ad34fb648 100644 (file)
@@ -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
index 52a4055d157b4341dbb4193579a407b3a245b161..0f68c58b8d8dcf627f4ed57136a9df3ae481a468 100644 (file)
@@ -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,
index 5228ca53032f889e884d12fae3bc882e4fc498f2..237501cfeffe446efea7dcebd02e80584ec699a2 100644 (file)
@@ -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:
index 753d5d9f6cebf9758596b8697a52936410385229..3ed3bd67cef171ff187e55385b0c86e89cc50d2a 100644 (file)
@@ -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