Skip to content

Commit

Permalink
[SLP][NFC]Format and improve function, returning std::optional<struct>,
Browse files Browse the repository at this point in the history
NFC.
  • Loading branch information
alexey-bataev committed Feb 24, 2023
1 parent b3185bd commit 6e30dff
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Expand Up @@ -294,7 +294,7 @@ static bool isCommutative(Instruction *I) {
/// \returns inserting index of InsertElement or InsertValue instruction,
/// using Offset as base offset for index.
static std::optional<unsigned> getInsertIndex(const Value *InsertInst,
unsigned Offset = 0) {
unsigned Offset = 0) {
int Index = Offset;
if (const auto *IE = dyn_cast<InsertElementInst>(InsertInst)) {
const auto *VT = dyn_cast<FixedVectorType>(IE->getType());
Expand Down Expand Up @@ -1200,7 +1200,8 @@ class BoUpSLP {
/// reordered and return the most optimal order.
/// \param TopToBottom If true, include the order of vectorized stores and
/// insertelement nodes, otherwise skip them.
std::optional<OrdersType> getReorderingData(const TreeEntry &TE, bool TopToBottom);
std::optional<OrdersType> getReorderingData(const TreeEntry &TE,
bool TopToBottom);

/// Reorders the current graph to the most profitable order starting from the
/// root node to the leaf nodes. The best order is chosen only from the nodes
Expand Down Expand Up @@ -1798,9 +1799,10 @@ class BoUpSLP {
// Search all operands in Ops[*][Lane] for the one that matches best
// Ops[OpIdx][LastLane] and return its opreand index.
// If no good match can be found, return std::nullopt.
std::optional<unsigned> getBestOperand(unsigned OpIdx, int Lane, int LastLane,
ArrayRef<ReorderingMode> ReorderingModes,
ArrayRef<Value *> MainAltOps) {
std::optional<unsigned>
getBestOperand(unsigned OpIdx, int Lane, int LastLane,
ArrayRef<ReorderingMode> ReorderingModes,
ArrayRef<Value *> MainAltOps) {
unsigned NumOperands = getNumOperands();

// The operand of the previous lane at OpIdx.
Expand Down Expand Up @@ -2812,7 +2814,8 @@ class BoUpSLP {
#endif

/// Create a new VectorizableTree entry.
TreeEntry *newTreeEntry(ArrayRef<Value *> VL, std::optional<ScheduleData *> Bundle,
TreeEntry *newTreeEntry(ArrayRef<Value *> VL,
std::optional<ScheduleData *> Bundle,
const InstructionsState &S,
const EdgeInfo &UserTreeIdx,
ArrayRef<int> ReuseShuffleIndices = std::nullopt,
Expand Down Expand Up @@ -3768,10 +3771,8 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE) {
return false;
return true;
};
if (IsIdentityOrder(CurrentOrder)) {
CurrentOrder.clear();
return CurrentOrder;
}
if (IsIdentityOrder(CurrentOrder))
return OrdersType();
auto *It = CurrentOrder.begin();
for (unsigned I = 0; I < NumScalars;) {
if (UsedPositions.test(I)) {
Expand All @@ -3784,7 +3785,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE) {
}
++It;
}
return CurrentOrder;
return std::move(CurrentOrder);
}
return std::nullopt;
}
Expand Down Expand Up @@ -3977,7 +3978,7 @@ BoUpSLP::findPartiallyOrderedLoads(const BoUpSLP::TreeEntry &TE) {

BoUpSLP::OrdersType Order;
if (clusterSortPtrAccesses(Ptrs, ScalarTy, *DL, *SE, Order))
return Order;
return std::move(Order);
return std::nullopt;
}

Expand Down Expand Up @@ -4026,8 +4027,8 @@ static bool areTwoInsertFromSameBuildVector(
return false;
}

std::optional<BoUpSLP::OrdersType> BoUpSLP::getReorderingData(const TreeEntry &TE,
bool TopToBottom) {
std::optional<BoUpSLP::OrdersType>
BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) {
// No need to reorder if need to shuffle reuses, still need to shuffle the
// node.
if (!TE.ReuseShuffleIndices.empty()) {
Expand Down Expand Up @@ -4081,8 +4082,8 @@ std::optional<BoUpSLP::OrdersType> BoUpSLP::getReorderingData(const TreeEntry &T
}
if (all_of(enumerate(ResOrder),
[](const auto &Data) { return Data.index() == Data.value(); }))
return {}; // Use identity order.
return ResOrder;
return std::nullopt; // No need to reorder.
return std::move(ResOrder);
}
if (TE.State == TreeEntry::Vectorize &&
(isa<LoadInst, ExtractElementInst, ExtractValueInst>(TE.getMainOp()) ||
Expand Down Expand Up @@ -4138,8 +4139,8 @@ std::optional<BoUpSLP::OrdersType> BoUpSLP::getReorderingData(const TreeEntry &T
for (unsigned Id = 0, Sz = Phis.size(); Id < Sz; ++Id)
ResOrder[Id] = PhiToId[Phis[Id]];
if (IsIdentityOrder(ResOrder))
return {};
return ResOrder;
return std::nullopt; // No need to reorder.
return std::move(ResOrder);
}
if (TE.State == TreeEntry::NeedToGather) {
// TODO: add analysis of other gather nodes with extractelement
Expand All @@ -4165,7 +4166,7 @@ std::optional<BoUpSLP::OrdersType> BoUpSLP::getReorderingData(const TreeEntry &T
if (Reuse || !CurrentOrder.empty()) {
if (!CurrentOrder.empty())
fixupOrderingIndices(CurrentOrder);
return CurrentOrder;
return std::move(CurrentOrder);
}
}
if (std::optional<OrdersType> CurrentOrder = findReusedOrderedScalars(TE))
Expand Down

0 comments on commit 6e30dff

Please sign in to comment.