//===-- TargetData.cpp - Data size & alignment routines --------------------==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file defines target properties related to datatype size/offset/alignment
// information. It uses lazy annotations to cache information about how
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
-// Handle the Pass registration stuff neccesary to use TargetData's.
+// Handle the Pass registration stuff necessary to use TargetData's.
namespace {
// Register the default SparcV9 implementation...
RegisterPass<TargetData> X("targetdata", "Target Data Layout");
getTypeInfo(Ty, &TD, TySize, A);
TyAlign = A;
- // Add padding if neccesary to make the data element aligned properly...
+ // Add padding if necessary to make the data element aligned properly...
if (StructSize % TyAlign != 0)
StructSize = (StructSize/TyAlign + 1) * TyAlign; // Add padding...
StructSize += TySize; // Consume space for this data item
}
+ // Empty structures have alignment of 1 byte.
+ if (StructAlignment == 0) StructAlignment = 1;
+
// Add padding to the end of the struct so that it could be put in an array
// and all array elements would be aligned correctly.
if (StructSize % StructAlignment != 0)
StructSize = (StructSize/StructAlignment + 1) * StructAlignment;
-
- if (StructSize == 0) {
- StructSize = 1; // Empty struct is 1 byte
- StructAlignment = 1;
- }
}
Annotation *TargetData::TypeAnFactory(AnnotationID AID, const Annotable *T,
void *D) {
const TargetData &TD = *(const TargetData*)D;
assert(AID == TD.AID && "Target data annotation ID mismatch!");
- const Type *Ty = cast<const Type>((const Value *)T);
+ const Type *Ty = cast<Type>((const Value *)T);
assert(isa<StructType>(Ty) &&
"Can only create StructLayout annotation on structs!");
- return new StructLayout((const StructType *)Ty, TD);
+ return new StructLayout(cast<StructType>(Ty), TD);
}
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
TargetData::TargetData(const std::string &TargetName,
- bool isLittleEndian, unsigned char SubWordSize,
- unsigned char IntRegSize, unsigned char PtrSize,
+ bool isLittleEndian, unsigned char PtrSize,
unsigned char PtrAl, unsigned char DoubleAl,
unsigned char FloatAl, unsigned char LongAl,
unsigned char IntAl, unsigned char ShortAl,
"ERROR: Tool did not specify a target data to use!");
LittleEndian = isLittleEndian;
- SubWordDataSize = SubWordSize;
- IntegerRegSize = IntRegSize;
PointerSize = PtrSize;
PointerAlignment = PtrAl;
DoubleAlignment = DoubleAl;
: AID(AnnotationManager::getID("TargetData::" + ToolName)) {
AnnotationManager::registerAnnotationFactory(AID, TypeAnFactory, this);
- LittleEndian = M->isLittleEndian();
- SubWordDataSize = 1;
- IntegerRegSize = 8;
- PointerSize = M->has32BitPointers() ? 4 : 8;
+ LittleEndian = M->getEndianness() != Module::BigEndian;
+ PointerSize = M->getPointerSize() != Module::Pointer64 ? 4 : 8;
PointerAlignment = PointerSize;
DoubleAlignment = PointerSize;
FloatAlignment = 4;
Ty = cast<SequentialType>(Ty)->getElementType();
// Get the array index and the size of each array element.
- // Both must be known constants, or the index shd be 0; else this fails.
int64_t arrayIdx = cast<ConstantSInt>(Idx[CurIDX])->getValue();
- Result += arrayIdx == 0? 0
- : (uint64_t) (arrayIdx * (int64_t) getTypeSize(Ty));
-
- } else if (const StructType *STy = dyn_cast<const StructType>(Ty)) {
+ Result += arrayIdx * (int64_t)getTypeSize(Ty);
+ } else {
+ const StructType *STy = cast<StructType>(Ty);
assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
unsigned FieldNo = cast<ConstantUInt>(Idx[CurIDX])->getValue();
// Update Ty to refer to current element
Ty = STy->getElementTypes()[FieldNo];
- } else {
- assert(0 && "Indexing type that is not struct or array?");
- return 0; // Load directly through ptr
}
}