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"
20
21namespace llvm {
22class DataLayout;
23class FastMathFlags;
24class IRBuilderBase;
25class Instruction;
26class PHINode;
27class Type;
28class Value;
29enum class RecurKind;
30} // namespace llvm
31
32namespace llvm::slpvectorizer {
33
34struct NarrowedLeafInfo;
35
36/// The result of matching a boolean bitmask reduction over narrowed leaves.
37enum class BoolBitmask {
38 None, // not a boolean bitmask reduction
39 NoMask, // bitmask; the absorbed masks are redundant
40 NeedMask, // bitmask; the absorbed masks must be applied before the zero test
41};
42
43/// \returns the wide leaf type if the logical and/or reduction \p RdxKind
44/// with the i1 root type \p RootTy and the leaf type \p LeafTy is a
45/// booleanized reduction (performed in the wide leaf type, bit 0 of the
46/// result is the final value), nullptr otherwise.
47Type *getBoolReduxWideTy(RecurKind RdxKind, Type *RootTy, Type *LeafTy);
48
49/// \returns the BoolBitmask match if the or-reduction of the narrowed leaves
50/// packs each boolean (0 or 1 after masking) leaf into its own bit position
51/// 0..N-1, i.e. it is a bitcast of the per-lane zero tests to an iN integer;
52/// BoolBitmask::None otherwise.
54 RecurKind RdxKind,
55 const SmallDenseMap<Value *, NarrowedLeafInfo> &NarrowedLeafShifts,
56 const DataLayout &DL);
57
58/// \returns the first operand of \p I that does not match \p Phi. If
59/// the operand is not an instruction, returns nullptr.
61
62/// \returns true if \p I is a candidate instruction for reduction
63/// vectorization.
65
66/// Emits the booleanized logical and/or reduction of \p Vec with the i1 root
67/// \p Root as trunc+bitcast+cmp (all-ones comparison for And, zero for Or) if
68/// it is cheaper than the wide reduction plus the result trunc. \returns the
69/// i1 result or nullptr if the wide reduction form is cheaper.
72 RecurKind RdxKind, Value *Vec,
73 const Value *Root, FastMathFlags FMF,
75
76} // namespace llvm::slpvectorizer
77
78#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPREDUCTIONUTILS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:57
This pass exposes codegen information to IR-level passes.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
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.
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...
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:396