Halide 22.0.0 Halide compiler and libraries

EliminateBoolVectors.h
Go to the documentation of this file.
1#ifndef HALIDE_IR_ELIMINATE_BOOL_VECTORS_H
2#define HALIDE_IR_ELIMINATE_BOOL_VECTORS_H
3
4/** \file
5 * Method to eliminate vectors of booleans from IR.
6 */
7
8#include "Expr.h"
9
10 namespace Halide {
11 namespace Internal {
12
13/** Some targets treat vectors of bools as integers of the same type that the
14 * boolean operation is being used to operate on. For example, instead of
15 * select(i1x8, u16x8, u16x8), the target would prefer to see select(u16x8,
16 * u16x8, u16x8), where the first argument is a vector of integers representing
17 * a mask. This pass converts vectors of bools to vectors of integers to meet
18 * this requirement. This is done by injecting intrinsics to convert bools to
19 * architecture-specific masks, and using a select_mask intrinsic instead of a
20 * Select node. This also converts any intrinsics that operate on vectorized
21 * conditions to a *_mask equivalent (if_then_else, require). Because the masks
22 * are architecture specific, they may not be stored or loaded. On Stores, the
23 * masks are converted to UInt(8) with a value of 0 or 1, which is our canonical
24 * in-memory representation of a bool. */
25///@{
26 Stmt eliminate_bool_vectors(const Stmt &s);
27 Expr eliminate_bool_vectors(const Expr &s);
28///@}
29
30/** If a type is a boolean vector, find the type that it has been
31 * changed to by eliminate_bool_vectors. */
32 inline Type eliminated_bool_type(Type bool_type, Type other_type) {
33 if (bool_type.is_vector() && bool_type.bits() == 1) {
34 bool_type = bool_type.with_code(Type::Int).with_bits(other_type.bits());
35 }
36 return bool_type;
37}
38
39} // namespace Internal
40} // namespace Halide
41
42#endif
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Halide::Internal::eliminated_bool_type
Type eliminated_bool_type(Type bool_type, Type other_type)
If a type is a boolean vector, find the type that it has been changed to by eliminate_bool_vectors.
Definition: EliminateBoolVectors.h:32
Halide::Internal::eliminate_bool_vectors
Stmt eliminate_bool_vectors(const Stmt &s)
Some targets treat vectors of bools as integers of the same type that the boolean operation is being ...
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:258
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition: Expr.h:427
Halide::Type
Types in the halide type system.
Definition: Type.h:283
Halide::Type::with_bits
Type with_bits(int new_bits) const
Return Type with same type code and lanes, but new_bits for the number of bits.
Definition: Type.h:366
Halide::Type::Int
static constexpr halide_type_code_t Int
Aliases for halide_type_code_t values for legacy compatibility and to match the Halide internal C++ s...
Definition: Type.h:291
Halide::Type::bits
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
Definition: Type.h:349
Halide::Type::is_vector
HALIDE_ALWAYS_INLINE bool is_vector() const
Is this type a vector type? (lanes() != 1).
Definition: Type.h:410
Halide::Type::with_code
Type with_code(halide_type_code_t new_code) const
Return Type with same number of bits and lanes, but new_code for a type code.
Definition: Type.h:360