aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Target/TargetData.h9
-rw-r--r--lib/Analysis/ConstantFolding.cpp2
-rw-r--r--lib/CodeGen/AsmPrinter.cpp4
-rw-r--r--lib/CodeGen/MachOWriter.cpp3
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp4
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp2
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp2
-rw-r--r--lib/Target/TargetData.cpp3
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp2
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp3
10 files changed, 20 insertions, 14 deletions
diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h
index d577de7c8a..516aae700d 100644
--- a/include/llvm/Target/TargetData.h
+++ b/include/llvm/Target/TargetData.h
@@ -275,16 +275,21 @@ public:
/// 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 25a64ab9a6..1515301a77 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -70,7 +70,7 @@ static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
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 0394a02aa1..6dac1ea375 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -739,8 +739,8 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
// 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 3beb11a25f..384dd3ee54 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -878,7 +878,8 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
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 ae7a495bf4..16d25ee225 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -1678,7 +1678,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
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 @@ static bool OptimizeGEPExpression(GetElementPtrInst *GEPI,
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 0fd6d461e1..6878f89fff 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -716,7 +716,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
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 fe80dfddd6..936d64f444 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1082,7 +1082,7 @@ GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I,
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 41288ec671..1ebe5b5711 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -466,8 +466,7 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices,
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 d841642de0..e97921237f 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -267,7 +267,7 @@ SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) {
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 6b99bc899b..016a421945 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -801,7 +801,8 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) {
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;