[llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/ElfReader.cpp ElfReader.h Phases.cpp

Joel Stanley jstanley at cs.uiuc.edu
Tue Apr 29 14:43:01 PDT 2003


Changes in directory llvm/lib/Reoptimizer/Inst:

ElfReader.cpp updated: 1.4 -> 1.5
ElfReader.h updated: 1.3 -> 1.4
Phases.cpp updated: 1.13 -> 1.14

---
Log message:

Restricted symtable search to those functions whose symbols are associated with the
section labelled '.text', which is fixed according to the ELF spec.


---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/Inst/ElfReader.cpp
diff -u llvm/lib/Reoptimizer/Inst/ElfReader.cpp:1.4 llvm/lib/Reoptimizer/Inst/ElfReader.cpp:1.5
--- llvm/lib/Reoptimizer/Inst/ElfReader.cpp:1.4	Thu Apr 10 18:23:58 2003
+++ llvm/lib/Reoptimizer/Inst/ElfReader.cpp	Tue Apr 29 14:48:29 2003
@@ -28,6 +28,8 @@
 using std::cerr;
 using std::endl;
 
+const std::string ElfReader::sm_codeSegmentName = ".text";
+
 ElfReader::ElfReader(const char* execName):
     m_execFD(-1),
     m_elfDes(0),
@@ -46,11 +48,11 @@
     m_elfHdr = elf64_getehdr(m_elfDes);
     assert(m_elfHdr && "Failed to obtain valid ELF header");
 
-    LocateSymbolTable();
+    LocateSections();
 
     // Obtain pointer to string table associated with the symbol table
     Elf_Data* strTabHand = elf_getdata(elf_getscn(m_elfDes, m_symTab->sh_link), 0);
-    assert(strTabHand && "Couldn't obtain ELF data handle to string table");
+    assert(strTabHand && "Couldn't obtain ELF data handle to symbol-name string table");
     m_strTab = (char*) strTabHand->d_buf;
 
     // Determine the size of each entry and the number of entries in the table
@@ -85,23 +87,34 @@
             rdcnt = read(m_execFD, &sym + rdcnt, m_entrySize);
         } while(rdcnt < m_entrySize);
 
-        // If it is a function, extract name, extents, and return
+        // If it is a function in the code segment, extract name, extents, and return.
         if(STT_FUNC == (sym.st_info & 0xf)) { // Symbol type is lower 4 bits
-            fname = m_strTab + sym.st_name;
-            range.first = sym.st_value;
-            range.second = sym.st_value + sym.st_size - 4;
-            return true;
+            if(sym.st_shndx == m_codeSectionIdx) {
+                fname = m_strTab + sym.st_name;
+                range.first = sym.st_value;
+                range.second = sym.st_value + sym.st_size - 4;
+                return true;
+            }
         }
     }
 
     return false;
 }
 
-void ElfReader::LocateSymbolTable()
+void ElfReader::LocateSections()
 {
-    // Examine the section header of each section, looking for the symbol table.  When
-    // found, ensure that it is unique, otherwise, assert out.
-    
+    // Obtain the base pointer to the string table containing the names of the
+    // sections in the file.
+
+    Elf_Data* strTabHand = elf_getdata(elf_getscn(m_elfDes, m_elfHdr->e_shstrndx), 0);
+    assert(strTabHand && "Couldn't obtain ELF data handle to section-name string table");
+    char* secNameTable = (char*) strTabHand->d_buf;
+
+    // Examine the section header of each section, looking for:
+    // a) The symbol table.  When found ensure that it is unique, otherwise, assert out.
+    // b) The code segment (i.e. the segment which has the spec-defined name ".text"
+
+    bool codeSegmentFound = false;
     Elf64_Shdr* secHdr;
     for(Elf_Scn* currScn = 0; (currScn = elf_nextscn(m_elfDes, currScn)); ) {
         secHdr = elf64_getshdr(currScn);
@@ -112,10 +125,23 @@
             assert(!m_symTab && "Should only be one symbol table in the image");
             m_symTab = secHdr;
         }
+        else if(SHT_PROGBITS == secHdr->sh_type) {
+            if(!codeSegmentFound) {
+                // Found section marked as "program-defined".  Obtain section name and
+                // see if it matches the name of the code segment.
+                
+                char* sectionName = secNameTable + secHdr->sh_name;
+                if(sm_codeSegmentName == sectionName) {
+                    m_codeSectionIdx = elf_ndxscn(currScn);
+                    codeSegmentFound = true;
+                }
+            }
+        }
         // NB: May need to look for SHT_DYNSYM here later on.
     }
 
     assert(m_symTab && "Couldn't locate symbol table (stripped executable?)");
+    assert(codeSegmentFound && "Couldn't locate code segment");
 }
 
 ElfReader::~ElfReader() 


Index: llvm/lib/Reoptimizer/Inst/ElfReader.h
diff -u llvm/lib/Reoptimizer/Inst/ElfReader.h:1.3 llvm/lib/Reoptimizer/Inst/ElfReader.h:1.4
--- llvm/lib/Reoptimizer/Inst/ElfReader.h:1.3	Tue Apr  8 22:35:57 2003
+++ llvm/lib/Reoptimizer/Inst/ElfReader.h	Tue Apr 29 14:48:29 2003
@@ -21,7 +21,7 @@
     
   private:
     ElfReader() {}
-    void LocateSymbolTable();
+    void LocateSections();
 
     int           m_execFD;       // Executable FD
     Elf*          m_elfDes;       // ELF descriptor
@@ -31,6 +31,9 @@
     Elf64_Xword   m_numEntries;
     Elf64_Xword   m_entriesProcessed;
     char*         m_strTab;
+    unsigned      m_codeSectionIdx; // Section index of code section
+
+    static const std::string sm_codeSegmentName;
 };
 
 #endif // _INCLUDED_ELFREADER_H


Index: llvm/lib/Reoptimizer/Inst/Phases.cpp
diff -u llvm/lib/Reoptimizer/Inst/Phases.cpp:1.13 llvm/lib/Reoptimizer/Inst/Phases.cpp:1.14
--- llvm/lib/Reoptimizer/Inst/Phases.cpp:1.13	Tue Apr 29 13:36:53 2003
+++ llvm/lib/Reoptimizer/Inst/Phases.cpp	Tue Apr 29 14:48:29 2003
@@ -205,8 +205,14 @@
     
     TraceCache*     m_pTraceCache;
     InstManip       m_instManip;
+
+    static uint64_t* sm_pSpillRegion; // Base pointer to the spill region for phase 3 invocations
+    static uint64_t* sm_pCurrSpill;   // Pointer to current location in the spill region
 };
 
+uint64_t* Phase2::sm_pSpillRegion = 0;
+uint64_t* Phase2::sm_pCurrSpill = 0;
+
 // Phase3 is the class that is responsible for making the "phase 3" transformation; the
 // global function phase3() is responsible for constructing one Phase3 instance per
 // invocation and invoking transform on it.
@@ -279,13 +285,20 @@
     std::string funcName;
     AddressRange range;
 
-    while(elfReader.GetNextFunction(funcName, range)) {
-        if(funcName == "fibs") {
-            //cerr << "Printing information about function " << funcName << endl;
-            //m_instManip.printRange(range.first, range.second);
-
-            cerr << "Transforming function " << funcName << "..." << endl;
-            transformFunction(range);
+    // TODO: Come up with a better way to do this that doesn't involve storing the entire
+    // list of functions here -- this could be quite large.
+    
+    vector<std::pair<std::string, AddressRange> > funcs;
+    while(elfReader.GetNextFunction(funcName, range))
+        funcs.push_back(std::make_pair(funcName, range));
+
+    cerr << "There are " << funcs.size() << " functions to process." << endl << endl;
+
+    for(vector<std::pair<std::string, AddressRange> >::iterator i = funcs.begin(),
+            e = funcs.end(); i != e; ++i) {
+        if(i->first == "fibs") {
+            cerr << "Transforming function " << i->first << "..." << endl;
+            transformFunction(i->second);
         }
     }
 
@@ -413,15 +426,6 @@
     for(vector<InstCandidate>::iterator i = candidates.begin(), e = candidates.end(); i != e; ++i) {
         cerr << "Transforming " << *i << endl;
 
-#if 0
-        uint64_t slotBase = m_pTraceCache->getMemMgr()->getMemory(getSlotSize(*i));
-        assert(slotBase && "Unable to obtain memory from MemoryManger instance");
-
-        // Replace load candidate instruction with a branch to start of slot.
-        VirtualMem* vm = m_pTraceCache->getVM();
-        uint64_t loadAddr = i->front().first;
-        vm->writeInstToVM(loadAddr, m_instManip.getBranchAlways(slotBase, loadAddr));
-#endif
         // Replace load candidate instruction with a branch to the start of a new slot.
         uint64_t slotBase = replaceInstWithBrToSlot(i->front().first, getSlotSize(*i),
                                                     m_pTraceCache, m_instManip);





More information about the llvm-commits mailing list