diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-20 02:45:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-20 02:45:37 +0000 |
commit | 6bbe3ecee58aed836295c6ab34a01392082d39bd (patch) | |
tree | ac853b34469faa989f03e05b1f7fc74bed2b05ef /llvm/lib/ExecutionEngine | |
parent | dc997d94707a95df0a276dc7515d10f746569ea7 (diff) | |
download | bcm5719-llvm-6bbe3ecee58aed836295c6ab34a01392082d39bd.tar.gz bcm5719-llvm-6bbe3ecee58aed836295c6ab34a01392082d39bd.zip |
Simple refactorings to prepare for lazy global emission
Also, add a stat for the number of globals emitted
llvm-svn: 10547
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r-- | llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp index dd5b6a4f5b7..42c95727e29 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/llvm/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; } |