[llvm-commits] CVS: llvm/lib/CWriter/Writer.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Nov 1 19:30:00 PST 2003


Changes in directory llvm/lib/CWriter:

Writer.cpp updated: 1.137 -> 1.138

---
Log message:

The "correct" fix for CBackend/2003-10-23-UnusedType.ll is to not even try
to emit types which are not used.


---
Diffs of the changes:  (+24 -15)

Index: llvm/lib/CWriter/Writer.cpp
diff -u llvm/lib/CWriter/Writer.cpp:1.137 llvm/lib/CWriter/Writer.cpp:1.138
--- llvm/lib/CWriter/Writer.cpp:1.137	Thu Oct 23 13:39:22 2003
+++ llvm/lib/CWriter/Writer.cpp	Sat Nov  1 19:29:27 2003
@@ -36,6 +36,8 @@
     std::ostream &Out; 
     Mangler *Mang;
     const Module *TheModule;
+    FindUsedTypes *FUT;
+
     std::map<const Type *, std::string> TypeNames;
     std::set<const Value*> MangledGlobals;
     bool needsMalloc, emittedInvoke;
@@ -52,6 +54,7 @@
     virtual bool run(Module &M) {
       // Initialize
       TheModule = &M;
+      FUT = &getAnalysis<FindUsedTypes>();
 
       // Ensure that all structure types have names...
       bool Changed = nameAllUsedStructureTypes(M);
@@ -542,7 +545,7 @@
 //
 bool CWriter::nameAllUsedStructureTypes(Module &M) {
   // Get a set of types that are used by the program...
-  std::set<const Type *> UT = getAnalysis<FindUsedTypes>().getTypes();
+  std::set<const Type *> UT = FUT->getTypes();
 
   // Loop over the module symbol table, removing types from UT that are already
   // named.
@@ -786,24 +789,28 @@
   // Print out forward declarations for structure types before anything else!
   Out << "/* Structure forward decls */\n";
   for (; I != End; ++I)
-    if (const Type *STy = dyn_cast<StructType>(I->second)) {
-      std::string Name = "struct l_" + Mangler::makeNameProper(I->first);
-      Out << Name << ";\n";
-      TypeNames.insert(std::make_pair(STy, Name));
-    }
+    if (const Type *STy = dyn_cast<StructType>(I->second))
+      // Only print out used types!
+      if (FUT->getTypes().count(STy)) {
+        std::string Name = "struct l_" + Mangler::makeNameProper(I->first);
+        Out << Name << ";\n";
+        TypeNames.insert(std::make_pair(STy, Name));
+      }
 
   Out << "\n";
 
   // Now we can print out typedefs...
   Out << "/* Typedefs */\n";
-  for (I = ST.type_begin(Type::TypeTy); I != End; ++I) {
-    const Type *Ty = cast<Type>(I->second);
-    std::string Name = "l_" + Mangler::makeNameProper(I->first);
-    Out << "typedef ";
-    printType(Out, Ty, Name);
-    Out << ";\n";
-  }
-
+  for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
+    // Only print out used types!
+    if (FUT->getTypes().count(cast<Type>(I->second))) {
+      const Type *Ty = cast<Type>(I->second);
+      std::string Name = "l_" + Mangler::makeNameProper(I->first);
+      Out << "typedef ";
+      printType(Out, Ty, Name);
+      Out << ";\n";
+    }
+  
   Out << "\n";
 
   // Keep track of which structures have been printed so far...
@@ -815,7 +822,9 @@
   Out << "/* Structure contents */\n";
   for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
     if (const StructType *STy = dyn_cast<StructType>(I->second))
-      printContainedStructs(STy, StructPrinted);
+      // Only print out used types!
+      if (FUT->getTypes().count(STy))
+        printContainedStructs(STy, StructPrinted);
 }
 
 // Push the struct onto the stack and recursively push all structs





More information about the llvm-commits mailing list