-// 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::createSlot(const Value *V) {
- assert(V && "Can't insert a null Value to SlotMachine");
- assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
- "Can't insert a non-GlobalValue Constant into SlotMachine");
-
- const Type* VTy = V->getType();
-
- // Just ignore void typed things
- if (VTy == Type::VoidTy) return 0; // FIXME: Wrong return value!
-
- // 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;
-
- // else the value exists in the function map
- } else {
- if (MI == mMap.end())
- return FVI->second;
- else
- // Return the slot number as the module's contribution to
- // the type plane plus the index in the function's contribution
- // to the type plane.
- return MI->second.next_slot + FVI->second;
- }
-
- // else there is not a corresponding type plane in the function map
- } else {
- // If the type plane doesn't exists at the module level
- if (MI == mMap.end()) {
- return insertValue(V);
- // else type plane exists at the module level, examine it
- } else {
- // Look up the value in the module's map
- ValueMap::const_iterator MVI = MI->second.map.find(V);
- // If we didn't find it there either
- if (MVI == MI->second.map.end())
- // Return the slot number as the module's contribution to
- // the type plane plus the index of the function map insertion.
- return MI->second.next_slot + insertValue(V);
- else
- return MVI->second;
- }
- }
- }