Implement findOptimalStorageSize a bit more generally
authorChris Lattner <sabre@nondot.org>
Tue, 29 Oct 2002 21:47:50 +0000 (21:47 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 29 Oct 2002 21:47:50 +0000 (21:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4416 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetMachine.cpp

index 2d0d330d8db38c4e0259ea7a3ee11ab6264ae4e3..f50580332a65ace30c02494a9a0a0f569a5f56e1 100644 (file)
 //   space equal to optSizeForSubWordData, and all other primitive data
 //   items use space according to the type.
 //   
-unsigned int
-TargetMachine::findOptimalStorageSize(const Type* ty) const
-{
-  switch(ty->getPrimitiveID())
-    {
-    case Type::BoolTyID:
-    case Type::UByteTyID:
-    case Type::SByteTyID:     
-    case Type::UShortTyID:
-    case Type::ShortTyID:     
-      return optSizeForSubWordData;
-    
-    default:
-      return DataLayout.getTypeSize(ty);
-    }
+unsigned TargetMachine::findOptimalStorageSize(const Type *Ty) const {
+  // Round integral values smaller than SubWordDataSize up to SubWordDataSize
+  if (Ty->isIntegral() &&
+      Ty->getPrimitiveSize() < DataLayout.getSubWordDataSize())
+    return DataLayout.getSubWordDataSize();
+
+  return DataLayout.getTypeSize(Ty);
 }