summaryrefslogtreecommitdiff
path: root/lib/VMCore/AsmWriter.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-19 18:32:53 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-19 18:32:53 +0000
commit590b3c559fd7ca42e3d8c21e834481b0ff12c1a1 (patch)
tree6fa4ed2caf411b2f66d20e3be3e9d60bd5c440e6 /lib/VMCore/AsmWriter.cpp
parent2318ec67b833e78499e1f9cfa5b2da48a9655887 (diff)
downloadllvm-590b3c559fd7ca42e3d8c21e834481b0ff12c1a1.tar.gz
llvm-590b3c559fd7ca42e3d8c21e834481b0ff12c1a1.tar.bz2
llvm-590b3c559fd7ca42e3d8c21e834481b0ff12c1a1.tar.xz
For PR1258:
Radically simplify the SlotMachine. There is no need to keep Value planes around any more. This change causes slot numbering to number all un-named, non-void values starting at 0 and incrementing monotonically through the function, regardless of type (including BasicBlocks). Getting slot numbers is now a single lookup operation instead of a double lookup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35171 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/AsmWriter.cpp')
-rw-r--r--lib/VMCore/AsmWriter.cpp59
1 files changed, 20 insertions, 39 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 7c851f78fa..674e077a4f 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -48,17 +48,7 @@ class SlotMachine {
public:
/// @brief A mapping of Values to slot numbers
- typedef std::map<const Value*, unsigned> ValueMap;
-
- /// @brief A plane with next slot number and ValueMap
- struct ValuePlane {
- unsigned next_slot; ///< The next slot number to use
- ValueMap map; ///< The map of Value* -> unsigned
- ValuePlane() { next_slot = 0; } ///< Make sure we start at 0
- };
-
- /// @brief The map of planes by Type
- typedef std::map<const Type*, ValuePlane> TypedPlanes;
+ typedef std::map<const Value*,unsigned> ValueMap;
/// @}
/// @name Constructors
@@ -131,10 +121,12 @@ public:
bool FunctionProcessed;
/// @brief The TypePlanes map for the module level data
- TypedPlanes mMap;
+ ValueMap mMap;
+ unsigned mNext;
/// @brief The TypePlanes map for the function level data
- TypedPlanes fMap;
+ ValueMap fMap;
+ unsigned fNext;
/// @}
@@ -1385,6 +1377,7 @@ SlotMachine::SlotMachine(const Module *M)
: TheModule(M) ///< Saved for lazy initialization.
, TheFunction(0)
, FunctionProcessed(false)
+ , mMap(), mNext(0), fMap(), fNext(0)
{
}
@@ -1394,6 +1387,7 @@ SlotMachine::SlotMachine(const Function *F)
: TheModule(F ? F->getParent() : 0) ///< Saved for lazy initialization
, TheFunction(F) ///< Saved for lazy initialization
, FunctionProcessed(false)
+ , mMap(), mNext(0), fMap(), fNext(0)
{
}
@@ -1430,6 +1424,7 @@ void SlotMachine::processModule() {
// Process the arguments, basic blocks, and instructions of a function.
void SlotMachine::processFunction() {
SC_DEBUG("begin processFunction!\n");
+ fNext = 0;
// Add all the function arguments with no names.
for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
@@ -1471,12 +1466,10 @@ int SlotMachine::getGlobalSlot(const GlobalValue *V) {
initialize();
// Find the type plane in the module map
- TypedPlanes::const_iterator MI = mMap.find(V->getType());
+ ValueMap::const_iterator MI = mMap.find(V);
if (MI == mMap.end()) return -1;
-
- // Lookup the value in the module plane's map.
- ValueMap::const_iterator MVI = MI->second.map.find(V);
- return MVI != MI->second.map.end() ? int(MVI->second) : -1;
+
+ return MI->second;
}
@@ -1487,33 +1480,23 @@ int SlotMachine::getLocalSlot(const Value *V) {
// Check for uninitialized state and do lazy initialization.
initialize();
- // Get the type of the value
- const Type *VTy = V->getType();
-
- TypedPlanes::const_iterator FI = fMap.find(VTy);
+ ValueMap::const_iterator FI = fMap.find(V);
if (FI == fMap.end()) return -1;
- // Lookup the Value in the function and module maps.
- ValueMap::const_iterator FVI = FI->second.map.find(V);
-
- // If the value doesn't exist in the function map, it is a <badref>
- if (FVI == FI->second.map.end()) return -1;
-
- return FVI->second;
+ return FI->second;
}
/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
void SlotMachine::CreateModuleSlot(const GlobalValue *V) {
assert(V && "Can't insert a null Value into SlotMachine!");
+ assert(V->getType() != Type::VoidTy && "Doesn't need a slot!");
+ assert(!V->hasName() && "Doesn't need a slot!");
- unsigned DestSlot = 0;
- const Type *VTy = V->getType();
-
- ValuePlane &PlaneMap = mMap[VTy];
- DestSlot = PlaneMap.map[V] = PlaneMap.next_slot++;
+ unsigned DestSlot = mNext++;
+ mMap[V] = DestSlot;
- SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" <<
+ SC_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
DestSlot << " [");
// G = Global, F = Function, o = other
SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : 'F') << "]\n");
@@ -1525,10 +1508,8 @@ void SlotMachine::CreateFunctionSlot(const Value *V) {
const Type *VTy = V->getType();
assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!");
- unsigned DestSlot = 0;
-
- ValuePlane &PlaneMap = fMap[VTy];
- DestSlot = PlaneMap.map[V] = PlaneMap.next_slot++;
+ unsigned DestSlot = fNext++;
+ fMap[V] = DestSlot;
// G = Global, F = Function, o = other
SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" <<