[cfe-commits] r70827 - in /cfe/trunk: include/clang/AST/RecordLayout.h include/clang/Basic/LangOptions.h include/clang/Driver/Options.def lib/AST/ASTContext.cpp lib/Driver/Tools.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Sun May 3 22:16:22 PDT 2009


Author: ddunbar
Date: Mon May  4 00:16:21 2009
New Revision: 70827

URL: http://llvm.org/viewvc/llvm-project?rev=70827&view=rev
Log:
Add -fobjc-tight-layout.
 - This implements gcc style Objective-C interface layout (I
   think). Currently it is always off, there is no functionality
   change unless this is passed.
   
   For the curious, the deal is that gcc lays out the fields of a
   subclass as if they were part of the superclass. That is, the
   subclass fields immediately follow the super class fields instead
   of being padded to the alignment of the superclass structure.

 - Currently gcc uses the tight layout in 32-bit and 64-bit modes, and
   llvm-gcc uses it in 32-bit only, for reasons which aren't clear
   yet. We probably want to switch to matching gcc, once this makes it
   through testing... my hope is that we can also fix llvm-gcc in
   order to maintain compatibility between the compilers.

Modified:
    cfe/trunk/include/clang/AST/RecordLayout.h
    cfe/trunk/include/clang/Basic/LangOptions.h
    cfe/trunk/include/clang/Driver/Options.def
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=70827&r1=70826&r2=70827&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Mon May  4 00:16:21 2009
@@ -29,13 +29,14 @@
 /// These objects are managed by ASTContext.
 class ASTRecordLayout {
   uint64_t Size;        // Size of record in bits.
+  uint64_t *FieldOffsets;
   unsigned Alignment;   // Alignment of record in bits.
   unsigned FieldCount;  // Number of fields
-  uint64_t *FieldOffsets;
+  unsigned NextOffset;  // Next available offset
   friend class ASTContext;
 
   ASTRecordLayout(uint64_t S = 0, unsigned A = 8) 
-    : Size(S), Alignment(A), FieldCount(0) {}
+    : Size(S), Alignment(A), FieldCount(0), NextOffset(0) {}
   ~ASTRecordLayout() {
     delete [] FieldOffsets;
   }

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

==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon May  4 00:16:21 2009
@@ -37,6 +37,9 @@
   unsigned ObjC1             : 1;  // Objective-C 1 support enabled.
   unsigned ObjC2             : 1;  // Objective-C 2 support enabled.
   unsigned ObjCNonFragileABI : 1;  // Objective-C modern abi enabled
+  unsigned ObjCTightLayout   : 1;  // Use tight interface layout, in
+                                   // which subclass ivars can be
+                                   // placed inside the superclass.
     
   unsigned PascalStrings     : 1;  // Allow Pascal strings
   unsigned WritableStrings   : 1;  // Allow writable strings
@@ -100,7 +103,7 @@
     Trigraphs = BCPLComment = DollarIdents = AsmPreprocessor = 0;
     GNUMode = ImplicitInt = Digraphs = 0;
     HexFloats = 0;
-    GC = ObjC1 = ObjC2 = ObjCNonFragileABI = 0;
+    GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCTightLayout = 0;
     C99 = Microsoft = CPlusPlus = CPlusPlus0x = 0;
     CXXOperatorNames = PascalStrings = WritableStrings = 0;
     Exceptions = NeXTRuntime = Freestanding = NoBuiltin = 0;

Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=70827&r1=70826&r2=70827&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Mon May  4 00:16:21 2009
@@ -420,6 +420,7 @@
 OPTION("-fobjc-gc", fobjc_gc, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-new-property", fobjc_new_property, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-nonfragile-abi", fobjc_nonfragile_abi, Flag, f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fobjc-tight-layout", fobjc_tight_layout, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc", fobjc, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fomit-frame-pointer", fomit_frame_pointer, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fopenmp", fopenmp, Flag, f_Group, INVALID, "", 0, 0, 0)

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=70827&r1=70826&r2=70827&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon May  4 00:16:21 2009
@@ -654,6 +654,9 @@
     Size = FieldOffset + FieldSize;
   }
   
+  // Remember the next available offset.
+  NextOffset = Size;
+
   // Remember max struct/class alignment.
   Alignment = std::max(Alignment, FieldAlign);
 }
@@ -718,6 +721,12 @@
     unsigned Alignment = SL.getAlignment();
     uint64_t Size = SL.getSize();
 
+    // If we are using tight interface packing, then we start laying
+    // out ivars not at the end of the superclass structure, but at
+    // the next byte following the last field.
+    if (getLangOptions().ObjCTightLayout)
+      Size = llvm::RoundUpToAlignment(SL.NextOffset, 8);
+
     ObjCLayouts[Key] = NewEntry = new ASTRecordLayout(Size, Alignment);
     NewEntry->InitializeLayout(FieldCount);
     // Super class is at the beginning of the layout.

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=70827&r1=70826&r2=70827&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon May  4 00:16:21 2009
@@ -466,6 +466,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc);
   // FIXME: Should we remove this?
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_nonfragile_abi);
+  Args.AddLastArg(CmdArgs, options::OPT_fobjc_tight_layout);
   Args.AddLastArg(CmdArgs, options::OPT_fprint_source_range_info);
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=70827&r1=70826&r2=70827&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon May  4 00:16:21 2009
@@ -628,6 +628,11 @@
 ObjCNonFragileABI("fobjc-nonfragile-abi",
                   llvm::cl::desc("enable objective-c's nonfragile abi"));
 
+
+static llvm::cl::opt<bool>
+ObjCTightLayout("fobjc-tight-layout",
+                  llvm::cl::desc("enable tight objective-c interface layout"));
+
 static llvm::cl::opt<bool>
 EmitAllDecls("femit-all-decls",
               llvm::cl::desc("Emit all declarations, even if unused"));
@@ -843,6 +848,9 @@
 
   if (ObjCNonFragileABI)
     Options.ObjCNonFragileABI = 1;
+  
+  if (ObjCTightLayout)
+    Options.ObjCTightLayout = 1;
 
   if (EmitAllDecls)
     Options.EmitAllDecls = 1;





More information about the cfe-commits mailing list