- // Lookup the value in the module's map
- ValueMap::const_iterator MVI = MI->second.map.find(V);
- // Make sure we found it.
- if (MVI == MI->second.map.end()) return -1;
- // Return it.
- return MVI->second;
-}
-
-
-// Create a new slot, or return the existing slot if it is already
-// inserted. Note that the logic here parallels getSlot but instead
-// of asserting when the Value* isn't found, it inserts the value.
-unsigned SlotMachine::getOrCreateSlot(const Value *V) {
- const Type* VTy = V->getType();
- assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!");
- assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
- "Can't insert a non-GlobalValue Constant into SlotMachine");
-
- // Look up the type plane for the Value's type from the module map
- TypedPlanes::const_iterator MI = mMap.find(VTy);
-
- if (TheFunction) {
- // Get the type plane for the Value's type from the function map
- TypedPlanes::const_iterator FI = fMap.find(VTy);
- // If there is a corresponding type plane in the function map
- if (FI != fMap.end()) {
- // Lookup the Value in the function map
- ValueMap::const_iterator FVI = FI->second.map.find(V);
- // If the value doesn't exist in the function map
- if (FVI == FI->second.map.end()) {
- // If there is no corresponding type plane in the module map
- if (MI == mMap.end())
- return insertValue(V);
- // Look up the value in the module map
- ValueMap::const_iterator MVI = MI->second.map.find(V);
- // If we didn't find it, it wasn't inserted
- if (MVI == MI->second.map.end())
- return insertValue(V);
- else
- // We found it only at the module level
- return MVI->second;