aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/ExecutionEngine.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-12-20 02:45:37 +0000
committerChris Lattner <sabre@nondot.org>2003-12-20 02:45:37 +0000
commit24b0a18c4357de0515c542e97edb2c2eacc543f2 (patch)
tree58baad67c975933d6f278cf5bb2d1c0e1081b19e /lib/ExecutionEngine/ExecutionEngine.cpp
parent3ddc05bdde6ed65f93340ea467d362e80c0ceb9c (diff)
Simple refactorings to prepare for lazy global emission
Also, add a stat for the number of globals emitted git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/ExecutionEngine.cpp')
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index dd5b6a4f5b..42c95727e2 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -30,6 +30,7 @@ using namespace llvm;
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 @@ void ExecutionEngine::emitGlobals() {
// 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 @@ void ExecutionEngine::emitGlobals() {
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;
}