Split CreateSlot into two versions, one for globals and one for function-local

values


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33036 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2007-01-09 07:55:49 +00:00
parent 3a4621c5f6
commit 9446bbe7d4

View File

@@ -102,9 +102,11 @@ private:
/// This function does the actual initialization.
inline void initialize();
/// CreateSlot - If the specified Value* doesn't have a name, assign it a slot
/// number.
void CreateSlot(const Value *V);
/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
void CreateModuleSlot(const GlobalValue *V);
/// CreateFunctionSlot - Insert the specified Value* into the slot table.
void CreateFunctionSlot(const Value *V);
/// Insert a value into the value table.
void insertValue(const Value *V);
@@ -1424,13 +1426,13 @@ void SlotMachine::processModule() {
for (Module::const_global_iterator I = TheModule->global_begin(),
E = TheModule->global_end(); I != E; ++I)
if (!I->hasName())
CreateSlot(I);
CreateModuleSlot(I);
// Add all the unnamed functions to the table.
for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
I != E; ++I)
if (!I->hasName())
CreateSlot(I);
CreateModuleSlot(I);
SC_DEBUG("end processModule!\n");
}
@@ -1444,7 +1446,7 @@ void SlotMachine::processFunction() {
for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
AE = TheFunction->arg_end(); AI != AE; ++AI)
if (!AI->hasName())
CreateSlot(AI);
CreateFunctionSlot(AI);
SC_DEBUG("Inserting Instructions:\n");
@@ -1452,10 +1454,10 @@ void SlotMachine::processFunction() {
for (Function::const_iterator BB = TheFunction->begin(),
E = TheFunction->end(); BB != E; ++BB) {
if (!BB->hasName())
CreateSlot(BB);
CreateFunctionSlot(BB);
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
if (I->getType() != Type::VoidTy && !I->hasName())
CreateSlot(I);
CreateFunctionSlot(I);
}
FunctionProcessed = true;
@@ -1464,7 +1466,7 @@ void SlotMachine::processFunction() {
}
/// Clean up after incorporating a function. This is the only way to get out of
/// the function incorporation state that affects getSlot/CreateSlot. Function
/// the function incorporation state that affects getSlot/Create*Slot. Function
/// incorporation state is indicated by TheFunction != 0.
void SlotMachine::purgeFunction() {
SC_DEBUG("begin purgeFunction!\n");
@@ -1475,7 +1477,7 @@ void SlotMachine::purgeFunction() {
}
/// Get the slot number for a value. This function will assert if you
/// ask for a Value that hasn't previously been inserted with CreateSlot.
/// ask for a Value that hasn't previously been inserted with Create*Slot.
int SlotMachine::getSlot(const Value *V) {
assert(V && "Can't get slot for null Value");
assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
@@ -1535,17 +1537,35 @@ int SlotMachine::getSlot(const Value *V) {
}
/// CreateSlot - Create a new slot for the specified value if it has no name.
void SlotMachine::CreateSlot(const Value *V) {
/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
void SlotMachine::CreateModuleSlot(const GlobalValue *V) {
assert(!V->hasName() && "Doesn't need a slot!");
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) {
// If the module map's type plane is not for the Value's type
if (MI != mMap.end()) {
// Lookup the value in the module's map
ValueMap::const_iterator MVI = MI->second.map.find(V);
if (MVI != MI->second.map.end())
return;
}
return insertValue(V);
}
/// CreateSlot - Create a new slot for the specified value if it has no name.
void SlotMachine::CreateFunctionSlot(const Value *V) {
const Type *VTy = V->getType();
assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!");
assert(!isa<Constant>(V) && "Can't insert a Constants into SlotMachine");
// Look up the type plane for the Value's type from the module map
TypedPlanes::const_iterator MI = mMap.find(VTy);
// 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
@@ -1565,9 +1585,10 @@ void SlotMachine::CreateSlot(const Value *V) {
if (MVI != MI->second.map.end())
return;
return insertValue(V);
}
// Otherwise, there is no corresponding type plane in the function map yet.
// 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);
@@ -1584,20 +1605,6 @@ void SlotMachine::CreateSlot(const Value *V) {
return;
}
}
}
// N.B. Can only get here if TheFunction == 0
// If the module map's type plane is not for the Value's type
if (MI != mMap.end()) {
// Lookup the value in the module's map
ValueMap::const_iterator MVI = MI->second.map.find(V);
if (MVI != MI->second.map.end())
return;
}
return insertValue(V);
}
// Low level insert function. Minimal checking is done. This