#include "llvm/ADT/StringExtras.h"
#include <algorithm>
#include <cstdlib>
-#include <sstream>
using namespace llvm;
// Handle the Pass registration stuff necessary to use TargetData's.
-namespace {
- // Register the default SparcV9 implementation...
- RegisterPass<TargetData> X("targetdata", "Target Data Layout");
-}
+
+// Register the default SparcV9 implementation...
+static RegisterPass<TargetData> X("targetdata", "Target Data Layout", false,
+ true);
char TargetData::ID = 0;
//===----------------------------------------------------------------------===//
// 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 TyAlign = ST->isPacked() ?
- 1 : TD.getABITypeAlignment(Ty);
- uint64_t TySize = ST->isPacked() ?
- TD.getTypeStoreSize(Ty) : TD.getABITypeSize(Ty);
+ unsigned TyAlign = ST->isPacked() ? 1 : TD.getABITypeAlignment(Ty);
// Add padding if necessary to align the data element properly...
StructSize = (StructSize + TyAlign - 1)/TyAlign * TyAlign;
StructAlignment = std::max(TyAlign, StructAlignment);
MemberOffsets[i] = StructSize;
- StructSize += TySize; // Consume space for this data item
+ StructSize += TD.getABITypeSize(Ty); // Consume space for this data item
}
// Empty structures have alignment of 1 byte.
}
TargetData::TargetData(const Module *M)
- : ImmutablePass((intptr_t)&ID) {
+ : ImmutablePass(&ID) {
init(M->getDataLayout());
}
: Alignments[BestMatchIdx].PrefAlign;
}
+namespace {
+
/// LayoutInfo - The lazy cache of structure layout information maintained by
/// TargetData. Note that the struct types must have been free'd before
/// llvm_shutdown is called (and thus this is deallocated) because all the
};
typedef DenseMap<LayoutKey, StructLayout*, DenseMapLayoutKeyInfo> LayoutInfoTy;
-static ManagedStatic<LayoutInfoTy> LayoutInfo;
+}
+
+static ManagedStatic<LayoutInfoTy> LayoutInfo;
TargetData::~TargetData() {
if (LayoutInfo.isConstructed()) {