4#include <llvm/ADT/DenseMap.h>
5#include <llvm/ADT/ScopedHashTable.h>
8#include <unordered_map>
11#include "mlir/IR/BuiltinTypes.h"
12#include "mlir/IR/Operation.h"
13#include "mlir/IR/Value.h"
14#include "mlir/Support/LLVM.h"
27 std::vector<int64_t> shape_;
28 std::vector<int64_t> strides_;
35 const std::vector<int64_t>&
shape()
const;
36 const std::vector<int64_t>&
strides()
const;
70 std::unique_ptr<::sdfg::types::Tensor>
get_sdfg_tensor(const ::sdfg::types::Scalar& element_type)
const;
83 llvm::ScopedHashTable<Value, std::string> value_map_;
84 size_t value_counter_;
86 std::list<::sdfg::structured_control_flow::Sequence*> insertion_points_;
88 std::unordered_map<std::string, TensorInfo> tensor_info_map_;
90 std::unordered_map<::sdfg::structured_control_flow::Sequence*, std::list<std::string>> memory_map_;
92 std::unordered_map<std::string, std::string> alias_map_;
97 llvm::DenseMap<Value, Value> constant_fill_map_;
99 std::vector<std::string> output_args_;
121 std::unique_ptr<::sdfg::types::IType>
convertType(
const Type mlir_type);
126 const std::string& src_container,
127 const std::string& dst_container,
132 std::string container,
133 const ::sdfg::symbolic::Expression size,
145 Value output, const ::sdfg::DebugInfo& deb_info =
::sdfg::DebugInfo(),
bool consumer_overwrites_output =
false
164 const std::string& container,
166 const ::sdfg::types::Scalar& element_type,
178 const std::string& src_container,
180 const ::sdfg::types::Scalar& element_type,
181 const std::string& output_container,
187 const std::string& src_container,
188 const std::string& output_container,
Definition SDFGTranslator.h:79
std::string get_or_create_container(Value val, bool argument=false)
void record_constant_fill(Value result, Value value)
Record that result is produced by a constant value linalg.fill whose materialization is deferred.
void handle_frees(std::string return_container="", const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo())
llvm::ScopedHashTable< Value, std::string > & value_map()
::sdfg::builder::StructuredSDFGBuilder & builder()
void copy_to_output(const std::string &src_container, const TensorInfo &tensor_info, const ::sdfg::types::Scalar &element_type, const std::string &output_container, const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo())
Copy tensor data to an output argument container in C-order.
void copy_scalar_to_output(const std::string &src_container, const std::string &output_container, const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo())
Copy scalar data to an output argument container.
::sdfg::DebugInfo get_debug_info(llvm::StringLiteral operation_name, Location loc)
Creates an SDFG debug info from an operation.
void add_reference(const std::string &src_container, const std::string &dst_container, const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo())
std::string store_in_c_order(const std::string &container, const TensorInfo &tensor_info, const ::sdfg::types::Scalar &element_type, const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo())
void handle_malloc(std::string container, const ::sdfg::symbolic::Expression size, const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo())
void builder_empty(bool empty)
std::unique_ptr<::sdfg::types::IType > convertType(const Type mlir_type)
std::string try_inplace_reuse_container(Value input, Value result)
Returns the container of input if its buffer can be safely overwritten in place by an elementwise con...
std::string convertTypedAttr(const TypedAttr attr)
void set_output_args(const std::vector< std::string > &output_args)
Set the output argument names for multi-output support.
void enter_sequence(::sdfg::structured_control_flow::Sequence &sequence)
TensorInfo & get_or_create_tensor_info(const std::string &container, const TensorType &type)
const std::vector< std::string > & output_args() const
Get the output argument names.
::sdfg::structured_control_flow::Sequence & insertion_point()
std::string get_or_copy_output_container(Value output, const ::sdfg::DebugInfo &deb_info=::sdfg::DebugInfo(), bool consumer_overwrites_output=false)
If output is used as a DPS init by more than one linalg op, allocate a fresh copy via malloc + memcpy...
void exit_sequence(::sdfg::structured_control_flow::Sequence &sequence)
bool is_constant_fill(Value result) const
Returns true if result was recorded via record_constant_fill.
std::unordered_map< std::string, TensorInfo > & tensor_info_map()
Definition SDFGTranslator.h:26
::sdfg::math::tensor::TensorLayout get_tensor_layout() const
Create SDFG tensor layout.
std::string toStr() const
Return string representation of tensor info (for debug purposes).
static bool has_basic_strides(ArrayRef< int64_t > shape, ArrayRef< int64_t > strides)
Returns true iff the tensor has basic C-order contiguous strides.
TensorInfo(std::vector< int64_t > shape, std::vector< int64_t > strides, int64_t offset=0)
bool has_transposed_strides_last_two_dims() const
Returns true iff the tensor is transposed in the last two dimensions.
TensorInfo reshape(ArrayRef< int64_t > new_shape) const
Create reshaped view (only valid for contiguous tensors).
const std::vector< int64_t > & shape() const
static TensorInfo from_tensor_type(TensorType type)
Create TensorInfo from a tensor type (assumes C-order contiguous).
std::string shape_str() const
return shape as string for metadata
static std::vector< int64_t > compute_strides(const std::vector< int64_t > &shape)
Compute C-order contiguous strides from shape.
const std::vector< int64_t > & strides() const
bool is_reshape_valid(ArrayRef< int64_t > new_shape) const
Returns true iff a reshape is valid (contiguous layout, same element count).
std::unique_ptr<::sdfg::types::Tensor > get_sdfg_tensor(const ::sdfg::types::Scalar &element_type) const
Create SDFG tensor type.
TensorInfo flip(ArrayRef< int64_t > axes) const
Create flipped view: negate stride and adjust offset for each flipped axis.
TensorInfo transpose(ArrayRef< int64_t > permutation) const
Create transposed view: output_strides[i] = input_strides[perm[i]].
bool has_basic_strides() const
Returns true iff the tensor has basic C-order contiguous strides.
Note: Even though the class references unique_ptr, it will never delete an SDFG it has a reference to...
Definition structured_sdfg_builder.h:44
The metadata associated with a addressing a tensor in elements Meant to be used with TensorNodes to d...
Definition tensor_layout.h:20
A sequential container of control flow nodes.
Definition sequence.h:52
Definition ArithToSDFGTranslator.h:8
LogicalResult translateOp(SDFGTranslator &translator, Operation *op)
LogicalResult emitJSON(SDFGTranslator &translator, raw_ostream &os)
Definition CustomPasses.h:6
Scalar (primitive) type representation.
Symbolic system for integer-based symbol analysis.