#ifndef HALIDE_MODULE_H
#define HALIDE_MODULE_H
#include <functional>
#include "Argument.h"
#include "ExternalCode.h"
#include "IR.h"
#include "ModulusRemainder.h"
#include "Outputs.h"
#include "Target.h"
namespace Halide {
namespace Internal {
struct LoweredArgument : public Argument {
ModulusRemainder alignment;
LoweredArgument() {}
LoweredArgument(const Argument &arg) : Argument(arg) {}
LoweredArgument(const std::string &_name, Kind _kind, const Type &_type, uint8_t _dimensions,
Expr _def = Expr(),
Expr _min = Expr(),
Expr _max = Expr()) : Argument(_name, _kind, _type, _dimensions, _def, _min, _max) {}
};
struct LoweredFunc {
std::string name;
std::vector<LoweredArgument> args;
Stmt body;
enum LinkageType {
External,
ExternalPlusMetadata,
Internal,
};
LinkageType linkage;
NameMangling name_mangling;
LoweredFunc(const std::string &name,
const std::vector<LoweredArgument> &args,
Stmt body,
LinkageType linkage,
NameMangling mangling = NameMangling::Default);
LoweredFunc(const std::string &name,
const std::vector<Argument> &args,
Stmt body,
LinkageType linkage,
NameMangling mangling = NameMangling::Default);
};
}
namespace Internal {
struct ModuleContents;
}
class Module {
Internal::IntrusivePtr<Internal::ModuleContents> contents;
public:
EXPORT Module(const std::string &name, const Target &target);
EXPORT const Target &target() const;
EXPORT const std::string &name() const;
EXPORT const std::vector<Buffer<>> &buffers() const;
EXPORT const std::vector<Internal::LoweredFunc> &functions() const;
EXPORT std::vector<Internal::LoweredFunc> &functions();
EXPORT const std::vector<Module> &submodules() const;
EXPORT const std::vector<ExternalCode> &external_code() const;
EXPORT Internal::LoweredFunc get_function_by_name(const std::string &name) const;
EXPORT void append(const Buffer<> &buffer);
EXPORT void append(const Internal::LoweredFunc &function);
EXPORT void append(const Module &module);
EXPORT void append(const ExternalCode &external_code);
EXPORT void compile(const Outputs &output_files) const;
EXPORT Buffer<uint8_t> compile_to_buffer() const;
EXPORT Module resolve_submodules() const;
};
EXPORT Module link_modules(const std::string &name, const std::vector<Module> &modules);
EXPORT void compile_standalone_runtime(const std::string &object_filename, Target t);
EXPORT Outputs compile_standalone_runtime(const Outputs &output_files, Target t);
typedef std::function<Module(const std::string &, const Target &)> ModuleProducer;
EXPORT void compile_multitarget(const std::string &fn_name,
const Outputs &output_files,
const std::vector<Target> &targets,
ModuleProducer module_producer,
const std::map<std::string, std::string> &suffixes = {});
}
#endif