Re: [llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Hi Chris, + (CE-getOpcode() == Instruction::BitCast || + CE-getOpcode() == Instruction::GetElementPtr)) +return dyn_castGlobalValue(CE-getOperand(0)); isn't this only correct if all the GEP indices are zero? By the way, ExtractGlobalVariable in SelectionDAGISel does the same thing as this function, maybe they should be combined? Ciao, Duncan. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
On May 5, 2007, at 11:48 PM, Duncan Sands wrote: Hi Chris, + (CE-getOpcode() == Instruction::BitCast || + CE-getOpcode() == Instruction::GetElementPtr)) +return dyn_castGlobalValue(CE-getOperand(0)); isn't this only correct if all the GEP indices are zero? By the way, ExtractGlobalVariable in SelectionDAGISel does the same thing as this function, maybe they should be combined? The verifier should reject any GEPs that don't have all zero indices. -Chris ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Changes in directory llvm/lib/VMCore: Globals.cpp updated: 1.23 - 1.24 --- Log message: Unbreak VC++ build. --- Diffs of the changes: (+2 -2) Globals.cpp |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.23 llvm/lib/VMCore/Globals.cpp:1.24 --- llvm/lib/VMCore/Globals.cpp:1.23Mon Apr 30 05:28:40 2007 +++ llvm/lib/VMCore/Globals.cpp Thu May 3 17:09:21 2007 @@ -223,7 +223,7 @@ else assert(0 Unsupported aliasee); } - } else -return 0; + } + return 0; } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Changes in directory llvm/lib/VMCore: Globals.cpp updated: 1.22 - 1.23 --- Log message: Fix typo. Interesting, but old variant worked too :) --- Diffs of the changes: (+1 -1) Globals.cpp |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.22 llvm/lib/VMCore/Globals.cpp:1.23 --- llvm/lib/VMCore/Globals.cpp:1.22Sun Apr 29 13:02:48 2007 +++ llvm/lib/VMCore/Globals.cpp Mon Apr 30 05:28:40 2007 @@ -217,7 +217,7 @@ return GV; else { const ConstantExpr *CE = 0; - if ((CE = dyn_castConstantExpr(Aliasee)) + if ((CE = dyn_castConstantExpr(C)) (CE-getOpcode() == Instruction::BitCast)) return castGlobalValue(CE-getOperand(0)); else ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Changes in directory llvm/lib/VMCore: Globals.cpp updated: 1.15 - 1.16 --- Log message: Rework GlobalValue::removeDeadConstantUsers to always remove dead constant exprs hanging off a global, even if the global is not otherwise dead. This requires some tricky iterator gymnastics. This implements Transforms/GlobalOpt/constantexpr-dangle.ll by deleting a constantexpr that made it appear that the address of the function was taken. --- Diffs of the changes: (+29 -21) Globals.cpp | 50 +- 1 files changed, 29 insertions(+), 21 deletions(-) Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.15 llvm/lib/VMCore/Globals.cpp:1.16 --- llvm/lib/VMCore/Globals.cpp:1.15Mon Feb 5 14:47:20 2007 +++ llvm/lib/VMCore/Globals.cpp Sun Feb 25 15:06:13 2007 @@ -22,20 +22,18 @@ //GlobalValue Class //===--===// -/// This could be named SafeToDestroyGlobalValue. It just makes sure that -/// there are no non-constant uses of this GlobalValue. If there aren't then -/// this and the transitive closure of the constants can be deleted. See the -/// destructor for details. -static bool removeDeadConstantUsers(Constant* C) { +/// removeDeadUsersOfConstant - If the specified constantexpr is dead, remove +/// it. This involves recursively eliminating any dead users of the +/// constantexpr. +static bool removeDeadUsersOfConstant(Constant *C) { if (isaGlobalValue(C)) return false; // Cannot remove this - while (!C-use_empty()) -if (Constant *User = dyn_castConstant(C-use_back())) { - if (!removeDeadConstantUsers(User)) -return false; // Constant wasn't dead -} else { - return false; // Non-constant usage; -} + while (!C-use_empty()) { +Constant *User = dyn_castConstant(C-use_back()); +if (!User) return false; // Non-constant usage; +if (!removeDeadUsersOfConstant(User)) + return false; // Constant wasn't dead + } C-destroyConstant(); return true; @@ -45,17 +43,27 @@ /// off of this global value, remove them. This method is useful for clients /// that want to check to see if a global is unused, but don't want to deal /// with potentially dead constants hanging off of the globals. -/// -/// This function returns true if the global value is now dead. If all -/// users of this global are not dead, this method may return false and -/// leave some of them around. void GlobalValue::removeDeadConstantUsers() { - while(!use_empty()) { -if (Constant* User = dyn_castConstant(use_back())) { - if (!::removeDeadConstantUsers(User)) -return; // Constant wasn't dead + + Value::use_iterator I = use_begin(), E = use_end(); + Value::use_iterator LastNonDeadUser = E; + for (; I != E; ++I) { +if (Constant *User = dyn_castConstant(*I)) { + if (!removeDeadUsersOfConstant(User)) { +// If the constant wasn't dead, remember that this was the last live use +// and move on to the next constant. +LastNonDeadUser = I; + } else { +// If the constant was dead, then the iterator is invalidated. +if (LastNonDeadUser == E) { + I = use_begin(); + if (I == E) break; +} else { + I = LastNonDeadUser; +} + } } else { - return; // Non-constant usage; + LastNonDeadUser = I; } } } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Changes in directory llvm/lib/VMCore: Globals.cpp updated: 1.16 - 1.17 --- Log message: revert my previous change, something strange is happening. --- Diffs of the changes: (+21 -29) Globals.cpp | 50 +- 1 files changed, 21 insertions(+), 29 deletions(-) Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.16 llvm/lib/VMCore/Globals.cpp:1.17 --- llvm/lib/VMCore/Globals.cpp:1.16Sun Feb 25 15:06:13 2007 +++ llvm/lib/VMCore/Globals.cpp Sun Feb 25 22:43:19 2007 @@ -22,18 +22,20 @@ //GlobalValue Class //===--===// -/// removeDeadUsersOfConstant - If the specified constantexpr is dead, remove -/// it. This involves recursively eliminating any dead users of the -/// constantexpr. -static bool removeDeadUsersOfConstant(Constant *C) { +/// This could be named SafeToDestroyGlobalValue. It just makes sure that +/// there are no non-constant uses of this GlobalValue. If there aren't then +/// this and the transitive closure of the constants can be deleted. See the +/// destructor for details. +static bool removeDeadConstantUsers(Constant* C) { if (isaGlobalValue(C)) return false; // Cannot remove this - while (!C-use_empty()) { -Constant *User = dyn_castConstant(C-use_back()); -if (!User) return false; // Non-constant usage; -if (!removeDeadUsersOfConstant(User)) - return false; // Constant wasn't dead - } + while (!C-use_empty()) +if (Constant *User = dyn_castConstant(C-use_back())) { + if (!removeDeadConstantUsers(User)) +return false; // Constant wasn't dead +} else { + return false; // Non-constant usage; +} C-destroyConstant(); return true; @@ -43,27 +45,17 @@ /// off of this global value, remove them. This method is useful for clients /// that want to check to see if a global is unused, but don't want to deal /// with potentially dead constants hanging off of the globals. +/// +/// This function returns true if the global value is now dead. If all +/// users of this global are not dead, this method may return false and +/// leave some of them around. void GlobalValue::removeDeadConstantUsers() { - - Value::use_iterator I = use_begin(), E = use_end(); - Value::use_iterator LastNonDeadUser = E; - for (; I != E; ++I) { -if (Constant *User = dyn_castConstant(*I)) { - if (!removeDeadUsersOfConstant(User)) { -// If the constant wasn't dead, remember that this was the last live use -// and move on to the next constant. -LastNonDeadUser = I; - } else { -// If the constant was dead, then the iterator is invalidated. -if (LastNonDeadUser == E) { - I = use_begin(); - if (I == E) break; -} else { - I = LastNonDeadUser; -} - } + while(!use_empty()) { +if (Constant* User = dyn_castConstant(use_back())) { + if (!::removeDeadConstantUsers(User)) +return; // Constant wasn't dead } else { - LastNonDeadUser = I; + return; // Non-constant usage; } } } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Changes in directory llvm/lib/VMCore: Globals.cpp updated: 1.17 - 1.18 --- Log message: reapply my previous patch with a bugfix. --- Diffs of the changes: (+31 -21) Globals.cpp | 52 +++- 1 files changed, 31 insertions(+), 21 deletions(-) Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.17 llvm/lib/VMCore/Globals.cpp:1.18 --- llvm/lib/VMCore/Globals.cpp:1.17Sun Feb 25 22:43:19 2007 +++ llvm/lib/VMCore/Globals.cpp Sun Feb 25 23:02:39 2007 @@ -22,20 +22,18 @@ //GlobalValue Class //===--===// -/// This could be named SafeToDestroyGlobalValue. It just makes sure that -/// there are no non-constant uses of this GlobalValue. If there aren't then -/// this and the transitive closure of the constants can be deleted. See the -/// destructor for details. -static bool removeDeadConstantUsers(Constant* C) { +/// removeDeadUsersOfConstant - If the specified constantexpr is dead, remove +/// it. This involves recursively eliminating any dead users of the +/// constantexpr. +static bool removeDeadUsersOfConstant(Constant *C) { if (isaGlobalValue(C)) return false; // Cannot remove this - while (!C-use_empty()) -if (Constant *User = dyn_castConstant(C-use_back())) { - if (!removeDeadConstantUsers(User)) -return false; // Constant wasn't dead -} else { - return false; // Non-constant usage; -} + while (!C-use_empty()) { +Constant *User = dyn_castConstant(C-use_back()); +if (!User) return false; // Non-constant usage; +if (!removeDeadUsersOfConstant(User)) + return false; // Constant wasn't dead + } C-destroyConstant(); return true; @@ -45,17 +43,29 @@ /// off of this global value, remove them. This method is useful for clients /// that want to check to see if a global is unused, but don't want to deal /// with potentially dead constants hanging off of the globals. -/// -/// This function returns true if the global value is now dead. If all -/// users of this global are not dead, this method may return false and -/// leave some of them around. void GlobalValue::removeDeadConstantUsers() { - while(!use_empty()) { -if (Constant* User = dyn_castConstant(use_back())) { - if (!::removeDeadConstantUsers(User)) -return; // Constant wasn't dead + Value::use_iterator I = use_begin(), E = use_end(); + Value::use_iterator LastNonDeadUser = E; + while (I != E) { +if (Constant *User = dyn_castConstant(*I)) { + if (!removeDeadUsersOfConstant(User)) { +// If the constant wasn't dead, remember that this was the last live use +// and move on to the next constant. +LastNonDeadUser = I; +++I; + } else { +// If the constant was dead, then the iterator is invalidated. +if (LastNonDeadUser == E) { + I = use_begin(); + if (I == E) break; +} else { + I = LastNonDeadUser; + ++I; +} + } } else { - return; // Non-constant usage; + LastNonDeadUser = I; + ++I; } } } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Globals.cpp
Changes in directory llvm/lib/VMCore: Globals.cpp updated: 1.13 - 1.14 --- Log message: Add a version of the globalvariable ctor that inserts at a specific location. --- Diffs of the changes: (+21 -0) Globals.cpp | 21 + 1 files changed, 21 insertions(+) Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.13 llvm/lib/VMCore/Globals.cpp:1.14 --- llvm/lib/VMCore/Globals.cpp:1.13Mon Jan 23 22:13:11 2006 +++ llvm/lib/VMCore/Globals.cpp Sat Sep 30 16:31:26 2006 @@ -91,6 +91,27 @@ ParentModule-getGlobalList().push_back(this); } +GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, + Constant *InitVal, + const std::string Name, GlobalVariable *Before) + : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, +Initializer, InitVal != 0, Link, Name), +isConstantGlobal(constant) { + if (InitVal) { +assert(InitVal-getType() == Ty + Initializer should be the same type as the GlobalVariable!); +Initializer.init(InitVal, this); + } else { +Initializer.init(0, this); + } + + LeakDetector::addGarbageObject(this); + + if (Before) +Before-getParent()-getGlobalList().insert(Before, this); +} + + void GlobalVariable::setParent(Module *parent) { if (getParent()) LeakDetector::addGarbageObject(this); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits