Handle arguments passed in through the va_arg area
[oota-llvm.git] / lib / Transforms / TransformInternals.cpp
index 62953f8c6d08a8b52c649b0f3dd1a1db3b5971f1..7aa5564fbee13b6744b39b4248ad85bcddc1ca91 100644 (file)
 #include "llvm/Function.h"
 #include "llvm/iOther.h"
 
-// TargetData Hack: Eventually we will have annotations given to us by the
-// backend so that we know stuff about type size and alignments.  For now
-// though, just use this, because it happens to match the model that GCC uses.
-//
-const TargetData TD("LevelRaise: Should be GCC though!");
-
-
 static const Type *getStructOffsetStep(const StructType *STy, uint64_t &Offset,
-                                       std::vector<Value*> &Indices) {
+                                       std::vector<Value*> &Indices,
+                                       const TargetData &TD) {
   assert(Offset < TD.getTypeSize(STy) && "Offset not in composite!");
   const StructLayout *SL = TD.getStructLayout(STy);
 
@@ -52,7 +46,7 @@ static const Type *getStructOffsetStep(const StructType *STy, uint64_t &Offset,
 //
 const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
                                 std::vector<Value*> &Indices,
-                                bool StopEarly) {
+                                const TargetData &TD, bool StopEarly) {
   if (Offset == 0 && StopEarly && !Indices.empty())
     return Ty;    // Return the leaf type
 
@@ -60,9 +54,10 @@ const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
   const Type *NextType;
   if (const StructType *STy = dyn_cast<StructType>(Ty)) {
     ThisOffset = Offset;
-    NextType = getStructOffsetStep(STy, ThisOffset, Indices);
+    NextType = getStructOffsetStep(STy, ThisOffset, Indices, TD);
   } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
-    assert(Offset < TD.getTypeSize(ATy) && "Offset not in composite!");
+    assert(Offset == 0 || Offset < TD.getTypeSize(ATy) &&
+           "Offset not in composite!");
 
     NextType = ATy->getElementType();
     unsigned ChildSize = TD.getTypeSize(NextType);
@@ -75,18 +70,19 @@ const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
 
   unsigned SubOffs = Offset - ThisOffset;
   const Type *LeafTy = getStructOffsetType(NextType, SubOffs,
-                                           Indices, StopEarly);
+                                           Indices, TD, StopEarly);
   Offset = ThisOffset + SubOffs;
   return LeafTy;
 }
 
-// ConvertableToGEP - This function returns true if the specified value V is
+// ConvertibleToGEP - This function returns true if the specified value V is
 // a valid index into a pointer of type Ty.  If it is valid, Idx is filled in
 // with the values that would be appropriate to make this a getelementptr
 // instruction.  The type returned is the root type that the GEP would point to
 //
-const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal,
+const Type *ConvertibleToGEP(const Type *Ty, Value *OffsetVal,
                              std::vector<Value*> &Indices,
+                             const TargetData &TD,
                              BasicBlock::iterator *BI) {
   const CompositeType *CompTy = dyn_cast<CompositeType>(Ty);
   if (CompTy == 0) return 0;
@@ -116,7 +112,7 @@ const Type *ConvertableToGEP(const Type *Ty, Value *OffsetVal,
     if (const StructType *StructTy = dyn_cast<StructType>(CompTy)) {
       // Step into the appropriate element of the structure...
       uint64_t ActualOffset = (Offset < 0) ? 0 : (uint64_t)Offset;
-      NextTy = getStructOffsetStep(StructTy, ActualOffset, Indices);
+      NextTy = getStructOffsetStep(StructTy, ActualOffset, Indices, TD);
       Offset -= ActualOffset;
     } else {
       const Type *ElTy = cast<SequentialType>(CompTy)->getElementType();