32 using EdgeMaskCacheTy =
33 DenseMap<std::pair<const VPBasicBlock *, const VPBasicBlock *>,
35 using BlockMaskCacheTy = DenseMap<VPBasicBlock *, VPValue *>;
36 EdgeMaskCacheTy EdgeMaskCache;
38 BlockMaskCacheTy BlockMaskCache;
41 void createSwitchEdgeMasks(VPInstruction *SI);
45 VPValue *createEdgeMask(VPBasicBlock *Src, VPBasicBlock *Dst);
49 void setBlockInMask(VPBasicBlock *VPBB, VPValue *Mask) {
52 assert(!getBlockInMask(VPBB) &&
"Mask already set");
53 BlockMaskCache[VPBB] =
Mask;
58 VPValue *setEdgeMask(
const VPBasicBlock *Src,
const VPBasicBlock *Dst,
60 assert(Src != Dst &&
"Src and Dst must be different");
61 assert(!getEdgeMask(Src, Dst) &&
"Mask already set");
62 return EdgeMaskCache[{Src, Dst}] =
Mask;
67 VPValue *getBlockInMask(VPBasicBlock *VPBB)
const {
68 return BlockMaskCache.
lookup(VPBB);
72 VPValue *getEdgeMask(
const VPBasicBlock *Src,
const VPBasicBlock *Dst)
const {
73 return EdgeMaskCache.
lookup({Src, Dst});
77 void createHeaderMask(VPBasicBlock *HeaderVPBB,
bool FoldTail);
81 void createBlockInMask(VPBasicBlock *VPBB);
84 void convertPhisToBlends(VPBasicBlock *VPBB);
92 VPValue *EdgeMask = getEdgeMask(Src, Dst);
96 VPValue *SrcMask = getBlockInMask(Src);
99 if (Src->getNumSuccessors() == 1)
100 return setEdgeMask(Src, Dst, SrcMask);
103 if (
Term->getOpcode() == Instruction::Switch) {
104 createSwitchEdgeMasks(Term);
105 return getEdgeMask(Src, Dst);
109 "Unsupported terminator");
110 if (Src->getSuccessors()[0] == Src->getSuccessors()[1])
111 return setEdgeMask(Src, Dst, SrcMask);
113 EdgeMask =
Term->getOperand(0);
114 assert(EdgeMask &&
"No Edge Mask found for condition");
116 if (Src->getSuccessors()[0] != Dst)
126 return setEdgeMask(Src, Dst, EdgeMask);
129void VPPredicator::createBlockInMask(VPBasicBlock *VPBB) {
134 VPValue *BlockMask =
nullptr;
136 for (
auto *Predecessor : SetVector<VPBlockBase *>(
141 setBlockInMask(VPBB, EdgeMask);
146 BlockMask = EdgeMask;
150 BlockMask = Builder.
createOr(BlockMask, EdgeMask, {});
153 setBlockInMask(VPBB, BlockMask);
156void VPPredicator::createHeaderMask(VPBasicBlock *HeaderVPBB,
bool FoldTail) {
158 setBlockInMask(HeaderVPBB,
nullptr);
167 auto &Plan = *HeaderVPBB->
getPlan();
173 VPValue *BTC = Plan.getOrCreateBackedgeTakenCount();
175 setBlockInMask(HeaderVPBB, BlockMask);
178void VPPredicator::createSwitchEdgeMasks(VPInstruction *SI) {
179 VPBasicBlock *Src =
SI->getParent();
184 VPValue *
Cond =
SI->getOperand(0);
186 MapVector<VPBasicBlock *, SmallVector<VPValue *>> Dst2Compares;
189 assert(!getEdgeMask(Src, Dst) &&
"Edge masks already created");
192 if (Dst == DefaultDst)
194 auto &Compares = Dst2Compares[Dst];
195 VPValue *
V =
SI->getOperand(Idx + 1);
201 VPValue *SrcMask = getBlockInMask(Src);
202 VPValue *DefaultMask =
nullptr;
203 for (
const auto &[Dst, Conds] : Dst2Compares) {
207 VPValue *
Mask = Conds[0];
212 setEdgeMask(Src, Dst, Mask);
218 DefaultMask = DefaultMask ? Builder.
createOr(DefaultMask, Mask) :
Mask;
222 DefaultMask = Builder.
createNot(DefaultMask);
228 DefaultMask = SrcMask;
230 setEdgeMask(Src, DefaultDst, DefaultMask);
233void VPPredicator::convertPhisToBlends(VPBasicBlock *VPBB) {
235 for (VPRecipeBase &R : VPBB->
phis())
237 for (VPPhi *PhiR : Phis) {
245 return !match(V, m_Poison());
248 PhiR->replaceAllUsesWith(NotPoison.empty() ? PhiR->getIncomingValue(0)
249 : *NotPoison.begin());
250 PhiR->eraseFromParent();
255 for (
const auto &[InVPV, InVPBB] : PhiR->incoming_values_and_blocks()) {
257 OperandsWithMask.
push_back(getEdgeMask(InVPBB, VPBB));
261 new VPBlendRecipe(IRPhi, OperandsWithMask, *PhiR, PhiR->getDebugLoc());
263 PhiR->replaceAllUsesWith(Blend);
264 PhiR->eraseFromParent();
282 if (VPBB == Header) {
283 Predicator.createHeaderMask(Header, FoldTail);
296 VPI->addMask(BlockMask);
304 if (Successors.size() > 1)
309 for (
auto *Succ : Successors)
323 "only a single-exit block is supported currently");
326 "the exit block must have middle block as single predecessor");
340 R.getVPSingleValue()->replaceAllUsesWith(Ext);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > & Cond
This file contains the declarations of the Vectorization Plan base classes:
static const uint32_t IV[8]
@ ICMP_ULE
unsigned less or equal
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
void push_back(const T &Elt)
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
VPRecipeBase * getTerminator()
If the block has multiple successors, return the branch recipe terminating the block.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
VPRegionBlock * getParent()
const VPBlocksTy & getPredecessors() const
const VPBasicBlock * getEntryBasicBlock() const
const VPBlocksTy & getSuccessors() const
static auto blocksOnly(const T &Range)
Return an iterator range over Range which only includes BlockTy blocks.
static void connectBlocks(VPBlockBase *From, VPBlockBase *To, unsigned PredIdx=-1u, unsigned SuccIdx=-1u)
Connect VPBlockBases From and To bi-directionally.
static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To)
Disconnect VPBlockBases From and To bi-directionally.
VPlan-based builder utility analogous to IRBuilder.
VPInstruction * createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
VPInstruction * createNot(VPValue *Operand, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
VPInstruction * createLogicalAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
void insert(VPRecipeBase *R)
Insert R at the current insertion point.
VPInstruction * createICmp(CmpInst::Predicate Pred, VPValue *A, VPValue *B, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
Create a new ICmp VPInstruction with predicate Pred and operands A and B.
void setInsertPoint(VPBasicBlock *TheBB)
This specifies that created VPInstructions should be appended to the end of the specified block.
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the region.
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
VPBasicBlock * getMiddleBlock()
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool match(Val *V, const Pattern &P)
VPInstruction_match< VPInstruction::ExtractLastLane, Op0_t > m_ExtractLastLane(const Op0_t &Op0)
VPInstruction_match< VPInstruction::ExtractLastPart, Op0_t > m_ExtractLastPart(const Op0_t &Op0)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto cast_or_null(const Y &Val)
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.