2009-05-12 04:17:14 +02:00
|
|
|
//===- llvm/Analysis/IVUsers.h - Induction Variable Users -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements bookkeeping for "interesting" users of expressions
|
|
|
|
// computed from induction variables.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_IVUSERS_H
|
|
|
|
#define LLVM_ANALYSIS_IVUSERS_H
|
|
|
|
|
|
|
|
#include "llvm/Analysis/LoopPass.h"
|
2016-08-09 02:28:52 +02:00
|
|
|
#include "llvm/Analysis/LoopPassManager.h"
|
2010-04-08 00:27:08 +02:00
|
|
|
#include "llvm/Analysis/ScalarEvolutionNormalization.h"
|
2014-03-04 12:17:44 +01:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2009-05-12 04:17:14 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-07-13 05:28:53 +02:00
|
|
|
class AssumptionCache;
|
2009-05-12 04:17:14 +02:00
|
|
|
class DominatorTree;
|
|
|
|
class Instruction;
|
|
|
|
class Value;
|
2010-02-12 11:34:29 +01:00
|
|
|
class ScalarEvolution;
|
|
|
|
class SCEV;
|
2010-04-08 00:27:08 +02:00
|
|
|
class IVUsers;
|
2012-10-08 18:38:25 +02:00
|
|
|
class DataLayout;
|
2010-02-12 11:34:29 +01:00
|
|
|
|
|
|
|
/// IVStrideUse - Keep track of one use of a strided induction variable.
|
|
|
|
/// The Expr member keeps track of the expression, User is the actual user
|
|
|
|
/// instruction of the operand, and 'OperandValToReplace' is the operand of
|
|
|
|
/// the User that is the use.
|
2015-08-04 00:30:24 +02:00
|
|
|
class IVStrideUse final : public CallbackVH, public ilist_node<IVStrideUse> {
|
2010-04-08 00:27:08 +02:00
|
|
|
friend class IVUsers;
|
2009-05-12 04:17:14 +02:00
|
|
|
public:
|
2011-06-21 17:43:52 +02:00
|
|
|
IVStrideUse(IVUsers *P, Instruction* U, Value *O)
|
|
|
|
: CallbackVH(U), Parent(P), OperandValToReplace(O) {
|
2009-05-12 04:17:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getUser - Return the user instruction for this use.
|
|
|
|
Instruction *getUser() const {
|
|
|
|
return cast<Instruction>(getValPtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setUser - Assign a new user instruction for this use.
|
|
|
|
void setUser(Instruction *NewUser) {
|
|
|
|
setValPtr(NewUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOperandValToReplace - Return the Value of the operand in the user
|
|
|
|
/// instruction that this IVStrideUse is representing.
|
|
|
|
Value *getOperandValToReplace() const {
|
|
|
|
return OperandValToReplace;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setOperandValToReplace - Assign a new Value as the operand value
|
|
|
|
/// to replace.
|
|
|
|
void setOperandValToReplace(Value *Op) {
|
|
|
|
OperandValToReplace = Op;
|
|
|
|
}
|
|
|
|
|
2010-04-08 00:27:08 +02:00
|
|
|
/// getPostIncLoops - Return the set of loops for which the expression has
|
|
|
|
/// been adjusted to use post-inc mode.
|
|
|
|
const PostIncLoopSet &getPostIncLoops() const {
|
|
|
|
return PostIncLoops;
|
2009-05-12 04:17:14 +02:00
|
|
|
}
|
|
|
|
|
2010-04-08 00:27:08 +02:00
|
|
|
/// transformToPostInc - Transform the expression to post-inc form for the
|
|
|
|
/// given loop.
|
|
|
|
void transformToPostInc(const Loop *L);
|
2009-05-12 04:17:14 +02:00
|
|
|
|
|
|
|
private:
|
2010-02-12 11:34:29 +01:00
|
|
|
/// Parent - a pointer to the IVUsers that owns this IVStrideUse.
|
|
|
|
IVUsers *Parent;
|
|
|
|
|
2009-05-12 04:17:14 +02:00
|
|
|
/// OperandValToReplace - The Value of the operand in the user instruction
|
|
|
|
/// that this IVStrideUse is representing.
|
|
|
|
WeakVH OperandValToReplace;
|
|
|
|
|
2010-04-08 00:27:08 +02:00
|
|
|
/// PostIncLoops - The set of loops for which Expr has been adjusted to
|
|
|
|
/// use post-inc mode. This corresponds with SCEVExpander's post-inc concept.
|
|
|
|
PostIncLoopSet PostIncLoops;
|
2009-05-12 04:17:14 +02:00
|
|
|
|
|
|
|
/// Deleted - Implementation of CallbackVH virtual function to
|
2010-03-01 18:49:51 +01:00
|
|
|
/// receive notification when the User is deleted.
|
2014-03-05 08:30:04 +01:00
|
|
|
void deleted() override;
|
2009-05-12 04:17:14 +02:00
|
|
|
};
|
|
|
|
|
2016-08-12 17:00:55 +02:00
|
|
|
template <>
|
|
|
|
struct ilist_sentinel_traits<IVStrideUse>
|
|
|
|
: public ilist_embedded_sentinel_traits<IVStrideUse> {};
|
2009-05-12 04:17:14 +02:00
|
|
|
|
2016-07-17 00:51:33 +02:00
|
|
|
class IVUsers {
|
2010-02-12 11:34:29 +01:00
|
|
|
friend class IVStrideUse;
|
2009-05-12 04:17:14 +02:00
|
|
|
Loop *L;
|
2015-07-13 05:28:53 +02:00
|
|
|
AssumptionCache *AC;
|
2009-05-12 04:17:14 +02:00
|
|
|
LoopInfo *LI;
|
|
|
|
DominatorTree *DT;
|
|
|
|
ScalarEvolution *SE;
|
2015-07-13 05:28:53 +02:00
|
|
|
SmallPtrSet<Instruction*, 16> Processed;
|
2009-05-12 04:17:14 +02:00
|
|
|
|
|
|
|
/// IVUses - A list of all tracked IV uses of induction variable expressions
|
|
|
|
/// we are interested in.
|
2010-02-12 11:34:29 +01:00
|
|
|
ilist<IVStrideUse> IVUses;
|
2009-05-12 04:17:14 +02:00
|
|
|
|
2015-07-13 05:28:53 +02:00
|
|
|
// Ephemeral values used by @llvm.assume in this function.
|
|
|
|
SmallPtrSet<const Value *, 32> EphValues;
|
|
|
|
|
2009-05-12 04:17:14 +02:00
|
|
|
public:
|
2016-07-17 00:51:33 +02:00
|
|
|
IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI, DominatorTree *DT,
|
|
|
|
ScalarEvolution *SE);
|
2009-05-12 04:17:14 +02:00
|
|
|
|
2011-08-10 05:46:27 +02:00
|
|
|
Loop *getLoop() const { return L; }
|
|
|
|
|
2010-09-01 03:45:53 +02:00
|
|
|
/// AddUsersIfInteresting - Inspect the specified Instruction. If it is a
|
|
|
|
/// reducible SCEV, recursively add its users to the IVUsesByStride set and
|
|
|
|
/// return true. Otherwise, return false.
|
2012-03-22 18:47:33 +01:00
|
|
|
bool AddUsersIfInteresting(Instruction *I);
|
2009-05-12 04:17:14 +02:00
|
|
|
|
2011-06-21 17:43:52 +02:00
|
|
|
IVStrideUse &AddUser(Instruction *User, Value *Operand);
|
2009-11-12 08:35:05 +01:00
|
|
|
|
2009-05-12 04:17:14 +02:00
|
|
|
/// getReplacementExpr - Return a SCEV expression which computes the
|
|
|
|
/// value of the OperandValToReplace of the given IVStrideUse.
|
2010-04-19 23:48:58 +02:00
|
|
|
const SCEV *getReplacementExpr(const IVStrideUse &IU) const;
|
|
|
|
|
|
|
|
/// getExpr - Return the expression for the use.
|
|
|
|
const SCEV *getExpr(const IVStrideUse &IU) const;
|
|
|
|
|
|
|
|
const SCEV *getStride(const IVStrideUse &IU, const Loop *L) const;
|
2009-05-12 04:17:14 +02:00
|
|
|
|
2010-02-12 11:34:29 +01:00
|
|
|
typedef ilist<IVStrideUse>::iterator iterator;
|
|
|
|
typedef ilist<IVStrideUse>::const_iterator const_iterator;
|
|
|
|
iterator begin() { return IVUses.begin(); }
|
|
|
|
iterator end() { return IVUses.end(); }
|
|
|
|
const_iterator begin() const { return IVUses.begin(); }
|
|
|
|
const_iterator end() const { return IVUses.end(); }
|
|
|
|
bool empty() const { return IVUses.empty(); }
|
|
|
|
|
2012-01-06 22:41:55 +01:00
|
|
|
bool isIVUserOrOperand(Instruction *Inst) const {
|
|
|
|
return Processed.count(Inst);
|
|
|
|
}
|
|
|
|
|
2016-07-17 00:51:33 +02:00
|
|
|
void releaseMemory();
|
|
|
|
|
|
|
|
void print(raw_ostream &OS, const Module * = nullptr) const;
|
2009-05-12 04:17:14 +02:00
|
|
|
|
|
|
|
/// dump - This method is used for debugging.
|
|
|
|
void dump() const;
|
2016-07-17 00:51:33 +02:00
|
|
|
|
2012-03-22 18:47:33 +01:00
|
|
|
protected:
|
2014-08-21 07:55:13 +02:00
|
|
|
bool AddUsersImpl(Instruction *I, SmallPtrSetImpl<Loop*> &SimpleLoopNests);
|
2009-05-12 04:17:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Pass *createIVUsersPass();
|
|
|
|
|
2016-07-17 00:51:33 +02:00
|
|
|
class IVUsersWrapperPass : public LoopPass {
|
|
|
|
std::unique_ptr<IVUsers> IU;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
IVUsersWrapperPass();
|
|
|
|
|
|
|
|
IVUsers &getIU() { return *IU; }
|
|
|
|
const IVUsers &getIU() const { return *IU; }
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
|
|
|
|
bool runOnLoop(Loop *L, LPPassManager &LPM) override;
|
|
|
|
|
|
|
|
void releaseMemory() override;
|
|
|
|
|
|
|
|
void print(raw_ostream &OS, const Module * = nullptr) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Analysis pass that exposes the \c IVUsers for a loop.
|
|
|
|
class IVUsersAnalysis : public AnalysisInfoMixin<IVUsersAnalysis> {
|
|
|
|
friend AnalysisInfoMixin<IVUsersAnalysis>;
|
|
|
|
static char PassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef IVUsers Result;
|
|
|
|
|
2016-08-09 02:28:52 +02:00
|
|
|
IVUsers run(Loop &L, LoopAnalysisManager &AM);
|
2016-07-17 00:51:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Printer pass for the \c IVUsers for a loop.
|
|
|
|
class IVUsersPrinterPass : public PassInfoMixin<IVUsersPrinterPass> {
|
|
|
|
raw_ostream &OS;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit IVUsersPrinterPass(raw_ostream &OS) : OS(OS) {}
|
2016-08-09 02:28:52 +02:00
|
|
|
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM);
|
2016-07-17 00:51:33 +02:00
|
|
|
};
|
2015-06-23 11:49:53 +02:00
|
|
|
}
|
2009-05-12 04:17:14 +02:00
|
|
|
|
|
|
|
#endif
|