#include "llvm/Support/MathExtras.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/System/Mutex.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
#include <algorithm>
// TargetData Class Implementation
//===----------------------------------------------------------------------===//
-typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
-
/*!
A TargetDescription string consists of a sequence of hyphen-delimited
specifiers for target endianness, pointer size and alignments, and various
alignment will be used.
*/
void TargetData::init(const std::string &TargetDescription) {
- LayoutMap = static_cast<void*>(new LayoutInfoTy());
std::string temp = TargetDescription;
+ LayoutMap = 0;
LittleEndian = false;
PointerMemSize = 8;
PointerABIAlign = 8;
}
}
-TargetData::TargetData(const std::string &TargetDescription)
- : ImmutablePass(&ID) {
- init(TargetDescription);
-}
-
TargetData::TargetData(const Module *M)
: ImmutablePass(&ID) {
init(M->getDataLayout());
}
-TargetData::TargetData(const TargetData &TD) :
- ImmutablePass(&ID),
- LittleEndian(TD.isLittleEndian()),
- PointerMemSize(TD.PointerMemSize),
- PointerABIAlign(TD.PointerABIAlign),
- PointerPrefAlign(TD.PointerPrefAlign),
- Alignments(TD.Alignments) {
- LayoutInfoTy *Other = static_cast<LayoutInfoTy*>(TD.LayoutMap);
- LayoutMap = static_cast<void*>(new LayoutInfoTy(*Other));
-}
-
-
void
TargetData::setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
unsigned char pref_align, uint32_t bit_width) {
: Alignments[BestMatchIdx].PrefAlign;
}
-TargetData::~TargetData() {
- assert(LayoutMap && "LayoutMap not initialized?");
- LayoutInfoTy &TheMap = *static_cast<LayoutInfoTy*>(LayoutMap);
+typedef DenseMap<const StructType*, StructLayout*>LayoutInfoTy;
+TargetData::~TargetData() {
+ if (!LayoutMap)
+ return;
+
// Remove any layouts for this TD.
+ LayoutInfoTy &TheMap = *static_cast<LayoutInfoTy*>(LayoutMap);
for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end(); I != E; ) {
I->second->~StructLayout();
free(I->second);
}
delete static_cast<LayoutInfoTy*>(LayoutMap);
- LayoutMap = 0;
}
const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
- assert(LayoutMap && "LayoutMap not initialized?");
+ if (!LayoutMap)
+ LayoutMap = static_cast<void*>(new LayoutInfoTy());
+
LayoutInfoTy &TheMap = *static_cast<LayoutInfoTy*>(LayoutMap);
StructLayout *&SL = TheMap[Ty];
/// removed, this method must be called whenever a StructType is removed to
/// avoid a dangling pointer in this cache.
void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
- assert(LayoutMap && "LayoutMap not initialized?");
- LayoutInfoTy *LayoutInfo = static_cast<LayoutInfoTy*>(LayoutMap);
+ if (!LayoutMap) return; // No cache.
+
+ LayoutInfoTy* LayoutInfo = static_cast<LayoutInfoTy*>(LayoutMap);
LayoutInfoTy::iterator I = LayoutInfo->find(Ty);
if (I == LayoutInfo->end()) return;