Halide
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 
18 namespace llvm {
19 class ConstantFolder;
20 class ElementCount;
21 class Function;
22 class IRBuilderDefaultInserter;
23 class LLVMContext;
24 class Module;
25 class StructType;
26 class TargetMachine;
27 class TargetOptions;
28 class Type;
29 class Value;
30 template<typename, typename>
31 class IRBuilder;
32 } // namespace llvm
33 
34 namespace Halide {
35 
36 struct Target;
37 
38 namespace Internal {
39 
40 /** Get the scalar type of an llvm vector type. Returns the argument
41  * if it's not a vector type. */
42 llvm::Type *get_vector_element_type(llvm::Type *);
43 
44 /** Which built-in functions require a user-context first argument? */
45 bool 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}. */
55 std::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 ///@{
63 Expr lower_int_uint_div(const Expr &a, const Expr &b, bool round_to_zero = false);
64 Expr 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 ///@{
70 Expr lower_euclidean_div(Expr a, Expr b);
71 Expr lower_euclidean_mod(Expr a, Expr b);
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 ///@{
77 Expr lower_signed_shift_left(const Expr &a, const Expr &b);
78 Expr lower_signed_shift_right(const Expr &a, const Expr &b);
79 ///@}
80 
81 /** Reduce a mux intrinsic to a select tree */
82 Expr lower_mux(const Call *mux);
83 
84 /** Reduce bit extraction and concatenation to bit ops */
85 ///@{
86 Expr lower_extract_bits(const Call *c);
87 Expr lower_concat_bits(const Call *c);
88 ///@}
89 
90 /** An vectorizable implementation of Halide::round that doesn't depend on any
91  * standard library being present. */
92 Expr lower_round_to_nearest_ties_to_even(const Expr &);
93 
94 /** Given an llvm::Module, set llvm:TargetOptions information */
95 void get_target_options(const llvm::Module &module, llvm::TargetOptions &options);
96 
97 /** Given two llvm::Modules, clone target options from one to the other */
98 void clone_target_options(const llvm::Module &from, llvm::Module &to);
99 
100 /** Given an llvm::Module, get or create an llvm:TargetMachine */
101 std::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. */
110 void embed_bitcode(llvm::Module *M, const std::string &halide_command);
111 
112 } // namespace Internal
113 } // namespace Halide
114 
115 #endif
Halide::Internal::get_target_options
void get_target_options(const llvm::Module &module, llvm::TargetOptions &options)
Given an llvm::Module, set llvm:TargetOptions information.
Scope.h
llvm
Definition: CodeGen_Internal.h:18
Halide::Internal::set_function_attributes_from_halide_target_options
void set_function_attributes_from_halide_target_options(llvm::Function &)
Set the appropriate llvm Function attributes given the Halide Target.
Halide::Internal::lower_concat_bits
Expr lower_concat_bits(const Call *c)
Reduce bit extraction and concatenation to bit ops.
Halide::Internal::make_target_machine
std::unique_ptr< llvm::TargetMachine > make_target_machine(const llvm::Module &module)
Given an llvm::Module, get or create an llvm:TargetMachine.
Halide::Internal::lower_extract_bits
Expr lower_extract_bits(const Call *c)
Reduce bit extraction and concatenation to bit ops.
Halide::mux
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,...
Halide::Internal::lower_euclidean_div
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...
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:23
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::Internal::embed_bitcode
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,...
Halide::Internal::long_div_mod_round_to_zero
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.
Halide::Internal::clone_target_options
void clone_target_options(const llvm::Module &from, llvm::Module &to)
Given two llvm::Modules, clone target options from one to the other.
Halide::Internal::lower_signed_shift_left
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...
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
Halide::Internal::lower_int_uint_mod
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...
Expr.h
Halide::Internal::get_vector_element_type
llvm::Type * get_vector_element_type(llvm::Type *)
Get the scalar type of an llvm vector type.
Halide::Internal::function_takes_user_context
bool function_takes_user_context(const std::string &name)
Which built-in functions require a user-context first argument?
Halide::Internal::can_allocation_fit_on_stack
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,...
Halide::Internal::lower_mux
Expr lower_mux(const Call *mux)
Reduce a mux intrinsic to a select tree.
Halide::Internal::lower_round_to_nearest_ties_to_even
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...
Halide::Internal::lower_euclidean_mod
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...
Closure.h
llvm::IRBuilder
Definition: CodeGen_Internal.h:31
Halide::Internal::lower_int_uint_div
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...
Halide::Internal::lower_signed_shift_right
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...