14#include <nlohmann/json.hpp>
22using json = nlohmann::json;
80 std::vector<symbolic::Expression> args_;
99 const std::string&
value,
119 return allocation_size_;
128 [[deprecated(
"use args")]]
134 [[deprecated(
"use args")]]
136 if (args_.size() > 1) {
139 args_.push_back(arg);
143 std::vector<symbolic::Expression>&
args() {
147 const std::vector<symbolic::Expression>&
args()
const {
151 void args(
const std::vector<symbolic::Expression>&
args) {
155 void args(std::vector<symbolic::Expression>&&
args) {
156 args_ = std::move(
args);
171 return deallocation_;
185 if (value_ != other.value_) {
188 if (allocation_ != other.allocation_) {
191 if (deallocation_ != other.deallocation_) {
197 if (args_.size() != other.args_.size()) {
200 for (
size_t i = 0; i < args_.size(); ++i) {
211 return value_ ==
"CPU_Stack";
216 return value_ ==
"CPU_Heap";
226 return value_ ==
"NV_Generic";
231 return value_ ==
"AMD_Generic";
236 return value_ ==
"NV_Global";
241 return value_ ==
"NV_Shared";
246 return value_ ==
"NV_Constant";
251 return value_ ==
"NV_Symbol";
263 return value_ ==
"GPU_Static";
375 throw std::invalid_argument(
"Invalid primitive type");
387 }
else if (e ==
"Bool") {
389 }
else if (e ==
"Int8") {
391 }
else if (e ==
"Int16") {
393 }
else if (e ==
"Int32") {
395 }
else if (e ==
"Int64") {
397 }
else if (e ==
"Int128") {
399 }
else if (e ==
"UInt8") {
401 }
else if (e ==
"UInt16") {
403 }
else if (e ==
"UInt32") {
405 }
else if (e ==
"UInt64") {
407 }
else if (e ==
"UInt128") {
409 }
else if (e ==
"Half") {
411 }
else if (e ==
"BFloat") {
413 }
else if (e ==
"Float") {
415 }
else if (e ==
"Double") {
417 }
else if (e ==
"X86_FP80") {
419 }
else if (e ==
"FP128") {
421 }
else if (e ==
"PPC_FP128") {
424 throw std::invalid_argument(
"Invalid primitive type");
474 throw std::invalid_argument(
"Invalid primitive type");
724 virtual std::unique_ptr<IType>
clone()
const = 0;
730 virtual std::string
print()
const = 0;
Represents a c-style array type.
Definition array.h:33
Represents a function type.
Definition function.h:31
virtual std::unique_ptr< IType > clone() const =0
Creates a deep copy of this type.
size_t alignment_
Memory alignment requirement in bytes.
Definition type.h:628
void storage_type(const StorageType &storage_type)
Sets the storage type.
Definition type.h:668
IType(StorageType storage_type=StorageType::CPU_Stack(), size_t alignment=0, const std::string &initializer="")
Constructs an IType with optional storage, alignment, and initializer.
Definition type.h:638
virtual void replace_symbols(const symbolic::ExpressionMapping &replacements)=0
virtual bool operator==(const IType &other) const =0
Compares two types for equality.
void alignment(size_t alignment)
Sets the alignment requirement in bytes.
Definition type.h:678
virtual TypeID type_id() const =0
Returns the TypeID for runtime type identification.
virtual PrimitiveType primitive_type() const =0
Returns the primitive type for this type.
std::string initializer_
Optional initializer expression.
Definition type.h:629
virtual bool is_pointer_like() const =0
Checks if this is a pointer or a structure behaves like a pointer.
StorageType storage_type_
Where and how the data is stored.
Definition type.h:627
virtual void replace_symbols(const symbolic::Expression old_expression, const symbolic::Expression new_expression)=0
Replace symbolic expressions on this type.
virtual bool is_symbol() const =0
Checks if this type represents a symbolic/integer type.
StorageType storage_type() const
Gets the storage type (const version).
Definition type.h:651
std::string initializer() const
Gets the initializer expression.
Definition type.h:683
virtual ~IType()=default
Virtual destructor for proper cleanup of derived classes.
friend std::ostream & operator<<(std::ostream &os, const IType &type)
Stream output operator for types.
Definition type.h:738
StorageType & storage_type()
Gets the storage type (mutable reference).
Definition type.h:663
void initializer(const std::string &initializer)
Sets the initializer expression.
Definition type.h:688
size_t alignment() const
Gets the alignment requirement in bytes.
Definition type.h:673
virtual std::string print() const =0
Returns a string representation of this type.
Represents a pointer type.
Definition pointer.h:32
Represents a scalar primitive type.
Definition scalar.h:27
Represents the storage location and management characteristics of data.
Definition type.h:64
StorageType(const std::string &value)
Constructs a StorageType with default unmanaged allocation.
Definition type.h:87
bool is_amd_generic() const
Checks if this storage is AMD generic memory.
Definition type.h:230
symbolic::Expression allocation_size() const
Gets the allocation size.
Definition type.h:118
void args(const std::vector< symbolic::Expression > &args)
Definition type.h:151
void arg1(const symbolic::Expression &arg)
Sets the additional argument.
Definition type.h:135
bool is_gpu_static() const
Checks if this storage is a static GPU buffer.
Definition type.h:262
static StorageType CPU_Stack()
Creates a CPU stack storage type.
Definition type.h:270
static StorageType NV_Generic()
Creates an NVIDIA generic memory storage type.
Definition type.h:298
bool is_nv_symbol() const
Checks if this storage is an NVIDIA symbol.
Definition type.h:250
static StorageType GPU_Static()
Creates a static GPU buffer storage type (see is_gpu_static).
Definition type.h:323
bool is_cpu_stack() const
Checks if this storage is CPU stack storage.
Definition type.h:210
std::string value() const
Gets the storage location identifier.
Definition type.h:108
const symbolic::Expression & arg1() const
Gets the additional argument.
Definition type.h:129
bool is_nv_global() const
Checks if this storage is NVIDIA global memory.
Definition type.h:235
const std::vector< symbolic::Expression > & args() const
Definition type.h:147
AllocationType
Defines how memory allocation/deallocation is managed.
Definition type.h:70
@ Managed
Memory is automatically managed.
Definition type.h:72
@ Unmanaged
Memory is not automatically managed.
Definition type.h:71
bool is_nv_shared() const
Checks if this storage is NVIDIA shared memory.
Definition type.h:240
void allocation_size(const symbolic::Expression &allocation_size)
Sets the allocation size.
Definition type.h:123
bool is_nv_generic() const
Checks if this storage is NVIDIA generic memory.
Definition type.h:225
std::vector< symbolic::Expression > & args()
Definition type.h:143
AllocationType deallocation() const
Gets the deallocation management type.
Definition type.h:170
static StorageType CPU_Heap(symbolic::Expression allocation_size, StorageType::AllocationType allocation, StorageType::AllocationType deallocation)
Creates a CPU heap storage type with explicit allocation management.
Definition type.h:289
void args(std::vector< symbolic::Expression > &&args)
Definition type.h:155
static StorageType NV_Shared()
Creates an NVIDIA shared memory storage type.
Definition type.h:308
static StorageType NV_Constant()
Creates an NVIDIA constant memory storage type.
Definition type.h:313
void value(const std::string &value)
Sets the storage location identifier.
Definition type.h:113
bool is_cpu_heap() const
Checks if this storage is CPU heap storage.
Definition type.h:215
void deallocation(AllocationType deallocation)
Sets the deallocation management type.
Definition type.h:175
StorageType(const std::string &value, const symbolic::Expression &allocation_size, AllocationType allocation, AllocationType deallocation)
Constructs a StorageType with explicit allocation management.
Definition type.h:98
static StorageType NV_Symbol()
Creates an NVIDIA symbol storage type.
Definition type.h:318
static StorageType NV_Global()
Creates an NVIDIA global memory storage type.
Definition type.h:303
bool is_nv_constant() const
Checks if this storage is NVIDIA constant memory.
Definition type.h:245
bool operator==(const StorageType &other) const
Compares two StorageType objects for equality.
Definition type.h:184
bool is_device() const
Checks if this storage resides on a device (i.e. not CPU stack/heap).
Definition type.h:220
AllocationType allocation() const
Gets the allocation management type.
Definition type.h:160
static StorageType CPU_Heap()
Creates a CPU heap storage type with default unmanaged allocation.
Definition type.h:278
void allocation(AllocationType allocation)
Sets the allocation management type.
Definition type.h:165
Represents a structure type (similar to C struct).
Definition structure.h:37
bool null_safe_eq(const Expression lhs, const Expression rhs)
Tests equality of expressions with null-safety.
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
SymEngine::map_basic_basic ExpressionMapping
Definition symbolic.h:109
nlohmann::json json
Definition interstate_edge.h:14
constexpr bool is_signed(PrimitiveType e) noexcept
Checks if a PrimitiveType is a signed integer type.
Definition type.h:526
constexpr size_t bit_width(PrimitiveType e)
Returns the bit width of a PrimitiveType.
Definition type.h:433
constexpr PrimitiveType as_unsigned(PrimitiveType e) noexcept
Converts a signed integer type to its unsigned equivalent.
Definition type.h:584
constexpr PrimitiveType as_signed(PrimitiveType e) noexcept
Converts an unsigned integer type to its signed equivalent.
Definition type.h:562
PrimitiveType
Enumeration of all primitive data types supported by sdfglib.
Definition type.h:35
@ Int32
32-bit signed integer
Definition type.h:40
@ UInt64
64-bit unsigned integer
Definition type.h:46
@ Bool
Boolean type (1 bit).
Definition type.h:37
@ Int16
16-bit signed integer
Definition type.h:39
@ UInt16
16-bit unsigned integer
Definition type.h:44
@ Half
16-bit floating-point (IEEE 754 half precision)
Definition type.h:48
@ FP128
128-bit floating-point (IEEE 754 quadruple precision)
Definition type.h:53
@ Double
64-bit floating-point (IEEE 754 double precision)
Definition type.h:51
@ Int64
64-bit signed integer
Definition type.h:41
@ UInt32
32-bit unsigned integer
Definition type.h:45
@ Int8
8-bit signed integer
Definition type.h:38
@ Int128
128-bit signed integer
Definition type.h:42
@ PPC_FP128
128-bit floating-point (PowerPC double-double)
Definition type.h:54
@ UInt8
8-bit unsigned integer
Definition type.h:43
@ Void
Void type (0 bits).
Definition type.h:36
@ BFloat
16-bit brain floating-point
Definition type.h:49
@ UInt128
128-bit unsigned integer
Definition type.h:47
@ X86_FP80
80-bit extended precision floating-point (x86)
Definition type.h:52
@ Float
32-bit floating-point (IEEE 754 single precision)
Definition type.h:50
constexpr bool is_integer(PrimitiveType e) noexcept
Checks if a PrimitiveType is an integer type.
Definition type.h:502
constexpr const char * primitive_type_to_string(PrimitiveType e)
Converts a PrimitiveType to its string representation.
Definition type.h:334
TypeID
Enumeration of high-level type categories.
Definition type.h:607
@ Reference
Reference type.
Definition type.h:612
constexpr bool is_unsigned(PrimitiveType e) noexcept
Checks if a PrimitiveType is an unsigned integer type.
Definition type.h:544
constexpr PrimitiveType primitive_type_from_string(std::string_view e)
Converts a string to its corresponding PrimitiveType.
Definition type.h:384
constexpr bool is_floating_point(PrimitiveType e) noexcept
Checks if a PrimitiveType is a floating-point type.
Definition type.h:482
Symbolic system for integer-based symbol analysis.