[cfe-commits] r57132 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/Targets.cpp lib/Lex/Preprocessor.cpp

Chris Lattner sabre at nondot.org
Sun Oct 5 13:06:37 PDT 2008


Author: lattner
Date: Sun Oct  5 15:06:37 2008
New Revision: 57132

URL: http://llvm.org/viewvc/llvm-project?rev=57132&view=rev
Log:
move a bunch more integer sizing out of target-specific code into
target indep code.  

Note that this changes functionality on PIC16: it defines __INT_MAX__
correctly for it, and it changes sizeof(long) to 16-bits (to match
the size of pointer).

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=57132&r1=57131&r2=57132&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Sun Oct  5 15:06:37 2008
@@ -72,12 +72,6 @@
   uint64_t getPointerAlign(unsigned AddrSpace) const {
     return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
-  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
-    return PointerWidth;
-  }
-  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
-    return PointerAlign;
-  }
   
   /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
   /// target, in bits.
@@ -219,6 +213,13 @@
   virtual bool useNeXTRuntimeAsDefault() const { return false; }
 
 protected:
+  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
+    return PointerWidth;
+  }
+  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
+    return PointerAlign;
+  }
+  
   virtual void getGCCRegNames(const char * const *&Names, 
                               unsigned &NumNames) const = 0;
   virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=57132&r1=57131&r2=57132&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Sun Oct  5 15:06:37 2008
@@ -115,22 +115,6 @@
   Define(Defs, "_BIG_ENDIAN");
   Define(Defs, "__BIG_ENDIAN__");
 
-  if (is64Bit) {
-    Define(Defs, "__INTMAX_MAX__", "9223372036854775807L");
-    Define(Defs, "__INTMAX_TYPE__", "long int");
-    Define(Defs, "__LONG_MAX__", "9223372036854775807L");
-    Define(Defs, "__PTRDIFF_TYPE__", "long int");
-    Define(Defs, "__UINTMAX_TYPE__", "long unsigned int");
-  } else {
-    Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
-    Define(Defs, "__INTMAX_TYPE__", "long long int");
-    Define(Defs, "__LONG_MAX__", "2147483647L");
-    Define(Defs, "__PTRDIFF_TYPE__", "int");
-    Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
-  }
-  Define(Defs, "__INT_MAX__", "2147483647");
-  Define(Defs, "__SIZE_TYPE__", "long unsigned int");
-  
   // Subtarget options.
   Define(Defs, "__NATURAL_ALIGNMENT__");
   Define(Defs, "__REGISTER_PREFIX__", "");
@@ -210,22 +194,6 @@
   // Target properties.
   Define(Defs, "__LITTLE_ENDIAN__");
   
-  if (is64Bit) {
-    Define(Defs, "__INTMAX_MAX__", "9223372036854775807L");
-    Define(Defs, "__INTMAX_TYPE__", "long int");
-    Define(Defs, "__LONG_MAX__", "9223372036854775807L");
-    Define(Defs, "__PTRDIFF_TYPE__", "long int");
-    Define(Defs, "__UINTMAX_TYPE__", "long unsigned int");
-  } else {
-    Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
-    Define(Defs, "__INTMAX_TYPE__", "long long int");
-    Define(Defs, "__LONG_MAX__", "2147483647L");
-    Define(Defs, "__PTRDIFF_TYPE__", "int");
-    Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
-  }
-  Define(Defs, "__SIZE_TYPE__", "long unsigned int");
-  Define(Defs, "__INT_MAX__", "2147483647");
-  
   // Subtarget options.
   Define(Defs, "__nocona");
   Define(Defs, "__nocona__");
@@ -297,15 +265,6 @@
   // Target properties.
   Define(Defs, "__LITTLE_ENDIAN__");
   
-  Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
-  Define(Defs, "__INTMAX_TYPE__", "long long int");
-  Define(Defs, "__LONG_MAX__", "2147483647L");
-  Define(Defs, "__PTRDIFF_TYPE__", "int");
-  Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
-  Define(Defs, "__SIZE_TYPE__", "long unsigned int");
-  
-  Define(Defs, "__INT_MAX__", "2147483647");
-  
   // Subtarget options.  [hard coded to v6 for now]
   Define(Defs, "__ARM_ARCH_6K__");
   Define(Defs, "__ARMEL__");
@@ -936,6 +895,7 @@
       // FIXME: Is IntAlign really supposed to be 16?  There seems
       // little point on a platform with 8-bit loads.
       IntWidth = IntAlign = LongAlign = LongLongAlign = PointerWidth = 16;
+      LongWidth = 16;
       PointerAlign = 8;
       DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8";
     }

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=57132&r1=57131&r2=57132&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sun Oct  5 15:06:37 2008
@@ -477,10 +477,59 @@
   DefineBuiltinMacro(Buf, "__CHAR_BIT__=8");
   DefineBuiltinMacro(Buf, "__SHRT_MAX__=32767");
   
+  if (TI.getIntWidth() == 32)
+    DefineBuiltinMacro(Buf, "__INT_MAX__=2147483647");
+  else if (TI.getIntWidth() == 16)
+    DefineBuiltinMacro(Buf, "__INT_MAX__=32767");
+  else
+    assert(0 && "Unknown integer size");
   
   assert(TI.getLongLongWidth() == 64 && "Only support 64-bit long long so far");
   DefineBuiltinMacro(Buf, "__LONG_LONG_MAX__=9223372036854775807LL");
 
+  if (TI.getLongWidth() == 32)
+    DefineBuiltinMacro(Buf, "__LONG_MAX__=2147483647L");
+  else if (TI.getLongWidth() == 64)
+    DefineBuiltinMacro(Buf, "__LONG_MAX__=9223372036854775807L");
+  else if (TI.getLongWidth() == 16)
+    DefineBuiltinMacro(Buf, "__LONG_MAX__=32767L");
+  else
+    assert(0 && "Unknown long size");
+  
+  // For "32-bit" targets, GCC generally defines intmax to be 'long long' and
+  // ptrdiff_t to be 'int'.  On "64-bit" targets, it defines intmax to be long,
+  // and ptrdiff_t to be 'long int'.  This sort of stuff shouldn't matter in
+  // theory, but can affect C++ overloading, stringizing, etc.
+  if (TI.getPointerWidth(0) == TI.getLongLongWidth()) {
+    // If sizeof(void*) == sizeof(long long) assume we have an LP64 target,
+    // because we assume sizeof(long) always is sizeof(void*) currently.
+    assert(TI.getPointerWidth(0) == TI.getLongWidth() && 
+           TI.getLongWidth() == 64 && 
+           TI.getIntWidth() == 32 && "Not I32 LP64?");
+    DefineBuiltinMacro(Buf, "__INTMAX_MAX__=9223372036854775807L");
+    DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long int");
+    DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long int");
+    DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long unsigned int");
+  } else {
+    // Otherwise we know that the pointer is smaller than long long. We continue
+    // to assume that sizeof(void*) == sizeof(long).
+    assert(TI.getPointerWidth(0) < TI.getLongLongWidth() &&
+           TI.getPointerWidth(0) == TI.getLongWidth() &&
+           "Unexpected target sizes");
+    // We currently only support targets where long is 32-bit.  This can be
+    // easily generalized in the future.
+    DefineBuiltinMacro(Buf, "__INTMAX_MAX__=9223372036854775807LL");
+    DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long long int");
+    DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int");
+    DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long long unsigned int");
+  }
+  
+  // All of our current targets have sizeof(long) == sizeof(void*).
+  assert(TI.getPointerWidth(0) == TI.getLongWidth());
+  DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long unsigned int");
+
+  
+  
   
   // Add __builtin_va_list typedef.
   {





More information about the cfe-commits mailing list