summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Vectorize/VPlan.h
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/VPlan.h')
-rw-r--r--llvm/lib/Transforms/Vectorize/VPlan.h145
1 files changed, 74 insertions, 71 deletions
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 3c11fdeb076..d43774dd36e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1,4 +1,4 @@
-//===- VPlan.h - Represent A Vectorizer Plan ------------------------------===//
+//===- VPlan.h - Represent A Vectorizer Plan --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,7 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
+//
/// \file
/// This file contains the declarations of the Vectorization Plan base classes:
/// 1. VPBasicBlock and VPRegionBlock that inherit from a common pure virtual
@@ -18,34 +18,37 @@
/// 4. The VPlan class holding a candidate for vectorization;
/// 5. The VPlanPrinter class providing a way to print a plan in dot format.
/// These are documented in docs/VectorizationPlan.rst.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/GraphTraits.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/IR/IRBuilder.h"
-#include "llvm/Support/raw_ostream.h"
-
-// The (re)use of existing LoopVectorize classes is subject to future VPlan
-// refactoring.
-namespace {
-// Forward declarations.
-//class InnerLoopVectorizer;
-class LoopVectorizationLegality;
-class LoopVectorizationCostModel;
-} // namespace
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <map>
+#include <string>
namespace llvm {
-// Forward declarations.
class BasicBlock;
+class DominatorTree;
class InnerLoopVectorizer;
+class LoopInfo;
+class raw_ostream;
+class Value;
class VPBasicBlock;
+class VPRegionBlock;
/// In what follows, the term "input IR" refers to code that is fed into the
/// vectorizer whereas the term "output IR" refers to code that is generated by
@@ -54,8 +57,11 @@ class VPBasicBlock;
/// VPIteration represents a single point in the iteration space of the output
/// (vectorized and/or unrolled) IR loop.
struct VPIteration {
- unsigned Part; ///< in [0..UF)
- unsigned Lane; ///< in [0..VF)
+ /// in [0..UF)
+ unsigned Part;
+
+ /// in [0..VF)
+ unsigned Lane;
};
/// This is a helper struct for maintaining vectorization state. It's used for
@@ -75,7 +81,6 @@ struct VPIteration {
///
/// Entries from either map can be retrieved using the getVectorValue and
/// getScalarValue functions, which assert that the desired value exists.
-
struct VectorizerValueMap {
private:
/// The unroll factor. Each entry in the vector map contains UF vector values.
@@ -87,8 +92,8 @@ private:
/// The vector and scalar map storage. We use std::map and not DenseMap
/// because insertions to DenseMap invalidate its iterators.
- typedef SmallVector<Value *, 2> VectorParts;
- typedef SmallVector<SmallVector<Value *, 4>, 2> ScalarParts;
+ using VectorParts = SmallVector<Value *, 2>;
+ using ScalarParts = SmallVector<SmallVector<Value *, 4>, 2>;
std::map<Value *, VectorParts> VectorMapStorage;
std::map<Value *, ScalarParts> ScalarMapStorage;
@@ -193,12 +198,11 @@ public:
/// VPTransformState holds information passed down when "executing" a VPlan,
/// needed for generating the output IR.
struct VPTransformState {
-
- VPTransformState(unsigned VF, unsigned UF, class LoopInfo *LI,
- class DominatorTree *DT, IRBuilder<> &Builder,
- VectorizerValueMap &ValueMap, InnerLoopVectorizer *ILV)
- : VF(VF), UF(UF), Instance(), LI(LI), DT(DT), Builder(Builder),
- ValueMap(ValueMap), ILV(ILV) {}
+ VPTransformState(unsigned VF, unsigned UF, LoopInfo *LI, DominatorTree *DT,
+ IRBuilder<> &Builder, VectorizerValueMap &ValueMap,
+ InnerLoopVectorizer *ILV)
+ : VF(VF), UF(UF), LI(LI), DT(DT), Builder(Builder), ValueMap(ValueMap),
+ ILV(ILV) {}
/// The chosen Vectorization and Unroll Factors of the loop being vectorized.
unsigned VF;
@@ -213,25 +217,28 @@ struct VPTransformState {
/// traversing the VPBasicBlocks and generating corresponding IR BasicBlocks.
struct CFGState {
/// The previous VPBasicBlock visited. Initially set to null.
- VPBasicBlock *PrevVPBB;
+ VPBasicBlock *PrevVPBB = nullptr;
+
/// The previous IR BasicBlock created or used. Initially set to the new
/// header BasicBlock.
- BasicBlock *PrevBB;
+ BasicBlock *PrevBB = nullptr;
+
/// The last IR BasicBlock in the output IR. Set to the new latch
/// BasicBlock, used for placing the newly created BasicBlocks.
- BasicBlock *LastBB;
+ BasicBlock *LastBB = nullptr;
+
/// A mapping of each VPBasicBlock to the corresponding BasicBlock. In case
/// of replication, maps the BasicBlock of the last replica created.
SmallDenseMap<VPBasicBlock *, BasicBlock *> VPBB2IRBB;
- CFGState() : PrevVPBB(nullptr), PrevBB(nullptr), LastBB(nullptr) {}
+ CFGState() = default;
} CFG;
/// Hold a pointer to LoopInfo to register new basic blocks in the loop.
- class LoopInfo *LI;
+ LoopInfo *LI;
/// Hold a pointer to Dominator Tree to register new basic blocks in the loop.
- class DominatorTree *DT;
+ DominatorTree *DT;
/// Hold a reference to the IRBuilder used to generate output IR code.
IRBuilder<> &Builder;
@@ -241,7 +248,7 @@ struct VPTransformState {
VectorizerValueMap &ValueMap;
/// Hold a pointer to InnerLoopVectorizer to reuse its IR generation methods.
- class InnerLoopVectorizer *ILV;
+ InnerLoopVectorizer *ILV;
};
/// VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
@@ -255,7 +262,7 @@ private:
/// The immediate VPRegionBlock which this VPBlockBase belongs to, or null if
/// it is a topmost VPBlockBase.
- class VPRegionBlock *Parent;
+ VPRegionBlock *Parent = nullptr;
/// List of predecessor blocks.
SmallVector<VPBlockBase *, 1> Predecessors;
@@ -291,18 +298,18 @@ private:
protected:
VPBlockBase(const unsigned char SC, const std::string &N)
- : SubclassID(SC), Name(N), Parent(nullptr) {}
+ : SubclassID(SC), Name(N) {}
public:
/// An enumeration for keeping track of the concrete subclass of VPBlockBase
/// that are actually instantiated. Values of this enumeration are kept in the
/// SubclassID field of the VPBlockBase objects. They are used for concrete
/// type identification.
- typedef enum { VPBasicBlockSC, VPRegionBlockSC } VPBlockTy;
+ using VPBlockTy = enum { VPBasicBlockSC, VPRegionBlockSC };
- typedef SmallVectorImpl<VPBlockBase *> VPBlocksTy;
+ using VPBlocksTy = SmallVectorImpl<VPBlockBase *>;
- virtual ~VPBlockBase() {}
+ virtual ~VPBlockBase() = default;
const std::string &getName() const { return Name; }
@@ -437,14 +444,14 @@ private:
const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
/// Each VPRecipe belongs to a single VPBasicBlock.
- VPBasicBlock *Parent;
+ VPBasicBlock *Parent = nullptr;
public:
/// An enumeration for keeping track of the concrete subclass of VPRecipeBase
/// that is actually instantiated. Values of this enumeration are kept in the
/// SubclassID field of the VPRecipeBase objects. They are used for concrete
/// type identification.
- typedef enum {
+ using VPRecipeTy = enum {
VPBranchOnMaskSC,
VPInterleaveSC,
VPPredInstPHISC,
@@ -452,11 +459,10 @@ public:
VPWidenIntOrFpInductionSC,
VPWidenPHISC,
VPWidenSC,
- } VPRecipeTy;
-
- VPRecipeBase(const unsigned char SC) : SubclassID(SC), Parent(nullptr) {}
+ };
- virtual ~VPRecipeBase() {}
+ VPRecipeBase(const unsigned char SC) : SubclassID(SC) {}
+ virtual ~VPRecipeBase() = default;
/// \return an ID for the concrete type of this object.
/// This is used to implement the classof checks. This should not be used
@@ -480,18 +486,26 @@ public:
/// output IR instructions.
class VPBasicBlock : public VPBlockBase {
public:
- typedef iplist<VPRecipeBase> RecipeListTy;
+ using RecipeListTy = iplist<VPRecipeBase>;
private:
/// The VPRecipes held in the order of output instructions to generate.
RecipeListTy Recipes;
public:
+ VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
+ : VPBlockBase(VPBasicBlockSC, Name.str()) {
+ if (Recipe)
+ appendRecipe(Recipe);
+ }
+
+ ~VPBasicBlock() override { Recipes.clear(); }
+
/// Instruction iterators...
- typedef RecipeListTy::iterator iterator;
- typedef RecipeListTy::const_iterator const_iterator;
- typedef RecipeListTy::reverse_iterator reverse_iterator;
- typedef RecipeListTy::const_reverse_iterator const_reverse_iterator;
+ using iterator = RecipeListTy::iterator;
+ using const_iterator = RecipeListTy::const_iterator;
+ using reverse_iterator = RecipeListTy::reverse_iterator;
+ using const_reverse_iterator = RecipeListTy::const_reverse_iterator;
//===--------------------------------------------------------------------===//
/// Recipe iterator methods
@@ -518,14 +532,6 @@ public:
return &VPBasicBlock::Recipes;
}
- VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
- : VPBlockBase(VPBasicBlockSC, Name.str()) {
- if (Recipe)
- appendRecipe(Recipe);
- }
-
- ~VPBasicBlock() { Recipes.clear(); }
-
/// Method to support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const VPBlockBase *V) {
return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC;
@@ -581,7 +587,7 @@ public:
Exit->setParent(this);
}
- ~VPRegionBlock() {
+ ~VPRegionBlock() override {
if (Entry)
deleteCFG(Entry);
}
@@ -649,7 +655,7 @@ public:
private:
/// Add to the given dominator tree the header block and every new basic block
/// that was created between it and the latch block, inclusive.
- static void updateDominatorTree(class DominatorTree *DT,
+ static void updateDominatorTree(DominatorTree *DT,
BasicBlock *LoopPreHeaderBB,
BasicBlock *LoopLatchBB);
};
@@ -667,11 +673,11 @@ private:
unsigned Depth;
unsigned TabWidth = 2;
std::string Indent;
-
unsigned BID = 0;
-
SmallDenseMap<const VPBlockBase *, unsigned> BlockID;
+ VPlanPrinter(raw_ostream &O, VPlan &P) : OS(O), Plan(P) {}
+
/// Handle indentation.
void bumpIndent(int b) { Indent = std::string((Depth += b) * TabWidth, ' '); }
@@ -701,8 +707,6 @@ private:
void drawEdge(const VPBlockBase *From, const VPBlockBase *To, bool Hidden,
const Twine &Label);
- VPlanPrinter(raw_ostream &O, VPlan &P) : OS(O), Plan(P) {}
-
void dump();
static void printAsIngredient(raw_ostream &O, Value *V);
@@ -710,6 +714,7 @@ private:
struct VPlanIngredient {
Value *V;
+
VPlanIngredient(Value *V) : V(V) {}
};
@@ -732,8 +737,8 @@ inline raw_ostream &operator<<(raw_ostream &OS, VPlan &Plan) {
// graph of VPBlockBase nodes...
template <> struct GraphTraits<VPBlockBase *> {
- typedef VPBlockBase *NodeRef;
- typedef SmallVectorImpl<VPBlockBase *>::iterator ChildIteratorType;
+ using NodeRef = VPBlockBase *;
+ using ChildIteratorType = SmallVectorImpl<VPBlockBase *>::iterator;
static NodeRef getEntryNode(NodeRef N) { return N; }
@@ -747,8 +752,8 @@ template <> struct GraphTraits<VPBlockBase *> {
};
template <> struct GraphTraits<const VPBlockBase *> {
- typedef const VPBlockBase *NodeRef;
- typedef SmallVectorImpl<VPBlockBase *>::const_iterator ChildIteratorType;
+ using NodeRef = const VPBlockBase *;
+ using ChildIteratorType = SmallVectorImpl<VPBlockBase *>::const_iterator;
static NodeRef getEntryNode(NodeRef N) { return N; }
@@ -765,11 +770,9 @@ template <> struct GraphTraits<const VPBlockBase *> {
// graph of VPBlockBase nodes... and to walk it in inverse order. Inverse order
// for a VPBlockBase is considered to be when traversing the predecessors of a
// VPBlockBase instead of its successors.
-//
-
template <> struct GraphTraits<Inverse<VPBlockBase *>> {
- typedef VPBlockBase *NodeRef;
- typedef SmallVectorImpl<VPBlockBase *>::iterator ChildIteratorType;
+ using NodeRef = VPBlockBase *;
+ using ChildIteratorType = SmallVectorImpl<VPBlockBase *>::iterator;
static Inverse<VPBlockBase *> getEntryNode(Inverse<VPBlockBase *> B) {
return B;
@@ -784,6 +787,6 @@ template <> struct GraphTraits<Inverse<VPBlockBase *>> {
}
};
-} // namespace llvm
+} // end namespace llvm
#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
OpenPOWER on IntegriCloud