Files
swift-mirror/lib/SILAnalysis/ClassHierarchyAnalysis.cpp
Nadav Rotem 1b980052b1 Cache the class hierarchy construction.
Before this commit we scanned the vtables every time we wanted to know who are the subclasses of a class. Now we scan the vtables just once.



Swift SVN r20847
2014-07-31 21:07:11 +00:00

40 lines
1.4 KiB
C++

//===- ClassHierarchyAnalysis.cpp - Analysis of class hierarchy -*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/SILAnalysis/ClassHierarchyAnalysis.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Module.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILValue.h"
#include "swift/SIL/SILModule.h"
using namespace swift;
void ClassHierarchyAnalysis::init() {
// For each class declaration in our V-table list:
for (auto &VT : M->getVTableList()) {
ClassDecl *C = VT.getClass();
// Ignore classes that are at the top of the class hierarchy:
if (!C->hasSuperclass())
continue;
// Add the superclass to the list of inherited classes.
ClassDecl *Super = C->getSuperclass()->getClassOrBoundGenericClass();
auto &K = SubclassesCache[Super];
assert(std::find(K.begin(), K.end(), C) == K.end() &&
"Class vector must be unique");
K.push_back(C);
}
}
ClassHierarchyAnalysis::~ClassHierarchyAnalysis() {}