diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-07-17 23:50:19 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-07-17 23:50:19 +0000 |
commit | bb9051531c29bf425c78b88dd96aba601e00656d (patch) | |
tree | f6b81b8ad0977e80e9ef92a6797718a35e1ec62d /lib/VMCore/Function.cpp | |
parent | 1c9c8e64d22bcab91ce2321a06b2b5640a6ae927 (diff) |
bug 122:
- Move GlobalValue and GlobalVariable implementations to Globals.cpp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14929 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Function.cpp')
-rw-r--r-- | lib/VMCore/Function.cpp | 75 |
1 files changed, 3 insertions, 72 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index d12c4dd44f..4c13836688 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -68,7 +68,7 @@ Argument::Argument(const Type *Ty, const std::string &Name, Function *Par) void Argument::setName(const std::string &name, SymbolTable *ST) { Function *P; assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && - "Invalid symtab argument!"); + "Invalid symtab argument!"); if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); Value::setName(name); if (P && hasName()) P->getSymbolTable().insert(this); @@ -82,42 +82,6 @@ void Argument::setParent(Function *parent) { LeakDetector::removeGarbageObject(this); } -static bool removeDeadConstantUsers(Constant *C) { - while (!C->use_empty()) { - if (Constant *CU = dyn_cast<Constant>(C->use_back())) { - if (!removeDeadConstantUsers(CU)) - return false; // Constant wasn't dead. - } else { - return false; // Nonconstant user of the global. - } - } - - C->destroyConstant(); - return true; -} - - -/// removeDeadConstantUsers - If there are any dead constant users dangling -/// 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. -bool GlobalValue::removeDeadConstantUsers() { - while (!use_empty()) { - if (Constant *C = dyn_cast<Constant>(use_back())) { - if (!::removeDeadConstantUsers(C)) - return false; // Constant wasn't dead. - } else { - return false; // Nonconstant user of the global. - } - } - return true; -} - - //===----------------------------------------------------------------------===// // Function Implementation //===----------------------------------------------------------------------===// @@ -161,7 +125,7 @@ Function::~Function() { void Function::setName(const std::string &name, SymbolTable *ST) { Module *P; assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && - "Invalid symtab argument!"); + "Invalid symtab argument!"); if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); Value::setName(name); if (P && hasName()) P->getSymbolTable().insert(this); @@ -294,37 +258,4 @@ unsigned Function::getIntrinsicID() const { } -//===----------------------------------------------------------------------===// -// GlobalVariable Implementation -//===----------------------------------------------------------------------===// - -GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, - Constant *Initializer, - const std::string &Name, Module *ParentModule) - : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, Link, Name), - isConstantGlobal(constant) { - if (Initializer) Operands.push_back(Use((Value*)Initializer, this)); - - LeakDetector::addGarbageObject(this); - - if (ParentModule) - ParentModule->getGlobalList().push_back(this); -} - -void GlobalVariable::setParent(Module *parent) { - if (getParent()) - LeakDetector::addGarbageObject(this); - Parent = parent; - if (getParent()) - LeakDetector::removeGarbageObject(this); -} - -// Specialize setName to take care of symbol table majik -void GlobalVariable::setName(const std::string &name, SymbolTable *ST) { - Module *P; - assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && - "Invalid symtab argument!"); - if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); - Value::setName(name); - if (P && hasName()) P->getSymbolTable().insert(this); -} +// vim: sw=2 ai |