[llvm-commits] [llvm] r120889 - in /llvm/trunk: include/llvm/MC/MCAsmInfo.h include/llvm/MC/MCObjectStreamer.h include/llvm/MC/MCStreamer.h lib/MC/MCAsmInfo.cpp lib/MC/MCAsmStreamer.cpp lib/MC/MCDwarf.cpp lib/MC/MCLoggingStreamer.cpp lib/MC/MCNullStreamer.cpp lib/MC/MCObjectStreamer.cpp lib/Target/PTX/PTXMCAsmStreamer.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
Fri Dec 3 19:21:47 PST 2010


Author: rafael
Date: Fri Dec  3 21:21:47 2010
New Revision: 120889

URL: http://llvm.org/viewvc/llvm-project?rev=120889&view=rev
Log:
There are two reasons why we might want to use

foo = a - b
.long foo
instead of just
.long a - b

First, on darwin9 64 bits the assembler produces the wrong result. Second,
if "a" is the end of the section all darwin assemblers (9, 10 and mc) will not
consider a - b to be a constant but will if the dummy foo is created.

Split how we handle these cases. The first one is something MC should take care
of. The second one has to be handled by the caller.

Modified:
    llvm/trunk/include/llvm/MC/MCAsmInfo.h
    llvm/trunk/include/llvm/MC/MCObjectStreamer.h
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/MC/MCAsmInfo.cpp
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/lib/MC/MCLoggingStreamer.cpp
    llvm/trunk/lib/MC/MCNullStreamer.cpp
    llvm/trunk/lib/MC/MCObjectStreamer.cpp
    llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.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/MCAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmInfo.h Fri Dec  3 21:21:47 2010
@@ -197,6 +197,13 @@
     /// HasSetDirective - True if the assembler supports the .set directive.
     bool HasSetDirective;                    // Defaults to true.
 
+    /// NeedsSetToChangeDiffSize - True if the assembler requires that we do
+    /// Lc = a - b
+    /// .long Lc
+    /// instead of doing
+    /// .long a - b
+    bool NeedsSetToChangeDiffSize;           // Defaults to false.
+
     /// HasLCOMMDirective - This is true if the target supports the .lcomm
     /// directive.
     bool HasLCOMMDirective;                  // Defaults to false.
@@ -400,6 +407,7 @@
       return ExternDirective;
     }
     bool hasSetDirective() const { return HasSetDirective; }
+    bool needsSetToChangeDiffSize() const { return NeedsSetToChangeDiffSize; }
     bool hasLCOMMDirective() const { return HasLCOMMDirective; }
     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
     bool getCOMMDirectiveAlignmentIsInBytes() const {

Modified: llvm/trunk/include/llvm/MC/MCObjectStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectStreamer.h?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectStreamer.h Fri Dec  3 21:21:47 2010
@@ -60,8 +60,7 @@
   /// @{
 
   virtual void EmitLabel(MCSymbol *Symbol);
-  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace,
-                         bool UseSet = false);
+  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
   virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
   virtual void EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Fri Dec  3 21:21:47 2010
@@ -242,7 +242,7 @@
     /// @param Size - The size of the integer (in bytes) to emit. This must
     /// match a native machine width.
     virtual void EmitValue(const MCExpr *Value, unsigned Size,
-                           unsigned AddrSpace = 0, bool UseSet = false) = 0;
+                           unsigned AddrSpace = 0) = 0;
 
     /// EmitIntValue - Special case of EmitValue that avoids the client having
     /// to pass in a MCExpr for constant integers.

Modified: llvm/trunk/lib/MC/MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfo.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfo.cpp Fri Dec  3 21:21:47 2010
@@ -54,6 +54,7 @@
   GPRel32Directive = 0;
   GlobalDirective = "\t.globl\t";
   HasSetDirective = true;
+  NeedsSetToChangeDiffSize = false;
   HasLCOMMDirective = false;
   COMMDirectiveAlignmentIsInBytes = true;
   HasDotTypeDotSizeDirective = true;

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Dec  3 21:21:47 2010
@@ -44,6 +44,8 @@
   unsigned IsVerboseAsm : 1;
   unsigned ShowInst : 1;
 
+  bool needsSet(const MCExpr *Value);
+
 public:
   MCAsmStreamer(MCContext &Context, formatted_raw_ostream &os,
                 bool isLittleEndian, bool isVerboseAsm,
@@ -150,8 +152,7 @@
 
   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
 
-  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace,
-                         bool UseSet = false);
+  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
   virtual void EmitIntValue(uint64_t Value, unsigned Size,
                             unsigned AddrSpace = 0);
 
@@ -511,8 +512,34 @@
   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, bool UseSet) {
+                              unsigned AddrSpace) {
   assert(CurSection && "Cannot emit contents before setting section!");
   const char *Directive = 0;
   switch (Size) {
@@ -538,7 +565,7 @@
   }
 
   assert(Directive && "Invalid size for machine code value!");
-  if (UseSet && MAI.hasSetDirective()) {
+  if (needsSet(Value)) {
     MCSymbol *SetLabel = getContext().CreateTempSymbol();
     EmitAssignment(SetLabel, Value);
     OS << Directive << *SetLabel;

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Fri Dec  3 21:21:47 2010
@@ -213,8 +213,15 @@
 
   // The first 4 bytes is the total length of the information for this
   // compilation unit (not including these 4 bytes for the length).
-  MCOS->EmitValue(MakeStartMinusEndExpr(MCOS, LineStartSym, LineEndSym, 4),
-                  4, 0, true /*UseSet*/);
+  // 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);
 
   // Next 2 bytes is the Version, which is Dwarf 2.
   MCOS->EmitIntValue(2, 2);
@@ -228,7 +235,7 @@
   // length of the prologue.
   MCOS->EmitValue(MakeStartMinusEndExpr(MCOS, LineStartSym, ProEndSym,
                                         (4 + 2 + 4)),
-                  4, 0, true /*UseSet*/);
+                  4, 0);
 
   // Parameters of the state machine, are next.
   MCOS->EmitIntValue(DWARF2_LINE_MIN_INSN_LENGTH, 1);

Modified: llvm/trunk/lib/MC/MCLoggingStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCLoggingStreamer.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCLoggingStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCLoggingStreamer.cpp Fri Dec  3 21:21:47 2010
@@ -154,8 +154,7 @@
     return Child->EmitBytes(Data, AddrSpace);
   }
 
-  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace,
-                         bool UseSet = false){
+  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace){
     LogCall("EmitValue");
     return Child->EmitValue(Value, Size, AddrSpace);
   }

Modified: llvm/trunk/lib/MC/MCNullStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCNullStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCNullStreamer.cpp Fri Dec  3 21:21:47 2010
@@ -69,7 +69,7 @@
     virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
 
     virtual void EmitValue(const MCExpr *Value, unsigned Size,
-                           unsigned AddrSpace, bool UseSet = false) {}
+                           unsigned AddrSpace) {}
     virtual void EmitULEB128Value(const MCExpr *Value,
                                   unsigned AddrSpace = 0) {}
     virtual void EmitSLEB128Value(const MCExpr *Value,

Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Fri Dec  3 21:21:47 2010
@@ -77,7 +77,7 @@
 }
 
 void MCObjectStreamer::EmitValue(const MCExpr *Value, unsigned Size,
-                                 unsigned AddrSpace, bool UseSet) {
+                                 unsigned AddrSpace) {
   assert(AddrSpace == 0 && "Address space must be 0!");
   MCDataFragment *DF = getOrCreateDataFragment();
 

Modified: llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp Fri Dec  3 21:21:47 2010
@@ -147,8 +147,7 @@
 
   virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
 
-  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace,
-                         bool UseSet = false);
+  virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
   virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
   virtual void EmitSLEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
   virtual void EmitGPRel32Value(const MCExpr *Value);
@@ -361,7 +360,7 @@
 }
 
 void PTXMCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
-                                 unsigned AddrSpace, bool UseSet) {
+                                 unsigned AddrSpace) {
   assert(CurSection && "Cannot emit contents before setting section!");
   const char *Directive = 0;
   switch (Size) {

Modified: llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp?rev=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMCAsmInfo.cpp Fri Dec  3 21:21:47 2010
@@ -21,6 +21,10 @@
 
   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=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp Fri Dec  3 21:21:47 2010
@@ -56,6 +56,10 @@
   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=120889&r1=120888&r2=120889&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/empty-dwarf-lines.s (original)
+++ llvm/trunk/test/MC/MachO/empty-dwarf-lines.s Fri Dec  3 21:21:47 2010
@@ -17,7 +17,7 @@
 // CHECK-NEXT:  ('offset', 452)
 // CHECK-NEXT:  ('alignment', 0)
 // CHECK-NEXT:  ('reloc_offset', 496)
-// CHECK-NEXT:  ('num_reloc', 4)
+// CHECK-NEXT:  ('num_reloc', 2)
 // CHECK-NEXT:  ('flags', 0x2000000)
 // CHECK-NEXT:  ('reserved1', 0)
 // CHECK-NEXT:  ('reserved2', 0)





More information about the llvm-commits mailing list