aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-12-04 02:01:07 +0000
committerAnders Carlsson <andersca@mac.com>2009-12-04 02:01:07 +0000
commitc7ab1a8dfc3e37b7c2967ff6a97ed684f0ac1015 (patch)
treeb54b1620d1c3526574c1d8a9196b6b9ce0042fb8
parent0a3816e566db7cd6084310a2f5a3167d0ec30b31 (diff)
Add a data structure for efficient storing of vtable methods. Not used yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90515 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGVtable.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index 8cbd6adb08..46a0bab035 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -57,6 +57,63 @@ private:
/// PureVirtualFunction - Points to __cxa_pure_virtual.
llvm::Constant *PureVirtualFn;
+ /// VtableMethods - A data structure for keeping track of methods in a vtable.
+ /// Can add methods, override methods and iterate in vtable order.
+ class VtableMethods {
+ // MethodToIndexMap - Maps from a global decl to the index it has in the
+ // Methods vector.
+ llvm::DenseMap<GlobalDecl, uint64_t> MethodToIndexMap;
+
+ /// Methods - The methods, in vtable order.
+ typedef llvm::SmallVector<GlobalDecl, 16> MethodsVectorTy;
+ MethodsVectorTy Methods;
+
+ public:
+ /// AddMethod - Add a method to the vtable methods.
+ void AddMethod(GlobalDecl GD) {
+ assert(!MethodToIndexMap.count(GD) &&
+ "Method has already been added!");
+
+ MethodToIndexMap[GD] = Methods.size();
+ Methods.push_back(GD);
+ }
+
+ /// OverrideMethod - Replace a method with another.
+ void OverrideMethod(GlobalDecl OverriddenGD, GlobalDecl GD) {
+ llvm::DenseMap<GlobalDecl, uint64_t>::iterator i
+ = MethodToIndexMap.find(OverriddenGD);
+ assert(i != MethodToIndexMap.end() && "Did not find entry!");
+
+ // Get the index of the old decl.
+ uint64_t Index = i->second;
+
+ // Replace the old decl with the new decl.
+ Methods[Index] = GD;
+
+ // Now remove the old decl from the method to index map.
+ MethodToIndexMap.erase(i);
+
+ // And add the new.
+ MethodToIndexMap[GD] = Index;
+ }
+
+ MethodsVectorTy::size_type size() const {
+ return Methods.size();
+ }
+
+ void clear() {
+ MethodToIndexMap.clear();
+ Methods.clear();
+ }
+
+ GlobalDecl operator[](unsigned Index) const {
+ return Methods[Index];
+ }
+ };
+
+ /// Methods - The vtable methods we're currently building.
+ VtableMethods Methods;
+
/// Thunk - Represents a single thunk.
struct Thunk {
Thunk() { }