2017-11-20 20:01:47 +08:00
|
|
|
//===- VPlanValue.h - Represent Values in Vectorizer Plan -----------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-11-20 20:01:47 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// This file contains the declarations of the entities induced by Vectorization
|
|
|
|
/// Plans, e.g. the instructions the VPlan intends to generate if executed.
|
|
|
|
/// VPlan models the following entities:
|
|
|
|
/// VPValue
|
|
|
|
/// |-- VPUser
|
|
|
|
/// | |-- VPInstruction
|
|
|
|
/// These are documented in docs/VectorizationPlan.rst.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
|
|
|
|
#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
// Forward declarations.
|
|
|
|
class VPUser;
|
|
|
|
|
2020-03-05 22:55:08 +08:00
|
|
|
class VPSlotTracker;
|
|
|
|
|
2017-11-20 20:01:47 +08:00
|
|
|
// This is the base class of the VPlan Def/Use graph, used for modeling the data
|
|
|
|
// flow into, within and out of the VPlan. VPValues can stand for live-ins
|
|
|
|
// coming from the input IR, instructions which VPlan will generate if executed
|
|
|
|
// and live-outs which the VPlan will need to fix accordingly.
|
|
|
|
class VPValue {
|
2018-05-22 02:14:23 +08:00
|
|
|
friend class VPBuilder;
|
2019-12-07 16:52:36 +08:00
|
|
|
friend class VPlanTransforms;
|
[VPlan] Implement initial vector code generation support for simple outer loops.
Summary:
[VPlan] Implement vector code generation support for simple outer loops.
Context: Patch Series #1 for outer loop vectorization support in LV using VPlan. (RFC: http://lists.llvm.org/pipermail/llvm-dev/2017-December/119523.html).
This patch introduces vector code generation support for simple outer loops that are currently supported in the VPlanNativePath. Changes here essentially do the following:
- force vector code generation using explicit vectorize_width
- add conservative early returns in cost model and other places for VPlanNativePath
- add code for setting up outer loop inductions
- support for widening non-induction PHIs that can result from inner loops and uniform conditional branches
- support for generating uniform inner branches
We plan to add a handful C outer loop executable tests once the initial code generation support is committed. This patch is expected to be NFC for the inner loop vectorizer path. Since we are moving in the direction of supporting outer loop vectorization in LV, it may also be time to rename classes such as InnerLoopVectorizer.
Reviewers: fhahn, rengolin, hsaito, dcaballe, mkuper, hfinkel, Ayal
Reviewed By: fhahn, hsaito
Subscribers: dmgreen, bollu, tschuett, rkruppe, rogfer01, llvm-commits
Differential Revision: https://reviews.llvm.org/D50820
llvm-svn: 342197
2018-09-14 08:36:00 +08:00
|
|
|
friend class VPBasicBlock;
|
2018-11-13 23:58:18 +08:00
|
|
|
friend class VPInterleavedAccessInfo;
|
[VPlan] Implement initial vector code generation support for simple outer loops.
Summary:
[VPlan] Implement vector code generation support for simple outer loops.
Context: Patch Series #1 for outer loop vectorization support in LV using VPlan. (RFC: http://lists.llvm.org/pipermail/llvm-dev/2017-December/119523.html).
This patch introduces vector code generation support for simple outer loops that are currently supported in the VPlanNativePath. Changes here essentially do the following:
- force vector code generation using explicit vectorize_width
- add conservative early returns in cost model and other places for VPlanNativePath
- add code for setting up outer loop inductions
- support for widening non-induction PHIs that can result from inner loops and uniform conditional branches
- support for generating uniform inner branches
We plan to add a handful C outer loop executable tests once the initial code generation support is committed. This patch is expected to be NFC for the inner loop vectorizer path. Since we are moving in the direction of supporting outer loop vectorization in LV, it may also be time to rename classes such as InnerLoopVectorizer.
Reviewers: fhahn, rengolin, hsaito, dcaballe, mkuper, hfinkel, Ayal
Reviewed By: fhahn, hsaito
Subscribers: dmgreen, bollu, tschuett, rkruppe, rogfer01, llvm-commits
Differential Revision: https://reviews.llvm.org/D50820
llvm-svn: 342197
2018-09-14 08:36:00 +08:00
|
|
|
|
2017-11-20 20:01:47 +08:00
|
|
|
private:
|
|
|
|
const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
|
|
|
|
|
|
|
|
SmallVector<VPUser *, 1> Users;
|
|
|
|
|
|
|
|
protected:
|
2018-05-22 02:14:23 +08:00
|
|
|
// Hold the underlying Value, if any, attached to this VPValue.
|
|
|
|
Value *UnderlyingVal;
|
|
|
|
|
|
|
|
VPValue(const unsigned char SC, Value *UV = nullptr)
|
|
|
|
: SubclassID(SC), UnderlyingVal(UV) {}
|
|
|
|
|
|
|
|
// DESIGN PRINCIPLE: Access to the underlying IR must be strictly limited to
|
|
|
|
// the front-end and back-end of VPlan so that the middle-end is as
|
|
|
|
// independent as possible of the underlying IR. We grant access to the
|
|
|
|
// underlying IR using friendship. In that way, we should be able to use VPlan
|
|
|
|
// for multiple underlying IRs (Polly?) by providing a new VPlan front-end,
|
|
|
|
// back-end and analysis information for the new IR.
|
|
|
|
|
|
|
|
/// Return the underlying Value attached to this VPValue.
|
|
|
|
Value *getUnderlyingValue() { return UnderlyingVal; }
|
|
|
|
|
|
|
|
// Set \p Val as the underlying Value of this VPValue.
|
|
|
|
void setUnderlyingValue(Value *Val) {
|
|
|
|
assert(!UnderlyingVal && "Underlying Value is already set.");
|
|
|
|
UnderlyingVal = Val;
|
|
|
|
}
|
2017-11-20 20:01:47 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// An enumeration for keeping track of the concrete subclass of VPValue that
|
|
|
|
/// are actually instantiated. Values of this enumeration are kept in the
|
|
|
|
/// SubclassID field of the VPValue objects. They are used for concrete
|
|
|
|
/// type identification.
|
|
|
|
enum { VPValueSC, VPUserSC, VPInstructionSC };
|
|
|
|
|
2018-05-22 02:14:23 +08:00
|
|
|
VPValue(Value *UV = nullptr) : VPValue(VPValueSC, UV) {}
|
2017-11-20 20:01:47 +08:00
|
|
|
VPValue(const VPValue &) = delete;
|
|
|
|
VPValue &operator=(const VPValue &) = delete;
|
|
|
|
|
|
|
|
/// \return an ID for the concrete type of this object.
|
|
|
|
/// This is used to implement the classof checks. This should not be used
|
|
|
|
/// for any other purpose, as the values may change as LLVM evolves.
|
|
|
|
unsigned getVPValueID() const { return SubclassID; }
|
|
|
|
|
2020-03-05 22:55:08 +08:00
|
|
|
void printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const;
|
|
|
|
void print(raw_ostream &OS, VPSlotTracker &Tracker) const;
|
2017-11-20 20:01:47 +08:00
|
|
|
|
|
|
|
unsigned getNumUsers() const { return Users.size(); }
|
|
|
|
void addUser(VPUser &User) { Users.push_back(&User); }
|
|
|
|
|
|
|
|
typedef SmallVectorImpl<VPUser *>::iterator user_iterator;
|
|
|
|
typedef SmallVectorImpl<VPUser *>::const_iterator const_user_iterator;
|
|
|
|
typedef iterator_range<user_iterator> user_range;
|
|
|
|
typedef iterator_range<const_user_iterator> const_user_range;
|
|
|
|
|
|
|
|
user_iterator user_begin() { return Users.begin(); }
|
|
|
|
const_user_iterator user_begin() const { return Users.begin(); }
|
|
|
|
user_iterator user_end() { return Users.end(); }
|
|
|
|
const_user_iterator user_end() const { return Users.end(); }
|
|
|
|
user_range users() { return user_range(user_begin(), user_end()); }
|
|
|
|
const_user_range users() const {
|
|
|
|
return const_user_range(user_begin(), user_end());
|
|
|
|
}
|
[VPlan, SLP] Add simple SLP analysis on top of VPlan.
This patch adds an initial implementation of the look-ahead SLP tree
construction described in 'Look-Ahead SLP: Auto-vectorization in the Presence
of Commutative Operations, CGO 2018 by Vasileios Porpodas, Rodrigo C. O. Rocha,
Luís F. W. Góes'.
It returns an SLP tree represented as VPInstructions, with combined
instructions represented as a single, wider VPInstruction.
This initial version does not support instructions with multiple
different users (either inside or outside the SLP tree) or
non-instruction operands; it won't generate any shuffles or
insertelement instructions.
It also just adds the analysis that builds an SLP tree rooted in a set
of stores. It does not include any cost modeling or memory legality
checks. The plan is to integrate it with VPlan based cost modeling, once
available and to only apply it to operations that can be widened.
A follow-up patch will add a support for replacing instructions in a
VPlan with their SLP counter parts.
Reviewers: Ayal, mssimpso, rengolin, mkuper, hfinkel, hsaito, dcaballe, vporpo, RKSimon, ABataev
Reviewed By: rengolin
Differential Revision: https://reviews.llvm.org/D4949
llvm-svn: 346857
2018-11-14 21:11:49 +08:00
|
|
|
|
|
|
|
/// Returns true if the value has more than one unique user.
|
|
|
|
bool hasMoreThanOneUniqueUser() {
|
|
|
|
if (getNumUsers() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check if all users match the first user.
|
|
|
|
auto Current = std::next(user_begin());
|
|
|
|
while (Current != user_end() && *user_begin() == *Current)
|
|
|
|
Current++;
|
|
|
|
return Current != user_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void replaceAllUsesWith(VPValue *New);
|
2017-11-20 20:01:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef DenseMap<Value *, VPValue *> Value2VPValueTy;
|
|
|
|
typedef DenseMap<VPValue *, Value *> VPValue2ValueTy;
|
|
|
|
|
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const VPValue &V);
|
|
|
|
|
|
|
|
/// This class augments VPValue with operands which provide the inverse def-use
|
|
|
|
/// edges from VPValue's users to their defs.
|
|
|
|
class VPUser : public VPValue {
|
|
|
|
private:
|
|
|
|
SmallVector<VPValue *, 2> Operands;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
VPUser(const unsigned char SC) : VPValue(SC) {}
|
|
|
|
VPUser(const unsigned char SC, ArrayRef<VPValue *> Operands) : VPValue(SC) {
|
|
|
|
for (VPValue *Operand : Operands)
|
|
|
|
addOperand(Operand);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
VPUser() : VPValue(VPValue::VPUserSC) {}
|
|
|
|
VPUser(ArrayRef<VPValue *> Operands) : VPUser(VPValue::VPUserSC, Operands) {}
|
|
|
|
VPUser(std::initializer_list<VPValue *> Operands)
|
|
|
|
: VPUser(ArrayRef<VPValue *>(Operands)) {}
|
|
|
|
VPUser(const VPUser &) = delete;
|
|
|
|
VPUser &operator=(const VPUser &) = delete;
|
|
|
|
|
|
|
|
/// Method to support type inquiry through isa, cast, and dyn_cast.
|
|
|
|
static inline bool classof(const VPValue *V) {
|
|
|
|
return V->getVPValueID() >= VPUserSC &&
|
|
|
|
V->getVPValueID() <= VPInstructionSC;
|
|
|
|
}
|
|
|
|
|
2018-05-22 02:14:23 +08:00
|
|
|
void addOperand(VPValue *Operand) {
|
|
|
|
Operands.push_back(Operand);
|
|
|
|
Operand->addUser(*this);
|
|
|
|
}
|
|
|
|
|
2017-11-20 20:01:47 +08:00
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
|
|
|
inline VPValue *getOperand(unsigned N) const {
|
|
|
|
assert(N < Operands.size() && "Operand index out of bounds");
|
|
|
|
return Operands[N];
|
|
|
|
}
|
|
|
|
|
[VPlan, SLP] Add simple SLP analysis on top of VPlan.
This patch adds an initial implementation of the look-ahead SLP tree
construction described in 'Look-Ahead SLP: Auto-vectorization in the Presence
of Commutative Operations, CGO 2018 by Vasileios Porpodas, Rodrigo C. O. Rocha,
Luís F. W. Góes'.
It returns an SLP tree represented as VPInstructions, with combined
instructions represented as a single, wider VPInstruction.
This initial version does not support instructions with multiple
different users (either inside or outside the SLP tree) or
non-instruction operands; it won't generate any shuffles or
insertelement instructions.
It also just adds the analysis that builds an SLP tree rooted in a set
of stores. It does not include any cost modeling or memory legality
checks. The plan is to integrate it with VPlan based cost modeling, once
available and to only apply it to operations that can be widened.
A follow-up patch will add a support for replacing instructions in a
VPlan with their SLP counter parts.
Reviewers: Ayal, mssimpso, rengolin, mkuper, hfinkel, hsaito, dcaballe, vporpo, RKSimon, ABataev
Reviewed By: rengolin
Differential Revision: https://reviews.llvm.org/D4949
llvm-svn: 346857
2018-11-14 21:11:49 +08:00
|
|
|
void setOperand(unsigned I, VPValue *New) { Operands[I] = New; }
|
|
|
|
|
2017-11-20 20:01:47 +08:00
|
|
|
typedef SmallVectorImpl<VPValue *>::iterator operand_iterator;
|
|
|
|
typedef SmallVectorImpl<VPValue *>::const_iterator const_operand_iterator;
|
|
|
|
typedef iterator_range<operand_iterator> operand_range;
|
|
|
|
typedef iterator_range<const_operand_iterator> const_operand_range;
|
|
|
|
|
|
|
|
operand_iterator op_begin() { return Operands.begin(); }
|
|
|
|
const_operand_iterator op_begin() const { return Operands.begin(); }
|
|
|
|
operand_iterator op_end() { return Operands.end(); }
|
|
|
|
const_operand_iterator op_end() const { return Operands.end(); }
|
|
|
|
operand_range operands() { return operand_range(op_begin(), op_end()); }
|
|
|
|
const_operand_range operands() const {
|
|
|
|
return const_operand_range(op_begin(), op_end());
|
|
|
|
}
|
|
|
|
};
|
2020-03-05 22:55:08 +08:00
|
|
|
class VPlan;
|
|
|
|
class VPBasicBlock;
|
|
|
|
class VPRegionBlock;
|
|
|
|
|
|
|
|
/// This class can be used to assign consecutive numbers to all VPValues in a
|
|
|
|
/// VPlan and allows querying the numbering for printing, similar to the
|
|
|
|
/// ModuleSlotTracker for IR values.
|
|
|
|
class VPSlotTracker {
|
|
|
|
private:
|
|
|
|
DenseMap<const VPValue *, unsigned> Slots;
|
|
|
|
unsigned NextSlot = 0;
|
|
|
|
|
|
|
|
void assignSlots(const VPBlockBase *VPBB);
|
|
|
|
void assignSlots(const VPRegionBlock *Region);
|
|
|
|
void assignSlots(const VPBasicBlock *VPBB);
|
|
|
|
void assignSlot(const VPValue *V);
|
|
|
|
|
|
|
|
void assignSlots(const VPlan &Plan);
|
|
|
|
|
|
|
|
public:
|
|
|
|
VPSlotTracker(const VPlan *Plan) {
|
|
|
|
if (Plan)
|
|
|
|
assignSlots(*Plan);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getSlot(const VPValue *V) const {
|
|
|
|
auto I = Slots.find(V);
|
|
|
|
if (I == Slots.end())
|
|
|
|
return -1;
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
};
|
2017-11-20 20:01:47 +08:00
|
|
|
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
|