[LoopAccesses] Change debug messages from LV to LAA

Also add pass name as an argument to VectorizationReport::emitAnalysis.

This is part of the patchset that converts LoopAccessAnalysis into an
actual analysis pass.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229628 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adam Nemet
2015-02-18 03:43:37 +00:00
parent 47985fb7cd
commit ce5c5c0301
3 changed files with 46 additions and 43 deletions

View File

@ -55,11 +55,13 @@ public:
std::string &str() { return Message; } std::string &str() { return Message; }
operator Twine() { return Message; } operator Twine() { return Message; }
/// \brief Emit an analysis note with the debug location from the instruction /// \brief Emit an analysis note for \p PassName with the debug location from
/// in \p Message if available. Otherwise use the location of \p TheLoop. /// the instruction in \p Message if available. Otherwise use the location of
/// \p TheLoop.
static void emitAnalysis(VectorizationReport &Message, static void emitAnalysis(VectorizationReport &Message,
const Function *TheFunction, const Function *TheFunction,
const Loop *TheLoop); const Loop *TheLoop,
const char *PassName);
}; };
/// \brief Collection of parameters shared beetween the Loop Vectorizer and the /// \brief Collection of parameters shared beetween the Loop Vectorizer and the

View File

@ -23,15 +23,16 @@
#include "llvm/Transforms/Utils/VectorUtils.h" #include "llvm/Transforms/Utils/VectorUtils.h"
using namespace llvm; using namespace llvm;
#define DEBUG_TYPE "loop-vectorize" #define DEBUG_TYPE "loop-accesses"
void VectorizationReport::emitAnalysis(VectorizationReport &Message, void VectorizationReport::emitAnalysis(VectorizationReport &Message,
const Function *TheFunction, const Function *TheFunction,
const Loop *TheLoop) { const Loop *TheLoop,
const char *PassName) {
DebugLoc DL = TheLoop->getStartLoc(); DebugLoc DL = TheLoop->getStartLoc();
if (Instruction *I = Message.getInstr()) if (Instruction *I = Message.getInstr())
DL = I->getDebugLoc(); DL = I->getDebugLoc();
emitOptimizationRemarkAnalysis(TheFunction->getContext(), DEBUG_TYPE, emitOptimizationRemarkAnalysis(TheFunction->getContext(), PassName,
*TheFunction, DL, Message.str()); *TheFunction, DL, Message.str());
} }
@ -64,7 +65,7 @@ const SCEV *llvm::replaceSymbolicStrideSCEV(ScalarEvolution *SE,
const SCEV *ByOne = const SCEV *ByOne =
SCEVParameterRewriter::rewrite(OrigSCEV, *SE, RewriteMap, true); SCEVParameterRewriter::rewrite(OrigSCEV, *SE, RewriteMap, true);
DEBUG(dbgs() << "LV: Replacing SCEV: " << *OrigSCEV << " by: " << *ByOne DEBUG(dbgs() << "LAA: Replacing SCEV: " << *OrigSCEV << " by: " << *ByOne
<< "\n"); << "\n");
return ByOne; return ByOne;
} }
@ -247,7 +248,7 @@ bool AccessAnalysis::canCheckPtrAtRT(
RtCheck.insert(SE, TheLoop, Ptr, IsWrite, DepId, ASId, StridesMap); RtCheck.insert(SE, TheLoop, Ptr, IsWrite, DepId, ASId, StridesMap);
DEBUG(dbgs() << "LV: Found a runtime check ptr:" << *Ptr << '\n'); DEBUG(dbgs() << "LAA: Found a runtime check ptr:" << *Ptr << '\n');
} else { } else {
CanDoRT = false; CanDoRT = false;
} }
@ -284,7 +285,7 @@ bool AccessAnalysis::canCheckPtrAtRT(
unsigned ASi = PtrI->getType()->getPointerAddressSpace(); unsigned ASi = PtrI->getType()->getPointerAddressSpace();
unsigned ASj = PtrJ->getType()->getPointerAddressSpace(); unsigned ASj = PtrJ->getType()->getPointerAddressSpace();
if (ASi != ASj) { if (ASi != ASj) {
DEBUG(dbgs() << "LV: Runtime check would require comparison between" DEBUG(dbgs() << "LAA: Runtime check would require comparison between"
" different address spaces\n"); " different address spaces\n");
return false; return false;
} }
@ -299,9 +300,9 @@ void AccessAnalysis::processMemAccesses() {
// process read-only pointers. This allows us to skip dependence tests for // process read-only pointers. This allows us to skip dependence tests for
// read-only pointers. // read-only pointers.
DEBUG(dbgs() << "LV: Processing memory accesses...\n"); DEBUG(dbgs() << "LAA: Processing memory accesses...\n");
DEBUG(dbgs() << " AST: "; AST.dump()); DEBUG(dbgs() << " AST: "; AST.dump());
DEBUG(dbgs() << "LV: Accesses:\n"); DEBUG(dbgs() << "LAA: Accesses:\n");
DEBUG({ DEBUG({
for (auto A : Accesses) for (auto A : Accesses)
dbgs() << "\t" << *A.getPointer() << " (" << dbgs() << "\t" << *A.getPointer() << " (" <<
@ -532,8 +533,8 @@ static int isStridedPtr(ScalarEvolution *SE, const DataLayout *DL, Value *Ptr,
// Make sure that the pointer does not point to aggregate types. // Make sure that the pointer does not point to aggregate types.
const PointerType *PtrTy = cast<PointerType>(Ty); const PointerType *PtrTy = cast<PointerType>(Ty);
if (PtrTy->getElementType()->isAggregateType()) { if (PtrTy->getElementType()->isAggregateType()) {
DEBUG(dbgs() << "LV: Bad stride - Not a pointer to a scalar type" << *Ptr << DEBUG(dbgs() << "LAA: Bad stride - Not a pointer to a scalar type"
"\n"); << *Ptr << "\n");
return 0; return 0;
} }
@ -541,14 +542,14 @@ static int isStridedPtr(ScalarEvolution *SE, const DataLayout *DL, Value *Ptr,
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev); const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev);
if (!AR) { if (!AR) {
DEBUG(dbgs() << "LV: Bad stride - Not an AddRecExpr pointer " DEBUG(dbgs() << "LAA: Bad stride - Not an AddRecExpr pointer "
<< *Ptr << " SCEV: " << *PtrScev << "\n"); << *Ptr << " SCEV: " << *PtrScev << "\n");
return 0; return 0;
} }
// The accesss function must stride over the innermost loop. // The accesss function must stride over the innermost loop.
if (Lp != AR->getLoop()) { if (Lp != AR->getLoop()) {
DEBUG(dbgs() << "LV: Bad stride - Not striding over innermost loop " << DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop " <<
*Ptr << " SCEV: " << *PtrScev << "\n"); *Ptr << " SCEV: " << *PtrScev << "\n");
} }
@ -563,7 +564,7 @@ static int isStridedPtr(ScalarEvolution *SE, const DataLayout *DL, Value *Ptr,
bool IsNoWrapAddRec = AR->getNoWrapFlags(SCEV::NoWrapMask); bool IsNoWrapAddRec = AR->getNoWrapFlags(SCEV::NoWrapMask);
bool IsInAddressSpaceZero = PtrTy->getAddressSpace() == 0; bool IsInAddressSpaceZero = PtrTy->getAddressSpace() == 0;
if (!IsNoWrapAddRec && !IsInBoundsGEP && !IsInAddressSpaceZero) { if (!IsNoWrapAddRec && !IsInBoundsGEP && !IsInAddressSpaceZero) {
DEBUG(dbgs() << "LV: Bad stride - Pointer may wrap in the address space " DEBUG(dbgs() << "LAA: Bad stride - Pointer may wrap in the address space "
<< *Ptr << " SCEV: " << *PtrScev << "\n"); << *Ptr << " SCEV: " << *PtrScev << "\n");
return 0; return 0;
} }
@ -574,7 +575,7 @@ static int isStridedPtr(ScalarEvolution *SE, const DataLayout *DL, Value *Ptr,
// Calculate the pointer stride and check if it is consecutive. // Calculate the pointer stride and check if it is consecutive.
const SCEVConstant *C = dyn_cast<SCEVConstant>(Step); const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
if (!C) { if (!C) {
DEBUG(dbgs() << "LV: Bad stride - Not a constant strided " << *Ptr << DEBUG(dbgs() << "LAA: Bad stride - Not a constant strided " << *Ptr <<
" SCEV: " << *PtrScev << "\n"); " SCEV: " << *PtrScev << "\n");
return 0; return 0;
} }
@ -631,7 +632,7 @@ bool MemoryDepChecker::couldPreventStoreLoadForward(unsigned Distance,
} }
if (MaxVFWithoutSLForwardIssues< 2*TypeByteSize) { if (MaxVFWithoutSLForwardIssues< 2*TypeByteSize) {
DEBUG(dbgs() << "LV: Distance " << Distance << DEBUG(dbgs() << "LAA: Distance " << Distance <<
" that could cause a store-load forwarding conflict\n"); " that could cause a store-load forwarding conflict\n");
return true; return true;
} }
@ -685,9 +686,9 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
const SCEV *Dist = SE->getMinusSCEV(Sink, Src); const SCEV *Dist = SE->getMinusSCEV(Sink, Src);
DEBUG(dbgs() << "LV: Src Scev: " << *Src << "Sink Scev: " << *Sink DEBUG(dbgs() << "LAA: Src Scev: " << *Src << "Sink Scev: " << *Sink
<< "(Induction step: " << StrideAPtr << ")\n"); << "(Induction step: " << StrideAPtr << ")\n");
DEBUG(dbgs() << "LV: Distance for " << *InstMap[AIdx] << " to " DEBUG(dbgs() << "LAA: Distance for " << *InstMap[AIdx] << " to "
<< *InstMap[BIdx] << ": " << *Dist << "\n"); << *InstMap[BIdx] << ": " << *Dist << "\n");
// Need consecutive accesses. We don't want to vectorize // Need consecutive accesses. We don't want to vectorize
@ -700,7 +701,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist); const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
if (!C) { if (!C) {
DEBUG(dbgs() << "LV: Dependence because of non-constant distance\n"); DEBUG(dbgs() << "LAA: Dependence because of non-constant distance\n");
ShouldRetryWithRuntimeCheck = true; ShouldRetryWithRuntimeCheck = true;
return true; return true;
} }
@ -718,7 +719,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
ATy != BTy)) ATy != BTy))
return true; return true;
DEBUG(dbgs() << "LV: Dependence is negative: NoDep\n"); DEBUG(dbgs() << "LAA: Dependence is negative: NoDep\n");
return false; return false;
} }
@ -727,7 +728,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
if (Val == 0) { if (Val == 0) {
if (ATy == BTy) if (ATy == BTy)
return false; return false;
DEBUG(dbgs() << "LV: Zero dependence difference but different types\n"); DEBUG(dbgs() << "LAA: Zero dependence difference but different types\n");
return true; return true;
} }
@ -736,7 +737,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
// Positive distance bigger than max vectorization factor. // Positive distance bigger than max vectorization factor.
if (ATy != BTy) { if (ATy != BTy) {
DEBUG(dbgs() << DEBUG(dbgs() <<
"LV: ReadWrite-Write positive dependency with different types\n"); "LAA: ReadWrite-Write positive dependency with different types\n");
return false; return false;
} }
@ -754,7 +755,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
if (Distance < 2*TypeByteSize || if (Distance < 2*TypeByteSize ||
2*TypeByteSize > MaxSafeDepDistBytes || 2*TypeByteSize > MaxSafeDepDistBytes ||
Distance < TypeByteSize * ForcedUnroll * ForcedFactor) { Distance < TypeByteSize * ForcedUnroll * ForcedFactor) {
DEBUG(dbgs() << "LV: Failure because of Positive distance " DEBUG(dbgs() << "LAA: Failure because of Positive distance "
<< Val.getSExtValue() << '\n'); << Val.getSExtValue() << '\n');
return true; return true;
} }
@ -767,7 +768,7 @@ bool MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
couldPreventStoreLoadForward(Distance, TypeByteSize)) couldPreventStoreLoadForward(Distance, TypeByteSize))
return true; return true;
DEBUG(dbgs() << "LV: Positive distance " << Val.getSExtValue() << DEBUG(dbgs() << "LAA: Positive distance " << Val.getSExtValue() <<
" with max VF = " << MaxSafeDepDistBytes / TypeByteSize << '\n'); " with max VF = " << MaxSafeDepDistBytes / TypeByteSize << '\n');
return false; return false;
@ -854,7 +855,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
if (!Ld || (!Ld->isSimple() && !IsAnnotatedParallel)) { if (!Ld || (!Ld->isSimple() && !IsAnnotatedParallel)) {
emitAnalysis(VectorizationReport(Ld) emitAnalysis(VectorizationReport(Ld)
<< "read with atomic ordering or volatile read"); << "read with atomic ordering or volatile read");
DEBUG(dbgs() << "LV: Found a non-simple load.\n"); DEBUG(dbgs() << "LAA: Found a non-simple load.\n");
CanVecMem = false; CanVecMem = false;
return; return;
} }
@ -876,7 +877,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
if (!St->isSimple() && !IsAnnotatedParallel) { if (!St->isSimple() && !IsAnnotatedParallel) {
emitAnalysis(VectorizationReport(St) emitAnalysis(VectorizationReport(St)
<< "write with atomic ordering or volatile write"); << "write with atomic ordering or volatile write");
DEBUG(dbgs() << "LV: Found a non-simple store.\n"); DEBUG(dbgs() << "LAA: Found a non-simple store.\n");
CanVecMem = false; CanVecMem = false;
return; return;
} }
@ -893,7 +894,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
// Check if we see any stores. If there are no stores, then we don't // Check if we see any stores. If there are no stores, then we don't
// care if the pointers are *restrict*. // care if the pointers are *restrict*.
if (!Stores.size()) { if (!Stores.size()) {
DEBUG(dbgs() << "LV: Found a read-only loop!\n"); DEBUG(dbgs() << "LAA: Found a read-only loop!\n");
CanVecMem = true; CanVecMem = true;
return; return;
} }
@ -917,7 +918,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
emitAnalysis( emitAnalysis(
VectorizationReport(ST) VectorizationReport(ST)
<< "write to a loop invariant address could not be vectorized"); << "write to a loop invariant address could not be vectorized");
DEBUG(dbgs() << "LV: We don't allow storing to uniform addresses\n"); DEBUG(dbgs() << "LAA: We don't allow storing to uniform addresses\n");
CanVecMem = false; CanVecMem = false;
return; return;
} }
@ -940,7 +941,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
if (IsAnnotatedParallel) { if (IsAnnotatedParallel) {
DEBUG(dbgs() DEBUG(dbgs()
<< "LV: A loop annotated parallel, ignore memory dependency " << "LAA: A loop annotated parallel, ignore memory dependency "
<< "checks.\n"); << "checks.\n");
CanVecMem = true; CanVecMem = true;
return; return;
@ -977,7 +978,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
// If we write (or read-write) to a single destination and there are no // If we write (or read-write) to a single destination and there are no
// other reads in this loop then is it safe to vectorize. // other reads in this loop then is it safe to vectorize.
if (NumReadWrites == 1 && NumReads == 0) { if (NumReadWrites == 1 && NumReads == 0) {
DEBUG(dbgs() << "LV: Found a write-only loop!\n"); DEBUG(dbgs() << "LAA: Found a write-only loop!\n");
CanVecMem = true; CanVecMem = true;
return; return;
} }
@ -995,7 +996,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE, TheLoop, CanDoRT = Accesses.canCheckPtrAtRT(PtrRtCheck, NumComparisons, SE, TheLoop,
Strides); Strides);
DEBUG(dbgs() << "LV: We need to do " << NumComparisons << DEBUG(dbgs() << "LAA: We need to do " << NumComparisons <<
" pointer comparisons.\n"); " pointer comparisons.\n");
// If we only have one set of dependences to check pointers among we don't // If we only have one set of dependences to check pointers among we don't
@ -1012,12 +1013,12 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
} }
if (CanDoRT) { if (CanDoRT) {
DEBUG(dbgs() << "LV: We can perform a memory runtime check if needed.\n"); DEBUG(dbgs() << "LAA: We can perform a memory runtime check if needed.\n");
} }
if (NeedRTCheck && !CanDoRT) { if (NeedRTCheck && !CanDoRT) {
emitAnalysis(VectorizationReport() << "cannot identify array bounds"); emitAnalysis(VectorizationReport() << "cannot identify array bounds");
DEBUG(dbgs() << "LV: We can't vectorize because we can't find " << DEBUG(dbgs() << "LAA: We can't vectorize because we can't find " <<
"the array bounds.\n"); "the array bounds.\n");
PtrRtCheck.reset(); PtrRtCheck.reset();
CanVecMem = false; CanVecMem = false;
@ -1028,13 +1029,13 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
CanVecMem = true; CanVecMem = true;
if (Accesses.isDependencyCheckNeeded()) { if (Accesses.isDependencyCheckNeeded()) {
DEBUG(dbgs() << "LV: Checking memory dependencies\n"); DEBUG(dbgs() << "LAA: Checking memory dependencies\n");
CanVecMem = DepChecker.areDepsSafe( CanVecMem = DepChecker.areDepsSafe(
DependentAccesses, Accesses.getDependenciesToCheck(), Strides); DependentAccesses, Accesses.getDependenciesToCheck(), Strides);
MaxSafeDepDistBytes = DepChecker.getMaxSafeDepDistBytes(); MaxSafeDepDistBytes = DepChecker.getMaxSafeDepDistBytes();
if (!CanVecMem && DepChecker.shouldRetryWithRuntimeCheck()) { if (!CanVecMem && DepChecker.shouldRetryWithRuntimeCheck()) {
DEBUG(dbgs() << "LV: Retrying with memory checks\n"); DEBUG(dbgs() << "LAA: Retrying with memory checks\n");
NeedRTCheck = true; NeedRTCheck = true;
// Clear the dependency checks. We assume they are not needed. // Clear the dependency checks. We assume they are not needed.
@ -1057,7 +1058,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
<< NumComparisons << " exceeds limit of " << NumComparisons << " exceeds limit of "
<< VectorizerParams::RuntimeMemoryCheckThreshold << VectorizerParams::RuntimeMemoryCheckThreshold
<< " dependent memory operations checked at runtime"); << " dependent memory operations checked at runtime");
DEBUG(dbgs() << "LV: Can't vectorize with memory checks\n"); DEBUG(dbgs() << "LAA: Can't vectorize with memory checks\n");
PtrRtCheck.reset(); PtrRtCheck.reset();
CanVecMem = false; CanVecMem = false;
return; return;
@ -1071,7 +1072,7 @@ void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) {
emitAnalysis(VectorizationReport() << emitAnalysis(VectorizationReport() <<
"unsafe dependent memory operations in loop"); "unsafe dependent memory operations in loop");
DEBUG(dbgs() << "LV: We" << (NeedRTCheck ? "" : " don't") << DEBUG(dbgs() << "LAA: We" << (NeedRTCheck ? "" : " don't") <<
" need a runtime memory check.\n"); " need a runtime memory check.\n");
} }
@ -1123,12 +1124,12 @@ LoopAccessInfo::addRuntimeCheck(Instruction *Loc) {
const SCEV *Sc = SE->getSCEV(Ptr); const SCEV *Sc = SE->getSCEV(Ptr);
if (SE->isLoopInvariant(Sc, TheLoop)) { if (SE->isLoopInvariant(Sc, TheLoop)) {
DEBUG(dbgs() << "LV: Adding RT check for a loop invariant ptr:" << DEBUG(dbgs() << "LAA: Adding RT check for a loop invariant ptr:" <<
*Ptr <<"\n"); *Ptr <<"\n");
Starts.push_back(Ptr); Starts.push_back(Ptr);
Ends.push_back(Ptr); Ends.push_back(Ptr);
} else { } else {
DEBUG(dbgs() << "LV: Adding RT check for range:" << *Ptr << '\n'); DEBUG(dbgs() << "LAA: Adding RT check for range:" << *Ptr << '\n');
unsigned AS = Ptr->getType()->getPointerAddressSpace(); unsigned AS = Ptr->getType()->getPointerAddressSpace();
// Use this type for pointer arithmetic. // Use this type for pointer arithmetic.

View File

@ -837,7 +837,7 @@ private:
/// Report an analysis message to assist the user in diagnosing loops that are /// Report an analysis message to assist the user in diagnosing loops that are
/// not vectorized. /// not vectorized.
void emitAnalysis(VectorizationReport &Message) { void emitAnalysis(VectorizationReport &Message) {
VectorizationReport::emitAnalysis(Message, TheFunction, TheLoop); VectorizationReport::emitAnalysis(Message, TheFunction, TheLoop, LV_NAME);
} }
unsigned NumPredStores; unsigned NumPredStores;
@ -974,7 +974,7 @@ private:
/// Report an analysis message to assist the user in diagnosing loops that are /// Report an analysis message to assist the user in diagnosing loops that are
/// not vectorized. /// not vectorized.
void emitAnalysis(VectorizationReport &Message) { void emitAnalysis(VectorizationReport &Message) {
VectorizationReport::emitAnalysis(Message, TheFunction, TheLoop); VectorizationReport::emitAnalysis(Message, TheFunction, TheLoop, LV_NAME);
} }
/// Values used only by @llvm.assume calls. /// Values used only by @llvm.assume calls.