[llvm] r323183 - This change add's optimization remark in LoopVersioning LICM pass.
Ashutosh Nema via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 01:47:28 PST 2018
Author: ashutosh
Date: Tue Jan 23 01:47:28 2018
New Revision: 323183
URL: http://llvm.org/viewvc/llvm-project?rev=323183&view=rev
Log:
This change add's optimization remark in LoopVersioning LICM pass.
Summary:
This patch is adding remark messages to the LoopVersioning LICM pass,
which will be useful for optimization remark emitter (ORE) infrastructure.
Patch by: Deepak Porwal
Reviewers: anemet, ashutosh.nema, eastig
Subscribers: eastig, vivekvpandya, fhahn, llvm-commits
Modified:
llvm/trunk/include/llvm/IR/DiagnosticInfo.h
llvm/trunk/lib/IR/DiagnosticInfo.cpp
llvm/trunk/lib/Transforms/Scalar/LoopVersioningLICM.cpp
Modified: llvm/trunk/include/llvm/IR/DiagnosticInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=323183&r1=323182&r2=323183&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DiagnosticInfo.h (original)
+++ llvm/trunk/include/llvm/IR/DiagnosticInfo.h Tue Jan 23 01:47:28 2018
@@ -415,6 +415,7 @@ public:
Argument(StringRef Key, const Type *T);
Argument(StringRef Key, StringRef S);
Argument(StringRef Key, int N);
+ Argument(StringRef Key, float N);
Argument(StringRef Key, long N);
Argument(StringRef Key, long long N);
Argument(StringRef Key, unsigned N);
Modified: llvm/trunk/lib/IR/DiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DiagnosticInfo.cpp?rev=323183&r1=323182&r2=323183&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/IR/DiagnosticInfo.cpp Tue Jan 23 01:47:28 2018
@@ -35,6 +35,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ScopedPrinter.h"
#include <atomic>
#include <cassert>
#include <memory>
@@ -167,6 +168,9 @@ DiagnosticInfoOptimizationBase::Argument
DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, int N)
: Key(Key), Val(itostr(N)) {}
+DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, float N)
+ : Key(Key), Val(llvm::to_string(N)) {}
+
DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, long N)
: Key(Key), Val(itostr(N)) {}
Modified: llvm/trunk/lib/Transforms/Scalar/LoopVersioningLICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopVersioningLICM.cpp?rev=323183&r1=323182&r2=323183&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopVersioningLICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopVersioningLICM.cpp Tue Jan 23 01:47:28 2018
@@ -68,6 +68,7 @@
#include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
@@ -166,6 +167,7 @@ struct LoopVersioningLICM : public LoopP
AU.addRequired<ScalarEvolutionWrapperPass>();
AU.addPreserved<AAResultsWrapperPass>();
AU.addPreserved<GlobalsAAWrapperPass>();
+ AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
}
StringRef getPassName() const override { return "Loop Versioning for LICM"; }
@@ -178,6 +180,7 @@ struct LoopVersioningLICM : public LoopP
LoadAndStoreCounter = 0;
InvariantCounter = 0;
IsReadOnlyLoop = true;
+ ORE = nullptr;
CurAST.reset();
}
@@ -207,7 +210,7 @@ private:
Loop *CurLoop = nullptr;
// AliasSet information for the current loop.
- std::unique_ptr<AliasSetTracker> CurAST;
+ std::unique_ptr<AliasSetTracker> CurAST;
// Maximum loop nest threshold
unsigned LoopDepthThreshold;
@@ -224,6 +227,9 @@ private:
// Read only loop marker.
bool IsReadOnlyLoop = true;
+ // OptimizationRemarkEmitter
+ OptimizationRemarkEmitter *ORE;
+
bool isLegalForVersioning();
bool legalLoopStructure();
bool legalLoopInstructions();
@@ -403,13 +409,19 @@ bool LoopVersioningLICM::legalLoopInstru
LoadAndStoreCounter = 0;
InvariantCounter = 0;
IsReadOnlyLoop = true;
+ using namespace ore;
// Iterate over loop blocks and instructions of each block and check
// instruction safety.
for (auto *Block : CurLoop->getBlocks())
for (auto &Inst : *Block) {
// If instruction is unsafe just return false.
- if (!instructionSafeForVersioning(&Inst))
+ if (!instructionSafeForVersioning(&Inst)) {
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "IllegalLoopInst", &Inst)
+ << " Unsafe Loop Instruction";
+ });
return false;
+ }
}
// Get LoopAccessInfo from current loop.
LAI = &LAA->getInfo(CurLoop);
@@ -422,6 +434,15 @@ bool LoopVersioningLICM::legalLoopInstru
if (LAI->getNumRuntimePointerChecks() >
VectorizerParams::RuntimeMemoryCheckThreshold) {
DEBUG(dbgs() << " LAA: Runtime checks are more than threshold !!\n");
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "RuntimeCheck",
+ CurLoop->getStartLoc(),
+ CurLoop->getHeader())
+ << "Number of runtime checks "
+ << NV("RuntimeChecks", LAI->getNumRuntimePointerChecks())
+ << " exceeds threshold "
+ << NV("Threshold", VectorizerParams::RuntimeMemoryCheckThreshold);
+ });
return false;
}
// Loop should have at least one invariant load or store instruction.
@@ -443,6 +464,16 @@ bool LoopVersioningLICM::legalLoopInstru
<< ((InvariantCounter * 100) / LoadAndStoreCounter) << "%\n");
DEBUG(dbgs() << " Invariant loads & store threshold: "
<< InvariantThreshold << "%\n");
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "InvariantThreshold",
+ CurLoop->getStartLoc(),
+ CurLoop->getHeader())
+ << "Invariant load & store "
+ << NV("LoadAndStoreCounter",
+ ((InvariantCounter * 100) / LoadAndStoreCounter))
+ << " are less then defined threshold "
+ << NV("Threshold", InvariantThreshold);
+ });
return false;
}
return true;
@@ -464,6 +495,7 @@ bool LoopVersioningLICM::isLoopAlreadyVi
/// c) loop memory access legality.
/// Return true if legal else returns false.
bool LoopVersioningLICM::isLegalForVersioning() {
+ using namespace ore;
DEBUG(dbgs() << "Loop: " << *CurLoop);
// Make sure not re-visiting same loop again.
if (isLoopAlreadyVisited()) {
@@ -475,6 +507,12 @@ bool LoopVersioningLICM::isLegalForVersi
if (!legalLoopStructure()) {
DEBUG(
dbgs() << " Loop structure not suitable for LoopVersioningLICM\n\n");
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "IllegalLoopStruct",
+ CurLoop->getStartLoc(),
+ CurLoop->getHeader())
+ << " Unsafe Loop structure";
+ });
return false;
}
// Check loop instruction leagality.
@@ -487,10 +525,23 @@ bool LoopVersioningLICM::isLegalForVersi
if (!legalLoopMemoryAccesses()) {
DEBUG(dbgs()
<< " Loop memory access not suitable for LoopVersioningLICM\n\n");
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "IllegalLoopMemoryAccess",
+ CurLoop->getStartLoc(),
+ CurLoop->getHeader())
+ << " Unsafe Loop memory access";
+ });
return false;
}
// Loop versioning is feasible, return true.
DEBUG(dbgs() << " Loop Versioning found to be beneficial\n\n");
+ ORE->emit([&]() {
+ return OptimizationRemark(DEBUG_TYPE, "IsLegalForVersioning",
+ CurLoop->getStartLoc(), CurLoop->getHeader())
+ << " Versioned loop for LICM."
+ << " Number of runtime checks we had to insert "
+ << NV("RuntimeChecks", LAI->getNumRuntimePointerChecks());
+ });
return true;
}
@@ -542,6 +593,7 @@ bool LoopVersioningLICM::runOnLoop(Loop
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
+ ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
LAI = nullptr;
// Set Current Loop
CurLoop = L;
@@ -592,6 +644,7 @@ INITIALIZE_PASS_DEPENDENCY(LoopAccessLeg
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
INITIALIZE_PASS_END(LoopVersioningLICM, "loop-versioning-licm",
"Loop Versioning For LICM", false, false)
More information about the llvm-commits
mailing list