<commit_before>#ifndef HALIDE_JIT_MODULE_H
#define HALIDE_JIT_MODULE_H

/** \file Defines the struct representing lifetime and dependencies of
 * a JIT compiled halide pipeline
 */

#include <map>

#include "IntrusivePtr.h"
#include "Type.h"
#include "runtime/HalideRuntime.h"

namespace llvm {
class Module;
class Type;
}

namespace Halide {

struct Target;
class Module;

class Func;

struct ScalarOrBufferT {
    bool is_buffer;
    Type scalar_type; // Only meaningful if is_buffer is false.
};

namespace {

template <typename T>
bool voidable_halide_type(Type &t) {
    t = type_of<T>();
    return false;
}

template<>
inline bool voidable_halide_type<void>(Type &t) {
    return true;
}        

template <typename T>
bool scalar_arg_type_or_buffer(Type &t) {
    t = type_of<T>();
    return false;
}

template <>
inline bool scalar_arg_type_or_buffer<struct buffer_t *>(Type &t) {
    return true;
}

template <typename T>
ScalarOrBufferT arg_type_info() {
    ScalarOrBufferT result;
    result.is_buffer = scalar_arg_type_or_buffer<T>(result.scalar_type);
    return result;
}

template <typename A1, typename... Args>
struct make_argument_list {
    static void add_args(std::vector<ScalarOrBufferT> &arg_types) {
        arg_types.push_back(arg_type_info<A1>());
        make_argument_list<Args...>::add_args(arg_types);
    }
};

template <>
struct make_argument_list<void> {
    static void add_args(std::vector<ScalarOrBufferT> &) { }
};


template <typename... Args>
void init_arg_types(std::vector<ScalarOrBufferT> &arg_types) {
  make_argument_list<Args..., void>::add_args(arg_types);
}

#if 0
//template <typename A1, typename... Args>
//void init_arg_types_helper(std::vector<ScalarOrBufferT> &arg_types) {
//    arg_types.push_back(arg_type_info<A1>());
//    init_arg_types<Args...>(arg_types);
//}

template <typename A1, typename... Args>
void init_arg_types(std::vector<ScalarOrBufferT> &arg_types) {
    arg_types.push_back(arg_type_info<A1>());
    init_arg_types<Args...>(arg_types);
}

template <>
void init_arg_types<void, >(std::vector<ScalarOrBufferT> &arg_types) {
}
#endif

}

struct JITExtern {
    // assert func.defined() == (c_function == NULL) -- strictly one or the other
    Func *func;
    std::map<std::string, JITExtern> func_externs;

    void *c_function;
    bool is_void_return; // could use ret_type.bits == 0...
    Type ret_type;
    std::vector<ScalarOrBufferT> arg_types;

   JITExtern(Func &func,
             const std::map<std::string, JITExtern> &func_externs = std::map<std::string, JITExtern>())
        : func(&func), func_externs(func_externs), c_function(NULL) {
    }

    template <typename RT, typename... Args>
    JITExtern(RT (*f)(Args... args)) : func(NULL) {<commit_msg>Remove #if 0 code.<commit_after>#ifndef HALIDE_JIT_MODULE_H
#define HALIDE_JIT_MODULE_H

/** \file Defines the struct representing lifetime and dependencies of
 * a JIT compiled halide pipeline
 */

#include <map>

#include "IntrusivePtr.h"
#include "Type.h"
#include "runtime/HalideRuntime.h"

namespace llvm {
class Module;
class Type;
}

namespace Halide {

struct Target;
class Module;

class Func;

struct ScalarOrBufferT {
    bool is_buffer;
    Type scalar_type; // Only meaningful if is_buffer is false.
};

namespace {

template <typename T>
bool voidable_halide_type(Type &t) {
    t = type_of<T>();
    return false;
}

template<>
inline bool voidable_halide_type<void>(Type &t) {
    return true;
}        

template <typename T>
bool scalar_arg_type_or_buffer(Type &t) {
    t = type_of<T>();
    return false;
}

template <>
inline bool scalar_arg_type_or_buffer<struct buffer_t *>(Type &t) {
    return true;
}

template <typename T>
ScalarOrBufferT arg_type_info() {
    ScalarOrBufferT result;
    result.is_buffer = scalar_arg_type_or_buffer<T>(result.scalar_type);
    return result;
}

template <typename A1, typename... Args>
struct make_argument_list {
    static void add_args(std::vector<ScalarOrBufferT> &arg_types) {
        arg_types.push_back(arg_type_info<A1>());
        make_argument_list<Args...>::add_args(arg_types);
    }
};

template <>
struct make_argument_list<void> {
    static void add_args(std::vector<ScalarOrBufferT> &) { }
};


template <typename... Args>
void init_arg_types(std::vector<ScalarOrBufferT> &arg_types) {
  make_argument_list<Args..., void>::add_args(arg_types);
}

}

struct JITExtern {
    // assert func.defined() == (c_function == NULL) -- strictly one or the other
    Func *func;
    std::map<std::string, JITExtern> func_externs;

    void *c_function;
    bool is_void_return; // could use ret_type.bits == 0...
    Type ret_type;
    std::vector<ScalarOrBufferT> arg_types;

   JITExtern(Func &func,
             const std::map<std::string, JITExtern> &func_externs = std::map<std::string, JITExtern>())
        : func(&func), func_externs(func_externs), c_function(NULL) {
    }

    template <typename RT, typename... Args>
    JITExtern(RT (*f)(Args... args)) : func(NULL) {
{'fraction_non_alphanumeric': 0.13148927640809782, 'fraction_numerical': 0.0024052916416115455, 'mean_word_length': 4.2142110762800415, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294638', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1739, 'n_words': 381}