[cfe-commits] r130001 - /cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

Ken Dyck kd at kendyck.com
Fri Apr 22 10:51:05 PDT 2011


Author: kjdyck
Date: Fri Apr 22 12:51:05 2011
New Revision: 130001

URL: http://llvm.org/viewvc/llvm-project?rev=130001&view=rev
Log:
Eliminate some literal 8s from EmitNullInitialization() by converting
variables to CharUnits. No change in functionality intended.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=130001&r1=130000&r2=130001&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Apr 22 12:51:05 2011
@@ -654,15 +654,16 @@
     DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");
 
   // Get size and alignment info for this aggregate.
-  std::pair<uint64_t, unsigned> TypeInfo = getContext().getTypeInfo(Ty);
-  uint64_t Size = TypeInfo.first / 8;
-  unsigned Align = TypeInfo.second / 8;
+  std::pair<CharUnits, CharUnits> TypeInfo = 
+    getContext().getTypeInfoInChars(Ty);
+  CharUnits Size = TypeInfo.first;
+  CharUnits Align = TypeInfo.second;
 
   llvm::Value *SizeVal;
   const VariableArrayType *vla;
 
   // Don't bother emitting a zero-byte memset.
-  if (Size == 0) {
+  if (Size.isZero()) {
     // But note that getTypeInfo returns 0 for a VLA.
     if (const VariableArrayType *vlaType =
           dyn_cast_or_null<VariableArrayType>(
@@ -673,7 +674,7 @@
       return;
     }
   } else {
-    SizeVal = llvm::ConstantInt::get(IntPtrTy, Size);
+    SizeVal = llvm::ConstantInt::get(IntPtrTy, Size.getQuantity());
     vla = 0;
   }
 
@@ -698,14 +699,15 @@
     if (vla) return emitNonZeroVLAInit(*this, Ty, DestPtr, SrcPtr, SizeVal);
 
     // Get and call the appropriate llvm.memcpy overload.
-    Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, Align, false);
+    Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, Align.getQuantity(), false);
     return;
   } 
   
   // Otherwise, just memset the whole thing to zero.  This is legal
   // because in LLVM, all default initializers (other than the ones we just
   // handled above) are guaranteed to have a bit pattern of all zeros.
-  Builder.CreateMemSet(DestPtr, Builder.getInt8(0), SizeVal, Align, false);
+  Builder.CreateMemSet(DestPtr, Builder.getInt8(0), SizeVal, 
+                       Align.getQuantity(), false);
 }
 
 llvm::BlockAddress *CodeGenFunction::GetAddrOfLabel(const LabelDecl *L) {





More information about the cfe-commits mailing list