[llvm-commits] [llvm] r121006 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp lib/MC/MCAsmInfoDarwin.cpp lib/MC/MCAsmStreamer.cpp lib/MC/MCDwarf.cpp lib/MC/MCStreamer.cpp lib/Target/PowerPC/PPCMCAsmInfo.cpp lib/Target/X86/X86MCAsmInfo.cpp test/MC/MachO/empty-dwarf-lines.s

Rafael Espindola rafael.espindola at gmail.com
Mon Dec 6 09:27:56 PST 2010


Author: rafael
Date: Mon Dec  6 11:27:56 2010
New Revision: 121006

URL: http://llvm.org/viewvc/llvm-project?rev=121006&view=rev
Log:
Second try at making direct object emission produce the same results
as llc + llvm-mc. This time ELF is not changed and I tested that llvm-gcc
bootstrap on darwin10 using darwin9's assembler and linker.

Modified:
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
    llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/lib/MC/MCStreamer.cpp
    llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp
    llvm/trunk/test/MC/MachO/empty-dwarf-lines.s

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Mon Dec  6 11:27:56 2010
@@ -249,6 +249,12 @@
     virtual void EmitIntValue(uint64_t Value, unsigned Size,
                               unsigned AddrSpace = 0);
 
+    /// EmitAbsValue - Emit the Value, but try to avoid relocations. On MachO
+    /// this is done by producing
+    /// foo = value
+    /// .long foo
+    void EmitAbsValue(const MCExpr *Value, unsigned Size,
+                      unsigned AddrSpace = 0);
 
     virtual void EmitULEB128Value(const MCExpr *Value,
                                   unsigned AddrSpace = 0) = 0;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp Mon Dec  6 11:27:56 2010
@@ -156,7 +156,7 @@
   
   const MCExpr *Exp =
     TLOF.getExprForDwarfReference(Sym, Mang, MMI, Encoding, OutStreamer);
-  OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding), /*addrspace*/0);
+  OutStreamer.EmitAbsValue(Exp, GetSizeOfEncodedValue(Encoding));
 }
 
 void AsmPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const{

Modified: llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp Mon Dec  6 11:27:56 2010
@@ -40,7 +40,8 @@
 
   // FIXME: Darwin 10 and newer don't need this.
   LinkerRequiresNonEmptyDwarfLines = true;
-  
+
+  NeedsSetToChangeDiffSize = true;
   HiddenVisibilityAttr = MCSA_PrivateExtern;
   // Doesn't support protected visibility.
   ProtectedVisibilityAttr = MCSA_Global;

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Mon Dec  6 11:27:56 2010
@@ -512,32 +512,6 @@
   EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace);
 }
 
-static bool hasSymbolDifference(const MCExpr *Value) {
-  switch (Value->getKind()) {
-  case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!");
-  case MCExpr::Constant:
-  case MCExpr::SymbolRef:
-    return false;
-  case MCExpr::Unary:
-    return hasSymbolDifference(cast<MCUnaryExpr>(Value)->getSubExpr());
-  case MCExpr::Binary: {
-    const MCBinaryExpr *BE = cast<MCBinaryExpr>(Value);
-    if (BE->getOpcode() == MCBinaryExpr::Sub &&
-	BE->getLHS()->getKind() == MCExpr::SymbolRef &&
-	BE->getRHS()->getKind() == MCExpr::SymbolRef)
-      return true;
-    return hasSymbolDifference(BE->getLHS()) ||
-      hasSymbolDifference(BE->getRHS());
-  }
-  }
-  llvm_unreachable("Switch covers all cases");
-}
-
-bool MCAsmStreamer::needsSet(const MCExpr *Value) {
-  return getContext().getAsmInfo().needsSetToChangeDiffSize() &&
-    hasSymbolDifference(Value);
-}
-
 void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
                               unsigned AddrSpace) {
   assert(CurSection && "Cannot emit contents before setting section!");
@@ -565,14 +539,6 @@
   }
 
   assert(Directive && "Invalid size for machine code value!");
-  if (needsSet(Value)) {
-    MCSymbol *SetLabel = getContext().CreateTempSymbol();
-    EmitAssignment(SetLabel, Value);
-    OS << Directive << *SetLabel;
-    EmitEOL();
-    return;
-  }
-
   OS << Directive << *Value;
   EmitEOL();
 }

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Mon Dec  6 11:27:56 2010
@@ -213,15 +213,8 @@
 
   // The first 4 bytes is the total length of the information for this
   // compilation unit (not including these 4 bytes for the length).
-  // FIXME: We create the dummy TotalLength variable because LineEndSym points
-  // to the end of the section and the darwin assembler doesn't consider that
-  // difference an assembly time constant. It might be better for this to be
-  // proected by a flag.
-  MCSymbol *TotalLength = MCOS->getContext().CreateTempSymbol();
-  MCOS->EmitAssignment(TotalLength,
-		       MakeStartMinusEndExpr(MCOS, LineStartSym, LineEndSym,
-					     4));
-  MCOS->EmitSymbolValue(TotalLength, 4, 0);
+  MCOS->EmitAbsValue(MakeStartMinusEndExpr(MCOS, LineStartSym, LineEndSym,4),
+                     4);
 
   // Next 2 bytes is the Version, which is Dwarf 2.
   MCOS->EmitIntValue(2, 2);
@@ -233,7 +226,7 @@
   // section to the end of the prologue.  Not including the 4 bytes for the
   // total length, the 2 bytes for the version, and these 4 bytes for the
   // length of the prologue.
-  MCOS->EmitValue(MakeStartMinusEndExpr(MCOS, LineStartSym, ProEndSym,
+  MCOS->EmitAbsValue(MakeStartMinusEndExpr(MCOS, LineStartSym, ProEndSym,
                                         (4 + 2 + 4)),
                   4, 0);
 

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Mon Dec  6 11:27:56 2010
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCExpr.h"
@@ -72,6 +73,17 @@
   EmitBytes(OSE.str(), AddrSpace);
 }
 
+void MCStreamer::EmitAbsValue(const MCExpr *Value, unsigned Size,
+                              unsigned AddrSpace) {
+  if (!getContext().getAsmInfo().needsSetToChangeDiffSize()) {
+    EmitValue(Value, Size, AddrSpace);
+    return;
+  }
+  MCSymbol *ABS = getContext().CreateTempSymbol();
+  EmitAssignment(ABS, Value);
+  EmitSymbolValue(ABS, Size, AddrSpace);
+}
+
 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
                                  unsigned AddrSpace) {
   EmitValue(MCSymbolRefExpr::Create(Sym, getContext()), Size, AddrSpace);

Modified: llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp Mon Dec  6 11:27:56 2010
@@ -22,9 +22,6 @@
   if (!is64Bit)
     Data64bitsDirective = 0;      // We can't emit a 64-bit unit in PPC32 mode.
 
-  if (is64Bit)
-    NeedsSetToChangeDiffSize = true;
-
   AssemblerDialect = 1;           // New-Style mnemonics.
   SupportsDebugInformation= true; // Debug information.
 }

Modified: llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp Mon Dec  6 11:27:56 2010
@@ -56,10 +56,6 @@
   if (!is64Bit)
     Data64bitsDirective = 0;       // we can't emit a 64-bit unit
 
-  // FIXME: Darwin 10 doesn't need this.
-  if (is64Bit)
-    NeedsSetToChangeDiffSize = true;
-
   // Use ## as a comment string so that .s files generated by llvm can go
   // through the GCC preprocessor without causing an error.  This is needed
   // because "clang foo.s" runs the C preprocessor, which is usually reserved

Modified: llvm/trunk/test/MC/MachO/empty-dwarf-lines.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/empty-dwarf-lines.s?rev=121006&r1=121005&r2=121006&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/empty-dwarf-lines.s (original)
+++ llvm/trunk/test/MC/MachO/empty-dwarf-lines.s Mon Dec  6 11:27:56 2010
@@ -16,8 +16,8 @@
 // CHECK-NEXT:  ('size', 44)
 // CHECK-NEXT:  ('offset', 452)
 // CHECK-NEXT:  ('alignment', 0)
-// CHECK-NEXT:  ('reloc_offset', 496)
-// CHECK-NEXT:  ('num_reloc', 2)
+// CHECK-NEXT:  ('reloc_offset', 0)
+// CHECK-NEXT:  ('num_reloc', 0)
 // CHECK-NEXT:  ('flags', 0x2000000)
 // CHECK-NEXT:  ('reserved1', 0)
 // CHECK-NEXT:  ('reserved2', 0)





More information about the llvm-commits mailing list