[llvm-commits] [gcc-plugin] r76446 - in /gcc-plugin/trunk: bits_and_bobs.cpp bits_and_bobs.h llvm-types.cpp

Duncan Sands baldrick at free.fr
Mon Jul 20 11:22:44 PDT 2009


Author: baldrick
Date: Mon Jul 20 13:22:43 2009
New Revision: 76446

URL: http://llvm.org/viewvc/llvm-project?rev=76446&view=rev
Log:
Associate llvm types to gcc type trees using the cache.
There's no good way right now to handle switching from
one LLVM type to another, but with this we can at least
make progress on other fronts.

Modified:
    gcc-plugin/trunk/bits_and_bobs.cpp
    gcc-plugin/trunk/bits_and_bobs.h
    gcc-plugin/trunk/llvm-types.cpp

Modified: gcc-plugin/trunk/bits_and_bobs.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/bits_and_bobs.cpp?rev=76446&r1=76445&r2=76446&view=diff

==============================================================================
--- gcc-plugin/trunk/bits_and_bobs.cpp (original)
+++ gcc-plugin/trunk/bits_and_bobs.cpp Mon Jul 20 13:22:43 2009
@@ -38,10 +38,6 @@
 abort();
 }
 
-const Type *llvm_set_type(tree Tr, const Type *Ty) {
-abort();
-}
-
-const Type *llvm_get_type(unsigned Index) {
+void llvmEraseLType(const Type *Ty) {
 abort();
 }

Modified: gcc-plugin/trunk/bits_and_bobs.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/bits_and_bobs.h?rev=76446&r1=76445&r2=76446&view=diff

==============================================================================
--- gcc-plugin/trunk/bits_and_bobs.h (original)
+++ gcc-plugin/trunk/bits_and_bobs.h Mon Jul 20 13:22:43 2009
@@ -26,10 +26,9 @@
 
 #define SET_TYPE_LLVM(NODE, TYPE) (const Type *)llvm_set_type(NODE, TYPE)
 
-extern const Type *llvm_get_type(unsigned Index);
+extern const Type *llvm_get_type(tree Tr);
 
-#define GET_TYPE_LLVM(NODE) \
-  (const Type *)llvm_get_type( 0 )
+#define GET_TYPE_LLVM(NODE) (const Type *)llvm_get_type(NODE)
 
 // emit_global_to_llvm - Emit the specified VAR_DECL to LLVM as a global
 // variable.
@@ -38,4 +37,6 @@
 
 extern bool flag_odr;
 
+void llvmEraseLType(const Type *);
+
 #endif

Modified: gcc-plugin/trunk/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-types.cpp?rev=76446&r1=76445&r2=76446&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-types.cpp (original)
+++ gcc-plugin/trunk/llvm-types.cpp Mon Jul 20 13:22:43 2009
@@ -52,115 +52,130 @@
 
 // Plugin headers
 #include "llvm-abi.h"
+#include "llvm-cache.h"
 #include "bits_and_bobs.h"
 
+static LLVMContext &Context = getGlobalContext();
+
 //===----------------------------------------------------------------------===//
 //                   Matching LLVM types with GCC trees
 //===----------------------------------------------------------------------===//
-//
-// LTypes is a vector of LLVM types. GCC tree nodes keep track of LLVM types 
-// using this vector's index. It is easier to save and restore the index than 
-// the LLVM type pointer while usig PCH. STL vector does not provide fast 
-// searching mechanism which is required to remove LLVM Type entry when type is 
-// refined and replaced by another LLVM Type. This is achieved by maintaining 
-// a map.
-
-// Collection of LLVM Types
-static std::vector<const Type *> LTypes;
-typedef DenseMap<const Type *, unsigned> LTypesMapTy;
-static LTypesMapTy LTypesMap;
-
-static LLVMContext &Context = getGlobalContext();
-
-// Erase type from LTypes vector
-static void llvmEraseLType(const Type *Ty) {
 
-  LTypesMapTy::iterator I = LTypesMap.find(Ty);
+// GET_TYPE_LLVM/SET_TYPE_LLVM - Associate an LLVM type with each TREE type.
+// These are lazily computed by ConvertType.
 
-  if (I != LTypesMap.end()) {
-    // It is OK to clear this entry instead of removing this entry
-    // to avoid re-indexing of other entries.
-    LTypes[ LTypesMap[Ty] - 1] = NULL;
-    LTypesMap.erase(I);
-  }
+const Type *llvm_set_type(tree Tr, const Type *Ty) {
+  assert(TYPE_P(Tr) && "Expected a gcc type!");
+  return (const Type *)llvm_set_cached(Tr, Ty);
 }
 
-// Read LLVM Types string table
-void readLLVMTypesStringTable() {
-
-  GlobalValue *V = TheModule->getNamedGlobal("llvm.pch.types");
-  if (!V)
-    return;
-
-  //  Value *GV = TheModule->getValueSymbolTable().lookup("llvm.pch.types");
-  GlobalVariable *GV = cast<GlobalVariable>(V);
-  ConstantStruct *LTypesNames = cast<ConstantStruct>(GV->getOperand(0));
-
-  for (unsigned i = 0; i < LTypesNames->getNumOperands(); ++i) {
-    const Type *Ty = NULL;
-
-    if (ConstantArray *CA = 
-        dyn_cast<ConstantArray>(LTypesNames->getOperand(i))) {
-      std::string Str = CA->getAsString();
-      Ty = TheModule->getTypeByName(Str);
-      assert (Ty != NULL && "Invalid Type in LTypes string table");
-    } 
-    // If V is not a string then it is empty. Insert NULL to represent 
-    // empty entries.
-    LTypes.push_back(Ty);
-  }
-
-  // Now, llvm.pch.types value is not required so remove it from the symbol
-  // table.
-  GV->eraseFromParent();
+const Type *llvm_get_type(tree Tr) {
+  assert(TYPE_P(Tr) && "Expected a gcc type!");
+  return (const Type *)llvm_get_cached(Tr);
 }
 
-
-// GCC tree's uses LTypes vector's index to reach LLVM types.
-// Create a string table to hold these LLVM types' names. This string
-// table will be used to recreate LTypes vector after loading PCH.
-void writeLLVMTypesStringTable() {
-  
-  if (LTypes.empty()) 
-    return;
-
-  std::vector<Constant *> LTypesNames;
-  std::map < const Type *, std::string > TypeNameMap;
-
-  // Collect Type Names in advance.
-  const TypeSymbolTable &ST = TheModule->getTypeSymbolTable();
-  TypeSymbolTable::const_iterator TI = ST.begin();
-  for (; TI != ST.end(); ++TI) {
-    TypeNameMap[TI->second] = TI->first;
-  }
-
-  // Populate LTypesNames vector.
-  for (std::vector<const Type *>::iterator I = LTypes.begin(),
-         E = LTypes.end(); I != E; ++I)  {
-    const Type *Ty = *I;
-
-    // Give names to nameless types.
-    if (Ty && TypeNameMap[Ty].empty()) {
-      std::string NewName =
-        TheModule->getTypeSymbolTable().getUniqueName("llvm.fe.ty");
-      TheModule->addTypeName(NewName, Ty);
-      TypeNameMap[*I] = NewName;
-    }
-
-    const std::string &TypeName = TypeNameMap[*I];
-    LTypesNames.push_back(Context.getConstantArray(TypeName, false));
-  }
-
-  // Create string table.
-  Constant *LTypesNameTable = Context.getConstantStruct(LTypesNames, false);
-
-  // Create variable to hold this string table.
-  GlobalVariable *GV = new GlobalVariable(*TheModule,   
-                                          LTypesNameTable->getType(), true,
-                                          GlobalValue::ExternalLinkage, 
-                                          LTypesNameTable,
-                                          "llvm.pch.types");
-}
+//
+//TODO// LTypes is a vector of LLVM types. GCC tree nodes keep track of LLVM types 
+//TODO// using this vector's index. It is easier to save and restore the index than 
+//TODO// the LLVM type pointer while usig PCH. STL vector does not provide fast 
+//TODO// searching mechanism which is required to remove LLVM Type entry when type is 
+//TODO// refined and replaced by another LLVM Type. This is achieved by maintaining 
+//TODO// a map.
+//TODO
+//TODO// Collection of LLVM Types
+//TODOstatic std::vector<const Type *> LTypes;
+//TODOtypedef DenseMap<const Type *, unsigned> LTypesMapTy;
+//TODOstatic LTypesMapTy LTypesMap;
+//TODO
+//TODO// Erase type from LTypes vector
+//TODOstatic void llvmEraseLType(const Type *Ty) {
+//TODO
+//TODO  LTypesMapTy::iterator I = LTypesMap.find(Ty);
+//TODO
+//TODO  if (I != LTypesMap.end()) {
+//TODO    // It is OK to clear this entry instead of removing this entry
+//TODO    // to avoid re-indexing of other entries.
+//TODO    LTypes[ LTypesMap[Ty] - 1] = NULL;
+//TODO    LTypesMap.erase(I);
+//TODO  }
+//TODO}
+//TODO
+//TODO// Read LLVM Types string table
+//TODOvoid readLLVMTypesStringTable() {
+//TODO
+//TODO  GlobalValue *V = TheModule->getNamedGlobal("llvm.pch.types");
+//TODO  if (!V)
+//TODO    return;
+//TODO
+//TODO  //  Value *GV = TheModule->getValueSymbolTable().lookup("llvm.pch.types");
+//TODO  GlobalVariable *GV = cast<GlobalVariable>(V);
+//TODO  ConstantStruct *LTypesNames = cast<ConstantStruct>(GV->getOperand(0));
+//TODO
+//TODO  for (unsigned i = 0; i < LTypesNames->getNumOperands(); ++i) {
+//TODO    const Type *Ty = NULL;
+//TODO
+//TODO    if (ConstantArray *CA = 
+//TODO        dyn_cast<ConstantArray>(LTypesNames->getOperand(i))) {
+//TODO      std::string Str = CA->getAsString();
+//TODO      Ty = TheModule->getTypeByName(Str);
+//TODO      assert (Ty != NULL && "Invalid Type in LTypes string table");
+//TODO    } 
+//TODO    // If V is not a string then it is empty. Insert NULL to represent 
+//TODO    // empty entries.
+//TODO    LTypes.push_back(Ty);
+//TODO  }
+//TODO
+//TODO  // Now, llvm.pch.types value is not required so remove it from the symbol
+//TODO  // table.
+//TODO  GV->eraseFromParent();
+//TODO}
+//TODO
+//TODO
+//TODO// GCC tree's uses LTypes vector's index to reach LLVM types.
+//TODO// Create a string table to hold these LLVM types' names. This string
+//TODO// table will be used to recreate LTypes vector after loading PCH.
+//TODOvoid writeLLVMTypesStringTable() {
+//TODO  
+//TODO  if (LTypes.empty()) 
+//TODO    return;
+//TODO
+//TODO  std::vector<Constant *> LTypesNames;
+//TODO  std::map < const Type *, std::string > TypeNameMap;
+//TODO
+//TODO  // Collect Type Names in advance.
+//TODO  const TypeSymbolTable &ST = TheModule->getTypeSymbolTable();
+//TODO  TypeSymbolTable::const_iterator TI = ST.begin();
+//TODO  for (; TI != ST.end(); ++TI) {
+//TODO    TypeNameMap[TI->second] = TI->first;
+//TODO  }
+//TODO
+//TODO  // Populate LTypesNames vector.
+//TODO  for (std::vector<const Type *>::iterator I = LTypes.begin(),
+//TODO         E = LTypes.end(); I != E; ++I)  {
+//TODO    const Type *Ty = *I;
+//TODO
+//TODO    // Give names to nameless types.
+//TODO    if (Ty && TypeNameMap[Ty].empty()) {
+//TODO      std::string NewName =
+//TODO        TheModule->getTypeSymbolTable().getUniqueName("llvm.fe.ty");
+//TODO      TheModule->addTypeName(NewName, Ty);
+//TODO      TypeNameMap[*I] = NewName;
+//TODO    }
+//TODO
+//TODO    const std::string &TypeName = TypeNameMap[*I];
+//TODO    LTypesNames.push_back(Context.getConstantArray(TypeName, false));
+//TODO  }
+//TODO
+//TODO  // Create string table.
+//TODO  Constant *LTypesNameTable = Context.getConstantStruct(LTypesNames, false);
+//TODO
+//TODO  // Create variable to hold this string table.
+//TODO  GlobalVariable *GV = new GlobalVariable(*TheModule,   
+//TODO                                          LTypesNameTable->getType(), true,
+//TODO                                          GlobalValue::ExternalLinkage, 
+//TODO                                          LTypesNameTable,
+//TODO                                          "llvm.pch.types");
+//TODO}
 
 //===----------------------------------------------------------------------===//
 //                   Recursive Type Handling Code and Data





More information about the llvm-commits mailing list