summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
diff options
context:
space:
mode:
authorEugene Zelenko <eugene.zelenko@gmail.com>2017-10-18 21:46:47 +0000
committerEugene Zelenko <eugene.zelenko@gmail.com>2017-10-18 21:46:47 +0000
commit306d29977d4fb5b7e08880bf67109d656c711a12 (patch)
tree5b046a88bb8d31d63c7e55e59b2f66aee0c7cece /llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
parent2023e213276524158873b8197017ecadb6723d39 (diff)
downloadbcm5719-llvm-306d29977d4fb5b7e08880bf67109d656c711a12.tar.gz
bcm5719-llvm-306d29977d4fb5b7e08880bf67109d656c711a12.zip
[Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 316128
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopRerollPass.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopRerollPass.cpp70
1 files changed, 55 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
index fc0216e76a5..d1a54b87795 100644
--- a/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRerollPass.cpp
@@ -1,4 +1,4 @@
-//===-- LoopReroll.cpp - Loop rerolling pass ------------------------------===//
+//===- LoopReroll.cpp - Loop rerolling pass -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,22 +11,42 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/APInt.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
+#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -34,6 +54,13 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <cstdlib>
+#include <iterator>
+#include <map>
+#include <utility>
using namespace llvm;
@@ -127,6 +154,7 @@ NumToleratedFailedMatches("reroll-num-tolerated-failed-matches", cl::init(400),
// br %cmp, header, exit
namespace {
+
enum IterationLimits {
/// The maximum number of iterations that we'll try and reroll.
IL_MaxRerollIterations = 32,
@@ -139,6 +167,7 @@ namespace {
class LoopReroll : public LoopPass {
public:
static char ID; // Pass ID, replacement for typeid
+
LoopReroll() : LoopPass(ID) {
initializeLoopRerollPass(*PassRegistry::getPassRegistry());
}
@@ -158,11 +187,12 @@ namespace {
DominatorTree *DT;
bool PreserveLCSSA;
- typedef SmallVector<Instruction *, 16> SmallInstructionVector;
- typedef SmallSet<Instruction *, 16> SmallInstructionSet;
+ using SmallInstructionVector = SmallVector<Instruction *, 16>;
+ using SmallInstructionSet = SmallSet<Instruction *, 16>;
// Map between induction variable and its increment
DenseMap<Instruction *, int64_t> IVToIncMap;
+
// For loop with multiple induction variable, remember the one used only to
// control the loop.
Instruction *LoopControlIV;
@@ -171,8 +201,7 @@ namespace {
// representing a reduction. Only the last value may be used outside the
// loop.
struct SimpleLoopReduction {
- SimpleLoopReduction(Instruction *P, Loop *L)
- : Valid(false), Instructions(1, P) {
+ SimpleLoopReduction(Instruction *P, Loop *L) : Instructions(1, P) {
assert(isa<PHINode>(P) && "First reduction instruction must be a PHI");
add(L);
}
@@ -204,8 +233,8 @@ namespace {
return Instructions.size()-1;
}
- typedef SmallInstructionVector::iterator iterator;
- typedef SmallInstructionVector::const_iterator const_iterator;
+ using iterator = SmallInstructionVector::iterator;
+ using const_iterator = SmallInstructionVector::const_iterator;
iterator begin() {
assert(Valid && "Using invalid reduction");
@@ -221,7 +250,7 @@ namespace {
const_iterator end() const { return Instructions.end(); }
protected:
- bool Valid;
+ bool Valid = false;
SmallInstructionVector Instructions;
void add(Loop *L);
@@ -230,7 +259,7 @@ namespace {
// The set of all reductions, and state tracking of possible reductions
// during loop instruction processing.
struct ReductionTracker {
- typedef SmallVector<SimpleLoopReduction, 16> SmallReductionVector;
+ using SmallReductionVector = SmallVector<SimpleLoopReduction, 16>;
// Add a new possible reduction.
void addSLR(SimpleLoopReduction &SLR) { PossibleReds.push_back(SLR); }
@@ -342,6 +371,7 @@ namespace {
struct DAGRootSet {
Instruction *BaseInst;
SmallInstructionVector Roots;
+
// The instructions between IV and BaseInst (but not including BaseInst).
SmallInstructionSet SubsumedInsts;
};
@@ -361,15 +391,17 @@ namespace {
/// Stage 1: Find all the DAG roots for the induction variable.
bool findRoots();
+
/// Stage 2: Validate if the found roots are valid.
bool validate(ReductionTracker &Reductions);
+
/// Stage 3: Assuming validate() returned true, perform the
/// replacement.
/// @param IterCount The maximum iteration count of L.
void replace(const SCEV *IterCount);
protected:
- typedef MapVector<Instruction*, BitVector> UsesTy;
+ using UsesTy = MapVector<Instruction *, BitVector>;
void findRootsRecursive(Instruction *IVU,
SmallInstructionSet SubsumedInsts);
@@ -412,22 +444,29 @@ namespace {
// The loop induction variable.
Instruction *IV;
+
// Loop step amount.
int64_t Inc;
+
// Loop reroll count; if Inc == 1, this records the scaling applied
// to the indvar: a[i*2+0] = ...; a[i*2+1] = ... ;
// If Inc is not 1, Scale = Inc.
uint64_t Scale;
+
// The roots themselves.
SmallVector<DAGRootSet,16> RootSets;
+
// All increment instructions for IV.
SmallInstructionVector LoopIncs;
+
// Map of all instructions in the loop (in order) to the iterations
// they are used in (or specially, IL_All for instructions
// used in the loop increment mechanism).
UsesTy Uses;
+
// Map between induction variable and its increment
DenseMap<Instruction *, int64_t> &IVToIncMap;
+
Instruction *LoopControlIV;
};
@@ -446,9 +485,11 @@ namespace {
bool reroll(Instruction *IV, Loop *L, BasicBlock *Header, const SCEV *IterCount,
ReductionTracker &Reductions);
};
-}
+
+} // end anonymous namespace
char LoopReroll::ID = 0;
+
INITIALIZE_PASS_BEGIN(LoopReroll, "loop-reroll", "Reroll loops", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopPass)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
@@ -1069,7 +1110,6 @@ bool LoopReroll::DAGRootTracker::collectUsedInstructions(SmallInstructionSet &Po
}
return true;
-
}
/// Get the next instruction in "In" that is a member of set Val.
@@ -1124,7 +1164,7 @@ static bool isIgnorableInst(const Instruction *I) {
switch (II->getIntrinsicID()) {
default:
return false;
- case llvm::Intrinsic::annotation:
+ case Intrinsic::annotation:
case Intrinsic::ptr_annotation:
case Intrinsic::var_annotation:
// TODO: the following intrinsics may also be whitelisted:
@@ -1407,8 +1447,8 @@ bool LoopReroll::DAGRootTracker::validate(ReductionTracker &Reductions) {
BaseIt = nextInstr(0, Uses, Visited);
RootIt = nextInstr(Iter, Uses, Visited);
}
- assert (BaseIt == Uses.end() && RootIt == Uses.end() &&
- "Mismatched set sizes!");
+ assert(BaseIt == Uses.end() && RootIt == Uses.end() &&
+ "Mismatched set sizes!");
}
DEBUG(dbgs() << "LRR: Matched all iteration increments for " <<
OpenPOWER on IntegriCloud