-
- // DeclareNewGlobalValue - Called every time a new GV has been defined. This
- // is used to remove things from the forward declaration map, resolving them
- // to the correct thing as needed.
- //
- void DeclareNewGlobalValue(GlobalValue *GV, ValID D) {
- // Check to see if there is a forward reference to this global variable...
- // if there is, eliminate it and patch the reference to use the new def'n.
- GlobalRefsType::iterator I =
- GlobalRefs.find(std::make_pair(GV->getType(), D));
-
- if (I != GlobalRefs.end()) {
- GlobalValue *OldGV = I->second; // Get the placeholder...
- I->first.second.destroy(); // Free string memory if necessary
-
- // Replace all uses of the placeholder with the new GV
- OldGV->replaceAllUsesWith(GV);
-
- // Remove OldGV from the module...
- if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(OldGV))
- CurrentModule->getGlobalList().erase(GVar);
- else
- CurrentModule->getFunctionList().erase(cast<Function>(OldGV));
-
- // Remove the map entry for the global now that it has been created...
- GlobalRefs.erase(I);
- }
- }
-