forked from OSchip/llvm-project
Rename IVUse to IVUsersOfOneStride, use a struct instead of a pair to
unify some parallel vectors and get field names more descriptive than "first" and "second". This isn't lisp afterall :) llvm-svn: 22633
This commit is contained in:
parent
84e9baa925
commit
430d0022df
|
@ -51,15 +51,30 @@ namespace {
|
||||||
std::map<Value *, GEPCache> Map;
|
std::map<Value *, GEPCache> Map;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IVUse {
|
/// IVStrideUse - Keep track of one use of a strided induction variable, where
|
||||||
/// Users - Keep track of all of the users of this stride as well as the
|
/// the stride is stored externally. The Offset member keeps track of the
|
||||||
/// initial value.
|
/// offset from the IV, User is the actual user of the operand, and 'Operand'
|
||||||
std::vector<std::pair<SCEVHandle, Instruction*> > Users;
|
/// is the operand # of the User that is the use.
|
||||||
std::vector<Instruction *> UserOperands;
|
struct IVStrideUse {
|
||||||
|
SCEVHandle Offset;
|
||||||
|
Instruction *User;
|
||||||
|
Value *OperandValToReplace;
|
||||||
|
|
||||||
void addUser(SCEVHandle &SH, Instruction *U, Instruction *V) {
|
IVStrideUse(const SCEVHandle &Offs, Instruction *U, Value *O)
|
||||||
Users.push_back(std::make_pair(SH, U));
|
: Offset(Offs), User(U), OperandValToReplace(O) {}
|
||||||
UserOperands.push_back(V);
|
};
|
||||||
|
|
||||||
|
/// IVUsersOfOneStride - This structure keeps track of all instructions that
|
||||||
|
/// have an operand that is based on the trip count multiplied by some stride.
|
||||||
|
/// The stride for all of these users is common and kept external to this
|
||||||
|
/// structure.
|
||||||
|
struct IVUsersOfOneStride {
|
||||||
|
/// Users - Keep track of all of the users of this stride as well as the
|
||||||
|
/// initial value and the operand that uses the IV.
|
||||||
|
std::vector<IVStrideUse> Users;
|
||||||
|
|
||||||
|
void addUser(const SCEVHandle &Offset,Instruction *User, Value *Operand) {
|
||||||
|
Users.push_back(IVStrideUse(Offset, User, Operand));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,7 +93,7 @@ namespace {
|
||||||
|
|
||||||
/// IVUsesByStride - Keep track of all uses of induction variables that we
|
/// IVUsesByStride - Keep track of all uses of induction variables that we
|
||||||
/// are interested in. The key of the map is the stride of the access.
|
/// are interested in. The key of the map is the stride of the access.
|
||||||
std::map<Value*, IVUse> IVUsesByStride;
|
std::map<Value*, IVUsersOfOneStride> IVUsesByStride;
|
||||||
|
|
||||||
/// CastedBasePointers - As we need to lower getelementptr instructions, we
|
/// CastedBasePointers - As we need to lower getelementptr instructions, we
|
||||||
/// cast the pointer input to uintptr_t. This keeps track of the casted
|
/// cast the pointer input to uintptr_t. This keeps track of the casted
|
||||||
|
@ -120,8 +135,8 @@ namespace {
|
||||||
void AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP, Instruction *I,
|
void AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP, Instruction *I,
|
||||||
Loop *L);
|
Loop *L);
|
||||||
|
|
||||||
void StrengthReduceStridedIVUsers(Value *Stride, IVUse &Uses, Loop *L,
|
void StrengthReduceStridedIVUsers(Value *Stride, IVUsersOfOneStride &Uses,
|
||||||
bool isOnlyStride);
|
Loop *L, bool isOnlyStride);
|
||||||
|
|
||||||
void strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L,
|
void strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L,
|
||||||
GEPCache* GEPCache,
|
GEPCache* GEPCache,
|
||||||
|
@ -339,7 +354,6 @@ void LoopStrengthReduce::AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP,
|
||||||
DEBUG(std::cerr << "FOUND USER: " << *User
|
DEBUG(std::cerr << "FOUND USER: " << *User
|
||||||
<< " OF STRIDE: " << *Step << " BASE = " << *Base << "\n");
|
<< " OF STRIDE: " << *Step << " BASE = " << *Base << "\n");
|
||||||
|
|
||||||
|
|
||||||
// Okay, we found a user that we cannot reduce. Analyze the instruction
|
// Okay, we found a user that we cannot reduce. Analyze the instruction
|
||||||
// and decide what to do with it.
|
// and decide what to do with it.
|
||||||
IVUsesByStride[Step].addUser(Base, User, GEP);
|
IVUsesByStride[Step].addUser(Base, User, GEP);
|
||||||
|
@ -410,8 +424,9 @@ namespace {
|
||||||
/// Inst - The instruction using the induction variable.
|
/// Inst - The instruction using the induction variable.
|
||||||
Instruction *Inst;
|
Instruction *Inst;
|
||||||
|
|
||||||
/// Op - The value to replace with the EmittedBase.
|
/// OperandValToReplace - The operand value of Inst to replace with the
|
||||||
Value *Op;
|
/// EmittedBase.
|
||||||
|
Value *OperandValToReplace;
|
||||||
|
|
||||||
/// Imm - The immediate value that should be added to the base immediately
|
/// Imm - The immediate value that should be added to the base immediately
|
||||||
/// before Inst, because it will be folded into the imm field of the
|
/// before Inst, because it will be folded into the imm field of the
|
||||||
|
@ -422,8 +437,8 @@ namespace {
|
||||||
/// operation. This is null if we should just use zero so far.
|
/// operation. This is null if we should just use zero so far.
|
||||||
Value *EmittedBase;
|
Value *EmittedBase;
|
||||||
|
|
||||||
BasedUser(Instruction *I, Value *V, const SCEVHandle &IMM)
|
BasedUser(Instruction *I, Value *Op, const SCEVHandle &IMM)
|
||||||
: Inst(I), Op(V), Imm(IMM), EmittedBase(0) {}
|
: Inst(I), OperandValToReplace(Op), Imm(IMM), EmittedBase(0) {}
|
||||||
|
|
||||||
|
|
||||||
// No need to compare these.
|
// No need to compare these.
|
||||||
|
@ -490,7 +505,8 @@ static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress) {
|
||||||
/// stride of IV. All of the users may have different starting values, and this
|
/// stride of IV. All of the users may have different starting values, and this
|
||||||
/// may not be the only stride (we know it is if isOnlyStride is true).
|
/// may not be the only stride (we know it is if isOnlyStride is true).
|
||||||
void LoopStrengthReduce::StrengthReduceStridedIVUsers(Value *Stride,
|
void LoopStrengthReduce::StrengthReduceStridedIVUsers(Value *Stride,
|
||||||
IVUse &Uses, Loop *L,
|
IVUsersOfOneStride &Uses,
|
||||||
|
Loop *L,
|
||||||
bool isOnlyStride) {
|
bool isOnlyStride) {
|
||||||
// Transform our list of users and offsets to a bit more complex table. In
|
// Transform our list of users and offsets to a bit more complex table. In
|
||||||
// this new vector, the first entry for each element is the base of the
|
// this new vector, the first entry for each element is the base of the
|
||||||
|
@ -501,12 +517,12 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(Value *Stride,
|
||||||
UsersToProcess.reserve(Uses.Users.size());
|
UsersToProcess.reserve(Uses.Users.size());
|
||||||
|
|
||||||
SCEVHandle ZeroBase = SCEVUnknown::getIntegerSCEV(0,
|
SCEVHandle ZeroBase = SCEVUnknown::getIntegerSCEV(0,
|
||||||
Uses.Users[0].first->getType());
|
Uses.Users[0].Offset->getType());
|
||||||
|
|
||||||
for (unsigned i = 0, e = Uses.Users.size(); i != e; ++i)
|
for (unsigned i = 0, e = Uses.Users.size(); i != e; ++i)
|
||||||
UsersToProcess.push_back(std::make_pair(Uses.Users[i].first,
|
UsersToProcess.push_back(std::make_pair(Uses.Users[i].Offset,
|
||||||
BasedUser(Uses.Users[i].second,
|
BasedUser(Uses.Users[i].User,
|
||||||
Uses.UserOperands[i],
|
Uses.Users[i].OperandValToReplace,
|
||||||
ZeroBase)));
|
ZeroBase)));
|
||||||
|
|
||||||
// First pass, figure out what we can represent in the immediate fields of
|
// First pass, figure out what we can represent in the immediate fields of
|
||||||
|
@ -547,7 +563,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(Value *Stride,
|
||||||
|
|
||||||
while (!UsersToProcess.empty()) {
|
while (!UsersToProcess.empty()) {
|
||||||
// Create a new Phi for this base, and stick it in the loop header.
|
// Create a new Phi for this base, and stick it in the loop header.
|
||||||
Value *Replaced = UsersToProcess.front().second.Op;
|
Value *Replaced = UsersToProcess.front().second.OperandValToReplace;
|
||||||
const Type *ReplacedTy = Replaced->getType();
|
const Type *ReplacedTy = Replaced->getType();
|
||||||
PHINode *NewPHI = new PHINode(ReplacedTy, Replaced->getName()+".str",
|
PHINode *NewPHI = new PHINode(ReplacedTy, Replaced->getName()+".str",
|
||||||
PhiInsertBefore);
|
PhiInsertBefore);
|
||||||
|
@ -630,8 +646,8 @@ void LoopStrengthReduce::runOnLoop(Loop *L) {
|
||||||
// If we only have one stride, we can more aggressively eliminate some things.
|
// If we only have one stride, we can more aggressively eliminate some things.
|
||||||
bool HasOneStride = IVUsesByStride.size() == 1;
|
bool HasOneStride = IVUsesByStride.size() == 1;
|
||||||
|
|
||||||
for (std::map<Value*, IVUse>::iterator SI = IVUsesByStride.begin(),
|
for (std::map<Value*, IVUsersOfOneStride>::iterator SI
|
||||||
E = IVUsesByStride.end(); SI != E; ++SI)
|
= IVUsesByStride.begin(), E = IVUsesByStride.end(); SI != E; ++SI)
|
||||||
StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride);
|
StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride);
|
||||||
|
|
||||||
// Clean up after ourselves
|
// Clean up after ourselves
|
||||||
|
|
Loading…
Reference in New Issue