[llvm-commits] CVS: llvm/lib/ExecutionEngine/ExecutionEngine.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Dec 19 20:46:11 PST 2003


Changes in directory llvm/lib/ExecutionEngine:

ExecutionEngine.cpp updated: 1.40 -> 1.41

---
Log message:

Simple refactorings to prepare for lazy global emission
Also, add a stat for the number of globals emitted


---
Diffs of the changes:  (+16 -2)

Index: llvm/lib/ExecutionEngine/ExecutionEngine.cpp
diff -u llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.40 llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.41
--- llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.40	Fri Dec 19 19:45:17 2003
+++ llvm/lib/ExecutionEngine/ExecutionEngine.cpp	Fri Dec 19 20:45:37 2003
@@ -30,6 +30,7 @@
 
 namespace {
   Statistic<> NumInitBytes("lli", "Number of bytes of global vars initialized");
+  Statistic<> NumGlobals  ("lli", "Number of global vars initialized");
 }
 
 ExecutionEngine::ExecutionEngine(ModuleProvider *P) : 
@@ -372,7 +373,7 @@
       
       // Allocate some memory for it!
       unsigned Size = TD.getTypeSize(Ty);
-      GlobalAddress[I] = new char[Size];
+      addGlobalMapping(I, new char[Size]);
       NumInitBytes += Size;
 
       DEBUG(std::cerr << "Global '" << I->getName() << "' -> "
@@ -394,5 +395,18 @@
   for (Module::giterator I = getModule().gbegin(), E = getModule().gend();
        I != E; ++I)
     if (!I->isExternal())
-      InitializeMemory(I->getInitializer(), GlobalAddress[I]);
+      EmitGlobalVariable(I);
+}
+
+// EmitGlobalVariable - This method emits the specified global variable to the
+// address specified in GlobalAddresses, or allocates new memory if it's not
+// already in the map.
+void ExecutionEngine::EmitGlobalVariable(GlobalVariable *GV) {
+  void *&GA = GlobalAddress[GV];
+  if (GA == 0) {
+    // If it's not already specified, allocate memory for the global.
+    GA = new char[getTargetData().getTypeSize(GV->getType()->getElementType())];
+  }
+  InitializeMemory(GV->getInitializer(), GA);
+  ++NumGlobals;
 }





More information about the llvm-commits mailing list