summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-12-02 06:25:58 +0000
committerChris Lattner <sabre@nondot.org>2004-12-02 06:25:58 +0000
commit3b18139b3cdefe8fc8d606b8946b8355b2227ee2 (patch)
tree98ae5ff06836cfc15653c38e5ef547d500a4e806 /llvm/lib/Transforms
parent7784c2f12ed03a5532193e0278af33d4d08aac66 (diff)
downloadbcm5719-llvm-3b18139b3cdefe8fc8d606b8946b8355b2227ee2.tar.gz
bcm5719-llvm-3b18139b3cdefe8fc8d606b8946b8355b2227ee2.zip
Fix a minor bug where we set a var to initialized on malloc, not on store.
This doesn't fix anything that I'm aware of, just noticed it by inspection llvm-svn: 18417
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index b8edc32f16f..db2d0b3535a 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -670,9 +670,13 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// If there is a comparison against null, we will insert a global bool to
// keep track of whether the global was initialized yet or not.
- GlobalVariable *InitBool = 0;
+ GlobalVariable *InitBool =
+ new GlobalVariable(Type::BoolTy, false, GlobalValue::InternalLinkage,
+ ConstantBool::False, GV->getName()+".init");
+ bool InitBoolUsed = false;
// Loop over all uses of GV, processing them in turn.
+ std::vector<StoreInst*> Stores;
while (!GV->use_empty())
if (LoadInst *LI = dyn_cast<LoadInst>(GV->use_back())) {
while (!LI->use_empty()) {
@@ -681,18 +685,10 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
if (!isa<SetCondInst>(LoadUse.getUser()))
LoadUse = RepValue;
else {
- if (InitBool == 0) {
- InitBool = new GlobalVariable(Type::BoolTy, false,
- GlobalValue::InternalLinkage,
- ConstantBool::False,
- GV->getName()+".init");
- GV->getParent()->getGlobalList().insert(GV, InitBool);
- // The global is initialized when the malloc is run.
- new StoreInst(ConstantBool::True, InitBool, MI);
- }
// Replace the setcc X, 0 with a use of the bool value.
SetCondInst *SCI = cast<SetCondInst>(LoadUse.getUser());
Value *LV = new LoadInst(InitBool, InitBool->getName()+".val", SCI);
+ InitBoolUsed = true;
switch (SCI->getOpcode()) {
default: assert(0 && "Unknown opcode!");
case Instruction::SetLT:
@@ -714,9 +710,20 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
LI->eraseFromParent();
} else {
StoreInst *SI = cast<StoreInst>(GV->use_back());
+ // The global is initialized when the store to it occurs.
+ new StoreInst(ConstantBool::True, InitBool, SI);
SI->eraseFromParent();
}
+ // If the initialization boolean was used, insert it, otherwise delete it.
+ if (!InitBoolUsed) {
+ while (!InitBool->use_empty()) // Delete initializations
+ cast<Instruction>(InitBool->use_back())->eraseFromParent();
+ delete InitBool;
+ } else
+ GV->getParent()->getGlobalList().insert(GV, InitBool);
+
+
// Now the GV is dead, nuke it and the malloc.
GV->eraseFromParent();
MI->eraseFromParent();
OpenPOWER on IntegriCloud