1 #ifndef HALIDE_CODEGEN_C_H 2 #define HALIDE_CODEGEN_C_H 44 const std::string &include_guard =
"");
96 std::map<std::string, std::string>
cache;
128 virtual std::string
print_name(
const std::string &);
225 void visit(
const EQ *)
override;
226 void visit(
const NE *)
override;
227 void visit(
const LT *)
override;
228 void visit(
const LE *)
override;
229 void visit(
const GT *)
override;
230 void visit(
const GE *)
override;
232 void visit(
const Or *)
override;
262 static std::string
with_sep(
const std::vector<T> &v,
const std::string &sep) {
263 std::ostringstream o;
264 for (
size_t i = 0; i < v.size(); ++i) {
275 return with_sep<T>(v,
", ");
296 const std::vector<LoweredArgument> &args);
298 const std::vector<LoweredArgument> &args,
301 const std::vector<LoweredArgument> &args,
Unsigned integer constants.
Scope< Allocation > allocations
Track the types of allocations to avoid unnecessary casts.
The actual IR nodes begin here.
static std::string with_commas(const std::vector< T > &v)
void open_scope()
Open a new C scope (i.e.
virtual std::string print_assignment(Type t, const std::string &rhs)
Emit an SSA-style assignment, and set id to the freshly generated name.
Expr scalarize_vector_reduce(const VectorReduce *op)
bool is_header_or_extern_decl()
Return true if only generating an interface, which may be extern "C" or C++.
A fragment of Halide syntax.
bool is_c_plus_plus_interface()
Return true if generating C++ linkage.
Is the first expression greater than the second.
A reference-counted handle to a statement node.
Load a value from a named symbol if predicate is true.
The difference of two expressions.
A vector with 'lanes' elements, in which every element is 'value'.
Logical and - are both expressions true.
void close_scope(const std::string &comment)
Close a C scope (i.e.
virtual std::string print_type(Type, AppendSpaceIfNeeded space_option=DoNotAppendSpace)
Emit the C name for a halide type.
Logical not - true if the expression false.
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
A struct representing a target machine and os to generate code for.
Is the first expression less than the second.
The product of two expressions.
This class emits C++ code equivalent to a halide Stmt.
Lock all the Store nodes in the body statement.
void emit_argv_wrapper(const std::string &function_name, const std::vector< LoweredArgument > &args)
Floating point constants.
std::string print_cast_expr(const Type &, const Expr &)
Like print_expr, but cast the Expr to the given Type.
The sum of two expressions.
This header file defines operators that let you dump a Halide expression, statement, or type directly into an output stream in a human readable form.
void visit_relop(Type t, const Expr &a, const Expr &b, const char *scalar_op, const char *vector_op)
A linear ramp vector node.
void emit_metadata_getter(const std::string &function_name, const std::vector< LoweredArgument > &args, const MetadataNameMap &metadata_name_map)
Allocate a multi-dimensional buffer of the given type and size.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide's bounds tools to query properties of it.
bool uses_gpu_for_loops
True if at least one gpu-based for loop is used.
An IRVisitor that emits IR to the given output stream in a human readable form.
Defines the structure that describes a Halide target.
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
bool extern_c_open
Track current calling convention scope.
Allocate a scratch area called with the given name, type, and size.
CodeGen_C(std::ostream &dest, const Target &target, OutputKind output_kind=CImplementation, const std::string &include_guard="")
Initialize a C code generator pointing at a particular output stream (e.g.
void print_stmt(const Stmt &)
Emit a statement.
virtual bool is_stack_private_to_thread() const
Some architectures have private memory for the call stack; this means a thread cannot hand pointers t...
Is the first expression greater than or equal to the second.
bool inside_atomic_mutex_node
Are we inside an atomic node that uses mutex locks? This is used for detecting deadlocks from nested ...
A common pattern when traversing Halide IR is that you need to keep track of stuff when you find a Le...
void visit(const IntImm *) override
void visit(const Variable *) override
This defines the value of a function at a multi-dimensional location.
Represent a multi-dimensional region of a Func or an ImageParam that needs to be prefetched.
The ratio of two expressions.
std::map< std::string, std::string > MetadataNameMap
Definition of a lowered function.
static std::string with_sep(const std::vector< T > &v, const std::string &sep)
std::string print_expr(const Expr &)
Emit an expression as an assignment, then return the id of the resulting var.
virtual std::string print_reinterpret(Type, const Expr &)
Emit a statement to reinterpret an expression as another type.
Is the first expression less than or equal to the second.
Is the first expression not equal to the second.
bool have_user_context
True if there is a void * __user_context parameter in the arguments.
const Target & get_target() const
The target we're generating code for.
virtual void add_vector_typedefs(const std::set< Type > &vector_types)
Add typedefs for vector types.
void create_assertion(const std::string &id_cond, const Expr &message)
If the 'condition' is false, then evaluate and return the message, which should be a call to an error...
void visit_binop(Type t, const Expr &a, const Expr &b, const char *op)
bool using_vector_typedefs
true if add_vector_typedefs() has been called.
Not visible externally, similar to 'static' linkage in C.
Is the first expression equal to the second.
The greater of two values.
A pair of statements executed concurrently.
void set_name_mangling_mode(NameMangling mode)
void print_heap_free(const std::string &alloc_name)
Emit free for the heap allocation.
Defines the Scope class, which is used for keeping track of names in a scope while traversing IR...
A let expression, like you might find in a functional language.
Free the resources associated with the given buffer.
std::string id
An ID for the most recently generated ssa variable.
bool emit_atomic_stores
Emit atomic store instructions?
virtual std::string print_extern_call(const Call *op)
Bottleneck to allow customization of calls to generic Extern/PureExtern calls.
Types in the halide type system.
NameMangling
An enum to specify calling convention for extern stages.
void forward_declare_type_if_needed(const Type &t)
If the Type is a handle type, emit a forward-declaration for it if we haven't already.
std::string print_scalarized_expr(const Expr &e)
Convert a vector Expr into a series of scalar Exprs, then reassemble into vector of original type...
virtual void add_platform_prologue()
Add platform specific prologue.
The lesser of two values.
virtual std::string print_name(const std::string &)
Emit a version of a string that is a valid identifier in C (.
virtual Stmt preprocess_function_body(const Stmt &stmt)
This is a hook that subclasses can use to transform a function body just before it is emitted – e...
Reinterpret value as another type, without affecting any of the bits (on little-endian systems)...
std::set< const halide_handle_cplusplus_type * > forward_declared
Track which handle types have been forward-declared already.
The statement form of a let node.
bool is_header()
Return true if only generating an interface, which may be extern "C" or C++.
Target target
The target being generated for.
Logical or - is at least one of the expression true.
This node is a helpful annotation to do with permissions.
Scope heap_allocations
Track which allocations actually went on the heap.
void emit_halide_free_helper(const std::string &alloc_name, const std::string &free_function)
IntegerSuffixStyle integer_suffix_style
How to emit 64-bit integer constants.
void emit_constexpr_function_info(const std::string &function_name, const std::vector< LoweredArgument > &args, const MetadataNameMap &metadata_name_map)
Evaluate and discard an expression, presumably because it has some side-effect.
bool is_extern_decl()
Return true if only generating an interface, which may be extern "C" or C++.
void compile(const Module &module)
Emit the declarations contained in the module as C code.
OutputKind output_kind
Controls whether this instance is generating declarations or definitions and whether the interface us...
std::map< std::string, std::string > cache
A cache of generated values in scope.
Construct a new vector by taking elements from another sequence of vectors.