35 VPPostDominatorTree VPPDT;
39 using EdgeMaskCacheTy =
40 DenseMap<std::pair<const VPBasicBlock *, const VPBasicBlock *>,
42 using BlockMaskCacheTy = DenseMap<const VPBasicBlock *, VPValue *>;
43 EdgeMaskCacheTy EdgeMaskCache;
45 BlockMaskCacheTy BlockMaskCache;
48 void createSwitchEdgeMasks(
const VPInstruction *SI);
52 VPValue *createEdgeMask(
const VPBasicBlock *Src,
const VPBasicBlock *Dst);
56 void setBlockInMask(
const VPBasicBlock *VPBB, VPValue *Mask) {
59 assert(!getBlockInMask(VPBB) &&
"Mask already set");
60 BlockMaskCache[VPBB] =
Mask;
65 VPValue *setEdgeMask(
const VPBasicBlock *Src,
const VPBasicBlock *Dst,
67 assert(Src != Dst &&
"Src and Dst must be different");
68 assert(!getEdgeMask(Src, Dst) &&
"Mask already set");
69 return EdgeMaskCache[{Src, Dst}] =
Mask;
73 VPPredicator(VPlan &Plan) : VPDT(Plan), VPPDT(Plan) {}
76 VPValue *getBlockInMask(
const VPBasicBlock *VPBB)
const {
77 return BlockMaskCache.
lookup(VPBB);
81 VPValue *getEdgeMask(
const VPBasicBlock *Src,
const VPBasicBlock *Dst)
const {
82 return EdgeMaskCache.
lookup({Src, Dst});
86 void createBlockInMask(VPBasicBlock *VPBB);
89 void convertPhisToBlends(VPBasicBlock *VPBB);
98 VPValue *EdgeMask = getEdgeMask(Src, Dst);
102 VPValue *SrcMask = getBlockInMask(Src);
105 if (Src->getNumSuccessors() == 1)
106 return setEdgeMask(Src, Dst, SrcMask);
109 if (
Term->getOpcode() == Instruction::Switch) {
110 createSwitchEdgeMasks(Term);
111 return getEdgeMask(Src, Dst);
115 "Unsupported terminator");
116 if (Src->getSuccessors()[0] == Src->getSuccessors()[1])
117 return setEdgeMask(Src, Dst, SrcMask);
119 EdgeMask =
Term->getOperand(0);
120 assert(EdgeMask &&
"No Edge Mask found for condition");
122 if (Src->getSuccessors()[0] != Dst)
132 return setEdgeMask(Src, Dst, EdgeMask);
135void VPPredicator::createBlockInMask(VPBasicBlock *VPBB) {
142 assert(IDom &&
"Block in loop must have immediate dominator");
145 setBlockInMask(VPBB, getBlockInMask(IDomBB));
150 VPValue *BlockMask =
nullptr;
152 for (
auto *Predecessor : SetVector<VPBlockBase *>(
157 setBlockInMask(VPBB, EdgeMask);
162 BlockMask = EdgeMask;
166 BlockMask = Builder.
createOr(BlockMask, EdgeMask, {});
169 setBlockInMask(VPBB, BlockMask);
172void VPPredicator::createSwitchEdgeMasks(
const VPInstruction *SI) {
173 const VPBasicBlock *Src =
SI->getParent();
178 VPValue *
Cond =
SI->getOperand(0);
180 MapVector<VPBasicBlock *, SmallVector<VPValue *>> Dst2Compares;
183 assert(!getEdgeMask(Src, Dst) &&
"Edge masks already created");
186 if (Dst == DefaultDst)
188 auto &Compares = Dst2Compares[Dst];
189 VPValue *
V =
SI->getOperand(Idx + 1);
195 VPValue *SrcMask = getBlockInMask(Src);
196 VPValue *DefaultMask =
nullptr;
197 for (
const auto &[Dst, Conds] : Dst2Compares) {
201 VPValue *
Mask = Conds[0];
206 setEdgeMask(Src, Dst, Mask);
212 DefaultMask = DefaultMask ? Builder.
createOr(DefaultMask, Mask) :
Mask;
216 DefaultMask = Builder.
createNot(DefaultMask);
222 DefaultMask = SrcMask;
224 setEdgeMask(Src, DefaultDst, DefaultMask);
227void VPPredicator::convertPhisToBlends(VPBasicBlock *VPBB) {
229 for (VPRecipeBase &R : VPBB->
phis())
231 for (VPPhi *PhiR : Phis) {
239 return !match(V, m_Poison());
242 PhiR->replaceAllUsesWith(NotPoison.empty() ? PhiR->getIncomingValue(0)
243 : *NotPoison.begin());
244 PhiR->eraseFromParent();
249 for (
const auto &[InVPV, InVPBB] : PhiR->incoming_values_and_blocks()) {
251 OperandsWithMask.
push_back(createEdgeMask(InVPBB, VPBB));
255 new VPBlendRecipe(IRPhi, OperandsWithMask, *PhiR, PhiR->getDebugLoc());
257 PhiR->replaceAllUsesWith(Blend);
258 PhiR->eraseFromParent();
276 if (VPBB != Header) {
288 VPI->addMask(BlockMask);
296 if (Successors.size() > 1)
301 for (
auto *Succ : Successors)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > & Cond
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
This file contains the declarations of the Vectorization Plan base classes:
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...
DomTreeNodeBase * getIDom() const
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
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.
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.
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.
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...
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...
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
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.
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...
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.