Intermediate representation wrapper for supported value types in AX as immutable instances.
More...
|
| Value (llvm::Value *val, llvm::Type *utype) |
| Create a Value with a provided underlying type. More...
|
|
| Value (llvm::Constant *costant) |
| Initialize from a constant value. More...
|
|
| Value (const Value &)=default |
|
| Value (Value &&)=default |
|
Value & | operator= (const Value &)=default |
|
Value & | operator= (Value &&)=default |
|
Value | Zero () const |
| Create a new zero scalar Value using the underlying scalar precision of this Value. Does not generate IR, however will return an invalid constant if this Value is a string. More...
|
|
Value | One () const |
| Create a new one scalar Value using the underlying scalar precision of this Value. Does not generate IR, however will return an invalid constant if this Value is a string. More...
|
|
| operator bool () const |
| Check if this Value contains an active underlying llvm Value/Type. When asserts are enabled. This method strictly checks all possible valid combination types of a Value. More...
|
|
bool | operator! () const |
| See bool operator. More...
|
|
bool | IsVoid () const |
| Return true if this value represents a void type. This is typically only possible for void function returns. More...
|
|
bool | IsBool () const |
| Return true if the underlying type is a bool type. More...
|
|
bool | IsScalar () const |
| Return true if the underlying type is a scalar type (bool, int or float). More...
|
|
bool | IsInteger () const |
| Return true if the underlying type is an integer type. More...
|
|
bool | IsFloat () const |
| Return true if the underlying type is an floating point type (float or double). More...
|
|
bool | IsArray () const |
| Return true if the underlying type is an array type. More...
|
|
bool | IsVector () const |
| Return true if the underlying type is an vector 2/3/4 type. More...
|
|
bool | IsMatrix () const |
| Return true if the underlying type is an matrix 3/4 type. More...
|
|
bool | IsString () const |
| Return true if the underlying type is a string type. More...
|
|
bool | IsPtr () const |
| Return true if this Value is a pointer type. More...
|
|
bool | IsConstant () const |
| Return true if this Value is a constant. More...
|
|
size_t | GetArrayNumElements () const |
| Return the number of elements in this array type. More...
|
|
Value | IsNan (llvm::IRBuilder<> &B) const |
| Emit IR to check whether this value is NaN. Only works on Float types and will generate invalid IR if this Value is not a Float instance. More...
|
|
Value | Load (llvm::IRBuilder<> &B) const |
| Emit IR to load the current value. Not typically required to call directly. Will generate invalid IR if this Value is not a Ptr. More...
|
|
Value | LoadIfPtr (llvm::IRBuilder<> &B) const |
| Emit IR to load the current value if it is a ptr. Not typically required to call directly. More...
|
|
Value | GetArrayElement (llvm::IRBuilder<> &B, Value idx) const |
| Emit IR to return a scalar at the provided index from this array value. Will generate invalid IR if this Value is not an array or if idx is not an integer. More...
|
|
Value | GetArrayElement (llvm::IRBuilder<> &B, uint64_t idx) const |
| Emit IR to return a scalar at the provided index from this array value. Will generate invalid IR if this Value is not an array. More...
|
|
void | ArrayToScalars (llvm::IRBuilder<> &B, std::vector< Value > &elements, const bool load=false) const |
| Emit IR to extract scalar values from the elements in this array and populate the provided vector with them. The scalars are additionally loaded if load is true. Will generate invalid IR if this is not an array. More...
|
|
Value | ScalarToArray (llvm::IRBuilder<> &B, size_t size) const |
| Emit IR to broadcast this scalar to a new array. Will generated invalid IR if this is not a scalar or if size is zero. More...
|
|
Value | ScalarToIdentMatrix3 (llvm::IRBuilder<> &B) const |
| Emit IR to create a new 3x3 matrix from this scalar value, adhering to scalar->matrix promotion rules. Will generate invalid IR if this is not a scalar value. More...
|
|
Value | ScalarToIdentMatrix4 (llvm::IRBuilder<> &B) const |
| Emit IR to create a new 4x4 matrix from this scalar value, adhering to scalar->matrix promotion rules. Will generate invalid IR if this is not a scalar value. More...
|
|
Value | ScalarBoolComparison (llvm::IRBuilder<> &B) const |
| Emit IR to perform standard boolean comparison on this scalar i.e. bool(scalar) or bool(scalar == 0). Returns a Value of type bool. Will return Value::Invalid() if this is not a bool/int/float. More...
|
|
Value | Select (llvm::IRBuilder<> &B, const Value &trueval, const Value &falseval) const |
| Emit IR to select a value based on this boolean scalar value. Will generate invalid IR if this is not a boolean value, or if trueval and falseval have different types. More...
|
|
Value | CastToPrecision (llvm::IRBuilder<> &B, llvm::Type *precision) const |
| Emit IR to cast this scalar or array to a new value of the provided scalar precision. Returns a new value of the same class type (scalar or array) but with a new precision. Will generate invalid IR if the precision is not an integer or floating point precision type. If this is not an array or scalar, no IR is emitted and Value::Invalid() is returned. Additionally, if the provided precision is the same as this scalar/array's underlying precision, no IR is emitted and no new value is created. More...
|
|
Value | Not (llvm::IRBuilder<> &B, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to create a unary not instruction on this scalar or integer array (i.e. !value). If the value is not a int/float/integer array, no IR is emitted, a warning is logged (if a logger is provided) and Value::Invalid is returned. More...
|
|
Value | BitNot (llvm::IRBuilder<> &B, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to create a unary not instruction on this integer or integer array (i.e. ~value). If the value is not a int/integer array, no IR is emitted, a warning is logged (if a logger is provided) and Value::Invalid is returned. More...
|
|
Value | Negate (llvm::IRBuilder<> &B, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to create a unary not instruction on this scalar or array (i.e. -value). If the value is not a int/float/array, no IR is is emitted, a warning is logged (if a logger is provided) and Value::Invalid is returned. More...
|
|
Value | Increment (llvm::IRBuilder<> &B, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to increment this scalar (i.e. value + 1). Will return Value::Invalid() and report a message to a logger (if provided) if this is not an integer (non-bool) or float scalar. More...
|
|
Value | Decrement (llvm::IRBuilder<> &B, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to increment this scalar (i.e. value - 1). Will return Value::Invalid() and report a message to a logger (if provided) if this is not an integer (non-bool) or float scalar. More...
|
|
Value | Binary (llvm::IRBuilder<> &B, Value rhs, const ast::tokens::OperatorToken &op, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a binary operation on this LHS value and a provided RHS value. If the operation is not a valid binary operation, Value::Invalid() is returned. Defer to the explicit binary methods on this class for more details. More...
|
|
Value | And (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a && operation on two scalars. Assumes both inputs are scalars (this checking is currently done in the ComputeGenerator) and will cause undefined behaviour if they are not. More...
|
|
Value | Or (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a || operation on two scalars. Assumes both inputs are scalars (this checking is currently done in the ComputeGenerator) and will cause undefined behaviour if they are not. More...
|
|
Value | Add (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a + operation on two values. More...
|
|
Value | Subtract (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a - operation on two values. More...
|
|
Value | Multiply (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a * operation on two values. More...
|
|
Value | Divide (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a / operation on two values If the denominator is constant and zero, returns Value::Invalid() More...
|
|
Value | Modulo (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a FLOORED % operation on two values. More...
|
|
Value | TruncatedModulo (llvm::IRBuilder<> &B, Value rhs) const |
| Emit IR to perform a TRUNCATED % operation on two values. More...
|
|
Value | Equals (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a == operation on two values. More...
|
|
Value | NotEquals (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a != operation on two values. More...
|
|
Value | GreaterThan (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a > operation on two values. More...
|
|
Value | GreaterThanEquals (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a >= operation on two values. More...
|
|
Value | LessThan (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a < operation on two values. More...
|
|
Value | LessThanEquals (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a <= operation on two values. More...
|
|
Value | ShiftLeft (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a << operation. Both values must be integers. More...
|
|
Value | ShiftRight (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a >> operation. Both values must be integers. More...
|
|
Value | BitAnd (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a & operation. Both values must be integers. More...
|
|
Value | BitOr (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a | operation. Both values must be integers. More...
|
|
Value | BitXor (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to perform a ^ operation. Both values must be integers. More...
|
|
Value | Assign (llvm::IRBuilder<> &B, Value rhs, Logger *log=nullptr, const ax::ast::Node *node=nullptr) const |
| Emit IR to assign the provided rhs to this value. More...
|
|
void | Print () const |
| Dump this value/type to llvm::errs. More...
|
|
llvm::Value * | GetValue () const |
| Access the underlying llvm Value. More...
|
|
llvm::Type * | GetUnderlyingType () const |
| Access the underlying llvm Type. More...
|
|
llvm::Type * | GetUnderlyingScalarType () const |
| Access the underlying scalar type. This method assumes the current value is a scalar or array. More...
|
|
Intermediate representation wrapper for supported value types in AX as immutable instances.
This class allows you to generate LLVM IR for common operations supported by the AX grammar whilst abstracting away a lot of the complexity of the underlying LLVM state. This class is not meant as a definitive representation of all possible LLVM IR instructions that can be emitted, more as a strict helper translation layer for some supported AX instructions to LLVM IR. More generally, this is intended to be used for all arithmetic operations and less so for program control flow (branches, loops, etc). Importantly, this class abstracts away the concept of ptr/loaded instructions. That is, users of this API usually do not need to worry about explicitly loading or querying the state of LLVM IR allocations when calling methods. Instances of Value types also ensure that the required underlying type information is retained, necessary from LLVM 15 onwards (due to the introduction of LLVM's opaque ptr changes).
The subset of possible types this class supports are
- void types (for function returns)
- AX scalar values (bool, ints, floats)
- AX array values (element types of ints or floats)
- AX string values
Note that a Value can have a variety of arithmetic type/precision states. The API of this class does not guaranteed compatibility between all states. Some failure cases may report a log message and return Value::Invalid() or generate invalid IR/result in undefined behaviour if the inputs are not correct. Refer to individual API methods for more details.