[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Nov 11 17:33:52 PST 2005



Changes in directory llvm/lib/Bytecode/Reader:

Reader.cpp updated: 1.173 -> 1.174
---
Log message:

Read and write section info from/to .bc files


---
Diffs of the changes:  (+42 -10)

 Reader.cpp |   52 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 10 deletions(-)


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.173 llvm/lib/Bytecode/Reader/Reader.cpp:1.174
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.173	Sun Nov  6 02:23:17 2005
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Fri Nov 11 19:33:40 2005
@@ -1891,6 +1891,10 @@
 
   if (Handler) Handler->handleModuleGlobalsBegin();
 
+  // SectionID - If a global has an explicit section specified, this map
+  // remembers the ID until we can translate it into a string.
+  std::map<GlobalValue*, unsigned> SectionID;
+  
   // Read global variables...
   unsigned VarType = read_vbr_uint();
   while (VarType != Type::VoidTyID) { // List is terminated by Void
@@ -1903,6 +1907,7 @@
     bool isConstant = VarType & 1;
     bool hasInitializer = (VarType & 2) != 0;
     unsigned Alignment = 0;
+    unsigned GlobalSectionID = 0;
     
     // An extension word is present when linkage = 3 (internal) and hasinit = 0.
     if (LinkageID == 3 && !hasInitializer) {
@@ -1912,6 +1917,9 @@
       hasInitializer = ExtWord & 1;
       LinkageID = (ExtWord >> 1) & 7;
       Alignment = (1 << ((ExtWord >> 4) & 31)) >> 1;
+      
+      if (ExtWord & (1 << 9))  // Has a section ID.
+        GlobalSectionID = read_vbr_uint();
     }
 
     GlobalValue::LinkageTypes Linkage;
@@ -1942,6 +1950,9 @@
     GV->setAlignment(Alignment);
     insertValue(GV, SlotNo, ModuleValues);
 
+    if (GlobalSectionID != 0)
+      SectionID[GV] = GlobalSectionID;
+
     unsigned initSlot = 0;
     if (hasInitializer) {
       initSlot = read_vbr_uint();
@@ -1975,9 +1986,8 @@
     const FunctionType* FTy =
       cast<FunctionType>(cast<PointerType>(Ty)->getElementType());
 
-
     // Insert the place holder.
-    Function* Func = new Function(FTy, GlobalValue::ExternalLinkage,
+    Function *Func = new Function(FTy, GlobalValue::ExternalLinkage,
                                   "", TheModule);
     insertValue(Func, (FnSignature & (~0U >> 1)) >> 5, ModuleValues);
 
@@ -1997,6 +2007,9 @@
       unsigned ExtWord = read_vbr_uint();
       Alignment = (1 << (ExtWord & 31)) >> 1;
       CC |= ((ExtWord >> 5) & 15) << 4;
+      
+      if (ExtWord & (1 << 10))  // Has a section ID.
+        SectionID[Func] = read_vbr_uint();
     }
     
     Func->setCallingConv(CC-1);
@@ -2014,28 +2027,47 @@
   // remove elements efficiently from the back of the vector.
   std::reverse(FunctionSignatureList.begin(), FunctionSignatureList.end());
 
-  // If this bytecode format has dependent library information in it ..
-  if (!hasNoDependentLibraries) {
-    // Read in the number of dependent library items that follow
+  /// SectionNames - This contains the list of section names encoded in the
+  /// moduleinfoblock.  Functions and globals with an explicit section index
+  /// into this to get their section name.
+  std::vector<std::string> SectionNames;
+  
+  if (hasInconsistentModuleGlobalInfo) {
+    align32();
+  } else if (!hasNoDependentLibraries) {
+    // If this bytecode format has dependent library information in it, read in
+    // the number of dependent library items that follow.
     unsigned num_dep_libs = read_vbr_uint();
     std::string dep_lib;
-    while( num_dep_libs-- ) {
+    while (num_dep_libs--) {
       dep_lib = read_str();
       TheModule->addLibrary(dep_lib);
       if (Handler)
         Handler->handleDependentLibrary(dep_lib);
     }
 
-
-    // Read target triple and place into the module
+    // Read target triple and place into the module.
     std::string triple = read_str();
     TheModule->setTargetTriple(triple);
     if (Handler)
       Handler->handleTargetTriple(triple);
+    
+    if (At != BlockEnd) {
+      // If the file has section info in it, read the section names now.
+      unsigned NumSections = read_vbr_uint();
+      while (NumSections--)
+        SectionNames.push_back(read_str());
+    }
   }
 
-  if (hasInconsistentModuleGlobalInfo)
-    align32();
+  // If any globals are in specified sections, assign them now.
+  for (std::map<GlobalValue*, unsigned>::iterator I = SectionID.begin(), E =
+       SectionID.end(); I != E; ++I)
+    if (I->second) {
+      if (I->second > SectionID.size())
+        error("SectionID out of range for global!");
+      I->first->setSection(SectionNames[I->second-1]);
+    }
 
   // This is for future proofing... in the future extra fields may be added that
   // we don't understand, so we transparently ignore them.






More information about the llvm-commits mailing list