Go to the documentation of this file.
26 #ifdef Halide_STATIC_DEFINE
32 #define HALIDE_EXPORT __declspec(dllexport)
34 #define HALIDE_EXPORT __declspec(dllimport)
37 #define HALIDE_EXPORT __attribute__((visibility("default")))
42 #if defined(COMPILING_HALIDE) || defined(BUILDING_PYTHON)
43 #define HALIDE_NO_USER_CODE_INLINE
45 #define HALIDE_NO_USER_CODE_INLINE HALIDE_NEVER_INLINE
49 #if defined(__has_feature)
50 #if __has_feature(address_sanitizer)
51 #define HALIDE_INTERNAL_USING_ASAN
53 #if __has_feature(memory_sanitizer)
54 #define HALIDE_INTERNAL_USING_MSAN
56 #if __has_feature(thread_sanitizer)
57 #define HALIDE_INTERNAL_USING_TSAN
59 #if __has_feature(coverage_sanitizer)
60 #define HALIDE_INTERNAL_USING_COVSAN
62 #if __has_feature(undefined_behavior_sanitizer)
63 #define HALIDE_INTERNAL_USING_UBSAN
70 #if defined(__SANITIZE_ADDRESS__) && !defined(HALIDE_INTERNAL_USING_ASAN)
71 #define HALIDE_INTERNAL_USING_ASAN
95 template<
typename DST,
typename SRC,
96 typename std::enable_if<std::is_floating_point<SRC>::value>::type * =
nullptr>
98 if (std::is_integral<DST>::value) {
112 template<
typename DST,
typename SRC,
113 typename std::enable_if<std::is_integral<SRC>::value>::type * =
nullptr>
115 if (std::is_integral<DST>::value) {
123 if (std::is_integral<SRC>::value && std::is_signed<DST>::value &&
sizeof(DST) <
sizeof(SRC)) {
124 using UnsignedSrc =
typename std::make_unsigned<SRC>::type;
125 return (DST)(s & (UnsignedSrc)(-1));
132 template<
typename DstType,
typename SrcType>
134 static_assert(
sizeof(SrcType) ==
sizeof(DstType),
"Types must be same size");
136 memcpy(&dst, &src,
sizeof(SrcType));
143 std::string
make_entity_name(
void *stack_ptr,
const std::string &type,
char prefix);
173 std::string
unique_name(
const std::string &prefix);
177 bool starts_with(
const std::string &str,
const std::string &prefix);
180 bool ends_with(
const std::string &str,
const std::string &suffix);
183 std::string
replace_all(
const std::string &str,
const std::string &find,
const std::string &replace);
186 std::vector<std::string>
split_string(
const std::string &source,
const std::string &delim);
191 template<
typename T,
typename Fn>
198 for (
size_t i = 1; i < vec.size(); i++) {
199 result = f(result, vec[i]);
206 template<
typename T,
typename Fn>
213 for (
size_t i = vec.size() - 1; i > 0; i--) {
214 result = f(vec[i - 1], result);
219 template<
typename... T>
222 template<
typename T1,
typename... Args>
223 struct meta_and<T1, Args...> : std::integral_constant<bool, T1::value && meta_and<Args...>::value> {};
225 template<
typename... T>
228 template<
typename T1,
typename... Args>
229 struct meta_or<T1, Args...> : std::integral_constant<bool, T1::value || meta_or<Args...>::value> {};
231 template<
typename To,
typename... Args>
235 std::string
extract_namespaces(
const std::string &name, std::vector<std::string> &namespaces);
258 std::string
file_make_temp(
const std::string &prefix,
const std::string &suffix);
300 void write_entire_file(
const std::string &pathname,
const void *source,
size_t source_len);
333 const std::string temp_path;
334 bool do_unlink =
true;
396 #define HALIDE_TIC Halide::Internal::halide_tic_impl(__FILE__, __LINE__)
397 #define HALIDE_TOC Halide::Internal::halide_toc_impl(__FILE__, __LINE__)
398 #ifdef COMPILING_HALIDE
399 #define TIC HALIDE_TIC
400 #define TOC HALIDE_TOC
406 template<
typename TO>
408 template<
typename FROM>
409 inline constexpr
static TO
value(
const FROM &from) {
410 if constexpr (std::is_same<TO, bool>::value) {
413 return static_cast<TO
>(from);
421 template<
typename TO>
423 template<
typename FROM>
424 inline constexpr
static bool value(
const FROM &from) {
425 if constexpr (std::is_convertible<FROM, TO>::value) {
426 if constexpr (std::is_arithmetic<TO>::value &&
427 std::is_arithmetic<FROM>::value &&
428 !std::is_same<TO, FROM>::value) {
429 const TO to =
static_cast<TO
>(from);
430 const FROM roundtripped =
static_cast<FROM
>(to);
431 return roundtripped == from;
445 std::string
c_print_name(
const std::string &name,
bool prefix_underscore =
true);
const std::string & pathname() const
void set_compiler_stack_size(size_t)
Set how much stack the compiler should use for compilation in bytes.
void run_with_large_stack(const std::function< void()> &action)
Call the given action in a platform-specific context that provides at least the stack space returned ...
size_t get_compiler_stack_size()
Return how much stack size the compiler should use for calls that go through run_with_large_stack bel...
std::string running_program_name()
Get the name of the currently running executable.
bool sub_would_overflow(int bits, int64_t a, int64_t b)
void halide_tic_impl(const char *file, int line)
std::string replace_all(const std::string &str, const std::string &find, const std::string &replace)
Replace all matches of the second string in the first string with the last string.
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
std::vector< std::string > split_string(const std::string &source, const std::string &delim)
Split the source string using 'delim' as the divider.
std::string make_entity_name(void *stack_ptr, const std::string &type, char prefix)
Make a unique name for an object based on the name of the stack variable passed in.
std::string strip_namespaces(const std::string &name)
Like extract_namespaces(), but strip and discard the namespaces, returning base name only.
std::string get_env_variable(char const *env_var_name)
Get value of an environment variable.
constexpr size_t default_compiler_stack_size
The default amount of stack used for lowering and codegen.
std::string extract_namespaces(const std::string &name, std::vector< std::string > &namespaces)
Returns base name and fills in namespaces, outermost one first in vector.
constexpr static TO value(const FROM &from)
Helper class for saving/restoring variable values on the stack, to allow for early-exit that preserve...
void dir_rmdir(const std::string &name)
Wrapper for rmdir().
std::vector< char > read_entire_file(const std::string &pathname)
Read the entire contents of a file into a vector<char>.
std::string file_make_temp(const std::string &prefix, const std::string &suffix)
Create a unique file with a name of the form prefixXXXXXsuffix in an arbitrary (but writable) directo...
TemporaryFile & operator=(const TemporaryFile &)=delete
unsigned __INT64_TYPE__ uint64_t
HALIDE_MUST_USE_RESULT bool add_with_overflow(int bits, int64_t a, int64_t b, int64_t *result)
Routines to perform arithmetic on signed types without triggering signed overflow.
bool add_would_overflow(int bits, int64_t a, int64_t b)
Routines to test if math would overflow for signed integers with the given number of bits.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
void ensure_no_file_exists(const std::string &name)
Ensure that no file with this path exists.
@ Internal
Not visible externally, similar to 'static' linkage in C.
ScopedValue(T &var, T new_value)
Preserve the old value, then set the var to a new value.
void write_entire_file(const std::string &pathname, const void *source, size_t source_len)
Create or replace the contents of a file with a given pointer-and-length of memory.
FileStat file_stat(const std::string &name)
Wrapper for stat().
T fold_right(const std::vector< T > &vec, Fn f)
Returns a right fold of a vector.
void file_unlink(const std::string &name)
Wrapper for unlink().
#define HALIDE_MUST_USE_RESULT
void assert_no_file_exists(const std::string &name)
assert-fail if the file DOES exist.
DST safe_numeric_cast(SRC s)
Some numeric conversions are UB if the value won't fit in the result; safe_numeric_cast<>() is meant ...
int popcount64(uint64_t x)
Portable versions of popcount, count-leading-zeros, and count-trailing-zeros.
std::string dir_make_temp()
Create a unique directory in an arbitrary (but writable) directory; this is typically somewhere insid...
bool starts_with(const std::string &str, const std::string &prefix)
Test if the first string starts with the second string.
signed __INT64_TYPE__ int64_t
ScopedValue(T &var)
Preserve the old value, restored at dtor time.
HALIDE_MUST_USE_RESULT bool mul_with_overflow(int bits, int64_t a, int64_t b, int64_t *result)
void halide_toc_impl(const char *file, int line)
T fold_left(const std::vector< T > &vec, Fn f)
Perform a left fold of a vector.
DstType reinterpret_bits(const SrcType &src)
An aggressive form of reinterpret cast used for correct type-punning.
void * memcpy(void *s1, const void *s2, size_t n)
HALIDE_MUST_USE_RESULT bool sub_with_overflow(int bits, int64_t a, int64_t b, int64_t *result)
A simple utility class that creates a temporary file in its ctor and deletes that file in its dtor; t...
std::string c_print_name(const std::string &name, bool prefix_underscore=true)
Emit a version of a string that is a valid identifier in C (.
bool ends_with(const std::string &str, const std::string &suffix)
Test if the first string ends with the second string.
void load_plugin(const std::string &lib_name)
Load a plugin in the form of a dynamic library (e.g.
bool mul_would_overflow(int bits, int64_t a, int64_t b)
constexpr static bool value(const FROM &from)
std::string unique_name(char prefix)
Generate a unique name starting with the given prefix.
unsigned __INT32_TYPE__ uint32_t
Expr max(const FuncRef &a, const FuncRef &b)
bool file_exists(const std::string &name)
Wrapper for access().
TemporaryFile(const std::string &prefix, const std::string &suffix)
int get_llvm_version()
Return the LLVM_VERSION against which this libHalide is compiled.
void assert_file_exists(const std::string &name)
assert-fail if the file doesn't exist.