//===----------------------------------------------------------------------===//
#include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/GlobalVariable.h"
#include "llvm/InstrTypes.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "Support/STLExtras.h"
+#include "Support/LeakDetector.h"
#include "SymbolTableListTraitsImpl.h"
#include <algorithm>
#include <map>
Function *ilist_traits<Function>::createNode() {
- return new Function(FunctionType::get(Type::VoidTy,std::vector<const Type*>(),
- false), false);
+ FunctionType *FTy =
+ FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
+ Function *Ret = new Function(FTy, false);
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
}
GlobalVariable *ilist_traits<GlobalVariable>::createNode() {
- return new GlobalVariable(Type::IntTy, false, false);
+ GlobalVariable *Ret = new GlobalVariable(Type::IntTy, false, false);
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
}
iplist<Function> &ilist_traits<Function>::getList(Module *M) {
delete SymTab;
}
+// Module::dump() - Allow printing from debugger
+void Module::dump() const {
+ print(std::cerr);
+}
+
SymbolTable *Module::getSymbolTableSure() {
- if (!SymTab) SymTab = new SymbolTable(0);
+ if (!SymTab) SymTab = new SymbolTable();
return SymTab;
}
}
-// dropAllReferences() - This function causes all the subinstructions to "let
-// go" of all references that they are maintaining. This allows one to
-// 'delete' a whole class at a time, even though there may be circular
-// references... first all references are dropped, and all use counts go to
-// zero. Then everything is delete'd for real. Note that no operations are
-// valid on an object that has "dropped all references", except operator
-// delete.
+// dropAllReferences() - This function causes all the subelementss to "let go"
+// of all references that they are maintaining. This allows one to 'delete' a
+// whole module at a time, even though there may be circular references... first
+// all references are dropped, and all use counts go to zero. Then everything
+// is delete'd for real. Note that no operations are valid on an object that
+// has "dropped all references", except operator delete.
//
void Module::dropAllReferences() {
for(Module::iterator I = begin(), E = end(); I != E; ++I)
// If there are any GlobalVariable references still out there, nuke them now.
// Since all references are hereby dropped, nothing could possibly reference
- // them still.
- if (GVRefMap) {
- for (GlobalValueRefMap::iterator I = GVRefMap->Map.begin(),
- E = GVRefMap->Map.end(); I != E; ++I) {
- // Delete the ConstantPointerRef node...
- I->second->destroyConstant();
- }
-
- // Since the table is empty, we can now delete it...
- delete GVRefMap;
- }
+ // them still. Note that destroying all of the constant pointer refs will
+ // eventually cause the GVRefMap field to be set to null (by
+ // destroyConstantPointerRef, below).
+ //
+ while (GVRefMap)
+ // Delete the ConstantPointerRef node...
+ GVRefMap->Map.begin()->second->destroyConstant();
}
// Accessor for the underlying GlobalValRefMap...
if (I != GVRefMap->Map.end()) return I->second;
ConstantPointerRef *Ref = new ConstantPointerRef(V);
- GVRefMap->Map.insert(std::make_pair(V, Ref));
-
+ GVRefMap->Map[V] = Ref;
return Ref;
}
+void Module::destroyConstantPointerRef(ConstantPointerRef *CPR) {
+ assert(GVRefMap && "No map allocated, but we have a CPR?");
+ if (!GVRefMap->Map.erase(CPR->getValue())) // Remove it from the map...
+ assert(0 && "ConstantPointerRef not found in module CPR map!");
+
+ if (GVRefMap->Map.empty()) { // If the map is empty, delete it.
+ delete GVRefMap;
+ GVRefMap = 0;
+ }
+}
+
void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) {
GlobalValueRefMap::iterator I = GVRefMap->Map.find(OldGV);
assert(I != GVRefMap->Map.end() &&