Loading...
Searching...
No Matches
CodeGen_Internal.h
Go to the documentation of this file.
#ifndef HALIDE_CODEGEN_INTERNAL_H
#define HALIDE_CODEGEN_INTERNAL_H
/** \file
*
* Defines functionality that's useful to multiple target-specific
* CodeGen paths, but shouldn't live in CodeGen_LLVM.h (because that's the
* front-end-facing interface to CodeGen).
*/
#include <memory>
#include <string>
#include "Closure.h"
#include "Expr.h"
#include "Scope.h"
namespace llvm {
class ConstantFolder;
class ElementCount;
class Function;
class IRBuilderDefaultInserter;
class LLVMContext;
class Module;
class StructType;
class TargetMachine;
class TargetOptions;
class Type;
class Value;
template<typename, typename>
class IRBuilder;
} // namespace llvm
namespace Halide {
struct Target;
namespace Internal {
/** Get the scalar type of an llvm vector type. Returns the argument
* if it's not a vector type. */
llvm::Type *get_vector_element_type(llvm::Type *);
/** Which built-in functions require a user-context first argument? */
bool function_takes_user_context(const std::string &name);
/** Given a size (in bytes), return True if the allocation size can fit
* on the stack; otherwise, return False. This routine asserts if size is
* non-positive. */
bool can_allocation_fit_on_stack(int64_t size);
/** Does a {div/mod}_round_to_zero using binary long division for int/uint.
* max_abs is the maximum absolute value of (a/b).
* Returns the pair {div_round_to_zero, mod_round_to_zero}. */
std::pair<Expr, Expr> long_div_mod_round_to_zero(const Expr &a, const Expr &b,
std::optional<uint64_t> max_abs = std::nullopt);
/** Given a Halide Euclidean division/mod operation, do constant optimizations
* and possibly call lower_euclidean_div/lower_euclidean_mod if necessary.
* Can introduce mulhi_shr and sorted_avg intrinsics as well as those from the
* lower_euclidean_ operation -- div_round_to_zero or mod_round_to_zero. */
///@{
Expr lower_int_uint_div(const Expr &a, const Expr &b, bool round_to_zero = false);
Expr lower_int_uint_mod(const Expr &a, const Expr &b);
///@}
/** Given a Halide Euclidean division/mod operation, define it in terms of
* div_round_to_zero or mod_round_to_zero. */
///@{
Expr lower_euclidean_div(Expr a, Expr b);
Expr lower_euclidean_mod(Expr a, Expr b);
///@}
/** Given a Halide shift operation with a signed shift amount (may be negative), define
* an equivalent expression using only shifts by unsigned amounts. */
///@{
Expr lower_signed_shift_left(const Expr &a, const Expr &b);
Expr lower_signed_shift_right(const Expr &a, const Expr &b);
///@}
/** Reduce a mux intrinsic to a select tree */
Expr lower_mux(const Call *mux);
/** Reduce bit extraction and concatenation to bit ops */
///@{
Expr lower_extract_bits(const Call *c);
Expr lower_concat_bits(const Call *c);
///@}
/** An vectorizable implementation of Halide::round that doesn't depend on any
* standard library being present. */
Expr lower_round_to_nearest_ties_to_even(const Expr &);
/** Given an llvm::Module, set llvm:TargetOptions information */
void get_target_options(const llvm::Module &module, llvm::TargetOptions &options);
/** Given two llvm::Modules, clone target options from one to the other */
void clone_target_options(const llvm::Module &from, llvm::Module &to);
/** Given an llvm::Module, get or create an llvm:TargetMachine */
std::unique_ptr<llvm::TargetMachine> make_target_machine(const llvm::Module &module);
/** Set the appropriate llvm Function attributes given the Halide Target. */
void set_function_attributes_from_halide_target_options(llvm::Function &);
/** Save a copy of the llvm IR currently represented by the module as
* data in the __LLVM,__bitcode section. Emulates clang's
* -fembed-bitcode flag and is useful to satisfy Apple's bitcode
* inclusion requirements. */
void embed_bitcode(llvm::Module *M, const std::string &halide_command);
} // namespace Internal
} // namespace Halide
#endif
Closure.h
Provides Closure class.
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt).
Scope.h
Defines the Scope class, which is used for keeping track of names in a scope while traversing IR.
llvm::IRBuilder
Definition CodeGen_Internal.h:31
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::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::long_div_mod_round_to_zero
std::pair< Expr, Expr > long_div_mod_round_to_zero(const Expr &a, const Expr &b, std::optional< uint64_t > max_abs=std::nullopt)
Does a {div/mod}_round_to_zero using binary long division for int/uint.
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...
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::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...
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_concat_bits
Expr lower_concat_bits(const Call *c)
Reduce bit extraction and concatenation to bit ops.
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::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...
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_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...
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::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::get_target_options
void get_target_options(const llvm::Module &module, llvm::TargetOptions &options)
Given an llvm::Module, set llvm:TargetOptions information.
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...
Halide::Internal::lower_extract_bits
Expr lower_extract_bits(const Call *c)
Reduce bit extraction and concatenation to bit ops.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
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,...
llvm
Definition CodeGen_Internal.h:18
int64_t
signed __INT64_TYPE__ int64_t
Definition runtime_internal.h:22
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Internal::Call
A function call.
Definition IR.h:490