14 #define DEBUG_TYPE "ppc-loop-data-prefetch"
44 cl::desc(
"Prefetch write addresses"));
50 cl::desc(
"The loop prefetch distance"));
54 cl::desc(
"The loop prefetch cache line size"));
82 bool runOnLoop(
Loop *L);
95 "PPC Loop Data Prefetch",
false,
false)
105 bool PPCLoopDataPrefetch::runOnFunction(
Function &
F) {
106 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
107 SE = &getAnalysis<ScalarEvolution>();
109 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
110 TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
112 bool MadeChange =
false;
114 for (
auto I = LI->begin(),
IE = LI->end();
I !=
IE; ++
I)
116 MadeChange |= runOnLoop(*L);
121 bool PPCLoopDataPrefetch::runOnLoop(
Loop *L) {
122 bool MadeChange =
false;
140 if (
CallInst *CI = dyn_cast<CallInst>(J))
141 if (
Function *F = CI->getCalledFunction())
147 unsigned LoopSize = Metrics.
NumInsts;
151 unsigned ItersAhead =
PrefDist/LoopSize;
163 if (
LoadInst *LMemI = dyn_cast<LoadInst>(J)) {
165 PtrValue = LMemI->getPointerOperand();
166 }
else if (
StoreInst *SMemI = dyn_cast<StoreInst>(J)) {
169 PtrValue = SMemI->getPointerOperand();
179 const SCEV *LSCEV = SE->getSCEV(PtrValue);
187 bool DupPref =
false;
188 for (
SmallVector<std::pair<Instruction *, const SCEVAddRecExpr *>,
189 16>::iterator K = PrefLoads.
begin(), KE = PrefLoads.
end();
191 const SCEV *PtrDiff = SE->getMinusSCEV(LSCEVAddRec, K->second);
193 dyn_cast<SCEVConstant>(PtrDiff)) {
194 int64_t
PD =
std::abs(ConstPtrDiff->getValue()->getSExtValue());
204 const SCEV *NextLSCEV = SE->getAddExpr(LSCEVAddRec, SE->getMulExpr(
205 SE->getConstant(LSCEVAddRec->
getType(), ItersAhead),
210 PrefLoads.
push_back(std::make_pair(MemI, LSCEVAddRec));
213 SCEVExpander SCEVE(*SE, J->getModule()->getDataLayout(),
"prefaddr");
214 Value *PrefPtrValue = SCEVE.expandCodeFor(NextLSCEV, I8Ptr, MemI);
217 Module *M = (*I)->getParent()->getParent();
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A Module instance is used to store all the information related to an LLVM module. ...
static cl::opt< bool > PrefetchWrites("ppc-loop-prefetch-writes", cl::Hidden, cl::init(false), cl::desc("Prefetch write addresses"))
ScalarEvolution - This class is the main scalar evolution driver.
CallInst - This class represents a function call, abstracting a target machine's calling convention...
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
getStepRecurrence - This method constructs and returns the recurrence indicating how much this expres...
LoadInst - an instruction for reading from memory.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
bool isLoopInvariant(const Value *V) const
isLoopInvariant - Return true if the specified value is loop invariant
bool mayReadFromMemory() const
mayReadFromMemory - Return true if this instruction may read memory.
SCEVAddRecExpr - This node represents a polynomial recurrence on the trip count of the specified loop...
FunctionPass * createPPCLoopDataPrefetchPass()
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
StoreInst - an instruction for storing to memory.
ppc loop data PPC Loop Data Prefetch
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, SmallPtrSetImpl< const Value * > &EphValues)
Add information about a block to the current state.
static cl::opt< unsigned > PrefDist("ppc-loop-prefetch-distance", cl::Hidden, cl::init(300), cl::desc("The loop prefetch distance"))
initializer< Ty > init(const Ty &Val)
The instances of the Type class are immutable: once they are created, they are never changed...
df_iterator< T > df_end(const T &G)
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
INITIALIZE_PASS_BEGIN(PPCLoopDataPrefetch,"ppc-loop-data-prefetch","PPC Loop Data Prefetch", false, false) INITIALIZE_PASS_END(PPCLoopDataPrefetch
machine trace Machine Trace Metrics
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Utility to calculate the size and a few similar metrics for a set of basic blocks.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
df_iterator< T > df_begin(const T &G)
This class uses information about analyze scalars to rewrite expressions in canonical form...
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
std::vector< BlockT * >::const_iterator block_iterator
block_iterator block_end() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
SCEV - This class represents an analyzed expression in the program.
static IntegerType * getInt32Ty(LLVMContext &C)
void initializePPCLoopDataPrefetchPass(PassRegistry &)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
ppc loop data PPC Loop Data false
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
block_iterator block_begin() const
The legacy pass manager's analysis pass to compute loop information.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Legacy analysis pass which computes a DominatorTree.
static cl::opt< unsigned > CacheLineSize("ppc-loop-prefetch-cache-line", cl::Hidden, cl::init(64), cl::desc("The loop prefetch cache line size"))
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop)...
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE)
Return true if the given expression is safe to expand in the sense that all materialized values are s...
unsigned NumInsts
Number of instructions in the analyzed blocks.
SCEVConstant - This class represents a constant integer value.