Privatize StructLayout::MemberOffsets, adding an accessor


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34156 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h
index d577de7..516aae7 100644
--- a/include/llvm/Target/TargetData.h
+++ b/include/llvm/Target/TargetData.h
@@ -275,16 +275,21 @@
 /// target machine, based on the TargetData structure.
 ///
 class StructLayout {
-public:
   std::vector<uint64_t> MemberOffsets;
-  uint64_t StructSize;
+public:
   unsigned StructAlignment;
+  uint64_t StructSize;
 
   /// getElementContainingOffset - Given a valid offset into the structure,
   /// return the structure index that contains it.
   ///
   unsigned getElementContainingOffset(uint64_t Offset) const;
 
+  uint64_t getElementOffset(unsigned Idx) const {
+    assert(Idx < MemberOffsets.size() && "Invalid element idx!");
+    return MemberOffsets[Idx];
+  }
+  
 private:
   friend class TargetData;   // Only TargetData can create this class
   StructLayout(const StructType *ST, const TargetData &TD);
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 25a64ab..1515301 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -70,7 +70,7 @@
       
       if (const StructType *ST = dyn_cast<StructType>(*GTI)) {
         // N = N + Offset
-        Offset += TD.getStructLayout(ST)->MemberOffsets[CI->getZExtValue()];
+        Offset += TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue());
       } else {
         const SequentialType *ST = cast<SequentialType>(*GTI);
         Offset += TD.getTypeSize(ST->getElementType())*CI->getSExtValue();
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 0394a02..6dac1ea 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -739,8 +739,8 @@
       // Check if padding is needed and insert one or more 0s.
       uint64_t fieldSize = TD->getTypeSize(field->getType());
       uint64_t padSize = ((i == e-1? cvsLayout->StructSize
-                           : cvsLayout->MemberOffsets[i+1])
-                          - cvsLayout->MemberOffsets[i]) - fieldSize;
+                           : cvsLayout->getElementOffset(i+1))
+                          - cvsLayout->getElementOffset(i)) - fieldSize;
       sizeSoFar += fieldSize + padSize;
 
       // Now print the actual field value
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index 3beb11a..384dd3e 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -878,7 +878,8 @@
       const StructLayout *SL =
         TD->getStructLayout(cast<StructType>(CPS->getType()));
       for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
-        WorkList.push_back(CPair(CPS->getOperand(i), PA+SL->MemberOffsets[i]));
+        WorkList.push_back(CPair(CPS->getOperand(i),
+                                 PA+SL->getElementOffset(i)));
     } else {
       cerr << "Bad Type: " << *PC->getType() << "\n";
       assert(0 && "Unknown constant type to initialize memory with!");
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index ae7a495..16d25ee 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -1678,7 +1678,7 @@
       unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
       if (Field) {
         // N = N + Offset
-        uint64_t Offset = TD->getStructLayout(StTy)->MemberOffsets[Field];
+        uint64_t Offset = TD->getStructLayout(StTy)->getElementOffset(Field);
         N = DAG.getNode(ISD::ADD, N.getValueType(), N,
                         getIntPtrConstant(Offset));
       }
@@ -3702,7 +3702,7 @@
     if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
       unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
       if (Field)
-        ConstantOffset += TD->getStructLayout(StTy)->MemberOffsets[Field];
+        ConstantOffset += TD->getStructLayout(StTy)->getElementOffset(Field);
       Ty = StTy->getElementType(Field);
     } else {
       Ty = cast<SequentialType>(Ty)->getElementType();
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index 0fd6d46..6878f89 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -716,7 +716,7 @@
     const StructLayout *SL =
       getTargetData()->getStructLayout(cast<StructType>(CPS->getType()));
     for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
-      InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->MemberOffsets[i]);
+      InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
     return;
   }
 
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index fe80dfd..936d64f 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1082,7 +1082,7 @@
       const ConstantInt *CPU = cast<ConstantInt>(I.getOperand());
       unsigned Index = unsigned(CPU->getZExtValue());
 
-      Total += (PointerTy)SLO->MemberOffsets[Index];
+      Total += (PointerTy)SLO->getElementOffset(Index);
     } else {
       const SequentialType *ST = cast<SequentialType>(*I);
       // Get the index number for the array... which must be long type...
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index 41288ec..1ebe5b5 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -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);
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index d841642..e979212 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -267,7 +267,7 @@
     if (const StructType *STy = dyn_cast<StructType>(*GTI)) {
       const StructLayout *SL = TD->getStructLayout(STy);
       unsigned Idx = cast<ConstantInt>(GEP->getOperand(i))->getZExtValue();
-      uint64_t Offset = SL->MemberOffsets[Idx];
+      uint64_t Offset = SL->getElementOffset(Idx);
       GEPVal = SCEVAddExpr::get(GEPVal,
                                 SCEVUnknown::getIntegerSCEV(Offset, UIntPtrTy));
     } else {
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 6b99bc8..016a421 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -801,7 +801,8 @@
           else
             NewOffset += AggSizeInBits-ElSizeBits*(Idx+1);
         } else if (const StructType *STy = dyn_cast<StructType>(AggTy)) {
-          unsigned EltBitOffset = TD.getStructLayout(STy)->MemberOffsets[Idx]*8;
+          unsigned EltBitOffset =
+            TD.getStructLayout(STy)->getElementOffset(Idx)*8;
           
           if (TD.isLittleEndian() || isVectorInsert)
             NewOffset += EltBitOffset;