mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-17 21:35:07 +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:
|
||||
|
||||
/// @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();
|
||||
unsigned DestSlot = mNext++;
|
||||
mMap[V] = DestSlot;
|
||||
|
||||
ValuePlane &PlaneMap = mMap[VTy];
|
||||
DestSlot = PlaneMap.map[V] = PlaneMap.next_slot++;
|
||||
|
||||
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=" <<
|
||||
|
Loading…
x
Reference in New Issue
Block a user