Many fixes for recent LLVM dev tree API changes

This commit is contained in:
Matt Pharr
2011-07-18 15:54:39 +01:00
parent 65a29ec316
commit 654cfb4b4b
11 changed files with 233 additions and 154 deletions

View File

@@ -476,7 +476,7 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module,
Symbol *pw = new Symbol(name, SourcePos(), AtomicType::UniformConstInt32); Symbol *pw = new Symbol(name, SourcePos(), AtomicType::UniformConstInt32);
pw->isStatic = true; pw->isStatic = true;
pw->constValue = new ConstExpr(pw->type, val, SourcePos()); pw->constValue = new ConstExpr(pw->type, val, SourcePos());
const llvm::Type *ltype = LLVMTypes::Int32Type; LLVM_TYPE_CONST llvm::Type *ltype = LLVMTypes::Int32Type;
llvm::Constant *linit = LLVMInt32(val); llvm::Constant *linit = LLVMInt32(val);
pw->storagePtr = new llvm::GlobalVariable(*module, ltype, true, pw->storagePtr = new llvm::GlobalVariable(*module, ltype, true,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
@@ -496,7 +496,7 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) {
pi[i] = i; pi[i] = i;
pidx->constValue = new ConstExpr(pidx->type, pi, SourcePos()); pidx->constValue = new ConstExpr(pidx->type, pi, SourcePos());
const llvm::Type *ltype = LLVMTypes::Int32VectorType; LLVM_TYPE_CONST llvm::Type *ltype = LLVMTypes::Int32VectorType;
llvm::Constant *linit = LLVMInt32Vector(pi); llvm::Constant *linit = LLVMInt32Vector(pi);
pidx->storagePtr = new llvm::GlobalVariable(*module, ltype, true, pidx->storagePtr = new llvm::GlobalVariable(*module, ltype, true,
llvm::GlobalValue::InternalLinkage, linit, llvm::GlobalValue::InternalLinkage, linit,

161
ctx.cpp
View File

@@ -147,7 +147,7 @@ FunctionEmitContext::FunctionEmitContext(const Type *rt, llvm::Function *functio
if (!returnType || returnType == AtomicType::Void) if (!returnType || returnType == AtomicType::Void)
returnValuePtr = NULL; returnValuePtr = NULL;
else { else {
const llvm::Type *ftype = returnType->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *ftype = returnType->LLVMType(g->ctx);
returnValuePtr = AllocaInst(ftype, "return_value_memory"); returnValuePtr = AllocaInst(ftype, "return_value_memory");
// FIXME: don't do this store??? // FIXME: don't do this store???
StoreInst(llvm::Constant::getNullValue(ftype), returnValuePtr); StoreInst(llvm::Constant::getNullValue(ftype), returnValuePtr);
@@ -735,11 +735,12 @@ FunctionEmitContext::CreateBasicBlock(const char *name) {
llvm::Value * llvm::Value *
FunctionEmitContext::I1VecToBoolVec(llvm::Value *b) { FunctionEmitContext::I1VecToBoolVec(llvm::Value *b) {
const llvm::ArrayType *at = llvm::dyn_cast<const llvm::ArrayType>(b->getType()); LLVM_TYPE_CONST llvm::ArrayType *at =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(b->getType());
if (at) { if (at) {
// If we're given an array of vectors of i1s, then do the // If we're given an array of vectors of i1s, then do the
// conversion for each of the elements // conversion for each of the elements
const llvm::Type *boolArrayType = LLVM_TYPE_CONST llvm::Type *boolArrayType =
llvm::ArrayType::get(LLVMTypes::BoolVectorType, at->getNumElements()); llvm::ArrayType::get(LLVMTypes::BoolVectorType, at->getNumElements());
llvm::Value *ret = llvm::UndefValue::get(boolArrayType); llvm::Value *ret = llvm::UndefValue::get(boolArrayType);
@@ -757,11 +758,11 @@ FunctionEmitContext::I1VecToBoolVec(llvm::Value *b) {
llvm::Value * llvm::Value *
FunctionEmitContext::EmitMalloc(const llvm::Type *ty, int align) { FunctionEmitContext::EmitMalloc(LLVM_TYPE_CONST llvm::Type *ty, int align) {
// Emit code to compute the size of the given type using a GEP with a // Emit code to compute the size of the given type using a GEP with a
// NULL base pointer, indexing one element of the given type, and // NULL base pointer, indexing one element of the given type, and
// casting the resulting 'pointer' to an int giving its size. // casting the resulting 'pointer' to an int giving its size.
const llvm::Type *ptrType = llvm::PointerType::get(ty, 0); LLVM_TYPE_CONST llvm::Type *ptrType = llvm::PointerType::get(ty, 0);
llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType); llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType);
llvm::Value *index[1] = { LLVMInt32(1) }; llvm::Value *index[1] = { LLVMInt32(1) };
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[1], llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[1],
@@ -941,15 +942,16 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym) {
Otherwise return zero. Otherwise return zero.
*/ */
static int static int
lArrayVectorWidth(const llvm::Type *t) { lArrayVectorWidth(LLVM_TYPE_CONST llvm::Type *t) {
const llvm::ArrayType *arrayType = llvm::dyn_cast<const llvm::ArrayType>(t); LLVM_TYPE_CONST llvm::ArrayType *arrayType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(t);
if (arrayType == NULL) if (arrayType == NULL)
return 0; return 0;
// We shouldn't be seeing arrays of anything but vectors being passed // We shouldn't be seeing arrays of anything but vectors being passed
// to things like FunctionEmitContext::BinaryOperator() as operands // to things like FunctionEmitContext::BinaryOperator() as operands
const llvm::VectorType *vectorElementType = LLVM_TYPE_CONST llvm::VectorType *vectorElementType =
llvm::dyn_cast<const llvm::VectorType>(arrayType->getElementType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(arrayType->getElementType());
assert(vectorElementType != NULL && assert(vectorElementType != NULL &&
(int)vectorElementType->getNumElements() == g->target.vectorWidth); (int)vectorElementType->getNumElements() == g->target.vectorWidth);
return (int)arrayType->getNumElements(); return (int)arrayType->getNumElements();
@@ -966,7 +968,7 @@ FunctionEmitContext::BinaryOperator(llvm::Instruction::BinaryOps inst,
} }
assert(v0->getType() == v1->getType()); assert(v0->getType() == v1->getType());
const llvm::Type *type = v0->getType(); LLVM_TYPE_CONST llvm::Type *type = v0->getType();
int arraySize = lArrayVectorWidth(type); int arraySize = lArrayVectorWidth(type);
if (arraySize == 0) { if (arraySize == 0) {
llvm::Instruction *bop = llvm::Instruction *bop =
@@ -1000,7 +1002,7 @@ FunctionEmitContext::NotOperator(llvm::Value *v, const char *name) {
// Similarly to BinaryOperator, do the operation on all the elements of // Similarly to BinaryOperator, do the operation on all the elements of
// the array if we're given an array type; otherwise just do the // the array if we're given an array type; otherwise just do the
// regular llvm operation. // regular llvm operation.
const llvm::Type *type = v->getType(); LLVM_TYPE_CONST llvm::Type *type = v->getType();
int arraySize = lArrayVectorWidth(type); int arraySize = lArrayVectorWidth(type);
if (arraySize == 0) { if (arraySize == 0) {
llvm::Instruction *binst = llvm::Instruction *binst =
@@ -1025,20 +1027,20 @@ FunctionEmitContext::NotOperator(llvm::Value *v, const char *name) {
// Given the llvm Type that represents an ispc VectorType, return an // Given the llvm Type that represents an ispc VectorType, return an
// equally-shaped type with boolean elements. (This is the type that will // equally-shaped type with boolean elements. (This is the type that will
// be returned from CmpInst with ispc VectorTypes). // be returned from CmpInst with ispc VectorTypes).
static const llvm::Type * static LLVM_TYPE_CONST llvm::Type *
lGetMatchingBoolVectorType(const llvm::Type *type) { lGetMatchingBoolVectorType(LLVM_TYPE_CONST llvm::Type *type) {
const llvm::ArrayType *arrayType = LLVM_TYPE_CONST llvm::ArrayType *arrayType =
llvm::dyn_cast<const llvm::ArrayType>(type); llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(type);
// should only be called for vector typed stuff... // should only be called for vector typed stuff...
assert(arrayType != NULL); assert(arrayType != NULL);
const llvm::VectorType *vectorElementType = LLVM_TYPE_CONST llvm::VectorType *vectorElementType =
llvm::dyn_cast<const llvm::VectorType>(arrayType->getElementType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(arrayType->getElementType());
assert(vectorElementType != NULL && assert(vectorElementType != NULL &&
(int)vectorElementType->getNumElements() == g->target.vectorWidth); (int)vectorElementType->getNumElements() == g->target.vectorWidth);
const llvm::Type *base = llvm::VectorType::get(LLVMTypes::BoolType, LLVM_TYPE_CONST llvm::Type *base =
g->target.vectorWidth); llvm::VectorType::get(LLVMTypes::BoolType, g->target.vectorWidth);
return llvm::ArrayType::get(base, arrayType->getNumElements()); return llvm::ArrayType::get(base, arrayType->getNumElements());
} }
@@ -1054,7 +1056,7 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst,
} }
assert(v0->getType() == v1->getType()); assert(v0->getType() == v1->getType());
const llvm::Type *type = v0->getType(); LLVM_TYPE_CONST llvm::Type *type = v0->getType();
int arraySize = lArrayVectorWidth(type); int arraySize = lArrayVectorWidth(type);
if (arraySize == 0) { if (arraySize == 0) {
llvm::Instruction *ci = llvm::Instruction *ci =
@@ -1064,7 +1066,7 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst,
return ci; return ci;
} }
else { else {
const llvm::Type *boolType = lGetMatchingBoolVectorType(type); LLVM_TYPE_CONST llvm::Type *boolType = lGetMatchingBoolVectorType(type);
llvm::Value *ret = llvm::UndefValue::get(boolType); llvm::Value *ret = llvm::UndefValue::get(boolType);
for (int i = 0; i < arraySize; ++i) { for (int i = 0; i < arraySize; ++i) {
llvm::Value *a = ExtractInst(v0, i); llvm::Value *a = ExtractInst(v0, i);
@@ -1078,16 +1080,17 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst,
llvm::Value * llvm::Value *
FunctionEmitContext::BitCastInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::BitCastInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
return NULL; return NULL;
} }
const llvm::Type *valType = value->getType(); LLVM_TYPE_CONST llvm::Type *valType = value->getType();
const llvm::ArrayType *at = llvm::dyn_cast<const llvm::ArrayType>(valType); LLVM_TYPE_CONST llvm::ArrayType *at =
if (at && llvm::isa<const llvm::PointerType>(at->getElementType())) { llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(valType);
if (at && llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(at->getElementType())) {
// If we're bitcasting an array of pointers, we have a varying // If we're bitcasting an array of pointers, we have a varying
// lvalue; apply the corresponding bitcast to each of the // lvalue; apply the corresponding bitcast to each of the
// individual pointers and return the result array. // individual pointers and return the result array.
@@ -1112,16 +1115,17 @@ FunctionEmitContext::BitCastInst(llvm::Value *value, const llvm::Type *type,
llvm::Value * llvm::Value *
FunctionEmitContext::PtrToIntInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::PtrToIntInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
return NULL; return NULL;
} }
const llvm::Type *valType = value->getType(); LLVM_TYPE_CONST llvm::Type *valType = value->getType();
const llvm::ArrayType *at = llvm::dyn_cast<const llvm::ArrayType>(valType); LLVM_TYPE_CONST llvm::ArrayType *at =
if (at && llvm::isa<const llvm::PointerType>(at->getElementType())) { llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(valType);
if (at && llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(at->getElementType())) {
// varying lvalue -> apply ptr to int to the individual pointers // varying lvalue -> apply ptr to int to the individual pointers
assert((int)at->getNumElements() == g->target.vectorWidth); assert((int)at->getNumElements() == g->target.vectorWidth);
@@ -1144,16 +1148,17 @@ FunctionEmitContext::PtrToIntInst(llvm::Value *value, const llvm::Type *type,
llvm::Value * llvm::Value *
FunctionEmitContext::IntToPtrInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::IntToPtrInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
return NULL; return NULL;
} }
const llvm::Type *valType = value->getType(); LLVM_TYPE_CONST llvm::Type *valType = value->getType();
const llvm::ArrayType *at = llvm::dyn_cast<const llvm::ArrayType>(valType); LLVM_TYPE_CONST llvm::ArrayType *at =
if (at && llvm::isa<const llvm::PointerType>(at->getElementType())) { llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(valType);
if (at && llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(at->getElementType())) {
// varying lvalue -> apply int to ptr to the individual pointers // varying lvalue -> apply int to ptr to the individual pointers
assert((int)at->getNumElements() == g->target.vectorWidth); assert((int)at->getNumElements() == g->target.vectorWidth);
@@ -1176,7 +1181,7 @@ FunctionEmitContext::IntToPtrInst(llvm::Value *value, const llvm::Type *type,
llvm::Instruction * llvm::Instruction *
FunctionEmitContext::TruncInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::TruncInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
@@ -1194,7 +1199,7 @@ FunctionEmitContext::TruncInst(llvm::Value *value, const llvm::Type *type,
llvm::Instruction * llvm::Instruction *
FunctionEmitContext::CastInst(llvm::Instruction::CastOps op, llvm::Value *value, FunctionEmitContext::CastInst(llvm::Instruction::CastOps op, llvm::Value *value,
const llvm::Type *type, const char *name) { LLVM_TYPE_CONST llvm::Type *type, const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
return NULL; return NULL;
@@ -1210,7 +1215,7 @@ FunctionEmitContext::CastInst(llvm::Instruction::CastOps op, llvm::Value *value,
llvm::Instruction * llvm::Instruction *
FunctionEmitContext::FPCastInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::FPCastInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
@@ -1227,7 +1232,7 @@ FunctionEmitContext::FPCastInst(llvm::Value *value, const llvm::Type *type,
llvm::Instruction * llvm::Instruction *
FunctionEmitContext::SExtInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::SExtInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
@@ -1244,7 +1249,7 @@ FunctionEmitContext::SExtInst(llvm::Value *value, const llvm::Type *type,
llvm::Instruction * llvm::Instruction *
FunctionEmitContext::ZExtInst(llvm::Value *value, const llvm::Type *type, FunctionEmitContext::ZExtInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); assert(m->errorCount > 0);
@@ -1270,14 +1275,15 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0
// FIXME: do we need need to handle the case of the first index being // FIXME: do we need need to handle the case of the first index being
// varying? It's currently needed... // varying? It's currently needed...
assert(!llvm::isa<const llvm::VectorType>(index0->getType())); assert(!llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(index0->getType()));
const llvm::Type *basePtrType = basePtr->getType(); LLVM_TYPE_CONST llvm::Type *basePtrType = basePtr->getType();
const llvm::ArrayType *baseArrayType = LLVM_TYPE_CONST llvm::ArrayType *baseArrayType =
llvm::dyn_cast<const llvm::ArrayType>(basePtrType); llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(basePtrType);
bool baseIsVaryingTypePointer = (baseArrayType != NULL) && bool baseIsVaryingTypePointer = (baseArrayType != NULL) &&
llvm::isa<const llvm::PointerType>(baseArrayType->getElementType()); llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(baseArrayType->getElementType());
bool indexIsVaryingType = llvm::isa<const llvm::VectorType>(index1->getType()); bool indexIsVaryingType =
llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(index1->getType());
if (!indexIsVaryingType && !baseIsVaryingTypePointer) { if (!indexIsVaryingType && !baseIsVaryingTypePointer) {
// The easy case: both the base pointer and the indices are // The easy case: both the base pointer and the indices are
@@ -1316,9 +1322,10 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0
// This is kind of a hack: use the type from the GEP to // This is kind of a hack: use the type from the GEP to
// figure out the return type and the first time through, // figure out the return type and the first time through,
// create an undef value of that type here // create an undef value of that type here
const llvm::PointerType *elementPtrType = LLVM_TYPE_CONST llvm::PointerType *elementPtrType =
llvm::dyn_cast<const llvm::PointerType>(eltPtr->getType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(eltPtr->getType());
const llvm::Type *elementType = elementPtrType->getElementType(); LLVM_TYPE_CONST llvm::Type *elementType =
elementPtrType->getElementType();
lret = llvm::UndefValue::get(LLVMPointerVectorType(elementType)); lret = llvm::UndefValue::get(LLVMPointerVectorType(elementType));
} }
@@ -1345,7 +1352,7 @@ FunctionEmitContext::LoadInst(llvm::Value *lvalue, const Type *type,
return NULL; return NULL;
} }
if (llvm::isa<const llvm::PointerType>(lvalue->getType())) { if (llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(lvalue->getType())) {
// If the lvalue is a straight up regular pointer, then just issue // If the lvalue is a straight up regular pointer, then just issue
// a regular load. First figure out the alignment; in general we // a regular load. First figure out the alignment; in general we
// can just assume the natural alignment (0 here), but for varying // can just assume the natural alignment (0 here), but for varying
@@ -1372,7 +1379,7 @@ FunctionEmitContext::LoadInst(llvm::Value *lvalue, const Type *type,
// information we need from the LLVM::Type, so have to carry the // information we need from the LLVM::Type, so have to carry the
// ispc type in through this path.. // ispc type in through this path..
assert(type != NULL); assert(type != NULL);
assert(llvm::isa<const llvm::ArrayType>(lvalue->getType())); assert(llvm::isa<LLVM_TYPE_CONST llvm::ArrayType>(lvalue->getType()));
return gather(lvalue, type, name); return gather(lvalue, type, name);
} }
} }
@@ -1382,9 +1389,9 @@ llvm::Value *
FunctionEmitContext::gather(llvm::Value *lvalue, const Type *type, FunctionEmitContext::gather(llvm::Value *lvalue, const Type *type,
const char *name) { const char *name) {
// We should have a varying lvalue if we get here... // We should have a varying lvalue if we get here...
assert(llvm::dyn_cast<const llvm::ArrayType>(lvalue->getType())); assert(llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(lvalue->getType()));
const llvm::Type *retType = type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *retType = type->LLVMType(g->ctx);
const StructType *st = dynamic_cast<const StructType *>(type); const StructType *st = dynamic_cast<const StructType *>(type);
if (st) { if (st) {
@@ -1410,7 +1417,7 @@ FunctionEmitContext::gather(llvm::Value *lvalue, const Type *type,
// the GEP stuff in the loop below ends up computing pointers based // the GEP stuff in the loop below ends up computing pointers based
// on elements in the vectors rather than incorrectly advancing to // on elements in the vectors rather than incorrectly advancing to
// the next vector... // the next vector...
const llvm::Type *eltType = LLVM_TYPE_CONST llvm::Type *eltType =
vt->GetBaseType()->GetAsUniformType()->LLVMType(g->ctx); vt->GetBaseType()->GetAsUniformType()->LLVMType(g->ctx);
lvalue = BitCastInst(lvalue, llvm::PointerType::get(llvm::ArrayType::get(eltType, 0), 0)); lvalue = BitCastInst(lvalue, llvm::PointerType::get(llvm::ArrayType::get(eltType, 0), 0));
@@ -1499,7 +1506,7 @@ FunctionEmitContext::addGSMetadata(llvm::Instruction *inst, SourcePos pos) {
llvm::Value * llvm::Value *
FunctionEmitContext::AllocaInst(const llvm::Type *llvmType, const char *name, FunctionEmitContext::AllocaInst(LLVM_TYPE_CONST llvm::Type *llvmType, const char *name,
int align, bool atEntryBlock) { int align, bool atEntryBlock) {
llvm::AllocaInst *inst = NULL; llvm::AllocaInst *inst = NULL;
if (atEntryBlock) { if (atEntryBlock) {
@@ -1519,9 +1526,10 @@ FunctionEmitContext::AllocaInst(const llvm::Type *llvmType, const char *name,
// unlikely that this array will be loaded into varying variables with // unlikely that this array will be loaded into varying variables with
// what will be aligned accesses if the uniform -> varying load is done // what will be aligned accesses if the uniform -> varying load is done
// in regular chunks. // in regular chunks.
const llvm::ArrayType *arrayType = llvm::dyn_cast<const llvm::ArrayType>(llvmType); LLVM_TYPE_CONST llvm::ArrayType *arrayType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(llvmType);
if (align == 0 && arrayType != NULL && if (align == 0 && arrayType != NULL &&
!llvm::isa<const llvm::VectorType>(arrayType->getElementType())) !llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(arrayType->getElementType()))
align = 4 * g->target.nativeVectorWidth; align = 4 * g->target.nativeVectorWidth;
if (align != 0) if (align != 0)
@@ -1546,7 +1554,7 @@ FunctionEmitContext::maskedStore(llvm::Value *rvalue, llvm::Value *lvalue,
return; return;
} }
assert(llvm::isa<const llvm::PointerType>(lvalue->getType())); assert(llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(lvalue->getType()));
const CollectionType *collectionType = const CollectionType *collectionType =
dynamic_cast<const CollectionType *>(rvalueType); dynamic_cast<const CollectionType *>(rvalueType);
@@ -1616,7 +1624,7 @@ void
FunctionEmitContext::scatter(llvm::Value *rvalue, llvm::Value *lvalue, FunctionEmitContext::scatter(llvm::Value *rvalue, llvm::Value *lvalue,
llvm::Value *storeMask, const Type *rvalueType) { llvm::Value *storeMask, const Type *rvalueType) {
assert(rvalueType->IsVaryingType()); assert(rvalueType->IsVaryingType());
assert(llvm::isa<const llvm::ArrayType>(lvalue->getType())); assert(llvm::isa<LLVM_TYPE_CONST llvm::ArrayType>(lvalue->getType()));
const StructType *structType = dynamic_cast<const StructType *>(rvalueType); const StructType *structType = dynamic_cast<const StructType *>(rvalueType);
if (structType) { if (structType) {
@@ -1635,7 +1643,8 @@ FunctionEmitContext::scatter(llvm::Value *rvalue, llvm::Value *lvalue,
// the GEP stuff in the loop below ends up computing pointers based // the GEP stuff in the loop below ends up computing pointers based
// on elements in the vectors rather than incorrectly advancing to // on elements in the vectors rather than incorrectly advancing to
// the next vector... // the next vector...
const llvm::Type *eltType = vt->GetBaseType()->GetAsUniformType()->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *eltType =
vt->GetBaseType()->GetAsUniformType()->LLVMType(g->ctx);
lvalue = BitCastInst(lvalue, llvm::PointerType::get(llvm::ArrayType::get(eltType, 0), 0)); lvalue = BitCastInst(lvalue, llvm::PointerType::get(llvm::ArrayType::get(eltType, 0), 0));
for (int i = 0; i < vt->GetElementCount(); ++i) { for (int i = 0; i < vt->GetElementCount(); ++i) {
@@ -1653,7 +1662,7 @@ FunctionEmitContext::scatter(llvm::Value *rvalue, llvm::Value *lvalue,
assert(dynamic_cast<const AtomicType *>(rvalueType) != NULL); assert(dynamic_cast<const AtomicType *>(rvalueType) != NULL);
llvm::Function *func = NULL; llvm::Function *func = NULL;
const llvm::Type *type = rvalue->getType(); LLVM_TYPE_CONST llvm::Type *type = rvalue->getType();
if (type == LLVMTypes::DoubleVectorType || if (type == LLVMTypes::DoubleVectorType ||
type == LLVMTypes::Int64VectorType) { type == LLVMTypes::Int64VectorType) {
func = m->module->getFunction("__pseudo_scatter_64"); func = m->module->getFunction("__pseudo_scatter_64");
@@ -1720,7 +1729,7 @@ FunctionEmitContext::StoreInst(llvm::Value *rvalue, llvm::Value *lvalue,
llvm::Instruction *si = new llvm::StoreInst(rvalue, lvalue, bblock); llvm::Instruction *si = new llvm::StoreInst(rvalue, lvalue, bblock);
AddDebugPos(si); AddDebugPos(si);
} }
else if (llvm::isa<const llvm::ArrayType>(lvalue->getType())) else if (llvm::isa<LLVM_TYPE_CONST llvm::ArrayType>(lvalue->getType()))
// We have a varying lvalue (an array of pointers), so it's time to // We have a varying lvalue (an array of pointers), so it's time to
// scatter // scatter
scatter(rvalue, lvalue, storeMask, rvalueType); scatter(rvalue, lvalue, storeMask, rvalueType);
@@ -1764,7 +1773,7 @@ FunctionEmitContext::ExtractInst(llvm::Value *v, int elt, const char *name) {
} }
llvm::Instruction *ei = NULL; llvm::Instruction *ei = NULL;
if (llvm::isa<const llvm::VectorType>(v->getType())) if (llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(v->getType()))
ei = llvm::ExtractElementInst::Create(v, LLVMInt32(elt), ei = llvm::ExtractElementInst::Create(v, LLVMInt32(elt),
name ? name : "extract", bblock); name ? name : "extract", bblock);
else else
@@ -1784,7 +1793,7 @@ FunctionEmitContext::InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt,
} }
llvm::Instruction *ii = NULL; llvm::Instruction *ii = NULL;
if (llvm::isa<const llvm::VectorType>(v->getType())) if (llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(v->getType()))
ii = llvm::InsertElementInst::Create(v, eltVal, LLVMInt32(elt), ii = llvm::InsertElementInst::Create(v, eltVal, LLVMInt32(elt),
name ? name : "insert", bblock); name ? name : "insert", bblock);
else else
@@ -1796,7 +1805,7 @@ FunctionEmitContext::InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt,
llvm::PHINode * llvm::PHINode *
FunctionEmitContext::PhiNode(const llvm::Type *type, int count, FunctionEmitContext::PhiNode(LLVM_TYPE_CONST llvm::Type *type, int count,
const char *name) { const char *name) {
llvm::PHINode *pn = llvm::PHINode::Create(type, llvm::PHINode *pn = llvm::PHINode::Create(type,
#if !defined(LLVM_2_8) && !defined(LLVM_2_9) #if !defined(LLVM_2_8) && !defined(LLVM_2_9)
@@ -1833,9 +1842,14 @@ FunctionEmitContext::CallInst(llvm::Function *func,
return NULL; return NULL;
} }
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::Instruction *ci =
llvm::CallInst::Create(func, args, name ? name : "", bblock);
#else
llvm::Instruction *ci = llvm::Instruction *ci =
llvm::CallInst::Create(func, args.begin(), args.end(), llvm::CallInst::Create(func, args.begin(), args.end(),
name ? name : "", bblock); name ? name : "", bblock);
#endif
AddDebugPos(ci); AddDebugPos(ci);
return ci; return ci;
} }
@@ -1849,10 +1863,15 @@ FunctionEmitContext::CallInst(llvm::Function *func, llvm::Value *arg,
return NULL; return NULL;
} }
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::Instruction *ci =
llvm::CallInst::Create(func, arg, name ? name : "", bblock);
#else
llvm::Value *args[] = { arg }; llvm::Value *args[] = { arg };
llvm::Instruction *ci = llvm::Instruction *ci =
llvm::CallInst::Create(func, &args[0], &args[1], name ? name : "", llvm::CallInst::Create(func, &args[0], &args[1], name ? name : "",
bblock); bblock);
#endif
AddDebugPos(ci); AddDebugPos(ci);
return ci; return ci;
} }
@@ -1867,9 +1886,16 @@ FunctionEmitContext::CallInst(llvm::Function *func, llvm::Value *arg0,
} }
llvm::Value *args[] = { arg0, arg1 }; llvm::Value *args[] = { arg0, arg1 };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> argArrayRef(&args[0], &args[2]);
llvm::Instruction *ci =
llvm::CallInst::Create(func, argArrayRef, name ? name : "",
bblock);
#else
llvm::Instruction *ci = llvm::Instruction *ci =
llvm::CallInst::Create(func, &args[0], &args[2], name ? name : "", llvm::CallInst::Create(func, &args[0], &args[2], name ? name : "",
bblock); bblock);
#endif
AddDebugPos(ci); AddDebugPos(ci);
return ci; return ci;
} }
@@ -1916,12 +1942,13 @@ FunctionEmitContext::LaunchInst(llvm::Function *callee,
launchedTasks = true; launchedTasks = true;
const llvm::Type *argType = callee->arg_begin()->getType(); LLVM_TYPE_CONST llvm::Type *argType = callee->arg_begin()->getType();
assert(llvm::PointerType::classof(argType)); assert(llvm::PointerType::classof(argType));
const llvm::PointerType *pt = static_cast<const llvm::PointerType *>(argType); LLVM_TYPE_CONST llvm::PointerType *pt =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(argType);
assert(llvm::StructType::classof(pt->getElementType())); assert(llvm::StructType::classof(pt->getElementType()));
const llvm::StructType *argStructType = LLVM_TYPE_CONST llvm::StructType *argStructType =
static_cast<const llvm::StructType *>(pt->getElementType()); static_cast<LLVM_TYPE_CONST llvm::StructType *>(pt->getElementType());
assert(argStructType->getNumElements() == argVals.size() + 1); assert(argStructType->getNumElements() == argVals.size() + 1);
int align = 4 * RoundUpPow2(g->target.nativeVectorWidth); int align = 4 * RoundUpPow2(g->target.nativeVectorWidth);

23
ctx.h
View File

@@ -213,7 +213,7 @@ public:
/** Emit code to call the user-supplied ISPCMalloc function to /** Emit code to call the user-supplied ISPCMalloc function to
allocate space for an object of thee given type. Returns the allocate space for an object of thee given type. Returns the
pointer value returned by the ISPCMalloc call. */ pointer value returned by the ISPCMalloc call. */
llvm::Value *EmitMalloc(const llvm::Type *ty, int align = 0); llvm::Value *EmitMalloc(LLVM_TYPE_CONST llvm::Type *ty, int align = 0);
/** Emit code to call the user-supplied ISPCFree function, passing it /** Emit code to call the user-supplied ISPCFree function, passing it
the given pointer to storage previously allocated by an the given pointer to storage previously allocated by an
@@ -303,21 +303,21 @@ public:
llvm::CmpInst::Predicate pred, llvm::CmpInst::Predicate pred,
llvm::Value *v0, llvm::Value *v1, const char *name = NULL); llvm::Value *v0, llvm::Value *v1, const char *name = NULL);
llvm::Value *BitCastInst(llvm::Value *value, const llvm::Type *type, llvm::Value *BitCastInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
llvm::Value *PtrToIntInst(llvm::Value *value, const llvm::Type *type, llvm::Value *PtrToIntInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
llvm::Value *IntToPtrInst(llvm::Value *value, const llvm::Type *type, llvm::Value *IntToPtrInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
llvm::Instruction *TruncInst(llvm::Value *value, const llvm::Type *type, llvm::Instruction *TruncInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
llvm::Instruction *CastInst(llvm::Instruction::CastOps op, llvm::Value *value, llvm::Instruction *CastInst(llvm::Instruction::CastOps op, llvm::Value *value,
const llvm::Type *type, const char *name = NULL); LLVM_TYPE_CONST llvm::Type *type, const char *name = NULL);
llvm::Instruction *FPCastInst(llvm::Value *value, const llvm::Type *type, llvm::Instruction *FPCastInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
llvm::Instruction *SExtInst(llvm::Value *value, const llvm::Type *type, llvm::Instruction *SExtInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
llvm::Instruction *ZExtInst(llvm::Value *value, const llvm::Type *type, llvm::Instruction *ZExtInst(llvm::Value *value, LLVM_TYPE_CONST llvm::Type *type,
const char *name = NULL); const char *name = NULL);
/** This GEP method is a generalization of the standard one in LLVM; it /** This GEP method is a generalization of the standard one in LLVM; it
@@ -347,7 +347,7 @@ public:
instruction is added at the start of the function in the entry instruction is added at the start of the function in the entry
basic block; if it should be added to the current basic block, then basic block; if it should be added to the current basic block, then
the atEntryBlock parameter should be false. */ the atEntryBlock parameter should be false. */
llvm::Value *AllocaInst(const llvm::Type *llvmType, const char *name = NULL, llvm::Value *AllocaInst(LLVM_TYPE_CONST llvm::Type *llvmType, const char *name = NULL,
int align = 0, bool atEntryBlock = true); int align = 0, bool atEntryBlock = true);
/** Standard store instruction; for this variant, the lvalue must be a /** Standard store instruction; for this variant, the lvalue must be a
@@ -378,7 +378,8 @@ public:
llvm::Value *InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt, llvm::Value *InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt,
const char *name = NULL); const char *name = NULL);
llvm::PHINode *PhiNode(const llvm::Type *type, int count, const char *name = NULL); llvm::PHINode *PhiNode(LLVM_TYPE_CONST llvm::Type *type, int count,
const char *name = NULL);
llvm::Instruction *SelectInst(llvm::Value *test, llvm::Value *val0, llvm::Instruction *SelectInst(llvm::Value *test, llvm::Value *val0,
llvm::Value *val1, const char *name = NULL); llvm::Value *val1, const char *name = NULL);

View File

@@ -397,7 +397,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
// a recursive call to lLLVMConstantValue(). // a recursive call to lLLVMConstantValue().
const Type *baseType = vectorType->GetBaseType(); const Type *baseType = vectorType->GetBaseType();
llvm::Constant *constElement = lLLVMConstantValue(baseType, ctx, value); llvm::Constant *constElement = lLLVMConstantValue(baseType, ctx, value);
const llvm::Type *llvmVectorType = vectorType->LLVMType(ctx); LLVM_TYPE_CONST llvm::Type *llvmVectorType = vectorType->LLVMType(ctx);
// Now create a constant version of the corresponding LLVM type that we // Now create a constant version of the corresponding LLVM type that we
// use to represent the VectorType. // use to represent the VectorType.
@@ -406,8 +406,8 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
// LLVM ArrayTypes leaks into the code here; it feels like this detail // LLVM ArrayTypes leaks into the code here; it feels like this detail
// should be better encapsulated? // should be better encapsulated?
if (baseType->IsUniformType()) { if (baseType->IsUniformType()) {
const llvm::VectorType *lvt = LLVM_TYPE_CONST llvm::VectorType *lvt =
llvm::dyn_cast<const llvm::VectorType>(llvmVectorType); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(llvmVectorType);
assert(lvt != NULL); assert(lvt != NULL);
std::vector<llvm::Constant *> vals; std::vector<llvm::Constant *> vals;
for (unsigned int i = 0; i < lvt->getNumElements(); ++i) for (unsigned int i = 0; i < lvt->getNumElements(); ++i)
@@ -415,8 +415,8 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
return llvm::ConstantVector::get(vals); return llvm::ConstantVector::get(vals);
} }
else { else {
const llvm::ArrayType *lat = LLVM_TYPE_CONST llvm::ArrayType *lat =
llvm::dyn_cast<const llvm::ArrayType>(llvmVectorType); llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(llvmVectorType);
assert(lat != NULL); assert(lat != NULL);
std::vector<llvm::Constant *> vals; std::vector<llvm::Constant *> vals;
for (unsigned int i = 0; i < lat->getNumElements(); ++i) for (unsigned int i = 0; i < lat->getNumElements(); ++i)
@@ -2419,7 +2419,7 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const {
// The return value for the non-void case is either undefined or the // The return value for the non-void case is either undefined or the
// function return value, depending on whether we actually ran the code // function return value, depending on whether we actually ran the code
// path that called the function or not. // path that called the function or not.
const llvm::Type *lrType = ft->GetReturnType()->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *lrType = ft->GetReturnType()->LLVMType(g->ctx);
llvm::PHINode *ret = ctx->PhiNode(lrType, 2, "fun_ret"); llvm::PHINode *ret = ctx->PhiNode(lrType, 2, "fun_ret");
assert(retVal != NULL); assert(retVal != NULL);
ret->addIncoming(llvm::UndefValue::get(lrType), bSkip); ret->addIncoming(llvm::UndefValue::get(lrType), bSkip);
@@ -2576,15 +2576,16 @@ ExprList::GetConstant(const Type *type) const {
#if defined(LLVM_2_8) || defined(LLVM_2_9) #if defined(LLVM_2_8) || defined(LLVM_2_9)
return llvm::ConstantStruct::get(*g->ctx, cv, false); return llvm::ConstantStruct::get(*g->ctx, cv, false);
#else #else
const llvm::StructType *llvmStructType = LLVM_TYPE_CONST llvm::StructType *llvmStructType =
llvm::dyn_cast<const llvm::StructType>(collectionType->LLVMType(g->ctx)); llvm::dyn_cast<LLVM_TYPE_CONST llvm::StructType>(collectionType->LLVMType(g->ctx));
assert(llvmStructType != NULL); assert(llvmStructType != NULL);
return llvm::ConstantStruct::get(llvmStructType, cv); return llvm::ConstantStruct::get(llvmStructType, cv);
#endif #endif
} }
else { else {
const llvm::Type *lt = type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *lt = type->LLVMType(g->ctx);
const llvm::ArrayType *lat = llvm::dyn_cast<const llvm::ArrayType>(lt); LLVM_TYPE_CONST llvm::ArrayType *lat =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(lt);
// FIXME: should the assert below validly fail for uniform vectors // FIXME: should the assert below validly fail for uniform vectors
// now? Need a test case to reproduce it and then to be sure we // now? Need a test case to reproduce it and then to be sure we
// have the right fix; leave the assert until we can hit it... // have the right fix; leave the assert until we can hit it...
@@ -2625,19 +2626,19 @@ IndexExpr::IndexExpr(Expr *a, Expr *i, SourcePos p)
static llvm::Value * static llvm::Value *
lCastUniformVectorBasePtr(llvm::Value *ptr, FunctionEmitContext *ctx) { lCastUniformVectorBasePtr(llvm::Value *ptr, FunctionEmitContext *ctx) {
const llvm::PointerType *baseType = LLVM_TYPE_CONST llvm::PointerType *baseType =
llvm::dyn_cast<const llvm::PointerType>(ptr->getType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(ptr->getType());
if (!baseType) if (!baseType)
return ptr; return ptr;
const llvm::VectorType *baseEltVecType = LLVM_TYPE_CONST llvm::VectorType *baseEltVecType =
llvm::dyn_cast<const llvm::VectorType>(baseType->getElementType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(baseType->getElementType());
if (!baseEltVecType) if (!baseEltVecType)
return ptr; return ptr;
const llvm::Type *vecEltType = baseEltVecType->getElementType(); LLVM_TYPE_CONST llvm::Type *vecEltType = baseEltVecType->getElementType();
int numElts = baseEltVecType->getNumElements(); int numElts = baseEltVecType->getNumElements();
const llvm::Type *castType = LLVM_TYPE_CONST llvm::Type *castType =
llvm::PointerType::get(llvm::ArrayType::get(vecEltType, numElts), 0); llvm::PointerType::get(llvm::ArrayType::get(vecEltType, numElts), 0);
return ctx->BitCastInst(ptr, castType); return ctx->BitCastInst(ptr, castType);
} }
@@ -3622,7 +3623,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
switch (toType->basicType) { switch (toType->basicType) {
case AtomicType::TYPE_FLOAT: { case AtomicType::TYPE_FLOAT: {
const llvm::Type *targetType = LLVM_TYPE_CONST llvm::Type *targetType =
fromType->IsUniformType() ? LLVMTypes::FloatType : fromType->IsUniformType() ? LLVMTypes::FloatType :
LLVMTypes::FloatVectorType; LLVMTypes::FloatVectorType;
switch (fromType->basicType) { switch (fromType->basicType) {
@@ -3662,7 +3663,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
break; break;
} }
case AtomicType::TYPE_DOUBLE: { case AtomicType::TYPE_DOUBLE: {
const llvm::Type *targetType = LLVM_TYPE_CONST llvm::Type *targetType =
fromType->IsUniformType() ? LLVMTypes::DoubleType : fromType->IsUniformType() ? LLVMTypes::DoubleType :
LLVMTypes::DoubleVectorType; LLVMTypes::DoubleVectorType;
switch (fromType->basicType) { switch (fromType->basicType) {
@@ -3699,7 +3700,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
break; break;
} }
case AtomicType::TYPE_INT32: { case AtomicType::TYPE_INT32: {
const llvm::Type *targetType = LLVM_TYPE_CONST llvm::Type *targetType =
fromType->IsUniformType() ? LLVMTypes::Int32Type : fromType->IsUniformType() ? LLVMTypes::Int32Type :
LLVMTypes::Int32VectorType; LLVMTypes::Int32VectorType;
switch (fromType->basicType) { switch (fromType->basicType) {
@@ -3731,7 +3732,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
break; break;
} }
case AtomicType::TYPE_UINT32: { case AtomicType::TYPE_UINT32: {
const llvm::Type *targetType = LLVM_TYPE_CONST llvm::Type *targetType =
fromType->IsUniformType() ? LLVMTypes::Int32Type : fromType->IsUniformType() ? LLVMTypes::Int32Type :
LLVMTypes::Int32VectorType; LLVMTypes::Int32VectorType;
switch (fromType->basicType) { switch (fromType->basicType) {
@@ -3769,7 +3770,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
break; break;
} }
case AtomicType::TYPE_INT64: { case AtomicType::TYPE_INT64: {
const llvm::Type *targetType = LLVM_TYPE_CONST llvm::Type *targetType =
fromType->IsUniformType() ? LLVMTypes::Int64Type : fromType->IsUniformType() ? LLVMTypes::Int64Type :
LLVMTypes::Int64VectorType; LLVMTypes::Int64VectorType;
switch (fromType->basicType) { switch (fromType->basicType) {
@@ -3803,7 +3804,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
break; break;
} }
case AtomicType::TYPE_UINT64: { case AtomicType::TYPE_UINT64: {
const llvm::Type *targetType = LLVM_TYPE_CONST llvm::Type *targetType =
fromType->IsUniformType() ? LLVMTypes::Int64Type : fromType->IsUniformType() ? LLVMTypes::Int64Type :
LLVMTypes::Int64VectorType; LLVMTypes::Int64VectorType;
switch (fromType->basicType) { switch (fromType->basicType) {
@@ -3904,7 +3905,7 @@ lTypeConvAtomic(FunctionEmitContext *ctx, llvm::Value *exprVal,
// If we also want to go from uniform to varying, replicate out the // If we also want to go from uniform to varying, replicate out the
// value across the vector elements.. // value across the vector elements..
if (toType->IsVaryingType() && fromType->IsUniformType()) { if (toType->IsVaryingType() && fromType->IsUniformType()) {
const llvm::Type *vtype = toType->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *vtype = toType->LLVMType(g->ctx);
llvm::Value *castVec = llvm::UndefValue::get(vtype); llvm::Value *castVec = llvm::UndefValue::get(vtype);
for (int i = 0; i < g->target.vectorWidth; ++i) for (int i = 0; i < g->target.vectorWidth; ++i)
castVec = ctx->InsertInst(castVec, cast, i, "smearinsert"); castVec = ctx->InsertInst(castVec, cast, i, "smearinsert");
@@ -3925,7 +3926,7 @@ lUniformValueToVarying(FunctionEmitContext *ctx, llvm::Value *value,
if (type->IsVaryingType()) if (type->IsVaryingType())
return value; return value;
const llvm::Type *llvmType = type->GetAsVaryingType()->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *llvmType = type->GetAsVaryingType()->LLVMType(g->ctx);
llvm::Value *retValue = llvm::UndefValue::get(llvmType); llvm::Value *retValue = llvm::UndefValue::get(llvmType);
// for structs/arrays/vectors, just recursively make their elements // for structs/arrays/vectors, just recursively make their elements
@@ -3989,7 +3990,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
assert(Type::Equal(toArray->GetBaseType()->GetAsConstType(), assert(Type::Equal(toArray->GetBaseType()->GetAsConstType(),
fromArray->GetBaseType()->GetAsConstType())); fromArray->GetBaseType()->GetAsConstType()));
llvm::Value *v = expr->GetValue(ctx); llvm::Value *v = expr->GetValue(ctx);
const llvm::Type *ptype = toType->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *ptype = toType->LLVMType(g->ctx);
return ctx->BitCastInst(v, ptype); //, "array_cast_0size"); return ctx->BitCastInst(v, ptype); //, "array_cast_0size");
} }

View File

@@ -325,8 +325,8 @@ LLVMBoolVector(const bool *bvec) {
} }
const llvm::ArrayType * LLVM_TYPE_CONST llvm::ArrayType *
LLVMPointerVectorType(const llvm::Type *t) { LLVMPointerVectorType(LLVM_TYPE_CONST llvm::Type *t) {
// NOTE: ArrayType, not VectorType // NOTE: ArrayType, not VectorType
return llvm::ArrayType::get(llvm::PointerType::get(t, 0), return llvm::ArrayType::get(llvm::PointerType::get(t, 0),
g->target.vectorWidth); g->target.vectorWidth);

View File

@@ -155,6 +155,6 @@ extern llvm::Constant *LLVMMaskAllOff;
pointers to that type. (In practice, an array of pointers, since LLVM pointers to that type. (In practice, an array of pointers, since LLVM
prohibits vectors of pointers. prohibits vectors of pointers.
*/ */
extern const llvm::ArrayType *LLVMPointerVectorType(const llvm::Type *t); extern LLVM_TYPE_CONST llvm::ArrayType *LLVMPointerVectorType(LLVM_TYPE_CONST llvm::Type *t);
#endif // ISPC_LLVMUTIL_H #endif // ISPC_LLVMUTIL_H

View File

@@ -317,7 +317,7 @@ lInitFunSymDecl(DeclSpecs *ds, Declarator *decl) {
// Get the LLVM FunctionType // Get the LLVM FunctionType
bool includeMask = (ds->storageClass != SC_EXTERN_C); bool includeMask = (ds->storageClass != SC_EXTERN_C);
const llvm::FunctionType *llvmFunctionType = LLVM_TYPE_CONST llvm::FunctionType *llvmFunctionType =
functionType->LLVMFunctionType(g->ctx, includeMask); functionType->LLVMFunctionType(g->ctx, includeMask);
if (llvmFunctionType == NULL) if (llvmFunctionType == NULL)
return false; return false;
@@ -486,7 +486,7 @@ Module::AddGlobal(DeclSpecs *ds, Declarator *decl) {
return; return;
} }
const llvm::Type *llvmType = decl->sym->type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *llvmType = decl->sym->type->LLVMType(g->ctx);
llvm::GlobalValue::LinkageTypes linkage = llvm::GlobalValue::LinkageTypes linkage =
(ds->storageClass == SC_STATIC) ? llvm::GlobalValue::InternalLinkage : (ds->storageClass == SC_STATIC) ? llvm::GlobalValue::InternalLinkage :
llvm::GlobalValue::ExternalLinkage; llvm::GlobalValue::ExternalLinkage;
@@ -576,7 +576,7 @@ lCopyInTaskParameter(int i, llvm::Value *structArgPtr, Declarator *decl,
llvm::dyn_cast<const llvm::StructType>(pt->getElementType()); llvm::dyn_cast<const llvm::StructType>(pt->getElementType());
// Get the type of the argument we're copying in and its Symbol pointer // Get the type of the argument we're copying in and its Symbol pointer
const llvm::Type *argType = argStructType->getElementType(i); LLVM_TYPE_CONST llvm::Type *argType = argStructType->getElementType(i);
Declaration *pdecl = (*decl->functionArgs)[i]; Declaration *pdecl = (*decl->functionArgs)[i];
assert(pdecl->declarators.size() == 1); assert(pdecl->declarators.size() == 1);
Symbol *sym = pdecl->declarators[0]->sym; Symbol *sym = pdecl->declarators[0]->sym;
@@ -796,7 +796,8 @@ Module::AddFunction(DeclSpecs *ds, Declarator *decl, Stmt *code) {
// the application can call it // the application can call it
if (ds->storageClass == SC_EXPORT) { if (ds->storageClass == SC_EXPORT) {
if (!functionType->isTask) { if (!functionType->isTask) {
const llvm::FunctionType *ftype = functionType->LLVMFunctionType(g->ctx); LLVM_TYPE_CONST llvm::FunctionType *ftype =
functionType->LLVMFunctionType(g->ctx);
llvm::GlobalValue::LinkageTypes linkage = llvm::GlobalValue::ExternalLinkage; llvm::GlobalValue::LinkageTypes linkage = llvm::GlobalValue::ExternalLinkage;
llvm::Function *appFunction = llvm::Function *appFunction =
llvm::Function::Create(ftype, linkage, funSym->name.c_str(), module); llvm::Function::Create(ftype, linkage, funSym->name.c_str(), module);

112
opt.cpp
View File

@@ -692,7 +692,7 @@ lSizeOfIfKnown(const llvm::Type *type, uint64_t *size) {
inserted before insertBefore. inserted before insertBefore.
*/ */
static llvm::Value * static llvm::Value *
lSizeOf(const llvm::Type *type, llvm::Instruction *insertBefore) { lSizeOf(LLVM_TYPE_CONST llvm::Type *type, llvm::Instruction *insertBefore) {
// First try the easy case and see if we can get it as a simple // First try the easy case and see if we can get it as a simple
// constant.. // constant..
uint64_t size; uint64_t size;
@@ -703,7 +703,7 @@ lSizeOf(const llvm::Type *type, llvm::Instruction *insertBefore) {
// the pointer to the second element of an array of items of this type. // the pointer to the second element of an array of items of this type.
// Then convert that pointer to an int and we've got the offset to the // Then convert that pointer to an int and we've got the offset to the
// second element in the array, a.k.a. the size of the type. // second element in the array, a.k.a. the size of the type.
const llvm::Type *ptrType = llvm::PointerType::get(type, 0); LLVM_TYPE_CONST llvm::Type *ptrType = llvm::PointerType::get(type, 0);
llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType); llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType);
llvm::Value *index[1] = { LLVMInt32(1) }; llvm::Value *index[1] = { LLVMInt32(1) };
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[1], llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[1],
@@ -721,13 +721,13 @@ lSizeOf(const llvm::Type *type, llvm::Instruction *insertBefore) {
instructions that compute this value are inserted before insertBefore. instructions that compute this value are inserted before insertBefore.
*/ */
static llvm::Value * static llvm::Value *
lStructOffset(const llvm::Type *type, uint64_t member, lStructOffset(LLVM_TYPE_CONST llvm::Type *type, uint64_t member,
llvm::Instruction *insertBefore) { llvm::Instruction *insertBefore) {
// Do a similar trick to the one done in lSizeOf above; compute the // Do a similar trick to the one done in lSizeOf above; compute the
// pointer to the member starting from a NULL base pointer and then // pointer to the member starting from a NULL base pointer and then
// cast that 'pointer' to an int... // cast that 'pointer' to an int...
assert(llvm::isa<const llvm::StructType>(type)); assert(llvm::isa<const llvm::StructType>(type));
const llvm::Type *ptrType = llvm::PointerType::get(type, 0); LLVM_TYPE_CONST llvm::Type *ptrType = llvm::PointerType::get(type, 0);
llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType); llvm::Value *nullPtr = llvm::Constant::getNullValue(ptrType);
llvm::Value *index[2] = { LLVMInt32(0), LLVMInt32((int32_t)member) }; llvm::Value *index[2] = { LLVMInt32(0), LLVMInt32((int32_t)member) };
llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[2], llvm::Value *poffset = llvm::GetElementPtrInst::Create(nullPtr, &index[0], &index[2],
@@ -741,8 +741,9 @@ lStructOffset(const llvm::Type *type, uint64_t member,
static llvm::Value * static llvm::Value *
lGetTypeSize(const llvm::Type *type, llvm::Instruction *insertBefore) { lGetTypeSize(LLVM_TYPE_CONST llvm::Type *type, llvm::Instruction *insertBefore) {
const llvm::ArrayType *arrayType = llvm::dyn_cast<const llvm::ArrayType>(type); LLVM_TYPE_CONST llvm::ArrayType *arrayType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(type);
if (arrayType != NULL) if (arrayType != NULL)
type = arrayType->getElementType(); type = arrayType->getElementType();
@@ -756,7 +757,7 @@ lGetTypeSize(const llvm::Type *type, llvm::Instruction *insertBefore) {
static llvm::Value * static llvm::Value *
lGetOffsetForLane(int lane, llvm::Value *value, llvm::Value **offset, lGetOffsetForLane(int lane, llvm::Value *value, llvm::Value **offset,
const llvm::Type **scaleType, bool *leafIsVarying, LLVM_TYPE_CONST llvm::Type **scaleType, bool *leafIsVarying,
llvm::Instruction *insertBefore) { llvm::Instruction *insertBefore) {
if (!llvm::isa<llvm::GetElementPtrInst>(value)) { if (!llvm::isa<llvm::GetElementPtrInst>(value)) {
assert(llvm::isa<llvm::BitCastInst>(value)); assert(llvm::isa<llvm::BitCastInst>(value));
@@ -777,21 +778,22 @@ lGetOffsetForLane(int lane, llvm::Value *value, llvm::Value **offset,
} }
if (leafIsVarying != NULL) { if (leafIsVarying != NULL) {
const llvm::Type *pt = value->getType(); LLVM_TYPE_CONST llvm::Type *pt = value->getType();
const llvm::PointerType *ptrType = llvm::dyn_cast<const llvm::PointerType>(pt); LLVM_TYPE_CONST llvm::PointerType *ptrType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(pt);
assert(ptrType); assert(ptrType);
const llvm::Type *eltType = ptrType->getElementType(); LLVM_TYPE_CONST llvm::Type *eltType = ptrType->getElementType();
*leafIsVarying = llvm::isa<const llvm::VectorType>(eltType); *leafIsVarying = llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(eltType);
} }
llvm::GetElementPtrInst *gep = llvm::dyn_cast<llvm::GetElementPtrInst>(value); llvm::GetElementPtrInst *gep = llvm::dyn_cast<llvm::GetElementPtrInst>(value);
assert(gep); assert(gep);
assert(lGetIntValue(gep->getOperand(1)) == 0); assert(lGetIntValue(gep->getOperand(1)) == 0);
const llvm::PointerType *targetPtrType = LLVM_TYPE_CONST llvm::PointerType *targetPtrType =
llvm::dyn_cast<const llvm::PointerType>(gep->getOperand(0)->getType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(gep->getOperand(0)->getType());
assert(targetPtrType); assert(targetPtrType);
const llvm::Type *targetType = targetPtrType->getElementType(); LLVM_TYPE_CONST llvm::Type *targetType = targetPtrType->getElementType();
if (llvm::isa<const llvm::StructType>(targetType)) { if (llvm::isa<const llvm::StructType>(targetType)) {
*offset = lStructOffset(targetType, lGetIntValue(gep->getOperand(2)), *offset = lStructOffset(targetType, lGetIntValue(gep->getOperand(2)),
@@ -841,7 +843,7 @@ lGetOffsetForLane(int lane, llvm::Value *value, llvm::Value **offset,
*/ */
static llvm::Value * static llvm::Value *
lTraverseInsertChain(llvm::Value *ptrs, llvm::Value *offsets[ISPC_MAX_NVEC], lTraverseInsertChain(llvm::Value *ptrs, llvm::Value *offsets[ISPC_MAX_NVEC],
const llvm::Type **scaleType, bool *leafIsVarying, LLVM_TYPE_CONST llvm::Type **scaleType, bool *leafIsVarying,
llvm::Instruction *insertBefore) { llvm::Instruction *insertBefore) {
// This depends on the front-end constructing the arrays of pointers // This depends on the front-end constructing the arrays of pointers
// via InsertValue instructions. (Which it does do in // via InsertValue instructions. (Which it does do in
@@ -897,7 +899,7 @@ lTraverseInsertChain(llvm::Value *ptrs, llvm::Value *offsets[ISPC_MAX_NVEC],
*/ */
static llvm::Value * static llvm::Value *
lSmearScalar(llvm::Value *scalar, llvm::Instruction *insertBefore) { lSmearScalar(llvm::Value *scalar, llvm::Instruction *insertBefore) {
const llvm::Type *vectorType = llvm::VectorType::get(scalar->getType(), LLVM_TYPE_CONST llvm::Type *vectorType = llvm::VectorType::get(scalar->getType(),
g->target.vectorWidth); g->target.vectorWidth);
llvm::Value *result = llvm::UndefValue::get(vectorType); llvm::Value *result = llvm::UndefValue::get(vectorType);
for (int i = 0; i < g->target.vectorWidth; ++i) { for (int i = 0; i < g->target.vectorWidth; ++i) {
@@ -919,7 +921,7 @@ lGetPtrAndOffsets(llvm::Value *ptrs, llvm::Value **basePtr,
llvm::Value *offsets[ISPC_MAX_NVEC]; llvm::Value *offsets[ISPC_MAX_NVEC];
for (int i = 0; i < g->target.vectorWidth; ++i) for (int i = 0; i < g->target.vectorWidth; ++i)
offsets[i] = NULL; offsets[i] = NULL;
const llvm::Type *scaleType = NULL; LLVM_TYPE_CONST llvm::Type *scaleType = NULL;
llvm::Value *nextChain = llvm::Value *nextChain =
lTraverseInsertChain(ptrs, offsets, &scaleType, lTraverseInsertChain(ptrs, offsets, &scaleType,
@@ -1026,12 +1028,19 @@ GatherScatterFlattenOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
// Generate a new function call to the next pseudo gather // Generate a new function call to the next pseudo gather
// base+offsets instruction. Note that we're passing a NULL // base+offsets instruction. Note that we're passing a NULL
// llvm::BasicBlock to llvm::CallInst::Create; this means that // llvm::Instruction to llvm::CallInst::Create; this means that
// the instruction isn't inserted into a basic block and that // the instruction isn't inserted into a basic block and that
// way we can then call ReplaceInstWithInst(). // way we can then call ReplaceInstWithInst().
llvm::Value *newArgs[3] = { basePtr, offsetVector, mask }; llvm::Value *newArgs[3] = { basePtr, offsetVector, mask };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> newArgArray(&newArgs[0], &newArgs[3]);
llvm::Instruction *newCall =
llvm::CallInst::Create(gFunc, newArgArray, "newgather",
(llvm::Instruction *)NULL);
#else
llvm::Instruction *newCall = llvm::Instruction *newCall =
llvm::CallInst::Create(gFunc, &newArgs[0], &newArgs[3], "newgather"); llvm::CallInst::Create(gFunc, &newArgs[0], &newArgs[3], "newgather");
#endif
lCopyMetadata(newCall, callInst); lCopyMetadata(newCall, callInst);
llvm::ReplaceInstWithInst(callInst, newCall); llvm::ReplaceInstWithInst(callInst, newCall);
} }
@@ -1045,10 +1054,17 @@ GatherScatterFlattenOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
// Generate a new function call to the next pseudo scatter // Generate a new function call to the next pseudo scatter
// base+offsets instruction. See above for why passing NULL // base+offsets instruction. See above for why passing NULL
// for the basic block is intended. // for the Instruction * is intended.
llvm::Value *newArgs[4] = { basePtr, offsetVector, rvalue, mask }; llvm::Value *newArgs[4] = { basePtr, offsetVector, rvalue, mask };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> newArgArray(&newArgs[0], &newArgs[4]);
llvm::Instruction *newCall =
llvm::CallInst::Create(gFunc, newArgArray, "",
(llvm::Instruction *)NULL);
#else
llvm::Instruction *newCall = llvm::Instruction *newCall =
llvm::CallInst::Create(gFunc, &newArgs[0], &newArgs[4]); llvm::CallInst::Create(gFunc, &newArgs[0], &newArgs[4]);
#endif
lCopyMetadata(newCall, callInst); lCopyMetadata(newCall, callInst);
llvm::ReplaceInstWithInst(callInst, newCall); llvm::ReplaceInstWithInst(callInst, newCall);
} }
@@ -1131,8 +1147,9 @@ MaskedStoreOptPass::runOnBasicBlock(llvm::BasicBlock &bb) {
} }
else if (maskAsInt == allOnMask) { else if (maskAsInt == allOnMask) {
// The mask is all on, so turn this into a regular store // The mask is all on, so turn this into a regular store
const llvm::Type *rvalueType = rvalue->getType(); LLVM_TYPE_CONST llvm::Type *rvalueType = rvalue->getType();
const llvm::Type *ptrType = llvm::PointerType::get(rvalueType, 0); LLVM_TYPE_CONST llvm::Type *ptrType =
llvm::PointerType::get(rvalueType, 0);
// Need to update this when int8/int16 are added // Need to update this when int8/int16 are added
int align = (called == pms32Func || called == pms64Func || int align = (called == pms32Func || called == pms64Func ||
called == msb32Func) ? 4 : 8; called == msb32Func) ? 4 : 8;
@@ -1268,8 +1285,14 @@ LowerMaskedStorePass::runOnBasicBlock(llvm::BasicBlock &bb) {
llvm::Function *fms = m->module->getFunction(lMaskedStoreName(doBlend, is32)); llvm::Function *fms = m->module->getFunction(lMaskedStoreName(doBlend, is32));
assert(fms); assert(fms);
llvm::Value *args[3] = { lvalue, rvalue, mask }; llvm::Value *args[3] = { lvalue, rvalue, mask };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[3]);
llvm::Instruction *inst = llvm::CallInst::Create(fms, newArgArray, "",
callInst);
#else
llvm::Instruction *inst = llvm::CallInst::Create(fms, &args[0], &args[3], "", llvm::Instruction *inst = llvm::CallInst::Create(fms, &args[0], &args[3], "",
callInst); callInst);
#endif
lCopyMetadata(inst, callInst); lCopyMetadata(inst, callInst);
callInst->eraseFromParent(); callInst->eraseFromParent();
@@ -1445,11 +1468,11 @@ lScalarizeVector(llvm::Value *vec, llvm::Value *scalarizedVector[ISPC_MAX_NVEC])
if (!lScalarizeVector(ci->getOperand(0), scalarizedTarget)) if (!lScalarizeVector(ci->getOperand(0), scalarizedTarget))
return false; return false;
const llvm::Type *destType = ci->getDestTy(); LLVM_TYPE_CONST llvm::Type *destType = ci->getDestTy();
const llvm::VectorType *vectorDestType = LLVM_TYPE_CONST llvm::VectorType *vectorDestType =
llvm::dyn_cast<const llvm::VectorType>(destType); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(destType);
assert(vectorDestType != NULL); assert(vectorDestType != NULL);
const llvm::Type *elementType = vectorDestType->getElementType(); LLVM_TYPE_CONST llvm::Type *elementType = vectorDestType->getElementType();
for (int i = 0; i < g->target.vectorWidth; ++i) { for (int i = 0; i < g->target.vectorWidth; ++i) {
scalarizedVector[i] = scalarizedVector[i] =
@@ -1467,19 +1490,19 @@ lScalarizeVector(llvm::Value *vec, llvm::Value *scalarizedVector[ISPC_MAX_NVEC])
// an assert at the bottom of this routien will hit the first time // an assert at the bottom of this routien will hit the first time
// it runs as a reminder that this needs to be tested further. // it runs as a reminder that this needs to be tested further.
const llvm::VectorType *svInstType = LLVM_TYPE_CONST llvm::VectorType *svInstType =
llvm::dyn_cast<const llvm::VectorType>(svi->getType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(svi->getType());
assert(svInstType != NULL); assert(svInstType != NULL);
assert((int)svInstType->getNumElements() == g->target.vectorWidth); assert((int)svInstType->getNumElements() == g->target.vectorWidth);
// Scalarize the two vectors being shuffled. First figure out how // Scalarize the two vectors being shuffled. First figure out how
// big they are. // big they are.
const llvm::Type *type0 = svi->getOperand(0)->getType(); LLVM_TYPE_CONST llvm::Type *type0 = svi->getOperand(0)->getType();
const llvm::Type *type1 = svi->getOperand(1)->getType(); LLVM_TYPE_CONST llvm::Type *type1 = svi->getOperand(1)->getType();
const llvm::VectorType *vectorType0 = LLVM_TYPE_CONST llvm::VectorType *vectorType0 =
llvm::dyn_cast<const llvm::VectorType>(type0); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(type0);
const llvm::VectorType *vectorType1 = LLVM_TYPE_CONST llvm::VectorType *vectorType1 =
llvm::dyn_cast<const llvm::VectorType>(type1); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(type1);
assert(vectorType0 != NULL && vectorType1 != NULL); assert(vectorType0 != NULL && vectorType1 != NULL);
int n0 = vectorType0->getNumElements(); int n0 = vectorType0->getNumElements();
@@ -1926,9 +1949,16 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
"__load_and_broadcast_64"); "__load_and_broadcast_64");
assert(loadBroadcast); assert(loadBroadcast);
llvm::Value *args[2] = { ptr, mask }; llvm::Value *args[2] = { ptr, mask };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> newArgArray(&args[0], &args[2]);
llvm::Instruction *newCall =
llvm::CallInst::Create(loadBroadcast, newArgArray,
"load_broadcast", (llvm::Instruction *)NULL);
#else
llvm::Instruction *newCall = llvm::Instruction *newCall =
llvm::CallInst::Create(loadBroadcast, &args[0], &args[2], llvm::CallInst::Create(loadBroadcast, &args[0], &args[2],
"load_broadcast"); "load_broadcast");
#endif
lCopyMetadata(newCall, callInst); lCopyMetadata(newCall, callInst);
llvm::ReplaceInstWithInst(callInst, newCall); llvm::ReplaceInstWithInst(callInst, newCall);
} }
@@ -1984,8 +2014,15 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
assert(loadMasked); assert(loadMasked);
llvm::Value *args[2] = { ptr, mask }; llvm::Value *args[2] = { ptr, mask };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> argArray(&args[0], &args[2]);
llvm::Instruction *newCall =
llvm::CallInst::Create(loadMasked, argArray, "load_masked",
(llvm::Instruction *)NULL);
#else
llvm::Instruction *newCall = llvm::Instruction *newCall =
llvm::CallInst::Create(loadMasked, &args[0], &args[2], "load_masked"); llvm::CallInst::Create(loadMasked, &args[0], &args[2], "load_masked");
#endif
lCopyMetadata(newCall, callInst); lCopyMetadata(newCall, callInst);
llvm::ReplaceInstWithInst(callInst, newCall); llvm::ReplaceInstWithInst(callInst, newCall);
} }
@@ -2000,13 +2037,20 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
m->module->getFunction(is32 ? "__pseudo_masked_store_32" : m->module->getFunction(is32 ? "__pseudo_masked_store_32" :
"__pseudo_masked_store_64"); "__pseudo_masked_store_64");
assert(storeMasked); assert(storeMasked);
const llvm::Type *vecPtrType = is32 ? LLVM_TYPE_CONST llvm::Type *vecPtrType = is32 ?
LLVMTypes::Int32VectorPointerType : LLVMTypes::Int64VectorPointerType; LLVMTypes::Int32VectorPointerType : LLVMTypes::Int64VectorPointerType;
ptr = new llvm::BitCastInst(ptr, vecPtrType, "ptrcast", callInst); ptr = new llvm::BitCastInst(ptr, vecPtrType, "ptrcast", callInst);
llvm::Value *args[3] = { ptr, rvalue, mask }; llvm::Value *args[3] = { ptr, rvalue, mask };
#if defined(LLVM_3_0) || defined(LLVM_3_0svn)
llvm::ArrayRef<llvm::Value *> argArray(&args[0], &args[3]);
llvm::Instruction *newCall =
llvm::CallInst::Create(storeMasked, argArray, "",
(llvm::Instruction *)NULL);
#else
llvm::Instruction *newCall = llvm::Instruction *newCall =
llvm::CallInst::Create(storeMasked, &args[0], &args[3], ""); llvm::CallInst::Create(storeMasked, &args[0], &args[3], "");
#endif
lCopyMetadata(newCall, callInst); lCopyMetadata(newCall, callInst);
llvm::ReplaceInstWithInst(callInst, newCall); llvm::ReplaceInstWithInst(callInst, newCall);
} }

View File

@@ -133,7 +133,7 @@ lInitSymbol(llvm::Value *lvalue, const char *symName, const Type *type,
// Initialize things without initializers to the undefined value. // Initialize things without initializers to the undefined value.
// To auto-initialize everything to zero, replace 'UndefValue' with // To auto-initialize everything to zero, replace 'UndefValue' with
// 'NullValue' in the below // 'NullValue' in the below
const llvm::Type *ltype = type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *ltype = type->LLVMType(g->ctx);
ctx->StoreInst(llvm::UndefValue::get(ltype), lvalue); ctx->StoreInst(llvm::UndefValue::get(ltype), lvalue);
return; return;
} }
@@ -281,7 +281,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
continue; continue;
} }
const llvm::Type *llvmType = type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *llvmType = type->LLVMType(g->ctx);
assert(llvmType != NULL); assert(llvmType != NULL);
if (declaration->declSpecs->storageClass == SC_STATIC) { if (declaration->declSpecs->storageClass == SC_STATIC) {
@@ -1414,7 +1414,7 @@ lProcessPrintArg(Expr *expr, FunctionEmitContext *ctx, std::string &argTypes) {
else { else {
argTypes.push_back(t); argTypes.push_back(t);
const llvm::Type *llvmExprType = type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *llvmExprType = type->LLVMType(g->ctx);
llvm::Value *ptr = ctx->AllocaInst(llvmExprType, "print_arg"); llvm::Value *ptr = ctx->AllocaInst(llvmExprType, "print_arg");
llvm::Value *val = expr->GetValue(ctx); llvm::Value *val = expr->GetValue(ctx);
if (!val) if (!val)
@@ -1460,7 +1460,7 @@ PrintStmt::EmitCode(FunctionEmitContext *ctx) const {
int nArgs = elist ? elist->exprs.size() : 1; int nArgs = elist ? elist->exprs.size() : 1;
// Allocate space for the array of pointers to values to be printed // Allocate space for the array of pointers to values to be printed
const llvm::Type *argPtrArrayType = LLVM_TYPE_CONST llvm::Type *argPtrArrayType =
llvm::ArrayType::get(LLVMTypes::VoidPointerType, nArgs); llvm::ArrayType::get(LLVMTypes::VoidPointerType, nArgs);
llvm::Value *argPtrArray = ctx->AllocaInst(argPtrArrayType, llvm::Value *argPtrArray = ctx->AllocaInst(argPtrArrayType,
"print_arg_ptrs"); "print_arg_ptrs");

View File

@@ -582,9 +582,14 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue); m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue);
enumeratorDescriptors.push_back(descriptor); enumeratorDescriptors.push_back(descriptor);
} }
#ifdef LLVM_2_9
llvm::DIArray elementArray = llvm::DIArray elementArray =
m->diBuilder->getOrCreateArray(&enumeratorDescriptors[0], m->diBuilder->getOrCreateArray(&enumeratorDescriptors[0],
enumeratorDescriptors.size()); enumeratorDescriptors.size());
#else
llvm::DIArray elementArray =
m->diBuilder->getOrCreateArray(enumeratorDescriptors);
#endif
llvm::DIFile diFile = pos.GetDIFile(); llvm::DIFile diFile = pos.GetDIFile();
llvm::DIType diType = llvm::DIType diType =
@@ -1775,7 +1780,7 @@ FunctionType::GetDIType(llvm::DIDescriptor scope) const {
} }
const llvm::FunctionType * LLVM_TYPE_CONST llvm::FunctionType *
FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool includeMask) const { FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool includeMask) const {
if (!includeMask && isTask) { if (!includeMask && isTask) {
Error(pos, "Function can't have both \"task\" and \"export\" qualifiers"); Error(pos, "Function can't have both \"task\" and \"export\" qualifiers");

2
type.h
View File

@@ -660,7 +660,7 @@ public:
function type. The \c includeMask parameter indicates whether the function type. The \c includeMask parameter indicates whether the
llvm::FunctionType should have a mask as the last argument in its llvm::FunctionType should have a mask as the last argument in its
function signature. */ function signature. */
const llvm::FunctionType *LLVMFunctionType(llvm::LLVMContext *ctx, LLVM_TYPE_CONST llvm::FunctionType *LLVMFunctionType(llvm::LLVMContext *ctx,
bool includeMask = false) const; bool includeMask = false) const;
const std::vector<const Type *> &GetArgumentTypes() const { return argTypes; } const std::vector<const Type *> &GetArgumentTypes() const { return argTypes; }