[llvm-commits] [llvm-gcc-4.2] r97676 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-internal.h llvm-types.cpp tree.c tree.h
Stuart Hastings
stuart at apple.com
Wed Mar 3 15:20:17 PST 2010
Author: stuart
Date: Wed Mar 3 17:20:17 2010
New Revision: 97676
URL: http://llvm.org/viewvc/llvm-project?rev=97676&view=rev
Log:
Preserve TypeRefinementDatabase::TypeUsers in the PCH. Radar 7657755.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
llvm-gcc-4.2/trunk/gcc/llvm-internal.h
llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
llvm-gcc-4.2/trunk/gcc/tree.c
llvm-gcc-4.2/trunk/gcc/tree.h
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=97676&r1=97675&r2=97676&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Mar 3 17:20:17 2010
@@ -855,6 +855,7 @@
if (flag_pch_file) {
writeLLVMTypesStringTable();
writeLLVMValues();
+ writeLLVMTypeUsers();
}
// Add an llvm.global_ctors global if needed.
@@ -986,6 +987,11 @@
TREE_ASM_WRITTEN(fndecl) = 1;
return; // Do not process broken code.
}
+
+ // Random initialization of TypeRefinementDatabase if we're using a
+ // PCH. Won't work until the GCC PCH has been read in and digested.
+ readLLVMTypeUsers();
+
timevar_push(TV_LLVM_FUNCS);
// Convert the AST to raw/ugly LLVM code.
Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=97676&r1=97675&r2=97676&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Wed Mar 3 17:20:17 2010
@@ -102,6 +102,8 @@
void writeLLVMTypesStringTable();
void readLLVMValues();
void writeLLVMValues();
+void readLLVMTypeUsers();
+void writeLLVMTypeUsers();
void eraseLocalLLVMValues();
void clearTargetBuiltinCache();
const char* extractRegisterName(union tree_node*);
Modified: llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=97676&r1=97675&r2=97676&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Wed Mar 3 17:20:17 2010
@@ -387,10 +387,10 @@
const Type *NewTy);
virtual void typeBecameConcrete(const DerivedType *AbsTy);
+ public:
// TypeUsers - For each abstract LLVM type, we keep track of all of the GCC
// types that point to it.
std::map<const Type*, std::vector<tree> > TypeUsers;
- public:
/// setType - call SET_TYPE_LLVM(type, Ty), associating the type with the
/// specified tree type. In addition, if the LLVM type is an abstract type,
/// we add it to our data structure to track it.
@@ -406,6 +406,8 @@
return SET_TYPE_LLVM(type, Ty);
}
+ void friend readLLVMTypeUsers();
+ void friend writeLLVMTypeUsers();
void RemoveTypeFromTable(tree type);
void dump() const;
};
@@ -494,6 +496,31 @@
outs().flush();
}
+// We've just read in a PCH; retrieve the set of GCC types that were
+// known to TypeUsers[], and re-populate it. Intended to be called
+// once, but harmless if called multiple times, or if no PCH is
+// present.
+void readLLVMTypeUsers() {
+ tree ty;
+ while ((ty = llvm_pop_TypeUsers())) {
+ const Type *NewTy = GET_TYPE_LLVM(ty);
+ std::vector<tree> &NewSlot = TypeDB.TypeUsers[NewTy];
+ if (NewSlot.empty()) NewTy->addAbstractTypeUser(&TypeDB);
+ NewSlot.push_back(ty);
+ }
+}
+
+// Record the set of GCC types currently known to TypeUsers[] inside
+// GCC so they will be preserved in a PCH. Intended to be called
+// once, just before the PCH is written.
+void writeLLVMTypeUsers() {
+ std::map<const Type*, std::vector<tree> >::iterator
+ I = TypeDB.TypeUsers.begin(),
+ E = TypeDB.TypeUsers.end();
+ for (; I != E; I++)
+ for (unsigned i = 0, e = I->second.size(); i != e; ++i)
+ llvm_push_TypeUsers(I->second[i]);
+}
//===----------------------------------------------------------------------===//
// Helper Routines
//===----------------------------------------------------------------------===//
Modified: llvm-gcc-4.2/trunk/gcc/tree.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree.c?rev=97676&r1=97675&r2=97676&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree.c (original)
+++ llvm-gcc-4.2/trunk/gcc/tree.c Wed Mar 3 17:20:17 2010
@@ -7961,6 +7961,28 @@
{
VEC_safe_push(tree, gc, llvm_types_used, type);
}
+
+static GTY(()) VEC(tree,gc) *llvm_TypeUsers;
+
+/* We're about to write a PCH; record the set of GCC types known to
+ the llvm-types.ccp:TypeRefinementDatabase::TypeUsers[] mapping. */
+void
+llvm_push_TypeUsers(tree type)
+{
+ VEC_safe_push(tree, gc, llvm_TypeUsers, type);
+}
+
+/* We just read in a PCH. Retrieve the set of types recorded here,
+ used to repopulate the
+ llvm-types.ccp:TypeRefinementDatabase::TypeUsers[] mapping. */
+tree
+llvm_pop_TypeUsers(void)
+{
+ if (VEC_empty (tree, llvm_TypeUsers))
+ return NULL_TREE;
+ else
+ return VEC_pop(tree, llvm_TypeUsers);
+}
/* LLVM LOCAL end */
/* APPLE LOCAL begin weak_import on property 6676828 */
Modified: llvm-gcc-4.2/trunk/gcc/tree.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree.h?rev=97676&r1=97675&r2=97676&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree.h (original)
+++ llvm-gcc-4.2/trunk/gcc/tree.h Wed Mar 3 17:20:17 2010
@@ -4433,6 +4433,8 @@
/* LLVM LOCAL begin */
#ifdef ENABLE_LLVM
extern void llvm_note_type_used(tree);
+extern void llvm_push_TypeUsers(tree);
+extern tree llvm_pop_TypeUsers(void);
#endif
/* LLVM LOCAL begin */
More information about the llvm-commits
mailing list