mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 06:30:16 +00:00
Switch an assortment of maps, sets and vectors to more efficient versions,
patch contributed by m-s! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55270 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
62ca32540f
commit
cf712dee93
@ -36,6 +36,7 @@
|
|||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/InstVisitor.h"
|
#include "llvm/Support/InstVisitor.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
|
#include "llvm/ADT/DenseSet.h"
|
||||||
#include "llvm/ADT/SmallSet.h"
|
#include "llvm/ADT/SmallSet.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
@ -137,7 +138,7 @@ public:
|
|||||||
/// Constant Propagation.
|
/// Constant Propagation.
|
||||||
///
|
///
|
||||||
class SCCPSolver : public InstVisitor<SCCPSolver> {
|
class SCCPSolver : public InstVisitor<SCCPSolver> {
|
||||||
SmallSet<BasicBlock*, 16> BBExecutable;// The basic blocks that are executable
|
DenseSet<BasicBlock*> BBExecutable;// The basic blocks that are executable
|
||||||
std::map<Value*, LatticeVal> ValueState; // The state each value is in.
|
std::map<Value*, LatticeVal> ValueState; // The state each value is in.
|
||||||
|
|
||||||
/// GlobalValue - If we are tracking any values for the contents of a global
|
/// GlobalValue - If we are tracking any values for the contents of a global
|
||||||
@ -153,7 +154,7 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
|
|||||||
|
|
||||||
/// TrackedMultipleRetVals - Same as TrackedRetVals, but used for functions
|
/// TrackedMultipleRetVals - Same as TrackedRetVals, but used for functions
|
||||||
/// that return multiple values.
|
/// that return multiple values.
|
||||||
std::map<std::pair<Function*, unsigned>, LatticeVal> TrackedMultipleRetVals;
|
DenseMap<std::pair<Function*, unsigned>, LatticeVal> TrackedMultipleRetVals;
|
||||||
|
|
||||||
// The reason for two worklists is that overdefined is the lowest state
|
// The reason for two worklists is that overdefined is the lowest state
|
||||||
// on the lattice, and moving things to overdefined as fast as possible
|
// on the lattice, and moving things to overdefined as fast as possible
|
||||||
@ -161,11 +162,11 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
|
|||||||
// By having a separate worklist, we accomplish this because everything
|
// By having a separate worklist, we accomplish this because everything
|
||||||
// possibly overdefined will become overdefined at the soonest possible
|
// possibly overdefined will become overdefined at the soonest possible
|
||||||
// point.
|
// point.
|
||||||
std::vector<Value*> OverdefinedInstWorkList;
|
SmallVector<Value*, 64> OverdefinedInstWorkList;
|
||||||
std::vector<Value*> InstWorkList;
|
SmallVector<Value*, 64> InstWorkList;
|
||||||
|
|
||||||
|
|
||||||
std::vector<BasicBlock*> BBWorkList; // The BasicBlock work list
|
SmallVector<BasicBlock*, 64> BBWorkList; // The BasicBlock work list
|
||||||
|
|
||||||
/// UsersOfOverdefinedPHIs - Keep track of any users of PHI nodes that are not
|
/// UsersOfOverdefinedPHIs - Keep track of any users of PHI nodes that are not
|
||||||
/// overdefined, despite the fact that the PHI node is overdefined.
|
/// overdefined, despite the fact that the PHI node is overdefined.
|
||||||
@ -174,7 +175,7 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
|
|||||||
/// KnownFeasibleEdges - Entries in this set are edges which have already had
|
/// KnownFeasibleEdges - Entries in this set are edges which have already had
|
||||||
/// PHI nodes retriggered.
|
/// PHI nodes retriggered.
|
||||||
typedef std::pair<BasicBlock*, BasicBlock*> Edge;
|
typedef std::pair<BasicBlock*, BasicBlock*> Edge;
|
||||||
std::set<Edge> KnownFeasibleEdges;
|
DenseSet<Edge> KnownFeasibleEdges;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// MarkBlockExecutable - This method can be used by clients to mark all of
|
/// MarkBlockExecutable - This method can be used by clients to mark all of
|
||||||
@ -225,7 +226,7 @@ public:
|
|||||||
|
|
||||||
/// getExecutableBlocks - Once we have solved for constants, return the set of
|
/// getExecutableBlocks - Once we have solved for constants, return the set of
|
||||||
/// blocks that is known to be executable.
|
/// blocks that is known to be executable.
|
||||||
SmallSet<BasicBlock*, 16> &getExecutableBlocks() {
|
DenseSet<BasicBlock*> &getExecutableBlocks() {
|
||||||
return BBExecutable;
|
return BBExecutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,7 +574,7 @@ void SCCPSolver::visitPHINode(PHINode &PN) {
|
|||||||
|
|
||||||
if (isEdgeFeasible(PN.getIncomingBlock(i), PN.getParent())) {
|
if (isEdgeFeasible(PN.getIncomingBlock(i), PN.getParent())) {
|
||||||
if (IV.isOverdefined()) { // PHI node becomes overdefined!
|
if (IV.isOverdefined()) { // PHI node becomes overdefined!
|
||||||
markOverdefined(PNIV, &PN);
|
markOverdefined(&PN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,7 +590,7 @@ void SCCPSolver::visitPHINode(PHINode &PN) {
|
|||||||
// Yes there is. This means the PHI node is not constant.
|
// Yes there is. This means the PHI node is not constant.
|
||||||
// You must be overdefined poor PHI.
|
// You must be overdefined poor PHI.
|
||||||
//
|
//
|
||||||
markOverdefined(PNIV, &PN); // The PHI node now becomes overdefined
|
markOverdefined(&PN); // The PHI node now becomes overdefined
|
||||||
return; // I'm done analyzing you
|
return; // I'm done analyzing you
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -602,7 +603,7 @@ void SCCPSolver::visitPHINode(PHINode &PN) {
|
|||||||
// this is the case, the PHI remains undefined.
|
// this is the case, the PHI remains undefined.
|
||||||
//
|
//
|
||||||
if (OperandVal)
|
if (OperandVal)
|
||||||
markConstant(PNIV, &PN, OperandVal); // Acquire operand value
|
markConstant(&PN, OperandVal); // Acquire operand value
|
||||||
}
|
}
|
||||||
|
|
||||||
void SCCPSolver::visitReturnInst(ReturnInst &I) {
|
void SCCPSolver::visitReturnInst(ReturnInst &I) {
|
||||||
@ -627,7 +628,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
|
|||||||
// Handle functions that return multiple values.
|
// Handle functions that return multiple values.
|
||||||
if (!TrackedMultipleRetVals.empty() && I.getNumOperands() > 1) {
|
if (!TrackedMultipleRetVals.empty() && I.getNumOperands() > 1) {
|
||||||
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
|
||||||
std::map<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
||||||
It = TrackedMultipleRetVals.find(std::make_pair(F, i));
|
It = TrackedMultipleRetVals.find(std::make_pair(F, i));
|
||||||
if (It == TrackedMultipleRetVals.end()) break;
|
if (It == TrackedMultipleRetVals.end()) break;
|
||||||
mergeInValue(It->second, F, getValueState(I.getOperand(i)));
|
mergeInValue(It->second, F, getValueState(I.getOperand(i)));
|
||||||
@ -637,7 +638,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
|
|||||||
isa<StructType>(I.getOperand(0)->getType())) {
|
isa<StructType>(I.getOperand(0)->getType())) {
|
||||||
for (unsigned i = 0, e = I.getOperand(0)->getType()->getNumContainedTypes();
|
for (unsigned i = 0, e = I.getOperand(0)->getType()->getNumContainedTypes();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
std::map<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
||||||
It = TrackedMultipleRetVals.find(std::make_pair(F, i));
|
It = TrackedMultipleRetVals.find(std::make_pair(F, i));
|
||||||
if (It == TrackedMultipleRetVals.end()) break;
|
if (It == TrackedMultipleRetVals.end()) break;
|
||||||
Value *Val = FindInsertedValue(I.getOperand(0), i);
|
Value *Val = FindInsertedValue(I.getOperand(0), i);
|
||||||
@ -694,13 +695,9 @@ void SCCPSolver::visitExtractValueInst(ExtractValueInst &EVI) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if we are tracking the result of the callee.
|
// See if we are tracking the result of the callee. If not tracking this
|
||||||
std::map<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
// function (for example, it is a declaration) just move to overdefined.
|
||||||
It = TrackedMultipleRetVals.find(std::make_pair(F, *EVI.idx_begin()));
|
if (!TrackedMultipleRetVals.count(std::make_pair(F, *EVI.idx_begin()))) {
|
||||||
|
|
||||||
// If not tracking this function (for example, it is a declaration) just move
|
|
||||||
// to overdefined.
|
|
||||||
if (It == TrackedMultipleRetVals.end()) {
|
|
||||||
markOverdefined(&EVI);
|
markOverdefined(&EVI);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -742,7 +739,7 @@ void SCCPSolver::visitInsertValueInst(InsertValueInst &IVI) {
|
|||||||
|
|
||||||
// See if we are tracking the result of the callee.
|
// See if we are tracking the result of the callee.
|
||||||
Function *F = IVI.getParent()->getParent();
|
Function *F = IVI.getParent()->getParent();
|
||||||
std::map<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
||||||
It = TrackedMultipleRetVals.find(std::make_pair(F, *IVI.idx_begin()));
|
It = TrackedMultipleRetVals.find(std::make_pair(F, *IVI.idx_begin()));
|
||||||
|
|
||||||
// Merge in the inserted member value.
|
// Merge in the inserted member value.
|
||||||
@ -1220,7 +1217,7 @@ CallOverdefined:
|
|||||||
} else if (isa<StructType>(I->getType())) {
|
} else if (isa<StructType>(I->getType())) {
|
||||||
// Check to see if we're tracking this callee, if not, handle it in the
|
// Check to see if we're tracking this callee, if not, handle it in the
|
||||||
// common path above.
|
// common path above.
|
||||||
std::map<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
DenseMap<std::pair<Function*, unsigned>, LatticeVal>::iterator
|
||||||
TMRVI = TrackedMultipleRetVals.find(std::make_pair(F, 0));
|
TMRVI = TrackedMultipleRetVals.find(std::make_pair(F, 0));
|
||||||
if (TMRVI == TrackedMultipleRetVals.end())
|
if (TMRVI == TrackedMultipleRetVals.end())
|
||||||
goto CallOverdefined;
|
goto CallOverdefined;
|
||||||
@ -1553,8 +1550,8 @@ bool SCCP::runOnFunction(Function &F) {
|
|||||||
// delete their contents now. Note that we cannot actually delete the blocks,
|
// delete their contents now. Note that we cannot actually delete the blocks,
|
||||||
// as we cannot modify the CFG of the function.
|
// as we cannot modify the CFG of the function.
|
||||||
//
|
//
|
||||||
SmallSet<BasicBlock*, 16> &ExecutableBBs = Solver.getExecutableBlocks();
|
DenseSet<BasicBlock*> &ExecutableBBs = Solver.getExecutableBlocks();
|
||||||
SmallVector<Instruction*, 32> Insts;
|
SmallVector<Instruction*, 512> Insts;
|
||||||
std::map<Value*, LatticeVal> &Values = Solver.getValueMapping();
|
std::map<Value*, LatticeVal> &Values = Solver.getValueMapping();
|
||||||
|
|
||||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
@ -1698,9 +1695,9 @@ bool IPSCCP::runOnModule(Module &M) {
|
|||||||
// Iterate over all of the instructions in the module, replacing them with
|
// Iterate over all of the instructions in the module, replacing them with
|
||||||
// constants if we have found them to be of constant values.
|
// constants if we have found them to be of constant values.
|
||||||
//
|
//
|
||||||
SmallSet<BasicBlock*, 16> &ExecutableBBs = Solver.getExecutableBlocks();
|
DenseSet<BasicBlock*> &ExecutableBBs = Solver.getExecutableBlocks();
|
||||||
SmallVector<Instruction*, 32> Insts;
|
SmallVector<Instruction*, 512> Insts;
|
||||||
SmallVector<BasicBlock*, 32> BlocksToErase;
|
SmallVector<BasicBlock*, 512> BlocksToErase;
|
||||||
std::map<Value*, LatticeVal> &Values = Solver.getValueMapping();
|
std::map<Value*, LatticeVal> &Values = Solver.getValueMapping();
|
||||||
|
|
||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user