Improve naming of llvm Instructions created.
We now try harder to keep the names of instructions related to the initial names of variables they're derived from and so forth. This is useful for making both LLVM IR as well as generated C++ code easier to correlate back to the original ispc source code. Issue #244.
This commit is contained in:
233
expr.cpp
233
expr.cpp
@@ -68,6 +68,7 @@
|
||||
#include <llvm/ExecutionEngine/GenericValue.h>
|
||||
#include <llvm/Support/InstIterator.h>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Expr
|
||||
|
||||
@@ -1029,20 +1030,26 @@ lEmitPrePostIncDec(UnaryExpr::Op op, Expr *expr, SourcePos pos,
|
||||
llvm::Value *binop = NULL;
|
||||
int delta = (op == UnaryExpr::PreInc || op == UnaryExpr::PostInc) ? 1 : -1;
|
||||
|
||||
std::string opName = rvalue->getName().str();
|
||||
if (op == UnaryExpr::PreInc || op == UnaryExpr::PostInc)
|
||||
opName += "_plus1";
|
||||
else
|
||||
opName += "_minus1";
|
||||
|
||||
if (dynamic_cast<const PointerType *>(type) != NULL) {
|
||||
const Type *incType = type->IsUniformType() ? AtomicType::UniformInt32 :
|
||||
AtomicType::VaryingInt32;
|
||||
llvm::Constant *dval = lLLVMConstantValue(incType, g->ctx, delta);
|
||||
binop = ctx->GetElementPtrInst(rvalue, dval, type, "ptr_inc_or_dec");
|
||||
binop = ctx->GetElementPtrInst(rvalue, dval, type, opName.c_str());
|
||||
}
|
||||
else {
|
||||
llvm::Constant *dval = lLLVMConstantValue(type, g->ctx, delta);
|
||||
if (type->IsFloatType())
|
||||
binop = ctx->BinaryOperator(llvm::Instruction::FAdd, rvalue,
|
||||
dval, "val_inc_or_dec");
|
||||
dval, opName.c_str());
|
||||
else
|
||||
binop = ctx->BinaryOperator(llvm::Instruction::Add, rvalue,
|
||||
dval, "val_inc_or_dec");
|
||||
dval, opName.c_str());
|
||||
}
|
||||
|
||||
// And store the result out to the lvalue
|
||||
@@ -1071,11 +1078,11 @@ lEmitNegate(Expr *arg, SourcePos pos, FunctionEmitContext *ctx) {
|
||||
ctx->SetDebugPos(pos);
|
||||
if (type->IsFloatType())
|
||||
return ctx->BinaryOperator(llvm::Instruction::FSub, zero, argVal,
|
||||
"fnegate");
|
||||
LLVMGetName(argVal, "_negate"));
|
||||
else {
|
||||
Assert(type->IsIntType());
|
||||
return ctx->BinaryOperator(llvm::Instruction::Sub, zero, argVal,
|
||||
"inegate");
|
||||
LLVMGetName(argVal, "_negate"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1103,11 +1110,11 @@ UnaryExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
return lEmitNegate(expr, pos, ctx);
|
||||
case LogicalNot: {
|
||||
llvm::Value *argVal = expr->GetValue(ctx);
|
||||
return ctx->NotOperator(argVal, "logicalnot");
|
||||
return ctx->NotOperator(argVal, LLVMGetName(argVal, "_logicalnot"));
|
||||
}
|
||||
case BitNot: {
|
||||
llvm::Value *argVal = expr->GetValue(ctx);
|
||||
return ctx->NotOperator(argVal, "bitnot");
|
||||
return ctx->NotOperator(argVal, LLVMGetName(argVal, "_bitnot"));
|
||||
}
|
||||
default:
|
||||
FATAL("logic error");
|
||||
@@ -1506,17 +1513,22 @@ lEmitBinaryArith(BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1,
|
||||
bool isFloatOp = type0->IsFloatType();
|
||||
bool isUnsignedOp = type0->IsUnsignedType();
|
||||
|
||||
const char *opName = NULL;
|
||||
switch (op) {
|
||||
case BinaryExpr::Add:
|
||||
opName = "add";
|
||||
inst = isFloatOp ? llvm::Instruction::FAdd : llvm::Instruction::Add;
|
||||
break;
|
||||
case BinaryExpr::Sub:
|
||||
opName = "sub";
|
||||
inst = isFloatOp ? llvm::Instruction::FSub : llvm::Instruction::Sub;
|
||||
break;
|
||||
case BinaryExpr::Mul:
|
||||
opName = "mul";
|
||||
inst = isFloatOp ? llvm::Instruction::FMul : llvm::Instruction::Mul;
|
||||
break;
|
||||
case BinaryExpr::Div:
|
||||
opName = "div";
|
||||
if (type0->IsVaryingType() && !isFloatOp)
|
||||
PerformanceWarning(pos, "Division with varying integer types is "
|
||||
"very inefficient.");
|
||||
@@ -1524,6 +1536,7 @@ lEmitBinaryArith(BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1,
|
||||
(isUnsignedOp ? llvm::Instruction::UDiv : llvm::Instruction::SDiv);
|
||||
break;
|
||||
case BinaryExpr::Mod:
|
||||
opName = "mod";
|
||||
if (type0->IsVaryingType() && !isFloatOp)
|
||||
PerformanceWarning(pos, "Modulus operator with varying types is "
|
||||
"very inefficient.");
|
||||
@@ -1535,7 +1548,7 @@ lEmitBinaryArith(BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctx->BinaryOperator(inst, value0, value1, "binop");
|
||||
return ctx->BinaryOperator(inst, value0, value1, LLVMGetName(opName, value0, value1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1550,27 +1563,34 @@ lEmitBinaryCmp(BinaryExpr::Op op, llvm::Value *e0Val, llvm::Value *e1Val,
|
||||
bool isUnsignedOp = type->IsUnsignedType();
|
||||
|
||||
llvm::CmpInst::Predicate pred;
|
||||
const char *opName = NULL;
|
||||
switch (op) {
|
||||
case BinaryExpr::Lt:
|
||||
opName = "less";
|
||||
pred = isFloatOp ? llvm::CmpInst::FCMP_OLT :
|
||||
(isUnsignedOp ? llvm::CmpInst::ICMP_ULT : llvm::CmpInst::ICMP_SLT);
|
||||
break;
|
||||
case BinaryExpr::Gt:
|
||||
opName = "greater";
|
||||
pred = isFloatOp ? llvm::CmpInst::FCMP_OGT :
|
||||
(isUnsignedOp ? llvm::CmpInst::ICMP_UGT : llvm::CmpInst::ICMP_SGT);
|
||||
break;
|
||||
case BinaryExpr::Le:
|
||||
opName = "lessequal";
|
||||
pred = isFloatOp ? llvm::CmpInst::FCMP_OLE :
|
||||
(isUnsignedOp ? llvm::CmpInst::ICMP_ULE : llvm::CmpInst::ICMP_SLE);
|
||||
break;
|
||||
case BinaryExpr::Ge:
|
||||
opName = "greaterequal";
|
||||
pred = isFloatOp ? llvm::CmpInst::FCMP_OGE :
|
||||
(isUnsignedOp ? llvm::CmpInst::ICMP_UGE : llvm::CmpInst::ICMP_SGE);
|
||||
break;
|
||||
case BinaryExpr::Equal:
|
||||
opName = "equal";
|
||||
pred = isFloatOp ? llvm::CmpInst::FCMP_OEQ : llvm::CmpInst::ICMP_EQ;
|
||||
break;
|
||||
case BinaryExpr::NotEqual:
|
||||
opName = "notequal";
|
||||
pred = isFloatOp ? llvm::CmpInst::FCMP_ONE : llvm::CmpInst::ICMP_NE;
|
||||
break;
|
||||
default:
|
||||
@@ -1580,7 +1600,8 @@ lEmitBinaryCmp(BinaryExpr::Op op, llvm::Value *e0Val, llvm::Value *e1Val,
|
||||
|
||||
llvm::Value *cmp = ctx->CmpInst(isFloatOp ? llvm::Instruction::FCmp :
|
||||
llvm::Instruction::ICmp,
|
||||
pred, e0Val, e1Val, "bincmp");
|
||||
pred, e0Val, e1Val,
|
||||
LLVMGetName(opName, e0Val, e1Val));
|
||||
// This is a little ugly: CmpInst returns i1 values, but we use vectors
|
||||
// of i32s for varying bool values; type convert the result here if
|
||||
// needed.
|
||||
@@ -2618,7 +2639,7 @@ lEmitOpAssign(AssignExpr::Op op, Expr *arg0, Expr *arg1, const Type *type,
|
||||
llvm::Value *rvalue = arg1->GetValue(ctx);
|
||||
ctx->SetDebugPos(pos);
|
||||
llvm::Value *mask = lMaskForSymbol(baseSym, ctx);
|
||||
llvm::Value *oldLHS = ctx->LoadInst(lv, mask, lvalueType, "opassign_load");
|
||||
llvm::Value *oldLHS = ctx->LoadInst(lv, mask, lvalueType);
|
||||
|
||||
// Map the operator to the corresponding BinaryExpr::Op operator
|
||||
BinaryExpr::Op basicop;
|
||||
@@ -3955,7 +3976,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
}
|
||||
|
||||
ctx->SetDebugPos(pos);
|
||||
return ctx->LoadInst(ptr, mask, lvalueType, "index");
|
||||
return ctx->LoadInst(ptr, mask, lvalueType);
|
||||
}
|
||||
|
||||
|
||||
@@ -4026,7 +4047,7 @@ lConvertToSlicePointer(FunctionEmitContext *ctx, llvm::Value *ptr,
|
||||
// offsets
|
||||
llvm::Value *result = llvm::Constant::getNullValue(sliceStructType);
|
||||
// And replace the pointer in the struct with the given pointer
|
||||
return ctx->InsertInst(result, ptr, 0);
|
||||
return ctx->InsertInst(result, ptr, 0, LLVMGetName(ptr, "_slice"));
|
||||
}
|
||||
|
||||
|
||||
@@ -4117,7 +4138,8 @@ IndexExpr::GetLValue(FunctionEmitContext *ctx) const {
|
||||
&baseExprType);
|
||||
|
||||
llvm::Value *ptr = ctx->GetElementPtrInst(basePtrValue, indexValue,
|
||||
baseExprType, "ptr_offset");
|
||||
baseExprType,
|
||||
LLVMGetName(basePtrValue, "_offset"));
|
||||
return lAddVaryingOffsetsIfNeeded(ctx, ptr, GetLValueType());
|
||||
}
|
||||
|
||||
@@ -4153,7 +4175,7 @@ IndexExpr::GetLValue(FunctionEmitContext *ctx) const {
|
||||
// And do the actual indexing calculation..
|
||||
llvm::Value *ptr =
|
||||
ctx->GetElementPtrInst(basePtr, LLVMInt32(0), indexValue,
|
||||
basePtrType);
|
||||
basePtrType, LLVMGetName(basePtr, "_offset"));
|
||||
return lAddVaryingOffsetsIfNeeded(ctx, ptr, GetLValueType());
|
||||
}
|
||||
|
||||
@@ -4643,8 +4665,8 @@ VectorMemberExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
|
||||
// Allocate temporary memory to tore the result
|
||||
llvm::Value *resultPtr = ctx->AllocaInst(memberType->LLVMType(g->ctx),
|
||||
"vector_tmp");
|
||||
|
||||
"vector_tmp");
|
||||
|
||||
// FIXME: we should be able to use the internal mask here according
|
||||
// to the same logic where it's used elsewhere
|
||||
llvm::Value *elementMask = ctx->GetFullMask();
|
||||
@@ -4655,17 +4677,19 @@ VectorMemberExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
|
||||
ctx->SetDebugPos(pos);
|
||||
for (size_t i = 0; i < identifier.size(); ++i) {
|
||||
char idStr[2] = { identifier[i], '\0' };
|
||||
llvm::Value *elementPtr = ctx->AddElementOffset(basePtr, indices[i],
|
||||
basePtrType);
|
||||
basePtrType,
|
||||
LLVMGetName(basePtr, idStr));
|
||||
llvm::Value *elementValue =
|
||||
ctx->LoadInst(elementPtr, elementMask, elementPtrType,
|
||||
"vec_element");
|
||||
ctx->LoadInst(elementPtr, elementMask, elementPtrType);
|
||||
|
||||
llvm::Value *ptmp = ctx->AddElementOffset(resultPtr, i, NULL);
|
||||
const char *resultName = LLVMGetName(resultPtr, idStr);
|
||||
llvm::Value *ptmp = ctx->AddElementOffset(resultPtr, i, NULL, resultName);
|
||||
ctx->StoreInst(elementValue, ptmp);
|
||||
}
|
||||
|
||||
return ctx->LoadInst(resultPtr, "swizzle_vec");
|
||||
return ctx->LoadInst(resultPtr, LLVMGetName(basePtr, "_swizzle"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4799,7 +4823,9 @@ MemberExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
}
|
||||
|
||||
ctx->SetDebugPos(pos);
|
||||
return ctx->LoadInst(lvalue, mask, lvalueType, "structelement");
|
||||
std::string suffix = std::string("_") + identifier;
|
||||
return ctx->LoadInst(lvalue, mask, lvalueType,
|
||||
LLVMGetName(lvalue, suffix.c_str()));
|
||||
}
|
||||
|
||||
|
||||
@@ -4841,7 +4867,8 @@ MemberExpr::GetLValue(FunctionEmitContext *ctx) const {
|
||||
expr->GetLValueType();
|
||||
ctx->SetDebugPos(pos);
|
||||
llvm::Value *ptr = ctx->AddElementOffset(basePtr, elementNumber,
|
||||
exprLValueType);
|
||||
exprLValueType,
|
||||
basePtr->getName().str().c_str());
|
||||
|
||||
ptr = lAddVaryingOffsetsIfNeeded(ctx, ptr, GetLValueType());
|
||||
|
||||
@@ -5814,6 +5841,23 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
SourcePos pos) {
|
||||
llvm::Value *cast = NULL;
|
||||
|
||||
std::string opName = exprVal->getName().str();
|
||||
switch (toType->basicType) {
|
||||
case AtomicType::TYPE_BOOL: opName += "_to_bool"; break;
|
||||
case AtomicType::TYPE_INT8: opName += "_to_int8"; break;
|
||||
case AtomicType::TYPE_UINT8: opName += "_to_uint8"; break;
|
||||
case AtomicType::TYPE_INT16: opName += "_to_int16"; break;
|
||||
case AtomicType::TYPE_UINT16: opName += "_to_uint16"; break;
|
||||
case AtomicType::TYPE_INT32: opName += "_to_int32"; break;
|
||||
case AtomicType::TYPE_UINT32: opName += "_to_uint32"; break;
|
||||
case AtomicType::TYPE_INT64: opName += "_to_int64"; break;
|
||||
case AtomicType::TYPE_UINT64: opName += "_to_uint64"; break;
|
||||
case AtomicType::TYPE_FLOAT: opName += "_to_float"; break;
|
||||
case AtomicType::TYPE_DOUBLE: opName += "_to_double"; break;
|
||||
default: FATAL("Unimplemented");
|
||||
}
|
||||
const char *cOpName = opName.c_str();
|
||||
|
||||
switch (toType->basicType) {
|
||||
case AtomicType::TYPE_FLOAT: {
|
||||
llvm::Type *targetType =
|
||||
@@ -5825,17 +5869,17 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
// If we have a bool vector of i32 elements, first truncate
|
||||
// down to a single bit
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
// And then do an unisgned int->float cast
|
||||
cast = ctx->CastInst(llvm::Instruction::UIToFP, // unsigned int
|
||||
exprVal, targetType, "bool2float");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_INT16:
|
||||
case AtomicType::TYPE_INT32:
|
||||
case AtomicType::TYPE_INT64:
|
||||
cast = ctx->CastInst(llvm::Instruction::SIToFP, // signed int to float
|
||||
exprVal, targetType, "int2float");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
@@ -5845,14 +5889,14 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
PerformanceWarning(pos, "Conversion from unsigned int to float is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::UIToFP, // unsigned int to float
|
||||
exprVal, targetType, "uint2float");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
// No-op cast.
|
||||
cast = exprVal;
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
cast = ctx->FPCastInst(exprVal, targetType, "double2float");
|
||||
cast = ctx->FPCastInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -5868,26 +5912,26 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
// truncate i32 bool vector values to i1s
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->CastInst(llvm::Instruction::UIToFP, // unsigned int to double
|
||||
exprVal, targetType, "bool2double");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_INT16:
|
||||
case AtomicType::TYPE_INT32:
|
||||
case AtomicType::TYPE_INT64:
|
||||
cast = ctx->CastInst(llvm::Instruction::SIToFP, // signed int
|
||||
exprVal, targetType, "int2double");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->CastInst(llvm::Instruction::UIToFP, // unsigned int
|
||||
exprVal, targetType, "uint2double");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
cast = ctx->FPCastInst(exprVal, targetType, "float2double");
|
||||
cast = ctx->FPCastInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
cast = exprVal;
|
||||
@@ -5905,8 +5949,8 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2int");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_UINT8:
|
||||
@@ -5918,15 +5962,15 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_UINT32:
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->TruncInst(exprVal, targetType, "int64_to_int8");
|
||||
cast = ctx->TruncInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "float2int");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "double2int");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -5941,8 +5985,8 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2uint");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_UINT8:
|
||||
@@ -5954,21 +5998,21 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_UINT32:
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->TruncInst(exprVal, targetType, "int64_to_uint8");
|
||||
cast = ctx->TruncInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
if (fromType->IsVaryingType())
|
||||
PerformanceWarning(pos, "Conversion from float to unsigned int is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // unsigned int
|
||||
exprVal, targetType, "float2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
if (fromType->IsVaryingType())
|
||||
PerformanceWarning(pos, "Conversion from double to unsigned int is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // unsigned int
|
||||
exprVal, targetType, "double2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -5983,14 +6027,14 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2int");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
cast = ctx->SExtInst(exprVal, targetType, "int2int16");
|
||||
cast = ctx->SExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "uint2uint16");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT16:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
@@ -5998,17 +6042,17 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "float2int");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT32:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->TruncInst(exprVal, targetType, "int64_to_int16");
|
||||
cast = ctx->TruncInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "double2int");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -6023,14 +6067,14 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2uint16");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
cast = ctx->SExtInst(exprVal, targetType, "uint2uint16");
|
||||
cast = ctx->SExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "uint2uint16");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT16:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
@@ -6041,20 +6085,20 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
PerformanceWarning(pos, "Conversion from float to unsigned int is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // unsigned int
|
||||
exprVal, targetType, "float2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT32:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->TruncInst(exprVal, targetType, "int64_to_uint16");
|
||||
cast = ctx->TruncInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
if (fromType->IsVaryingType())
|
||||
PerformanceWarning(pos, "Conversion from double to unsigned int is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // unsigned int
|
||||
exprVal, targetType, "double2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -6069,16 +6113,16 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2int");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_INT16:
|
||||
cast = ctx->SExtInst(exprVal, targetType, "int2int32");
|
||||
cast = ctx->SExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "uint2uint32");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT32:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
@@ -6086,15 +6130,15 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "float2int");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->TruncInst(exprVal, targetType, "int64_to_int32");
|
||||
cast = ctx->TruncInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "double2int");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -6109,16 +6153,16 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2uint");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_INT16:
|
||||
cast = ctx->SExtInst(exprVal, targetType, "uint2uint");
|
||||
cast = ctx->SExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "uint2uint");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT32:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
@@ -6129,18 +6173,18 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
PerformanceWarning(pos, "Conversion from float to unsigned int is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // unsigned int
|
||||
exprVal, targetType, "float2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
cast = ctx->TruncInst(exprVal, targetType, "int64_to_uint32");
|
||||
cast = ctx->TruncInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
if (fromType->IsVaryingType())
|
||||
PerformanceWarning(pos, "Conversion from double to unsigned int is slow. "
|
||||
"Use \"int\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // unsigned int
|
||||
exprVal, targetType, "double2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -6155,22 +6199,22 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2int64");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_INT16:
|
||||
case AtomicType::TYPE_INT32:
|
||||
cast = ctx->SExtInst(exprVal, targetType, "int_to_int64");
|
||||
cast = ctx->SExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "uint_to_int64");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "float2int64");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
@@ -6178,7 +6222,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
break;
|
||||
case AtomicType::TYPE_DOUBLE:
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToSI, // signed int
|
||||
exprVal, targetType, "double2int64");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -6193,25 +6237,25 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
case AtomicType::TYPE_BOOL:
|
||||
if (fromType->IsVaryingType() &&
|
||||
LLVMTypes::BoolVectorType == LLVMTypes::Int32VectorType)
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, "bool_to_i1");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "bool2uint");
|
||||
exprVal = ctx->TruncInst(exprVal, LLVMTypes::Int1VectorType, cOpName);
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT8:
|
||||
case AtomicType::TYPE_INT16:
|
||||
case AtomicType::TYPE_INT32:
|
||||
cast = ctx->SExtInst(exprVal, targetType, "int_to_uint64");
|
||||
cast = ctx->SExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_UINT8:
|
||||
case AtomicType::TYPE_UINT16:
|
||||
case AtomicType::TYPE_UINT32:
|
||||
cast = ctx->ZExtInst(exprVal, targetType, "uint_to_uint64");
|
||||
cast = ctx->ZExtInst(exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_FLOAT:
|
||||
if (fromType->IsVaryingType())
|
||||
PerformanceWarning(pos, "Conversion from float to unsigned int64 is slow. "
|
||||
"Use \"int64\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // signed int
|
||||
exprVal, targetType, "float2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
case AtomicType::TYPE_INT64:
|
||||
case AtomicType::TYPE_UINT64:
|
||||
@@ -6222,7 +6266,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
PerformanceWarning(pos, "Conversion from double to unsigned int64 is slow. "
|
||||
"Use \"int64\" if possible");
|
||||
cast = ctx->CastInst(llvm::Instruction::FPToUI, // signed int
|
||||
exprVal, targetType, "double2uint");
|
||||
exprVal, targetType, cOpName);
|
||||
break;
|
||||
default:
|
||||
FATAL("unimplemented");
|
||||
@@ -6239,7 +6283,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
llvm::Value *zero = fromType->IsUniformType() ? (llvm::Value *)LLVMInt8(0) :
|
||||
(llvm::Value *)LLVMInt8Vector((int8_t)0);
|
||||
cast = ctx->CmpInst(llvm::Instruction::ICmp, llvm::CmpInst::ICMP_NE,
|
||||
exprVal, zero, "cmpi0");
|
||||
exprVal, zero, cOpName);
|
||||
break;
|
||||
}
|
||||
case AtomicType::TYPE_INT16:
|
||||
@@ -6247,7 +6291,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
llvm::Value *zero = fromType->IsUniformType() ? (llvm::Value *)LLVMInt16(0) :
|
||||
(llvm::Value *)LLVMInt16Vector((int16_t)0);
|
||||
cast = ctx->CmpInst(llvm::Instruction::ICmp, llvm::CmpInst::ICMP_NE,
|
||||
exprVal, zero, "cmpi0");
|
||||
exprVal, zero, cOpName);
|
||||
break;
|
||||
}
|
||||
case AtomicType::TYPE_INT32:
|
||||
@@ -6255,14 +6299,14 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
llvm::Value *zero = fromType->IsUniformType() ? (llvm::Value *)LLVMInt32(0) :
|
||||
(llvm::Value *)LLVMInt32Vector(0);
|
||||
cast = ctx->CmpInst(llvm::Instruction::ICmp, llvm::CmpInst::ICMP_NE,
|
||||
exprVal, zero, "cmpi0");
|
||||
exprVal, zero, cOpName);
|
||||
break;
|
||||
}
|
||||
case AtomicType::TYPE_FLOAT: {
|
||||
llvm::Value *zero = fromType->IsUniformType() ? (llvm::Value *)LLVMFloat(0.f) :
|
||||
(llvm::Value *)LLVMFloatVector(0.f);
|
||||
cast = ctx->CmpInst(llvm::Instruction::FCmp, llvm::CmpInst::FCMP_ONE,
|
||||
exprVal, zero, "cmpf0");
|
||||
exprVal, zero, cOpName);
|
||||
break;
|
||||
}
|
||||
case AtomicType::TYPE_INT64:
|
||||
@@ -6270,14 +6314,14 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
llvm::Value *zero = fromType->IsUniformType() ? (llvm::Value *)LLVMInt64(0) :
|
||||
(llvm::Value *)LLVMInt64Vector((int64_t)0);
|
||||
cast = ctx->CmpInst(llvm::Instruction::ICmp, llvm::CmpInst::ICMP_NE,
|
||||
exprVal, zero, "cmpi0");
|
||||
exprVal, zero, cOpName);
|
||||
break;
|
||||
}
|
||||
case AtomicType::TYPE_DOUBLE: {
|
||||
llvm::Value *zero = fromType->IsUniformType() ? (llvm::Value *)LLVMDouble(0.) :
|
||||
(llvm::Value *)LLVMDoubleVector(0.);
|
||||
cast = ctx->CmpInst(llvm::Instruction::FCmp, llvm::CmpInst::FCMP_ONE,
|
||||
exprVal, zero, "cmpd0");
|
||||
exprVal, zero, cOpName);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -6291,7 +6335,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
|
||||
// turn into a vector below, the way it does for everyone
|
||||
// else...
|
||||
cast = ctx->SExtInst(cast, LLVMTypes::BoolVectorType->getElementType(),
|
||||
"i1bool_to_i32bool");
|
||||
LLVMGetName(cast, "to_i32bool"));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -7022,7 +7066,7 @@ DerefExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
ctx->GetFullMask();
|
||||
|
||||
ctx->SetDebugPos(pos);
|
||||
return ctx->LoadInst(ptr, mask, type, "deref_load");
|
||||
return ctx->LoadInst(ptr, mask, type);
|
||||
}
|
||||
|
||||
|
||||
@@ -7395,7 +7439,9 @@ SymbolExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
if (!symbol || !symbol->storagePtr)
|
||||
return NULL;
|
||||
ctx->SetDebugPos(pos);
|
||||
return ctx->LoadInst(symbol->storagePtr, symbol->name.c_str());
|
||||
|
||||
std::string loadName = symbol->name + std::string("_load");
|
||||
return ctx->LoadInst(symbol->storagePtr, loadName.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -8112,7 +8158,8 @@ NewExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
// pointer of the return type and to run the code for initializers,
|
||||
// if present.
|
||||
llvm::Type *ptrType = retType->LLVMType(g->ctx);
|
||||
ptrValue = ctx->BitCastInst(ptrValue, ptrType, "cast_new_ptr");
|
||||
ptrValue = ctx->BitCastInst(ptrValue, ptrType,
|
||||
LLVMGetName(ptrValue, "_cast_ptr"));
|
||||
|
||||
if (initExpr != NULL)
|
||||
InitSymbol(ptrValue, allocType, initExpr, ctx, pos);
|
||||
|
||||
Reference in New Issue
Block a user