svn commit: r193378 - in vendor/llvm/dist: docs include/llvm/ADT include/llvm/Analysis include/llvm/Support lib/Analysis lib/CodeGen lib/System lib/Target/ARM lib/Target/X86 lib/Transforms/Scalar t...

Ed Schouten ed at FreeBSD.org
Wed Jun 3 13:28:01 UTC 2009


Author: ed
Date: Wed Jun  3 13:28:00 2009
New Revision: 193378
URL: http://svn.freebsd.org/changeset/base/193378

Log:
  Import LLVM, at r72770.
  
  This should fix LLVM PR4225.

Added:
  vendor/llvm/dist/lib/CodeGen/MachO.h
  vendor/llvm/dist/lib/CodeGen/MachOCodeEmitter.cpp
  vendor/llvm/dist/lib/CodeGen/MachOCodeEmitter.h
  vendor/llvm/dist/test/Archive/GNU.a   (contents, props changed)
  vendor/llvm/dist/test/Archive/IsNAN.o   (contents, props changed)
  vendor/llvm/dist/test/Archive/MacOSX.a   (contents, props changed)
  vendor/llvm/dist/test/Archive/SVR4.a   (contents, props changed)
  vendor/llvm/dist/test/Archive/xpg4.a   (contents, props changed)
  vendor/llvm/dist/test/CodeGen/ARM/str_pre-2.ll
  vendor/llvm/dist/test/CodeGen/X86/2009-06-02-RewriterBug.ll
  vendor/llvm/dist/test/CodeGen/X86/codegen-prepare-cast.ll
  vendor/llvm/dist/test/CodeGen/X86/x86-store-gv-addr.ll
Modified:
  vendor/llvm/dist/docs/LangRef.html
  vendor/llvm/dist/include/llvm/ADT/ilist.h
  vendor/llvm/dist/include/llvm/Analysis/ConstantFolding.h
  vendor/llvm/dist/include/llvm/Analysis/ScalarEvolutionExpressions.h
  vendor/llvm/dist/include/llvm/Support/TargetFolder.h
  vendor/llvm/dist/lib/Analysis/ConstantFolding.cpp
  vendor/llvm/dist/lib/CodeGen/LiveVariables.cpp
  vendor/llvm/dist/lib/CodeGen/MachOWriter.cpp
  vendor/llvm/dist/lib/CodeGen/MachOWriter.h
  vendor/llvm/dist/lib/CodeGen/RegAllocLinearScan.cpp
  vendor/llvm/dist/lib/CodeGen/VirtRegRewriter.cpp
  vendor/llvm/dist/lib/System/Atomic.cpp
  vendor/llvm/dist/lib/Target/ARM/ARMLoadStoreOptimizer.cpp
  vendor/llvm/dist/lib/Target/X86/X86FastISel.cpp
  vendor/llvm/dist/lib/Transforms/Scalar/CodeGenPrepare.cpp
  vendor/llvm/dist/utils/NewNightlyTest.pl

Modified: vendor/llvm/dist/docs/LangRef.html
==============================================================================
--- vendor/llvm/dist/docs/LangRef.html	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/docs/LangRef.html	Wed Jun  3 13:28:00 2009	(r193378)
@@ -2403,9 +2403,10 @@ cleanup is performed in the case of eith
 exception.  Additionally, this is important for implementation of
 '<tt>catch</tt>' clauses in high-level languages that support them.</p>
 
-<p>It is not valid to reference the return value of an invoke call from
-anywhere not dominated by the normal label, since an unwind does not
-provide a return value.</p>
+<p>For the purposes of the SSA form, the definition of the value
+returned by the '<tt>invoke</tt>' instruction is deemed to occur on
+the edge from the current block to the "normal" label. If the callee
+unwinds then no return value is available.</p>
 
 <h5>Example:</h5>
 <pre>
@@ -4518,6 +4519,11 @@ may be used as the label arguments.</p>
 block and the PHI instructions: i.e. PHI instructions must be first in
 a basic block.</p>
 
+<p>For the purposes of the SSA form, the use of each incoming value is
+deemed to occur on the edge from the corresponding predecessor block
+to the current block (but after any definition of an '<tt>invoke</tt>'
+instruction's return value on the same edge).</p>
+
 <h5>Semantics:</h5>
 
 <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
@@ -7104,7 +7110,7 @@ declare void @llvm.stackprotector( i8* &
 
   <a href="mailto:sabre at nondot.org">Chris Lattner</a><br>
   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
-  Last modified: $Date: 2009-05-30 18:08:30 +0200 (Sat, 30 May 2009) $
+  Last modified: $Date: 2009-06-03 12:20:10 +0200 (Wed, 03 Jun 2009) $
 </address>
 
 </body>

Modified: vendor/llvm/dist/include/llvm/ADT/ilist.h
==============================================================================
--- vendor/llvm/dist/include/llvm/ADT/ilist.h	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/include/llvm/ADT/ilist.h	Wed Jun  3 13:28:00 2009	(r193378)
@@ -481,8 +481,8 @@ private:
       L2.setTail(0);
 
       // Remove [first, last) from its old position.
-      NodeTy *First = &*first, *Prev = getPrev(First);
-      NodeTy *Next = last.getNodePtrUnchecked(), *Last = getPrev(Next);
+      NodeTy *First = &*first, *Prev = this->getPrev(First);
+      NodeTy *Next = last.getNodePtrUnchecked(), *Last = this->getPrev(Next);
       if (Prev)
         this->setNext(Prev, Next);
       else
@@ -491,7 +491,7 @@ private:
 
       // Splice [first, last) into its new position.
       NodeTy *PosNext = position.getNodePtrUnchecked();
-      NodeTy *PosPrev = getPrev(PosNext);
+      NodeTy *PosPrev = this->getPrev(PosNext);
 
       // Fix head of list...
       if (PosPrev)
@@ -504,7 +504,7 @@ private:
       this->setNext(Last, PosNext);
       this->setPrev(PosNext, Last);
 
-      transferNodesFromList(L2, First, PosNext);
+      this->transferNodesFromList(L2, First, PosNext);
 
       // Now that everything is set, restore the pointers to the list sentinels.
       L2.setTail(L2Sentinel);

Modified: vendor/llvm/dist/include/llvm/Analysis/ConstantFolding.h
==============================================================================
--- vendor/llvm/dist/include/llvm/Analysis/ConstantFolding.h	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/include/llvm/Analysis/ConstantFolding.h	Wed Jun  3 13:28:00 2009	(r193378)
@@ -34,7 +34,7 @@ Constant *ConstantFoldInstruction(Instru
 /// using the specified TargetData.  If successful, the constant result is
 /// result is returned, if not, null is returned.
 Constant *ConstantFoldConstantExpression(ConstantExpr *CE,
-                                         const TargetData *TD);
+                                         const TargetData *TD = 0);
 
 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
 /// specified operands.  If successful, the constant result is returned, if not,

Modified: vendor/llvm/dist/include/llvm/Analysis/ScalarEvolutionExpressions.h
==============================================================================
--- vendor/llvm/dist/include/llvm/Analysis/ScalarEvolutionExpressions.h	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/include/llvm/Analysis/ScalarEvolutionExpressions.h	Wed Jun  3 13:28:00 2009	(r193378)
@@ -19,7 +19,6 @@
 namespace llvm {
   class ConstantInt;
   class ConstantRange;
-  class APInt;
   class DominatorTree;
 
   enum SCEVTypes {

Modified: vendor/llvm/dist/include/llvm/Support/TargetFolder.h
==============================================================================
--- vendor/llvm/dist/include/llvm/Support/TargetFolder.h	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/include/llvm/Support/TargetFolder.h	Wed Jun  3 13:28:00 2009	(r193378)
@@ -9,8 +9,10 @@
 //
 // This file defines the TargetFolder class, a helper for IRBuilder.
 // It provides IRBuilder with a set of methods for creating constants with
-// target dependent folding.  For general constant creation and folding,
-// use ConstantExpr and the routines in llvm/Analysis/ConstantFolding.h.
+// target dependent folding, in addition to the same target-independent
+// folding that the ConstantFolder class provides.  For general constant
+// creation and folding, use ConstantExpr and the routines in
+// llvm/Analysis/ConstantFolding.h.
 //
 //===----------------------------------------------------------------------===//
 
@@ -26,18 +28,18 @@ class TargetData;
 
 /// TargetFolder - Create constants with target dependent folding.
 class TargetFolder {
-  const TargetData &TD;
+  const TargetData *TD;
 
   /// Fold - Fold the constant using target specific information.
   Constant *Fold(Constant *C) const {
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
-      if (Constant *CF = ConstantFoldConstantExpression(CE, &TD))
+      if (Constant *CF = ConstantFoldConstantExpression(CE, TD))
         return CF;
     return C;
   }
 
 public:
-  TargetFolder(const TargetData &TheTD) : TD(TheTD) {}
+  explicit TargetFolder(const TargetData *TheTD) : TD(TheTD) {}
 
   //===--------------------------------------------------------------------===//
   // Binary Operators

Modified: vendor/llvm/dist/lib/Analysis/ConstantFolding.cpp
==============================================================================
--- vendor/llvm/dist/lib/Analysis/ConstantFolding.cpp	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/lib/Analysis/ConstantFolding.cpp	Wed Jun  3 13:28:00 2009	(r193378)
@@ -317,8 +317,6 @@ Constant *llvm::ConstantFoldInstruction(
 /// result is returned, if not, null is returned.
 Constant *llvm::ConstantFoldConstantExpression(ConstantExpr *CE,
                                                const TargetData *TD) {
-  assert(TD && "ConstantFoldConstantExpression requires a valid TargetData.");
-
   SmallVector<Constant*, 8> Ops;
   for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i)
     Ops.push_back(cast<Constant>(*i));

Modified: vendor/llvm/dist/lib/CodeGen/LiveVariables.cpp
==============================================================================
--- vendor/llvm/dist/lib/CodeGen/LiveVariables.cpp	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/lib/CodeGen/LiveVariables.cpp	Wed Jun  3 13:28:00 2009	(r193378)
@@ -242,20 +242,6 @@ void LiveVariables::HandlePhysRegUse(uns
     }
   }
 
-  // There was an earlier def of a super-register. Add implicit def to that MI.
-  //
-  //   A: EAX = ...
-  //   B: ... = AX
-  //
-  // Add implicit def to A if there isn't a use of AX (or EAX) before B.
-  if (!PhysRegUse[Reg]) {
-    MachineInstr *Def = PhysRegDef[Reg];
-    if (Def && !Def->modifiesRegister(Reg))
-      Def->addOperand(MachineOperand::CreateReg(Reg,
-                                                true  /*IsDef*/,
-                                                true  /*IsImp*/));
-  }
-  
   // Remember this use.
   PhysRegUse[Reg]  = MI;
   for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);

Added: vendor/llvm/dist/lib/CodeGen/MachO.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/llvm/dist/lib/CodeGen/MachO.h	Wed Jun  3 13:28:00 2009	(r193378)
@@ -0,0 +1,423 @@
+//=== MachO.h - Mach-O structures and constants -----------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines MachO .
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MACHO_H
+#define MACHO_H
+
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/CodeGen/MachineRelocation.h"
+#include "llvm/Target/TargetAsmInfo.h"
+#include <string>
+#include <vector>
+
+namespace llvm {
+
+typedef std::vector<unsigned char> DataBuffer;
+  
+/// MachOSym - This struct contains information about each symbol that is
+/// added to logical symbol table for the module.  This is eventually
+/// turned into a real symbol table in the file.
+struct MachOSym {
+  const GlobalValue *GV;    // The global value this corresponds to.
+  std::string GVName;       // The mangled name of the global value.
+  uint32_t    n_strx;       // index into the string table
+  uint8_t     n_type;       // type flag
+  uint8_t     n_sect;       // section number or NO_SECT
+  int16_t     n_desc;       // see <mach-o/stab.h>
+  uint64_t    n_value;      // value for this symbol (or stab offset)
+  
+  // Constants for the n_sect field
+  // see <mach-o/nlist.h>
+  enum { NO_SECT = 0 };   // symbol is not in any section
+
+  // Constants for the n_type field
+  // see <mach-o/nlist.h>
+  enum { N_UNDF  = 0x0,  // undefined, n_sect == NO_SECT
+         N_ABS   = 0x2,  // absolute, n_sect == NO_SECT
+         N_SECT  = 0xe,  // defined in section number n_sect
+         N_PBUD  = 0xc,  // prebound undefined (defined in a dylib)
+         N_INDR  = 0xa   // indirect
+  };
+  // The following bits are OR'd into the types above. For example, a type
+  // of 0x0f would be an external N_SECT symbol (0x0e | 0x01).
+  enum { N_EXT  = 0x01,   // external symbol bit
+         N_PEXT = 0x10    // private external symbol bit
+  };
+  
+  // Constants for the n_desc field
+  // see <mach-o/loader.h>
+  enum { REFERENCE_FLAG_UNDEFINED_NON_LAZY          = 0,
+         REFERENCE_FLAG_UNDEFINED_LAZY              = 1,
+         REFERENCE_FLAG_DEFINED                     = 2,
+         REFERENCE_FLAG_PRIVATE_DEFINED             = 3,
+         REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY  = 4,
+         REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY      = 5
+  };
+  enum { N_NO_DEAD_STRIP = 0x0020, // symbol is not to be dead stripped
+         N_WEAK_REF      = 0x0040, // symbol is weak referenced
+         N_WEAK_DEF      = 0x0080  // coalesced symbol is a weak definition
+  };
+  
+  MachOSym(const GlobalValue *gv, std::string name, uint8_t sect,
+           const TargetAsmInfo *TAI);
+
+  struct SymCmp {
+    // FIXME: this does not appear to be sorting 'f' after 'F'
+    bool operator()(const MachOSym &LHS, const MachOSym &RHS) {
+      return LHS.GVName < RHS.GVName;
+    }
+  };
+
+
+  /// PartitionByLocal - Simple boolean predicate that returns true if Sym is
+  /// a local symbol rather than an external symbol.
+  
+  static inline bool PartitionByLocal(const MachOSym &Sym) {
+    return (Sym.n_type & (MachOSym::N_EXT | MachOSym::N_PEXT)) == 0;
+  }
+  
+  /// PartitionByDefined - Simple boolean predicate that returns true if Sym is
+  /// defined in this module.
+  
+  static inline bool PartitionByDefined(const MachOSym &Sym) {
+    // FIXME: Do N_ABS or N_INDR count as defined?
+    return (Sym.n_type & MachOSym::N_SECT) == MachOSym::N_SECT;
+  }
+
+}; // end struct MachOSym
+
+/// MachOHeader - This struct contains the header information about a
+/// specific architecture type/subtype pair that is emitted to the file.
+
+struct MachOHeader {
+  uint32_t  magic;      // mach magic number identifier
+  uint32_t  filetype;   // type of file
+  uint32_t  ncmds;      // number of load commands
+  uint32_t  sizeofcmds; // the size of all the load commands
+  uint32_t  flags;      // flags
+  uint32_t  reserved;   // 64-bit only
+  
+  /// HeaderData - The actual data for the header which we are building
+  /// up for emission to the file.
+  DataBuffer HeaderData;
+
+  // Constants for the filetype field
+  // see <mach-o/loader.h> for additional info on the various types
+  enum { MH_OBJECT     = 1, // relocatable object file
+         MH_EXECUTE    = 2, // demand paged executable file
+         MH_FVMLIB     = 3, // fixed VM shared library file
+         MH_CORE       = 4, // core file
+         MH_PRELOAD    = 5, // preloaded executable file
+         MH_DYLIB      = 6, // dynamically bound shared library
+         MH_DYLINKER   = 7, // dynamic link editor
+         MH_BUNDLE     = 8, // dynamically bound bundle file
+         MH_DYLIB_STUB = 9, // shared library stub for static linking only
+         MH_DSYM       = 10 // companion file wiht only debug sections
+  };
+  
+  // Constants for the flags field
+  enum { MH_NOUNDEFS                = 1 << 0,
+            // the object file has no undefined references
+         MH_INCRLINK                = 1 << 1,
+            // the object file is the output of an incremental link against
+            // a base file and cannot be link edited again
+         MH_DYLDLINK                = 1 << 2,
+            // the object file is input for the dynamic linker and cannot be
+            // statically link edited again.
+         MH_BINDATLOAD              = 1 << 3,
+            // the object file's undefined references are bound by the
+            // dynamic linker when loaded.
+         MH_PREBOUND                = 1 << 4,
+            // the file has its dynamic undefined references prebound
+         MH_SPLIT_SEGS              = 1 << 5,
+            // the file has its read-only and read-write segments split
+            // see <mach/shared_memory_server.h>
+         MH_LAZY_INIT               = 1 << 6,
+            // the shared library init routine is to be run lazily via
+            // catching memory faults to its writable segments (obsolete)
+         MH_TWOLEVEL                = 1 << 7,
+            // the image is using two-level namespace bindings
+         MH_FORCE_FLAT              = 1 << 8,
+            // the executable is forcing all images to use flat namespace
+            // bindings.
+         MH_NOMULTIDEFS             = 1 << 8,
+            // this umbrella guarantees no multiple definitions of symbols
+            // in its sub-images so the two-level namespace hints can
+            // always be used.
+         MH_NOFIXPREBINDING         = 1 << 10,
+            // do not have dyld notify the prebidning agent about this
+            // executable.
+         MH_PREBINDABLE             = 1 << 11,
+            // the binary is not prebound but can have its prebinding
+            // redone.  only used when MH_PREBOUND is not set.
+         MH_ALLMODSBOUND            = 1 << 12,
+            // indicates that this binary binds to all two-level namespace
+            // modules of its dependent libraries.  Only used when
+            // MH_PREBINDABLE and MH_TWOLEVEL are both set.
+         MH_SUBSECTIONS_VIA_SYMBOLS = 1 << 13,
+            // safe to divide up the sections into sub-sections via symbols
+            // for dead code stripping.
+         MH_CANONICAL               = 1 << 14,
+            // the binary has been canonicalized via the unprebind operation
+         MH_WEAK_DEFINES            = 1 << 15,
+            // the final linked image contains external weak symbols
+         MH_BINDS_TO_WEAK           = 1 << 16,
+            // the final linked image uses weak symbols
+         MH_ALLOW_STACK_EXECUTION   = 1 << 17
+            // When this bit is set, all stacks in the task will be given
+            // stack execution privilege.  Only used in MH_EXECUTE filetype
+  };
+
+  MachOHeader() : magic(0), filetype(0), ncmds(0), sizeofcmds(0), flags(0),
+                  reserved(0) { }
+  
+  /// cmdSize - This routine returns the size of the MachOSection as written
+  /// to disk, depending on whether the destination is a 64 bit Mach-O file.
+  unsigned cmdSize(bool is64Bit) const {
+    if (is64Bit)
+      return 8 * sizeof(uint32_t);
+    else
+      return 7 * sizeof(uint32_t);
+  }
+
+  /// setMagic - This routine sets the appropriate value for the 'magic'
+  /// field based on pointer size and endianness.
+  void setMagic(bool isLittleEndian, bool is64Bit) {
+    if (isLittleEndian)
+      if (is64Bit) magic = 0xcffaedfe;
+      else         magic = 0xcefaedfe;
+    else
+      if (is64Bit) magic = 0xfeedfacf;
+      else         magic = 0xfeedface;
+  }
+
+}; // end struct MachOHeader
+    
+/// MachOSegment - This struct contains the necessary information to
+/// emit the load commands for each section in the file.
+struct MachOSegment {
+  uint32_t    cmd;      // LC_SEGMENT or LC_SEGMENT_64
+  uint32_t    cmdsize;  // Total size of this struct and section commands
+  std::string segname;  // segment name
+  uint64_t    vmaddr;   // address of this segment
+  uint64_t    vmsize;   // size of this segment, may be larger than filesize
+  uint64_t    fileoff;  // offset in file
+  uint64_t    filesize; // amount to read from file
+  uint32_t    maxprot;  // maximum VM protection
+  uint32_t    initprot; // initial VM protection
+  uint32_t    nsects;   // number of sections in this segment
+  uint32_t    flags;    // flags
+  
+  // The following constants are getting pulled in by one of the
+  // system headers, which creates a neat clash with the enum.
+#if !defined(VM_PROT_NONE)
+#define VM_PROT_NONE    0x00
+#endif
+#if !defined(VM_PROT_READ)
+#define VM_PROT_READ    0x01
+#endif
+#if !defined(VM_PROT_WRITE)
+#define VM_PROT_WRITE   0x02
+#endif
+#if !defined(VM_PROT_EXECUTE)
+#define VM_PROT_EXECUTE 0x04
+#endif
+#if !defined(VM_PROT_ALL)
+#define VM_PROT_ALL     0x07
+#endif
+
+  // Constants for the vm protection fields
+  // see <mach-o/vm_prot.h>
+  enum { SEG_VM_PROT_NONE     = VM_PROT_NONE, 
+         SEG_VM_PROT_READ     = VM_PROT_READ, // read permission
+         SEG_VM_PROT_WRITE    = VM_PROT_WRITE, // write permission
+         SEG_VM_PROT_EXECUTE  = VM_PROT_EXECUTE,
+         SEG_VM_PROT_ALL      = VM_PROT_ALL
+  };
+  
+  // Constants for the cmd field
+  // see <mach-o/loader.h>
+  enum { LC_SEGMENT    = 0x01,  // segment of this file to be mapped
+         LC_SEGMENT_64 = 0x19   // 64-bit segment of this file to be mapped
+  };
+  
+  /// cmdSize - This routine returns the size of the MachOSection as written
+  /// to disk, depending on whether the destination is a 64 bit Mach-O file.
+  unsigned cmdSize(bool is64Bit) const {
+    if (is64Bit)
+      return 6 * sizeof(uint32_t) + 4 * sizeof(uint64_t) + 16;
+    else
+      return 10 * sizeof(uint32_t) + 16;  // addresses only 32 bits
+  }
+
+  MachOSegment(const std::string &seg, bool is64Bit)
+    : cmd(is64Bit ? LC_SEGMENT_64 : LC_SEGMENT), cmdsize(0), segname(seg),
+      vmaddr(0), vmsize(0), fileoff(0), filesize(0), maxprot(VM_PROT_ALL),
+      initprot(VM_PROT_ALL), nsects(0), flags(0) { }
+};
+
+/// MachOSection - This struct contains information about each section in a 
+/// particular segment that is emitted to the file.  This is eventually
+/// turned into the SectionCommand in the load command for a particlar
+/// segment.
+
+struct MachOSection { 
+  std::string  sectname; // name of this section, 
+  std::string  segname;  // segment this section goes in
+  uint64_t  addr;        // memory address of this section
+  uint64_t  size;        // size in bytes of this section
+  uint32_t  offset;      // file offset of this section
+  uint32_t  align;       // section alignment (power of 2)
+  uint32_t  reloff;      // file offset of relocation entries
+  uint32_t  nreloc;      // number of relocation entries
+  uint32_t  flags;       // flags (section type and attributes)
+  uint32_t  reserved1;   // reserved (for offset or index)
+  uint32_t  reserved2;   // reserved (for count or sizeof)
+  uint32_t  reserved3;   // reserved (64 bit only)
+  
+  /// A unique number for this section, which will be used to match symbols
+  /// to the correct section.
+  uint32_t Index;
+  
+  /// SectionData - The actual data for this section which we are building
+  /// up for emission to the file.
+  DataBuffer SectionData;
+
+  /// RelocBuffer - A buffer to hold the mach-o relocations before we write
+  /// them out at the appropriate location in the file.
+  DataBuffer RelocBuffer;
+  
+  /// Relocations - The relocations that we have encountered so far in this 
+  /// section that we will need to convert to MachORelocation entries when
+  /// the file is written.
+  std::vector<MachineRelocation> Relocations;
+  
+  // Constants for the section types (low 8 bits of flags field)
+  // see <mach-o/loader.h>
+  enum { S_REGULAR = 0,
+            // regular section
+         S_ZEROFILL = 1,
+            // zero fill on demand section
+         S_CSTRING_LITERALS = 2,
+            // section with only literal C strings
+         S_4BYTE_LITERALS = 3,
+            // section with only 4 byte literals
+         S_8BYTE_LITERALS = 4,
+            // section with only 8 byte literals
+         S_LITERAL_POINTERS = 5, 
+            // section with only pointers to literals
+         S_NON_LAZY_SYMBOL_POINTERS = 6,
+            // section with only non-lazy symbol pointers
+         S_LAZY_SYMBOL_POINTERS = 7,
+            // section with only lazy symbol pointers
+         S_SYMBOL_STUBS = 8,
+            // section with only symbol stubs
+            // byte size of stub in the reserved2 field
+         S_MOD_INIT_FUNC_POINTERS = 9,
+            // section with only function pointers for initialization
+         S_MOD_TERM_FUNC_POINTERS = 10,
+            // section with only function pointers for termination
+         S_COALESCED = 11,
+            // section contains symbols that are coalesced
+         S_GB_ZEROFILL = 12,
+            // zero fill on demand section (that can be larger than 4GB)
+         S_INTERPOSING = 13,
+            // section with only pairs of function pointers for interposing
+         S_16BYTE_LITERALS = 14
+            // section with only 16 byte literals
+  };
+  
+  // Constants for the section flags (high 24 bits of flags field)
+  // see <mach-o/loader.h>
+  enum { S_ATTR_PURE_INSTRUCTIONS   = 1 << 31,
+            // section contains only true machine instructions
+         S_ATTR_NO_TOC              = 1 << 30,
+            // section contains coalesced symbols that are not to be in a 
+            // ranlib table of contents
+         S_ATTR_STRIP_STATIC_SYMS   = 1 << 29,
+            // ok to strip static symbols in this section in files with the
+            // MY_DYLDLINK flag
+         S_ATTR_NO_DEAD_STRIP       = 1 << 28,
+            // no dead stripping
+         S_ATTR_LIVE_SUPPORT        = 1 << 27,
+            // blocks are live if they reference live blocks
+         S_ATTR_SELF_MODIFYING_CODE = 1 << 26,
+            // used with i386 code stubs written on by dyld
+         S_ATTR_DEBUG               = 1 << 25,
+            // a debug section
+         S_ATTR_SOME_INSTRUCTIONS   = 1 << 10,
+            // section contains some machine instructions
+         S_ATTR_EXT_RELOC           = 1 << 9,
+            // section has external relocation entries
+         S_ATTR_LOC_RELOC           = 1 << 8
+            // section has local relocation entries
+  };
+
+  /// cmdSize - This routine returns the size of the MachOSection as written
+  /// to disk, depending on whether the destination is a 64 bit Mach-O file.
+  unsigned cmdSize(bool is64Bit) const {
+    if (is64Bit)
+      return 7 * sizeof(uint32_t) + 2 * sizeof(uint64_t) + 32;
+    else
+      return 9 * sizeof(uint32_t) + 32;  // addresses only 32 bits
+  }
+
+  MachOSection(const std::string &seg, const std::string &sect)
+    : sectname(sect), segname(seg), addr(0), size(0), offset(0), align(2),
+      reloff(0), nreloc(0), flags(0), reserved1(0), reserved2(0),
+      reserved3(0) { }
+
+}; // end struct MachOSection
+
+    /// MachOSymTab - This struct contains information about the offsets and 
+    /// size of symbol table information.
+    /// segment.
+    struct MachODySymTab {
+      uint32_t cmd;             // LC_DYSYMTAB
+      uint32_t cmdsize;         // sizeof( MachODySymTab )
+      uint32_t ilocalsym;       // index to local symbols
+      uint32_t nlocalsym;       // number of local symbols
+      uint32_t iextdefsym;      // index to externally defined symbols
+      uint32_t nextdefsym;      // number of externally defined symbols
+      uint32_t iundefsym;       // index to undefined symbols
+      uint32_t nundefsym;       // number of undefined symbols
+      uint32_t tocoff;          // file offset to table of contents
+      uint32_t ntoc;            // number of entries in table of contents
+      uint32_t modtaboff;       // file offset to module table
+      uint32_t nmodtab;         // number of module table entries
+      uint32_t extrefsymoff;    // offset to referenced symbol table
+      uint32_t nextrefsyms;     // number of referenced symbol table entries
+      uint32_t indirectsymoff;  // file offset to the indirect symbol table
+      uint32_t nindirectsyms;   // number of indirect symbol table entries
+      uint32_t extreloff;       // offset to external relocation entries
+      uint32_t nextrel;         // number of external relocation entries
+      uint32_t locreloff;       // offset to local relocation entries
+      uint32_t nlocrel;         // number of local relocation entries
+
+      // Constants for the cmd field
+      // see <mach-o/loader.h>
+      enum { LC_DYSYMTAB = 0x0B  // dynamic link-edit symbol table info
+      };
+      
+      MachODySymTab() : cmd(LC_DYSYMTAB), cmdsize(20 * sizeof(uint32_t)),
+        ilocalsym(0), nlocalsym(0), iextdefsym(0), nextdefsym(0),
+        iundefsym(0), nundefsym(0), tocoff(0), ntoc(0), modtaboff(0),
+        nmodtab(0), extrefsymoff(0), nextrefsyms(0), indirectsymoff(0),
+        nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) { }
+    };
+
+} // end namespace llvm
+
+#endif
+

Added: vendor/llvm/dist/lib/CodeGen/MachOCodeEmitter.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/llvm/dist/lib/CodeGen/MachOCodeEmitter.cpp	Wed Jun  3 13:28:00 2009	(r193378)
@@ -0,0 +1,207 @@
+//===-- MachOEmitter.cpp - Target-independent Mach-O Emitter code --------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "MachOCodeEmitter.h"
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/MachineJumpTableInfo.h"
+#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Support/Mangler.h"
+#include "llvm/Support/OutputBuffer.h"
+
+//===----------------------------------------------------------------------===//
+//                       MachOCodeEmitter Implementation
+//===----------------------------------------------------------------------===//
+
+namespace llvm {
+    
+/// startFunction - This callback is invoked when a new machine function is
+/// about to be emitted.
+
+void MachOCodeEmitter::startFunction(MachineFunction &MF) {
+  const TargetData *TD = TM.getTargetData();
+  const Function *F = MF.getFunction();
+
+  // Align the output buffer to the appropriate alignment, power of 2.
+  unsigned FnAlign = F->getAlignment();
+  unsigned TDAlign = TD->getPrefTypeAlignment(F->getType());
+  unsigned Align = Log2_32(std::max(FnAlign, TDAlign));
+  assert(!(Align & (Align-1)) && "Alignment is not a power of two!");
+
+  // Get the Mach-O Section that this function belongs in.
+  MachOSection *MOS = MOW.getTextSection();
+  
+  // FIXME: better memory management
+  MOS->SectionData.reserve(4096);
+  BufferBegin = &MOS->SectionData[0];
+  BufferEnd = BufferBegin + MOS->SectionData.capacity();
+
+  // Upgrade the section alignment if required.
+  if (MOS->align < Align) MOS->align = Align;
+
+  // Round the size up to the correct alignment for starting the new function.
+  if ((MOS->size & ((1 << Align) - 1)) != 0) {
+    MOS->size += (1 << Align);
+    MOS->size &= ~((1 << Align) - 1);
+  }
+
+  // FIXME: Using MOS->size directly here instead of calculating it from the
+  // output buffer size (impossible because the code emitter deals only in raw
+  // bytes) forces us to manually synchronize size and write padding zero bytes
+  // to the output buffer for all non-text sections.  For text sections, we do
+  // not synchonize the output buffer, and we just blow up if anyone tries to
+  // write non-code to it.  An assert should probably be added to
+  // AddSymbolToSection to prevent calling it on the text section.
+  CurBufferPtr = BufferBegin + MOS->size;
+}
+
+/// finishFunction - This callback is invoked after the function is completely
+/// finished.
+
+bool MachOCodeEmitter::finishFunction(MachineFunction &MF) {
+    
+  // Get the Mach-O Section that this function belongs in.
+  MachOSection *MOS = MOW.getTextSection();
+
+  // Get a symbol for the function to add to the symbol table
+  // FIXME: it seems like we should call something like AddSymbolToSection
+  // in startFunction rather than changing the section size and symbol n_value
+  // here.
+  const GlobalValue *FuncV = MF.getFunction();
+  MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TAI);
+  FnSym.n_value = MOS->size;
+  MOS->size = CurBufferPtr - BufferBegin;
+  
+  // Emit constant pool to appropriate section(s)
+  emitConstantPool(MF.getConstantPool());
+
+  // Emit jump tables to appropriate section
+  emitJumpTables(MF.getJumpTableInfo());
+  
+  // If we have emitted any relocations to function-specific objects such as 
+  // basic blocks, constant pools entries, or jump tables, record their
+  // addresses now so that we can rewrite them with the correct addresses
+  // later.
+  for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
+    MachineRelocation &MR = Relocations[i];
+    intptr_t Addr;
+
+    if (MR.isBasicBlock()) {
+      Addr = getMachineBasicBlockAddress(MR.getBasicBlock());
+      MR.setConstantVal(MOS->Index);
+      MR.setResultPointer((void*)Addr);
+    } else if (MR.isJumpTableIndex()) {
+      Addr = getJumpTableEntryAddress(MR.getJumpTableIndex());
+      MR.setConstantVal(MOW.getJumpTableSection()->Index);
+      MR.setResultPointer((void*)Addr);
+    } else if (MR.isConstantPoolIndex()) {
+      Addr = getConstantPoolEntryAddress(MR.getConstantPoolIndex());
+      MR.setConstantVal(CPSections[MR.getConstantPoolIndex()]);
+      MR.setResultPointer((void*)Addr);
+    } else if (MR.isGlobalValue()) {
+      // FIXME: This should be a set or something that uniques
+      MOW.PendingGlobals.push_back(MR.getGlobalValue());
+    } else {
+      assert(0 && "Unhandled relocation type");
+    }
+    MOS->Relocations.push_back(MR);
+  }
+  Relocations.clear();
+  
+  // Finally, add it to the symtab.
+  MOW.SymbolTable.push_back(FnSym);
+
+  // Clear per-function data structures.
+  CPLocations.clear();
+  CPSections.clear();
+  JTLocations.clear();
+  MBBLocations.clear();
+
+  return false;
+}
+
+/// emitConstantPool - For each constant pool entry, figure out which section
+/// the constant should live in, allocate space for it, and emit it to the 
+/// Section data buffer.
+void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) {
+  const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
+  if (CP.empty()) return;
+
+  // FIXME: handle PIC codegen
+  assert(TM.getRelocationModel() != Reloc::PIC_ &&
+         "PIC codegen not yet handled for mach-o jump tables!");
+
+  // Although there is no strict necessity that I am aware of, we will do what
+  // gcc for OS X does and put each constant pool entry in a section of constant
+  // objects of a certain size.  That means that float constants go in the
+  // literal4 section, and double objects go in literal8, etc.
+  //
+  // FIXME: revisit this decision if we ever do the "stick everything into one
+  // "giant object for PIC" optimization.
+  for (unsigned i = 0, e = CP.size(); i != e; ++i) {
+    const Type *Ty = CP[i].getType();
+    unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty);
+
+    MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal);
+    OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
+
+    CPLocations.push_back(Sec->SectionData.size());
+    CPSections.push_back(Sec->Index);
+    
+    // FIXME: remove when we have unified size + output buffer
+    Sec->size += Size;
+
+    // Allocate space in the section for the global.
+    // FIXME: need alignment?
+    // FIXME: share between here and AddSymbolToSection?
+    for (unsigned j = 0; j < Size; ++j)
+      SecDataOut.outbyte(0);
+
+    MOW.InitMem(CP[i].Val.ConstVal, &Sec->SectionData[0], CPLocations[i],
+                TM.getTargetData(), Sec->Relocations);
+  }
+}
+
+/// emitJumpTables - Emit all the jump tables for a given jump table info
+/// record to the appropriate section.
+
+void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) {
+  const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
+  if (JT.empty()) return;
+
+  // FIXME: handle PIC codegen
+  assert(TM.getRelocationModel() != Reloc::PIC_ &&
+         "PIC codegen not yet handled for mach-o jump tables!");
+
+  MachOSection *Sec = MOW.getJumpTableSection();
+  unsigned TextSecIndex = MOW.getTextSection()->Index;
+  OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian);
+
+  for (unsigned i = 0, e = JT.size(); i != e; ++i) {
+    // For each jump table, record its offset from the start of the section,
+    // reserve space for the relocations to the MBBs, and add the relocations.
+    const std::vector<MachineBasicBlock*> &MBBs = JT[i].MBBs;
+    JTLocations.push_back(Sec->SectionData.size());
+    for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) {
+      MachineRelocation MR(MOW.GetJTRelocation(Sec->SectionData.size(),
+                                               MBBs[mi]));
+      MR.setResultPointer((void *)JTLocations[i]);
+      MR.setConstantVal(TextSecIndex);
+      Sec->Relocations.push_back(MR);
+      SecDataOut.outaddr(0);
+    }
+  }
+  // FIXME: remove when we have unified size + output buffer
+  Sec->size = Sec->SectionData.size();
+}
+
+} // end namespace llvm
+

Added: vendor/llvm/dist/lib/CodeGen/MachOCodeEmitter.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/llvm/dist/lib/CodeGen/MachOCodeEmitter.h	Wed Jun  3 13:28:00 2009	(r193378)
@@ -0,0 +1,129 @@
+//===-- MachOEmitter.h - Target-independent Mach-O Emitter class ----------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MACHOCODEEMITTER_H
+#define MACHOCODEEMITTER_H
+
+#include "MachOWriter.h"
+#include "llvm/CodeGen/MachineCodeEmitter.h"
+#include <vector>
+
+namespace llvm {
+
+/// MachOCodeEmitter - This class is used by the MachOWriter to emit the code 
+/// for functions to the Mach-O file.
+
+class MachOCodeEmitter : public MachineCodeEmitter {
+  MachOWriter &MOW;
+
+  /// Target machine description.
+  TargetMachine &TM;
+
+  /// is64Bit/isLittleEndian - This information is inferred from the target
+  /// machine directly, indicating what header values and flags to set.
+  bool is64Bit, isLittleEndian;
+
+  const TargetAsmInfo *TAI;
+
+  /// Relocations - These are the relocations that the function needs, as
+  /// emitted.
+  std::vector<MachineRelocation> Relocations;
+  
+  /// CPLocations - This is a map of constant pool indices to offsets from the
+  /// start of the section for that constant pool index.
+  std::vector<uintptr_t> CPLocations;
+
+  /// CPSections - This is a map of constant pool indices to the MachOSection
+  /// containing the constant pool entry for that index.
+  std::vector<unsigned> CPSections;
+
+  /// JTLocations - This is a map of jump table indices to offsets from the
+  /// start of the section for that jump table index.
+  std::vector<uintptr_t> JTLocations;
+
+  /// MBBLocations - This vector is a mapping from MBB ID's to their address.
+  /// It is filled in by the StartMachineBasicBlock callback and queried by
+  /// the getMachineBasicBlockAddress callback.
+  std::vector<uintptr_t> MBBLocations;
+  
+public:
+  MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM)
+  {
+    is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
+    isLittleEndian = TM.getTargetData()->isLittleEndian();
+    TAI = TM.getTargetAsmInfo();  
+  }
+
+  virtual void startFunction(MachineFunction &MF);
+  virtual bool finishFunction(MachineFunction &MF);
+
+  virtual void addRelocation(const MachineRelocation &MR) {
+    Relocations.push_back(MR);
+  }
+  
+  void emitConstantPool(MachineConstantPool *MCP);
+  void emitJumpTables(MachineJumpTableInfo *MJTI);
+  
+  virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
+    assert(CPLocations.size() > Index && "CP not emitted!");
+    return CPLocations[Index];
+  }
+  virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const {
+    assert(JTLocations.size() > Index && "JT not emitted!");
+    return JTLocations[Index];
+  }
+
+  virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) {
+    if (MBBLocations.size() <= (unsigned)MBB->getNumber())
+      MBBLocations.resize((MBB->getNumber()+1)*2);
+    MBBLocations[MBB->getNumber()] = getCurrentPCOffset();
+  }
+
+  virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
+    assert(MBBLocations.size() > (unsigned)MBB->getNumber() && 
+           MBBLocations[MBB->getNumber()] && "MBB not emitted!");
+    return MBBLocations[MBB->getNumber()];
+  }
+
+  virtual uintptr_t getLabelAddress(uint64_t Label) const {
+    assert(0 && "get Label not implemented");
+    abort();
+    return 0;
+  }
+
+  virtual void emitLabel(uint64_t LabelID) {
+    assert(0 && "emit Label not implemented");
+    abort();
+  }
+
+  virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
+
+  /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
+  virtual void startGVStub(const GlobalValue* F, unsigned StubSize,
+                           unsigned Alignment = 1) {
+    assert(0 && "JIT specific function called!");
+    abort();
+  }
+  virtual void startGVStub(const GlobalValue* F, void *Buffer, 
+                           unsigned StubSize) {
+    assert(0 && "JIT specific function called!");
+    abort();
+  }
+  virtual void *finishGVStub(const GlobalValue* F) {
+    assert(0 && "JIT specific function called!");
+    abort();
+    return 0;
+  }
+
+}; // end class MachOCodeEmitter
+
+} // end namespace llvm
+
+#endif
+

Modified: vendor/llvm/dist/lib/CodeGen/MachOWriter.cpp
==============================================================================
--- vendor/llvm/dist/lib/CodeGen/MachOWriter.cpp	Wed Jun  3 13:25:50 2009	(r193377)
+++ vendor/llvm/dist/lib/CodeGen/MachOWriter.cpp	Wed Jun  3 13:28:00 2009	(r193378)
@@ -23,6 +23,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "MachOWriter.h"
+#include "MachOCodeEmitter.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
@@ -40,11 +41,12 @@
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cstring>
-using namespace llvm;
+
+namespace llvm {
 
 /// AddMachOWriter - Concrete function to add the Mach-O writer to the function
 /// pass manager.
-MachineCodeEmitter *llvm::AddMachOWriter(PassManagerBase &PM,
+MachineCodeEmitter *AddMachOWriter(PassManagerBase &PM,
                                          raw_ostream &O,
                                          TargetMachine &TM) {
   MachOWriter *MOW = new MachOWriter(O, TM);
@@ -53,304 +55,74 @@ MachineCodeEmitter *llvm::AddMachOWriter
 }
 
 //===----------------------------------------------------------------------===//
-//                       MachOCodeEmitter Implementation
+//                          MachOWriter Implementation
 //===----------------------------------------------------------------------===//
 
-namespace llvm {
-  /// MachOCodeEmitter - This class is used by the MachOWriter to emit the code 
-  /// for functions to the Mach-O file.
-  class MachOCodeEmitter : public MachineCodeEmitter {
-    MachOWriter &MOW;
-
-    /// Target machine description.
-    TargetMachine &TM;
-
-    /// is64Bit/isLittleEndian - This information is inferred from the target
-    /// machine directly, indicating what header values and flags to set.
-    bool is64Bit, isLittleEndian;
-
-    /// Relocations - These are the relocations that the function needs, as
-    /// emitted.
-    std::vector<MachineRelocation> Relocations;
-    
-    /// CPLocations - This is a map of constant pool indices to offsets from the
-    /// start of the section for that constant pool index.
-    std::vector<uintptr_t> CPLocations;
-
-    /// CPSections - This is a map of constant pool indices to the MachOSection
-    /// containing the constant pool entry for that index.
-    std::vector<unsigned> CPSections;
-
-    /// JTLocations - This is a map of jump table indices to offsets from the
-    /// start of the section for that jump table index.
-    std::vector<uintptr_t> JTLocations;
-
-    /// MBBLocations - This vector is a mapping from MBB ID's to their address.
-    /// It is filled in by the StartMachineBasicBlock callback and queried by
-    /// the getMachineBasicBlockAddress callback.
-    std::vector<uintptr_t> MBBLocations;
-    
-  public:
-    MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) {
-      is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
-      isLittleEndian = TM.getTargetData()->isLittleEndian();
-    }

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-vendor mailing list