llvm.org GIT mirror llvm / 607abd2
--- Reverse-merging r79555 into '.': U include/llvm/Target/TargetData.h U lib/Target/TargetData.cpp Temporarily revert 79555. It was causing hangs and test failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79568 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 10 years ago
2 changed file(s) with 67 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
9090 */
9191 static const TargetAlignElem InvalidAlignmentElem;
9292
93 /// Opaque pointer for the StructType -> StructLayout map
94 void* LayoutMap;
95
9693 //! Set/initialize target alignments
9794 void setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
9895 unsigned char pref_align, uint32_t bit_width);
109106 return (&align != &InvalidAlignmentElem);
110107 }
111108
112 // DO NOT IMPLEMENT
113 void operator=(const TargetData&);
114
115109 public:
116110 /// Default ctor.
117111 ///
123117 }
124118
125119 /// Constructs a TargetData from a specification string. See init().
126 explicit TargetData(const std::string &TargetDescription);
120 explicit TargetData(const std::string &TargetDescription)
121 : ImmutablePass(&ID) {
122 init(TargetDescription);
123 }
127124
128125 /// Initialize target data from properties stored in the module.
129126 explicit TargetData(const Module *M);
130 TargetData(const TargetData &TD);
127
128 TargetData(const TargetData &TD) :
129 ImmutablePass(&ID),
130 LittleEndian(TD.isLittleEndian()),
131 PointerMemSize(TD.PointerMemSize),
132 PointerABIAlign(TD.PointerABIAlign),
133 PointerPrefAlign(TD.PointerPrefAlign),
134 Alignments(TD.Alignments)
135 { }
131136
132137 ~TargetData(); // Not virtual, do not subclass this class
133138
2323 #include "llvm/Support/MathExtras.h"
2424 #include "llvm/Support/ManagedStatic.h"
2525 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/System/Mutex.h"
2627 #include "llvm/ADT/DenseMap.h"
2728 #include "llvm/ADT/StringExtras.h"
2829 #include
129130 //===----------------------------------------------------------------------===//
130131 // TargetData Class Implementation
131132 //===----------------------------------------------------------------------===//
132
133 typedef DenseMap LayoutInfoTy;
134133
135134 /*!
136135 A TargetDescription string consists of a sequence of hyphen-delimited
170169 alignment will be used.
171170 */
172171 void TargetData::init(const std::string &TargetDescription) {
173 LayoutMap = static_cast(new LayoutInfoTy());
174172 std::string temp = TargetDescription;
175173
176174 LittleEndian = false;
235233 }
236234 }
237235
238 TargetData::TargetData(const std::string &TargetDescription)
239 : ImmutablePass(&ID) {
240 init(TargetDescription);
241 }
242
243236 TargetData::TargetData(const Module *M)
244237 : ImmutablePass(&ID) {
245238 init(M->getDataLayout());
246239 }
247
248 TargetData::TargetData(const TargetData &TD) :
249 ImmutablePass(&ID),
250 LittleEndian(TD.isLittleEndian()),
251 PointerMemSize(TD.PointerMemSize),
252 PointerABIAlign(TD.PointerABIAlign),
253 PointerPrefAlign(TD.PointerPrefAlign),
254 Alignments(TD.Alignments) {
255 LayoutInfoTy *Other = static_cast(TD.LayoutMap);
256 LayoutMap = static_cast(new LayoutInfoTy(*Other));
257 }
258
259240
260241 void
261242 TargetData::setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
335316 : Alignments[BestMatchIdx].PrefAlign;
336317 }
337318
319 namespace {
320
321 /// LayoutInfo - The lazy cache of structure layout information maintained by
322 /// TargetData. Note that the struct types must have been free'd before
323 /// llvm_shutdown is called (and thus this is deallocated) because all the
324 /// targets with cached elements should have been destroyed.
325 ///
326 typedef std::pair LayoutKey;
327
328 struct DenseMapLayoutKeyInfo {
329 static inline LayoutKey getEmptyKey() { return LayoutKey(0, 0); }
330 static inline LayoutKey getTombstoneKey() {
331 return LayoutKey((TargetData*)(intptr_t)-1, 0);
332 }
333 static unsigned getHashValue(const LayoutKey &Val) {
334 return DenseMapInfo::getHashValue(Val.first) ^
335 DenseMapInfo::getHashValue(Val.second);
336 }
337 static bool isEqual(const LayoutKey &LHS, const LayoutKey &RHS) {
338 return LHS == RHS;
339 }
340
341 static bool isPod() { return true; }
342 };
343
344 typedef DenseMap LayoutInfoTy;
345
346 }
347
348 static ManagedStatic LayoutInfo;
349 static ManagedStatic > LayoutLock;
350
338351 TargetData::~TargetData() {
339 assert(LayoutMap && "LayoutMap not initialized?");
340 LayoutInfoTy &TheMap = *static_cast(LayoutMap);
341
352 if (!LayoutInfo.isConstructed())
353 return;
354
355 sys::SmartScopedLock Lock(*LayoutLock);
342356 // Remove any layouts for this TD.
357 LayoutInfoTy &TheMap = *LayoutInfo;
343358 for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end(); I != E; ) {
344 I->second->~StructLayout();
345 free(I->second);
346 TheMap.erase(I++);
347 }
348
349 delete static_cast(LayoutMap);
350 LayoutMap = 0;
359 if (I->first.first == this) {
360 I->second->~StructLayout();
361 free(I->second);
362 TheMap.erase(I++);
363 } else {
364 ++I;
365 }
366 }
351367 }
352368
353369 const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
354 assert(LayoutMap && "LayoutMap not initialized?");
355 LayoutInfoTy &TheMap = *static_cast(LayoutMap);
356
357 StructLayout *&SL = TheMap[Ty];
370 LayoutInfoTy &TheMap = *LayoutInfo;
371
372 sys::SmartScopedLock Lock(*LayoutLock);
373 StructLayout *&SL = TheMap[LayoutKey(this, Ty)];
358374 if (SL) return SL;
359375
360376 // Otherwise, create the struct layout. Because it is variable length, we
376392 /// removed, this method must be called whenever a StructType is removed to
377393 /// avoid a dangling pointer in this cache.
378394 void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
379 assert(LayoutMap && "LayoutMap not initialized?");
380 LayoutInfoTy *LayoutInfo = static_cast(LayoutMap);
381 LayoutInfoTy::iterator I = LayoutInfo->find(Ty);
395 if (!LayoutInfo.isConstructed()) return; // No cache.
396
397 sys::SmartScopedLock Lock(*LayoutLock);
398 LayoutInfoTy::iterator I = LayoutInfo->find(LayoutKey(this, Ty));
382399 if (I == LayoutInfo->end()) return;
383400
384401 I->second->~StructLayout();