mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
split loads and calls into separate tables. Loads are now just indexed
by their pointer instead of using MemoryValue to wrap it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122731 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
03d49e955e
commit
85db61066a
@ -28,7 +28,8 @@ using namespace llvm;
|
|||||||
|
|
||||||
STATISTIC(NumSimplify, "Number of instructions simplified or DCE'd");
|
STATISTIC(NumSimplify, "Number of instructions simplified or DCE'd");
|
||||||
STATISTIC(NumCSE, "Number of instructions CSE'd");
|
STATISTIC(NumCSE, "Number of instructions CSE'd");
|
||||||
STATISTIC(NumCSEMem, "Number of load and call instructions CSE'd");
|
STATISTIC(NumCSELoad, "Number of load instructions CSE'd");
|
||||||
|
STATISTIC(NumCSECall, "Number of call instructions CSE'd");
|
||||||
|
|
||||||
static unsigned getHash(const void *V) {
|
static unsigned getHash(const void *V) {
|
||||||
return DenseMapInfo<const void*>::getHashValue(V);
|
return DenseMapInfo<const void*>::getHashValue(V);
|
||||||
@ -124,16 +125,16 @@ bool DenseMapInfo<SimpleValue>::isEqual(SimpleValue LHS, SimpleValue RHS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// MemoryValue
|
// CallValue
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// MemoryValue - Instances of this struct represent available load and call
|
/// CallValue - Instances of this struct represent available call values in
|
||||||
/// values in the scoped hash table.
|
/// the scoped hash table.
|
||||||
struct MemoryValue {
|
struct CallValue {
|
||||||
Instruction *Inst;
|
Instruction *Inst;
|
||||||
|
|
||||||
MemoryValue(Instruction *I) : Inst(I) {
|
CallValue(Instruction *I) : Inst(I) {
|
||||||
assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
|
assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +144,6 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool canHandle(Instruction *Inst) {
|
static bool canHandle(Instruction *Inst) {
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(Inst))
|
|
||||||
return !LI->isVolatile();
|
|
||||||
if (CallInst *CI = dyn_cast<CallInst>(Inst))
|
if (CallInst *CI = dyn_cast<CallInst>(Inst))
|
||||||
return CI->onlyReadsMemory();
|
return CI->onlyReadsMemory();
|
||||||
return false;
|
return false;
|
||||||
@ -153,23 +152,23 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
// MemoryValue is POD.
|
// CallValue is POD.
|
||||||
template<> struct isPodLike<MemoryValue> {
|
template<> struct isPodLike<CallValue> {
|
||||||
static const bool value = true;
|
static const bool value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct DenseMapInfo<MemoryValue> {
|
template<> struct DenseMapInfo<CallValue> {
|
||||||
static inline MemoryValue getEmptyKey() {
|
static inline CallValue getEmptyKey() {
|
||||||
return DenseMapInfo<Instruction*>::getEmptyKey();
|
return DenseMapInfo<Instruction*>::getEmptyKey();
|
||||||
}
|
}
|
||||||
static inline MemoryValue getTombstoneKey() {
|
static inline CallValue getTombstoneKey() {
|
||||||
return DenseMapInfo<Instruction*>::getTombstoneKey();
|
return DenseMapInfo<Instruction*>::getTombstoneKey();
|
||||||
}
|
}
|
||||||
static unsigned getHashValue(MemoryValue Val);
|
static unsigned getHashValue(CallValue Val);
|
||||||
static bool isEqual(MemoryValue LHS, MemoryValue RHS);
|
static bool isEqual(CallValue LHS, CallValue RHS);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
unsigned DenseMapInfo<MemoryValue>::getHashValue(MemoryValue Val) {
|
unsigned DenseMapInfo<CallValue>::getHashValue(CallValue Val) {
|
||||||
Instruction *Inst = Val.Inst;
|
Instruction *Inst = Val.Inst;
|
||||||
// Hash in all of the operands as pointers.
|
// Hash in all of the operands as pointers.
|
||||||
unsigned Res = 0;
|
unsigned Res = 0;
|
||||||
@ -179,13 +178,10 @@ unsigned DenseMapInfo<MemoryValue>::getHashValue(MemoryValue Val) {
|
|||||||
return (Res << 1) ^ Inst->getOpcode();
|
return (Res << 1) ^ Inst->getOpcode();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DenseMapInfo<MemoryValue>::isEqual(MemoryValue LHS, MemoryValue RHS) {
|
bool DenseMapInfo<CallValue>::isEqual(CallValue LHS, CallValue RHS) {
|
||||||
Instruction *LHSI = LHS.Inst, *RHSI = RHS.Inst;
|
Instruction *LHSI = LHS.Inst, *RHSI = RHS.Inst;
|
||||||
|
|
||||||
if (LHS.isSentinel() || RHS.isSentinel())
|
if (LHS.isSentinel() || RHS.isSentinel())
|
||||||
return LHSI == RHSI;
|
return LHSI == RHSI;
|
||||||
|
|
||||||
if (LHSI->getOpcode() != RHSI->getOpcode()) return false;
|
|
||||||
return LHSI->isIdenticalTo(RHSI);
|
return LHSI->isIdenticalTo(RHSI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,16 +214,20 @@ public:
|
|||||||
/// their lookup.
|
/// their lookup.
|
||||||
ScopedHTType *AvailableValues;
|
ScopedHTType *AvailableValues;
|
||||||
|
|
||||||
typedef ScopedHashTable<MemoryValue, std::pair<Value*, unsigned> > MemHTType;
|
/// AvailableLoads - This scoped hash table contains the current values
|
||||||
/// AvailableMemValues - This scoped hash table contains the current values of
|
/// of loads. This allows us to get efficient access to dominating loads when
|
||||||
/// loads and other read-only memory values. This allows us to get efficient
|
/// we have a fully redundant load. In addition to the most recent load, we
|
||||||
/// access to dominating loads we we find a fully redundant load. In addition
|
/// keep track of a generation count of the read, which is compared against
|
||||||
/// to the most recent load, we keep track of a generation count of the read,
|
/// the current generation count. The current generation count is
|
||||||
/// which is compared against the current generation count. The current
|
/// incremented after every possibly writing memory operation, which ensures
|
||||||
/// generation count is incremented after every possibly writing memory
|
/// that we only CSE loads with other loads that have no intervening store.
|
||||||
/// operation, which ensures that we only CSE loads with other loads that have
|
typedef ScopedHashTable<Value*, std::pair<Value*, unsigned> > LoadHTType;
|
||||||
/// no intervening store.
|
LoadHTType *AvailableLoads;
|
||||||
MemHTType *AvailableMemValues;
|
|
||||||
|
/// AvailableCalls - This scoped hash table contains the current values
|
||||||
|
/// of read-only call values. It uses the same generation count as loads.
|
||||||
|
typedef ScopedHashTable<CallValue, std::pair<Value*, unsigned> > CallHTType;
|
||||||
|
CallHTType *AvailableCalls;
|
||||||
|
|
||||||
/// CurrentGeneration - This is the current generation of the memory value.
|
/// CurrentGeneration - This is the current generation of the memory value.
|
||||||
unsigned CurrentGeneration;
|
unsigned CurrentGeneration;
|
||||||
@ -268,9 +268,13 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
|
|||||||
// off all the values we install.
|
// off all the values we install.
|
||||||
ScopedHTType::ScopeTy Scope(*AvailableValues);
|
ScopedHTType::ScopeTy Scope(*AvailableValues);
|
||||||
|
|
||||||
// Define a scope for the memory values so that anything we add will get
|
// Define a scope for the load values so that anything we add will get
|
||||||
// popped when we recurse back up to our parent domtree node.
|
// popped when we recurse back up to our parent domtree node.
|
||||||
MemHTType::ScopeTy MemScope(*AvailableMemValues);
|
LoadHTType::ScopeTy LoadScope(*AvailableLoads);
|
||||||
|
|
||||||
|
// Define a scope for the call values so that anything we add will get
|
||||||
|
// popped when we recurse back up to our parent domtree node.
|
||||||
|
CallHTType::ScopeTy CallScope(*AvailableCalls);
|
||||||
|
|
||||||
BasicBlock *BB = Node->getBlock();
|
BasicBlock *BB = Node->getBlock();
|
||||||
|
|
||||||
@ -327,23 +331,48 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a read-only memory value, process it.
|
// If this is a non-volatile load, process it.
|
||||||
if (MemoryValue::canHandle(Inst)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
|
||||||
// If we have an available version of this value, and if it is the right
|
// Ignore volatile loads.
|
||||||
|
if (LI->isVolatile()) continue;
|
||||||
|
|
||||||
|
// If we have an available version of this load, and if it is the right
|
||||||
// generation, replace this instruction.
|
// generation, replace this instruction.
|
||||||
std::pair<Value*, unsigned> InVal = AvailableMemValues->lookup(Inst);
|
std::pair<Value*, unsigned> InVal =
|
||||||
|
AvailableLoads->lookup(Inst->getOperand(0));
|
||||||
if (InVal.first != 0 && InVal.second == CurrentGeneration) {
|
if (InVal.first != 0 && InVal.second == CurrentGeneration) {
|
||||||
DEBUG(dbgs() << "EarlyCSE CSE MEM: " << *Inst << " to: "
|
DEBUG(dbgs() << "EarlyCSE CSE LOAD: " << *Inst << " to: "
|
||||||
<< *InVal.first << '\n');
|
<< *InVal.first << '\n');
|
||||||
if (!Inst->use_empty()) Inst->replaceAllUsesWith(InVal.first);
|
if (!Inst->use_empty()) Inst->replaceAllUsesWith(InVal.first);
|
||||||
Inst->eraseFromParent();
|
Inst->eraseFromParent();
|
||||||
Changed = true;
|
Changed = true;
|
||||||
++NumCSEMem;
|
++NumCSELoad;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, remember that we have this instruction.
|
// Otherwise, remember that we have this instruction.
|
||||||
AvailableMemValues->insert(Inst,
|
AvailableLoads->insert(Inst->getOperand(0),
|
||||||
|
std::pair<Value*, unsigned>(Inst, CurrentGeneration));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is a read-only call, process it.
|
||||||
|
if (CallValue::canHandle(Inst)) {
|
||||||
|
// If we have an available version of this call, and if it is the right
|
||||||
|
// generation, replace this instruction.
|
||||||
|
std::pair<Value*, unsigned> InVal = AvailableCalls->lookup(Inst);
|
||||||
|
if (InVal.first != 0 && InVal.second == CurrentGeneration) {
|
||||||
|
DEBUG(dbgs() << "EarlyCSE CSE CALL: " << *Inst << " to: "
|
||||||
|
<< *InVal.first << '\n');
|
||||||
|
if (!Inst->use_empty()) Inst->replaceAllUsesWith(InVal.first);
|
||||||
|
Inst->eraseFromParent();
|
||||||
|
Changed = true;
|
||||||
|
++NumCSECall;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, remember that we have this instruction.
|
||||||
|
AvailableCalls->insert(Inst,
|
||||||
std::pair<Value*, unsigned>(Inst, CurrentGeneration));
|
std::pair<Value*, unsigned>(Inst, CurrentGeneration));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -368,11 +397,14 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
|
|||||||
bool EarlyCSE::runOnFunction(Function &F) {
|
bool EarlyCSE::runOnFunction(Function &F) {
|
||||||
TD = getAnalysisIfAvailable<TargetData>();
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
DT = &getAnalysis<DominatorTree>();
|
DT = &getAnalysis<DominatorTree>();
|
||||||
|
|
||||||
|
// Tables that the pass uses when walking the domtree.
|
||||||
ScopedHTType AVTable;
|
ScopedHTType AVTable;
|
||||||
AvailableValues = &AVTable;
|
AvailableValues = &AVTable;
|
||||||
|
LoadHTType LoadTable;
|
||||||
MemHTType MemTable;
|
AvailableLoads = &LoadTable;
|
||||||
AvailableMemValues = &MemTable;
|
CallHTType CallTable;
|
||||||
|
AvailableCalls = &CallTable;
|
||||||
|
|
||||||
CurrentGeneration = 0;
|
CurrentGeneration = 0;
|
||||||
return processNode(DT->getRootNode());
|
return processNode(DT->getRootNode());
|
||||||
|
Loading…
Reference in New Issue
Block a user