Fix GetConstantStringInfo to not look into MDString (it works on
[oota-llvm.git] / lib / Target / TargetData.cpp
index e482e201f276da2b0282dd0a1350843ecfe025d1..9434a1901ffde3be18730c0016682bcb9b5ccb91 100644 (file)
@@ -315,11 +315,10 @@ unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType,
                  : Alignments[BestMatchIdx].PrefAlign;
 }
 
-typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
-
 namespace {
 
 class StructLayoutMap : public AbstractTypeUser {
+  typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
   LayoutInfoTy LayoutInfo;
 
   /// refineAbstractType - The callback method invoked when an abstract type is
@@ -328,9 +327,7 @@ class StructLayoutMap : public AbstractTypeUser {
   ///
   virtual void refineAbstractType(const DerivedType *OldTy,
                                   const Type *) {
-    const StructType *STy = dyn_cast<const StructType>(OldTy);
-    assert(STy && "This can only track struct types.");
-
+    const StructType *STy = cast<const StructType>(OldTy);
     LayoutInfoTy::iterator Iter = LayoutInfo.find(STy);
     Iter->second->~StructLayout();
     free(Iter->second);
@@ -344,9 +341,7 @@ class StructLayoutMap : public AbstractTypeUser {
   /// This method notifies ATU's when this occurs for a type.
   ///
   virtual void typeBecameConcrete(const DerivedType *AbsTy) {
-    const StructType *STy = dyn_cast<const StructType>(AbsTy);
-    assert(STy && "This can only track struct types.");
-
+    const StructType *STy = cast<const StructType>(AbsTy);
     LayoutInfoTy::iterator Iter = LayoutInfo.find(STy);
     Iter->second->~StructLayout();
     free(Iter->second);
@@ -362,26 +357,24 @@ public:
       const Type *Key = I->first;
       StructLayout *Value = I->second;
 
-      if (Key && Key->isAbstract())
+      if (Key->isAbstract())
         Key->removeAbstractTypeUser(this);
 
-      if (Value) {
-        Value->~StructLayout();
-        free(Value);
-      }
+      Value->~StructLayout();
+      free(Value);
     }
   }
 
-  LayoutInfoTy::iterator end() {
-    return LayoutInfo.end();
-  }
+  void InvalidateEntry(const StructType *Ty) {
+    LayoutInfoTy::iterator I = LayoutInfo.find(Ty);
+    if (I == LayoutInfo.end()) return;
 
-  LayoutInfoTy::iterator find(const StructType *&Val) {
-    return LayoutInfo.find(Val);
-  }
+    I->second->~StructLayout();
+    free(I->second);
+    LayoutInfo.erase(I);
 
-  bool erase(LayoutInfoTy::iterator I) {
-    return LayoutInfo.erase(I);
+    if (Ty->isAbstract())
+      Ty->removeAbstractTypeUser(this);
   }
 
   StructLayout *&operator[](const StructType *STy) {
@@ -392,7 +385,7 @@ public:
   virtual void dump() const {}
 };
 
-} // end namespace llvm
+} // end anonymous namespace
 
 TargetData::~TargetData() {
   delete static_cast<StructLayoutMap*>(LayoutMap);
@@ -432,15 +425,7 @@ void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
   if (!LayoutMap) return;  // No cache.
   
   StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
-  LayoutInfoTy::iterator I = STM->find(Ty);
-  if (I == STM->end()) return;
-  
-  I->second->~StructLayout();
-  free(I->second);
-  STM->erase(I);
-
-  if (Ty->isAbstract())
-    Ty->removeAbstractTypeUser(STM);
+  STM->InvalidateEntry(Ty);
 }
 
 std::string TargetData::getStringRepresentation() const {