Go to the documentation of this file. 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,
bool uses_gpu_for_loops
True if at least one gpu-based for loop is used.
Target target
The target being generated for.
Allocate a scratch area called with the given name, type, and size.
bool emit_atomic_stores
Emit atomic store instructions?
The sum of two expressions.
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 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.
void compile(const Module &module)
Emit the declarations contained in the module as C code.
void visit(const Variable *) override
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
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....
Is the first expression greater than or equal to the second.
virtual std::string print_name(const std::string &)
Emit a version of a string that is a valid identifier in C (.
static std::string with_sep(const std::vector< T > &v, const std::string &sep)
Floating point constants.
An IRVisitor that emits IR to the given output stream in a human readable form.
A vector with 'lanes' elements, in which every element is 'value'.
The ratio of two expressions.
const Target & get_target() const
The target we're generating code for.
The statement form of a let node.
void create_assertion(const std::string &id_cond, const Expr &message)
A common pattern when traversing Halide IR is that you need to keep track of stuff when you find a Le...
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...
The actual IR nodes begin here.
Is the first expression less than or equal to the second.
Is the first expression not equal to the second.
A pair of statements executed concurrently.
OutputKind output_kind
Controls whether this instance is generating declarations or definitions and whether the interface us...
@ CPlusPlusImplementation
A reference-counted handle to a statement node.
This class emits C++ code equivalent to a halide Stmt.
static std::string with_commas(const std::vector< T > &v)
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.
Types in the halide type system.
void open_scope()
Open a new C scope (i.e.
Load a value from a named symbol if predicate is true.
Free the resources associated with the given buffer.
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,...
void print_heap_free(const std::string &alloc_name)
Emit free for the heap allocation.
Logical or - is at least one of the expression true.
Is the first expression equal to the second.
This defines the value of a function at a multi-dimensional location.
virtual void add_vector_typedefs(const std::set< Type > &vector_types)
Add typedefs for vector types.
@ Internal
Not visible externally, similar to 'static' linkage in C.
The greater of two values.
virtual std::string print_extern_call(const Call *op)
Bottleneck to allow customization of calls to generic Extern/PureExtern calls.
Scope heap_allocations
Track which allocations actually went on the heap.
A let expression, like you might find in a functional language.
void emit_halide_free_helper(const std::string &alloc_name, const std::string &free_function)
void emit_constexpr_function_info(const std::string &function_name, const std::vector< LoweredArgument > &args, const MetadataNameMap &metadata_name_map)
bool is_extern_decl()
Return true if only generating an interface, which may be extern "C" or C++.
IntegerSuffixStyle integer_suffix_style
How to emit 64-bit integer constants.
std::map< std::string, std::string > cache
A cache of generated values in scope.
A linear ramp vector node.
void visit(const IntImm *) override
virtual std::string print_assignment(Type t, const std::string &rhs)
Emit an SSA-style assignment, and set id to the freshly generated name.
Evaluate and discard an expression, presumably because it has some side-effect.
std::map< std::string, std::string > MetadataNameMap
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition of a lowered function.
std::string id
An ID for the most recently generated ssa variable.
NameMangling
An enum to specify calling convention for extern stages.
The lesser of two values.
This node is a helpful annotation to do with permissions.
If the 'condition' is false, then evaluate and return the message, which should be a call to an error...
bool inside_atomic_mutex_node
Are we inside an atomic node that uses mutex locks? This is used for detecting deadlocks from nested ...
bool using_vector_typedefs
true if add_vector_typedefs() has been called.
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++.
Reinterpret value as another type, without affecting any of the bits (on little-endian systems).
void visit_relop(Type t, const Expr &a, const Expr &b, const char *scalar_op, const char *vector_op)
void set_name_mangling_mode(NameMangling mode)
bool is_header()
Return true if only generating an interface, which may be extern "C" or C++.
void emit_metadata_getter(const std::string &function_name, const std::vector< LoweredArgument > &args, const MetadataNameMap &metadata_name_map)
A fragment of Halide syntax.
bool extern_c_open
Track current calling convention scope.
Represent a multi-dimensional region of a Func or an ImageParam that needs to be prefetched.
void visit_binop(Type t, const Expr &a, const Expr &b, const char *op)
Is the first expression greater than the second.
void print_stmt(const Stmt &)
Emit a statement.
Lock all the Store nodes in the body statement.
Construct a new vector by taking elements from another sequence of vectors.
Unsigned integer constants.
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.
Scope< Allocation > allocations
Track the types of allocations to avoid unnecessary casts.
The difference of two expressions.
void emit_argv_wrapper(const std::string &function_name, const std::vector< LoweredArgument > &args)
A struct representing a target machine and os to generate code for.
Logical and - are both expressions true.
std::string print_cast_expr(const Type &, const Expr &)
Like print_expr, but cast the Expr to the given Type.
bool is_c_plus_plus_interface()
Return true if generating C++ linkage.
@ CPlusPlusFunctionInfoHeader
Logical not - true if the expression false.
Is the first expression less than the second.
std::set< const halide_handle_cplusplus_type * > forward_declared
Track which handle types have been forward-declared already.
The product of two expressions.
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.
bool have_user_context
True if there is a void * __user_context parameter in the arguments.