-// This method returns true if the type is found to still be abstract.
-//
-bool Type::PromoteAbstractToConcrete(void *Ptr) {
- if (!isAbstract()) // Base case for the recursion
- return false; // Primitive = leaf type
-
- if (isa<OpaqueType>(this)) // Base case for the recursion
- return true; // This whole type is abstract!
-
- /// KnownAbstractTypes - This set contains all of the types that we know for
- /// sure are abstract. Once we discover that a type really is abstract, we
- /// remember this so we don't have to do potentially exponential amounts of
- /// checking in some cases.
- std::set<Type*> &KnownAbstractTypes = *(std::set<Type*>*)Ptr;
- if (KnownAbstractTypes.count(this))
- return true; // We already know this type is abstract!
-
- // We have to guard against recursion. To do this, we temporarily mark this
- // type as concrete, so that if we get back to here recursively we will think
- // it's not abstract, and thus not scan it again.
- setAbstract(false);
-
- // Scan all of the sub-types. If any of them are abstract, than so is this
- // one!
- for (Type::subtype_iterator I = subtype_begin(), E = subtype_end();
- I != E; ++I)
- if (const_cast<Type*>(I->get())->PromoteAbstractToConcrete(Ptr)) {
- KnownAbstractTypes.insert(this);
- setAbstract(true); // Restore the abstract bit.
- return true; // This type is abstract if subtype is abstract!
+void Type::PromoteAbstractToConcrete() {
+ if (!isAbstract()) return;
+
+ scc_iterator<TypePromotionGraph> SI = scc_begin(TypePromotionGraph(this));
+ scc_iterator<TypePromotionGraph> SE = scc_end (TypePromotionGraph(this));
+
+ for (; SI != SE; ++SI) {
+ std::vector<Type*> &SCC = *SI;
+
+ // Concrete types are leaves in the tree. Since an SCC will either be all
+ // abstract or all concrete, we only need to check one type.
+ if (SCC[0]->isAbstract()) {
+ if (isa<OpaqueType>(SCC[0]))
+ return; // Not going to be concrete, sorry.
+
+ // If all of the children of all of the types in this SCC are concrete,
+ // then this SCC is now concrete as well. If not, neither this SCC, nor
+ // any parent SCCs will be concrete, so we might as well just exit.
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i)
+ for (Type::subtype_iterator CI = SCC[i]->subtype_begin(),
+ E = SCC[i]->subtype_end(); CI != E; ++CI)
+ if ((*CI)->isAbstract())
+ // If the child type is in our SCC, it doesn't make the entire SCC
+ // abstract unless there is a non-SCC abstract type.
+ if (std::find(SCC.begin(), SCC.end(), *CI) == SCC.end())
+ return; // Not going to be concrete, sorry.
+
+ // Okay, we just discovered this whole SCC is now concrete, mark it as
+ // such!
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
+ assert(SCC[i]->isAbstract() && "Why are we processing concrete types?");
+
+ SCC[i]->setAbstract(false);
+ }
+
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
+ assert(!SCC[i]->isAbstract() && "Concrete type became abstract?");
+ // The type just became concrete, notify all users!
+ cast<DerivedType>(SCC[i])->notifyUsesThatTypeBecameConcrete();
+ }