[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-05-02 Thread Lauro Ramos Venancio


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.108 - 1.109
---
Log message:

Fix build error.


---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.108 
llvm/lib/Target/TargetData.cpp:1.109
--- llvm/lib/Target/TargetData.cpp:1.108Tue May  1 16:15:46 2007
+++ llvm/lib/Target/TargetData.cpp  Wed May  2 15:37:47 2007
@@ -33,9 +33,9 @@
 // Handle the Pass registration stuff necessary to use TargetData's.
 namespace {
   // Register the default SparcV9 implementation...
-  const int TargetData::ID = 0;
   RegisterPassTargetData X(targetdata, Target Data Layout);
 }
+const int TargetData::ID = 0;
 
 
//===--===//
 // Support for StructLayout



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-05-02 Thread Devang Patel


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.109 - 1.110
---
Log message:

Use 'static const char' instead of 'static const int'.
Due to darwin gcc bug, one version of darwin linker coalesces 
static const int, which defauts PassID based pass identification.


---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.109 
llvm/lib/Target/TargetData.cpp:1.110
--- llvm/lib/Target/TargetData.cpp:1.109Wed May  2 15:37:47 2007
+++ llvm/lib/Target/TargetData.cpp  Wed May  2 16:39:19 2007
@@ -35,7 +35,7 @@
   // Register the default SparcV9 implementation...
   RegisterPassTargetData X(targetdata, Target Data Layout);
 }
-const int TargetData::ID = 0;
+const char TargetData::ID = 0;
 
 
//===--===//
 // Support for StructLayout



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-05-02 Thread Devang Patel


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.110 - 1.111
---
Log message:

Drop 'const'


---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.110 
llvm/lib/Target/TargetData.cpp:1.111
--- llvm/lib/Target/TargetData.cpp:1.110Wed May  2 16:39:19 2007
+++ llvm/lib/Target/TargetData.cpp  Wed May  2 20:11:53 2007
@@ -35,7 +35,7 @@
   // Register the default SparcV9 implementation...
   RegisterPassTargetData X(targetdata, Target Data Layout);
 }
-const char TargetData::ID = 0;
+char TargetData::ID = 0;
 
 
//===--===//
 // Support for StructLayout



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-05-01 Thread Devang Patel


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.107 - 1.108
---
Log message:

Do not use typeinfo to identify pass in pass manager.


---
Diffs of the changes:  (+3 -1)

 TargetData.cpp |4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.107 
llvm/lib/Target/TargetData.cpp:1.108
--- llvm/lib/Target/TargetData.cpp:1.107Sun Apr 22 16:54:13 2007
+++ llvm/lib/Target/TargetData.cpp  Tue May  1 16:15:46 2007
@@ -33,6 +33,7 @@
 // Handle the Pass registration stuff necessary to use TargetData's.
 namespace {
   // Register the default SparcV9 implementation...
+  const int TargetData::ID = 0;
   RegisterPassTargetData X(targetdata, Target Data Layout);
 }
 
@@ -221,7 +222,8 @@
   }
 }
 
-TargetData::TargetData(const Module *M) {
+TargetData::TargetData(const Module *M) 
+  : ImmutablePass((intptr_t)ID) {
   init(M-getDataLayout());
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-03-04 Thread Jeff Cohen


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.104 - 1.105
---
Log message:

Unbreak VC++ build.

---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.104 
llvm/lib/Target/TargetData.cpp:1.105
--- llvm/lib/Target/TargetData.cpp:1.104Thu Mar  1 13:48:16 2007
+++ llvm/lib/Target/TargetData.cpp  Sun Mar  4 18:00:42 2007
@@ -400,7 +400,7 @@
 unsigned char Alignment;
 Size = getTypeSize(ATy-getElementType());
 Alignment = getABITypeAlignment(ATy-getElementType());
-unsigned AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
+uint64_t AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
 return AlignedSize*ATy-getNumElements();
   }
   case Type::StructTyID: {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-03-01 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.103 - 1.104
---
Log message:

Wrap a long line.


---
Diffs of the changes:  (+2 -1)

 TargetData.cpp |3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.103 
llvm/lib/Target/TargetData.cpp:1.104
--- llvm/lib/Target/TargetData.cpp:1.103Mon Feb 19 17:30:10 2007
+++ llvm/lib/Target/TargetData.cpp  Thu Mar  1 13:48:16 2007
@@ -541,7 +541,8 @@
 TI = gep_type_begin(ptrTy, Indices, Indices+NumIndices);
   for (unsigned CurIDX = 0; CurIDX != NumIndices; ++CurIDX, ++TI) {
 if (const StructType *STy = dyn_castStructType(*TI)) {
-  assert(Indices[CurIDX]-getType() == Type::Int32Ty Illegal struct 
idx);
+  assert(Indices[CurIDX]-getType() == Type::Int32Ty 
+ Illegal struct idx);
   unsigned FieldNo = castConstantInt(Indices[CurIDX])-getZExtValue();
 
   // Get structure layout information...



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-19 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.101 - 1.102
---
Log message:

Implement support for non-standard integer bit widths of any size. The 
rules alignment is to pick the alignment that corresponds to the smallest 
specified alignment that is larger than the bit width of the type or the 
largest specified integer alignment if none are larger than the bitwidth
of the type. For the byte size, the size returned is the next larger 
multiple of the alignment for that type (using the above rule). This patch
also changes bit widths from short to uint32_t to ensure there are 
enough bits to specify any bit width that LLVM can handle (currently 2^23);
16-bits isn't enough.


---
Diffs of the changes:  (+33 -10)

 TargetData.cpp |   43 +--
 1 files changed, 33 insertions(+), 10 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.101 
llvm/lib/Target/TargetData.cpp:1.102
--- llvm/lib/Target/TargetData.cpp:1.101Fri Feb 16 18:41:42 2007
+++ llvm/lib/Target/TargetData.cpp  Mon Feb 19 16:35:00 2007
@@ -94,7 +94,7 @@
 
 TargetAlignElem
 TargetAlignElem::get(AlignTypeEnum align_type, unsigned char abi_align,
- unsigned char pref_align, short bit_width) {
+ unsigned char pref_align, uint32_t bit_width) {
   TargetAlignElem retval;
   retval.AlignType = align_type;
   retval.ABIAlign = abi_align;
@@ -188,7 +188,7 @@
 std::string arg0 = getToken(token, :);
 const char *p = arg0.c_str();
 AlignTypeEnum align_type;
-short size;
+uint32_t size;
 unsigned char abi_align;
 unsigned char pref_align;
 
@@ -213,7 +213,7 @@
   align_type = (*p == 'i' ? INTEGER_ALIGN :
 (*p == 'f' ? FLOAT_ALIGN :
  (*p == 'v' ? VECTOR_ALIGN : AGGREGATE_ALIGN)));
-  size = (short) atoi(++p);
+  size = (uint32_t) atoi(++p);
   abi_align = atoi(getToken(token, :).c_str()) / 8;
   pref_align = atoi(getToken(token, :).c_str()) / 8;
   if (pref_align == 0)
@@ -233,7 +233,7 @@
 
 void
 TargetData::setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
- unsigned char pref_align, short bit_width) {
+ unsigned char pref_align, uint32_t bit_width) {
   for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
 if (Alignments[i].AlignType == align_type 
 Alignments[i].TypeBitWidth == bit_width) {
@@ -250,10 +250,11 @@
 
 /// getAlignmentInfo - Return the alignment (either ABI if ABIInfo = true or 
 /// preferred if ABIInfo = false) the target wants for the specified datatype.
-unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType, short BitWidth,
-  bool ABIInfo) const {
+unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType, 
+  uint32_t BitWidth, bool ABIInfo) const {
   // Check to see if we have an exact match and remember the best match we see.
   int BestMatchIdx = -1;
+  int LargestInt = -1;
   for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
 if (Alignments[i].AlignType == AlignType 
 Alignments[i].TypeBitWidth == BitWidth)
@@ -271,14 +272,30 @@
 Alignments[BestMatchIdx].TypeBitWidth  BitWidth)
   BestMatchIdx = i;
   }
+} else if (AlignType == INTEGER_ALIGN  
+   Alignments[i].AlignType == INTEGER_ALIGN) {
+  // The best match for integers is the smallest size that is larger than
+  // the BitWidth requested.
+  if (Alignments[i].TypeBitWidth  BitWidth  (BestMatchIdx == -1 || 
+   Alignments[i].TypeBitWidth  Alignments[BestMatchIdx].TypeBitWidth))
+BestMatchIdx = i;
+  // However, if there isn't one that's larger, then we must use the
+  // largest one we have (see below)
+  if (LargestInt == -1 || 
+  Alignments[i].TypeBitWidth  Alignments[LargestInt].TypeBitWidth)
+LargestInt = i;
 }
-
-// FIXME: handle things like i37.
   }
 
+  // For integers, if we didn't find a best match, use the largest one found.
+  if (BestMatchIdx == -1)
+BestMatchIdx = LargestInt;
+
   // Okay, we didn't find an exact solution.  Fall back here depending on what
   // is being looked for.
   assert(BestMatchIdx != -1  Didn't find alignment info for this 
datatype!);
+
+  // Since we got a best match index, just return it.
   return ABIInfo ? Alignments[BestMatchIdx].ABIAlign
  : Alignments[BestMatchIdx].PrefAlign;
 }
@@ -407,8 +424,14 @@
   return 4;
 } else if (BitWidth = 64) {
   return 8;
-} else
-  assert(0  Integer types  64 bits not supported.);
+} else {
+  // The size of this  64 bit type is chosen as a multiple of the
+  // preferred alignment of the largest native size the target supports. 
+  // We first obtain the the alignment info for this type and then compute
+  // 

[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-16 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.97 - 1.98
---
Log message:

simplify some code, ensure that packed structures get abi alignment of 1.


---
Diffs of the changes:  (+11 -18)

 TargetData.cpp |   29 +++--
 1 files changed, 11 insertions(+), 18 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.97 llvm/lib/Target/TargetData.cpp:1.98
--- llvm/lib/Target/TargetData.cpp:1.97 Thu Feb 15 16:07:05 2007
+++ llvm/lib/Target/TargetData.cpp  Fri Feb 16 16:25:34 2007
@@ -442,8 +442,7 @@
   Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
   == false) for the requested type \a Ty.
  */
-unsigned char TargetData::getAlignment(const Type *Ty, bool abi_or_pref) const
-{
+unsigned char TargetData::getAlignment(const Type *Ty, bool abi_or_pref) const 
{
   int AlignType = -1;
 
   assert(Ty-isSized()  Cannot getTypeInfo() on a type that is unsized!);
@@ -454,27 +453,21 @@
 return (abi_or_pref
 ? getPointerABIAlignment()
 : getPointerPrefAlignment());
-  case Type::ArrayTyID: {
-const ArrayType *ATy = castArrayType(Ty);
-return (abi_or_pref
-? getABITypeAlignment(ATy-getElementType())
-: getPrefTypeAlignment(ATy-getElementType()));
-  }
+  case Type::ArrayTyID:
+return getAlignment(castArrayType(Ty)-getElementType(), abi_or_pref);
+
   case Type::StructTyID: {
-  // Get the layout annotation... which is lazily created on demand.
+// Packed structure types always have an ABI alignment of one.
+if (castStructType(Ty)-isPacked()  abi_or_pref)
+  return 1;
+
+// Get the layout annotation... which is lazily created on demand.
 const StructLayout *Layout = getStructLayout(castStructType(Ty));
 const TargetAlignElem elem = getAlignment(AGGREGATE_ALIGN, 0);
 assert(validAlignment(elem)
 Aggregate alignment return invalid in getAlignment);
-if (abi_or_pref) {
-  return (elem.ABIAlign  Layout-getAlignment()
-  ? Layout-StructAlignment
-  : elem.ABIAlign);
-} else {
-  return (elem.PrefAlign  Layout-getAlignment()
-  ? Layout-StructAlignment
-  : elem.PrefAlign);
-}
+unsigned Align = abi_or_pref ? elem.ABIAlign : elem.PrefAlign;
+return Align  Layout-getAlignment() ? Layout-StructAlignment : Align;
   }
   case Type::IntegerTyID:
   case Type::VoidTyID:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-16 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.98 - 1.99
---
Log message:

Remove an unnecessary predicate.
Patch by Scott Michel.


---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.98 llvm/lib/Target/TargetData.cpp:1.99
--- llvm/lib/Target/TargetData.cpp:1.98 Fri Feb 16 16:25:34 2007
+++ llvm/lib/Target/TargetData.cpp  Fri Feb 16 16:42:40 2007
@@ -458,7 +458,7 @@
 
   case Type::StructTyID: {
 // Packed structure types always have an ABI alignment of one.
-if (castStructType(Ty)-isPacked()  abi_or_pref)
+if (castStructType(Ty)-isPacked())
   return 1;
 
 // Get the layout annotation... which is lazily created on demand.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-16 Thread Chris Lattner
 Remove an unnecessary predicate.
 Patch by Scott Michel.

It's not clear that this is unnecessary.  Scott, does this mean that

%X = global {int} { int 1 }

will get alignment 1?

-Chris


 ---
 Diffs of the changes:  (+1 -1)

  TargetData.cpp |2 +-
  1 files changed, 1 insertion(+), 1 deletion(-)


 Index: llvm/lib/Target/TargetData.cpp
 diff -u llvm/lib/Target/TargetData.cpp:1.98 llvm/lib/Target/ 
 TargetData.cpp:1.99
 --- llvm/lib/Target/TargetData.cpp:1.98   Fri Feb 16 16:25:34 2007
 +++ llvm/lib/Target/TargetData.cppFri Feb 16 16:42:40 2007
 @@ -458,7 +458,7 @@

case Type::StructTyID: {
  // Packed structure types always have an ABI alignment of one.
 -if (castStructType(Ty)-isPacked()  abi_or_pref)
 +if (castStructType(Ty)-isPacked())
return 1;

  // Get the layout annotation... which is lazily created on  
 demand.



 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-16 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.99 - 1.100
---
Log message:

Fix CodeGen/PowerPC/2007-02-16-AlignPacked.ll


---
Diffs of the changes:  (+2 -2)

 TargetData.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.99 llvm/lib/Target/TargetData.cpp:1.100
--- llvm/lib/Target/TargetData.cpp:1.99 Fri Feb 16 16:42:40 2007
+++ llvm/lib/Target/TargetData.cpp  Fri Feb 16 17:11:51 2007
@@ -186,7 +186,7 @@
   setAlignment(FLOAT_ALIGN, 8,  8, 64);  // double
   setAlignment(VECTOR_ALIGN,8,  8, 64);  // v2i32
   setAlignment(VECTOR_ALIGN,   16, 16, 128); // v16i8, v8i16, v4i32, ...
-  setAlignment(AGGREGATE_ALIGN, 0,  0,  0);  // struct, union, class, ...
+  setAlignment(AGGREGATE_ALIGN, 0,  8,  0);  // struct, union, class, ...
   
   while (!temp.empty()) {
 std::string token = getToken(temp, -);
@@ -458,7 +458,7 @@
 
   case Type::StructTyID: {
 // Packed structure types always have an ABI alignment of one.
-if (castStructType(Ty)-isPacked())
+if (castStructType(Ty)-isPacked()  abi_or_pref)
   return 1;
 
 // Get the layout annotation... which is lazily created on demand.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-16 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.100 - 1.101
---
Log message:

Do not dereference invalid ranges.  Generalize targetdata alignment model.
This fixes the UnitTests/Vector/sumarray-dbl regressions.


---
Diffs of the changes:  (+51 -61)

 TargetData.cpp |  112 +
 1 files changed, 51 insertions(+), 61 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.100 
llvm/lib/Target/TargetData.cpp:1.101
--- llvm/lib/Target/TargetData.cpp:1.100Fri Feb 16 17:11:51 2007
+++ llvm/lib/Target/TargetData.cpp  Fri Feb 16 18:41:42 2007
@@ -104,12 +104,6 @@
 }
 
 bool
-TargetAlignElem::operator(const TargetAlignElem rhs) const {
-  return ((AlignType  rhs.AlignType)
-  || (AlignType == rhs.AlignType  TypeBitWidth  rhs.TypeBitWidth));
-}
-
-bool
 TargetAlignElem::operator==(const TargetAlignElem rhs) const {
   return (AlignType == rhs.AlignType
ABIAlign == rhs.ABIAlign
@@ -240,44 +234,53 @@
 void
 TargetData::setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
  unsigned char pref_align, short bit_width) {
-  TargetAlignElem elt = TargetAlignElem::get(align_type, abi_align,
- pref_align, bit_width);
-  std::pairalign_iterator, align_iterator ins_result =
-std::equal_range(Alignments.begin(), Alignments.end(), elt);
-  align_iterator I = ins_result.first;
-  if (I != Alignments.end()  I-AlignType == align_type  
-  I-TypeBitWidth == bit_width) {
-// Update the abi, preferred alignments.
-I-ABIAlign = abi_align;
-I-PrefAlign = pref_align;
-  } else
-Alignments.insert(I, elt);
-
-#if 0
-  // Keep around for debugging and testing...
-  align_iterator E = ins_result.second;
-
-  cerr  setAlignment(  elt  )\n;
-  cerr  I =   (I - Alignments.begin())
-, E =   (E - Alignments.begin())  \n;
-  std::copy(Alignments.begin(), Alignments.end(),
-std::ostream_iteratorTargetAlignElem(*cerr, \n));
-  cerr  =\n;
-#endif
-}
-
-const TargetAlignElem 
-TargetData::getAlignment(AlignTypeEnum align_type, short bit_width) const
-{
-  std::pairalign_const_iterator, align_const_iterator find_result =
-std::equal_range(Alignments.begin(), Alignments.end(),
- TargetAlignElem::get(align_type, 0, 0,
-  bit_width));
-  align_const_iterator I = find_result.first;
-
-  // Note: This may not be reasonable if variable-width integer sizes are
-  // passed, at which point, more sophisticated searching will need to be done.
-  return *I;
+  for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
+if (Alignments[i].AlignType == align_type 
+Alignments[i].TypeBitWidth == bit_width) {
+  // Update the abi, preferred alignments.
+  Alignments[i].ABIAlign = abi_align;
+  Alignments[i].PrefAlign = pref_align;
+  return;
+}
+  }
+  
+  Alignments.push_back(TargetAlignElem::get(align_type, abi_align,
+pref_align, bit_width));
+}
+
+/// getAlignmentInfo - Return the alignment (either ABI if ABIInfo = true or 
+/// preferred if ABIInfo = false) the target wants for the specified datatype.
+unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType, short BitWidth,
+  bool ABIInfo) const {
+  // Check to see if we have an exact match and remember the best match we see.
+  int BestMatchIdx = -1;
+  for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
+if (Alignments[i].AlignType == AlignType 
+Alignments[i].TypeBitWidth == BitWidth)
+  return ABIInfo ? Alignments[i].ABIAlign : Alignments[i].PrefAlign;
+
+// The best match so far depends on what we're looking for.
+if (AlignType == VECTOR_ALIGN) {
+  // If this is a specification for a smaller vector type, we will fall 
back
+  // to it.  This happens because 128 x double can be implemented in 
terms
+  // of 64 2 x double.
+  if (Alignments[i].AlignType == VECTOR_ALIGN  
+  Alignments[i].TypeBitWidth  BitWidth) {
+// Verify that we pick the biggest of the fallbacks.
+if (BestMatchIdx == -1 ||
+Alignments[BestMatchIdx].TypeBitWidth  BitWidth)
+  BestMatchIdx = i;
+  }
+}
+
+// FIXME: handle things like i37.
+  }
+
+  // Okay, we didn't find an exact solution.  Fall back here depending on what
+  // is being looked for.
+  assert(BestMatchIdx != -1  Didn't find alignment info for this 
datatype!);
+  return ABIInfo ? Alignments[BestMatchIdx].ABIAlign
+ : Alignments[BestMatchIdx].PrefAlign;
 }
 
 /// LayoutInfo - The lazy cache of structure layout information maintained by
@@ -337,7 +340,6 @@
   SL = L;
   
   new (L) StructLayout(Ty, *this);
-
   return L;
 }
 
@@ -463,11 +465,8 @@
 
 

[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-15 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.96 - 1.97
---
Log message:

For PR1195: http://llvm.org/PR1195 :
PACKED_ALIGN - VECTOR_ALIGN


---
Diffs of the changes:  (+4 -4)

 TargetData.cpp |8 
 1 files changed, 4 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.96 llvm/lib/Target/TargetData.cpp:1.97
--- llvm/lib/Target/TargetData.cpp:1.96 Thu Feb 15 12:34:36 2007
+++ llvm/lib/Target/TargetData.cpp  Thu Feb 15 16:07:05 2007
@@ -184,8 +184,8 @@
   setAlignment(INTEGER_ALIGN,   4,  8, 64);  // long
   setAlignment(FLOAT_ALIGN, 4,  4, 32);  // float
   setAlignment(FLOAT_ALIGN, 8,  8, 64);  // double
-  setAlignment(PACKED_ALIGN,8,  8, 64);  // v2i32
-  setAlignment(PACKED_ALIGN,   16, 16, 128); // v16i8, v8i16, v4i32, ...
+  setAlignment(VECTOR_ALIGN,8,  8, 64);  // v2i32
+  setAlignment(VECTOR_ALIGN,   16, 16, 128); // v16i8, v8i16, v4i32, ...
   setAlignment(AGGREGATE_ALIGN, 0,  0,  0);  // struct, union, class, ...
   
   while (!temp.empty()) {
@@ -218,7 +218,7 @@
 case 'a': {
   align_type = (*p == 'i' ? INTEGER_ALIGN :
 (*p == 'f' ? FLOAT_ALIGN :
- (*p == 'v' ? PACKED_ALIGN : AGGREGATE_ALIGN)));
+ (*p == 'v' ? VECTOR_ALIGN : AGGREGATE_ALIGN)));
   size = (short) atoi(++p);
   abi_align = atoi(getToken(token, :).c_str()) / 8;
   pref_align = atoi(getToken(token, :).c_str()) / 8;
@@ -485,7 +485,7 @@
 AlignType = FLOAT_ALIGN;
 break;
   case Type::VectorTyID:
-AlignType = PACKED_ALIGN;
+AlignType = VECTOR_ALIGN;
 break;
   default:
 assert(0  Bad type for getAlignment!!!);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-14 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.93 - 1.94
---
Log message:

Fixed packed structure breakage from earlier TargetData patch; applied
Chris Lattner's code style suggestions.

Patch by Scott Michel!


---
Diffs of the changes:  (+31 -75)

 TargetData.cpp |  106 -
 1 files changed, 31 insertions(+), 75 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.93 llvm/lib/Target/TargetData.cpp:1.94
--- llvm/lib/Target/TargetData.cpp:1.93 Tue Feb 13 23:52:17 2007
+++ llvm/lib/Target/TargetData.cpp  Wed Feb 14 20:11:06 2007
@@ -50,8 +50,8 @@
 const Type *Ty = ST-getElementType(i);
 unsigned TyAlign;
 uint64_t TySize;
-TyAlign = (unsigned) TD.getABITypeAlignment(Ty);
-TySize = (unsigned) TD.getTypeSize(Ty);
+TyAlign = (ST-isPacked() ? 1 : TD.getABITypeAlignment(Ty));
+TySize = TD.getTypeSize(Ty);
 
 // Add padding if necessary to make the data element aligned properly...
 if (StructSize % TyAlign != 0)
@@ -94,8 +94,7 @@
 
 TargetAlignElem
 TargetAlignElem::get(AlignTypeEnum align_type, unsigned char abi_align,
- unsigned char pref_align, short bit_width)
-{
+ unsigned char pref_align, short bit_width) {
   TargetAlignElem retval;
   retval.AlignType = align_type;
   retval.ABIAlign = abi_align;
@@ -105,15 +104,13 @@
 }
 
 bool
-TargetAlignElem::operator(const TargetAlignElem rhs) const
-{
+TargetAlignElem::operator(const TargetAlignElem rhs) const {
   return ((AlignType  rhs.AlignType)
   || (AlignType == rhs.AlignType  TypeBitWidth  rhs.TypeBitWidth));
 }
 
 bool
-TargetAlignElem::operator==(const TargetAlignElem rhs) const
-{
+TargetAlignElem::operator==(const TargetAlignElem rhs) const {
   return (AlignType == rhs.AlignType
ABIAlign == rhs.ABIAlign
PrefAlign == rhs.PrefAlign
@@ -121,20 +118,13 @@
 }
 
 std::ostream 
-TargetAlignElem::dump(std::ostream os) const
-{
+TargetAlignElem::dump(std::ostream os) const {
   return os  AlignType
  TypeBitWidth
  :  (int) (ABIAlign * 8)
  :  (int) (PrefAlign * 8);
 }
 
-std::ostream 
-llvm::operator(std::ostream os, const TargetAlignElem elem)
-{
-  return elem.dump(os);
-}
-
 const TargetAlignElem TargetData::InvalidAlignmentElem =
 TargetAlignElem::get((AlignTypeEnum) -1, 0, 0, 0);
 
@@ -146,9 +136,9 @@
  A TargetDescription string consists of a sequence of hyphen-delimited
  specifiers for target endianness, pointer size and alignments, and various
  primitive type sizes and alignments. A typical string looks something like:
- br
+ brbr
  E-p:32:32:32-i1:8:8-i8:8:8-i32:32:32-i64:32:64-f32:32:32-f64:32:64
- br
+ brbr
  (note: this string is not fully specified and is only an example.)
  \p
  Alignments come in two flavors: ABI and preferred. ABI alignment (abi_align,
@@ -187,16 +177,16 @@
   PointerPrefAlign = PointerABIAlign;
 
   // Default alignments
-  setAlignment(INTEGER_ALIGN,   1,  1, 1); // Bool
-  setAlignment(INTEGER_ALIGN,   1,  1, 8); // Byte
-  setAlignment(INTEGER_ALIGN,   2,  2, 16); // short
-  setAlignment(INTEGER_ALIGN,   4,  4, 32); // int
-  setAlignment(INTEGER_ALIGN,   0,  8, 64); // long
-  setAlignment(FLOAT_ALIGN, 4,  4, 32); // float
-  setAlignment(FLOAT_ALIGN, 0,  8, 64); // double
-  setAlignment(PACKED_ALIGN,8,  8, 64); // v2i32
+  setAlignment(INTEGER_ALIGN,   1,  1, 1);   // Bool
+  setAlignment(INTEGER_ALIGN,   1,  1, 8);   // Byte
+  setAlignment(INTEGER_ALIGN,   2,  2, 16);  // short
+  setAlignment(INTEGER_ALIGN,   4,  4, 32);  // int
+  setAlignment(INTEGER_ALIGN,   4,  8, 64);  // long
+  setAlignment(FLOAT_ALIGN, 4,  4, 32);  // float
+  setAlignment(FLOAT_ALIGN, 8,  8, 64);  // double
+  setAlignment(PACKED_ALIGN,8,  8, 64);  // v2i32
   setAlignment(PACKED_ALIGN,   16, 16, 128); // v16i8, v8i16, v4i32, ...
-  setAlignment(AGGREGATE_ALIGN, 0,  0,  0); // struct, union, class, ...
+  setAlignment(AGGREGATE_ALIGN, 0,  0,  0);  // struct, union, class, ...
   
   while (!temp.empty()) {
 std::string token = getToken(temp, -);
@@ -241,17 +231,6 @@
   break;
 }
   }
-
-  // Unless explicitly specified, the alignments for longs and doubles is 
-  // capped by pointer size.
-  // FIXME: Is this still necessary?
-  const TargetAlignElem long_align = getAlignment(INTEGER_ALIGN, 64);
-  if (long_align.ABIAlign == 0)
-setAlignment(INTEGER_ALIGN, PointerMemSize, PointerMemSize, 64);
-
-  const TargetAlignElem double_align = getAlignment(FLOAT_ALIGN, 64);
-  if (double_align.ABIAlign == 0)
-setAlignment(FLOAT_ALIGN, PointerMemSize, PointerMemSize, 64);
 }
 
 TargetData::TargetData(const Module *M) {
@@ -377,44 +356,21 @@
 }
 
 
-struct hyphen_delimited :
-  public std::iteratorstd::output_iterator_tag, void, void, void, void
-{
-  std::ostream o;
-
-  hyphen_delimited(std::ostream os) :
-o(os)
-  { }
-
-  

[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-14 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.94 - 1.95
---
Log message:

For PR1195: http://llvm.org/PR1195 :
Rename PackedType - VectorType, ConstantPacked - ConstantVector, and
PackedTyID - VectorTyID. No functional changes.


---
Diffs of the changes:  (+3 -3)

 TargetData.cpp |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.94 llvm/lib/Target/TargetData.cpp:1.95
--- llvm/lib/Target/TargetData.cpp:1.94 Wed Feb 14 20:11:06 2007
+++ llvm/lib/Target/TargetData.cpp  Wed Feb 14 20:26:10 2007
@@ -414,8 +414,8 @@
 return 4;
   case Type::DoubleTyID:
 return 8;
-  case Type::PackedTyID: {
-const PackedType *PTy = castPackedType(Ty);
+  case Type::VectorTyID: {
+const VectorType *PTy = castVectorType(Ty);
 return PTy-getBitWidth() / 8;
   }
   default:
@@ -483,7 +483,7 @@
   case Type::DoubleTyID:
 AlignType = FLOAT_ALIGN;
 break;
-  case Type::PackedTyID:
+  case Type::VectorTyID:
 AlignType = PACKED_ALIGN;
 break;
   default:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-13 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.92 - 1.93
---
Log message:

Generalize TargetData strings, to support more interesting forms of data.
Patch by Scott Michel.


---
Diffs of the changes:  (+309 -216)

 TargetData.cpp |  525 +
 1 files changed, 309 insertions(+), 216 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.92 llvm/lib/Target/TargetData.cpp:1.93
--- llvm/lib/Target/TargetData.cpp:1.92 Sat Feb 10 14:26:17 2007
+++ llvm/lib/Target/TargetData.cpp  Tue Feb 13 23:52:17 2007
@@ -36,12 +36,6 @@
   RegisterPassTargetData X(targetdata, Target Data Layout);
 }
 
-static inline void getTypeInfoABI(const Type *Ty, const TargetData *TD,
-  uint64_t Size, unsigned char Alignment);
-
-static inline void getTypeInfoPref(const Type *Ty, const TargetData *TD,
-   uint64_t Size, unsigned char Alignment);
-
 
//===--===//
 // Support for StructLayout
 
//===--===//
@@ -54,11 +48,10 @@
   // Loop over each of the elements, placing them in memory...
   for (unsigned i = 0, e = NumElements; i != e; ++i) {
 const Type *Ty = ST-getElementType(i);
-unsigned char A;
 unsigned TyAlign;
 uint64_t TySize;
-getTypeInfoABI(Ty, TD, TySize, A);
-TyAlign = ST-isPacked() ? 1 : A;
+TyAlign = (unsigned) TD.getABITypeAlignment(Ty);
+TySize = (unsigned) TD.getTypeSize(Ty);
 
 // Add padding if necessary to make the data element aligned properly...
 if (StructSize % TyAlign != 0)
@@ -96,38 +89,126 @@
 }
 
 
//===--===//
+// TargetAlignElem, TargetAlign support
+//===--===//
+
+TargetAlignElem
+TargetAlignElem::get(AlignTypeEnum align_type, unsigned char abi_align,
+ unsigned char pref_align, short bit_width)
+{
+  TargetAlignElem retval;
+  retval.AlignType = align_type;
+  retval.ABIAlign = abi_align;
+  retval.PrefAlign = pref_align;
+  retval.TypeBitWidth = bit_width;
+  return retval;
+}
+
+bool
+TargetAlignElem::operator(const TargetAlignElem rhs) const
+{
+  return ((AlignType  rhs.AlignType)
+  || (AlignType == rhs.AlignType  TypeBitWidth  rhs.TypeBitWidth));
+}
+
+bool
+TargetAlignElem::operator==(const TargetAlignElem rhs) const
+{
+  return (AlignType == rhs.AlignType
+   ABIAlign == rhs.ABIAlign
+   PrefAlign == rhs.PrefAlign
+   TypeBitWidth == rhs.TypeBitWidth);
+}
+
+std::ostream 
+TargetAlignElem::dump(std::ostream os) const
+{
+  return os  AlignType
+ TypeBitWidth
+ :  (int) (ABIAlign * 8)
+ :  (int) (PrefAlign * 8);
+}
+
+std::ostream 
+llvm::operator(std::ostream os, const TargetAlignElem elem)
+{
+  return elem.dump(os);
+}
+
+const TargetAlignElem TargetData::InvalidAlignmentElem =
+TargetAlignElem::get((AlignTypeEnum) -1, 0, 0, 0);
+
+//===--===//
 //   TargetData Class Implementation
 
//===--===//
 
+/*!
+ A TargetDescription string consists of a sequence of hyphen-delimited
+ specifiers for target endianness, pointer size and alignments, and various
+ primitive type sizes and alignments. A typical string looks something like:
+ br
+ E-p:32:32:32-i1:8:8-i8:8:8-i32:32:32-i64:32:64-f32:32:32-f64:32:64
+ br
+ (note: this string is not fully specified and is only an example.)
+ \p
+ Alignments come in two flavors: ABI and preferred. ABI alignment (abi_align,
+ below) dictates how a type will be aligned within an aggregate and when used
+ as an argument.  Preferred alignment (pref_align, below) determines a type's
+ alignment when emitted as a global.
+ \p
+ Specifier string details:
+ brbr
+ i[E|e]/i: Endianness. E specifies a big-endian target data model, e
+ specifies a little-endian target data model.
+ brbr
+ ip:size:abi_align:pref_align/i: Pointer size, ABI and preferred
+ alignment.
+ brbr
+ itypesize:abi_align:pref_align/i: Numeric type alignment. Type is
+ one of ii|f|v|a/i, corresponding to integer, floating point, vector (aka
+ packed) or aggregate.  Size indicates the size, e.g., 32 or 64 bits.
+ \p
+ The default string, fully specified is:
+ brbr
+ E-p:64:64:64-a0:0:0-f32:32:32-f64:0:64
+ -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:0:64
+ -v64:64:64-v128:128:128
+ brbr
+ Note that in the case of aggregates, 0 is the default ABI and preferred
+ alignment. This is a special case, where the aggregate's computed worst-case
+ alignment will be used.
+ */ 
 void TargetData::init(const std::string TargetDescription) {
   std::string temp = TargetDescription;
  

Re: [llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-13 Thread Chris Lattner
 Generalize TargetData strings, to support more interesting forms of  
 data.
 Patch by Scott Michel.

Scott,

 @@ -54,11 +48,10 @@
// Loop over each of the elements, placing them in memory...
for (unsigned i = 0, e = NumElements; i != e; ++i) {
  const Type *Ty = ST-getElementType(i);
 -unsigned char A;
  unsigned TyAlign;
  uint64_t TySize;
 -getTypeInfoABI(Ty, TD, TySize, A);
 -TyAlign = ST-isPacked() ? 1 : A;
 +TyAlign = (unsigned) TD.getABITypeAlignment(Ty);
 +TySize = (unsigned) TD.getTypeSize(Ty);

Why are you casting typesize to unsigned here?  This breaks support  
for structs that are are bigger than 4G on a 64-bit system.

 +TargetAlignElem
 +TargetAlignElem::get(AlignTypeEnum align_type, unsigned char  
 abi_align,
 + unsigned char pref_align, short bit_width)
 +{

Please use KR style braces ( '{' on same line) for consistency with  
the rest of this file.


 +  // FIXME: Is this still necessary?
 +  const TargetAlignElem long_align = getAlignment(INTEGER_ALIGN,  
 64);
 +  if (long_align.ABIAlign == 0)
 +setAlignment(INTEGER_ALIGN, PointerMemSize, PointerMemSize, 64);

Please decide if this is needed :)

 +struct hyphen_delimited :
 +  public std::iteratorstd::output_iterator_tag, void, void, void,  
 void

This is very cute, but also very obtuse.  :)  Please write it as a  
simple loop for maintainability.

  std::string TargetData::getStringRepresentation() const {
std::stringstream repr;

Also, you should be able to eliminate the stringstream here.  Just  
use 'ustostr' from llvm/ADT/StringExtras.h


 -uint64_t TargetData::getTypeSize(const Type *Ty) const {
 -  uint64_t Size;
 -  unsigned char Align;
 -  getTypeInfoABI(Ty, this, Size, Align);
 -  return Size;
 +  const TargetAlignElem elem = getAlignment((AlignTypeEnum)  
 AlignType,
 + getTypeSize(Ty) * 8);
 +  if (validAlignment(elem))
 +return (abi_or_pref ? elem.ABIAlign : elem.PrefAlign);
 +  else {
 +cerr  TargetData::getAlignment: align type   AlignType
 +   size   getTypeSize(Ty)   not found in  
 Alignments.\n;

Please turn this into an assert message.

Overall, very nice work Scott!

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.85 - 1.86
---
Log message:

Change TargetData::getIndexedOffset interface to not require indices
in a vector.


---
Diffs of the changes:  (+8 -8)

 TargetData.cpp |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.85 llvm/lib/Target/TargetData.cpp:1.86
--- llvm/lib/Target/TargetData.cpp:1.85 Mon Feb  5 17:51:43 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 13:33:15 2007
@@ -452,18 +452,18 @@
 }
 
 
-uint64_t TargetData::getIndexedOffset(const Type *ptrTy,
-  const std::vectorValue* Idx) const {
+uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices,
+  unsigned NumIndices) const {
   const Type *Ty = ptrTy;
   assert(isaPointerType(Ty)  Illegal argument for getIndexedOffset());
   uint64_t Result = 0;
 
-  generic_gep_type_iteratorstd::vectorValue*::const_iterator
-TI = gep_type_begin(ptrTy, Idx.begin(), Idx.end());
-  for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX, ++TI) {
+  generic_gep_type_iteratorValue* const*
+TI = gep_type_begin(ptrTy, Indices, Indices+NumIndices);
+  for (unsigned CurIDX = 0; CurIDX != NumIndices; ++CurIDX, ++TI) {
 if (const StructType *STy = dyn_castStructType(*TI)) {
-  assert(Idx[CurIDX]-getType() == Type::Int32Ty  Illegal struct idx);
-  unsigned FieldNo = castConstantInt(Idx[CurIDX])-getZExtValue();
+  assert(Indices[CurIDX]-getType() == Type::Int32Ty Illegal struct 
idx);
+  unsigned FieldNo = castConstantInt(Indices[CurIDX])-getZExtValue();
 
   // Get structure layout information...
   const StructLayout *Layout = getStructLayout(STy);
@@ -479,7 +479,7 @@
   Ty = castSequentialType(Ty)-getElementType();
 
   // Get the array index and the size of each array element.
-  int64_t arrayIdx = castConstantInt(Idx[CurIDX])-getSExtValue();
+  int64_t arrayIdx = castConstantInt(Indices[CurIDX])-getSExtValue();
   Result += arrayIdx * (int64_t)getTypeSize(Ty);
 }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.86 - 1.87
---
Log message:

Use ManagedStatic to manage LayoutInfo, instead of rolling our own.


---
Diffs of the changes:  (+24 -27)

 TargetData.cpp |   51 ---
 1 files changed, 24 insertions(+), 27 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.86 llvm/lib/Target/TargetData.cpp:1.87
--- llvm/lib/Target/TargetData.cpp:1.86 Sat Feb 10 13:33:15 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 13:43:18 2007
@@ -22,6 +22,7 @@
 #include llvm/Constants.h
 #include llvm/Support/GetElementPtrTypeIterator.h
 #include llvm/Support/MathExtras.h
+#include llvm/Support/ManagedStatic.h
 #include llvm/ADT/StringExtras.h
 #include algorithm
 #include cstdlib
@@ -201,25 +202,23 @@
   init(M-getDataLayout());
 }
 
-/// Layouts - The lazy cache of structure layout information maintained by
+/// LayoutInfo - The lazy cache of structure layout information maintained by
 /// TargetData.
 ///
-static std::mapstd::pairconst TargetData*,const StructType*,
-StructLayout *Layouts = 0;
+typedef std::pairconst TargetData*,const StructType* LayoutKey;
+static ManagedStaticstd::mapLayoutKey, StructLayout  LayoutInfo;
 
 
 TargetData::~TargetData() {
-  if (Layouts) {
+  if (LayoutInfo.isConstructed()) {
 // Remove any layouts for this TD.
-std::mapstd::pairconst TargetData*,
-  const StructType*, StructLayout::iterator
-  I = Layouts-lower_bound(std::make_pair(this, (const StructType*)0));
-while (I != Layouts-end()  I-first.first == this)
-  Layouts-erase(I++);
-if (Layouts-empty()) {
-  delete Layouts;
-  Layouts = 0;
-}
+std::mapLayoutKey, StructLayout TheMap = *LayoutInfo;
+std::mapLayoutKey, StructLayout::iterator
+  I = TheMap.lower_bound(LayoutKey(this, (const StructType*)0));
+
+for (std::mapLayoutKey, StructLayout::iterator E = TheMap.end();
+ I != E  I-first.first == this; )
+  TheMap.erase(I++);
   }
 }
 
@@ -252,17 +251,15 @@
 }
 
 const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
-  if (Layouts == 0)
-Layouts = new std::mapstd::pairconst TargetData*,const StructType*,
-   StructLayout();
-  std::mapstd::pairconst TargetData*,const StructType*,
- StructLayout::iterator
-I = Layouts-lower_bound(std::make_pair(this, Ty));
-  if (I != Layouts-end()  I-first.first == this  I-first.second == Ty)
+  std::mapLayoutKey, StructLayout TheMap = *LayoutInfo;
+  
+  std::mapLayoutKey, StructLayout::iterator
+I = TheMap.lower_bound(LayoutKey(this, Ty));
+  if (I != TheMap.end()  I-first.first == this  I-first.second == Ty)
 return I-second;
   else {
-return Layouts-insert(I, std::make_pair(std::make_pair(this, Ty),
-  StructLayout(Ty, 
*this)))-second;
+return TheMap.insert(I, std::make_pair(LayoutKey(this, Ty),
+StructLayout(Ty, *this)))-second;
   }
 }
 
@@ -271,12 +268,12 @@
 /// removed, this method must be called whenever a StructType is removed to
 /// avoid a dangling pointer in this cache.
 void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
-  if (!Layouts) return;  // No cache.
+  if (!LayoutInfo.isConstructed()) return;  // No cache.
 
-  std::mapstd::pairconst TargetData*,const StructType*,
-   StructLayout::iterator I = Layouts-find(std::make_pair(this, Ty));
-  if (I != Layouts-end())
-Layouts-erase(I);
+  std::mapLayoutKey, StructLayout::iterator I = 
+LayoutInfo-find(std::make_pair(this, Ty));
+  if (I != LayoutInfo-end())
+LayoutInfo-erase(I);
 }
 
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.87 - 1.88
---
Log message:

Privatize StructLayout::MemberOffsets, adding an accessor


---
Diffs of the changes:  (+1 -2)

 TargetData.cpp |3 +--
 1 files changed, 1 insertion(+), 2 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.87 llvm/lib/Target/TargetData.cpp:1.88
--- llvm/lib/Target/TargetData.cpp:1.87 Sat Feb 10 13:43:18 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 13:55:17 2007
@@ -466,8 +466,7 @@
   const StructLayout *Layout = getStructLayout(STy);
 
   // Add in the offset, as calculated by the structure layout info...
-  assert(FieldNo  Layout-MemberOffsets.size() FieldNo out of range!);
-  Result += Layout-MemberOffsets[FieldNo];
+  Result += Layout-getElementOffset(FieldNo);
 
   // Update Ty to refer to current element
   Ty = STy-getElementType(FieldNo);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.88 - 1.89
---
Log message:

encapsulate the rest of the StructLayout members.


---
Diffs of the changes:  (+4 -4)

 TargetData.cpp |8 
 1 files changed, 4 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.88 llvm/lib/Target/TargetData.cpp:1.89
--- llvm/lib/Target/TargetData.cpp:1.88 Sat Feb 10 13:55:17 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 13:59:22 2007
@@ -325,7 +325,7 @@
   case Type::StructTyID: {
 // Get the layout annotation... which is lazily created on demand.
 const StructLayout *Layout = TD-getStructLayout(castStructType(Ty));
-Size = Layout-StructSize; Alignment = Layout-StructAlignment;
+Size = Layout-getSizeInBytes(); Alignment = Layout-getAlignment();
 return;
   }
 
@@ -387,9 +387,9 @@
 // Get the layout annotation... which is lazily created on demand;
 // enforce minimum aggregate alignment.
 const StructLayout *Layout = TD-getStructLayout(castStructType(Ty));
-Size = Layout-StructSize;
-Alignment = std::max(Layout-StructAlignment,
- (const unsigned int) TD-getAggMinPrefAlignment());
+Size = Layout-getSizeInBytes();
+Alignment = std::max(Layout-getAlignment(),
+ (const unsigned int)TD-getAggMinPrefAlignment());
 return;
   }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.89 - 1.90
---
Log message:

eliminate the std::vector from StructLayout, allocating the elements immediately
after the StructLayout object in memory.  This marginally improves locality,
speeding up -load-vn -gcse by ~0.8%.



---
Diffs of the changes:  (+57 -43)

 TargetData.cpp |  100 -
 1 files changed, 57 insertions(+), 43 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.89 llvm/lib/Target/TargetData.cpp:1.90
--- llvm/lib/Target/TargetData.cpp:1.89 Sat Feb 10 13:59:22 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 14:15:41 2007
@@ -48,11 +48,11 @@
 StructLayout::StructLayout(const StructType *ST, const TargetData TD) {
   StructAlignment = 0;
   StructSize = 0;
+  NumElements = ST-getNumElements();
 
   // Loop over each of the elements, placing them in memory...
-  for (StructType::element_iterator TI = ST-element_begin(),
- TE = ST-element_end(); TI != TE; ++TI) {
-const Type *Ty = *TI;
+  for (unsigned i = 0, e = NumElements; i != e; ++i) {
+const Type *Ty = ST-getElementType(i);
 unsigned char A;
 unsigned TyAlign;
 uint64_t TySize;
@@ -66,7 +66,7 @@
 // Keep track of maximum alignment constraint
 StructAlignment = std::max(TyAlign, StructAlignment);
 
-MemberOffsets.push_back(StructSize);
+MemberOffsets[i] = StructSize;
 StructSize += TySize; // Consume space for this data item
   }
 
@@ -83,15 +83,15 @@
 /// getElementContainingOffset - Given a valid offset into the structure,
 /// return the structure index that contains it.
 unsigned StructLayout::getElementContainingOffset(uint64_t Offset) const {
-  std::vectoruint64_t::const_iterator SI =
-std::upper_bound(MemberOffsets.begin(), MemberOffsets.end(), Offset);
-  assert(SI != MemberOffsets.begin()  Offset not in structure type!);
+  const uint64_t *SI =
+std::upper_bound(MemberOffsets[0], MemberOffsets[NumElements], Offset);
+  assert(SI != MemberOffsets[0]  Offset not in structure type!);
   --SI;
   assert(*SI = Offset  upper_bound didn't work);
-  assert((SI == MemberOffsets.begin() || *(SI-1)  Offset) 
- (SI+1 == MemberOffsets.end() || *(SI+1)  Offset) 
+  assert((SI == MemberOffsets[0] || *(SI-1)  Offset) 
+ (SI+1 == MemberOffsets[NumElements] || *(SI+1)  Offset) 
  Upper bound didn't work!);
-  return SI-MemberOffsets.begin();
+  return SI-MemberOffsets[0];
 }
 
 
//===--===//
@@ -203,25 +203,66 @@
 }
 
 /// LayoutInfo - The lazy cache of structure layout information maintained by
-/// TargetData.
+/// TargetData.  Note that the struct types must have been free'd before
+/// llvm_shutdown is called (and thus this is deallocated) because all the
+/// targets with cached elements should have been destroyed.
 ///
 typedef std::pairconst TargetData*,const StructType* LayoutKey;
-static ManagedStaticstd::mapLayoutKey, StructLayout  LayoutInfo;
+static ManagedStaticstd::mapLayoutKey, StructLayout*  LayoutInfo;
 
 
 TargetData::~TargetData() {
   if (LayoutInfo.isConstructed()) {
 // Remove any layouts for this TD.
-std::mapLayoutKey, StructLayout TheMap = *LayoutInfo;
-std::mapLayoutKey, StructLayout::iterator
+std::mapLayoutKey, StructLayout* TheMap = *LayoutInfo;
+std::mapLayoutKey, StructLayout*::iterator
   I = TheMap.lower_bound(LayoutKey(this, (const StructType*)0));
 
-for (std::mapLayoutKey, StructLayout::iterator E = TheMap.end();
- I != E  I-first.first == this; )
+for (std::mapLayoutKey, StructLayout*::iterator E = TheMap.end();
+ I != E  I-first.first == this; ) {
+  I-second-~StructLayout();
+  free(I-second);
   TheMap.erase(I++);
+}
+  }
+}
+
+const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
+  std::mapLayoutKey, StructLayout* TheMap = *LayoutInfo;
+  
+  std::mapLayoutKey, StructLayout*::iterator
+  I = TheMap.lower_bound(LayoutKey(this, Ty));
+  if (I != TheMap.end()  I-first.first == this  I-first.second == Ty)
+return I-second;
+
+  // Otherwise, create the struct layout.  Because it is variable length, we 
+  // malloc it, then use placement new.
+  unsigned NumElts = Ty-getNumElements();
+  StructLayout *L =
+(StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1)*sizeof(uint64_t));
+  new (L) StructLayout(Ty, *this);
+
+  TheMap.insert(I, std::make_pair(LayoutKey(this, Ty), L));
+  return L;
+}
+
+/// InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout
+/// objects.  If a TargetData object is alive when types are being refined and
+/// removed, this method must be called whenever a StructType is removed to
+/// avoid a dangling pointer in this cache.
+void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
+  if (!LayoutInfo.isConstructed()) 

[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.90 - 1.91
---
Log message:

add a typedef


---
Diffs of the changes:  (+8 -9)

 TargetData.cpp |   17 -
 1 files changed, 8 insertions(+), 9 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.90 llvm/lib/Target/TargetData.cpp:1.91
--- llvm/lib/Target/TargetData.cpp:1.90 Sat Feb 10 14:15:41 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 14:18:06 2007
@@ -208,17 +208,18 @@
 /// targets with cached elements should have been destroyed.
 ///
 typedef std::pairconst TargetData*,const StructType* LayoutKey;
-static ManagedStaticstd::mapLayoutKey, StructLayout*  LayoutInfo;
+typedef std::mapLayoutKey, StructLayout* LayoutInfoTy;
+static ManagedStaticLayoutInfoTy LayoutInfo;
 
 
 TargetData::~TargetData() {
   if (LayoutInfo.isConstructed()) {
 // Remove any layouts for this TD.
-std::mapLayoutKey, StructLayout* TheMap = *LayoutInfo;
-std::mapLayoutKey, StructLayout*::iterator
+LayoutInfoTy TheMap = *LayoutInfo;
+LayoutInfoTy::iterator
   I = TheMap.lower_bound(LayoutKey(this, (const StructType*)0));
 
-for (std::mapLayoutKey, StructLayout*::iterator E = TheMap.end();
+for (LayoutInfoTy::iterator E = TheMap.end();
  I != E  I-first.first == this; ) {
   I-second-~StructLayout();
   free(I-second);
@@ -228,10 +229,9 @@
 }
 
 const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
-  std::mapLayoutKey, StructLayout* TheMap = *LayoutInfo;
+  LayoutInfoTy TheMap = *LayoutInfo;
   
-  std::mapLayoutKey, StructLayout*::iterator
-  I = TheMap.lower_bound(LayoutKey(this, Ty));
+  LayoutInfoTy::iterator I = TheMap.lower_bound(LayoutKey(this, Ty));
   if (I != TheMap.end()  I-first.first == this  I-first.second == Ty)
 return I-second;
 
@@ -253,8 +253,7 @@
 void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
   if (!LayoutInfo.isConstructed()) return;  // No cache.
   
-  std::mapLayoutKey, StructLayout*::iterator I = 
-LayoutInfo-find(LayoutKey(this, Ty));
+  LayoutInfoTy::iterator I = LayoutInfo-find(LayoutKey(this, Ty));
   if (I != LayoutInfo-end()) {
 I-second-~StructLayout();
 free(I-second);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-10 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.91 - 1.92
---
Log message:

Switch LayoutInfo to be a DenseMap instead of an std::map.  This speeds up
-load-vn -gcse by 2.3%.


---
Diffs of the changes:  (+31 -13)

 TargetData.cpp |   44 +++-
 1 files changed, 31 insertions(+), 13 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.91 llvm/lib/Target/TargetData.cpp:1.92
--- llvm/lib/Target/TargetData.cpp:1.91 Sat Feb 10 14:18:06 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Feb 10 14:26:17 2007
@@ -23,6 +23,7 @@
 #include llvm/Support/GetElementPtrTypeIterator.h
 #include llvm/Support/MathExtras.h
 #include llvm/Support/ManagedStatic.h
+#include llvm/ADT/DenseMap.h
 #include llvm/ADT/StringExtras.h
 #include algorithm
 #include cstdlib
@@ -208,7 +209,20 @@
 /// targets with cached elements should have been destroyed.
 ///
 typedef std::pairconst TargetData*,const StructType* LayoutKey;
-typedef std::mapLayoutKey, StructLayout* LayoutInfoTy;
+
+struct DenseMapLayoutKeyInfo {
+  static inline LayoutKey getEmptyKey() { return LayoutKey(0, 0); }
+  static inline LayoutKey getTombstoneKey() {
+return LayoutKey((TargetData*)(intptr_t)-1, 0);
+  }
+  static unsigned getHashValue(const LayoutKey Val) {
+return DenseMapKeyInfovoid*::getHashValue(Val.first) ^
+   DenseMapKeyInfovoid*::getHashValue(Val.second);
+  }
+  static bool isPod() { return true; }
+};
+
+typedef DenseMapLayoutKey, StructLayout*, DenseMapLayoutKeyInfo LayoutInfoTy;
 static ManagedStaticLayoutInfoTy LayoutInfo;
 
 
@@ -216,14 +230,15 @@
   if (LayoutInfo.isConstructed()) {
 // Remove any layouts for this TD.
 LayoutInfoTy TheMap = *LayoutInfo;
-LayoutInfoTy::iterator
-  I = TheMap.lower_bound(LayoutKey(this, (const StructType*)0));
-
-for (LayoutInfoTy::iterator E = TheMap.end();
- I != E  I-first.first == this; ) {
-  I-second-~StructLayout();
-  free(I-second);
-  TheMap.erase(I++);
+for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end();
+ I != E; ) {
+  if (I-first.first == this) {
+I-second-~StructLayout();
+free(I-second);
+TheMap.erase(I++);
+  } else {
+++I;
+  }
 }
   }
 }
@@ -231,18 +246,21 @@
 const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
   LayoutInfoTy TheMap = *LayoutInfo;
   
-  LayoutInfoTy::iterator I = TheMap.lower_bound(LayoutKey(this, Ty));
-  if (I != TheMap.end()  I-first.first == this  I-first.second == Ty)
-return I-second;
+  StructLayout *SL = TheMap[LayoutKey(this, Ty)];
+  if (SL) return SL;
 
   // Otherwise, create the struct layout.  Because it is variable length, we 
   // malloc it, then use placement new.
   unsigned NumElts = Ty-getNumElements();
   StructLayout *L =
 (StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1)*sizeof(uint64_t));
+  
+  // Set SL before calling StructLayout's ctor.  The ctor could cause other
+  // entries to be added to TheMap, invalidating our reference.
+  SL = L;
+  
   new (L) StructLayout(Ty, *this);
 
-  TheMap.insert(I, std::make_pair(LayoutKey(this, Ty), L));
   return L;
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-02-05 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.84 - 1.85
---
Log message:

Although targets are not required to support integers  64bits, TargetData
must in order for backends that do want to support large integer types to be 
able to function. Consequently, don't assert if the bitwidth  64 bits 
when computing the size and alignment. Instead, compute the size by rounding
up to the next even number of bytes for the size. Compute the alignment
as the same as the LongABIAlignment. These provide reasonable defaults 
that the target can override.


---
Diffs of the changes:  (+4 -2)

 TargetData.cpp |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.84 llvm/lib/Target/TargetData.cpp:1.85
--- llvm/lib/Target/TargetData.cpp:1.84 Wed Jan 31 15:31:25 2007
+++ llvm/lib/Target/TargetData.cpp  Mon Feb  5 17:51:43 2007
@@ -295,8 +295,10 @@
   Size = 4; Alignment = TD-getIntABIAlignment();
 } else if (BitWidth = 64) {
   Size = 8; Alignment = TD-getLongABIAlignment();
-} else
-  assert(0  Integer types  64 bits not supported.);
+} else {
+  Size = ((BitWidth + 7) / 8)  ~1;
+  Alignment = TD-getLongABIAlignment();
+}
 return;
   }
   case Type::VoidTyID:   Size = 1; Alignment = TD-getByteABIAlignment(); 
return;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-31 Thread Evan Cheng


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.83 - 1.84
---
Log message:

Dead comment.

---
Diffs of the changes:  (+0 -1)

 TargetData.cpp |1 -
 1 files changed, 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.83 llvm/lib/Target/TargetData.cpp:1.84
--- llvm/lib/Target/TargetData.cpp:1.83 Fri Jan 26 02:11:39 2007
+++ llvm/lib/Target/TargetData.cpp  Wed Jan 31 15:31:25 2007
@@ -495,7 +495,6 @@
 Alignment = Log2_32(GV-getAlignment());
   
   if (GV-hasInitializer()) {
-// Always round up alignment of global doubles to 8 bytes.
 if (Alignment  4) {
   // If the global is not external, see if it is large.  If so, give it a
   // larger alignment.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-26 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.82 - 1.83
---
Log message:

For PR761: http://llvm.org/PR761 :
The Module::setEndianness and Module::setPointerSize methods have been
removed. Instead you can get/set the DataLayout. Adjust thise accordingly.


---
Diffs of the changes:  (+3 -21)

 TargetData.cpp |   24 +++-
 1 files changed, 3 insertions(+), 21 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.82 llvm/lib/Target/TargetData.cpp:1.83
--- llvm/lib/Target/TargetData.cpp:1.82 Wed Jan 24 01:03:39 2007
+++ llvm/lib/Target/TargetData.cpp  Fri Jan 26 02:11:39 2007
@@ -189,8 +189,8 @@
 }
   }
 
-  // Unless explicitly specified, the alignments for longs and doubles is 
capped by 
-  // pointer size.
+  // Unless explicitly specified, the alignments for longs and doubles is 
+  // capped by pointer size.
   if (LongABIAlignment == 0)
  LongABIAlignment = LongPrefAlignment = PointerMemSize;
   if (DoubleABIAlignment == 0)
@@ -198,25 +198,7 @@
 }
 
 TargetData::TargetData(const Module *M) {
-  LittleEndian   = M-getEndianness() != Module::BigEndian;
-  PointerMemSize = M-getPointerSize() != Module::Pointer64 ? 4 : 8;
-  PointerABIAlignment = PointerMemSize;
-  DoubleABIAlignment  = PointerMemSize;
-  FloatABIAlignment   = 4;
-  LongABIAlignment= PointerMemSize;
-  IntABIAlignment = 4;
-  ShortABIAlignment   = 2;
-  ByteABIAlignment= 1;
-  BoolABIAlignment= 1;
-  BoolPrefAlignment = BoolABIAlignment;
-  BytePrefAlignment = ByteABIAlignment;
-  ShortPrefAlignment = ShortABIAlignment;
-  IntPrefAlignment = IntABIAlignment;
-  LongPrefAlignment = LongABIAlignment;
-  FloatPrefAlignment = FloatABIAlignment;
-  DoublePrefAlignment = DoubleABIAlignment;
-  PointerPrefAlignment = PointerABIAlignment;
-  AggMinPrefAlignment = 0;
+  init(M-getDataLayout());
 }
 
 /// Layouts - The lazy cache of structure layout information maintained by



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-23 Thread Evan Cheng


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.81 - 1.82
---
Log message:

Renamed getTypeAlignmentShift() to getPreferredTypeAlignmentShift().

---
Diffs of the changes:  (+2 -2)

 TargetData.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.81 llvm/lib/Target/TargetData.cpp:1.82
--- llvm/lib/Target/TargetData.cpp:1.81 Mon Jan 22 17:08:19 2007
+++ llvm/lib/Target/TargetData.cpp  Wed Jan 24 01:03:39 2007
@@ -450,7 +450,7 @@
   return Align;
 }
 
-unsigned char TargetData::getTypeAlignmentShift(const Type *Ty) const {
+unsigned char TargetData::getPreferredTypeAlignmentShift(const Type *Ty) const 
{
   unsigned Align = getTypeAlignmentPref(Ty);
   assert(!(Align  (Align-1))  Alignment is not a power of two!);
   return Log2_32(Align);
@@ -508,7 +508,7 @@
 /// requested alignment (if the global has one).
 unsigned TargetData::getPreferredAlignmentLog(const GlobalVariable *GV) const {
   const Type *ElemType = GV-getType()-getElementType();
-  unsigned Alignment = getTypeAlignmentShift(ElemType);
+  unsigned Alignment = getPreferredTypeAlignmentShift(ElemType);
   if (GV-getAlignment()  (1U  Alignment))
 Alignment = Log2_32(GV-getAlignment());
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-20 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.76 - 1.77
---
Log message:

Teach TargetData to handle 'preferred' alignment for each target, and use 
these alignment amounts to align scalars when we can.  Patch by Scott Michel!



---
Diffs of the changes:  (+186 -57)

 TargetData.cpp |  243 +++--
 1 files changed, 186 insertions(+), 57 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.76 llvm/lib/Target/TargetData.cpp:1.77
--- llvm/lib/Target/TargetData.cpp:1.76 Fri Jan 12 01:05:13 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Jan 20 16:35:55 2007
@@ -34,8 +34,11 @@
   RegisterPassTargetData X(targetdata, Target Data Layout);
 }
 
-static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
-   uint64_t Size, unsigned char Alignment);
+static inline void getTypeInfoABI(const Type *Ty, const TargetData *TD,
+  uint64_t Size, unsigned char Alignment);
+
+static inline void getTypeInfoPref(const Type *Ty, const TargetData *TD,
+   uint64_t Size, unsigned char Alignment);
 
 
//===--===//
 // Support for StructLayout
@@ -52,7 +55,7 @@
 unsigned char A;
 unsigned TyAlign;
 uint64_t TySize;
-getTypeInfo(Ty, TD, TySize, A);
+getTypeInfoABI(Ty, TD, TySize, A);
 TyAlign = ST-isPacked() ? 1 : A;
 
 // Add padding if necessary to make the data element aligned properly...
@@ -80,8 +83,7 @@
 /// return the structure index that contains it.
 unsigned StructLayout::getElementContainingOffset(uint64_t Offset) const {
   std::vectoruint64_t::const_iterator SI =
-std::upper_bound(MemberOffsets.begin(), MemberOffsets.end(),
- Offset);
+std::upper_bound(MemberOffsets.begin(), MemberOffsets.end(), Offset);
   assert(SI != MemberOffsets.begin()  Offset not in structure type!);
   --SI;
   assert(*SI = Offset  upper_bound didn't work);
@@ -99,15 +101,24 @@
   std::string temp = TargetDescription;
   
   LittleEndian = false;
-  PointerSize = 8;
-  PointerAlignment   = 8;
-  DoubleAlignment = 8;
-  FloatAlignment = 4;
-  LongAlignment   = 8;
-  IntAlignment   = 4;
-  ShortAlignment  = 2;
-  ByteAlignment  = 1;
-  BoolAlignment   = 1;
+  PointerMemSize = 8;
+  PointerABIAlignment   = 8;
+  DoubleABIAlignment = 8;
+  FloatABIAlignment = 4;
+  LongABIAlignment   = 8;
+  IntABIAlignment   = 4;
+  ShortABIAlignment  = 2;
+  ByteABIAlignment  = 1;
+  BoolABIAlignment   = 1;
+  BoolPrefAlignment = BoolABIAlignment;
+  BytePrefAlignment = ByteABIAlignment;
+  ShortPrefAlignment = ShortABIAlignment;
+  IntPrefAlignment = IntABIAlignment;
+  LongPrefAlignment = LongABIAlignment;
+  FloatPrefAlignment = FloatABIAlignment;
+  DoublePrefAlignment = DoubleABIAlignment;
+  PointerPrefAlignment = PointerABIAlignment;
+  AggMinPrefAlignment = 0;
   
   while (!temp.empty()) {
 std::string token = getToken(temp, -);
@@ -122,29 +133,58 @@
   LittleEndian = true;
   break;
 case 'p':
-  PointerSize = atoi(getToken(token,:).c_str()) / 8;
-  PointerAlignment = atoi(getToken(token,:).c_str()) / 8;
+  PointerMemSize = atoi(getToken(token,:).c_str()) / 8;
+  PointerABIAlignment = atoi(getToken(token,:).c_str()) / 8;
+  PointerPrefAlignment = atoi(getToken(token,:).c_str()) / 8;
+  if (PointerPrefAlignment == 0)
+PointerPrefAlignment = PointerABIAlignment;
   break;
 case 'd':
-  DoubleAlignment = atoi(getToken(token,:).c_str()) / 8;
+  DoubleABIAlignment = atoi(getToken(token,:).c_str()) / 8;
+  DoublePrefAlignment = atoi(getToken(token,:).c_str()) / 8;
+  if (DoublePrefAlignment == 0)
+DoublePrefAlignment = DoubleABIAlignment;
   break;
 case 'f':
-  FloatAlignment = atoi(getToken(token, :).c_str()) / 8;
+  FloatABIAlignment = atoi(getToken(token, :).c_str()) / 8;
+  FloatPrefAlignment = atoi(getToken(token,:).c_str()) / 8;
+  if (FloatPrefAlignment == 0)
+FloatPrefAlignment = FloatABIAlignment;
   break;
 case 'l':
-  LongAlignment = atoi(getToken(token, :).c_str()) / 8;
+  LongABIAlignment = atoi(getToken(token, :).c_str()) / 8;
+  LongPrefAlignment = atoi(getToken(token,:).c_str()) / 8;
+  if (LongPrefAlignment == 0)
+LongPrefAlignment = LongABIAlignment;
   break;
 case 'i':
-  IntAlignment = atoi(getToken(token, :).c_str()) / 8;
+  IntABIAlignment = atoi(getToken(token, :).c_str()) / 8;
+  IntPrefAlignment = atoi(getToken(token,:).c_str()) / 8;
+  if (IntPrefAlignment == 0)
+IntPrefAlignment = IntABIAlignment;
   break;
 case 's':
-  ShortAlignment = atoi(getToken(token, :).c_str()) / 8;
+  ShortABIAlignment = atoi(getToken(token, :).c_str()) / 8;
+  ShortPrefAlignment = atoi(getToken(token,:).c_str()) / 8;
+  if 

[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-20 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.77 - 1.78
---
Log message:

trivial cleanup


---
Diffs of the changes:  (+0 -2)

 TargetData.cpp |2 --
 1 files changed, 2 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.77 llvm/lib/Target/TargetData.cpp:1.78
--- llvm/lib/Target/TargetData.cpp:1.77 Sat Jan 20 16:35:55 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Jan 20 16:39:15 2007
@@ -183,8 +183,6 @@
   break;
 case 'A':
   AggMinPrefAlignment = atoi(getToken(token,:).c_str()) / 8;
-  if (AggMinPrefAlignment == 0)
-AggMinPrefAlignment = 0;
   break;
 default:
   break;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-20 Thread Owen Anderson


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.78 - 1.79
---
Log message:

TargetData assumes (and some regression tests depend on it) that the size of
an unspecified datatype in the datalayout is capped by the size of a pointer.


---
Diffs of the changes:  (+11 -4)

 TargetData.cpp |   15 +++
 1 files changed, 11 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.78 llvm/lib/Target/TargetData.cpp:1.79
--- llvm/lib/Target/TargetData.cpp:1.78 Sat Jan 20 16:39:15 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Jan 20 17:07:13 2007
@@ -103,9 +103,9 @@
   LittleEndian = false;
   PointerMemSize = 8;
   PointerABIAlignment   = 8;
-  DoubleABIAlignment = 8;
+  DoubleABIAlignment = 0;
   FloatABIAlignment = 4;
-  LongABIAlignment   = 8;
+  LongABIAlignment   = 0;
   IntABIAlignment   = 4;
   ShortABIAlignment  = 2;
   ByteABIAlignment  = 1;
@@ -114,9 +114,9 @@
   BytePrefAlignment = ByteABIAlignment;
   ShortPrefAlignment = ShortABIAlignment;
   IntPrefAlignment = IntABIAlignment;
-  LongPrefAlignment = LongABIAlignment;
+  LongPrefAlignment = 8;
   FloatPrefAlignment = FloatABIAlignment;
-  DoublePrefAlignment = DoubleABIAlignment;
+  DoublePrefAlignment = 8;
   PointerPrefAlignment = PointerABIAlignment;
   AggMinPrefAlignment = 0;
   
@@ -188,6 +188,13 @@
   break;
 }
   }
+
+  // Unless explicitly specified, the alignments for longs and doubles is 
capped by 
+  // pointer size.
+  if (LongABIAlignment == 0)
+ LongABIAlignment = LongPrefAlignment = PointerMemSize;
+  if (DoubleABIAlignment == 0)
+DoubleABIAlignment = DoublePrefAlignment = PointerMemSize;
 }
 
 TargetData::TargetData(const Module *M) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-20 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.79 - 1.80
---
Log message:

Implement a getTypeSizeInBits method. This helps in transforms that want
to ensure the bit size of a type is identical before proceeding.


---
Diffs of the changes:  (+10 -0)

 TargetData.cpp |   10 ++
 1 files changed, 10 insertions(+)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.79 llvm/lib/Target/TargetData.cpp:1.80
--- llvm/lib/Target/TargetData.cpp:1.79 Sat Jan 20 17:07:13 2007
+++ llvm/lib/Target/TargetData.cpp  Sat Jan 20 17:32:04 2007
@@ -426,6 +426,16 @@
   return Size;
 }
 
+uint64_t TargetData::getTypeSizeInBits(const Type *Ty) const {
+  if (Ty-isInteger())
+return castIntegerType(Ty)-getBitWidth();
+
+  uint64_t Size;
+  unsigned char Align;
+  getTypeInfoABI(Ty, this, Size, Align);
+  return Size * 8;
+}
+
 unsigned char TargetData::getTypeAlignmentABI(const Type *Ty) const {
   uint64_t Size;
   unsigned char Align;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-11 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.74 - 1.75
---
Log message:

Rename BoolTy as Int1Ty. Patch by Sheng Zhou.


---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.74 llvm/lib/Target/TargetData.cpp:1.75
--- llvm/lib/Target/TargetData.cpp:1.74 Sat Dec 30 23:55:36 2006
+++ llvm/lib/Target/TargetData.cpp  Thu Jan 11 12:21:29 2007
@@ -241,7 +241,7 @@
uint64_t Size, unsigned char Alignment) {
   assert(Ty-isSized()  Cannot getTypeInfo() on a type that is unsized!);
   switch (Ty-getTypeID()) {
-  case Type::BoolTyID:   Size = 1; Alignment = TD-getBoolAlignment(); return;
+  case Type::Int1TyID:   Size = 1; Alignment = TD-getBoolAlignment(); return;
   case Type::VoidTyID:
   case Type::Int8TyID:   Size = 1; Alignment = TD-getByteAlignment(); return;
   case Type::Int16TyID:  Size = 2; Alignment = TD-getShortAlignment(); return;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2007-01-11 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.75 - 1.76
---
Log message:

For PR1064: http://llvm.org/PR1064 :
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8, 
16, 32, and 64 bit integers.  

This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
   bits in an integer. The Type classes SubclassData field is used to
   store the number of bits. This allows 2^23 bits in an integer type. 
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
   64-bit integers. These are replaced with just IntegerType which is not
   a primitive any more. 
3. Adjust the rest of LLVM to account for this change.

Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with 
them in any significant way. Most optimization passes, for example, will 
still only deal with the byte-width integer types.  Future increments
will rectify this situation.



---
Diffs of the changes:  (+15 -6)

 TargetData.cpp |   21 +++--
 1 files changed, 15 insertions(+), 6 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.75 llvm/lib/Target/TargetData.cpp:1.76
--- llvm/lib/Target/TargetData.cpp:1.75 Thu Jan 11 12:21:29 2007
+++ llvm/lib/Target/TargetData.cpp  Fri Jan 12 01:05:13 2007
@@ -241,12 +241,21 @@
uint64_t Size, unsigned char Alignment) {
   assert(Ty-isSized()  Cannot getTypeInfo() on a type that is unsized!);
   switch (Ty-getTypeID()) {
-  case Type::Int1TyID:   Size = 1; Alignment = TD-getBoolAlignment(); return;
-  case Type::VoidTyID:
-  case Type::Int8TyID:   Size = 1; Alignment = TD-getByteAlignment(); return;
-  case Type::Int16TyID:  Size = 2; Alignment = TD-getShortAlignment(); return;
-  case Type::Int32TyID:  Size = 4; Alignment = TD-getIntAlignment(); return;
-  case Type::Int64TyID:  Size = 8; Alignment = TD-getLongAlignment(); return;
+  case Type::IntegerTyID: {
+unsigned BitWidth = castIntegerType(Ty)-getBitWidth();
+if (BitWidth = 8) {
+  Size = 1; Alignment = TD-getByteAlignment();
+} else if (BitWidth = 16) {
+  Size = 2; Alignment = TD-getShortAlignment();
+} else if (BitWidth = 32) {
+  Size = 4; Alignment = TD-getIntAlignment();
+} else if (BitWidth = 64) {
+  Size = 8; Alignment = TD-getLongAlignment();
+} else
+  assert(0  Integer types  64 bits not supported.);
+return;
+  }
+  case Type::VoidTyID:   Size = 1; Alignment = TD-getByteAlignment(); return;
   case Type::FloatTyID:  Size = 4; Alignment = TD-getFloatAlignment(); return;
   case Type::DoubleTyID: Size = 8; Alignment = TD-getDoubleAlignment(); 
return;
   case Type::LabelTyID:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-12-08 Thread Andrew Lenharth


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.72 - 1.73
---
Log message:

Packed Structures

---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.72 llvm/lib/Target/TargetData.cpp:1.73
--- llvm/lib/Target/TargetData.cpp:1.72 Tue Oct 24 15:32:14 2006
+++ llvm/lib/Target/TargetData.cpp  Fri Dec  8 12:06:15 2006
@@ -53,7 +53,7 @@
 unsigned TyAlign;
 uint64_t TySize;
 getTypeInfo(Ty, TD, TySize, A);
-TyAlign = A;
+TyAlign = ST-isPacked() ? 1 : A;
 
 // Add padding if necessary to make the data element aligned properly...
 if (StructSize % TyAlign != 0)



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-10-24 Thread Devang Patel


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.71 - 1.72
---
Log message:

Move getPreferredAlignmentLog from AsmPrinter to TargetData


---
Diffs of the changes:  (+23 -0)

 TargetData.cpp |   23 +++
 1 files changed, 23 insertions(+)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.71 llvm/lib/Target/TargetData.cpp:1.72
--- llvm/lib/Target/TargetData.cpp:1.71 Fri Oct 20 02:07:24 2006
+++ llvm/lib/Target/TargetData.cpp  Tue Oct 24 15:32:14 2006
@@ -354,3 +354,26 @@
   return Result;
 }
 
+/// getPreferredAlignmentLog - Return the preferred alignment of the
+/// specified global, returned in log form.  This includes an explicitly
+/// requested alignment (if the global has one).
+unsigned TargetData::getPreferredAlignmentLog(const GlobalVariable *GV) const {
+  const Type *ElemType = GV-getType()-getElementType();
+  unsigned Alignment = getTypeAlignmentShift(ElemType);
+  if (GV-getAlignment()  (1U  Alignment))
+Alignment = Log2_32(GV-getAlignment());
+  
+  if (GV-hasInitializer()) {
+// Always round up alignment of global doubles to 8 bytes.
+if (GV-getType()-getElementType() == Type::DoubleTy  Alignment  3)
+  Alignment = 3;
+if (Alignment  4) {
+  // If the global is not external, see if it is large.  If so, give it a
+  // larger alignment.
+  if (getTypeSize(ElemType)  128)
+Alignment = 4;// 16-byte alignment.
+}
+  }
+  return Alignment;
+}
+



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-10-20 Thread Reid Spencer


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.70 - 1.71
---
Log message:

For PR950: http://llvm.org/PR950 :
This patch implements the first increment for the Signless Types feature.
All changes pertain to removing the ConstantSInt and ConstantUInt classes
in favor of just using ConstantInt.


---
Diffs of the changes:  (+2 -2)

 TargetData.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.70 llvm/lib/Target/TargetData.cpp:1.71
--- llvm/lib/Target/TargetData.cpp:1.70 Fri Jun 16 13:22:52 2006
+++ llvm/lib/Target/TargetData.cpp  Fri Oct 20 02:07:24 2006
@@ -330,7 +330,7 @@
   for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX, ++TI) {
 if (const StructType *STy = dyn_castStructType(*TI)) {
   assert(Idx[CurIDX]-getType() == Type::UIntTy  Illegal struct idx);
-  unsigned FieldNo = castConstantUInt(Idx[CurIDX])-getValue();
+  unsigned FieldNo = castConstantInt(Idx[CurIDX])-getZExtValue();
 
   // Get structure layout information...
   const StructLayout *Layout = getStructLayout(STy);
@@ -346,7 +346,7 @@
   Ty = castSequentialType(Ty)-getElementType();
 
   // Get the array index and the size of each array element.
-  int64_t arrayIdx = castConstantInt(Idx[CurIDX])-getRawValue();
+  int64_t arrayIdx = castConstantInt(Idx[CurIDX])-getSExtValue();
   Result += arrayIdx * (int64_t)getTypeSize(Ty);
 }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-06-16 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.68 - 1.69
---
Log message:

Remove ctor with each piece specifyable (which causes overload ambiguities),
add a new init method.


---
Diffs of the changes:  (+1 -32)

 TargetData.cpp |   33 +
 1 files changed, 1 insertion(+), 32 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.68 llvm/lib/Target/TargetData.cpp:1.69
--- llvm/lib/Target/TargetData.cpp:1.68 Sat May 20 18:28:54 2006
+++ llvm/lib/Target/TargetData.cpp  Fri Jun 16 13:11:26 2006
@@ -95,38 +95,7 @@
 //   TargetData Class Implementation
 
//===--===//
 
-TargetData::TargetData(const std::string TargetName,
-   bool isLittleEndian, unsigned char PtrSize,
-   unsigned char PtrAl, unsigned char DoubleAl,
-   unsigned char FloatAl, unsigned char LongAl,
-   unsigned char IntAl, unsigned char ShortAl,
-   unsigned char ByteAl, unsigned char BoolAl) {
-
-  // If this assert triggers, a pass required TargetData information, but the
-  // top level tool did not provide one for it.  We do not want to default
-  // construct, or else we might end up using a bad endianness or pointer size!
-  //
-  assert(!TargetName.empty() 
- ERROR: Tool did not specify a target data to use!);
-
-  LittleEndian = isLittleEndian;
-  PointerSize  = PtrSize;
-  PointerAlignment = PtrAl;
-  DoubleAlignment  = DoubleAl;
-  FloatAlignment   = FloatAl;
-  LongAlignment= LongAl;
-  IntAlignment = IntAl;
-  ShortAlignment   = ShortAl;
-  ByteAlignment= ByteAl;
-  BoolAlignment= BoolAl;
-}
-
-TargetData::TargetData(const std::string TargetName,
-   const std::string TargetDescription) {
-  assert(!TargetName.empty() 
- ERROR: Tool did not specify a target data to use!);
-
-   
+void TargetData::init(const std::string TargetDescription) {
   std::string temp = TargetDescription;
   
   LittleEndian = false;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-05-20 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.66 - 1.67
---
Log message:

Fix a parsing bug that caused 7 llvm-test regressions on PPC last night.  
I'm suprised it didn't cause more!


---
Diffs of the changes:  (+7 -7)

 TargetData.cpp |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.66 llvm/lib/Target/TargetData.cpp:1.67
--- llvm/lib/Target/TargetData.cpp:1.66 Fri May 19 19:24:56 2006
+++ llvm/lib/Target/TargetData.cpp  Sat May 20 16:16:59 2006
@@ -157,31 +157,31 @@
   PointerAlignment = atoi(getToken(token,:).c_str()) / 8;
   break;
 case 'd':
-  token = getToken(token,:); //Ignore the size
+  getToken(token,:); //Ignore the size
   DoubleAlignment = atoi(getToken(token,:).c_str()) / 8;
   break;
 case 'f':
-  token = getToken(token, :); //Ignore the size
+  getToken(token, :); //Ignore the size
   FloatAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'l':
-  token = getToken(token, :); //Ignore the size
+  getToken(token, :); //Ignore the size
   LongAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'i':
-  token = getToken(token, :); //Ignore the size
+  getToken(token, :); //Ignore the size
   IntAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 's':
-  token = getToken(token, :); //Ignore the size
+  getToken(token, :); //Ignore the size
   ShortAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'b':
-  token = getToken(token, :); //Ignore the size
+  getToken(token, :); //Ignore the size
   ByteAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'B':
-  token = getToken(token, :); //Ignore the size
+  getToken(token, :); //Ignore the size
   BoolAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 default:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-05-20 Thread Owen Anderson


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.67 - 1.68
---
Log message:

Make TargetData strings less redundant.


---
Diffs of the changes:  (+0 -7)

 TargetData.cpp |7 ---
 1 files changed, 7 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.67 llvm/lib/Target/TargetData.cpp:1.68
--- llvm/lib/Target/TargetData.cpp:1.67 Sat May 20 16:16:59 2006
+++ llvm/lib/Target/TargetData.cpp  Sat May 20 18:28:54 2006
@@ -157,31 +157,24 @@
   PointerAlignment = atoi(getToken(token,:).c_str()) / 8;
   break;
 case 'd':
-  getToken(token,:); //Ignore the size
   DoubleAlignment = atoi(getToken(token,:).c_str()) / 8;
   break;
 case 'f':
-  getToken(token, :); //Ignore the size
   FloatAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'l':
-  getToken(token, :); //Ignore the size
   LongAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'i':
-  getToken(token, :); //Ignore the size
   IntAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 's':
-  getToken(token, :); //Ignore the size
   ShortAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'b':
-  getToken(token, :); //Ignore the size
   ByteAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 case 'B':
-  getToken(token, :); //Ignore the size
   BoolAlignment = atoi(getToken(token, :).c_str()) / 8;
   break;
 default:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-05-19 Thread Owen Anderson


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.65 - 1.66
---
Log message:

Make all of the TargetMachine subclasses use the new string TargetData methods.

This is part of the on-going work on PR 761: http://llvm.cs.uiuc.edu/PR761 .


---
Diffs of the changes:  (+5 -1)

 TargetData.cpp |6 +-
 1 files changed, 5 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.65 llvm/lib/Target/TargetData.cpp:1.66
--- llvm/lib/Target/TargetData.cpp:1.65 Wed May 17 16:56:02 2006
+++ llvm/lib/Target/TargetData.cpp  Fri May 19 19:24:56 2006
@@ -123,6 +123,10 @@
 
 TargetData::TargetData(const std::string TargetName,
const std::string TargetDescription) {
+  assert(!TargetName.empty() 
+ ERROR: Tool did not specify a target data to use!);
+
+   
   std::string temp = TargetDescription;
   
   LittleEndian = false;
@@ -136,7 +140,7 @@
   ByteAlignment  = 1;
   BoolAlignment   = 1;
   
-  while (temp.length()  0) {
+  while (!temp.empty()) {
 std::string token = getToken(temp, -);
 
 char signal = getToken(token, :)[0];



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-05-17 Thread Owen Anderson


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.64 - 1.65
---
Log message:

Fix a stupid bug when parsing TargetData strings.


---
Diffs of the changes:  (+3 -1)

 TargetData.cpp |4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.64 llvm/lib/Target/TargetData.cpp:1.65
--- llvm/lib/Target/TargetData.cpp:1.64 Fri May 12 02:01:44 2006
+++ llvm/lib/Target/TargetData.cpp  Wed May 17 16:56:02 2006
@@ -139,7 +139,9 @@
   while (temp.length()  0) {
 std::string token = getToken(temp, -);
 
-switch(token[0]) {
+char signal = getToken(token, :)[0];
+
+switch(signal) {
 case 'E':
   LittleEndian = false;
   break;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-05-12 Thread Owen Anderson


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.62 - 1.63
---
Log message:

Fix some tabbing issues.


---
Diffs of the changes:  (+29 -29)

 TargetData.cpp |   58 -
 1 files changed, 29 insertions(+), 29 deletions(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.62 llvm/lib/Target/TargetData.cpp:1.63
--- llvm/lib/Target/TargetData.cpp:1.62 Fri May 12 00:49:47 2006
+++ llvm/lib/Target/TargetData.cpp  Fri May 12 01:06:55 2006
@@ -140,45 +140,45 @@
 
 switch(token[0]) {
 case 'E':
-   LittleEndian = false;
-break;
+  LittleEndian = false;
+  break;
 case 'e':
-   LittleEndian = true;
-   break;
+  LittleEndian = true;
+  break;
 case 'p':
-   PointerSize = atoi(getToken(token,:).c_str()) / 8;
-   PointerAlignment = atoi(getToken(token,:).c_str()) / 8;
-   break;
+  PointerSize = atoi(getToken(token,:).c_str()) / 8;
+  PointerAlignment = atoi(getToken(token,:).c_str()) / 8;
+  break;
 case 'd':
-   token = getToken(token,:); //Ignore the size
-   DoubleAlignment = atoi(getToken(token,:).c_str()) / 8;
-break;
+  token = getToken(token,:); //Ignore the size
+  DoubleAlignment = atoi(getToken(token,:).c_str()) / 8;
+  break;
 case 'f':
-   token = getToken(token, :); //Ignore the size
-   FloatAlignment = atoi(getToken(token, :).c_str()) / 8;
-   break;
+  token = getToken(token, :); //Ignore the size
+  FloatAlignment = atoi(getToken(token, :).c_str()) / 8;
+  break;
 case 'l':
-   token = getToken(token, :); //Ignore the size
-   LongAlignment = atoi(getToken(token, :).c_str()) / 8;
-   break;
+  token = getToken(token, :); //Ignore the size
+  LongAlignment = atoi(getToken(token, :).c_str()) / 8;
+  break;
 case 'i':
-   token = getToken(token, :); //Ignore the size
-   IntAlignment = atoi(getToken(token, :).c_str()) / 8;
-   break;
+  token = getToken(token, :); //Ignore the size
+  IntAlignment = atoi(getToken(token, :).c_str()) / 8;
+  break;
 case 's':
-   token = getToken(token, :); //Ignore the size
-   ShortAlignment = atoi(getToken(token, :).c_str()) / 8;
-   break;
+  token = getToken(token, :); //Ignore the size
+  ShortAlignment = atoi(getToken(token, :).c_str()) / 8;
+  break;
 case 'b':
-   token = getToken(token, :); //Ignore the size
-   ByteAlignment = atoi(getToken(token, :).c_str()) / 8;
-   break;
+  token = getToken(token, :); //Ignore the size
+  ByteAlignment = atoi(getToken(token, :).c_str()) / 8;
+  break;
 case 'B':
-   token = getToken(token, :); //Ignore the size
-   BoolAlignment = atoi(getToken(token, :).c_str()) / 8;
-   break;
+  token = getToken(token, :); //Ignore the size
+  BoolAlignment = atoi(getToken(token, :).c_str()) / 8;
+  break;
 default:
-   break;
+  break;
 }
   }
 }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-05-12 Thread Owen Anderson


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.63 - 1.64
---
Log message:

Add a method to generate a string representation from a TargetData.

This continues the work on PR 761: http://llvm.cs.uiuc.edu/PR761 .


---
Diffs of the changes:  (+21 -0)

 TargetData.cpp |   21 +
 1 files changed, 21 insertions(+)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.63 llvm/lib/Target/TargetData.cpp:1.64
--- llvm/lib/Target/TargetData.cpp:1.63 Fri May 12 01:06:55 2006
+++ llvm/lib/Target/TargetData.cpp  Fri May 12 02:01:44 2006
@@ -25,6 +25,7 @@
 #include llvm/ADT/StringExtras.h
 #include algorithm
 #include cstdlib
+#include sstream
 using namespace llvm;
 
 // Handle the Pass registration stuff necessary to use TargetData's.
@@ -218,6 +219,26 @@
   }
 }
 
+std::string TargetData::getStringRepresentation() const {
+  std::stringstream repr;
+  
+  if (LittleEndian)
+repr  e;
+  else
+repr  E;
+  
+  repr  -p:  (PointerSize * 8)  :  (PointerAlignment * 8);
+  repr  -d:64:  (DoubleAlignment * 8);
+  repr  -f:32:  (FloatAlignment * 8);
+  repr  -l:64:  (LongAlignment * 8);
+  repr  -i:32:  (IntAlignment * 8);
+  repr  -s:16:  (ShortAlignment * 8);
+  repr  -b:8:  (ByteAlignment * 8);
+  repr  -B:8:  (BoolAlignment * 8);
+  
+  return repr.str();
+}
+
 const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
   if (Layouts == 0)
 Layouts = new std::mapstd::pairconst TargetData*,const StructType*,



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-04-03 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.60 - 1.61
---
Log message:

revert previous patch


---
Diffs of the changes:  (+1 -1)

 TargetData.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.60 llvm/lib/Target/TargetData.cpp:1.61
--- llvm/lib/Target/TargetData.cpp:1.60 Mon Apr  3 14:28:50 2006
+++ llvm/lib/Target/TargetData.cpp  Mon Apr  3 18:14:49 2006
@@ -217,7 +217,7 @@
 Size = AlignedSize*PTy-getNumElements();
 // FIXME: The alignments of specific packed types are target dependent.
 // For now, just set it to be equal to Size.
-Alignment = (Size+7)/8;
+Alignment = Size;
 return;
   }
   case Type::StructTyID: {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-03-31 Thread Evan Cheng


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.58 - 1.59
---
Log message:

TargetData.cpp::getTypeInfo() was returning alignment of element type as the
alignment of a packed type. This is obviously wrong. Added a workaround that
returns the size of the packed type as its alignment. The correct fix would
be to return a target dependent alignment value provided via TargetLowering
(or some other interface).


---
Diffs of the changes:  (+3 -0)

 TargetData.cpp |3 +++
 1 files changed, 3 insertions(+)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.58 llvm/lib/Target/TargetData.cpp:1.59
--- llvm/lib/Target/TargetData.cpp:1.58 Fri Jan 13 18:07:34 2006
+++ llvm/lib/Target/TargetData.cpp  Fri Mar 31 16:33:42 2006
@@ -215,6 +215,9 @@
 getTypeInfo(PTy-getElementType(), TD, Size, Alignment);
 unsigned AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
 Size = AlignedSize*PTy-getNumElements();
+// FIXME: The alignments of specific packed types are target dependent.
+// For now, just set it to be equal to Size.
+Alignment = Size;
 return;
   }
   case Type::StructTyID: {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

2006-01-13 Thread Chris Lattner


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.57 - 1.58
---
Log message:

Implement a new InvalidateStructLayoutInfo method and add some comments


---
Diffs of the changes:  (+18 -0)

 TargetData.cpp |   18 ++
 1 files changed, 18 insertions(+)


Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.57 llvm/lib/Target/TargetData.cpp:1.58
--- llvm/lib/Target/TargetData.cpp:1.57 Tue Aug  2 14:25:02 2005
+++ llvm/lib/Target/TargetData.cpp  Fri Jan 13 18:07:34 2006
@@ -131,6 +131,9 @@
   BoolAlignment= 1;
 }
 
+/// Layouts - The lazy cache of structure layout information maintained by
+/// TargetData.
+///
 static std::mapstd::pairconst TargetData*,const StructType*,
 StructLayout *Layouts = 0;
 
@@ -165,6 +168,21 @@
   }
 }
 
+/// InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout
+/// objects.  If a TargetData object is alive when types are being refined and
+/// removed, this method must be called whenever a StructType is removed to
+/// avoid a dangling pointer in this cache.
+void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
+  if (!Layouts) return;  // No cache.
+
+  std::mapstd::pairconst TargetData*,const StructType*,
+   StructLayout::iterator I = Layouts-find(std::make_pair(this, Ty));
+  if (I != Layouts-end())
+Layouts-erase(I);
+}
+
+
+
 static inline void getTypeInfo(const Type *Ty, const TargetData *TD,
uint64_t Size, unsigned char Alignment) {
   assert(Ty-isSized()  Cannot getTypeInfo() on a type that is unsized!);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits