mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-03 19:15:30 +00:00
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
This commit is contained in:
parent
2318ec67b8
commit
590b3c559f
@ -48,17 +48,7 @@ class SlotMachine {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/// @brief A mapping of Values to slot numbers
|
/// @brief A mapping of Values to slot numbers
|
||||||
typedef std::map<const Value*, unsigned> ValueMap;
|
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;
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Constructors
|
/// @name Constructors
|
||||||
@ -131,10 +121,12 @@ public:
|
|||||||
bool FunctionProcessed;
|
bool FunctionProcessed;
|
||||||
|
|
||||||
/// @brief The TypePlanes map for the module level data
|
/// @brief The TypePlanes map for the module level data
|
||||||
TypedPlanes mMap;
|
ValueMap mMap;
|
||||||
|
unsigned mNext;
|
||||||
|
|
||||||
/// @brief The TypePlanes map for the function level data
|
/// @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.
|
: TheModule(M) ///< Saved for lazy initialization.
|
||||||
, TheFunction(0)
|
, TheFunction(0)
|
||||||
, FunctionProcessed(false)
|
, 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
|
: TheModule(F ? F->getParent() : 0) ///< Saved for lazy initialization
|
||||||
, TheFunction(F) ///< Saved for lazy initialization
|
, TheFunction(F) ///< Saved for lazy initialization
|
||||||
, FunctionProcessed(false)
|
, 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.
|
// Process the arguments, basic blocks, and instructions of a function.
|
||||||
void SlotMachine::processFunction() {
|
void SlotMachine::processFunction() {
|
||||||
SC_DEBUG("begin processFunction!\n");
|
SC_DEBUG("begin processFunction!\n");
|
||||||
|
fNext = 0;
|
||||||
|
|
||||||
// Add all the function arguments with no names.
|
// Add all the function arguments with no names.
|
||||||
for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
|
for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
|
||||||
@ -1471,12 +1466,10 @@ int SlotMachine::getGlobalSlot(const GlobalValue *V) {
|
|||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
// Find the type plane in the module map
|
// 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;
|
if (MI == mMap.end()) return -1;
|
||||||
|
|
||||||
// Lookup the value in the module plane's map.
|
return MI->second;
|
||||||
ValueMap::const_iterator MVI = MI->second.map.find(V);
|
|
||||||
return MVI != MI->second.map.end() ? int(MVI->second) : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1487,33 +1480,23 @@ int SlotMachine::getLocalSlot(const Value *V) {
|
|||||||
// Check for uninitialized state and do lazy initialization.
|
// Check for uninitialized state and do lazy initialization.
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
// Get the type of the value
|
ValueMap::const_iterator FI = fMap.find(V);
|
||||||
const Type *VTy = V->getType();
|
|
||||||
|
|
||||||
TypedPlanes::const_iterator FI = fMap.find(VTy);
|
|
||||||
if (FI == fMap.end()) return -1;
|
if (FI == fMap.end()) return -1;
|
||||||
|
|
||||||
// Lookup the Value in the function and module maps.
|
return FI->second;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
|
/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
|
||||||
void SlotMachine::CreateModuleSlot(const GlobalValue *V) {
|
void SlotMachine::CreateModuleSlot(const GlobalValue *V) {
|
||||||
assert(V && "Can't insert a null Value into SlotMachine!");
|
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;
|
unsigned DestSlot = mNext++;
|
||||||
const Type *VTy = V->getType();
|
mMap[V] = DestSlot;
|
||||||
|
|
||||||
ValuePlane &PlaneMap = mMap[VTy];
|
SC_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
|
||||||
DestSlot = PlaneMap.map[V] = PlaneMap.next_slot++;
|
|
||||||
|
|
||||||
SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" <<
|
|
||||||
DestSlot << " [");
|
DestSlot << " [");
|
||||||
// G = Global, F = Function, o = other
|
// G = Global, F = Function, o = other
|
||||||
SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : 'F') << "]\n");
|
SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : 'F') << "]\n");
|
||||||
@ -1525,10 +1508,8 @@ void SlotMachine::CreateFunctionSlot(const Value *V) {
|
|||||||
const Type *VTy = V->getType();
|
const Type *VTy = V->getType();
|
||||||
assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!");
|
assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!");
|
||||||
|
|
||||||
unsigned DestSlot = 0;
|
unsigned DestSlot = fNext++;
|
||||||
|
fMap[V] = DestSlot;
|
||||||
ValuePlane &PlaneMap = fMap[VTy];
|
|
||||||
DestSlot = PlaneMap.map[V] = PlaneMap.next_slot++;
|
|
||||||
|
|
||||||
// G = Global, F = Function, o = other
|
// G = Global, F = Function, o = other
|
||||||
SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" <<
|
SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" <<
|
||||||
|
Loading…
x
Reference in New Issue
Block a user