[llvm-commits] [dragonegg] r109343 - in /dragonegg/trunk: llvm-abi-default.cpp llvm-abi.h llvm-backend.cpp llvm-cache.c llvm-cache.h llvm-convert.cpp llvm-debug.cpp llvm-debug.h llvm-internal.h llvm-types.cpp x86/llvm-target.cpp x86/llvm-target.h

Duncan Sands baldrick at free.fr
Sat Jul 24 09:44:47 PDT 2010


Author: baldrick
Date: Sat Jul 24 11:44:47 2010
New Revision: 109343

URL: http://llvm.org/viewvc/llvm-project?rev=109343&view=rev
Log:
Get dragonegg compiling again with the latest gcc-4.5 and LLVM.  The
problem is that gcc likes to poison various declarations (like malloc)
in its header files, so if an LLVM header makes use of malloc and the
gcc header is included first, then the compile fails.  Solve this by
always including gcc headers after LLVM headers.  The tricky bit is
sorting out dragonegg's own headers, which include LLVM and gcc headers,
so including two dragonegg headers in a row breaks the rule of "LLVM
headers first".  The solution is to never include any gcc headers in
a dragonegg header, and instead use forward declarations.  This meant
moving some inline code out of headers.

Modified:
    dragonegg/trunk/llvm-abi-default.cpp
    dragonegg/trunk/llvm-abi.h
    dragonegg/trunk/llvm-backend.cpp
    dragonegg/trunk/llvm-cache.c
    dragonegg/trunk/llvm-cache.h
    dragonegg/trunk/llvm-convert.cpp
    dragonegg/trunk/llvm-debug.cpp
    dragonegg/trunk/llvm-debug.h
    dragonegg/trunk/llvm-internal.h
    dragonegg/trunk/llvm-types.cpp
    dragonegg/trunk/x86/llvm-target.cpp
    dragonegg/trunk/x86/llvm-target.h

Modified: dragonegg/trunk/llvm-abi-default.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-abi-default.cpp?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-abi-default.cpp (original)
+++ dragonegg/trunk/llvm-abi-default.cpp Sat Jul 24 11:44:47 2010
@@ -1,5 +1,98 @@
+// Plugin headers
 #include "llvm-abi.h"
 
+// System headers
+#include <gmp.h>
+
+// GCC headers
+extern "C" {
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "tree.h"
+}
+
+// doNotUseShadowReturn - Return true if the specified GCC type
+// should not be returned using a pointer to struct parameter.
+bool doNotUseShadowReturn(tree type, tree fndecl, CallingConv::ID CC) {
+  if (!TYPE_SIZE(type))
+    return false;
+  if (TREE_CODE(TYPE_SIZE(type)) != INTEGER_CST)
+    return false;
+  // LLVM says do not use shadow argument.
+  if (LLVM_SHOULD_NOT_RETURN_COMPLEX_IN_MEMORY(type) ||
+      LLVM_SHOULD_NOT_USE_SHADOW_RETURN(type, CC))
+    return true;
+  // GCC says use shadow argument.
+  if (aggregate_value_p(type, fndecl))
+    return false;
+  return true;
+}
+
+/// isSingleElementStructOrArray - If this is (recursively) a structure with one
+/// field or an array with one element, return the field type, otherwise return
+/// null.  If ignoreZeroLength, the struct (recursively) may include zero-length
+/// fields in addition to the single element that has data.  If
+/// rejectFatBitField, and the single element is a bitfield of a type that's
+/// bigger than the struct, return null anyway.
+tree isSingleElementStructOrArray(tree type, bool ignoreZeroLength,
+                                  bool rejectFatBitfield) {
+  // Scalars are good.
+  if (!AGGREGATE_TYPE_P(type)) return type;
+
+  tree FoundField = 0;
+  switch (TREE_CODE(type)) {
+  case QUAL_UNION_TYPE:
+  case UNION_TYPE:     // Single element unions don't count.
+  case COMPLEX_TYPE:   // Complex values are like 2-element records.
+  default:
+    return 0;
+  case RECORD_TYPE:
+    // If this record has variable length, reject it.
+    if (TREE_CODE(TYPE_SIZE(type)) != INTEGER_CST)
+      return 0;
+
+    for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field))
+      if (TREE_CODE(Field) == FIELD_DECL) {
+        if (ignoreZeroLength) {
+          if (DECL_SIZE(Field) &&
+              TREE_CODE(DECL_SIZE(Field)) == INTEGER_CST &&
+              TREE_INT_CST_LOW(DECL_SIZE(Field)) == 0)
+            continue;
+        }
+        if (!FoundField) {
+          if (rejectFatBitfield &&
+              TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST &&
+              TREE_INT_CST_LOW(TYPE_SIZE(TREE_TYPE(Field))) >
+              TREE_INT_CST_LOW(TYPE_SIZE(type)))
+            return 0;
+          FoundField = TREE_TYPE(Field);
+        } else {
+          return 0;   // More than one field.
+        }
+      }
+    return FoundField ? isSingleElementStructOrArray(FoundField,
+                                                     ignoreZeroLength, false)
+                      : 0;
+  case ARRAY_TYPE:
+    const ArrayType *Ty = dyn_cast<ArrayType>(ConvertType(type));
+    if (!Ty || Ty->getNumElements() != 1)
+      return 0;
+    return isSingleElementStructOrArray(TREE_TYPE(type), false, false);
+  }
+}
+
+/// isZeroSizedStructOrUnion - Returns true if this is a struct or union
+/// which is zero bits wide.
+bool isZeroSizedStructOrUnion(tree type) {
+  if (TREE_CODE(type) != RECORD_TYPE &&
+      TREE_CODE(type) != UNION_TYPE &&
+      TREE_CODE(type) != QUAL_UNION_TYPE)
+    return false;
+  return int_size_in_bytes(type) == 0;
+}
+
 DefaultABI::DefaultABI(DefaultABIClient &c) : C(c) {}
 
 bool DefaultABI::isShadowReturn() const { return C.isShadowReturn(); }

Modified: dragonegg/trunk/llvm-abi.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-abi.h?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-abi.h (original)
+++ dragonegg/trunk/llvm-abi.h Sat Jul 24 11:44:47 2010
@@ -28,30 +28,18 @@
 #ifndef LLVM_ABI_H
 #define LLVM_ABI_H
 
+// Plugin headers
+#include "llvm-internal.h"
+#include "llvm-target.h"
+
 // LLVM headers
 #include "llvm/Attributes.h"
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/LLVMContext.h"
-#include "llvm/Target/TargetData.h"
 #include "llvm/Support/Compiler.h"
-
-// System headers
-#include <gmp.h>
-
-// GCC headers
-extern "C" {
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "tm.h"
-#include "tree.h"
-}
-
-// Plugin headers
-#include "llvm-internal.h"
-#include "llvm-target.h"
+#include "llvm/Target/TargetData.h"
 
 namespace llvm {
   class BasicBlock;
@@ -96,21 +84,22 @@
   /// LLVM argument to pass.  It is only used for first class types.
   /// If RealSize is non Zero then it specifies number of bytes to access
   /// from LLVMTy.
-  virtual void HandleScalarArgument(const llvm::Type *LLVMTy, tree type,
+  virtual void HandleScalarArgument(const llvm::Type *LLVMTy, tree_node *type,
                             unsigned RealSize = 0) {}
 
   /// HandleByInvisibleReferenceArgument - This callback is invoked if a pointer
   /// (of type PtrTy) to the argument is passed rather than the argument itself.
-  virtual void HandleByInvisibleReferenceArgument(const llvm::Type *PtrTy, tree type) {}
+  virtual void HandleByInvisibleReferenceArgument(const llvm::Type *PtrTy,
+                                                  tree_node *type) {}
 
   /// HandleByValArgument - This callback is invoked if the aggregate function
   /// argument is passed by value.
-  virtual void HandleByValArgument(const llvm::Type *LLVMTy, tree type) {}
+  virtual void HandleByValArgument(const llvm::Type *LLVMTy, tree_node *type) {}
 
   /// HandleFCAArgument - This callback is invoked if the aggregate function
   /// argument is passed by value as a first class aggregate.
   virtual void HandleFCAArgument(const llvm::Type *LLVMTy,
-                         tree type ATTRIBUTE_UNUSED) {}
+                                 tree_node *type ATTRIBUTE_UNUSED) {}
 
   /// EnterField - Called when we're about the enter the field of a struct
   /// or union.  FieldNo is the number of the element we are entering in the
@@ -137,21 +126,8 @@
 
 // doNotUseShadowReturn - Return true if the specified GCC type
 // should not be returned using a pointer to struct parameter.
-static inline bool doNotUseShadowReturn(tree type, tree fndecl,
-                                        CallingConv::ID CC) {
-  if (!TYPE_SIZE(type))
-    return false;
-  if (TREE_CODE(TYPE_SIZE(type)) != INTEGER_CST)
-    return false;
-  // LLVM says do not use shadow argument.
-  if (LLVM_SHOULD_NOT_RETURN_COMPLEX_IN_MEMORY(type) ||
-     LLVM_SHOULD_NOT_USE_SHADOW_RETURN(type, CC))
-    return true;
-  // GCC says use shadow argument.
-  if (aggregate_value_p(type, fndecl))
-    return false;
-  return true;
-}
+extern bool doNotUseShadowReturn(tree_node *type, tree_node *fndecl,
+                                 CallingConv::ID CC);
 
 /// isSingleElementStructOrArray - If this is (recursively) a structure with one
 /// field or an array with one element, return the field type, otherwise return
@@ -159,69 +135,19 @@
 /// fields in addition to the single element that has data.  If
 /// rejectFatBitField, and the single element is a bitfield of a type that's
 /// bigger than the struct, return null anyway.
-static inline
-tree isSingleElementStructOrArray(tree type, bool ignoreZeroLength,
-                                  bool rejectFatBitfield) {
-  // Scalars are good.
-  if (!AGGREGATE_TYPE_P(type)) return type;
-
-  tree FoundField = 0;
-  switch (TREE_CODE(type)) {
-  case QUAL_UNION_TYPE:
-  case UNION_TYPE:     // Single element unions don't count.
-  case COMPLEX_TYPE:   // Complex values are like 2-element records.
-  default:
-    return 0;
-  case RECORD_TYPE:
-    // If this record has variable length, reject it.
-    if (TREE_CODE(TYPE_SIZE(type)) != INTEGER_CST)
-      return 0;
-
-    for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field))
-      if (TREE_CODE(Field) == FIELD_DECL) {
-        if (ignoreZeroLength) {
-          if (DECL_SIZE(Field) &&
-              TREE_CODE(DECL_SIZE(Field)) == INTEGER_CST &&
-              TREE_INT_CST_LOW(DECL_SIZE(Field)) == 0)
-            continue;
-        }
-        if (!FoundField) {
-          if (rejectFatBitfield &&
-              TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST &&
-              TREE_INT_CST_LOW(TYPE_SIZE(TREE_TYPE(Field))) >
-              TREE_INT_CST_LOW(TYPE_SIZE(type)))
-            return 0;
-          FoundField = TREE_TYPE(Field);
-        } else {
-          return 0;   // More than one field.
-        }
-      }
-    return FoundField ? isSingleElementStructOrArray(FoundField,
-                                                     ignoreZeroLength, false)
-                      : 0;
-  case ARRAY_TYPE:
-    const ArrayType *Ty = dyn_cast<ArrayType>(ConvertType(type));
-    if (!Ty || Ty->getNumElements() != 1)
-      return 0;
-    return isSingleElementStructOrArray(TREE_TYPE(type), false, false);
-  }
-}
+extern tree_node *isSingleElementStructOrArray(tree_node *type,
+                                               bool ignoreZeroLength,
+                                               bool rejectFatBitfield);
 
 /// isZeroSizedStructOrUnion - Returns true if this is a struct or union
 /// which is zero bits wide.
-static inline bool isZeroSizedStructOrUnion(tree type) {
-  if (TREE_CODE(type) != RECORD_TYPE &&
-      TREE_CODE(type) != UNION_TYPE &&
-      TREE_CODE(type) != QUAL_UNION_TYPE)
-    return false;
-  return int_size_in_bytes(type) == 0;
-}
+extern bool isZeroSizedStructOrUnion(tree_node *type);
 
 // getLLVMScalarTypeForStructReturn - Return LLVM Type if TY can be
 // returned as a scalar, otherwise return NULL. This is the default
 // target independent implementation.
 static inline
-const Type* getLLVMScalarTypeForStructReturn(tree type, unsigned *Offset) {
+const Type* getLLVMScalarTypeForStructReturn(tree_node *type, unsigned *Offset) {
   const Type *Ty = ConvertType(type);
   unsigned Size = getTargetData().getTypeAllocSize(Ty);
   *Offset = 0;
@@ -246,7 +172,7 @@
 // getLLVMAggregateTypeForStructReturn - Return LLVM type if TY can be
 // returns as multiple values, otherwise return NULL. This is the default
 // target independent implementation.
-static inline const Type* getLLVMAggregateTypeForStructReturn(tree type) {
+static inline const Type* getLLVMAggregateTypeForStructReturn(tree_node *type) {
   return NULL;
 }
 
@@ -394,24 +320,25 @@
   /// return type. It potentially breaks down the argument and invokes methods
   /// on the client that indicate how its pieces should be handled.  This
   /// handles things like returning structures via hidden parameters.
-  void HandleReturnType(tree type, tree fn, bool isBuiltin);
+  void HandleReturnType(tree_node *type, tree_node *fn, bool isBuiltin);
 
   /// HandleArgument - This is invoked by the target-independent code for each
   /// argument type passed into the function.  It potentially breaks down the
   /// argument and invokes methods on the client that indicate how its pieces
   /// should be handled.  This handles things like decimating structures into
   /// their fields.
-  void HandleArgument(tree type, std::vector<const Type*> &ScalarElts,
+  void HandleArgument(tree_node *type, std::vector<const Type*> &ScalarElts,
                       Attributes *Attributes = NULL);
 
   /// HandleUnion - Handle a UNION_TYPE or QUAL_UNION_TYPE tree.
   ///
-  void HandleUnion(tree type, std::vector<const Type*> &ScalarElts);
+  void HandleUnion(tree_node *type, std::vector<const Type*> &ScalarElts);
 
   /// PassInIntegerRegisters - Given an aggregate value that should be passed in
   /// integer registers, convert it to a structure containing ints and pass all
   /// of the struct elements in.  If Size is set we pass only that many bytes.
-  void PassInIntegerRegisters(tree type, std::vector<const Type*> &ScalarElts,
+  void PassInIntegerRegisters(tree_node *type,
+                              std::vector<const Type*> &ScalarElts,
                               unsigned origSize, bool DontCheckAlignment);
 
   /// PassInMixedRegisters - Given an aggregate value that should be passed in

Modified: dragonegg/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-backend.cpp?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-backend.cpp (original)
+++ dragonegg/trunk/llvm-backend.cpp Sat Jul 24 11:44:47 2010
@@ -19,6 +19,15 @@
 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.  */
 
+// Plugin headers
+extern "C" {
+#include "llvm-cache.h"
+}
+#include "llvm-debug.h"
+#include "llvm-internal.h"
+#include "llvm-os.h"
+#include "llvm-target.h"
+
 // LLVM headers
 #define DEBUG_TYPE "plugin"
 #include "llvm/Constants.h"
@@ -27,28 +36,28 @@
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/ValueSymbolTable.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/Verifier.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/Assembly/PrintModulePass.h"
+#include "llvm/Assembly/Writer.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/CodeGen/RegAllocRegistry.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/StandardPasses.h"
+#include "llvm/System/Program.h"
 #include "llvm/Target/SubtargetFeature.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/Scalar.h"
+#include "llvm/Target/TargetRegistry.h"
 #include "llvm/Transforms/IPO.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/StandardPasses.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/System/Program.h"
+#include "llvm/Transforms/Scalar.h"
 
 // System headers
 #include <cassert>
@@ -81,15 +90,6 @@
 #include "except.h"
 }
 
-// Plugin headers
-#include "llvm-internal.h"
-#include "llvm-debug.h"
-#include "llvm-target.h"
-#include "llvm-os.h"
-extern "C" {
-#include "llvm-cache.h"
-}
-
 #if (GCC_MAJOR != 4)
 #error Unsupported GCC major version
 #endif

Modified: dragonegg/trunk/llvm-cache.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-cache.c?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-cache.c (original)
+++ dragonegg/trunk/llvm-cache.c Sat Jul 24 11:44:47 2010
@@ -28,6 +28,11 @@
 #include "llvm-cache.h"
 
 // GCC headers
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "target.h"
+#include "tree.h"
 #include "ggc.h"
 
 struct GTY(()) tree_llvm_map {
@@ -47,7 +52,7 @@
 #include "gt-llvm-cache.h"
 
 /// llvm_has_cached - Returns whether a value has been associated with the tree.
-bool llvm_has_cached(union tree_node *tree) {
+int llvm_has_cached(union tree_node *tree) {
   struct tree_map_base in;
 
   if (!llvm_cache)

Modified: dragonegg/trunk/llvm-cache.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-cache.h?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-cache.h (original)
+++ dragonegg/trunk/llvm-cache.h Sat Jul 24 11:44:47 2010
@@ -28,14 +28,10 @@
 #ifndef LLVM_CACHE_H
 #define LLVM_CACHE_H
 
-#include "config.h"
-#include "system.h"
-#include "coretypes.h"
-#include "target.h"
-#include "tree.h"
+union tree_node;
 
 /// llvm_has_cached - Returns whether a value has been associated with the tree.
-extern bool llvm_has_cached(union tree_node *tree);
+extern int llvm_has_cached(union tree_node *tree);
 
 /// llvm_get_cached - Returns the value associated with the tree, or NULL.
 extern const void *llvm_get_cached(union tree_node *tree);

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Sat Jul 24 11:44:47 2010
@@ -23,8 +23,12 @@
 // This is the code that converts GCC AST nodes into LLVM code.
 //===----------------------------------------------------------------------===//
 
+// Plugin headers
+#include "llvm-abi.h"
+#include "llvm-debug.h"
+#include "llvm-internal.h"
+
 // LLVM headers
-#include "llvm/ValueSymbolTable.h"
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -32,20 +36,21 @@
 #include "llvm/Instructions.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/Analysis/ConstantFolding.h"
-#include "llvm/System/Host.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/ValueHandle.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ValueHandle.h"
+#include "llvm/System/Host.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetMachine.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/DenseMap.h"
 
 // System headers
 #include <gmp.h>
@@ -78,11 +83,6 @@
 extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
 }
 
-// Plugin headers
-#include "llvm-abi.h"
-#include "llvm-internal.h"
-#include "llvm-debug.h"
-
 static LLVMContext &Context = getGlobalContext();
 
 STATISTIC(NumBasicBlocks, "Number of basic blocks converted");
@@ -5884,6 +5884,12 @@
   return ConvertType(type);
 }
 
+/// EmitMemory - Convert the specified gimple register or local constant of
+/// register type to an LLVM value with in-memory type (given by ConvertType).
+Value *TreeToLLVM::EmitMemory(tree reg) {
+  return Reg2Mem(EmitRegister(reg), TREE_TYPE(reg), Builder);
+}
+
 /// EmitRegister - Convert the specified gimple register or local constant of
 /// register type to an LLVM value.  Only creates code in the entry block.
 Value *TreeToLLVM::EmitRegister(tree reg) {
@@ -6044,7 +6050,7 @@
 
 /// EmitCompare - Compare LHS with RHS using the appropriate comparison code.
 /// The result is an i1 boolean.
-Value *TreeToLLVM::EmitCompare(tree lhs, tree rhs, tree_code code) {
+Value *TreeToLLVM::EmitCompare(tree lhs, tree rhs, unsigned code) {
   Value *LHS = EmitRegister(lhs);
   Value *RHS = UselesslyTypeConvert(EmitRegister(rhs), LHS->getType());
 

Modified: dragonegg/trunk/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-debug.cpp?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-debug.cpp (original)
+++ dragonegg/trunk/llvm-debug.cpp Sat Jul 24 11:44:47 2010
@@ -23,18 +23,22 @@
 // This is a C++ source file that implements the debug information gathering.
 //===----------------------------------------------------------------------===//
 
+// Plugin headers
+#include "llvm-abi.h"
+#include "llvm-debug.h"
+#include "llvm-internal.h"
+
 // LLVM headers
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instructions.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/Module.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Analysis/DebugInfo.h"
-#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/SmallVector.h"
 
 // System headers
 #include <gmp.h>
@@ -53,11 +57,6 @@
 #include "version.h"
 }
 
-// Plugin headers
-#include "llvm-abi.h"
-#include "llvm-debug.h"
-#include "llvm-internal.h"
-
 using namespace llvm;
 using namespace llvm::dwarf;
 

Modified: dragonegg/trunk/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-debug.h?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-debug.h (original)
+++ dragonegg/trunk/llvm-debug.h Sat Jul 24 11:44:47 2010
@@ -27,14 +27,18 @@
 #ifndef LLVM_DEBUG_H
 #define LLVM_DEBUG_H
 
+// Plugin headers
+#include "llvm-internal.h"
+
 // LLVM headers
 #include "llvm/Analysis/DebugInfo.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/ValueHandle.h"
 
 // System headers
-#include <string>
 #include <map>
+#include <string>
 #include <vector>
 
 namespace llvm {

Modified: dragonegg/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-internal.h?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-internal.h (original)
+++ dragonegg/trunk/llvm-internal.h Sat Jul 24 11:44:47 2010
@@ -35,13 +35,17 @@
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Support/IRBuilder.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/TargetFolder.h"
 #include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/TargetFolder.h"
 
 // System headers
-#include <vector>
 #include <cassert>
 #include <string>
+#include <vector>
+
+struct basic_block_def;
+union gimple_statement_d;
+union tree_node;
 
 namespace llvm {
   class Module;
@@ -104,26 +108,26 @@
 /// AttributeUsedGlobals - The list of globals that are marked attribute(used).
 extern SmallSetVector<Constant *,32> AttributeUsedGlobals;
 
-extern Constant* ConvertMetadataStringToGV(const char* str);
+extern Constant* ConvertMetadataStringToGV(const char *str);
 
 /// AddAnnotateAttrsToGlobal - Adds decls that have a
 /// annotate attribute to a vector to be emitted later.
-extern void AddAnnotateAttrsToGlobal(GlobalValue *GV, union tree_node* decl);
+extern void AddAnnotateAttrsToGlobal(GlobalValue *GV, tree_node *decl);
 
 // Mapping between GCC declarations and LLVM values.  The GCC declaration must
 // satisfy HAS_RTL_P.
 
 /// DECL_LLVM - Returns the LLVM declaration of a global variable or function.
-extern Value *make_decl_llvm(union tree_node *);
+extern Value *make_decl_llvm(tree_node *);
 #define DECL_LLVM(NODE) make_decl_llvm(NODE)
 
 /// SET_DECL_LLVM - Set the DECL_LLVM for NODE to LLVM.
-extern Value *set_decl_llvm(union tree_node *, Value *);
+extern Value *set_decl_llvm(tree_node *, Value *);
 #define SET_DECL_LLVM(NODE, LLVM) set_decl_llvm(NODE, LLVM)
 
 /// DECL_LLVM_IF_SET - The DECL_LLVM for NODE, if it is set, or NULL, if it is
 /// not set.
-extern Value *get_decl_llvm(union tree_node *);
+extern Value *get_decl_llvm(tree_node *);
 #define DECL_LLVM_IF_SET(NODE) (HAS_RTL_P(NODE) ? get_decl_llvm(NODE) : NULL)
 
 /// DECL_LLVM_SET_P - Returns nonzero if the DECL_LLVM for NODE has already
@@ -132,7 +136,7 @@
 
 /// DEFINITION_LLVM - Ensures that the body or initial value of the given GCC
 /// global will be output, and returns a declaration for it.
-Value *make_definition_llvm(union tree_node *decl);
+Value *make_definition_llvm(tree_node *decl);
 #define DEFINITION_LLVM(NODE) make_definition_llvm(NODE)
 
 // Mapping between GCC declarations and non-negative integers.  The GCC
@@ -140,11 +144,11 @@
 
 /// set_decl_index - Associate a non-negative number with the given GCC
 /// declaration.
-int set_decl_index(union tree_node *, int);
+int set_decl_index(tree_node *, int);
 
 /// get_decl_index - Get the non-negative number associated with the given GCC
 /// declaration.  Returns a negative value if no such association has been made.
-int get_decl_index(union tree_node *);
+int get_decl_index(tree_node *);
 
 void changeLLVMConstant(Constant *Old, Constant *New);
 void register_ctor_dtor(Function *, int, bool);
@@ -153,15 +157,15 @@
 void readLLVMValues();
 void writeLLVMValues();
 void clearTargetBuiltinCache();
-const char* extractRegisterName(union tree_node*);
-void handleVisibility(union tree_node* decl, GlobalValue *GV);
-Twine getLLVMAssemblerName(union tree_node *);
+const char *extractRegisterName(tree_node *);
+void handleVisibility(tree_node *decl, GlobalValue *GV);
+Twine getLLVMAssemblerName(tree_node *);
 
 struct StructTypeConversionInfo;
 
 /// Return true if and only if field no. N from struct type T is a padding
 /// element added to match llvm struct type size and gcc struct type size.
-bool isPaddingElement(union tree_node*, unsigned N);
+bool isPaddingElement(tree_node*, unsigned N);
 
 /// TypeConverter - Implement the converter from GCC types to LLVM types.
 ///
@@ -225,17 +229,14 @@
 /// GetUnitPointerType - Returns an LLVM pointer type which points to memory one
 /// address unit wide.  For example, on a machine which has 16 bit bytes returns
 /// an i16*.
-inline const Type *GetUnitPointerType(LLVMContext &C, unsigned AddrSpace = 0) {
-  assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
-  return IntegerType::get(C, BITS_PER_UNIT)->getPointerTo(AddrSpace);
-}
+extern const Type *GetUnitPointerType(LLVMContext &C, unsigned AddrSpace = 0);
 
 /// GetFieldIndex - Return the index of the field in the given LLVM type that
 /// corresponds to the GCC field declaration 'decl'.  This means that the LLVM
 /// and GCC fields start in the same byte (if 'decl' is a bitfield, this means
 /// that its first bit is within the byte the LLVM field starts at).  Returns
 /// INT_MAX if there is no such LLVM field.
-int GetFieldIndex(union tree_node *decl, const Type *Ty);
+int GetFieldIndex(tree_node *decl, const Type *Ty);
 
 /// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t.
 ///
@@ -262,54 +263,21 @@
 /// type and the corresponding LLVM SequentialType lay out their components
 /// identically in memory, so doing a GEP accesses the right memory location.
 /// We assume that objects without a known size do not.
-inline bool isSequentialCompatible(tree_node *type) {
-  assert((TREE_CODE(type) == ARRAY_TYPE ||
-          TREE_CODE(type) == POINTER_TYPE ||
-          TREE_CODE(type) == REFERENCE_TYPE) && "not a sequential type!");
-  // This relies on gcc types with constant size mapping to LLVM types with the
-  // same size.  It is possible for the component type not to have a size:
-  // struct foo;  extern foo bar[];
-  return isInt64(TYPE_SIZE(TREE_TYPE(type)), true);
-}
+extern bool isSequentialCompatible(tree_node *type);
 
 /// OffsetIsLLVMCompatible - Return true if the given field is offset from the
 /// start of the record by a constant amount which is not humongously big.
-inline bool OffsetIsLLVMCompatible(tree_node *field_decl) {
-  return isInt64(DECL_FIELD_OFFSET(field_decl), true);
-}
+extern bool OffsetIsLLVMCompatible(tree_node *field_decl);
 
 /// ArrayLengthOf - Returns the length of the given gcc array type, or ~0ULL if
 /// the array has variable or unknown length.
-inline uint64_t ArrayLengthOf(tree_node *type) {
-  assert(TREE_CODE(type) == ARRAY_TYPE && "Only for array types!");
-  // If the element type has variable size and the array type has variable
-  // length, but by some miracle the product gives a constant size, then we
-  // also return ~0ULL here.  I can live with this, and I bet you can too!
-  if (!isInt64(TYPE_SIZE(type), true) ||
-      !isInt64(TYPE_SIZE(TREE_TYPE(type)), true))
-    return ~0ULL;
-  // May return zero for arrays that gcc considers to have non-zero length, but
-  // only if the array type has zero size (this can happen if the element type
-  // has zero size), in which case the discrepancy doesn't matter.
-  //
-  // If the user increased the alignment of the element type, then the size of
-  // the array type is rounded up by that alignment, but the size of the element
-  // is not.  Since gcc requires the user alignment to be strictly smaller than
-  // the element size, this does not impact the length computation.
-  return integer_zerop(TYPE_SIZE(type)) ?  0 : getInt64(TYPE_SIZE(type), true) /
-    getInt64(TYPE_SIZE(TREE_TYPE(type)), true);
-}
+extern uint64_t ArrayLengthOf(tree_node *type);
 
 /// isBitfield - Returns whether to treat the specified field as a bitfield.
 bool isBitfield(tree_node *field_decl);
 
 /// getFieldOffsetInBits - Return the bit offset of a FIELD_DECL in a structure.
-inline uint64_t getFieldOffsetInBits(tree_node *field) {
-  assert(OffsetIsLLVMCompatible(field) && "Offset is not constant!");
-  uint64_t Result = getInt64(DECL_FIELD_BIT_OFFSET(field), true);
-  Result += getInt64(DECL_FIELD_OFFSET(field), true) * BITS_PER_UNIT;
-  return Result;
-}
+extern uint64_t getFieldOffsetInBits(tree_node *field);
 
 /// ValidateRegisterVariable - Check that a static "asm" variable is
 /// well-formed.  If not, emit error messages and return true.  If so, return
@@ -368,7 +336,7 @@
 
 /// PhiRecord - This struct holds the LLVM PHI node associated with a GCC phi.
 struct PhiRecord {
-  gimple gcc_phi;
+  gimple_statement_d *gcc_phi;
   PHINode *PHI;
 };
 
@@ -398,7 +366,7 @@
   Instruction *SSAInsertionPoint;
 
   /// BasicBlocks - Map from GCC to LLVM basic blocks.
-  DenseMap<basic_block, BasicBlock*> BasicBlocks;
+  DenseMap<basic_block_def *, BasicBlock*> BasicBlocks;
 
   /// LocalDecls - Map from local declarations to their associated LLVM values.
   DenseMap<tree_node *, AssertingVH<Value> > LocalDecls;
@@ -416,23 +384,23 @@
   /// DECL_LOCAL - Like DECL_LLVM, returns the LLVM declaration of a variable or
   /// function.  However DECL_LOCAL can be used with declarations local to the
   /// current function as well as with global declarations.
-  Value *make_decl_local(union tree_node *);
+  Value *make_decl_local(tree_node *);
   #define DECL_LOCAL(NODE) make_decl_local(NODE)
 
   /// DEFINITION_LOCAL - Like DEFINITION_LLVM, ensures that the initial value or
   /// body of a variable or function will be output.  However DEFINITION_LOCAL
   /// can be used with declarations local to the current function as well as
   /// with global declarations.
-  Value *make_definition_local(union tree_node *);
+  Value *make_definition_local(tree_node *);
   #define DEFINITION_LOCAL(NODE) make_definition_local(NODE)
 
   /// SET_DECL_LOCAL - Set the DECL_LOCAL for NODE to LLVM.
-  Value *set_decl_local(union tree_node *, Value *);
+  Value *set_decl_local(tree_node *, Value *);
   #define SET_DECL_LOCAL(NODE, LLVM) set_decl_local(NODE, LLVM)
 
   /// DECL_LOCAL_IF_SET - The DECL_LOCAL for NODE, if it is set, or NULL, if it
   /// is not set.
-  Value *get_decl_local(union tree_node *);
+  Value *get_decl_local(tree_node *);
   #define DECL_LOCAL_IF_SET(NODE) (HAS_RTL_P(NODE) ? get_decl_local(NODE) : NULL)
 
   /// DECL_LOCAL_SET_P - Returns nonzero if the DECL_LOCAL for NODE has already
@@ -479,7 +447,7 @@
   Function *EmitFunction();
 
   /// EmitBasicBlock - Convert the given basic block.
-  void EmitBasicBlock(basic_block bb);
+  void EmitBasicBlock(basic_block_def *bb);
 
   /// EmitLV - Convert the specified l-value tree node to LLVM code, returning
   /// the address of the result.
@@ -489,22 +457,22 @@
 
   /// CastToAnyType - Cast the specified value to the specified type regardless
   /// of the types involved. This is an inferred cast.
-  Value *CastToAnyType (Value *V, bool VSigned, const Type* Ty, bool TySigned);
+  Value *CastToAnyType (Value *V, bool VSigned, const Type *Ty, bool TySigned);
 
   /// CastToUIntType - Cast the specified value to the specified type assuming
   /// that V's type and Ty are integral types. This arbitrates between BitCast,
   /// Trunc and ZExt.
-  Value *CastToUIntType(Value *V, const Type* Ty);
+  Value *CastToUIntType(Value *V, const Type *Ty);
 
   /// CastToSIntType - Cast the specified value to the specified type assuming
   /// that V's type and Ty are integral types. This arbitrates between BitCast,
   /// Trunc and SExt.
-  Value *CastToSIntType(Value *V, const Type* Ty);
+  Value *CastToSIntType(Value *V, const Type *Ty);
 
   /// CastToFPType - Cast the specified value to the specified type assuming
   /// that V's type and Ty are floating point types. This arbitrates between
   /// BitCast, FPTrunc and FPExt.
-  Value *CastToFPType(Value *V, const Type* Ty);
+  Value *CastToFPType(Value *V, const Type *Ty);
 
   /// CreateAnyAdd - Add two LLVM scalar values with the given GCC type.  Does
   /// not support complex numbers.  The type is used to set overflow flags.
@@ -552,7 +520,7 @@
   void PopulatePhiNodes();
 
   /// getBasicBlock - Find or create the LLVM basic block corresponding to BB.
-  BasicBlock *getBasicBlock(basic_block bb);
+  BasicBlock *getBasicBlock(basic_block_def *bb);
 
   /// getLabelDeclBlock - Lazily get and create a basic block for the specified
   /// label.
@@ -622,27 +590,27 @@
 
   //===------------------ Render* - Convert GIMPLE to LLVM ----------------===//
 
-  void RenderGIMPLE_ASM(gimple stmt);
-  void RenderGIMPLE_ASSIGN(gimple stmt);
-  void RenderGIMPLE_CALL(gimple stmt);
-  void RenderGIMPLE_COND(gimple stmt);
-  void RenderGIMPLE_EH_DISPATCH(gimple stmt);
-  void RenderGIMPLE_GOTO(gimple stmt);
-  void RenderGIMPLE_RESX(gimple stmt);
-  void RenderGIMPLE_RETURN(gimple stmt);
-  void RenderGIMPLE_SWITCH(gimple stmt);
+  void RenderGIMPLE_ASM(gimple_statement_d *stmt);
+  void RenderGIMPLE_ASSIGN(gimple_statement_d *stmt);
+  void RenderGIMPLE_CALL(gimple_statement_d *stmt);
+  void RenderGIMPLE_COND(gimple_statement_d *stmt);
+  void RenderGIMPLE_EH_DISPATCH(gimple_statement_d *stmt);
+  void RenderGIMPLE_GOTO(gimple_statement_d *stmt);
+  void RenderGIMPLE_RESX(gimple_statement_d *stmt);
+  void RenderGIMPLE_RETURN(gimple_statement_d *stmt);
+  void RenderGIMPLE_SWITCH(gimple_statement_d *stmt);
 
   // Render helpers.
 
   /// EmitAssignRHS - Convert the RHS of a scalar GIMPLE_ASSIGN to LLVM.
-  Value *EmitAssignRHS(gimple stmt);
+  Value *EmitAssignRHS(gimple_statement_d *stmt);
 
   /// EmitAssignSingleRHS - Helper for EmitAssignRHS.  Handles those RHS that
   /// are not register expressions.
   Value *EmitAssignSingleRHS(tree_node *rhs);
 
   /// OutputCallRHS - Convert the RHS of a GIMPLE_CALL.
-  Value *OutputCallRHS(gimple stmt, const MemRef *DestLoc);
+  Value *OutputCallRHS(gimple_statement_d *stmt, const MemRef *DestLoc);
 
   /// WriteScalarToLHS - Store RHS, a non-aggregate value, into the given LHS.
   void WriteScalarToLHS(tree_node *lhs, Value *Scalar);
@@ -689,15 +657,15 @@
 
   /// EmitCompare - Compare LHS with RHS using the appropriate comparison code.
   /// The result is an i1 boolean.
-  Value *EmitCompare(tree_node *lhs, tree_node *rhs, tree_code code);
+  Value *EmitCompare(tree_node *lhs, tree_node *rhs, unsigned code);
 
   // Binary expressions.
-  Value *EmitReg_MinMaxExpr(tree_node *type, tree_node *op0, tree_node* op1,
+  Value *EmitReg_MinMaxExpr(tree_node *type, tree_node *op0, tree_node *op1,
                             unsigned UIPred, unsigned SIPred, unsigned Opc,
                             bool isMax);
   Value *EmitReg_RotateOp(tree_node *type, tree_node *op0, tree_node *op1,
                           unsigned Opc1, unsigned Opc2);
-  Value *EmitReg_ShiftOp(tree_node *op0, tree_node* op1, unsigned Opc);
+  Value *EmitReg_ShiftOp(tree_node *op0, tree_node *op1, unsigned Opc);
   Value *EmitReg_TruthOp(tree_node *type, tree_node *op0, tree_node *op1,
                          unsigned Opc);
   Value *EmitReg_BIT_AND_EXPR(tree_node *op0, tree_node *op1);
@@ -723,8 +691,8 @@
   Value *EmitLoadOfLValue(tree_node *exp);
   Value *EmitOBJ_TYPE_REF(tree_node *exp);
   Value *EmitADDR_EXPR(tree_node *exp);
-  Value *EmitCallOf(Value *Callee, gimple stmt, const MemRef *DestLoc,
-                    const AttrListPtr &PAL);
+  Value *EmitCallOf(Value *Callee, gimple_statement_d *stmt,
+                    const MemRef *DestLoc, const AttrListPtr &PAL);
   Value *EmitFieldAnnotation(Value *FieldPtr, tree_node *FieldDecl);
 
   // Inline Assembly and Register Variables.
@@ -736,46 +704,49 @@
   Value *BuildVector(const std::vector<Value*> &Elts);
   Value *BuildVector(Value *Elt, ...);
   Value *BuildVectorShuffle(Value *InVec1, Value *InVec2, ...);
-  Value *BuildBinaryAtomicBuiltin(gimple stmt, Intrinsic::ID id);
-  Value *BuildCmpAndSwapAtomicBuiltin(gimple stmt, tree_node *type,
+  Value *BuildBinaryAtomicBuiltin(gimple_statement_d *stmt, Intrinsic::ID id);
+  Value *BuildCmpAndSwapAtomicBuiltin(gimple_statement_d *stmt, tree_node *type,
                                       bool isBool);
 
   // Builtin Function Expansion.
-  bool EmitBuiltinCall(gimple stmt, tree_node *fndecl,
+  bool EmitBuiltinCall(gimple_statement_d *stmt, tree_node *fndecl,
                        const MemRef *DestLoc, Value *&Result);
-  bool EmitFrontendExpandedBuiltinCall(gimple stmt, tree_node *fndecl,
-                                       const MemRef *DestLoc, Value *&Result);
+  bool EmitFrontendExpandedBuiltinCall(gimple_statement_d *stmt,
+                                       tree_node *fndecl, const MemRef *DestLoc,
+                                       Value *&Result);
   bool EmitBuiltinUnaryOp(Value *InVal, Value *&Result, Intrinsic::ID Id);
-  Value *EmitBuiltinSQRT(gimple stmt);
-  Value *EmitBuiltinPOWI(gimple stmt);
-  Value *EmitBuiltinPOW(gimple stmt);
-
-  bool EmitBuiltinConstantP(gimple stmt, Value *&Result);
-  bool EmitBuiltinAlloca(gimple stmt, Value *&Result);
-  bool EmitBuiltinExpect(gimple stmt, Value *&Result);
-  bool EmitBuiltinExtendPointer(gimple stmt, Value *&Result);
-  bool EmitBuiltinVAStart(gimple stmt);
-  bool EmitBuiltinVAEnd(gimple stmt);
-  bool EmitBuiltinVACopy(gimple stmt);
-  bool EmitBuiltinMemCopy(gimple stmt, Value *&Result,
+  Value *EmitBuiltinSQRT(gimple_statement_d *stmt);
+  Value *EmitBuiltinPOWI(gimple_statement_d *stmt);
+  Value *EmitBuiltinPOW(gimple_statement_d *stmt);
+
+  bool EmitBuiltinConstantP(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinAlloca(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinExpect(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinExtendPointer(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinVAStart(gimple_statement_d *stmt);
+  bool EmitBuiltinVAEnd(gimple_statement_d *stmt);
+  bool EmitBuiltinVACopy(gimple_statement_d *stmt);
+  bool EmitBuiltinMemCopy(gimple_statement_d *stmt, Value *&Result,
                           bool isMemMove, bool SizeCheck);
-  bool EmitBuiltinMemSet(gimple stmt, Value *&Result, bool SizeCheck);
-  bool EmitBuiltinBZero(gimple stmt, Value *&Result);
-  bool EmitBuiltinPrefetch(gimple stmt);
-  bool EmitBuiltinReturnAddr(gimple stmt, Value *&Result, bool isFrame);
-  bool EmitBuiltinExtractReturnAddr(gimple stmt, Value *&Result);
-  bool EmitBuiltinFrobReturnAddr(gimple stmt, Value *&Result);
-  bool EmitBuiltinStackSave(gimple stmt, Value *&Result);
-  bool EmitBuiltinStackRestore(gimple stmt);
-  bool EmitBuiltinEHPointer(gimple stmt, Value *&Result);
-  bool EmitBuiltinDwarfCFA(gimple stmt, Value *&Result);
-  bool EmitBuiltinDwarfSPColumn(gimple stmt, Value *&Result);
-  bool EmitBuiltinEHReturnDataRegno(gimple stmt, Value *&Result);
-  bool EmitBuiltinEHReturn(gimple stmt, Value *&Result);
-  bool EmitBuiltinInitDwarfRegSizes(gimple stmt, Value *&Result);
-  bool EmitBuiltinUnwindInit(gimple stmt, Value *&Result);
-  bool EmitBuiltinAdjustTrampoline(gimple stmt, Value *&Result);
-  bool EmitBuiltinInitTrampoline(gimple stmt, Value *&Result);
+  bool EmitBuiltinMemSet(gimple_statement_d *stmt, Value *&Result,
+                         bool SizeCheck);
+  bool EmitBuiltinBZero(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinPrefetch(gimple_statement_d *stmt);
+  bool EmitBuiltinReturnAddr(gimple_statement_d *stmt, Value *&Result,
+                             bool isFrame);
+  bool EmitBuiltinExtractReturnAddr(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinFrobReturnAddr(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinStackSave(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinStackRestore(gimple_statement_d *stmt);
+  bool EmitBuiltinEHPointer(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinDwarfCFA(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinDwarfSPColumn(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinEHReturnDataRegno(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinEHReturn(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinInitDwarfRegSizes(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinUnwindInit(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinAdjustTrampoline(gimple_statement_d *stmt, Value *&Result);
+  bool EmitBuiltinInitTrampoline(gimple_statement_d *stmt, Value *&Result);
 
   // Complex Math Expressions.
   Value *CreateComplex(Value *Real, Value *Imag, tree_node *elt_type);
@@ -825,9 +796,7 @@
 
   /// EmitMemory - Convert the specified gimple register or local constant of
   /// register type to an LLVM value with in-memory type (given by ConvertType).
-  Value *EmitMemory(tree_node *reg) {
-    return Reg2Mem(EmitRegister(reg), TREE_TYPE(reg), Builder);
-  }
+  Value *EmitMemory(tree_node *reg);
 
   /// LoadRegisterFromMemory - Loads a value of the given scalar GCC type from
   /// the memory location pointed to by Loc.  Takes care of adjusting for any
@@ -844,7 +813,7 @@
 
 private:
   // Optional target defined builtin intrinsic expanding function.
-  bool TargetIntrinsicLower(gimple stmt,
+  bool TargetIntrinsicLower(gimple_statement_d *stmt,
                             tree_node *fndecl,
                             const MemRef *DestLoc,
                             Value *&Result,

Modified: dragonegg/trunk/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-types.cpp?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/llvm-types.cpp (original)
+++ dragonegg/trunk/llvm-types.cpp Sat Jul 24 11:44:47 2010
@@ -23,19 +23,25 @@
 // This is the code that converts GCC tree types into LLVM types.
 //===----------------------------------------------------------------------===//
 
+// Plugin headers
+#include "llvm-abi.h"
+extern "C" {
+#include "llvm-cache.h"
+}
+
 // LLVM headers
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/TypeSymbolTable.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetMachine.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
 
 // System headers
 #include <gmp.h>
@@ -46,15 +52,10 @@
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "target.h"
 #include "tree.h"
 }
 
-// Plugin headers
-#include "llvm-abi.h"
-extern "C" {
-#include "llvm-cache.h"
-}
-
 static LLVMContext &Context = getGlobalContext();
 
 //===----------------------------------------------------------------------===//
@@ -201,6 +202,44 @@
 //                       Type Conversion Utilities
 //===----------------------------------------------------------------------===//
 
+/// ArrayLengthOf - Returns the length of the given gcc array type, or ~0ULL if
+/// the array has variable or unknown length.
+uint64_t ArrayLengthOf(tree type) {
+  assert(TREE_CODE(type) == ARRAY_TYPE && "Only for array types!");
+  // If the element type has variable size and the array type has variable
+  // length, but by some miracle the product gives a constant size, then we
+  // also return ~0ULL here.  I can live with this, and I bet you can too!
+  if (!isInt64(TYPE_SIZE(type), true) ||
+      !isInt64(TYPE_SIZE(TREE_TYPE(type)), true))
+    return ~0ULL;
+  // May return zero for arrays that gcc considers to have non-zero length, but
+  // only if the array type has zero size (this can happen if the element type
+  // has zero size), in which case the discrepancy doesn't matter.
+  //
+  // If the user increased the alignment of the element type, then the size of
+  // the array type is rounded up by that alignment, but the size of the element
+  // is not.  Since gcc requires the user alignment to be strictly smaller than
+  // the element size, this does not impact the length computation.
+  return integer_zerop(TYPE_SIZE(type)) ?  0 : getInt64(TYPE_SIZE(type), true) /
+    getInt64(TYPE_SIZE(TREE_TYPE(type)), true);
+}
+
+/// getFieldOffsetInBits - Return the bit offset of a FIELD_DECL in a structure.
+inline uint64_t getFieldOffsetInBits(tree field) {
+  assert(OffsetIsLLVMCompatible(field) && "Offset is not constant!");
+  uint64_t Result = getInt64(DECL_FIELD_BIT_OFFSET(field), true);
+  Result += getInt64(DECL_FIELD_OFFSET(field), true) * BITS_PER_UNIT;
+  return Result;
+}
+
+/// GetUnitPointerType - Returns an LLVM pointer type which points to memory one
+/// address unit wide.  For example, on a machine which has 16 bit bytes returns
+/// an i16*.
+const Type *GetUnitPointerType(LLVMContext &C, unsigned AddrSpace) {
+  assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
+  return IntegerType::get(C, BITS_PER_UNIT)->getPointerTo(AddrSpace);
+}
+
 // isPassedByInvisibleReference - Return true if an argument of the specified
 // type should be passed in by invisible reference.
 //
@@ -215,6 +254,26 @@
          TREE_CODE(TYPE_SIZE(Type)) != INTEGER_CST;
 }
 
+/// isSequentialCompatible - Return true if the specified gcc array or pointer
+/// type and the corresponding LLVM SequentialType lay out their components
+/// identically in memory, so doing a GEP accesses the right memory location.
+/// We assume that objects without a known size do not.
+bool isSequentialCompatible(tree type) {
+  assert((TREE_CODE(type) == ARRAY_TYPE ||
+          TREE_CODE(type) == POINTER_TYPE ||
+          TREE_CODE(type) == REFERENCE_TYPE) && "not a sequential type!");
+  // This relies on gcc types with constant size mapping to LLVM types with the
+  // same size.  It is possible for the component type not to have a size:
+  // struct foo;  extern foo bar[];
+  return isInt64(TYPE_SIZE(TREE_TYPE(type)), true);
+}
+
+/// OffsetIsLLVMCompatible - Return true if the given field is offset from the
+/// start of the record by a constant amount which is not humongously big.
+bool OffsetIsLLVMCompatible(tree field_decl) {
+  return isInt64(DECL_FIELD_OFFSET(field_decl), true);
+}
+
 /// NameType - Try to name the given type after the given GCC tree node.  If
 /// the GCC tree node has no sensible name then it does nothing.
 static void NameType(const Type *Ty, tree t, Twine Prefix = Twine(),

Modified: dragonegg/trunk/x86/llvm-target.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/x86/llvm-target.cpp?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/x86/llvm-target.cpp (original)
+++ dragonegg/trunk/x86/llvm-target.cpp Sat Jul 24 11:44:47 2010
@@ -23,6 +23,11 @@
 // This is a C++ source file that implements specific llvm IA-32 ABI.
 //===----------------------------------------------------------------------===//
 
+// Plugin headers
+#include "llvm-abi.h"
+#include "llvm-internal.h"
+#include "llvm-target.h"
+
 // LLVM headers
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instructions.h"
@@ -44,11 +49,6 @@
 #include "gimple.h"
 }
 
-// Plugin headers
-#include "llvm-abi.h"
-#include "llvm-internal.h"
-#include "llvm-target.h"
-
 static LLVMContext &Context = getGlobalContext();
 
 /// BitCastToIntVector - Bitcast the vector operand to a vector of integers of

Modified: dragonegg/trunk/x86/llvm-target.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/x86/llvm-target.h?rev=109343&r1=109342&r2=109343&view=diff
==============================================================================
--- dragonegg/trunk/x86/llvm-target.h (original)
+++ dragonegg/trunk/x86/llvm-target.h Sat Jul 24 11:44:47 2010
@@ -25,7 +25,7 @@
 /* LLVM specific stuff for supporting calling convention output */
 #define TARGET_ADJUST_LLVM_CC(CC, type)                         \
   {                                                             \
-    tree type_attributes = TYPE_ATTRIBUTES (type);              \
+    tree_node *type_attributes = TYPE_ATTRIBUTES (type);              \
     if (lookup_attribute ("stdcall", type_attributes)) {        \
       CC = CallingConv::X86_StdCall;                            \
     } else if (lookup_attribute("fastcall", type_attributes)) { \
@@ -35,7 +35,7 @@
 
 #define TARGET_ADJUST_LLVM_RETATTR(Rattributes, type)           \
   {                                                             \
-    tree type_attributes = TYPE_ATTRIBUTES (type);              \
+    tree_node *type_attributes = TYPE_ATTRIBUTES (type);              \
     if (!TARGET_64BIT && (TARGET_SSEREGPARM ||                  \
                lookup_attribute("sseregparm", type_attributes)))\
       RAttributes |= Attribute::InReg;                          \
@@ -49,7 +49,7 @@
 
 #define LLVM_TARGET_INIT_REGPARM(local_regparm, local_fp_regparm, type) \
   {                                                             \
-    tree attr;                                                  \
+    tree_node *attr;                                                  \
     local_regparm = ix86_regparm;                               \
     local_fp_regparm = TARGET_SSEREGPARM ? 3 : 0;               \
     attr = lookup_attribute ("regparm",                         \
@@ -102,7 +102,7 @@
 #define LLVM_BYVAL_ALIGNMENT(T) \
   (TYPE_ALIGN(T) / 8)
 
-extern tree llvm_x86_should_return_selt_struct_as_scalar(tree);
+extern tree_node *llvm_x86_should_return_selt_struct_as_scalar(tree_node *);
 
 /* Structs containing a single data field plus zero-length fields are
    considered as if they were the type of the data field.  On x86-64,
@@ -112,8 +112,8 @@
 #define LLVM_SHOULD_RETURN_SELT_STRUCT_AS_SCALAR(X) \
   llvm_x86_should_return_selt_struct_as_scalar((X))
 
-extern bool llvm_x86_should_pass_aggregate_in_integer_regs(tree,
-                                                          unsigned*, bool*);
+extern bool llvm_x86_should_pass_aggregate_in_integer_regs(tree_node *,
+                                                           unsigned*, bool*);
 
 /* LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS - Return true if this aggregate
    value should be passed in integer registers.  This differs from the usual
@@ -123,7 +123,7 @@
 #define LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS(X, Y, Z)             \
   llvm_x86_should_pass_aggregate_in_integer_regs((X), (Y), (Z))
 
-extern const Type *llvm_x86_scalar_type_for_struct_return(tree type,
+extern const Type *llvm_x86_scalar_type_for_struct_return(tree_node *type,
                                                           unsigned *Offset);
 
 /* LLVM_SCALAR_TYPE_FOR_STRUCT_RETURN - Return LLVM Type if X can be
@@ -131,7 +131,7 @@
 #define LLVM_SCALAR_TYPE_FOR_STRUCT_RETURN(X, Y) \
   llvm_x86_scalar_type_for_struct_return((X), (Y))
 
-extern const Type *llvm_x86_aggr_type_for_struct_return(tree type);
+extern const Type *llvm_x86_aggr_type_for_struct_return(tree_node *type);
 
 /* LLVM_AGGR_TYPE_FOR_STRUCT_RETURN - Return LLVM Type if X can be
    returned as an aggregate, otherwise return NULL. */
@@ -147,19 +147,19 @@
 #define LLVM_EXTRACT_MULTIPLE_RETURN_VALUE(Src,Dest,V,B)       \
   llvm_x86_extract_multiple_return_value((Src),(Dest),(V),(B))
 
-extern bool llvm_x86_should_pass_vector_using_byval_attr(tree);
+extern bool llvm_x86_should_pass_vector_using_byval_attr(tree_node *);
 
 /* On x86-64, vectors which are not MMX nor SSE should be passed byval. */
 #define LLVM_SHOULD_PASS_VECTOR_USING_BYVAL_ATTR(X)      \
   llvm_x86_should_pass_vector_using_byval_attr((X))
 
-extern bool llvm_x86_should_pass_vector_in_integer_regs(tree);
+extern bool llvm_x86_should_pass_vector_in_integer_regs(tree_node *);
 
 /* On x86-32, vectors which are not MMX nor SSE should be passed as integers. */
 #define LLVM_SHOULD_PASS_VECTOR_IN_INTEGER_REGS(X)      \
   llvm_x86_should_pass_vector_in_integer_regs((X))
 
-extern tree llvm_x86_should_return_vector_as_scalar(tree, bool);
+extern tree_node *llvm_x86_should_return_vector_as_scalar(tree_node *, bool);
 
 /* The MMX vector v1i64 is returned in EAX and EDX on Darwin.  Communicate
     this by returning i64 here.  Likewise, (generic) vectors such as v2i16
@@ -169,7 +169,7 @@
 #define LLVM_SHOULD_RETURN_VECTOR_AS_SCALAR(X,isBuiltin)\
   llvm_x86_should_return_vector_as_scalar((X), (isBuiltin))
 
-extern bool llvm_x86_should_return_vector_as_shadow(tree, bool);
+extern bool llvm_x86_should_return_vector_as_shadow(tree_node *, bool);
 
 /* MMX vectors v2i32, v4i16, v8i8, v2f32 are returned using sret on Darwin
    32-bit.  Vectors bigger than 128 are returned using sret.  */
@@ -177,7 +177,7 @@
   llvm_x86_should_return_vector_as_shadow((X),(isBuiltin))
 
 extern bool
-llvm_x86_should_not_return_complex_in_memory(tree type);
+llvm_x86_should_not_return_complex_in_memory(tree_node *type);
 
 /* LLVM_SHOULD_NOT_RETURN_COMPLEX_IN_MEMORY - A hook to allow
    special _Complex handling. Return true if X should be returned using
@@ -186,7 +186,7 @@
   llvm_x86_should_not_return_complex_in_memory((X))
 
 extern bool
-llvm_x86_should_pass_aggregate_as_fca(tree type, const Type *);
+llvm_x86_should_pass_aggregate_as_fca(tree_node *type, const Type *);
 
 /* LLVM_SHOULD_PASS_AGGREGATE_AS_FCA - Return true if an aggregate of the
    specified type should be passed as a first-class aggregate. */
@@ -195,17 +195,17 @@
   llvm_x86_should_pass_aggregate_as_fca(X, TY)
 #endif
 
-extern bool llvm_x86_should_pass_aggregate_in_memory(tree, const Type *);
+extern bool llvm_x86_should_pass_aggregate_in_memory(tree_node *, const Type *);
 
 #define LLVM_SHOULD_PASS_AGGREGATE_USING_BYVAL_ATTR(X, TY)      \
   llvm_x86_should_pass_aggregate_in_memory(X, TY)
 
 
 extern bool
-llvm_x86_64_should_pass_aggregate_in_mixed_regs(tree, const Type *Ty,
+llvm_x86_64_should_pass_aggregate_in_mixed_regs(tree_node *, const Type *Ty,
                                                 std::vector<const Type*>&);
 extern bool
-llvm_x86_32_should_pass_aggregate_in_mixed_regs(tree, const Type *Ty,
+llvm_x86_32_should_pass_aggregate_in_mixed_regs(tree_node *, const Type *Ty,
                                                 std::vector<const Type*>&);
 
 #define LLVM_SHOULD_PASS_AGGREGATE_IN_MIXED_REGS(T, TY, CC, E)       \





More information about the llvm-commits mailing list