summaryrefslogtreecommitdiff
path: root/lib/VMCore/AsmWriter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-01-09 07:55:49 +0000
committerChris Lattner <sabre@nondot.org>2007-01-09 07:55:49 +0000
commit9446bbe7d4099eb5b917519d458a07ca08270471 (patch)
tree41312afef44030bf5f682a2e8e22e70c1f6c1ed8 /lib/VMCore/AsmWriter.cpp
parent3a4621c5f6e406da75c15e1351e2df5a7a4d9297 (diff)
downloadllvm-9446bbe7d4099eb5b917519d458a07ca08270471.tar.gz
llvm-9446bbe7d4099eb5b917519d458a07ca08270471.tar.bz2
llvm-9446bbe7d4099eb5b917519d458a07ca08270471.tar.xz
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
Diffstat (limited to 'lib/VMCore/AsmWriter.cpp')
-rw-r--r--lib/VMCore/AsmWriter.cpp129
1 files changed, 68 insertions, 61 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 529dd1ac8b..6950a16aea 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -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,68 +1537,73 @@ int SlotMachine::getSlot(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();
+
+ // Look up the type plane for the Value's type from the module map
+ TypedPlanes::const_iterator MI = mMap.find(VTy);
+
+ // 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::CreateSlot(const Value *V) {
- const Type* VTy = V->getType();
+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) || isa<GlobalValue>(V) &&
- "Can't insert a non-GlobalValue Constant into SlotMachine");
+ 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);
- 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 exists in the function map, we're done.
- if (FVI != FI->second.map.end())
- return;
-
- // 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 found it, it was already inserted
- if (MVI != MI->second.map.end())
- return;
+ // 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 exists in the function map, we're done.
+ if (FVI != FI->second.map.end())
+ return;
+
+ // If there is no corresponding type plane in the module map
+ if (MI == mMap.end())
return insertValue(V);
-
- // 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 insertValue(V);
- else
- 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
+ // Look up the value in the module map
ValueMap::const_iterator MVI = MI->second.map.find(V);
+ // If we found it, it was already inserted
if (MVI != MI->second.map.end())
return;
+ return insertValue(V);
+ }
+
+ // Otherwise, there is no corresponding type plane in the function map yet.
+
+ // 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 insertValue(V);
+ else
+ return;
}
-
- return insertValue(V);
}