Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
CodeGen_Internal.h
Go to the documentation of this file.
1#ifndef HALIDE_CODEGEN_INTERNAL_H
2#define HALIDE_CODEGEN_INTERNAL_H
3
4/** \file
5 *
6 * Defines functionality that's useful to multiple target-specific
7 * CodeGen paths, but shouldn't live in CodeGen_LLVM.h (because that's the
8 * front-end-facing interface to CodeGen).
9 */
10
11#include <memory>
12#include <string>
13
14#include "Closure.h"
15#include "Expr.h"
16#include "Scope.h"
17
18namespace llvm {
19class ConstantFolder;
20class ElementCount;
21class Function;
22class IRBuilderDefaultInserter;
23class LLVMContext;
24class Module;
25class StructType;
26class TargetMachine;
27class TargetOptions;
28class Type;
29class Value;
30template<typename, typename>
31class IRBuilder;
32} // namespace llvm
33
34namespace Halide {
35
36struct Target;
37
38namespace Internal {
39
40/** Get the scalar type of an llvm vector type. Returns the argument
41 * if it's not a vector type. */
42llvm::Type *get_vector_element_type(llvm::Type *);
43
44/** Which built-in functions require a user-context first argument? */
45bool function_takes_user_context(const std::string &name);
46
47/** Given a size (in bytes), return True if the allocation size can fit
48 * on the stack; otherwise, return False. This routine asserts if size is
49 * non-positive. */
51
52/** Does a {div/mod}_round_to_zero using binary long division for int/uint.
53 * max_abs is the maximum absolute value of (a/b).
54 * Returns the pair {div_round_to_zero, mod_round_to_zero}. */
55std::pair<Expr, Expr> long_div_mod_round_to_zero(const Expr &a, const Expr &b,
56 const uint64_t *max_abs = nullptr);
57
58/** Given a Halide Euclidean division/mod operation, do constant optimizations
59 * and possibly call lower_euclidean_div/lower_euclidean_mod if necessary.
60 * Can introduce mulhi_shr and sorted_avg intrinsics as well as those from the
61 * lower_euclidean_ operation -- div_round_to_zero or mod_round_to_zero. */
62///@{
63Expr lower_int_uint_div(const Expr &a, const Expr &b, bool round_to_zero = false);
64Expr lower_int_uint_mod(const Expr &a, const Expr &b);
65///@}
66
67/** Given a Halide Euclidean division/mod operation, define it in terms of
68 * div_round_to_zero or mod_round_to_zero. */
69///@{
72///@}
73
74/** Given a Halide shift operation with a signed shift amount (may be negative), define
75 * an equivalent expression using only shifts by unsigned amounts. */
76///@{
79///@}
80
81/** Reduce a mux intrinsic to a select tree */
83
84/** Reduce bit extraction and concatenation to bit ops */
85///@{
88///@}
89
90/** An vectorizable implementation of Halide::round that doesn't depend on any
91 * standard library being present. */
93
94/** Given an llvm::Module, set llvm:TargetOptions information */
95void get_target_options(const llvm::Module &module, llvm::TargetOptions &options);
96
97/** Given two llvm::Modules, clone target options from one to the other */
98void clone_target_options(const llvm::Module &from, llvm::Module &to);
99
100/** Given an llvm::Module, get or create an llvm:TargetMachine */
101std::unique_ptr<llvm::TargetMachine> make_target_machine(const llvm::Module &module);
102
103/** Set the appropriate llvm Function attributes given the Halide Target. */
105
106/** Save a copy of the llvm IR currently represented by the module as
107 * data in the __LLVM,__bitcode section. Emulates clang's
108 * -fembed-bitcode flag and is useful to satisfy Apple's bitcode
109 * inclusion requirements. */
110void embed_bitcode(llvm::Module *M, const std::string &halide_command);
111
112} // namespace Internal
113} // namespace Halide
114
115#endif
Provides Closure class.
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines the Scope class, which is used for keeping track of names in a scope while traversing IR.
void set_function_attributes_from_halide_target_options(llvm::Function &)
Set the appropriate llvm Function attributes given the Halide Target.
void clone_target_options(const llvm::Module &from, llvm::Module &to)
Given two llvm::Modules, clone target options from one to the other.
Expr lower_int_uint_div(const Expr &a, const Expr &b, bool round_to_zero=false)
Given a Halide Euclidean division/mod operation, do constant optimizations and possibly call lower_eu...
Expr lower_signed_shift_right(const Expr &a, const Expr &b)
Given a Halide shift operation with a signed shift amount (may be negative), define an equivalent exp...
void embed_bitcode(llvm::Module *M, const std::string &halide_command)
Save a copy of the llvm IR currently represented by the module as data in the __LLVM,...
Expr lower_int_uint_mod(const Expr &a, const Expr &b)
Given a Halide Euclidean division/mod operation, do constant optimizations and possibly call lower_eu...
bool can_allocation_fit_on_stack(int64_t size)
Given a size (in bytes), return True if the allocation size can fit on the stack; otherwise,...
std::pair< Expr, Expr > long_div_mod_round_to_zero(const Expr &a, const Expr &b, const uint64_t *max_abs=nullptr)
Does a {div/mod}_round_to_zero using binary long division for int/uint.
Expr lower_mux(const Call *mux)
Reduce a mux intrinsic to a select tree.
Expr lower_concat_bits(const Call *c)
Reduce bit extraction and concatenation to bit ops.
llvm::Type * get_vector_element_type(llvm::Type *)
Get the scalar type of an llvm vector type.
Expr lower_signed_shift_left(const Expr &a, const Expr &b)
Given a Halide shift operation with a signed shift amount (may be negative), define an equivalent exp...
std::unique_ptr< llvm::TargetMachine > make_target_machine(const llvm::Module &module)
Given an llvm::Module, get or create an llvm:TargetMachine.
Expr lower_euclidean_div(Expr a, Expr b)
Given a Halide Euclidean division/mod operation, define it in terms of div_round_to_zero or mod_round...
Expr lower_round_to_nearest_ties_to_even(const Expr &)
An vectorizable implementation of Halide::round that doesn't depend on any standard library being pre...
bool function_takes_user_context(const std::string &name)
Which built-in functions require a user-context first argument?
void get_target_options(const llvm::Module &module, llvm::TargetOptions &options)
Given an llvm::Module, set llvm:TargetOptions information.
Expr lower_euclidean_mod(Expr a, Expr b)
Given a Halide Euclidean division/mod operation, define it in terms of div_round_to_zero or mod_round...
Expr lower_extract_bits(const Call *c)
Reduce bit extraction and concatenation to bit ops.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Expr mux(const Expr &id, const std::initializer_list< Expr > &values)
Oftentimes we want to pack a list of expressions with the same type into a channel dimension,...
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
A fragment of Halide syntax.
Definition Expr.h:258
A function call.
Definition IR.h:490