Intel® Implicit SPMD Program Compiler (Intel® ISPC)
1.13.0
|
Implementations of expression classes. More...
#include "expr.h"
#include "ast.h"
#include "ctx.h"
#include "llvmutil.h"
#include "module.h"
#include "sym.h"
#include "type.h"
#include "util.h"
#include <inttypes.h>
#include <list>
#include <set>
#include <stdio.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/IR/CallingConv.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
Go to the source code of this file.
Classes | |
class | StructMemberExpr |
class | VectorMemberExpr |
Macros | |
#define | FOLD_OP(O, E) |
#define | FOLD_OP_REF(O, E, TRef) |
Functions | |
static Expr * | lArrayToPointer (Expr *expr) |
static bool | lIsAllIntZeros (Expr *expr) |
static bool | lDoTypeConv (const Type *fromType, const Type *toType, Expr **expr, bool failureOk, const char *errorMsgBase, SourcePos pos) |
bool | CanConvertTypes (const Type *fromType, const Type *toType, const char *errorMsgBase, SourcePos pos) |
Expr * | TypeConvertExpr (Expr *expr, const Type *toType, const char *errorMsgBase) |
bool | PossiblyResolveFunctionOverloads (Expr *expr, const Type *type) |
void | InitSymbol (llvm::Value *ptr, const Type *symType, Expr *initExpr, FunctionEmitContext *ctx, SourcePos pos) |
static const Type * | lMatchingBoolType (const Type *type) |
static llvm::Constant * | lLLVMConstantValue (const Type *type, llvm::LLVMContext *ctx, double value) |
static llvm::Value * | lMaskForSymbol (Symbol *baseSym, FunctionEmitContext *ctx) |
static void | lStoreAssignResult (llvm::Value *value, llvm::Value *ptr, const Type *valueType, const Type *ptrType, FunctionEmitContext *ctx, Symbol *baseSym) |
static llvm::Value * | lEmitPrePostIncDec (UnaryExpr::Op op, Expr *expr, SourcePos pos, FunctionEmitContext *ctx) |
static llvm::Value * | lEmitNegate (Expr *arg, SourcePos pos, FunctionEmitContext *ctx) |
template<typename T > | |
static Expr * | lOptimizeBitNot (ConstExpr *constExpr, const Type *type, SourcePos pos) |
template<typename T > | |
static Expr * | lOptimizeNegate (ConstExpr *constExpr, const Type *type, SourcePos pos) |
static const char * | lOpString (BinaryExpr::Op op) |
static llvm::Value * | lEmitBinaryBitOp (BinaryExpr::Op op, llvm::Value *arg0Val, llvm::Value *arg1Val, bool isUnsigned, FunctionEmitContext *ctx) |
static llvm::Value * | lEmitBinaryPointerArith (BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1, const Type *type0, const Type *type1, FunctionEmitContext *ctx, SourcePos pos) |
static llvm::Value * | lEmitBinaryArith (BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1, const Type *type0, const Type *type1, FunctionEmitContext *ctx, SourcePos pos) |
static llvm::Value * | lEmitBinaryCmp (BinaryExpr::Op op, llvm::Value *e0Val, llvm::Value *e1Val, const Type *type, FunctionEmitContext *ctx, SourcePos pos) |
Expr * | lCreateBinaryOperatorCall (const BinaryExpr::Op bop, Expr *a0, Expr *a1, const SourcePos &sp) |
Expr * | MakeBinaryExpr (BinaryExpr::Op o, Expr *a, Expr *b, SourcePos p) |
llvm::Value * | lEmitLogicalOp (BinaryExpr::Op op, Expr *arg0, Expr *arg1, FunctionEmitContext *ctx, SourcePos pos) |
static bool | lIsDifficultShiftAmount (Expr *expr) |
template<typename T , typename TRef > | |
static ConstExpr * | lConstFoldBinaryIntOp (BinaryExpr::Op op, const T *v0, const T *v1, ConstExpr *carg0, SourcePos pos) |
template<typename T > | |
static ConstExpr * | lConstFoldBinaryLogicalOp (BinaryExpr::Op op, const T *v0, const T *v1, ConstExpr *carg0) |
template<typename T , typename TRef > | |
static ConstExpr * | lConstFoldBinaryArithOp (BinaryExpr::Op op, const T *v0, const T *v1, ConstExpr *carg0, SourcePos pos) |
static ConstExpr * | lConstFoldBoolBinaryOp (BinaryExpr::Op op, const bool *v0, const bool *v1, ConstExpr *carg0) |
template<typename T > | |
static Expr * | lConstFoldBinaryFPOp (ConstExpr *constArg0, ConstExpr *constArg1, BinaryExpr::Op op, BinaryExpr *origExpr, SourcePos pos) |
template<typename T , typename TRef > | |
static Expr * | lConstFoldBinaryIntOp (ConstExpr *constArg0, ConstExpr *constArg1, BinaryExpr::Op op, BinaryExpr *origExpr, SourcePos pos) |
static bool | lCanImproveVectorDivide (Expr *arg0, Expr *arg1, int *divisor) |
static std::pair< llvm::Constant *, bool > | lGetBinaryExprStorageConstant (const Type *type, const BinaryExpr *bExpr, bool isStorageType) |
static const char * | lOpString (AssignExpr::Op op) |
static llvm::Value * | lEmitOpAssign (AssignExpr::Op op, Expr *arg0, Expr *arg1, const Type *type, Symbol *baseSym, SourcePos pos, FunctionEmitContext *ctx) |
static bool | lCheckForConstStructMember (SourcePos pos, const StructType *structType, const StructType *initialType) |
static llvm::Value * | lEmitVaryingSelect (FunctionEmitContext *ctx, llvm::Value *test, llvm::Value *expr1, llvm::Value *expr2, const Type *type) |
static void | lEmitSelectExprCode (FunctionEmitContext *ctx, llvm::Value *testVal, llvm::Value *oldMask, llvm::Value *fullMask, Expr *expr, llvm::Value *exprPtr) |
template<typename T > | |
Expr * | lConstFoldSelect (const bool bv[], ConstExpr *constExpr1, ConstExpr *constExpr2, const Type *exprType, SourcePos pos) |
static const FunctionType * | lGetFunctionType (Expr *func) |
bool | FullResolveOverloads (Expr *func, ExprList *args, std::vector< const Type *> *argTypes, std::vector< bool > *argCouldBeNULL, std::vector< bool > *argIsConstant) |
static std::pair< llvm::Constant *, bool > | lGetExprListConstant (const Type *type, const ExprList *eList, bool isStorageType) |
static llvm::Value * | lAddVaryingOffsetsIfNeeded (FunctionEmitContext *ctx, llvm::Value *ptr, const Type *ptrRefType) |
static bool | lVaryingStructHasUniformMember (const Type *type, SourcePos pos) |
static llvm::Value * | lConvertToSlicePointer (FunctionEmitContext *ctx, llvm::Value *ptr, const PointerType *slicePtrType) |
static void | lCheckIndicesVersusBounds (const Type *baseExprType, Expr *index) |
static llvm::Value * | lConvertPtrToSliceIfNeeded (FunctionEmitContext *ctx, llvm::Value *ptr, const Type **type) |
static int | lIdentifierToVectorElement (char id) |
template<typename From , typename To > | |
static void | lConvertElement (From from, To *to) |
template<typename To > | |
static void | lConvertElement (bool from, To *to) |
template<typename From > | |
static void | lConvertElement (From from, bool *to) |
static void | lConvertElement (bool from, bool *to) |
template<typename From , typename To > | |
static void | lConvert (const From *from, To *to, int count, bool forceVarying) |
static std::pair< llvm::Constant *, bool > | lGetConstExprConstant (const Type *constType, const ConstExpr *cExpr, bool isStorageType) |
static llvm::Value * | lTypeConvAtomic (FunctionEmitContext *ctx, llvm::Value *exprVal, const AtomicType *toType, const AtomicType *fromType, SourcePos pos) |
static llvm::Value * | lUniformValueToVarying (FunctionEmitContext *ctx, llvm::Value *value, const Type *type, SourcePos pos) |
static const Type * | lDeconstifyType (const Type *t) |
static llvm::Constant * | lConvertPointerConstant (llvm::Constant *c, const Type *constType) |
static std::string | lGetOverloadCandidateMessage (const std::vector< Symbol *> &funcs, const std::vector< const Type *> &argTypes, const std::vector< bool > *argCouldBeNULL) |
static bool | lIsMatchWithTypeWidening (const Type *callType, const Type *funcArgType) |
static bool | lArgIsPointerType (const Type *type) |
Implementations of expression classes.
Definition in file expr.cpp.
#define FOLD_OP | ( | O, | |
E | |||
) |
Definition at line 2011 of file expr.cpp.
Referenced by lConstFoldBinaryLogicalOp(), and lConstFoldBoolBinaryOp().
#define FOLD_OP_REF | ( | O, | |
E, | |||
TRef | |||
) |
Definition at line 2017 of file expr.cpp.
Referenced by lConstFoldBinaryArithOp(), and lConstFoldBinaryIntOp().
bool CanConvertTypes | ( | const Type * | fromType, |
const Type * | toType, | ||
const char * | errorMsgBase = NULL , |
||
SourcePos | pos = SourcePos() |
||
) |
This function indicates whether it's legal to convert from fromType to toType. If the optional errorMsgBase and source position parameters are provided, then an error message is issued if the type conversion isn't possible.
Definition at line 544 of file expr.cpp.
References lDoTypeConv().
Referenced by FunctionSymbolExpr::computeOverloadCost(), and FunctionCallExpr::TypeCheck().
bool FullResolveOverloads | ( | Expr * | func, |
ExprList * | args, | ||
std::vector< const Type *> * | argTypes, | ||
std::vector< bool > * | argCouldBeNULL, | ||
std::vector< bool > * | argIsConstant | ||
) |
Definition at line 3558 of file expr.cpp.
References ExprList::exprs, Expr::GetType(), and lIsAllIntZeros().
Referenced by FunctionCallExpr::GetType(), and FunctionCallExpr::TypeCheck().
void InitSymbol | ( | llvm::Value * | ptr, |
const Type * | symType, | ||
Expr * | initExpr, | ||
FunctionEmitContext * | ctx, | ||
SourcePos | pos | ||
) |
Utility routine that emits code to initialize a symbol given an initializer expression.
ptr | Memory location of storage for the symbol's data |
symName | Name of symbol (used in error messages) |
symType | Type of variable being initialized |
initExpr | Expression for the initializer |
ctx | FunctionEmitContext to use for generating instructions |
pos | Source file position of the variable being initialized |
Definition at line 594 of file expr.cpp.
References FunctionEmitContext::AddElementOffset(), AssertPos, Globals::ctx, Type::Equal(), Error(), Module::errorCount, ExprList::exprs, FATAL, g, Type::GetAsUniformType(), FunctionEmitContext::GetCurrentBasicBlock(), CollectionType::GetElementCount(), FunctionEmitContext::GetElementPtrInst(), CollectionType::GetElementType(), Type::GetSOAWidth(), Expr::GetStorageConstant(), Variability::GetString(), Type::GetString(), ReferenceType::GetString(), Expr::GetType(), PointerType::GetUniform(), Expr::GetValue(), Type::GetVariability(), Target::getVectorWidth(), InitSymbol(), Type::IsBasicType(), Type::IsSOAType(), Type::IsVaryingType(), LLVMInt32(), Type::LLVMStorageType(), m, FunctionEmitContext::MemcpyInst(), Module::module, ASTNode::pos, PossiblyResolveFunctionOverloads(), Target::SizeOf(), FunctionEmitContext::StoreInst(), Globals::target, and TypeConvertExpr().
Referenced by DeclStmt::EmitCode(), NewExpr::GetValue(), and InitSymbol().
|
static |
When computing pointer values, we need to apply a per-lane offset when we have a varying pointer that is itself indexing into varying data. Consdier the following ispc code:
uniform float u[] = ...; float v[] = ...; int index = ...; float a = u[index]; float b = v[index];
To compute the varying pointer that holds the addresses to load from for u[index], we basically just need to multiply index element-wise by sizeof(float) before doing the memory load. For v[index], we need to do the same scaling but also need to add per-lane offsets <0, sizeof(float), 2*sizeof(float), ...> so that the i'th lane loads the i'th of the varying values at its index value.
This function handles figuring out when this additional offset is needed and then incorporates it in the varying pointer value.
Definition at line 3977 of file expr.cpp.
References Assert, Type::GetAsUniformType(), PointerType::GetBaseType(), FunctionEmitContext::GetElementPtrInst(), PointerType::GetVarying(), Type::IsBasicType(), PointerType::IsSlice(), Type::IsUniformType(), Type::IsVaryingType(), and FunctionEmitContext::ProgramIndexVector().
Referenced by IndexExpr::GetLValue(), MemberExpr::GetLValue(), IndexExpr::GetValue(), and DerefExpr::GetValue().
|
static |
Definition at line 7800 of file expr.cpp.
References ReferenceType::GetReferenceTarget().
Referenced by FunctionSymbolExpr::computeOverloadCost().
Definition at line 140 of file expr.cpp.
References Assert, AssertPos, Expr::GetType(), Expr::Optimize(), ASTNode::pos, Expr::TypeCheck(), and AtomicType::UniformInt32.
Referenced by TypeCastExpr::GetValue(), and BinaryExpr::TypeCheck().
Definition at line 2163 of file expr.cpp.
References BinaryExpr::arg1, Type::EqualIgnoringConst(), Expr::GetType(), ConstExpr::GetValues(), ISPC_MAX_NVEC, AtomicType::VaryingInt16, AtomicType::VaryingInt32, AtomicType::VaryingInt8, AtomicType::VaryingUInt16, AtomicType::VaryingUInt32, and AtomicType::VaryingUInt8.
Referenced by BinaryExpr::Optimize().
|
static |
Recursively checks a structure type to see if it (or any struct type that it holds) has a const-qualified member.
Definition at line 2951 of file expr.cpp.
References Error(), StructType::GetElementCount(), StructType::GetElementName(), StructType::GetElementType(), Type::GetString(), StructType::GetString(), and Type::IsConstType().
Referenced by AssignExpr::TypeCheck().
If the given array index is a compile time constant, check to see if it value/values don't go past the end of the array; issue a warning if so.
Definition at line 4186 of file expr.cpp.
References CollectionType::GetElementCount(), SequentialType::GetElementType(), Type::GetSOAWidth(), ConstExpr::GetValues(), IndexExpr::index, ISPC_MAX_NVEC, ASTNode::pos, and Warning().
Referenced by IndexExpr::GetLValue().
|
static |
Constant fold binary arithmetic ops.
Definition at line 2077 of file expr.cpp.
References BinaryExpr::Add, ConstExpr::Count(), BinaryExpr::Div, Error(), FOLD_OP_REF, ConstExpr::GetType(), ISPC_MAX_NVEC, BinaryExpr::Mul, ASTNode::pos, and BinaryExpr::Sub.
|
static |
Definition at line 2128 of file expr.cpp.
References ConstExpr::GetValues(), ISPC_MAX_NVEC, and lConstFoldBinaryLogicalOp().
|
static |
Constant fold the binary integer operations that aren't also applicable to floating-point types.
Definition at line 2032 of file expr.cpp.
References BinaryExpr::BitAnd, BinaryExpr::BitOr, BinaryExpr::BitXor, ConstExpr::Count(), FOLD_OP_REF, ConstExpr::GetType(), ISPC_MAX_NVEC, BinaryExpr::Mod, ASTNode::pos, BinaryExpr::Shl, and BinaryExpr::Shr.
|
static |
Definition at line 2143 of file expr.cpp.
References ConstExpr::GetValues(), ISPC_MAX_NVEC, and lConstFoldBinaryLogicalOp().
|
static |
Constant fold the binary logical ops.
Definition at line 2053 of file expr.cpp.
References ConstExpr::Count(), BinaryExpr::Equal, FOLD_OP, BinaryExpr::Ge, ConstExpr::GetType(), BinaryExpr::Gt, ISPC_MAX_NVEC, Type::IsUniformType(), BinaryExpr::Le, BinaryExpr::LogicalAnd, BinaryExpr::LogicalOr, BinaryExpr::Lt, BinaryExpr::NotEqual, ASTNode::pos, AtomicType::UniformBool, and AtomicType::VaryingBool.
Referenced by lConstFoldBinaryFPOp(), lConstFoldBinaryIntOp(), and BinaryExpr::Optimize().
|
static |
Constant fold the various boolean binary ops.
Definition at line 2104 of file expr.cpp.
References BinaryExpr::BitAnd, BinaryExpr::BitOr, BinaryExpr::BitXor, ConstExpr::Count(), BinaryExpr::Equal, FOLD_OP, BinaryExpr::Ge, ConstExpr::GetType(), BinaryExpr::Gt, ISPC_MAX_NVEC, BinaryExpr::Le, BinaryExpr::LogicalAnd, BinaryExpr::LogicalOr, BinaryExpr::Lt, BinaryExpr::NotEqual, and ASTNode::pos.
Referenced by BinaryExpr::Optimize().
Expr* lConstFoldSelect | ( | const bool | bv[], |
ConstExpr * | constExpr1, | ||
ConstExpr * | constExpr2, | ||
const Type * | exprType, | ||
SourcePos | pos | ||
) |
Definition at line 3270 of file expr.cpp.
References ConstExpr::GetValues(), and ISPC_MAX_NVEC.
|
static |
Type conversion utility function
Definition at line 5362 of file expr.cpp.
References g, Target::getVectorWidth(), lConvertElement(), and Globals::target.
Referenced by ConstExpr::GetValues().
|
inlinestatic |
Definition at line 5346 of file expr.cpp.
Referenced by lConvert().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
Definition at line 7073 of file expr.cpp.
References Assert, g, Type::GetSOAWidth(), Target::getVectorWidth(), Type::IsSOAType(), Type::IsUniformType(), Type::IsVaryingType(), LLVMTypes::PointerIntType, and Globals::target.
Referenced by TypeCastExpr::GetConstant(), and AddressOfExpr::GetConstant().
|
static |
Converts the given pointer value to a slice pointer if the pointer points to SOA'ed data.
Definition at line 4221 of file expr.cpp.
References Assert, PointerType::GetAsSlice(), PointerType::GetBaseType(), PointerType::IsSlice(), Type::IsSOAType(), and lConvertToSlicePointer().
Referenced by IndexExpr::GetLValue().
|
static |
Utility routine that takes a regualr pointer (either uniform or varying) and returns a slice pointer with zero offsets.
Definition at line 4169 of file expr.cpp.
References Assert, Globals::ctx, g, FunctionEmitContext::InsertInst(), LLVMGetName(), and PointerType::LLVMType().
Referenced by lConvertPtrToSliceIfNeeded().
Expr* lCreateBinaryOperatorCall | ( | const BinaryExpr::Op | bop, |
Expr * | a0, | ||
Expr * | a1, | ||
const SourcePos & | sp | ||
) |
Definition at line 1576 of file expr.cpp.
References BinaryExpr::arg0, BinaryExpr::arg1, Error(), Type::GetString(), Expr::GetType(), SymbolTable::LookupFunction(), lOpString(), m, ASTNode::pos, and Module::symbolTable.
Referenced by MakeBinaryExpr().
Definition at line 6887 of file expr.cpp.
References Type::GetAsNonConstType(), PointerType::GetBaseType(), and PointerType::GetVariability().
Referenced by TypeCastExpr::TypeCheck().
|
static |
Definition at line 175 of file expr.cpp.
References AssertPos, Type::Equal(), Type::EqualIgnoringConst(), Error(), Type::GetAsConstType(), Type::GetAsNonConstType(), Type::GetAsUniformType(), Type::GetBaseType(), ArrayType::GetElementCount(), ArrayType::GetElementType(), Type::GetReferenceTarget(), Type::GetSOAWidth(), Type::GetString(), Expr::GetType(), PointerType::GetUniform(), Type::GetVariability(), Type::IsBoolType(), Type::IsConstType(), Type::IsUniformType(), Type::IsVaryingType(), PointerType::IsVoidPointer(), Type::IsVoidType(), lIsAllIntZeros(), ASTNode::pos, PointerType::Void, and Warning().
Referenced by CanConvertTypes(), and TypeConvertExpr().
|
static |
Utility routine to emit binary arithmetic operator based on the given BinaryExpr::Op.
Definition at line 1468 of file expr.cpp.
References BinaryExpr::Add, AssertPos, FunctionEmitContext::BinaryOperator(), BinaryExpr::Div, Type::EqualIgnoringConst(), FATAL, Type::IsFloatType(), Type::IsUnsignedType(), Type::IsVaryingType(), lEmitBinaryPointerArith(), LLVMGetName(), BinaryExpr::Mod, BinaryExpr::Mul, PerformanceWarning(), and BinaryExpr::Sub.
Referenced by BinaryExpr::GetValue(), and lEmitOpAssign().
|
static |
Utility routine to emit the binary bitwise operator corresponding to the given BinaryExpr::Op.
Definition at line 1357 of file expr.cpp.
References FunctionEmitContext::BinaryOperator(), BinaryExpr::BitAnd, BinaryExpr::BitOr, BinaryExpr::BitXor, FATAL, BinaryExpr::Shl, and BinaryExpr::Shr.
Referenced by BinaryExpr::GetValue(), and lEmitOpAssign().
|
static |
Utility routine to emit a binary comparison operator based on the given BinaryExpr::Op.
Definition at line 1523 of file expr.cpp.
References FunctionEmitContext::CmpInst(), BinaryExpr::Equal, FATAL, BinaryExpr::Ge, BinaryExpr::Gt, FunctionEmitContext::I1VecToBoolVec(), Type::IsFloatType(), Type::IsUnsignedType(), Type::IsVaryingType(), BinaryExpr::Le, LLVMGetName(), BinaryExpr::Lt, and BinaryExpr::NotEqual.
Referenced by BinaryExpr::GetValue().
|
static |
Definition at line 1387 of file expr.cpp.
References BinaryExpr::Add, AssertPos, FunctionEmitContext::BinaryOperator(), Globals::ctx, Type::EqualIgnoringConst(), FunctionEmitContext::ExtractInst(), FATAL, Opt::force32BitAddressing, g, PointerType::GetAsNonSlice(), PointerType::GetBaseType(), FunctionEmitContext::GetCurrentBasicBlock(), FunctionEmitContext::GetElementPtrInst(), Type::GetSOAWidth(), LLVMTypes::Int32Type, LLVMTypes::Int32VectorType, Target::is32Bit(), PointerType::IsSlice(), Type::IsUniformType(), Type::IsVaryingType(), lLLVMConstantValue(), LLVMIntAsType(), Type::LLVMType(), FunctionEmitContext::MatchIntegerTypes(), Globals::opt, FunctionEmitContext::PtrToIntInst(), Target::SizeOf(), FunctionEmitContext::SmearUniform(), BinaryExpr::Sub, Globals::target, and FunctionEmitContext::TruncInst().
Referenced by lEmitBinaryArith().
llvm::Value* lEmitLogicalOp | ( | BinaryExpr::Op | op, |
Expr * | arg0, | ||
Expr * | arg1, | ||
FunctionEmitContext * | ctx, | ||
SourcePos | pos | ||
) |
Emit code for a && or || logical operator. In particular, the code here handles "short-circuit" evaluation, where the second expression isn't evaluated if the value of the first one determines the value of the result.
Definition at line 1631 of file expr.cpp.
References FunctionEmitContext::All(), FunctionEmitContext::AllocaInst(), AssertPos, FunctionEmitContext::BinaryOperator(), FunctionEmitContext::BranchInst(), FunctionEmitContext::CmpInst(), FunctionEmitContext::CreateBasicBlock(), Module::errorCount, BinaryExpr::EstimateCost(), FunctionEmitContext::GetFullMask(), FunctionEmitContext::GetInternalMask(), Expr::GetType(), Expr::GetValue(), FunctionEmitContext::I1VecToBoolVec(), Type::IsUniformType(), Type::IsVaryingType(), LLVMFalse, LLVMMaskAllOff, LLVMMaskAllOn, LLVMTrue, FunctionEmitContext::LoadInst(), BinaryExpr::LogicalAnd, BinaryExpr::LogicalOr, lOpString(), m, Type::MoreGeneralType(), FunctionEmitContext::NotOperator(), PREDICATE_SAFE_IF_STATEMENT_COST, SafeToRunWithMaskAllOff(), FunctionEmitContext::SetCurrentBasicBlock(), FunctionEmitContext::SetInternalMask(), FunctionEmitContext::SetInternalMaskAnd(), FunctionEmitContext::SetInternalMaskAndNot(), FunctionEmitContext::StoreInst(), TypeConvertExpr(), and AtomicType::VaryingBool.
Referenced by BinaryExpr::GetValue().
|
static |
Utility routine to emit code to negate the given expression.
Definition at line 1009 of file expr.cpp.
References AssertPos, FunctionEmitContext::BinaryOperator(), Globals::ctx, g, Expr::GetType(), Expr::GetValue(), Type::IsFloatType(), Type::IsIntType(), lLLVMConstantValue(), LLVMGetName(), Type::LLVMType(), and FunctionEmitContext::SetDebugPos().
Referenced by UnaryExpr::GetValue().
|
static |
Emit code to do an "assignment + operation" operator, e.g. "+=".
Definition at line 2792 of file expr.cpp.
References BinaryExpr::Add, AssignExpr::AddAssign, AssignExpr::AndAssign, BinaryExpr::BitAnd, BinaryExpr::BitOr, BinaryExpr::BitXor, BinaryExpr::Div, AssignExpr::DivAssign, Error(), FATAL, Expr::GetLValue(), Expr::GetLValueType(), Expr::GetType(), Expr::GetValue(), Type::IsUnsignedType(), lEmitBinaryArith(), lEmitBinaryBitOp(), lMaskForSymbol(), FunctionEmitContext::LoadInst(), lStoreAssignResult(), BinaryExpr::Mod, AssignExpr::ModAssign, BinaryExpr::Mul, AssignExpr::MulAssign, AssignExpr::OrAssign, ASTNode::pos, FunctionEmitContext::SetDebugPos(), BinaryExpr::Shl, AssignExpr::ShlAssign, BinaryExpr::Shr, AssignExpr::ShrAssign, BinaryExpr::Sub, AssignExpr::SubAssign, and AssignExpr::XorAssign.
Referenced by AssignExpr::GetValue().
|
static |
Utility routine to emit code to do a {pre,post}-{inc,dec}rement of the given expresion.
Definition at line 944 of file expr.cpp.
References FunctionEmitContext::BinaryOperator(), Globals::ctx, Error(), g, Expr::GetBaseSymbol(), FunctionEmitContext::GetElementPtrInst(), Expr::GetLValue(), Expr::GetLValueType(), Type::GetReferenceTarget(), Expr::GetType(), Expr::GetValue(), DerefExpr::GetValue(), Type::IsFloatType(), Type::IsUniformType(), lLLVMConstantValue(), lStoreAssignResult(), ASTNode::pos, UnaryExpr::PostInc, UnaryExpr::PreDec, UnaryExpr::PreInc, FunctionEmitContext::SetDebugPos(), AtomicType::UniformInt32, and AtomicType::VaryingInt32.
Referenced by UnaryExpr::GetValue().
|
static |
Definition at line 3105 of file expr.cpp.
References FunctionEmitContext::Any(), FunctionEmitContext::BinaryOperator(), FunctionEmitContext::BranchInst(), FunctionEmitContext::CreateBasicBlock(), Expr::GetType(), Expr::GetValue(), FunctionEmitContext::SetCurrentBasicBlock(), FunctionEmitContext::SetInternalMask(), and FunctionEmitContext::StoreInst().
Referenced by SelectExpr::GetValue().
|
static |
Emit code to select between two varying values based on a varying test value.
Definition at line 3092 of file expr.cpp.
References FunctionEmitContext::AllocaInst(), Assert, Globals::ctx, g, PointerType::GetUniform(), Type::LLVMStorageType(), FunctionEmitContext::LoadInst(), and FunctionEmitContext::StoreInst().
Referenced by SelectExpr::GetValue().
|
static |
Definition at line 2665 of file expr.cpp.
References BinaryExpr::arg0, BinaryExpr::arg1, Expr::GetConstant(), ConstExpr::GetConstant(), BinaryExpr::GetLValueType(), Expr::GetStorageConstant(), ConstExpr::GetStorageConstant(), Expr::GetType(), ConstExpr::GetType(), BinaryExpr::op, and PTYPE.
Referenced by BinaryExpr::GetConstant(), and BinaryExpr::GetStorageConstant().
|
static |
Definition at line 5824 of file expr.cpp.
References AssertPos, ConstExpr::Count(), Globals::ctx, Debug(), Type::Equal(), Module::errorCount, g, Type::GetAsNonConstType(), Type::GetString(), ConstExpr::GetValues(), ISPC_MAX_NVEC, Type::IsUniformType(), Type::IsVaryingType(), LLVMBoolVector(), LLVMBoolVectorInStorage(), LLVMDouble(), LLVMDoubleVector(), LLVMFalse, LLVMFalseInStorage, LLVMFloat(), LLVMFloatVector(), LLVMInt16(), LLVMInt16Vector(), LLVMInt32(), LLVMInt32Vector(), LLVMInt64(), LLVMInt64Vector(), LLVMInt8(), LLVMInt8Vector(), LLVMTrue, LLVMTrueInStorage, Type::LLVMType(), LLVMUInt16(), LLVMUInt16Vector(), LLVMUInt32(), LLVMUInt32Vector(), LLVMUInt64(), LLVMUInt64Vector(), LLVMUInt8(), LLVMUInt8Vector(), m, ASTNode::pos, AtomicType::UniformBool, AtomicType::UniformDouble, AtomicType::UniformFloat, AtomicType::UniformInt16, AtomicType::UniformInt32, AtomicType::UniformInt64, AtomicType::UniformInt8, AtomicType::UniformUInt16, AtomicType::UniformUInt32, AtomicType::UniformUInt64, AtomicType::UniformUInt8, AtomicType::VaryingBool, AtomicType::VaryingDouble, AtomicType::VaryingFloat, AtomicType::VaryingInt16, AtomicType::VaryingInt32, AtomicType::VaryingInt64, AtomicType::VaryingInt8, AtomicType::VaryingUInt16, AtomicType::VaryingUInt32, AtomicType::VaryingUInt64, and AtomicType::VaryingUInt8.
Referenced by ConstExpr::GetConstant(), and ConstExpr::GetStorageConstant().
|
static |
Definition at line 3781 of file expr.cpp.
References AssertPos, Globals::ctx, Error(), Module::errorCount, ExprList::exprs, FATAL, g, Type::GetAsUniformType(), Expr::GetConstant(), CollectionType::GetElementCount(), CollectionType::GetElementType(), Expr::GetStorageConstant(), Type::GetString(), VectorType::getVectorMemoryCount(), Target::getVectorWidth(), Type::IsUniformType(), Type::IsVaryingType(), Type::LLVMType(), m, FunctionCallExpr::Optimize(), ASTNode::pos, Globals::target, and TypeConvertExpr().
Referenced by ExprList::GetConstant(), and ExprList::GetStorageConstant().
|
static |
Definition at line 3429 of file expr.cpp.
References Type::GetBaseType(), and Expr::GetType().
Referenced by FunctionCallExpr::GetLValueType(), FunctionCallExpr::GetType(), and FunctionCallExpr::GetValue().
|
static |
Definition at line 7713 of file expr.cpp.
References Assert, and FunctionType::GetString().
Referenced by FunctionSymbolExpr::ResolveOverloads().
|
static |
Map one character ids to vector element numbers. Allow a few different conventions–xyzw, rgba, uv.
Definition at line 4460 of file expr.cpp.
Referenced by VectorMemberExpr::getElementNumber(), and VectorMemberExpr::GetValue().
|
static |
Definition at line 154 of file expr.cpp.
References Expr::GetType(), ConstExpr::GetValues(), Type::IsIntType(), and ISPC_MAX_NVEC.
Referenced by FullResolveOverloads(), lDoTypeConv(), and BinaryExpr::TypeCheck().
|
static |
Definition at line 1857 of file expr.cpp.
References TypeCastExpr::expr, Expr::GetType(), ConstExpr::GetValues(), ISPC_MAX_NVEC, Type::IsUniformType(), and Type::IsVaryingType().
Referenced by BinaryExpr::GetValue().
Helper function used for function overload resolution: returns true if converting the argument to the call type only requires a type conversion that won't lose information. Otherwise return false.
Definition at line 7740 of file expr.cpp.
References AtomicType::basicType, FATAL, Type::IsUniformType(), AtomicType::TYPE_BOOL, AtomicType::TYPE_DOUBLE, AtomicType::TYPE_FLOAT, AtomicType::TYPE_INT16, AtomicType::TYPE_INT32, AtomicType::TYPE_INT64, AtomicType::TYPE_INT8, AtomicType::TYPE_UINT16, AtomicType::TYPE_UINT32, AtomicType::TYPE_UINT64, and AtomicType::TYPE_UINT8.
Referenced by FunctionSymbolExpr::computeOverloadCost().
|
static |
Definition at line 794 of file expr.cpp.
References Assert, AtomicType::basicType, FATAL, Type::GetBaseType(), Type::IsUniformType(), LLVMBoolVector(), LLVMDouble(), LLVMDoubleVector(), LLVMFalse, LLVMFloat(), LLVMFloatVector(), LLVMInt16(), LLVMInt16Vector(), LLVMInt32(), LLVMInt32Vector(), LLVMInt64(), LLVMInt64Vector(), LLVMInt8(), LLVMInt8Vector(), LLVMTrue, LLVMUInt16(), LLVMUInt16Vector(), LLVMUInt32(), LLVMUInt32Vector(), LLVMUInt64(), LLVMUInt64Vector(), LLVMUInt8(), LLVMUInt8Vector(), AtomicType::TYPE_BOOL, AtomicType::TYPE_DOUBLE, AtomicType::TYPE_FLOAT, AtomicType::TYPE_INT16, AtomicType::TYPE_INT32, AtomicType::TYPE_INT64, AtomicType::TYPE_INT8, AtomicType::TYPE_UINT16, AtomicType::TYPE_UINT32, AtomicType::TYPE_UINT64, AtomicType::TYPE_UINT8, AtomicType::TYPE_VOID, LLVMTypes::VoidPointerType, and LLVMTypes::VoidPointerVectorType.
Referenced by lEmitBinaryPointerArith(), lEmitNegate(), and lEmitPrePostIncDec().
|
static |
Definition at line 902 of file expr.cpp.
References FunctionEmitContext::GetFullMask(), FunctionEmitContext::GetFunction(), FunctionEmitContext::GetInternalMask(), Symbol::parentFunction, SC_STATIC, Symbol::storageClass, and Symbol::type.
Referenced by IndexExpr::GetValue(), MemberExpr::GetValue(), DerefExpr::GetValue(), lEmitOpAssign(), and lStoreAssignResult().
Given an atomic or vector type, this returns a boolean type with the same "shape". In other words, if the given type is a vector type of three uniform ints, the returned type is a vector type of three uniform bools.
Definition at line 779 of file expr.cpp.
References Assert, VectorType::GetElementCount(), Type::IsBasicType(), Type::IsReferenceType(), Type::IsUniformType(), AtomicType::UniformBool, and AtomicType::VaryingBool.
Referenced by UnaryExpr::GetType(), BinaryExpr::GetType(), UnaryExpr::TypeCheck(), and SelectExpr::TypeCheck().
|
static |
Definition at line 1308 of file expr.cpp.
References BinaryExpr::Add, BinaryExpr::BitAnd, BinaryExpr::BitOr, BinaryExpr::BitXor, BinaryExpr::Comma, BinaryExpr::Div, BinaryExpr::Equal, FATAL, BinaryExpr::Ge, BinaryExpr::Gt, BinaryExpr::Le, BinaryExpr::LogicalAnd, BinaryExpr::LogicalOr, BinaryExpr::Lt, BinaryExpr::Mod, BinaryExpr::Mul, BinaryExpr::NotEqual, BinaryExpr::Shl, BinaryExpr::Shr, and BinaryExpr::Sub.
Referenced by BinaryExpr::GetType(), lCreateBinaryOperatorCall(), lEmitLogicalOp(), BinaryExpr::Print(), AssignExpr::Print(), BinaryExpr::TypeCheck(), and AssignExpr::TypeCheck().
|
static |
Definition at line 2760 of file expr.cpp.
References AssignExpr::AddAssign, AssignExpr::AndAssign, AssignExpr::Assign, AssignExpr::DivAssign, FATAL, AssignExpr::ModAssign, AssignExpr::MulAssign, AssignExpr::OrAssign, AssignExpr::ShlAssign, AssignExpr::ShrAssign, AssignExpr::SubAssign, and AssignExpr::XorAssign.
|
static |
Definition at line 1084 of file expr.cpp.
References ConstExpr::GetValues(), and ISPC_MAX_NVEC.
|
static |
Definition at line 1092 of file expr.cpp.
References ConstExpr::GetValues(), and ISPC_MAX_NVEC.
|
static |
Store the result of an assignment to the given location.
Definition at line 921 of file expr.cpp.
References Assert, Opt::disableMaskAllOnOptimizations, Opt::disableMaskedStoreToStore, g, LLVMMaskAllOn, lMaskForSymbol(), Globals::opt, SC_STATIC, Symbol::storageClass, FunctionEmitContext::StoreInst(), Symbol::type, Symbol::varyingCFDepth, and FunctionEmitContext::VaryingCFDepth().
Referenced by AssignExpr::GetValue(), lEmitOpAssign(), and lEmitPrePostIncDec().
|
static |
Handle all the grungy details of type conversion between atomic types. Given an input value in exprVal of type fromType, convert it to the llvm::Value with type toType.
Definition at line 6018 of file expr.cpp.
References AtomicType::basicType, LLVMTypes::BoolVectorType, FunctionEmitContext::CastInst(), FunctionEmitContext::CmpInst(), LLVMTypes::DoubleType, LLVMTypes::DoubleVectorType, FATAL, LLVMTypes::FloatType, LLVMTypes::FloatVectorType, FunctionEmitContext::FPCastInst(), g, Target::GENERIC, Target::getISA(), FunctionEmitContext::I1VecToBoolVec(), LLVMTypes::Int16Type, LLVMTypes::Int16VectorType, LLVMTypes::Int1VectorType, LLVMTypes::Int32Type, LLVMTypes::Int32VectorType, LLVMTypes::Int64Type, LLVMTypes::Int64VectorType, LLVMTypes::Int8Type, LLVMTypes::Int8VectorType, Type::IsUniformType(), Type::IsVaryingType(), LLVMDouble(), LLVMDoubleVector(), LLVMFloat(), LLVMFloatVector(), LLVMGetName(), LLVMInt16(), LLVMInt16Vector(), LLVMInt32(), LLVMInt32Vector(), LLVMInt64(), LLVMInt64Vector(), LLVMInt8(), LLVMInt8Vector(), PerformanceWarning(), FunctionEmitContext::SExtInst(), FunctionEmitContext::SmearUniform(), Globals::target, FunctionEmitContext::TruncInst(), AtomicType::TYPE_BOOL, AtomicType::TYPE_DOUBLE, AtomicType::TYPE_FLOAT, AtomicType::TYPE_INT16, AtomicType::TYPE_INT32, AtomicType::TYPE_INT64, AtomicType::TYPE_INT8, AtomicType::TYPE_UINT16, AtomicType::TYPE_UINT32, AtomicType::TYPE_UINT64, AtomicType::TYPE_UINT8, and FunctionEmitContext::ZExtInst().
Referenced by TypeCastExpr::GetValue(), and lUniformValueToVarying().
|
static |
Converts the given value of the given type to be the varying equivalent, returning the resulting value.
Definition at line 6518 of file expr.cpp.
References Assert, LLVMTypes::BoolType, LLVMTypes::BoolVectorStorageType, Globals::ctx, FunctionEmitContext::ExtractInst(), g, Type::GetAsVaryingType(), CollectionType::GetElementCount(), CollectionType::GetElementType(), StructType::GetElementType(), FunctionEmitContext::InsertInst(), Type::IsBoolType(), Type::IsUniformType(), Type::IsVaryingType(), Type::LLVMStorageType(), lTypeConvAtomic(), ASTNode::pos, FunctionEmitContext::SmearUniform(), FunctionEmitContext::SwitchBoolSize(), FunctionEmitContext::TruncInst(), and TypeCastExpr::type.
Referenced by TypeCastExpr::GetValue().
Check to see if the given type is an array of or pointer to a varying struct type that in turn has a member with bound 'uniform' variability. Issue an error and return true if such a member is found.
Definition at line 4011 of file expr.cpp.
References AssertPos, Error(), Module::errorCount, Type::GetAsVaryingType(), PointerType::GetBaseType(), StructType::GetElementCount(), StructType::GetElementName(), ArrayType::GetElementType(), StructType::GetElementType(), Type::GetString(), StructType::GetString(), Type::IsUniformType(), Type::IsVaryingType(), m, and IndexExpr::type.
Referenced by IndexExpr::GetValue(), and DerefExpr::GetValue().
Expr* MakeBinaryExpr | ( | BinaryExpr::Op | o, |
Expr * | a, | ||
Expr * | b, | ||
SourcePos | p | ||
) |
Definition at line 1617 of file expr.cpp.
References BinaryExpr::BinaryExpr(), lCreateBinaryOperatorCall(), and BinaryExpr::op.
Definition at line 565 of file expr.cpp.
References Type::GetBaseType(), FunctionType::GetNumParameters(), FunctionType::GetParameterType(), ASTNode::pos, and FunctionSymbolExpr::ResolveOverloads().
Referenced by DeclStmt::EmitCode(), InitSymbol(), and AssignExpr::TypeCheck().
This function attempts to convert the given expression to the given type, returning a pointer to a new expression that is the result. If the required type conversion is illegal, it returns NULL and prints an error message using the provided string to indicate the context for which type conversion was being applied (e.g. "function call parameter").
Definition at line 548 of file expr.cpp.
References Debug(), Type::GetString(), Expr::GetType(), lDoTypeConv(), and ASTNode::pos.
Referenced by Module::AddGlobalVariable(), checkInit(), FunctionEmitContext::CurrentLanesReturned(), DeclStmt::EmitCode(), FunctionCallExpr::GetValue(), InitSymbol(), lEmitLogicalOp(), lGetExprListConstant(), IfStmt::TypeCheck(), UnaryExpr::TypeCheck(), DoStmt::TypeCheck(), BinaryExpr::TypeCheck(), ForStmt::TypeCheck(), AssignExpr::TypeCheck(), SelectExpr::TypeCheck(), ForeachStmt::TypeCheck(), FunctionCallExpr::TypeCheck(), IndexExpr::TypeCheck(), SwitchStmt::TypeCheck(), TypeCastExpr::TypeCheck(), AssertStmt::TypeCheck(), and NewExpr::TypeCheck().