LLVM 24.0.0git
SLPReductionUtils.h
Go to the documentation of this file.
1//===- SLPReductionUtils.h - SLP reduction match helpers -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Internal header used by SLPVectorizer.cpp. It declares free reduction
10// pattern-match helpers that do not depend on BoUpSLP or any other SLP-private
11// type.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H
16#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H
17
18#include "llvm/ADT/DenseMap.h"
22
23namespace llvm {
24class BasicBlock;
25class DataLayout;
26class DominatorTree;
27class FastMathFlags;
28class IRBuilderBase;
29class Instruction;
30class LoopInfo;
31class PHINode;
32class ScalarEvolution;
33class Type;
34class Value;
35enum class RecurKind;
36} // namespace llvm
37
38namespace llvm::slpvectorizer {
39
40struct NarrowedLeafInfo;
41
42/// The result of matching a boolean bitmask reduction over narrowed leaves.
43enum class BoolBitmask {
44 None, // not a boolean bitmask reduction
45 NoMask, // bitmask; the absorbed masks are redundant
46 NeedMask, // bitmask; the absorbed masks must be applied before the zero test
47};
48
49/// \returns the wide leaf type if the logical and/or reduction \p RdxKind
50/// with the i1 root type \p RootTy and the leaf type \p LeafTy is a
51/// booleanized reduction (performed in the wide leaf type, bit 0 of the
52/// result is the final value), nullptr otherwise.
53Type *getBoolReduxWideTy(RecurKind RdxKind, Type *RootTy, Type *LeafTy);
54
55/// \returns the BoolBitmask match if the or-reduction of the narrowed leaves
56/// packs each boolean (0 or 1 after masking) leaf into its own bit position
57/// 0..N-1, i.e. it is a bitcast of the per-lane zero tests to an iN integer;
58/// BoolBitmask::None otherwise.
60 RecurKind RdxKind,
61 const SmallDenseMap<Value *, NarrowedLeafInfo> &NarrowedLeafShifts,
62 const DataLayout &DL);
63
64/// Matches \p V as the zero-extended fields, placed one after another from the
65/// lowest bit and filling \p V completely. The instructions are looked through
66/// up to \p MaxDepth. Appends the fields in the order of their positions to
67/// \p Fields and the instructions of the pack to \p Chain.
68bool matchPackedFields(Value *V, unsigned MaxDepth,
71
72/// \returns the first operand of \p I that does not match \p Phi. If
73/// the operand is not an instruction, returns nullptr.
75
76/// \returns true if \p I is a candidate instruction for reduction
77/// vectorization.
79
80/// Checks if the reduction, rooted at \p Root, reduces the loop accumulators,
81/// whose updates are the same expressions \p Shape in the same block, loading
82/// from consecutive addresses at each position. Such a reduction vectorizes
83/// along its own reduced values without gathers, while a tree across several
84/// such reductions transposes them. The different update expressions may form
85/// the nodes, which the other reductions, sharing them, cannot reuse. An empty
86/// \p Shape is set to the expressions of \p Root, \p Accs collects the
87/// accumulators.
89 const DataLayout &DL,
91 unsigned MaxDepth,
94
95/// Emits the booleanized logical and/or reduction of \p Vec with the i1 root
96/// \p Root as trunc+bitcast+cmp (all-ones comparison for And, zero for Or) if
97/// it is cheaper than the wide reduction plus the result trunc. \returns the
98/// i1 result or nullptr if the wide reduction form is cheaper.
101 RecurKind RdxKind, Value *Vec,
102 const Value *Root, FastMathFlags FMF,
104
105/// Try to get a reduction instruction from phi node \p P in block \p ParentBB,
106/// considering incoming values from \p ParentBB or the containing loop latch.
107/// \returns a candidate reduction value, or nullptr if none.
109 BasicBlock *ParentBB, LoopInfo *LI);
110
111} // namespace llvm::slpvectorizer
112
113#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This pass exposes codegen information to IR-level passes.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
Common base class shared among various IRBuilders.
Definition IRBuilder.h:111
The main scalar evolution driver.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
A private "module" namespace for types and utilities used by this pass.
bool matchPackedFields(Value *V, unsigned MaxDepth, SmallVectorImpl< Value * > &Fields, SmallVectorImpl< Instruction * > &Chain)
Matches V as the zero-extended fields, placed one after another from the lowest bit and filling V com...
Instruction * getReductionInstr(const DominatorTree *DT, PHINode *P, BasicBlock *ParentBB, LoopInfo *LI)
Try to get a reduction instruction from phi node P in block ParentBB, considering incoming values fro...
Type * getBoolReduxWideTy(RecurKind RdxKind, Type *RootTy, Type *LeafTy)
Value * tryEmitBoolReduxBitcastCmp(IRBuilderBase &Builder, const TargetTransformInfo &TTI, RecurKind RdxKind, Value *Vec, const Value *Root, FastMathFlags FMF, const TTI::TargetCostKind CostKind)
Emits the booleanized logical and/or reduction of Vec with the i1 root Root as trunc+bitcast+cmp (all...
bool isReductionOfConsecutiveAccumulators(Instruction *Root, const LoopInfo &LI, const DataLayout &DL, ScalarEvolution &SE, unsigned MaxDepth, SmallVectorImpl< unsigned > &Shape, SmallPtrSetImpl< PHINode * > &Accs)
Checks if the reduction, rooted at Root, reduces the loop accumulators, whose updates are the same ex...
BoolBitmask isBoolBitmaskRdx(RecurKind RdxKind, const SmallDenseMap< Value *, NarrowedLeafInfo > &NarrowedLeafShifts, const DataLayout &DL)
Instruction * getNonPhiOperand(Instruction *I, PHINode *Phi)
bool isReductionCandidate(Instruction *I)
BoolBitmask
The result of matching a boolean bitmask reduction over narrowed leaves.
This is an optimization pass for GlobalISel generic memory operations.
TargetTransformInfo TTI
RecurKind
These are the kinds of recurrences that we support.
Narrow reduction leaf: the value, the shift applied after widening and the mask applied in the narrow...
Definition SLPUtils.h:455