diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-20 03:36:47 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-20 03:36:47 +0000 |
commit | fbcc0aa18d01fd1e2af833f48b58ac091d421676 (patch) | |
tree | 53c5ba73de80379c1a744e4fb006a308e80e00ae /llvm/lib/ExecutionEngine/ExecutionEngine.cpp | |
parent | 620ac15114e79a4cd6906ec4c4eb4d2da34f4ce7 (diff) | |
download | bcm5719-llvm-fbcc0aa18d01fd1e2af833f48b58ac091d421676.tar.gz bcm5719-llvm-fbcc0aa18d01fd1e2af833f48b58ac091d421676.zip |
Implement PR135, lazy emission of global variables
llvm-svn: 10549
Diffstat (limited to 'llvm/lib/ExecutionEngine/ExecutionEngine.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp index 42c95727e29..c820f63c29f 100644 --- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp @@ -155,7 +155,8 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { const_cast<Function*>(dyn_cast<Function>(CPR->getValue()))) Result = PTOGV(getPointerToFunctionOrStub(F)); else - Result = PTOGV(getPointerToGlobal(CPR->getValue())); + Result = PTOGV(getOrEmitGlobalVariable( + cast<GlobalVariable>(CPR->getValue()))); } else { assert(0 && "Unknown constant pointer type!"); @@ -374,7 +375,6 @@ void ExecutionEngine::emitGlobals() { // Allocate some memory for it! unsigned Size = TD.getTypeSize(Ty); addGlobalMapping(I, new char[Size]); - NumInitBytes += Size; DEBUG(std::cerr << "Global '" << I->getName() << "' -> " << (void*)GlobalAddress[I] << "\n"); @@ -401,12 +401,15 @@ void ExecutionEngine::emitGlobals() { // 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 ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) { void *&GA = GlobalAddress[GV]; + const Type *ElTy = GV->getType()->getElementType(); if (GA == 0) { // If it's not already specified, allocate memory for the global. - GA = new char[getTargetData().getTypeSize(GV->getType()->getElementType())]; + GA = new char[getTargetData().getTypeSize(ElTy)]; } + InitializeMemory(GV->getInitializer(), GA); + NumInitBytes += getTargetData().getTypeSize(ElTy); ++NumGlobals; } |