Have assertion macro and FATAL() text ask user to file a bug, provide URL to do so.

Switch to Assert() from assert() to make it clear it's not the C stdlib one we're
using any more.
This commit is contained in:
Matt Pharr
2011-12-15 11:11:07 -08:00
parent b8987faeee
commit 8d1b77b235
19 changed files with 398 additions and 382 deletions

View File

@@ -257,7 +257,7 @@ static void
lAddModuleSymbols(llvm::Module *module, SymbolTable *symbolTable) { lAddModuleSymbols(llvm::Module *module, SymbolTable *symbolTable) {
#if 0 #if 0
// FIXME: handle globals? // FIXME: handle globals?
assert(module->global_empty()); Assert(module->global_empty());
#endif #endif
llvm::Module::iterator iter; llvm::Module::iterator iter;
@@ -287,11 +287,11 @@ lCheckModuleIntrinsics(llvm::Module *module) {
// check the llvm.x86.* intrinsics for now... // check the llvm.x86.* intrinsics for now...
if (!strncmp(funcName.c_str(), "llvm.x86.", 9)) { if (!strncmp(funcName.c_str(), "llvm.x86.", 9)) {
llvm::Intrinsic::ID id = (llvm::Intrinsic::ID)func->getIntrinsicID(); llvm::Intrinsic::ID id = (llvm::Intrinsic::ID)func->getIntrinsicID();
assert(id != 0); Assert(id != 0);
LLVM_TYPE_CONST llvm::Type *intrinsicType = LLVM_TYPE_CONST llvm::Type *intrinsicType =
llvm::Intrinsic::getType(*g->ctx, id); llvm::Intrinsic::getType(*g->ctx, id);
intrinsicType = llvm::PointerType::get(intrinsicType, 0); intrinsicType = llvm::PointerType::get(intrinsicType, 0);
assert(func->getType() == intrinsicType); Assert(func->getType() == intrinsicType);
} }
} }
} }
@@ -591,9 +591,9 @@ AddBitcodeToModule(const unsigned char *bitcode, int length,
// linking together modules with incompatible target triples.. // linking together modules with incompatible target triples..
llvm::Triple mTriple(m->module->getTargetTriple()); llvm::Triple mTriple(m->module->getTargetTriple());
llvm::Triple bcTriple(bcModule->getTargetTriple()); llvm::Triple bcTriple(bcModule->getTargetTriple());
assert(bcTriple.getArch() == llvm::Triple::UnknownArch || Assert(bcTriple.getArch() == llvm::Triple::UnknownArch ||
mTriple.getArch() == bcTriple.getArch()); mTriple.getArch() == bcTriple.getArch());
assert(bcTriple.getVendor() == llvm::Triple::UnknownVendor || Assert(bcTriple.getVendor() == llvm::Triple::UnknownVendor ||
mTriple.getVendor() == bcTriple.getVendor()); mTriple.getVendor() == bcTriple.getVendor());
bcModule->setTargetTriple(mTriple.str()); bcModule->setTargetTriple(mTriple.str());
@@ -639,7 +639,7 @@ lDefineConstantIntFunc(const char *name, int val, llvm::Module *module,
Symbol *sym = new Symbol(name, SourcePos(), ft, SC_STATIC); Symbol *sym = new Symbol(name, SourcePos(), ft, SC_STATIC);
llvm::Function *func = module->getFunction(name); llvm::Function *func = module->getFunction(name);
assert(func != NULL); // it should be declared already... Assert(func != NULL); // it should be declared already...
func->addFnAttr(llvm::Attribute::AlwaysInline); func->addFnAttr(llvm::Attribute::AlwaysInline);
llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0); llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0);
llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock); llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock);

190
ctx.cpp
View File

@@ -89,7 +89,7 @@ struct CFInfo {
private: private:
CFInfo(CFType t, bool uniformIf, llvm::Value *sm) { CFInfo(CFType t, bool uniformIf, llvm::Value *sm) {
assert(t == If); Assert(t == If);
type = t; type = t;
isUniform = uniformIf; isUniform = uniformIf;
savedBreakTarget = savedContinueTarget = NULL; savedBreakTarget = savedContinueTarget = NULL;
@@ -99,7 +99,7 @@ private:
CFInfo(CFType t, bool iu, llvm::BasicBlock *bt, llvm::BasicBlock *ct, CFInfo(CFType t, bool iu, llvm::BasicBlock *bt, llvm::BasicBlock *ct,
llvm::Value *sb, llvm::Value *sc, llvm::Value *sm, llvm::Value *sb, llvm::Value *sc, llvm::Value *sm,
llvm::Value *lm) { llvm::Value *lm) {
assert(t == Loop); Assert(t == Loop);
type = t; type = t;
isUniform = iu; isUniform = iu;
savedBreakTarget = bt; savedBreakTarget = bt;
@@ -112,7 +112,7 @@ private:
CFInfo(CFType t, llvm::BasicBlock *bt, llvm::BasicBlock *ct, CFInfo(CFType t, llvm::BasicBlock *bt, llvm::BasicBlock *ct,
llvm::Value *sb, llvm::Value *sc, llvm::Value *sm, llvm::Value *sb, llvm::Value *sc, llvm::Value *sm,
llvm::Value *lm) { llvm::Value *lm) {
assert(t == Foreach); Assert(t == Foreach);
type = t; type = t;
isUniform = false; isUniform = false;
savedBreakTarget = bt; savedBreakTarget = bt;
@@ -226,7 +226,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
llvm::Constant *offFunc = llvm::Constant *offFunc =
m->module->getOrInsertFunction(buf, LLVMTypes::VoidType, m->module->getOrInsertFunction(buf, LLVMTypes::VoidType,
NULL); NULL);
assert(llvm::isa<llvm::Function>(offFunc)); Assert(llvm::isa<llvm::Function>(offFunc));
llvm::BasicBlock *offBB = llvm::BasicBlock *offBB =
llvm::BasicBlock::Create(*g->ctx, "entry", llvm::BasicBlock::Create(*g->ctx, "entry",
(llvm::Function *)offFunc, 0); (llvm::Function *)offFunc, 0);
@@ -260,7 +260,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
llvm::DIFile file = funcStartPos.GetDIFile(); llvm::DIFile file = funcStartPos.GetDIFile();
Symbol *programIndexSymbol = m->symbolTable->LookupVariable("programIndex"); Symbol *programIndexSymbol = m->symbolTable->LookupVariable("programIndex");
assert(programIndexSymbol && programIndexSymbol->storagePtr); Assert(programIndexSymbol && programIndexSymbol->storagePtr);
m->diBuilder->createGlobalVariable(programIndexSymbol->name, m->diBuilder->createGlobalVariable(programIndexSymbol->name,
file, file,
funcStartPos.first_line, funcStartPos.first_line,
@@ -269,7 +269,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
programIndexSymbol->storagePtr); programIndexSymbol->storagePtr);
Symbol *programCountSymbol = m->symbolTable->LookupVariable("programCount"); Symbol *programCountSymbol = m->symbolTable->LookupVariable("programCount");
assert(programCountSymbol); Assert(programCountSymbol);
m->diBuilder->createGlobalVariable(programCountSymbol->name, m->diBuilder->createGlobalVariable(programCountSymbol->name,
file, file,
funcStartPos.first_line, funcStartPos.first_line,
@@ -281,8 +281,8 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
FunctionEmitContext::~FunctionEmitContext() { FunctionEmitContext::~FunctionEmitContext() {
assert(controlFlowInfo.size() == 0); Assert(controlFlowInfo.size() == 0);
assert(debugScopes.size() == (m->diBuilder ? 1 : 0)); Assert(debugScopes.size() == (m->diBuilder ? 1 : 0));
} }
@@ -376,7 +376,7 @@ FunctionEmitContext::SetInternalMaskAndNot(llvm::Value *oldMask, llvm::Value *te
void void
FunctionEmitContext::BranchIfMaskAny(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) { FunctionEmitContext::BranchIfMaskAny(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) {
assert(bblock != NULL); Assert(bblock != NULL);
llvm::Value *any = Any(GetFullMask()); llvm::Value *any = Any(GetFullMask());
BranchInst(btrue, bfalse, any); BranchInst(btrue, bfalse, any);
// It's illegal to add any additional instructions to the basic block // It's illegal to add any additional instructions to the basic block
@@ -387,7 +387,7 @@ FunctionEmitContext::BranchIfMaskAny(llvm::BasicBlock *btrue, llvm::BasicBlock *
void void
FunctionEmitContext::BranchIfMaskAll(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) { FunctionEmitContext::BranchIfMaskAll(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) {
assert(bblock != NULL); Assert(bblock != NULL);
llvm::Value *all = All(GetFullMask()); llvm::Value *all = All(GetFullMask());
BranchInst(btrue, bfalse, all); BranchInst(btrue, bfalse, all);
// It's illegal to add any additional instructions to the basic block // It's illegal to add any additional instructions to the basic block
@@ -398,7 +398,7 @@ FunctionEmitContext::BranchIfMaskAll(llvm::BasicBlock *btrue, llvm::BasicBlock *
void void
FunctionEmitContext::BranchIfMaskNone(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) { FunctionEmitContext::BranchIfMaskNone(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) {
assert(bblock != NULL); Assert(bblock != NULL);
// switch sense of true/false bblocks // switch sense of true/false bblocks
BranchIfMaskAny(bfalse, btrue); BranchIfMaskAny(bfalse, btrue);
// It's illegal to add any additional instructions to the basic block // It's illegal to add any additional instructions to the basic block
@@ -422,7 +422,7 @@ FunctionEmitContext::StartVaryingIf(llvm::Value *oldMask) {
void void
FunctionEmitContext::EndIf() { FunctionEmitContext::EndIf() {
// Make sure we match up with a Start{Uniform,Varying}If(). // Make sure we match up with a Start{Uniform,Varying}If().
assert(controlFlowInfo.size() > 0 && controlFlowInfo.back()->IsIf()); Assert(controlFlowInfo.size() > 0 && controlFlowInfo.back()->IsIf());
CFInfo *ci = controlFlowInfo.back(); CFInfo *ci = controlFlowInfo.back();
controlFlowInfo.pop_back(); controlFlowInfo.pop_back();
@@ -501,7 +501,7 @@ FunctionEmitContext::StartLoop(llvm::BasicBlock *bt, llvm::BasicBlock *ct,
void void
FunctionEmitContext::EndLoop() { FunctionEmitContext::EndLoop() {
assert(controlFlowInfo.size() && controlFlowInfo.back()->IsLoop()); Assert(controlFlowInfo.size() && controlFlowInfo.back()->IsLoop());
CFInfo *ci = controlFlowInfo.back(); CFInfo *ci = controlFlowInfo.back();
controlFlowInfo.pop_back(); controlFlowInfo.pop_back();
@@ -544,7 +544,7 @@ FunctionEmitContext::StartForeach(llvm::BasicBlock *ct) {
void void
FunctionEmitContext::EndForeach() { FunctionEmitContext::EndForeach() {
assert(controlFlowInfo.size() && controlFlowInfo.back()->IsForeach()); Assert(controlFlowInfo.size() && controlFlowInfo.back()->IsForeach());
CFInfo *ci = controlFlowInfo.back(); CFInfo *ci = controlFlowInfo.back();
controlFlowInfo.pop_back(); controlFlowInfo.pop_back();
@@ -598,7 +598,7 @@ FunctionEmitContext::Break(bool doCoherenceCheck) {
// Otherwise we need to update the mask of the lanes that have // Otherwise we need to update the mask of the lanes that have
// executed a 'break' statement: // executed a 'break' statement:
// breakLanes = breakLanes | mask // breakLanes = breakLanes | mask
assert(breakLanesPtr != NULL); Assert(breakLanesPtr != NULL);
llvm::Value *mask = GetInternalMask(); llvm::Value *mask = GetInternalMask();
llvm::Value *breakMask = LoadInst(breakLanesPtr, llvm::Value *breakMask = LoadInst(breakLanesPtr,
"break_mask"); "break_mask");
@@ -648,7 +648,7 @@ FunctionEmitContext::Continue(bool doCoherenceCheck) {
else { else {
// Otherwise update the stored value of which lanes have 'continue'd. // Otherwise update the stored value of which lanes have 'continue'd.
// continueLanes = continueLanes | mask // continueLanes = continueLanes | mask
assert(continueLanesPtr); Assert(continueLanesPtr);
llvm::Value *mask = GetInternalMask(); llvm::Value *mask = GetInternalMask();
llvm::Value *continueMask = llvm::Value *continueMask =
LoadInst(continueLanesPtr, "continue_mask"); LoadInst(continueLanesPtr, "continue_mask");
@@ -675,7 +675,7 @@ FunctionEmitContext::Continue(bool doCoherenceCheck) {
*/ */
bool bool
FunctionEmitContext::ifsInLoopAllUniform() const { FunctionEmitContext::ifsInLoopAllUniform() const {
assert(controlFlowInfo.size() > 0); Assert(controlFlowInfo.size() > 0);
// Go backwards through controlFlowInfo, since we add new nested scopes // Go backwards through controlFlowInfo, since we add new nested scopes
// to the back. Stop once we come to the first enclosing loop. // to the back. Stop once we come to the first enclosing loop.
int i = controlFlowInfo.size() - 1; int i = controlFlowInfo.size() - 1;
@@ -685,7 +685,7 @@ FunctionEmitContext::ifsInLoopAllUniform() const {
return false; return false;
--i; --i;
} }
assert(i >= 0); // else we didn't find a loop! Assert(i >= 0); // else we didn't find a loop!
return true; return true;
} }
@@ -693,7 +693,7 @@ FunctionEmitContext::ifsInLoopAllUniform() const {
void void
FunctionEmitContext::jumpIfAllLoopLanesAreDone(llvm::BasicBlock *target) { FunctionEmitContext::jumpIfAllLoopLanesAreDone(llvm::BasicBlock *target) {
llvm::Value *allDone = NULL; llvm::Value *allDone = NULL;
assert(continueLanesPtr != NULL); Assert(continueLanesPtr != NULL);
if (breakLanesPtr == NULL) { if (breakLanesPtr == NULL) {
// In a foreach loop, break and return are illegal, and // In a foreach loop, break and return are illegal, and
// breakLanesPtr is NULL. In this case, the mask is guaranteed to // breakLanesPtr is NULL. In this case, the mask is guaranteed to
@@ -876,7 +876,7 @@ FunctionEmitContext::LaneMask(llvm::Value *v) {
std::vector<Symbol *> mm; std::vector<Symbol *> mm;
m->symbolTable->LookupFunction("__movmsk", &mm); m->symbolTable->LookupFunction("__movmsk", &mm);
// There should be one with signed int signature, one unsigned int. // There should be one with signed int signature, one unsigned int.
assert(mm.size() == 2); Assert(mm.size() == 2);
// We can actually call either one, since both are i32s as far as // We can actually call either one, since both are i32s as far as
// LLVM's type system is concerned... // LLVM's type system is concerned...
llvm::Function *fmm = mm[0]->function; llvm::Function *fmm = mm[0]->function;
@@ -925,7 +925,7 @@ FunctionEmitContext::CreateBasicBlock(const char *name) {
llvm::Value * llvm::Value *
FunctionEmitContext::I1VecToBoolVec(llvm::Value *b) { FunctionEmitContext::I1VecToBoolVec(llvm::Value *b) {
if (b == NULL) { if (b == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -971,7 +971,7 @@ lGetStringAsValue(llvm::BasicBlock *bblock, const char *s) {
void void
FunctionEmitContext::AddInstrumentationPoint(const char *note) { FunctionEmitContext::AddInstrumentationPoint(const char *note) {
assert(note != NULL); Assert(note != NULL);
if (!g->emitInstrumentation) if (!g->emitInstrumentation)
return; return;
@@ -1039,7 +1039,7 @@ FunctionEmitContext::StartScope() {
void void
FunctionEmitContext::EndScope() { FunctionEmitContext::EndScope() {
if (m->diBuilder != NULL) { if (m->diBuilder != NULL) {
assert(debugScopes.size() > 0); Assert(debugScopes.size() > 0);
debugScopes.pop_back(); debugScopes.pop_back();
} }
} }
@@ -1047,7 +1047,7 @@ FunctionEmitContext::EndScope() {
llvm::DIScope llvm::DIScope
FunctionEmitContext::GetDIScope() const { FunctionEmitContext::GetDIScope() const {
assert(debugScopes.size() > 0); Assert(debugScopes.size() > 0);
return debugScopes.back(); return debugScopes.back();
} }
@@ -1108,7 +1108,7 @@ lArrayVectorWidth(LLVM_TYPE_CONST llvm::Type *t) {
// to things like FunctionEmitContext::BinaryOperator() as operands. // to things like FunctionEmitContext::BinaryOperator() as operands.
LLVM_TYPE_CONST llvm::VectorType *vectorElementType = LLVM_TYPE_CONST llvm::VectorType *vectorElementType =
llvm::dyn_cast<LLVM_TYPE_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();
@@ -1120,11 +1120,11 @@ FunctionEmitContext::BinaryOperator(llvm::Instruction::BinaryOps inst,
llvm::Value *v0, llvm::Value *v1, llvm::Value *v0, llvm::Value *v1,
const char *name) { const char *name) {
if (v0 == NULL || v1 == NULL) { if (v0 == NULL || v1 == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
assert(v0->getType() == v1->getType()); Assert(v0->getType() == v1->getType());
LLVM_TYPE_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) {
@@ -1152,7 +1152,7 @@ FunctionEmitContext::BinaryOperator(llvm::Instruction::BinaryOps inst,
llvm::Value * llvm::Value *
FunctionEmitContext::NotOperator(llvm::Value *v, const char *name) { FunctionEmitContext::NotOperator(llvm::Value *v, const char *name) {
if (v == NULL) { if (v == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -1188,12 +1188,12 @@ static LLVM_TYPE_CONST llvm::Type *
lGetMatchingBoolVectorType(LLVM_TYPE_CONST llvm::Type *type) { lGetMatchingBoolVectorType(LLVM_TYPE_CONST llvm::Type *type) {
LLVM_TYPE_CONST llvm::ArrayType *arrayType = LLVM_TYPE_CONST llvm::ArrayType *arrayType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(type); llvm::dyn_cast<LLVM_TYPE_CONST llvm::ArrayType>(type);
assert(arrayType != NULL); Assert(arrayType != NULL);
LLVM_TYPE_CONST llvm::VectorType *vectorElementType = LLVM_TYPE_CONST llvm::VectorType *vectorElementType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(arrayType->getElementType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::VectorType>(arrayType->getElementType());
assert(vectorElementType != NULL); Assert(vectorElementType != NULL);
assert((int)vectorElementType->getNumElements() == g->target.vectorWidth); Assert((int)vectorElementType->getNumElements() == g->target.vectorWidth);
LLVM_TYPE_CONST llvm::Type *base = LLVM_TYPE_CONST llvm::Type *base =
llvm::VectorType::get(LLVMTypes::BoolType, g->target.vectorWidth); llvm::VectorType::get(LLVMTypes::BoolType, g->target.vectorWidth);
@@ -1207,11 +1207,11 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst,
llvm::Value *v0, llvm::Value *v1, llvm::Value *v0, llvm::Value *v1,
const char *name) { const char *name) {
if (v0 == NULL || v1 == NULL) { if (v0 == NULL || v1 == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
assert(v0->getType() == v1->getType()); Assert(v0->getType() == v1->getType());
LLVM_TYPE_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) {
@@ -1238,7 +1238,7 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst,
llvm::Value * llvm::Value *
FunctionEmitContext::SmearUniform(llvm::Value *value, const char *name) { FunctionEmitContext::SmearUniform(llvm::Value *value, const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -1273,7 +1273,7 @@ FunctionEmitContext::BitCastInst(llvm::Value *value,
LLVM_TYPE_CONST llvm::Type *type, 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;
} }
@@ -1287,7 +1287,7 @@ FunctionEmitContext::BitCastInst(llvm::Value *value,
llvm::Value * llvm::Value *
FunctionEmitContext::PtrToIntInst(llvm::Value *value, const char *name) { FunctionEmitContext::PtrToIntInst(llvm::Value *value, const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -1308,7 +1308,7 @@ FunctionEmitContext::PtrToIntInst(llvm::Value *value,
LLVM_TYPE_CONST llvm::Type *toType, LLVM_TYPE_CONST llvm::Type *toType,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -1321,7 +1321,7 @@ FunctionEmitContext::PtrToIntInst(llvm::Value *value,
else if (fromType->getScalarSizeInBits() > toType->getScalarSizeInBits()) else if (fromType->getScalarSizeInBits() > toType->getScalarSizeInBits())
return TruncInst(value, toType, "ptr_to_int"); return TruncInst(value, toType, "ptr_to_int");
else { else {
assert(fromType->getScalarSizeInBits() < Assert(fromType->getScalarSizeInBits() <
toType->getScalarSizeInBits()); toType->getScalarSizeInBits());
return ZExtInst(value, toType, "ptr_to_int"); return ZExtInst(value, toType, "ptr_to_int");
} }
@@ -1339,7 +1339,7 @@ FunctionEmitContext::IntToPtrInst(llvm::Value *value,
LLVM_TYPE_CONST llvm::Type *toType, LLVM_TYPE_CONST llvm::Type *toType,
const char *name) { const char *name) {
if (value == NULL) { if (value == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -1352,7 +1352,7 @@ FunctionEmitContext::IntToPtrInst(llvm::Value *value,
else if (fromType->getScalarSizeInBits() > toType->getScalarSizeInBits()) else if (fromType->getScalarSizeInBits() > toType->getScalarSizeInBits())
return TruncInst(value, toType, "int_to_ptr"); return TruncInst(value, toType, "int_to_ptr");
else { else {
assert(fromType->getScalarSizeInBits() < Assert(fromType->getScalarSizeInBits() <
toType->getScalarSizeInBits()); toType->getScalarSizeInBits());
return ZExtInst(value, toType, "int_to_ptr"); return ZExtInst(value, toType, "int_to_ptr");
} }
@@ -1369,7 +1369,7 @@ llvm::Instruction *
FunctionEmitContext::TruncInst(llvm::Value *value, LLVM_TYPE_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);
return NULL; return NULL;
} }
@@ -1386,7 +1386,7 @@ llvm::Instruction *
FunctionEmitContext::CastInst(llvm::Instruction::CastOps op, llvm::Value *value, FunctionEmitContext::CastInst(llvm::Instruction::CastOps op, llvm::Value *value,
LLVM_TYPE_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;
} }
@@ -1403,7 +1403,7 @@ llvm::Instruction *
FunctionEmitContext::FPCastInst(llvm::Value *value, LLVM_TYPE_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);
return NULL; return NULL;
} }
@@ -1420,7 +1420,7 @@ llvm::Instruction *
FunctionEmitContext::SExtInst(llvm::Value *value, LLVM_TYPE_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);
return NULL; return NULL;
} }
@@ -1437,7 +1437,7 @@ llvm::Instruction *
FunctionEmitContext::ZExtInst(llvm::Value *value, LLVM_TYPE_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);
return NULL; return NULL;
} }
@@ -1510,7 +1510,7 @@ FunctionEmitContext::applyVaryingGEP(llvm::Value *basePtr, llvm::Value *index,
// index must be varying for this method to be called. // index must be varying for this method to be called.
bool baseIsUniform = bool baseIsUniform =
(llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(basePtr->getType())); (llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(basePtr->getType()));
assert(baseIsUniform == false || indexIsVarying == true); Assert(baseIsUniform == false || indexIsVarying == true);
llvm::Value *varyingPtr = baseIsUniform ? llvm::Value *varyingPtr = baseIsUniform ?
SmearUniform(basePtr, "ptr_smear") : basePtr; SmearUniform(basePtr, "ptr_smear") : basePtr;
@@ -1523,13 +1523,13 @@ llvm::Value *
FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index, FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index,
const Type *ptrType, const char *name) { const Type *ptrType, const char *name) {
if (basePtr == NULL || index == NULL) { if (basePtr == NULL || index == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
if (dynamic_cast<const ReferenceType *>(ptrType) != NULL) if (dynamic_cast<const ReferenceType *>(ptrType) != NULL)
ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget()); ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget());
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
bool indexIsVaryingType = bool indexIsVaryingType =
llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(index->getType()); llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(index->getType());
@@ -1561,13 +1561,13 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0
llvm::Value *index1, const Type *ptrType, llvm::Value *index1, const Type *ptrType,
const char *name) { const char *name) {
if (basePtr == NULL || index0 == NULL || index1 == NULL) { if (basePtr == NULL || index0 == NULL || index1 == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
if (dynamic_cast<const ReferenceType *>(ptrType) != NULL) if (dynamic_cast<const ReferenceType *>(ptrType) != NULL)
ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget()); ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget());
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
bool index0IsVaryingType = bool index0IsVaryingType =
llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(index0->getType()); llvm::isa<LLVM_TYPE_CONST llvm::VectorType>(index0->getType());
@@ -1600,7 +1600,7 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0
// out the type of ptr0. // out the type of ptr0.
const Type *baseType = ptrType->GetBaseType(); const Type *baseType = ptrType->GetBaseType();
const SequentialType *st = dynamic_cast<const SequentialType *>(baseType); const SequentialType *st = dynamic_cast<const SequentialType *>(baseType);
assert(st != NULL); Assert(st != NULL);
bool ptr0IsUniform = bool ptr0IsUniform =
llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(ptr0->getType()); llvm::isa<LLVM_TYPE_CONST llvm::PointerType>(ptr0->getType());
@@ -1635,7 +1635,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *basePtr, int elementNum,
if (dynamic_cast<const ReferenceType *>(ptrType) != NULL) if (dynamic_cast<const ReferenceType *>(ptrType) != NULL)
ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget()); ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget());
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
// Otherwise do the math to find the offset and add it to the given // Otherwise do the math to find the offset and add it to the given
// varying pointers // varying pointers
@@ -1652,7 +1652,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *basePtr, int elementNum,
// type of the vector. // type of the vector.
const SequentialType *st = const SequentialType *st =
dynamic_cast<const SequentialType *>(ptrType->GetBaseType()); dynamic_cast<const SequentialType *>(ptrType->GetBaseType());
assert(st != NULL); Assert(st != NULL);
llvm::Value *size = llvm::Value *size =
g->target.SizeOf(st->GetElementType()->LLVMType(g->ctx)); g->target.SizeOf(st->GetElementType()->LLVMType(g->ctx));
llvm::Value *scale = (g->target.is32Bit || g->opt.force32BitAddressing) ? llvm::Value *scale = (g->target.is32Bit || g->opt.force32BitAddressing) ?
@@ -1676,13 +1676,13 @@ FunctionEmitContext::AddElementOffset(llvm::Value *basePtr, int elementNum,
llvm::Value * llvm::Value *
FunctionEmitContext::LoadInst(llvm::Value *ptr, const char *name) { FunctionEmitContext::LoadInst(llvm::Value *ptr, const char *name) {
if (ptr == NULL) { if (ptr == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
LLVM_TYPE_CONST llvm::PointerType *pt = LLVM_TYPE_CONST llvm::PointerType *pt =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(ptr->getType()); llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(ptr->getType());
assert(pt != NULL); Assert(pt != NULL);
// FIXME: it's not clear to me that we generate unaligned vector loads // FIXME: it's not clear to me that we generate unaligned vector loads
// of varying stuff out of the front-end any more. (Only by the // of varying stuff out of the front-end any more. (Only by the
@@ -1703,16 +1703,16 @@ llvm::Value *
FunctionEmitContext::LoadInst(llvm::Value *ptr, llvm::Value *mask, FunctionEmitContext::LoadInst(llvm::Value *ptr, llvm::Value *mask,
const Type *ptrType, const char *name) { const Type *ptrType, const char *name) {
if (ptr == NULL) { if (ptr == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
assert(ptrType != NULL && mask != NULL); Assert(ptrType != NULL && mask != NULL);
if (dynamic_cast<const ReferenceType *>(ptrType) != NULL) if (dynamic_cast<const ReferenceType *>(ptrType) != NULL)
ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget()); ptrType = PointerType::GetUniform(ptrType->GetReferenceTarget());
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
if (ptrType->IsUniformType()) { if (ptrType->IsUniformType()) {
// FIXME: same issue as above load inst regarding alignment... // FIXME: same issue as above load inst regarding alignment...
@@ -1749,7 +1749,7 @@ llvm::Value *
FunctionEmitContext::gather(llvm::Value *ptr, const Type *ptrType, FunctionEmitContext::gather(llvm::Value *ptr, const Type *ptrType,
llvm::Value *mask, const char *name) { llvm::Value *mask, const char *name) {
// We should have a varying lvalue if we get here... // We should have a varying lvalue if we get here...
assert(ptrType->IsVaryingType() && Assert(ptrType->IsVaryingType() &&
ptr->getType() == LLVMTypes::VoidPointerVectorType); ptr->getType() == LLVMTypes::VoidPointerVectorType);
const Type *returnType = ptrType->GetBaseType()->GetAsVaryingType(); const Type *returnType = ptrType->GetBaseType()->GetAsVaryingType();
@@ -1798,13 +1798,13 @@ FunctionEmitContext::gather(llvm::Value *ptr, const Type *ptrType,
funcName = g->target.is32Bit ? "__pseudo_gather32_16" : funcName = g->target.is32Bit ? "__pseudo_gather32_16" :
"__pseudo_gather64_16"; "__pseudo_gather64_16";
else { else {
assert(llvmReturnType == LLVMTypes::Int8VectorType); Assert(llvmReturnType == LLVMTypes::Int8VectorType);
funcName = g->target.is32Bit ? "__pseudo_gather32_8" : funcName = g->target.is32Bit ? "__pseudo_gather32_8" :
"__pseudo_gather64_8"; "__pseudo_gather64_8";
} }
llvm::Function *gatherFunc = m->module->getFunction(funcName); llvm::Function *gatherFunc = m->module->getFunction(funcName);
assert(gatherFunc != NULL); Assert(gatherFunc != NULL);
llvm::Value *call = CallInst(gatherFunc, NULL, ptr, mask, name); llvm::Value *call = CallInst(gatherFunc, NULL, ptr, mask, name);
@@ -1854,7 +1854,7 @@ FunctionEmitContext::AllocaInst(LLVM_TYPE_CONST llvm::Type *llvmType,
const char *name, int align, const char *name, int align,
bool atEntryBlock) { bool atEntryBlock) {
if (llvmType == NULL) { if (llvmType == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -1863,7 +1863,7 @@ FunctionEmitContext::AllocaInst(LLVM_TYPE_CONST llvm::Type *llvmType,
// We usually insert it right before the jump instruction at the // We usually insert it right before the jump instruction at the
// end of allocaBlock // end of allocaBlock
llvm::Instruction *retInst = allocaBlock->getTerminator(); llvm::Instruction *retInst = allocaBlock->getTerminator();
assert(retInst); Assert(retInst);
inst = new llvm::AllocaInst(llvmType, name ? name : "", retInst); inst = new llvm::AllocaInst(llvmType, name ? name : "", retInst);
} }
else else
@@ -1899,12 +1899,12 @@ void
FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr, FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr,
const Type *ptrType, llvm::Value *mask) { const Type *ptrType, llvm::Value *mask) {
if (value == NULL || ptr == NULL) { if (value == NULL || ptr == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return; return;
} }
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
assert(ptrType->IsUniformType()); Assert(ptrType->IsUniformType());
const Type *valueType = ptrType->GetBaseType(); const Type *valueType = ptrType->GetBaseType();
const CollectionType *collectionType = const CollectionType *collectionType =
@@ -1926,7 +1926,7 @@ FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr,
// We must have a regular atomic, enumerator, or pointer type at this // We must have a regular atomic, enumerator, or pointer type at this
// point. // point.
assert(dynamic_cast<const AtomicType *>(valueType) != NULL || Assert(dynamic_cast<const AtomicType *>(valueType) != NULL ||
dynamic_cast<const EnumType *>(valueType) != NULL || dynamic_cast<const EnumType *>(valueType) != NULL ||
dynamic_cast<const PointerType *>(valueType) != NULL); dynamic_cast<const PointerType *>(valueType) != NULL);
valueType = valueType->GetAsNonConstType(); valueType = valueType->GetAsNonConstType();
@@ -1972,7 +1972,7 @@ FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr,
ptr = BitCastInst(ptr, LLVMTypes::Int8VectorPointerType, ptr = BitCastInst(ptr, LLVMTypes::Int8VectorPointerType,
"ptr_to_int8vecptr"); "ptr_to_int8vecptr");
} }
assert(maskedStoreFunc != NULL); Assert(maskedStoreFunc != NULL);
std::vector<llvm::Value *> args; std::vector<llvm::Value *> args;
args.push_back(ptr); args.push_back(ptr);
@@ -1992,13 +1992,13 @@ FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr,
void void
FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr, FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr,
const Type *ptrType, llvm::Value *mask) { const Type *ptrType, llvm::Value *mask) {
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
assert(ptrType->IsVaryingType()); Assert(ptrType->IsVaryingType());
const Type *valueType = ptrType->GetBaseType(); const Type *valueType = ptrType->GetBaseType();
// I think this should be impossible // I think this should be impossible
assert(dynamic_cast<const ArrayType *>(valueType) == NULL); Assert(dynamic_cast<const ArrayType *>(valueType) == NULL);
const CollectionType *collectionType = dynamic_cast<const CollectionType *>(valueType); const CollectionType *collectionType = dynamic_cast<const CollectionType *>(valueType);
if (collectionType != NULL) { if (collectionType != NULL) {
@@ -2017,7 +2017,7 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr,
const PointerType *pt = dynamic_cast<const PointerType *>(valueType); const PointerType *pt = dynamic_cast<const PointerType *>(valueType);
// And everything should be a pointer or atomic from here on out... // And everything should be a pointer or atomic from here on out...
assert(pt != NULL || Assert(pt != NULL ||
dynamic_cast<const AtomicType *>(valueType) != NULL); dynamic_cast<const AtomicType *>(valueType) != NULL);
LLVM_TYPE_CONST llvm::Type *type = value->getType(); LLVM_TYPE_CONST llvm::Type *type = value->getType();
@@ -2045,7 +2045,7 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr,
"__pseudo_scatter64_8"; "__pseudo_scatter64_8";
llvm::Function *scatterFunc = m->module->getFunction(funcName); llvm::Function *scatterFunc = m->module->getFunction(funcName);
assert(scatterFunc != NULL); Assert(scatterFunc != NULL);
AddInstrumentationPoint("scatter"); AddInstrumentationPoint("scatter");
@@ -2062,7 +2062,7 @@ void
FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr) { FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr) {
if (value == NULL || ptr == NULL) { if (value == NULL || ptr == NULL) {
// may happen due to error elsewhere // may happen due to error elsewhere
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return; return;
} }
@@ -2086,7 +2086,7 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr,
llvm::Value *mask, const Type *ptrType) { llvm::Value *mask, const Type *ptrType) {
if (value == NULL || ptr == NULL) { if (value == NULL || ptr == NULL) {
// may happen due to error elsewhere // may happen due to error elsewhere
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return; return;
} }
@@ -2106,7 +2106,7 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr,
maskedStore(value, ptr, ptrType, mask); maskedStore(value, ptr, ptrType, mask);
} }
else { else {
assert(ptrType->IsVaryingType()); Assert(ptrType->IsVaryingType());
// We have a varying ptr (an array of pointers), so it's time to // We have a varying ptr (an array of pointers), so it's time to
// scatter // scatter
scatter(value, ptr, ptrType, GetFullMask()); scatter(value, ptr, ptrType, GetFullMask());
@@ -2126,7 +2126,7 @@ FunctionEmitContext::BranchInst(llvm::BasicBlock *trueBlock,
llvm::BasicBlock *falseBlock, llvm::BasicBlock *falseBlock,
llvm::Value *test) { llvm::Value *test) {
if (test == NULL) { if (test == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return; return;
} }
@@ -2139,7 +2139,7 @@ FunctionEmitContext::BranchInst(llvm::BasicBlock *trueBlock,
llvm::Value * llvm::Value *
FunctionEmitContext::ExtractInst(llvm::Value *v, int elt, const char *name) { FunctionEmitContext::ExtractInst(llvm::Value *v, int elt, const char *name) {
if (v == NULL) { if (v == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -2159,7 +2159,7 @@ llvm::Value *
FunctionEmitContext::InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt, FunctionEmitContext::InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt,
const char *name) { const char *name) {
if (v == NULL || eltVal == NULL) { if (v == NULL || eltVal == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -2192,7 +2192,7 @@ llvm::Instruction *
FunctionEmitContext::SelectInst(llvm::Value *test, llvm::Value *val0, FunctionEmitContext::SelectInst(llvm::Value *test, llvm::Value *val0,
llvm::Value *val1, const char *name) { llvm::Value *val1, const char *name) {
if (test == NULL || val0 == NULL || val1 == NULL) { if (test == NULL || val0 == NULL || val1 == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -2223,7 +2223,7 @@ lCalleeArgCount(llvm::Value *callee, const FunctionType *funcType) {
ft = llvm::dyn_cast<LLVM_TYPE_CONST llvm::FunctionType>(pt->getElementType()); ft = llvm::dyn_cast<LLVM_TYPE_CONST llvm::FunctionType>(pt->getElementType());
} }
assert(ft != NULL); Assert(ft != NULL);
return ft->getNumParams(); return ft->getNumParams();
} }
@@ -2233,7 +2233,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType,
const std::vector<llvm::Value *> &args, const std::vector<llvm::Value *> &args,
const char *name) { const char *name) {
if (func == NULL) { if (func == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -2242,7 +2242,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType,
// isn't the case for things like intrinsics, builtins, and extern "C" // isn't the case for things like intrinsics, builtins, and extern "C"
// functions from the application. Add the mask if it's needed. // functions from the application. Add the mask if it's needed.
unsigned int calleeArgCount = lCalleeArgCount(func, funcType); unsigned int calleeArgCount = lCalleeArgCount(func, funcType);
assert(argVals.size() + 1 == calleeArgCount || Assert(argVals.size() + 1 == calleeArgCount ||
argVals.size() == calleeArgCount); argVals.size() == calleeArgCount);
if (argVals.size() + 1 == calleeArgCount) if (argVals.size() + 1 == calleeArgCount)
argVals.push_back(GetFullMask()); argVals.push_back(GetFullMask());
@@ -2313,7 +2313,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType,
llvm::Value *currentMask = LoadInst(maskPtr); llvm::Value *currentMask = LoadInst(maskPtr);
llvm::Function *cttz = llvm::Function *cttz =
m->module->getFunction("__count_trailing_zeros_i32"); m->module->getFunction("__count_trailing_zeros_i32");
assert(cttz != NULL); Assert(cttz != NULL);
llvm::Value *firstLane = CallInst(cttz, NULL, LaneMask(currentMask), llvm::Value *firstLane = CallInst(cttz, NULL, LaneMask(currentMask),
"first_lane"); "first_lane");
@@ -2360,12 +2360,12 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType,
// Now, do a masked store into the memory allocated to // Now, do a masked store into the memory allocated to
// accumulate the result using the call mask. // accumulate the result using the call mask.
if (callResult != NULL) { if (callResult != NULL) {
assert(resultPtr != NULL); Assert(resultPtr != NULL);
StoreInst(callResult, resultPtr, callMask, StoreInst(callResult, resultPtr, callMask,
PointerType::GetUniform(returnType)); PointerType::GetUniform(returnType));
} }
else else
assert(resultPtr == NULL); Assert(resultPtr == NULL);
// Update the mask to turn off the program instances for which // Update the mask to turn off the program instances for which
// we just called the function. // we just called the function.
@@ -2425,7 +2425,7 @@ FunctionEmitContext::ReturnInst() {
rinst = llvm::ReturnInst::Create(*g->ctx, retVal, bblock); rinst = llvm::ReturnInst::Create(*g->ctx, retVal, bblock);
} }
else { else {
assert(function->GetReturnType() == AtomicType::Void); Assert(function->GetReturnType() == AtomicType::Void);
rinst = llvm::ReturnInst::Create(*g->ctx, bblock); rinst = llvm::ReturnInst::Create(*g->ctx, bblock);
} }
@@ -2440,25 +2440,25 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee,
std::vector<llvm::Value *> &argVals, std::vector<llvm::Value *> &argVals,
llvm::Value *launchCount) { llvm::Value *launchCount) {
if (callee == NULL) { if (callee == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
launchedTasks = true; launchedTasks = true;
assert(llvm::isa<llvm::Function>(callee)); Assert(llvm::isa<llvm::Function>(callee));
LLVM_TYPE_CONST llvm::Type *argType = LLVM_TYPE_CONST llvm::Type *argType =
(llvm::dyn_cast<llvm::Function>(callee))->arg_begin()->getType(); (llvm::dyn_cast<llvm::Function>(callee))->arg_begin()->getType();
assert(llvm::PointerType::classof(argType)); Assert(llvm::PointerType::classof(argType));
LLVM_TYPE_CONST llvm::PointerType *pt = LLVM_TYPE_CONST llvm::PointerType *pt =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(argType); llvm::dyn_cast<LLVM_TYPE_CONST llvm::PointerType>(argType);
assert(llvm::StructType::classof(pt->getElementType())); Assert(llvm::StructType::classof(pt->getElementType()));
LLVM_TYPE_CONST llvm::StructType *argStructType = LLVM_TYPE_CONST llvm::StructType *argStructType =
static_cast<LLVM_TYPE_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);
llvm::Function *falloc = m->module->getFunction("ISPCAlloc"); llvm::Function *falloc = m->module->getFunction("ISPCAlloc");
assert(falloc != NULL); Assert(falloc != NULL);
llvm::Value *structSize = g->target.SizeOf(argStructType); llvm::Value *structSize = g->target.SizeOf(argStructType);
if (structSize->getType() != LLVMTypes::Int64Type) if (structSize->getType() != LLVMTypes::Int64Type)
// ISPCAlloc expects the size as an uint64_t, but on 32-bit // ISPCAlloc expects the size as an uint64_t, but on 32-bit
@@ -2493,7 +2493,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee,
// argument block we just filled in // argument block we just filled in
llvm::Value *fptr = BitCastInst(callee, LLVMTypes::VoidPointerType); llvm::Value *fptr = BitCastInst(callee, LLVMTypes::VoidPointerType);
llvm::Function *flaunch = m->module->getFunction("ISPCLaunch"); llvm::Function *flaunch = m->module->getFunction("ISPCLaunch");
assert(flaunch != NULL); Assert(flaunch != NULL);
std::vector<llvm::Value *> args; std::vector<llvm::Value *> args;
args.push_back(launchGroupHandlePtr); args.push_back(launchGroupHandlePtr);
args.push_back(fptr); args.push_back(fptr);
@@ -2542,7 +2542,7 @@ FunctionEmitContext::addVaryingOffsetsIfNeeded(llvm::Value *ptr,
const Type *ptrType) { const Type *ptrType) {
// This should only be called for varying pointers // This should only be called for varying pointers
const PointerType *pt = dynamic_cast<const PointerType *>(ptrType); const PointerType *pt = dynamic_cast<const PointerType *>(ptrType);
assert(pt && pt->IsVaryingType()); Assert(pt && pt->IsVaryingType());
const Type *baseType = ptrType->GetBaseType(); const Type *baseType = ptrType->GetBaseType();
if (dynamic_cast<const AtomicType *>(baseType) == NULL && if (dynamic_cast<const AtomicType *>(baseType) == NULL &&

View File

@@ -216,7 +216,7 @@ Declarator::GetFunctionInfo(DeclSpecs *ds, std::vector<Symbol *> *funArgs) {
return NULL; return NULL;
Symbol *declSym = GetSymbol(); Symbol *declSym = GetSymbol();
assert(declSym != NULL); Assert(declSym != NULL);
// Get the symbol for the function from the symbol table. (It should // Get the symbol for the function from the symbol table. (It should
// already have been added to the symbol table by AddGlobal() by the // already have been added to the symbol table by AddGlobal() by the
@@ -232,11 +232,11 @@ Declarator::GetFunctionInfo(DeclSpecs *ds, std::vector<Symbol *> *funArgs) {
Declarator *d = this; Declarator *d = this;
while (d != NULL && d->kind != DK_FUNCTION) while (d != NULL && d->kind != DK_FUNCTION)
d = d->child; d = d->child;
assert(d != NULL); Assert(d != NULL);
for (unsigned int i = 0; i < d->functionParams.size(); ++i) { for (unsigned int i = 0; i < d->functionParams.size(); ++i) {
Declaration *pdecl = d->functionParams[i]; Declaration *pdecl = d->functionParams[i];
assert(pdecl->declarators.size() == 1); Assert(pdecl->declarators.size() == 1);
funArgs->push_back(pdecl->declarators[0]->GetSymbol()); funArgs->push_back(pdecl->declarators[0]->GetSymbol());
} }
@@ -263,8 +263,8 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const {
case DK_BASE: case DK_BASE:
// All of the type qualifiers should be in the DeclSpecs for the // All of the type qualifiers should be in the DeclSpecs for the
// base declarator // base declarator
assert(typeQualifiers == 0); Assert(typeQualifiers == 0);
assert(child == NULL); Assert(child == NULL);
return type; return type;
case DK_POINTER: case DK_POINTER:
@@ -376,7 +376,7 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const {
// it lives down to the base declarator. // it lives down to the base declarator.
Declarator *decl = d->declarators[0]; Declarator *decl = d->declarators[0];
while (decl->child != NULL) { while (decl->child != NULL) {
assert(decl->initExpr == NULL); Assert(decl->initExpr == NULL);
decl = decl->child; decl = decl->child;
} }
@@ -485,7 +485,7 @@ Declaration::Declaration(DeclSpecs *ds, Declarator *d) {
std::vector<VariableDeclaration> std::vector<VariableDeclaration>
Declaration::GetVariableDeclarations() const { Declaration::GetVariableDeclarations() const {
assert(declSpecs->storageClass != SC_TYPEDEF); Assert(declSpecs->storageClass != SC_TYPEDEF);
std::vector<VariableDeclaration> vars; std::vector<VariableDeclaration> vars;
for (unsigned int i = 0; i < declarators.size(); ++i) { for (unsigned int i = 0; i < declarators.size(); ++i) {

226
expr.cpp
View File

@@ -137,15 +137,15 @@ lMaybeIssuePrecisionWarning(const AtomicType *toAtomicType,
static Expr * static Expr *
lArrayToPointer(Expr *expr) { lArrayToPointer(Expr *expr) {
assert(expr && dynamic_cast<const ArrayType *>(expr->GetType())); Assert(expr && dynamic_cast<const ArrayType *>(expr->GetType()));
Expr *zero = new ConstExpr(AtomicType::UniformInt32, 0, expr->pos); Expr *zero = new ConstExpr(AtomicType::UniformInt32, 0, expr->pos);
Expr *index = new IndexExpr(expr, zero, expr->pos); Expr *index = new IndexExpr(expr, zero, expr->pos);
Expr *addr = new AddressOfExpr(index, expr->pos); Expr *addr = new AddressOfExpr(index, expr->pos);
addr = addr->TypeCheck(); addr = addr->TypeCheck();
assert(addr != NULL); Assert(addr != NULL);
addr = addr->Optimize(); addr = addr->Optimize();
assert(addr != NULL); Assert(addr != NULL);
return addr; return addr;
} }
@@ -178,7 +178,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr,
bool failureOk, const char *errorMsgBase, SourcePos pos) { bool failureOk, const char *errorMsgBase, SourcePos pos) {
/* This function is way too long and complex. Is type conversion stuff /* This function is way too long and complex. Is type conversion stuff
always this messy, or can this be cleaned up somehow? */ always this messy, or can this be cleaned up somehow? */
assert(failureOk || errorMsgBase != NULL); Assert(failureOk || errorMsgBase != NULL);
if (toType == NULL || fromType == NULL) if (toType == NULL || fromType == NULL)
return false; return false;
@@ -380,7 +380,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr,
fromArrayType->GetElementType())) { fromArrayType->GetElementType())) {
// the case of different element counts should have returned // the case of different element counts should have returned
// successfully earlier, yes?? // successfully earlier, yes??
assert(toArrayType->GetElementCount() != fromArrayType->GetElementCount()); Assert(toArrayType->GetElementCount() != fromArrayType->GetElementCount());
goto typecast_ok; goto typecast_ok;
} }
else if (Type::Equal(toArrayType->GetElementType(), else if (Type::Equal(toArrayType->GetElementType(),
@@ -436,7 +436,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr,
// enum -> atomic (integer, generally...) is always ok // enum -> atomic (integer, generally...) is always ok
if (fromEnumType != NULL) { if (fromEnumType != NULL) {
assert(toAtomicType != NULL || toVectorType != NULL); Assert(toAtomicType != NULL || toVectorType != NULL);
goto typecast_ok; goto typecast_ok;
} }
@@ -509,7 +509,7 @@ lMatchingBoolType(const Type *type) {
if (vt != NULL) if (vt != NULL)
return new VectorType(boolBase, vt->GetElementCount()); return new VectorType(boolBase, vt->GetElementCount());
else { else {
assert(dynamic_cast<const AtomicType *>(type) != NULL || Assert(dynamic_cast<const AtomicType *>(type) != NULL ||
dynamic_cast<const PointerType *>(type) != NULL); dynamic_cast<const PointerType *>(type) != NULL);
return boolBase; return boolBase;
} }
@@ -527,7 +527,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
// This function is only called with, and only works for atomic, enum, // This function is only called with, and only works for atomic, enum,
// and vector types. // and vector types.
assert(atomicType != NULL || enumType != NULL || vectorType != NULL || Assert(atomicType != NULL || enumType != NULL || vectorType != NULL ||
pointerType != NULL); pointerType != NULL);
if (atomicType != NULL || enumType != NULL) { if (atomicType != NULL || enumType != NULL) {
@@ -549,7 +549,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
return LLVMBoolVector(value != 0.); return LLVMBoolVector(value != 0.);
case AtomicType::TYPE_INT8: { case AtomicType::TYPE_INT8: {
int i = (int)value; int i = (int)value;
assert((double)i == value); Assert((double)i == value);
return isUniform ? LLVMInt8(i) : LLVMInt8Vector(i); return isUniform ? LLVMInt8(i) : LLVMInt8Vector(i);
} }
case AtomicType::TYPE_UINT8: { case AtomicType::TYPE_UINT8: {
@@ -558,7 +558,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
} }
case AtomicType::TYPE_INT16: { case AtomicType::TYPE_INT16: {
int i = (int)value; int i = (int)value;
assert((double)i == value); Assert((double)i == value);
return isUniform ? LLVMInt16(i) : LLVMInt16Vector(i); return isUniform ? LLVMInt16(i) : LLVMInt16Vector(i);
} }
case AtomicType::TYPE_UINT16: { case AtomicType::TYPE_UINT16: {
@@ -567,7 +567,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
} }
case AtomicType::TYPE_INT32: { case AtomicType::TYPE_INT32: {
int i = (int)value; int i = (int)value;
assert((double)i == value); Assert((double)i == value);
return isUniform ? LLVMInt32(i) : LLVMInt32Vector(i); return isUniform ? LLVMInt32(i) : LLVMInt32Vector(i);
} }
case AtomicType::TYPE_UINT32: { case AtomicType::TYPE_UINT32: {
@@ -579,12 +579,12 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
LLVMFloatVector((float)value); LLVMFloatVector((float)value);
case AtomicType::TYPE_UINT64: { case AtomicType::TYPE_UINT64: {
uint64_t i = (uint64_t)value; uint64_t i = (uint64_t)value;
assert(value == (int64_t)i); Assert(value == (int64_t)i);
return isUniform ? LLVMUInt64(i) : LLVMUInt64Vector(i); return isUniform ? LLVMUInt64(i) : LLVMUInt64Vector(i);
} }
case AtomicType::TYPE_INT64: { case AtomicType::TYPE_INT64: {
int64_t i = (int64_t)value; int64_t i = (int64_t)value;
assert((double)i == value); Assert((double)i == value);
return isUniform ? LLVMInt64(i) : LLVMInt64Vector(i); return isUniform ? LLVMInt64(i) : LLVMInt64Vector(i);
} }
case AtomicType::TYPE_DOUBLE: case AtomicType::TYPE_DOUBLE:
@@ -595,7 +595,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
} }
} }
else if (pointerType != NULL) { else if (pointerType != NULL) {
assert(value == 0); Assert(value == 0);
if (pointerType->IsUniformType()) if (pointerType->IsUniformType())
return llvm::Constant::getNullValue(LLVMTypes::VoidPointerType); return llvm::Constant::getNullValue(LLVMTypes::VoidPointerType);
else else
@@ -617,7 +617,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
if (baseType->IsUniformType()) { if (baseType->IsUniformType()) {
LLVM_TYPE_CONST llvm::VectorType *lvt = LLVM_TYPE_CONST llvm::VectorType *lvt =
llvm::dyn_cast<LLVM_TYPE_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)
vals.push_back(constElement); vals.push_back(constElement);
@@ -626,7 +626,7 @@ lLLVMConstantValue(const Type *type, llvm::LLVMContext *ctx, double value) {
else { else {
LLVM_TYPE_CONST llvm::ArrayType *lat = LLVM_TYPE_CONST llvm::ArrayType *lat =
llvm::dyn_cast<LLVM_TYPE_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)
vals.push_back(constElement); vals.push_back(constElement);
@@ -658,7 +658,7 @@ lMaskForSymbol(Symbol *baseSym, FunctionEmitContext *ctx) {
static void static void
lStoreAssignResult(llvm::Value *value, llvm::Value *ptr, const Type *ptrType, lStoreAssignResult(llvm::Value *value, llvm::Value *ptr, const Type *ptrType,
FunctionEmitContext *ctx, Symbol *baseSym) { FunctionEmitContext *ctx, Symbol *baseSym) {
assert(baseSym != NULL && Assert(baseSym != NULL &&
baseSym->varyingCFDepth <= ctx->VaryingCFDepth()); baseSym->varyingCFDepth <= ctx->VaryingCFDepth());
if (!g->opt.disableMaskedStoreToStore && if (!g->opt.disableMaskedStoreToStore &&
!g->opt.disableMaskAllOnOptimizations && !g->opt.disableMaskAllOnOptimizations &&
@@ -769,7 +769,7 @@ lEmitNegate(Expr *arg, SourcePos pos, FunctionEmitContext *ctx) {
return ctx->BinaryOperator(llvm::Instruction::FSub, zero, argVal, return ctx->BinaryOperator(llvm::Instruction::FSub, zero, argVal,
"fnegate"); "fnegate");
else { else {
assert(type->IsIntType()); Assert(type->IsIntType());
return ctx->BinaryOperator(llvm::Instruction::Sub, zero, argVal, return ctx->BinaryOperator(llvm::Instruction::Sub, zero, argVal,
"inegate"); "inegate");
} }
@@ -913,7 +913,7 @@ UnaryExpr::Optimize() {
FATAL("unexpected type in UnaryExpr::Optimize() / BitNot case"); FATAL("unexpected type in UnaryExpr::Optimize() / BitNot case");
} }
case LogicalNot: { case LogicalNot: {
assert(type == AtomicType::UniformBool || Assert(type == AtomicType::UniformBool ||
type == AtomicType::VaryingBool || type == AtomicType::VaryingBool ||
type == AtomicType::UniformConstBool || type == AtomicType::UniformConstBool ||
type == AtomicType::VaryingConstBool); type == AtomicType::VaryingConstBool);
@@ -1155,7 +1155,7 @@ lEmitBinaryArith(BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1,
} }
} }
else { else {
assert(Type::EqualIgnoringConst(type0, type1)); Assert(Type::EqualIgnoringConst(type0, type1));
llvm::Instruction::BinaryOps inst; llvm::Instruction::BinaryOps inst;
bool isFloatOp = type0->IsFloatType(); bool isFloatOp = type0->IsFloatType();
@@ -1318,7 +1318,7 @@ BinaryExpr::GetType() const {
// and will fail type checking and (int + ptr) should be canonicalized // and will fail type checking and (int + ptr) should be canonicalized
// into (ptr + int) by type checking. // into (ptr + int) by type checking.
if (op == Add) if (op == Add)
assert(dynamic_cast<const PointerType *>(type1) == NULL); Assert(dynamic_cast<const PointerType *>(type1) == NULL);
if (op == Comma) if (op == Comma)
return arg1->GetType(); return arg1->GetType();
@@ -1343,14 +1343,14 @@ BinaryExpr::GetType() const {
} }
// otherwise fall through for these... // otherwise fall through for these...
assert(op == Lt || op == Gt || op == Le || op == Ge || Assert(op == Lt || op == Gt || op == Le || op == Ge ||
op == Equal || op == NotEqual); op == Equal || op == NotEqual);
} }
const Type *exprType = Type::MoreGeneralType(type0, type1, pos, lOpString(op)); const Type *exprType = Type::MoreGeneralType(type0, type1, pos, lOpString(op));
// I don't think that MoreGeneralType should be able to fail after the // I don't think that MoreGeneralType should be able to fail after the
// checks done in BinaryExpr::TypeCheck(). // checks done in BinaryExpr::TypeCheck().
assert(exprType != NULL); Assert(exprType != NULL);
switch (op) { switch (op) {
case Add: case Add:
@@ -1534,7 +1534,7 @@ BinaryExpr::Optimize() {
std::vector<Symbol *> rcpFuns; std::vector<Symbol *> rcpFuns;
m->symbolTable->LookupFunction("rcp", &rcpFuns); m->symbolTable->LookupFunction("rcp", &rcpFuns);
if (rcpFuns.size() > 0) { if (rcpFuns.size() > 0) {
assert(rcpFuns.size() == 2); Assert(rcpFuns.size() == 2);
Expr *rcpSymExpr = new FunctionSymbolExpr("rcp", rcpFuns, pos); Expr *rcpSymExpr = new FunctionSymbolExpr("rcp", rcpFuns, pos);
ExprList *args = new ExprList(arg1, arg1->pos); ExprList *args = new ExprList(arg1, arg1->pos);
Expr *rcpCall = new FunctionCallExpr(rcpSymExpr, args, Expr *rcpCall = new FunctionCallExpr(rcpSymExpr, args,
@@ -1564,7 +1564,7 @@ BinaryExpr::Optimize() {
if (constArg0 == NULL || constArg1 == NULL) if (constArg0 == NULL || constArg1 == NULL)
return this; return this;
assert(Type::EqualIgnoringConst(arg0->GetType(), arg1->GetType())); Assert(Type::EqualIgnoringConst(arg0->GetType(), arg1->GetType()));
const Type *type = arg0->GetType()->GetAsNonConstType(); const Type *type = arg0->GetType()->GetAsNonConstType();
if (type == AtomicType::UniformFloat || type == AtomicType::VaryingFloat) { if (type == AtomicType::UniformFloat || type == AtomicType::VaryingFloat) {
float v0[ISPC_MAX_NVEC], v1[ISPC_MAX_NVEC]; float v0[ISPC_MAX_NVEC], v1[ISPC_MAX_NVEC];
@@ -1653,12 +1653,12 @@ BinaryExpr::TypeCheck() {
if (dynamic_cast<const ReferenceType *>(type0) != NULL) { if (dynamic_cast<const ReferenceType *>(type0) != NULL) {
arg0 = new DereferenceExpr(arg0, arg0->pos); arg0 = new DereferenceExpr(arg0, arg0->pos);
type0 = arg0->GetType(); type0 = arg0->GetType();
assert(type0 != NULL); Assert(type0 != NULL);
} }
if (dynamic_cast<const ReferenceType *>(type1) != NULL) { if (dynamic_cast<const ReferenceType *>(type1) != NULL) {
arg1 = new DereferenceExpr(arg1, arg1->pos); arg1 = new DereferenceExpr(arg1, arg1->pos);
type1 = arg1->GetType(); type1 = arg1->GetType();
assert(type1 != NULL); Assert(type1 != NULL);
} }
// Convert arrays to pointers to their first elements // Convert arrays to pointers to their first elements
@@ -1711,7 +1711,7 @@ BinaryExpr::TypeCheck() {
std::swap(pt0, pt1); std::swap(pt0, pt1);
} }
assert(pt0 != NULL); Assert(pt0 != NULL);
if (PointerType::IsVoidPointer(pt0)) { if (PointerType::IsVoidPointer(pt0)) {
Error(pos, "Illegal to perform pointer arithmetic " Error(pos, "Illegal to perform pointer arithmetic "
@@ -1726,7 +1726,7 @@ BinaryExpr::TypeCheck() {
if (type1->IsVaryingType()) { if (type1->IsVaryingType()) {
arg0 = TypeConvertExpr(arg0, type0->GetAsVaryingType(), arg0 = TypeConvertExpr(arg0, type0->GetAsVaryingType(),
"pointer addition"); "pointer addition");
assert(arg0 != NULL); Assert(arg0 != NULL);
} }
arg1 = TypeConvertExpr(arg1, offsetType, lOpString(op)); arg1 = TypeConvertExpr(arg1, offsetType, lOpString(op));
@@ -2044,18 +2044,18 @@ AssignExpr::GetValue(FunctionEmitContext *ctx) const {
case Assign: { case Assign: {
llvm::Value *lv = lvalue->GetLValue(ctx); llvm::Value *lv = lvalue->GetLValue(ctx);
if (lv == NULL) { if (lv == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
const Type *lvalueType = lvalue->GetLValueType(); const Type *lvalueType = lvalue->GetLValueType();
if (lvalueType == NULL) { if (lvalueType == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
llvm::Value *rv = rvalue->GetValue(ctx); llvm::Value *rv = rvalue->GetValue(ctx);
if (rv == NULL) { if (rv == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -2076,7 +2076,7 @@ AssignExpr::GetValue(FunctionEmitContext *ctx) const {
case XorAssign: case XorAssign:
case OrAssign: { case OrAssign: {
// This should be caught during type checking // This should be caught during type checking
assert(!dynamic_cast<const ArrayType *>(type) && Assert(!dynamic_cast<const ArrayType *>(type) &&
!dynamic_cast<const StructType *>(type)); !dynamic_cast<const StructType *>(type));
return lEmitOpAssign(op, lvalue, rvalue, type, baseSym, pos, ctx); return lEmitOpAssign(op, lvalue, rvalue, type, baseSym, pos, ctx);
} }
@@ -2281,7 +2281,7 @@ lEmitVaryingSelect(FunctionEmitContext *ctx, llvm::Value *test,
// Don't need to worry about masking here // Don't need to worry about masking here
ctx->StoreInst(expr2, resultPtr); ctx->StoreInst(expr2, resultPtr);
// Use masking to conditionally store the expr1 values // Use masking to conditionally store the expr1 values
assert(resultPtr->getType() == Assert(resultPtr->getType() ==
PointerType::GetUniform(type)->LLVMType(g->ctx)); PointerType::GetUniform(type)->LLVMType(g->ctx));
ctx->StoreInst(expr1, resultPtr, test, PointerType::GetUniform(type)); ctx->StoreInst(expr1, resultPtr, test, PointerType::GetUniform(type));
return ctx->LoadInst(resultPtr, "selectexpr_final"); return ctx->LoadInst(resultPtr, "selectexpr_final");
@@ -2297,7 +2297,7 @@ SelectExpr::GetValue(FunctionEmitContext *ctx) const {
const Type *testType = test->GetType()->GetAsNonConstType(); const Type *testType = test->GetType()->GetAsNonConstType();
// This should be taken care of during typechecking // This should be taken care of during typechecking
assert(testType->GetBaseType() == AtomicType::UniformBool || Assert(testType->GetBaseType() == AtomicType::UniformBool ||
testType->GetBaseType() == AtomicType::VaryingBool); testType->GetBaseType() == AtomicType::VaryingBool);
const Type *type = expr1->GetType(); const Type *type = expr1->GetType();
@@ -2339,7 +2339,7 @@ SelectExpr::GetValue(FunctionEmitContext *ctx) const {
// value expressions with the mask set appropriately and then do an // value expressions with the mask set appropriately and then do an
// element-wise select to get the result // element-wise select to get the result
llvm::Value *testVal = test->GetValue(ctx); llvm::Value *testVal = test->GetValue(ctx);
assert(testVal->getType() == LLVMTypes::MaskType); Assert(testVal->getType() == LLVMTypes::MaskType);
llvm::Value *oldMask = ctx->GetInternalMask(); llvm::Value *oldMask = ctx->GetInternalMask();
ctx->SetInternalMaskAnd(oldMask, testVal); ctx->SetInternalMaskAnd(oldMask, testVal);
llvm::Value *expr1Val = expr1->GetValue(ctx); llvm::Value *expr1Val = expr1->GetValue(ctx);
@@ -2360,8 +2360,8 @@ SelectExpr::GetValue(FunctionEmitContext *ctx) const {
ctx->SetDebugPos(pos); ctx->SetDebugPos(pos);
const VectorType *vt = dynamic_cast<const VectorType *>(type); const VectorType *vt = dynamic_cast<const VectorType *>(type);
// Things that typechecking should have caught // Things that typechecking should have caught
assert(vt != NULL); Assert(vt != NULL);
assert(dynamic_cast<const VectorType *>(testType) != NULL && Assert(dynamic_cast<const VectorType *>(testType) != NULL &&
(dynamic_cast<const VectorType *>(testType)->GetElementCount() == (dynamic_cast<const VectorType *>(testType)->GetElementCount() ==
vt->GetElementCount())); vt->GetElementCount()));
@@ -2402,7 +2402,7 @@ SelectExpr::GetType() const {
dynamic_cast<const VectorType *>(testType)->GetElementCount() : 0; dynamic_cast<const VectorType *>(testType)->GetElementCount() : 0;
int expr1VecSize = dynamic_cast<const VectorType *>(expr1Type) != NULL ? int expr1VecSize = dynamic_cast<const VectorType *>(expr1Type) != NULL ?
dynamic_cast<const VectorType *>(expr1Type)->GetElementCount() : 0; dynamic_cast<const VectorType *>(expr1Type)->GetElementCount() : 0;
assert(!(testVecSize != 0 && expr1VecSize != 0 && testVecSize != expr1VecSize)); Assert(!(testVecSize != 0 && expr1VecSize != 0 && testVecSize != expr1VecSize));
int vectorSize = std::max(testVecSize, expr1VecSize); int vectorSize = std::max(testVecSize, expr1VecSize);
return Type::MoreGeneralType(expr1Type, expr2Type, Union(expr1->pos, expr2->pos), return Type::MoreGeneralType(expr1Type, expr2Type, Union(expr1->pos, expr2->pos),
@@ -2540,12 +2540,12 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const {
llvm::Value *callee = func->GetValue(ctx); llvm::Value *callee = func->GetValue(ctx);
if (callee == NULL) { if (callee == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
const FunctionType *ft = lGetFunctionType(func); const FunctionType *ft = lGetFunctionType(func);
assert(ft != NULL); Assert(ft != NULL);
bool isVoidFunc = (ft->GetReturnType() == AtomicType::Void); bool isVoidFunc = (ft->GetReturnType() == AtomicType::Void);
// Automatically convert function call args to references if needed. // Automatically convert function call args to references if needed.
@@ -2558,7 +2558,7 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const {
// Specifically, this can happen if there's an error earlier during // Specifically, this can happen if there's an error earlier during
// overload resolution. // overload resolution.
if ((int)callargs.size() > ft->GetNumParameters()) { if ((int)callargs.size() > ft->GetNumParameters()) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -2625,7 +2625,7 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const {
llvm::Value *retVal = NULL; llvm::Value *retVal = NULL;
ctx->SetDebugPos(pos); ctx->SetDebugPos(pos);
if (ft->isTask) { if (ft->isTask) {
assert(launchCountExpr != NULL); Assert(launchCountExpr != NULL);
llvm::Value *launchCount = launchCountExpr->GetValue(ctx); llvm::Value *launchCount = launchCountExpr->GetValue(ctx);
if (launchCount != NULL) if (launchCount != NULL)
ctx->LaunchInst(callee, argVals, launchCount); ctx->LaunchInst(callee, argVals, launchCount);
@@ -2723,7 +2723,7 @@ FunctionCallExpr::TypeCheck() {
if (isLaunch) if (isLaunch)
Error(pos, "\"launch\" expression illegal with non-\"task\"-" Error(pos, "\"launch\" expression illegal with non-\"task\"-"
"qualified function."); "qualified function.");
assert(launchCountExpr == NULL); Assert(launchCountExpr == NULL);
} }
} }
else { else {
@@ -2732,7 +2732,7 @@ FunctionCallExpr::TypeCheck() {
if (fptrType == NULL) if (fptrType == NULL)
return NULL; return NULL;
assert(dynamic_cast<const PointerType *>(fptrType) != NULL); Assert(dynamic_cast<const PointerType *>(fptrType) != NULL);
const FunctionType *funcType = const FunctionType *funcType =
dynamic_cast<const FunctionType *>(fptrType->GetBaseType()); dynamic_cast<const FunctionType *>(fptrType->GetBaseType());
if (funcType == NULL) { if (funcType == NULL) {
@@ -2779,7 +2779,7 @@ FunctionCallExpr::TypeCheck() {
// Otherwise the parameter default saves us. It should // Otherwise the parameter default saves us. It should
// be there for sure, given the check right above the // be there for sure, given the check right above the
// for loop. // for loop.
assert(funcType->GetParameterDefault(i) != NULL); Assert(funcType->GetParameterDefault(i) != NULL);
} }
if (fptrType->IsVaryingType() && if (fptrType->IsVaryingType() &&
@@ -2809,7 +2809,7 @@ FunctionCallExpr::EstimateCost() const {
// it's going through a function pointer // it's going through a function pointer
const Type *fpType = func->GetType(); const Type *fpType = func->GetType();
if (fpType != NULL) { if (fpType != NULL) {
assert(dynamic_cast<const PointerType *>(fpType) != NULL); Assert(dynamic_cast<const PointerType *>(fpType) != NULL);
if (fpType->IsUniformType()) if (fpType->IsUniformType())
callCost = COST_FUNPTR_UNIFORM; callCost = COST_FUNPTR_UNIFORM;
else else
@@ -2923,7 +2923,7 @@ ExprList::GetConstant(const Type *type) const {
#else #else
LLVM_TYPE_CONST llvm::StructType *llvmStructType = LLVM_TYPE_CONST llvm::StructType *llvmStructType =
llvm::dyn_cast<LLVM_TYPE_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
} }
@@ -2934,7 +2934,7 @@ ExprList::GetConstant(const Type *type) const {
// 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...
assert(lat != NULL); Assert(lat != NULL);
return llvm::ConstantArray::get(lat, cv); return llvm::ConstantArray::get(lat, cv);
} }
return NULL; return NULL;
@@ -3001,7 +3001,7 @@ lAddVaryingOffsetsIfNeeded(FunctionEmitContext *ctx, llvm::Value *ptr,
// References are uniform pointers, so no offsetting is needed // References are uniform pointers, so no offsetting is needed
return ptr; return ptr;
assert(dynamic_cast<const PointerType *>(ptrType) != NULL); Assert(dynamic_cast<const PointerType *>(ptrType) != NULL);
if (ptrType->IsUniformType()) if (ptrType->IsUniformType())
return ptr; return ptr;
@@ -3050,7 +3050,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const {
// that we can index from there... // that we can index from there...
llvm::Value *val = baseExpr->GetValue(ctx); llvm::Value *val = baseExpr->GetValue(ctx);
if (val == NULL) { if (val == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
ctx->SetDebugPos(pos); ctx->SetDebugPos(pos);
@@ -3064,7 +3064,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const {
const SequentialType *st = const SequentialType *st =
dynamic_cast<const SequentialType *>(baseExprType); dynamic_cast<const SequentialType *>(baseExprType);
if (st == NULL) { if (st == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
lvalueType = PointerType::GetUniform(st->GetElementType()); lvalueType = PointerType::GetUniform(st->GetElementType());
@@ -3075,7 +3075,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const {
} }
else { else {
Symbol *baseSym = GetBaseSymbol(); Symbol *baseSym = GetBaseSymbol();
assert(baseSym != NULL); Assert(baseSym != NULL);
mask = lMaskForSymbol(baseSym, ctx); mask = lMaskForSymbol(baseSym, ctx);
} }
@@ -3103,7 +3103,7 @@ IndexExpr::GetType() const {
const SequentialType *sequentialType = const SequentialType *sequentialType =
dynamic_cast<const SequentialType *>(baseExprType->GetReferenceTarget()); dynamic_cast<const SequentialType *>(baseExprType->GetReferenceTarget());
// Typechecking should have caught this... // Typechecking should have caught this...
assert(sequentialType != NULL); Assert(sequentialType != NULL);
elementType = sequentialType->GetElementType(); elementType = sequentialType->GetElementType();
} }
@@ -3152,7 +3152,7 @@ IndexExpr::GetLValue(FunctionEmitContext *ctx) const {
} }
else { else {
baseExprType = baseExprType->GetReferenceTarget(); baseExprType = baseExprType->GetReferenceTarget();
assert(dynamic_cast<const ArrayType *>(baseExprType) || Assert(dynamic_cast<const ArrayType *>(baseExprType) ||
dynamic_cast<const VectorType *>(baseExprType)); dynamic_cast<const VectorType *>(baseExprType));
basePtr = baseExpr->GetValue(ctx); basePtr = baseExpr->GetValue(ctx);
basePtrType = baseExpr->GetType(); basePtrType = baseExpr->GetType();
@@ -3197,7 +3197,7 @@ IndexExpr::GetLValueType() const {
if (dynamic_cast<const ReferenceType *>(baseExprLValueType) != NULL) if (dynamic_cast<const ReferenceType *>(baseExprLValueType) != NULL)
baseExprLValueType = PointerType::GetUniform(baseExprLValueType->GetReferenceTarget()); baseExprLValueType = PointerType::GetUniform(baseExprLValueType->GetReferenceTarget());
assert(dynamic_cast<const PointerType *>(baseExprLValueType) != NULL); Assert(dynamic_cast<const PointerType *>(baseExprLValueType) != NULL);
// FIXME: can we do something in the type system that unifies the // FIXME: can we do something in the type system that unifies the
// concept of a sequential type's element type and a pointer type's // concept of a sequential type's element type and a pointer type's
@@ -3214,7 +3214,7 @@ IndexExpr::GetLValueType() const {
const PointerType *pt = const PointerType *pt =
dynamic_cast<const PointerType *>(baseExprLValueType->GetBaseType()); dynamic_cast<const PointerType *>(baseExprLValueType->GetBaseType());
assert(pt != NULL); Assert(pt != NULL);
if (baseExprLValueType->IsUniformType() && indexType->IsUniformType()) if (baseExprLValueType->IsUniformType() && indexType->IsUniformType())
return PointerType::GetUniform(pt->GetBaseType()); return PointerType::GetUniform(pt->GetBaseType());
else else
@@ -3419,10 +3419,10 @@ StructMemberExpr::getStructType() const {
else { else {
const ReferenceType *rt = const ReferenceType *rt =
dynamic_cast<const ReferenceType *>(exprType); dynamic_cast<const ReferenceType *>(exprType);
assert(rt != NULL); Assert(rt != NULL);
structType = dynamic_cast<const StructType *>(rt->GetReferenceTarget()); structType = dynamic_cast<const StructType *>(rt->GetReferenceTarget());
} }
assert(structType != NULL); Assert(structType != NULL);
} }
return structType; return structType;
} }
@@ -3461,11 +3461,11 @@ VectorMemberExpr::VectorMemberExpr(Expr *e, const char *id, SourcePos p,
if (pt != NULL) if (pt != NULL)
exprVectorType = dynamic_cast<const VectorType *>(pt->GetBaseType()); exprVectorType = dynamic_cast<const VectorType *>(pt->GetBaseType());
else { else {
assert(dynamic_cast<const ReferenceType *>(exprType) != NULL); Assert(dynamic_cast<const ReferenceType *>(exprType) != NULL);
exprVectorType = exprVectorType =
dynamic_cast<const VectorType *>(exprType->GetReferenceTarget()); dynamic_cast<const VectorType *>(exprType->GetReferenceTarget());
} }
assert(exprVectorType != NULL); Assert(exprVectorType != NULL);
} }
memberType = new VectorType(exprVectorType->GetElementType(), memberType = new VectorType(exprVectorType->GetElementType(),
identifier.length()); identifier.length());
@@ -3515,7 +3515,7 @@ VectorMemberExpr::GetLValueType() const {
vt = dynamic_cast<const VectorType *>(exprLValueType->GetReferenceTarget()); vt = dynamic_cast<const VectorType *>(exprLValueType->GetReferenceTarget());
else else
vt = dynamic_cast<const VectorType *>(exprLValueType->GetBaseType()); vt = dynamic_cast<const VectorType *>(exprLValueType->GetBaseType());
assert(vt != NULL); Assert(vt != NULL);
// we don't want to report that it's e.g. a pointer to a float<1>, // we don't want to report that it's e.g. a pointer to a float<1>,
// but ta pointer to a float, etc. // but ta pointer to a float, etc.
@@ -3562,7 +3562,7 @@ VectorMemberExpr::GetValue(FunctionEmitContext *ctx) const {
} }
if (basePtr == NULL || basePtrType == NULL) { if (basePtr == NULL || basePtrType == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
@@ -3624,7 +3624,7 @@ MemberExpr::create(Expr *e, const char *id, SourcePos p, SourcePos idpos,
if (referenceType != NULL) { if (referenceType != NULL) {
e = new DereferenceExpr(e, e->pos); e = new DereferenceExpr(e, e->pos);
exprType = e->GetType(); exprType = e->GetType();
assert(exprType != NULL); Assert(exprType != NULL);
} }
const PointerType *pointerType = dynamic_cast<const PointerType *>(exprType); const PointerType *pointerType = dynamic_cast<const PointerType *>(exprType);
@@ -3686,7 +3686,7 @@ MemberExpr::GetValue(FunctionEmitContext *ctx) const {
// so that we can index from there... // so that we can index from there...
llvm::Value *val = expr->GetValue(ctx); llvm::Value *val = expr->GetValue(ctx);
if (!val) { if (!val) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return NULL; return NULL;
} }
ctx->SetDebugPos(pos); ctx->SetDebugPos(pos);
@@ -3706,7 +3706,7 @@ MemberExpr::GetValue(FunctionEmitContext *ctx) const {
} }
else { else {
Symbol *baseSym = GetBaseSymbol(); Symbol *baseSym = GetBaseSymbol();
assert(baseSym != NULL); Assert(baseSym != NULL);
mask = lMaskForSymbol(baseSym, ctx); mask = lMaskForSymbol(baseSym, ctx);
} }
@@ -3850,7 +3850,7 @@ ConstExpr::ConstExpr(const Type *t, int8_t i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt8); Assert(type == AtomicType::UniformConstInt8);
int8Val[0] = i; int8Val[0] = i;
} }
@@ -3859,7 +3859,7 @@ ConstExpr::ConstExpr(const Type *t, int8_t *i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt8 || Assert(type == AtomicType::UniformConstInt8 ||
type == AtomicType::VaryingConstInt8); type == AtomicType::VaryingConstInt8);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
int8Val[j] = i[j]; int8Val[j] = i[j];
@@ -3870,7 +3870,7 @@ ConstExpr::ConstExpr(const Type *t, uint8_t u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt8); Assert(type == AtomicType::UniformConstUInt8);
uint8Val[0] = u; uint8Val[0] = u;
} }
@@ -3879,7 +3879,7 @@ ConstExpr::ConstExpr(const Type *t, uint8_t *u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt8 || Assert(type == AtomicType::UniformConstUInt8 ||
type == AtomicType::VaryingConstUInt8); type == AtomicType::VaryingConstUInt8);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
uint8Val[j] = u[j]; uint8Val[j] = u[j];
@@ -3890,7 +3890,7 @@ ConstExpr::ConstExpr(const Type *t, int16_t i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt16); Assert(type == AtomicType::UniformConstInt16);
int16Val[0] = i; int16Val[0] = i;
} }
@@ -3899,7 +3899,7 @@ ConstExpr::ConstExpr(const Type *t, int16_t *i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt16 || Assert(type == AtomicType::UniformConstInt16 ||
type == AtomicType::VaryingConstInt16); type == AtomicType::VaryingConstInt16);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
int16Val[j] = i[j]; int16Val[j] = i[j];
@@ -3910,7 +3910,7 @@ ConstExpr::ConstExpr(const Type *t, uint16_t u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt16); Assert(type == AtomicType::UniformConstUInt16);
uint16Val[0] = u; uint16Val[0] = u;
} }
@@ -3919,7 +3919,7 @@ ConstExpr::ConstExpr(const Type *t, uint16_t *u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt16 || Assert(type == AtomicType::UniformConstUInt16 ||
type == AtomicType::VaryingConstUInt16); type == AtomicType::VaryingConstUInt16);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
uint16Val[j] = u[j]; uint16Val[j] = u[j];
@@ -3930,7 +3930,7 @@ ConstExpr::ConstExpr(const Type *t, int32_t i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt32); Assert(type == AtomicType::UniformConstInt32);
int32Val[0] = i; int32Val[0] = i;
} }
@@ -3939,7 +3939,7 @@ ConstExpr::ConstExpr(const Type *t, int32_t *i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt32 || Assert(type == AtomicType::UniformConstInt32 ||
type == AtomicType::VaryingConstInt32); type == AtomicType::VaryingConstInt32);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
int32Val[j] = i[j]; int32Val[j] = i[j];
@@ -3950,7 +3950,7 @@ ConstExpr::ConstExpr(const Type *t, uint32_t u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt32 || Assert(type == AtomicType::UniformConstUInt32 ||
(dynamic_cast<const EnumType *>(type) != NULL && (dynamic_cast<const EnumType *>(type) != NULL &&
type->IsUniformType())); type->IsUniformType()));
uint32Val[0] = u; uint32Val[0] = u;
@@ -3961,7 +3961,7 @@ ConstExpr::ConstExpr(const Type *t, uint32_t *u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt32 || Assert(type == AtomicType::UniformConstUInt32 ||
type == AtomicType::VaryingConstUInt32 || type == AtomicType::VaryingConstUInt32 ||
(dynamic_cast<const EnumType *>(type) != NULL)); (dynamic_cast<const EnumType *>(type) != NULL));
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
@@ -3973,7 +3973,7 @@ ConstExpr::ConstExpr(const Type *t, float f, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstFloat); Assert(type == AtomicType::UniformConstFloat);
floatVal[0] = f; floatVal[0] = f;
} }
@@ -3982,7 +3982,7 @@ ConstExpr::ConstExpr(const Type *t, float *f, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstFloat || Assert(type == AtomicType::UniformConstFloat ||
type == AtomicType::VaryingConstFloat); type == AtomicType::VaryingConstFloat);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
floatVal[j] = f[j]; floatVal[j] = f[j];
@@ -3993,7 +3993,7 @@ ConstExpr::ConstExpr(const Type *t, int64_t i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt64); Assert(type == AtomicType::UniformConstInt64);
int64Val[0] = i; int64Val[0] = i;
} }
@@ -4002,7 +4002,7 @@ ConstExpr::ConstExpr(const Type *t, int64_t *i, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstInt64 || Assert(type == AtomicType::UniformConstInt64 ||
type == AtomicType::VaryingConstInt64); type == AtomicType::VaryingConstInt64);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
int64Val[j] = i[j]; int64Val[j] = i[j];
@@ -4013,7 +4013,7 @@ ConstExpr::ConstExpr(const Type *t, uint64_t u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt64); Assert(type == AtomicType::UniformConstUInt64);
uint64Val[0] = u; uint64Val[0] = u;
} }
@@ -4022,7 +4022,7 @@ ConstExpr::ConstExpr(const Type *t, uint64_t *u, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstUInt64 || Assert(type == AtomicType::UniformConstUInt64 ||
type == AtomicType::VaryingConstUInt64); type == AtomicType::VaryingConstUInt64);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
uint64Val[j] = u[j]; uint64Val[j] = u[j];
@@ -4033,7 +4033,7 @@ ConstExpr::ConstExpr(const Type *t, double f, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstDouble); Assert(type == AtomicType::UniformConstDouble);
doubleVal[0] = f; doubleVal[0] = f;
} }
@@ -4042,7 +4042,7 @@ ConstExpr::ConstExpr(const Type *t, double *f, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstDouble || Assert(type == AtomicType::UniformConstDouble ||
type == AtomicType::VaryingConstDouble); type == AtomicType::VaryingConstDouble);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
doubleVal[j] = f[j]; doubleVal[j] = f[j];
@@ -4053,7 +4053,7 @@ ConstExpr::ConstExpr(const Type *t, bool b, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstBool); Assert(type == AtomicType::UniformConstBool);
boolVal[0] = b; boolVal[0] = b;
} }
@@ -4062,7 +4062,7 @@ ConstExpr::ConstExpr(const Type *t, bool *b, SourcePos p)
: Expr(p) { : Expr(p) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
assert(type == AtomicType::UniformConstBool || Assert(type == AtomicType::UniformConstBool ||
type == AtomicType::VaryingConstBool); type == AtomicType::VaryingConstBool);
for (int j = 0; j < Count(); ++j) for (int j = 0; j < Count(); ++j)
boolVal[j] = b[j]; boolVal[j] = b[j];
@@ -4129,7 +4129,7 @@ ConstExpr::getBasicType() const {
if (at != NULL) if (at != NULL)
return at->basicType; return at->basicType;
else { else {
assert(dynamic_cast<const EnumType *>(type) != NULL); Assert(dynamic_cast<const EnumType *>(type) != NULL);
return AtomicType::TYPE_UINT32; return AtomicType::TYPE_UINT32;
} }
} }
@@ -4481,7 +4481,7 @@ ConstExpr::GetConstant(const Type *type) const {
// Caller shouldn't be trying to stuff a varying value here into a // Caller shouldn't be trying to stuff a varying value here into a
// constant type. // constant type.
if (type->IsUniformType()) if (type->IsUniformType())
assert(Count() == 1); Assert(Count() == 1);
type = type->GetAsNonConstType(); type = type->GetAsNonConstType();
if (type == AtomicType::UniformBool || type == AtomicType::VaryingBool) { if (type == AtomicType::UniformBool || type == AtomicType::VaryingBool) {
@@ -5208,7 +5208,7 @@ lUniformValueToVarying(FunctionEmitContext *ctx, llvm::Value *value,
// Otherwise we must have a uniform AtomicType, so smear its value // Otherwise we must have a uniform AtomicType, so smear its value
// across the vector lanes. // across the vector lanes.
assert(dynamic_cast<const AtomicType *>(type) != NULL); Assert(dynamic_cast<const AtomicType *>(type) != NULL);
return ctx->SmearUniform(value); return ctx->SmearUniform(value);
} }
@@ -5247,13 +5247,13 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
return value; return value;
} }
else { else {
assert(fromType->IsUniformType() && toType->IsVaryingType()); Assert(fromType->IsUniformType() && toType->IsVaryingType());
value = ctx->PtrToIntInst(value); value = ctx->PtrToIntInst(value);
return ctx->SmearUniform(value); return ctx->SmearUniform(value);
} }
} }
else { else {
assert(dynamic_cast<const AtomicType *>(toType) != NULL); Assert(dynamic_cast<const AtomicType *>(toType) != NULL);
if (toType->IsBoolType()) { if (toType->IsBoolType()) {
// convert pointer to bool // convert pointer to bool
LLVM_TYPE_CONST llvm::Type *lfu = LLVM_TYPE_CONST llvm::Type *lfu =
@@ -5305,20 +5305,20 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
// implicit array to pointer to first element // implicit array to pointer to first element
Expr *arrayAsPtr = lArrayToPointer(expr); Expr *arrayAsPtr = lArrayToPointer(expr);
if (Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType) == false) { if (Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType) == false) {
assert(Type::EqualIgnoringConst(arrayAsPtr->GetType()->GetAsVaryingType(), Assert(Type::EqualIgnoringConst(arrayAsPtr->GetType()->GetAsVaryingType(),
toPointerType) == true); toPointerType) == true);
arrayAsPtr = new TypeCastExpr(toPointerType, arrayAsPtr, false, pos); arrayAsPtr = new TypeCastExpr(toPointerType, arrayAsPtr, false, pos);
arrayAsPtr = arrayAsPtr->TypeCheck(); arrayAsPtr = arrayAsPtr->TypeCheck();
assert(arrayAsPtr != NULL); Assert(arrayAsPtr != NULL);
arrayAsPtr = arrayAsPtr->Optimize(); arrayAsPtr = arrayAsPtr->Optimize();
assert(arrayAsPtr != NULL); Assert(arrayAsPtr != NULL);
} }
assert(Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType)); Assert(Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType));
return arrayAsPtr->GetValue(ctx); return arrayAsPtr->GetValue(ctx);
} }
// This also should be caught during typechecking // This also should be caught during typechecking
assert(!(toType->IsUniformType() && fromType->IsVaryingType())); Assert(!(toType->IsUniformType() && fromType->IsVaryingType()));
if (toArrayType != NULL && fromArrayType != NULL) { if (toArrayType != NULL && fromArrayType != NULL) {
// cast array pointer from [n x foo] to [0 x foo] if needed to be able // cast array pointer from [n x foo] to [0 x foo] if needed to be able
@@ -5327,7 +5327,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
(toArrayType->GetElementCount() != fromArrayType->GetElementCount())) (toArrayType->GetElementCount() != fromArrayType->GetElementCount()))
Warning(pos, "Type-converting array of length %d to length %d", Warning(pos, "Type-converting array of length %d to length %d",
fromArrayType->GetElementCount(), toArrayType->GetElementCount()); fromArrayType->GetElementCount(), toArrayType->GetElementCount());
assert(Type::EqualIgnoringConst(toArrayType->GetBaseType(), Assert(Type::EqualIgnoringConst(toArrayType->GetBaseType(),
fromArrayType->GetBaseType())); fromArrayType->GetBaseType()));
llvm::Value *v = expr->GetValue(ctx); llvm::Value *v = expr->GetValue(ctx);
LLVM_TYPE_CONST llvm::Type *ptype = toType->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *ptype = toType->LLVMType(g->ctx);
@@ -5349,14 +5349,14 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
(toArray->GetElementCount() != fromArray->GetElementCount())) (toArray->GetElementCount() != fromArray->GetElementCount()))
Warning(pos, "Type-converting array of length %d to length %d", Warning(pos, "Type-converting array of length %d to length %d",
fromArray->GetElementCount(), toArray->GetElementCount()); fromArray->GetElementCount(), toArray->GetElementCount());
assert(Type::EqualIgnoringConst(toArray->GetBaseType(), Assert(Type::EqualIgnoringConst(toArray->GetBaseType(),
fromArray->GetBaseType())); fromArray->GetBaseType()));
llvm::Value *v = expr->GetValue(ctx); llvm::Value *v = expr->GetValue(ctx);
LLVM_TYPE_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");
} }
assert(Type::Equal(toTarget, fromTarget) || Assert(Type::Equal(toTarget, fromTarget) ||
Type::Equal(toTarget, fromTarget->GetAsConstType())); Type::Equal(toTarget, fromTarget->GetAsConstType()));
return expr->GetValue(ctx); return expr->GetValue(ctx);
} }
@@ -5366,7 +5366,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
if (toStruct && fromStruct) { if (toStruct && fromStruct) {
// The only legal type conversions for structs are to go from a // The only legal type conversions for structs are to go from a
// uniform to a varying instance of the same struct type. // uniform to a varying instance of the same struct type.
assert(toStruct->IsVaryingType() && fromStruct->IsUniformType() && Assert(toStruct->IsVaryingType() && fromStruct->IsUniformType() &&
Type::Equal(toStruct, fromStruct->GetAsVaryingType())); Type::Equal(toStruct, fromStruct->GetAsVaryingType()));
llvm::Value *origValue = expr->GetValue(ctx); llvm::Value *origValue = expr->GetValue(ctx);
@@ -5379,7 +5379,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
const VectorType *fromVector = dynamic_cast<const VectorType *>(fromType); const VectorType *fromVector = dynamic_cast<const VectorType *>(fromType);
if (toVector && fromVector) { if (toVector && fromVector) {
// this should be caught during typechecking // this should be caught during typechecking
assert(toVector->GetElementCount() == fromVector->GetElementCount()); Assert(toVector->GetElementCount() == fromVector->GetElementCount());
llvm::Value *exprVal = expr->GetValue(ctx); llvm::Value *exprVal = expr->GetValue(ctx);
if (!exprVal) if (!exprVal)
@@ -5421,7 +5421,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
const AtomicType *fromAtomic = dynamic_cast<const AtomicType *>(fromType); const AtomicType *fromAtomic = dynamic_cast<const AtomicType *>(fromType);
// at this point, coming from an atomic type is all that's left... // at this point, coming from an atomic type is all that's left...
assert(fromAtomic != NULL); Assert(fromAtomic != NULL);
if (toVector) { if (toVector) {
// scalar -> short vector conversion // scalar -> short vector conversion
@@ -5449,7 +5449,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
else { else {
const AtomicType *toAtomic = dynamic_cast<const AtomicType *>(toType); const AtomicType *toAtomic = dynamic_cast<const AtomicType *>(toType);
// typechecking should ensure this is the case // typechecking should ensure this is the case
assert(toAtomic != NULL); Assert(toAtomic != NULL);
return lTypeConvAtomic(ctx, exprVal, toAtomic, fromAtomic, pos); return lTypeConvAtomic(ctx, exprVal, toAtomic, fromAtomic, pos);
} }
@@ -5666,7 +5666,7 @@ TypeCastExpr::GetConstant(const Type *constType) const {
// method called. Thus, the only case we do need to worry about here // method called. Thus, the only case we do need to worry about here
// is converting a uniform function pointer to a varying function // is converting a uniform function pointer to a varying function
// pointer of the same type. // pointer of the same type.
assert(Type::Equal(constType, type)); Assert(Type::Equal(constType, type));
const FunctionType *ft = NULL; const FunctionType *ft = NULL;
if (dynamic_cast<const PointerType *>(type) == NULL || if (dynamic_cast<const PointerType *>(type) == NULL ||
(ft = dynamic_cast<const FunctionType *>(type->GetBaseType())) == NULL) (ft = dynamic_cast<const FunctionType *>(type->GetBaseType())) == NULL)
@@ -5678,7 +5678,7 @@ TypeCastExpr::GetConstant(const Type *constType) const {
ec = llvm::ConstantExpr::getPtrToInt(ec, LLVMTypes::PointerIntType); ec = llvm::ConstantExpr::getPtrToInt(ec, LLVMTypes::PointerIntType);
assert(type->IsVaryingType()); Assert(type->IsVaryingType());
std::vector<llvm::Constant *> smear; std::vector<llvm::Constant *> smear;
for (int i = 0; i < g->target.vectorWidth; ++i) for (int i = 0; i < g->target.vectorWidth; ++i)
smear.push_back(ec); smear.push_back(ec);
@@ -5834,7 +5834,7 @@ DereferenceExpr::GetType() const {
if (dynamic_cast<const ReferenceType *>(exprType) != NULL) if (dynamic_cast<const ReferenceType *>(exprType) != NULL)
return exprType->GetReferenceTarget(); return exprType->GetReferenceTarget();
else { else {
assert(dynamic_cast<const PointerType *>(exprType) != NULL); Assert(dynamic_cast<const PointerType *>(exprType) != NULL);
if (exprType->IsUniformType()) if (exprType->IsUniformType())
return exprType->GetBaseType(); return exprType->GetBaseType();
else else
@@ -6095,7 +6095,7 @@ SymbolExpr::Optimize() {
if (symbol == NULL) if (symbol == NULL)
return NULL; return NULL;
else if (symbol->constValue != NULL) { else if (symbol->constValue != NULL) {
assert(GetType()->IsConstType()); Assert(GetType()->IsConstType());
return symbol->constValue; return symbol->constValue;
} }
else else
@@ -6191,8 +6191,8 @@ FunctionSymbolExpr::Print() const {
llvm::Constant * llvm::Constant *
FunctionSymbolExpr::GetConstant(const Type *type) const { FunctionSymbolExpr::GetConstant(const Type *type) const {
assert(type->IsUniformType()); Assert(type->IsUniformType());
assert(GetType()->IsUniformType()); Assert(GetType()->IsUniformType());
if (Type::EqualIgnoringConst(type, GetType()) == false) if (Type::EqualIgnoringConst(type, GetType()) == false)
return NULL; return NULL;
@@ -6364,7 +6364,7 @@ lMatchWithTypeConv(const Type *callType, const Type *funcArgType) {
*/ */
static Symbol * static Symbol *
lGetBestMatch(std::vector<std::pair<int, Symbol *> > &matches) { lGetBestMatch(std::vector<std::pair<int, Symbol *> > &matches) {
assert(matches.size() > 0); Assert(matches.size() > 0);
int minCost = matches[0].first; int minCost = matches[0].first;
for (unsigned int i = 1; i < matches.size(); ++i) for (unsigned int i = 1; i < matches.size(); ++i)
@@ -6405,7 +6405,7 @@ FunctionSymbolExpr::tryResolve(int (*matchFunc)(const Type *, const Type *),
Symbol *candidateFunction = *iter; Symbol *candidateFunction = *iter;
const FunctionType *ft = const FunctionType *ft =
dynamic_cast<const FunctionType *>(candidateFunction->type); dynamic_cast<const FunctionType *>(candidateFunction->type);
assert(ft != NULL); Assert(ft != NULL);
// There's no way to match if the caller is passing more arguments // There's no way to match if the caller is passing more arguments
// than this function instance takes. // than this function instance takes.

View File

@@ -72,7 +72,7 @@ Function::Function(Symbol *s, const std::vector<Symbol *> &a, Stmt *c) {
code = c; code = c;
maskSymbol = m->symbolTable->LookupVariable("__mask"); maskSymbol = m->symbolTable->LookupVariable("__mask");
assert(maskSymbol != NULL); Assert(maskSymbol != NULL);
if (code != NULL) { if (code != NULL) {
if (g->debugPrint) { if (g->debugPrint) {
@@ -109,7 +109,7 @@ Function::Function(Symbol *s, const std::vector<Symbol *> &a, Stmt *c) {
} }
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
assert(type != NULL); Assert(type != NULL);
for (unsigned int i = 0; i < args.size(); ++i) for (unsigned int i = 0; i < args.size(); ++i)
if (dynamic_cast<const ReferenceType *>(args[i]->type) == NULL) if (dynamic_cast<const ReferenceType *>(args[i]->type) == NULL)
@@ -117,13 +117,13 @@ Function::Function(Symbol *s, const std::vector<Symbol *> &a, Stmt *c) {
if (type->isTask) { if (type->isTask) {
threadIndexSym = m->symbolTable->LookupVariable("threadIndex"); threadIndexSym = m->symbolTable->LookupVariable("threadIndex");
assert(threadIndexSym); Assert(threadIndexSym);
threadCountSym = m->symbolTable->LookupVariable("threadCount"); threadCountSym = m->symbolTable->LookupVariable("threadCount");
assert(threadCountSym); Assert(threadCountSym);
taskIndexSym = m->symbolTable->LookupVariable("taskIndex"); taskIndexSym = m->symbolTable->LookupVariable("taskIndex");
assert(taskIndexSym); Assert(taskIndexSym);
taskCountSym = m->symbolTable->LookupVariable("taskCount"); taskCountSym = m->symbolTable->LookupVariable("taskCount");
assert(taskCountSym); Assert(taskCountSym);
} }
else else
threadIndexSym = threadCountSym = taskIndexSym = taskCountSym = NULL; threadIndexSym = threadCountSym = taskIndexSym = taskCountSym = NULL;
@@ -133,7 +133,7 @@ Function::Function(Symbol *s, const std::vector<Symbol *> &a, Stmt *c) {
const Type * const Type *
Function::GetReturnType() const { Function::GetReturnType() const {
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
assert(type != NULL); Assert(type != NULL);
return type->GetReturnType(); return type->GetReturnType();
} }
@@ -141,7 +141,7 @@ Function::GetReturnType() const {
const FunctionType * const FunctionType *
Function::GetType() const { Function::GetType() const {
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
assert(type != NULL); Assert(type != NULL);
return type; return type;
} }
@@ -157,9 +157,9 @@ lCopyInTaskParameter(int i, llvm::Value *structArgPtr, const std::vector<Symbol
// We expect the argument structure to come in as a poitner to a // We expect the argument structure to come in as a poitner to a
// structure. Confirm and figure out its type here. // structure. Confirm and figure out its type here.
const llvm::Type *structArgType = structArgPtr->getType(); const llvm::Type *structArgType = structArgPtr->getType();
assert(llvm::isa<llvm::PointerType>(structArgType)); Assert(llvm::isa<llvm::PointerType>(structArgType));
const llvm::PointerType *pt = llvm::dyn_cast<const llvm::PointerType>(structArgType); const llvm::PointerType *pt = llvm::dyn_cast<const llvm::PointerType>(structArgType);
assert(llvm::isa<llvm::StructType>(pt->getElementType())); Assert(llvm::isa<llvm::StructType>(pt->getElementType()));
const llvm::StructType *argStructType = const llvm::StructType *argStructType =
llvm::dyn_cast<const llvm::StructType>(pt->getElementType()); llvm::dyn_cast<const llvm::StructType>(pt->getElementType());
@@ -201,7 +201,7 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
llvm::BasicBlock *entryBBlock = ctx->GetCurrentBasicBlock(); llvm::BasicBlock *entryBBlock = ctx->GetCurrentBasicBlock();
#endif #endif
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
assert(type != NULL); Assert(type != NULL);
if (type->isTask == true) { if (type->isTask == true) {
// For tasks, we there should always be three parmeters: the // For tasks, we there should always be three parmeters: the
// pointer to the structure that holds all of the arguments, the // pointer to the structure that holds all of the arguments, the
@@ -266,9 +266,9 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
else { else {
// Otherwise use the mask to set the entry mask value // Otherwise use the mask to set the entry mask value
argIter->setName("__mask"); argIter->setName("__mask");
assert(argIter->getType() == LLVMTypes::MaskType); Assert(argIter->getType() == LLVMTypes::MaskType);
ctx->SetFunctionMask(argIter); ctx->SetFunctionMask(argIter);
assert(++argIter == function->arg_end()); Assert(++argIter == function->arg_end());
} }
} }
@@ -372,7 +372,7 @@ Function::GenerateIR() {
return; return;
llvm::Function *function = sym->function; llvm::Function *function = sym->function;
assert(function != NULL); Assert(function != NULL);
// But if that function has a definition, we don't want to redefine it. // But if that function has a definition, we don't want to redefine it.
if (function->empty() == false) { if (function->empty() == false) {
@@ -411,7 +411,7 @@ Function::GenerateIR() {
// it without a mask parameter and without name mangling so that // it without a mask parameter and without name mangling so that
// the application can call it // the application can call it
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
assert(type != NULL); Assert(type != NULL);
if (type->isExported) { if (type->isExported) {
if (!type->isTask) { if (!type->isTask) {
LLVM_TYPE_CONST llvm::FunctionType *ftype = LLVM_TYPE_CONST llvm::FunctionType *ftype =

View File

@@ -282,7 +282,7 @@ Target::GetTargetMachine() const {
#endif // !ISPC_IS_WINDOWS #endif // !ISPC_IS_WINDOWS
#endif // LLVM_2_9 #endif // LLVM_2_9
assert(targetMachine != NULL); Assert(targetMachine != NULL);
targetMachine->setAsmVerbosityDefault(true); targetMachine->setAsmVerbosityDefault(true);
return targetMachine; return targetMachine;
@@ -310,7 +310,7 @@ Target::GetISAString() const {
llvm::Value * llvm::Value *
Target::SizeOf(LLVM_TYPE_CONST llvm::Type *type) { Target::SizeOf(LLVM_TYPE_CONST llvm::Type *type) {
const llvm::TargetData *td = GetTargetMachine()->getTargetData(); const llvm::TargetData *td = GetTargetMachine()->getTargetData();
assert(td != NULL); Assert(td != NULL);
uint64_t byteSize = td->getTypeSizeInBits(type) / 8; uint64_t byteSize = td->getTypeSizeInBits(type) / 8;
if (is32Bit || g->opt.force32BitAddressing) if (is32Bit || g->opt.force32BitAddressing)
return LLVMInt32(byteSize); return LLVMInt32(byteSize);
@@ -322,12 +322,12 @@ Target::SizeOf(LLVM_TYPE_CONST llvm::Type *type) {
llvm::Value * llvm::Value *
Target::StructOffset(LLVM_TYPE_CONST llvm::Type *type, int element) { Target::StructOffset(LLVM_TYPE_CONST llvm::Type *type, int element) {
const llvm::TargetData *td = GetTargetMachine()->getTargetData(); const llvm::TargetData *td = GetTargetMachine()->getTargetData();
assert(td != NULL); Assert(td != NULL);
LLVM_TYPE_CONST llvm::StructType *structType = LLVM_TYPE_CONST llvm::StructType *structType =
llvm::dyn_cast<LLVM_TYPE_CONST llvm::StructType>(type); llvm::dyn_cast<LLVM_TYPE_CONST llvm::StructType>(type);
assert(structType != NULL); Assert(structType != NULL);
const llvm::StructLayout *sl = td->getStructLayout(structType); const llvm::StructLayout *sl = td->getStructLayout(structType);
assert(sl != NULL); Assert(sl != NULL);
uint64_t offset = sl->getElementOffset(element); uint64_t offset = sl->getElementOffset(element);
if (is32Bit || g->opt.force32BitAddressing) if (is32Bit || g->opt.force32BitAddressing)

14
ispc.h
View File

@@ -50,11 +50,21 @@
#define ISPC_IS_APPLE #define ISPC_IS_APPLE
#endif #endif
#include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <vector> #include <vector>
#include <string> #include <string>
#define Assert(expr) \
((void)((expr) ? 0 : __Assert (#expr, __FILE__, __LINE__)))
#define __Assert(expr, file, line) \
((void)fprintf(stderr, "%s:%u: Assertion failed: \"%s\"\n" \
"***\n*** Please file a bug report at " \
"https://github.com/ispc/ispc/issues\n*** (Including as much " \
"information as you can about how to reproduce this error).\n" \
"*** You have apparently encountered a bug in the compiler that " \
"we'd like to fix!\n***\n", file, line, expr), abort(), 0)
/** @def ISPC_MAX_NVEC maximum vector size of any of the compliation /** @def ISPC_MAX_NVEC maximum vector size of any of the compliation
targets. targets.
*/ */
@@ -247,7 +257,7 @@ struct Opt {
*/ */
bool force32BitAddressing; bool force32BitAddressing;
/** Indicates whether assert() statements should be ignored (for /** Indicates whether Assert() statements should be ignored (for
performance in the generated code). */ performance in the generated code). */
bool disableAsserts; bool disableAsserts;

20
lex.ll
View File

@@ -274,7 +274,7 @@ lParseBinary(const char *ptr, SourcePos pos) {
while (*ptr != '\0') { while (*ptr != '\0') {
/* if this hits, the regexp for 0b... constants is broken */ /* if this hits, the regexp for 0b... constants is broken */
assert(*ptr == '0' || *ptr == '1'); Assert(*ptr == '0' || *ptr == '1');
if ((val & (((int64_t)1)<<63)) && warned == false) { if ((val & (((int64_t)1)<<63)) && warned == false) {
// We're about to shift out a set bit // We're about to shift out a set bit
@@ -329,7 +329,7 @@ static void lHandleCppHash(SourcePos *pos) {
char *ptr, *src; char *ptr, *src;
// Advance past the opening stuff on the line. // Advance past the opening stuff on the line.
assert(yytext[0] == '#'); Assert(yytext[0] == '#');
if (yytext[1] == ' ') if (yytext[1] == ' ')
// On Linux/OSX, the preprocessor gives us lines like // On Linux/OSX, the preprocessor gives us lines like
// # 1234 "foo.c" // # 1234 "foo.c"
@@ -337,7 +337,7 @@ static void lHandleCppHash(SourcePos *pos) {
else { else {
// On windows, cl.exe's preprocessor gives us lines of the form: // On windows, cl.exe's preprocessor gives us lines of the form:
// #line 1234 "foo.c" // #line 1234 "foo.c"
assert(!strncmp(yytext+1, "line ", 5)); Assert(!strncmp(yytext+1, "line ", 5));
ptr = yytext + 6; ptr = yytext + 6;
} }
@@ -347,13 +347,13 @@ static void lHandleCppHash(SourcePos *pos) {
pos->last_column = 1; pos->last_column = 1;
// Make sure that the character after the integer is a space and that // Make sure that the character after the integer is a space and that
// then we have open quotes // then we have open quotes
assert(src != ptr && src[0] == ' ' && src[1] == '"'); Assert(src != ptr && src[0] == ' ' && src[1] == '"');
src += 2; src += 2;
// And the filename is everything up until the closing quotes // And the filename is everything up until the closing quotes
std::string filename; std::string filename;
while (*src != '"') { while (*src != '"') {
assert(*src && *src != '\n'); Assert(*src && *src != '\n');
filename.push_back(*src); filename.push_back(*src);
++src; ++src;
} }
@@ -454,13 +454,13 @@ ipow2(int exponent) {
*/ */
static double static double
lParseHexFloat(const char *ptr) { lParseHexFloat(const char *ptr) {
assert(ptr != NULL); Assert(ptr != NULL);
assert(ptr[0] == '0' && ptr[1] == 'x'); Assert(ptr[0] == '0' && ptr[1] == 'x');
ptr += 2; ptr += 2;
// Start initializing the mantissa // Start initializing the mantissa
assert(*ptr == '0' || *ptr == '1'); Assert(*ptr == '0' || *ptr == '1');
double mantissa = (*ptr == '1') ? 1. : 0.; double mantissa = (*ptr == '1') ? 1. : 0.;
++ptr; ++ptr;
@@ -480,7 +480,7 @@ lParseHexFloat(const char *ptr) {
else if (*ptr >= 'a' && *ptr <= 'f') else if (*ptr >= 'a' && *ptr <= 'f')
digit = 10 + *ptr - 'a'; digit = 10 + *ptr - 'a';
else { else {
assert(*ptr >= 'A' && *ptr <= 'F'); Assert(*ptr >= 'A' && *ptr <= 'F');
digit = 10 + *ptr - 'A'; digit = 10 + *ptr - 'A';
} }
@@ -493,7 +493,7 @@ lParseHexFloat(const char *ptr) {
else else
// If there's not a '.', then we better be going straight to the // If there's not a '.', then we better be going straight to the
// exponent // exponent
assert(*ptr == 'p'); Assert(*ptr == 'p');
++ptr; // skip the 'p' ++ptr; // skip the 'p'

View File

@@ -424,7 +424,7 @@ LLVMBoolVector(bool b) {
v = llvm::ConstantInt::get(LLVMTypes::Int32Type, b ? 0xffffffff : 0, v = llvm::ConstantInt::get(LLVMTypes::Int32Type, b ? 0xffffffff : 0,
false /*unsigned*/); false /*unsigned*/);
else { else {
assert(LLVMTypes::BoolVectorType->getElementType() == Assert(LLVMTypes::BoolVectorType->getElementType() ==
llvm::Type::getInt1Ty(*g->ctx)); llvm::Type::getInt1Ty(*g->ctx));
v = b ? LLVMTrue : LLVMFalse; v = b ? LLVMTrue : LLVMFalse;
} }
@@ -445,7 +445,7 @@ LLVMBoolVector(const bool *bvec) {
v = llvm::ConstantInt::get(LLVMTypes::Int32Type, bvec[i] ? 0xffffffff : 0, v = llvm::ConstantInt::get(LLVMTypes::Int32Type, bvec[i] ? 0xffffffff : 0,
false /*unsigned*/); false /*unsigned*/);
else { else {
assert(LLVMTypes::BoolVectorType->getElementType() == Assert(LLVMTypes::BoolVectorType->getElementType() ==
llvm::Type::getInt1Ty(*g->ctx)); llvm::Type::getInt1Ty(*g->ctx));
v = bvec[i] ? LLVMTrue : LLVMFalse; v = bvec[i] ? LLVMTrue : LLVMFalse;
} }

View File

@@ -167,10 +167,12 @@ int main(int Argc, char *Argv[]) {
char *argv[128]; char *argv[128];
lGetAllArgs(Argc, Argv, argc, argv); lGetAllArgs(Argc, Argv, argc, argv);
#if 0
// Use LLVM's little utility function to print out nice stack traces if // Use LLVM's little utility function to print out nice stack traces if
// we crash // we crash
llvm::sys::PrintStackTraceOnErrorSignal(); llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv); llvm::PrettyStackTraceProgram X(argc, argv);
#endif
// initialize available LLVM targets // initialize available LLVM targets
LLVMInitializeX86TargetInfo(); LLVMInitializeX86TargetInfo();

View File

@@ -49,7 +49,6 @@
#include "llvmutil.h" #include "llvmutil.h"
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
@@ -224,7 +223,7 @@ Module::AddGlobalVariable(Symbol *sym, Expr *initExpr, bool isConst) {
if (sym == NULL || sym->type == NULL) { if (sym == NULL || sym->type == NULL) {
// But if these are NULL and there haven't been any previous // But if these are NULL and there haven't been any previous
// errors, something surprising is going on // errors, something surprising is going on
assert(errorCount > 0); Assert(errorCount > 0);
return; return;
} }
@@ -391,7 +390,7 @@ void
Module::AddFunctionDeclaration(Symbol *funSym, bool isInline) { Module::AddFunctionDeclaration(Symbol *funSym, bool isInline) {
const FunctionType *functionType = const FunctionType *functionType =
dynamic_cast<const FunctionType *>(funSym->type); dynamic_cast<const FunctionType *>(funSym->type);
assert(functionType != NULL); Assert(functionType != NULL);
// If a global variable with the same name has already been declared // If a global variable with the same name has already been declared
// issue an error. // issue an error.
@@ -418,7 +417,7 @@ Module::AddFunctionDeclaration(Symbol *funSym, bool isInline) {
// allowed. // allowed.
const FunctionType *ofType = const FunctionType *ofType =
dynamic_cast<const FunctionType *>(overloadFunc->type); dynamic_cast<const FunctionType *>(overloadFunc->type);
assert(ofType != NULL); Assert(ofType != NULL);
if (ofType->GetNumParameters() == functionType->GetNumParameters()) { if (ofType->GetNumParameters() == functionType->GetNumParameters()) {
int i; int i;
for (i = 0; i < functionType->GetNumParameters(); ++i) { for (i = 0; i < functionType->GetNumParameters(); ++i) {
@@ -573,7 +572,7 @@ Module::AddFunctionDeclaration(Symbol *funSym, bool isInline) {
// Finally, we know all is good and we can add the function to the // Finally, we know all is good and we can add the function to the
// symbol table // symbol table
bool ok = symbolTable->AddFunction(funSym); bool ok = symbolTable->AddFunction(funSym);
assert(ok); Assert(ok);
} }
@@ -731,7 +730,7 @@ static void
lVisitNode(const StructType *structType, lVisitNode(const StructType *structType,
std::map<const StructType *, StructDAGNode *> &structToNode, std::map<const StructType *, StructDAGNode *> &structToNode,
std::vector<const StructType *> &sortedTypes) { std::vector<const StructType *> &sortedTypes) {
assert(structToNode.find(structType) != structToNode.end()); Assert(structToNode.find(structType) != structToNode.end());
// Get the node that encodes the structs that this one is immediately // Get the node that encodes the structs that this one is immediately
// dependent on. // dependent on.
StructDAGNode *node = structToNode[structType]; StructDAGNode *node = structToNode[structType];
@@ -795,7 +794,7 @@ lEmitStructDecls(std::vector<const StructType *> &structTypes, FILE *file) {
if (hasIncomingEdges.find(structType) == hasIncomingEdges.end()) if (hasIncomingEdges.find(structType) == hasIncomingEdges.end())
lVisitNode(structType, structToNode, sortedTypes); lVisitNode(structType, structToNode, sortedTypes);
} }
assert(sortedTypes.size() == structTypes.size()); Assert(sortedTypes.size() == structTypes.size());
// And finally we can emit the struct declarations by going through the // And finally we can emit the struct declarations by going through the
// sorted ones in order. // sorted ones in order.
@@ -830,10 +829,10 @@ lEmitEnumDecls(const std::vector<const EnumType *> &enumTypes, FILE *file) {
// Print the individual enumerators // Print the individual enumerators
for (int j = 0; j < enumTypes[i]->GetEnumeratorCount(); ++j) { for (int j = 0; j < enumTypes[i]->GetEnumeratorCount(); ++j) {
const Symbol *e = enumTypes[i]->GetEnumerator(j); const Symbol *e = enumTypes[i]->GetEnumerator(j);
assert(e->constValue != NULL); Assert(e->constValue != NULL);
unsigned int enumValue; unsigned int enumValue;
int count = e->constValue->AsUInt32(&enumValue); int count = e->constValue->AsUInt32(&enumValue);
assert(count == 1); Assert(count == 1);
// Always print an initializer to set the value. We could be // Always print an initializer to set the value. We could be
// 'clever' here and detect whether the implicit value given by // 'clever' here and detect whether the implicit value given by
@@ -899,7 +898,7 @@ lAddTypeIfNew(const Type *type, std::vector<const T *> *exportedTypes) {
return; return;
const T *castType = dynamic_cast<const T *>(type); const T *castType = dynamic_cast<const T *>(type);
assert(castType != NULL); Assert(castType != NULL);
exportedTypes->push_back(castType); exportedTypes->push_back(castType);
} }
@@ -936,7 +935,7 @@ lGetExportedTypes(const Type *type,
else if (dynamic_cast<const VectorType *>(type) != NULL) else if (dynamic_cast<const VectorType *>(type) != NULL)
lAddTypeIfNew(type, exportedVectorTypes); lAddTypeIfNew(type, exportedVectorTypes);
else else
assert(dynamic_cast<const AtomicType *>(type) != NULL); Assert(dynamic_cast<const AtomicType *>(type) != NULL);
} }
@@ -967,7 +966,7 @@ lPrintFunctionDeclarations(FILE *file, const std::vector<Symbol *> &funcs) {
fprintf(file, "#ifdef __cplusplus\nextern \"C\" {\n#endif // __cplusplus\n"); fprintf(file, "#ifdef __cplusplus\nextern \"C\" {\n#endif // __cplusplus\n");
for (unsigned int i = 0; i < funcs.size(); ++i) { for (unsigned int i = 0; i < funcs.size(); ++i) {
const FunctionType *ftype = dynamic_cast<const FunctionType *>(funcs[i]->type); const FunctionType *ftype = dynamic_cast<const FunctionType *>(funcs[i]->type);
assert(ftype); Assert(ftype);
std::string decl = ftype->GetCDeclaration(funcs[i]->name); std::string decl = ftype->GetCDeclaration(funcs[i]->name);
fprintf(file, " extern %s;\n", decl.c_str()); fprintf(file, " extern %s;\n", decl.c_str());
} }
@@ -992,7 +991,7 @@ lPrintExternGlobals(FILE *file, const std::vector<Symbol *> &externGlobals) {
static bool static bool
lIsExported(const Symbol *sym) { lIsExported(const Symbol *sym) {
const FunctionType *ft = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *ft = dynamic_cast<const FunctionType *>(sym->type);
assert(ft); Assert(ft);
return ft->isExported; return ft->isExported;
} }
@@ -1000,7 +999,7 @@ lIsExported(const Symbol *sym) {
static bool static bool
lIsExternC(const Symbol *sym) { lIsExternC(const Symbol *sym) {
const FunctionType *ft = dynamic_cast<const FunctionType *>(sym->type); const FunctionType *ft = dynamic_cast<const FunctionType *>(sym->type);
assert(ft); Assert(ft);
return ft->isExternC; return ft->isExternC;
} }
@@ -1186,9 +1185,9 @@ Module::execPreprocessor(const char* infilename, llvm::raw_string_ostream* ostre
if (g->includeStdlib) { if (g->includeStdlib) {
if (g->opt.disableAsserts) if (g->opt.disableAsserts)
opts.addMacroDef("assert(x)="); opts.addMacroDef("Assert(x)=");
else else
opts.addMacroDef("assert(x)=__assert(#x, x)"); opts.addMacroDef("Assert(x)=__Assert(#x, x)");
} }
for (unsigned int i = 0; i < g->cppArgs.size(); ++i) { for (unsigned int i = 0; i < g->cppArgs.size(); ++i) {
@@ -1327,7 +1326,7 @@ lExtractAndRewriteGlobals(llvm::Module *module,
Symbol *sym = Symbol *sym =
m->symbolTable->LookupVariable(gv->getName().str().c_str()); m->symbolTable->LookupVariable(gv->getName().str().c_str());
assert(sym != NULL); Assert(sym != NULL);
globals->push_back(RewriteGlobalInfo(gv, init, sym->pos)); globals->push_back(RewriteGlobalInfo(gv, init, sym->pos));
} }
} }
@@ -1376,9 +1375,9 @@ lAddExtractedGlobals(llvm::Module *module,
if (globals[j].size() > 0) { if (globals[j].size() > 0) {
// There should be the same number of globals in the other // There should be the same number of globals in the other
// vectors, in the same order. // vectors, in the same order.
assert(globals[firstActive].size() == globals[j].size()); Assert(globals[firstActive].size() == globals[j].size());
llvm::GlobalVariable *gv2 = globals[j][i].gv; llvm::GlobalVariable *gv2 = globals[j][i].gv;
assert(gv2->getName() == gv->getName()); Assert(gv2->getName() == gv->getName());
// It is possible that the types may not match, though--for // It is possible that the types may not match, though--for
// example, this happens with varying globals if we compile // example, this happens with varying globals if we compile
@@ -1432,7 +1431,7 @@ lCreateDispatchFunction(llvm::Module *module, llvm::Function *setISAFunc,
// Grab the type of the function as well. // Grab the type of the function as well.
if (ftype != NULL) if (ftype != NULL)
assert(ftype == funcs.func[i]->getFunctionType()); Assert(ftype == funcs.func[i]->getFunctionType());
else else
ftype = funcs.func[i]->getFunctionType(); ftype = funcs.func[i]->getFunctionType();
@@ -1520,7 +1519,7 @@ lCreateDispatchFunction(llvm::Module *module, llvm::Function *setISAFunc,
// or some such, but we don't want to start imposing too much of a // or some such, but we don't want to start imposing too much of a
// runtime library requirement either... // runtime library requirement either...
llvm::Function *abortFunc = module->getFunction("abort"); llvm::Function *abortFunc = module->getFunction("abort");
assert(abortFunc); Assert(abortFunc);
llvm::CallInst::Create(abortFunc, "", bblock); llvm::CallInst::Create(abortFunc, "", bblock);
// Return an undef value from the function here; we won't get to this // Return an undef value from the function here; we won't get to this
@@ -1552,10 +1551,10 @@ lCreateDispatchModule(std::map<std::string, FunctionTargetVariants> &functions)
// Get pointers to things we need below // Get pointers to things we need below
llvm::Function *setFunc = module->getFunction("__set_system_isa"); llvm::Function *setFunc = module->getFunction("__set_system_isa");
assert(setFunc != NULL); Assert(setFunc != NULL);
llvm::Value *systemBestISAPtr = llvm::Value *systemBestISAPtr =
module->getGlobalVariable("__system_best_isa", true); module->getGlobalVariable("__system_best_isa", true);
assert(systemBestISAPtr != NULL); Assert(systemBestISAPtr != NULL);
// For each exported function, create the dispatch function // For each exported function, create the dispatch function
std::map<std::string, FunctionTargetVariants>::iterator iter; std::map<std::string, FunctionTargetVariants>::iterator iter;
@@ -1601,7 +1600,7 @@ Module::CompileAndOutput(const char *srcFile, const char *arch, const char *cpu,
else { else {
// The user supplied multiple targets // The user supplied multiple targets
std::vector<std::string> targets = lExtractTargets(target); std::vector<std::string> targets = lExtractTargets(target);
assert(targets.size() > 1); Assert(targets.size() > 1);
if (outFileName != NULL && strcmp(outFileName, "-") == 0) { if (outFileName != NULL && strcmp(outFileName, "-") == 0) {
Error(SourcePos(), "Multi-target compilation can't generate output " Error(SourcePos(), "Multi-target compilation can't generate output "
@@ -1678,7 +1677,7 @@ Module::CompileAndOutput(const char *srcFile, const char *arch, const char *cpu,
int i = 1; int i = 1;
while (i < Target::NUM_ISAS && firstTargetMachine == NULL) while (i < Target::NUM_ISAS && firstTargetMachine == NULL)
firstTargetMachine = targetMachines[i++]; firstTargetMachine = targetMachines[i++];
assert(firstTargetMachine != NULL); Assert(firstTargetMachine != NULL);
if (outFileName != NULL) { if (outFileName != NULL) {
if (outputType == Bitcode) if (outputType == Bitcode)

62
opt.cpp
View File

@@ -152,19 +152,19 @@ lGetSourcePosFromMetadata(const llvm::Instruction *inst, SourcePos *pos) {
// All of these asserts are things that FunctionEmitContext::addGSMetadata() is // All of these asserts are things that FunctionEmitContext::addGSMetadata() is
// expected to have done in its operation // expected to have done in its operation
llvm::MDString *str = llvm::dyn_cast<llvm::MDString>(filename->getOperand(0)); llvm::MDString *str = llvm::dyn_cast<llvm::MDString>(filename->getOperand(0));
assert(str); Assert(str);
llvm::ConstantInt *first_lnum = llvm::ConstantInt *first_lnum =
llvm::dyn_cast<llvm::ConstantInt>(first_line->getOperand(0)); llvm::dyn_cast<llvm::ConstantInt>(first_line->getOperand(0));
assert(first_lnum); Assert(first_lnum);
llvm::ConstantInt *first_colnum = llvm::ConstantInt *first_colnum =
llvm::dyn_cast<llvm::ConstantInt>(first_column->getOperand(0)); llvm::dyn_cast<llvm::ConstantInt>(first_column->getOperand(0));
assert(first_column); Assert(first_column);
llvm::ConstantInt *last_lnum = llvm::ConstantInt *last_lnum =
llvm::dyn_cast<llvm::ConstantInt>(last_line->getOperand(0)); llvm::dyn_cast<llvm::ConstantInt>(last_line->getOperand(0));
assert(last_lnum); Assert(last_lnum);
llvm::ConstantInt *last_colnum = llvm::ConstantInt *last_colnum =
llvm::dyn_cast<llvm::ConstantInt>(last_column->getOperand(0)); llvm::dyn_cast<llvm::ConstantInt>(last_column->getOperand(0));
assert(last_column); Assert(last_column);
*pos = SourcePos(str->getString().data(), (int)first_lnum->getZExtValue(), *pos = SourcePos(str->getString().data(), (int)first_lnum->getZExtValue(),
(int)first_colnum->getZExtValue(), (int)last_lnum->getZExtValue(), (int)first_colnum->getZExtValue(), (int)last_lnum->getZExtValue(),
@@ -440,7 +440,7 @@ IntrinsicsOpt::IntrinsicsOpt()
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn) #if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
llvm::Function *avxMovmsk = llvm::Function *avxMovmsk =
llvm::Intrinsic::getDeclaration(m->module, llvm::Intrinsic::x86_avx_movmsk_ps_256); llvm::Intrinsic::getDeclaration(m->module, llvm::Intrinsic::x86_avx_movmsk_ps_256);
assert(avxMovmsk != NULL); Assert(avxMovmsk != NULL);
maskInstructions.push_back(avxMovmsk); maskInstructions.push_back(avxMovmsk);
#endif #endif
@@ -486,7 +486,7 @@ lGetMask(llvm::Value *factor) {
else { else {
// Otherwise get it as an int // Otherwise get it as an int
llvm::ConstantInt *ci = llvm::dyn_cast<llvm::ConstantInt>(elements[i]); llvm::ConstantInt *ci = llvm::dyn_cast<llvm::ConstantInt>(elements[i]);
assert(ci != NULL); // vs return -1 if NULL? Assert(ci != NULL); // vs return -1 if NULL?
intMaskValue = ci->getValue(); intMaskValue = ci->getValue();
} }
// Is the high-bit set? If so, OR in the appropriate bit in // Is the high-bit set? If so, OR in the appropriate bit in
@@ -509,7 +509,7 @@ lGetMask(llvm::Value *factor) {
factor = c; factor = c;
} }
// else we should be able to handle it above... // else we should be able to handle it above...
assert(!llvm::isa<llvm::Constant>(factor)); Assert(!llvm::isa<llvm::Constant>(factor));
#endif #endif
return -1; return -1;
} }
@@ -549,8 +549,8 @@ IntrinsicsOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
llvm::Intrinsic::getDeclaration(m->module, llvm::Intrinsic::x86_avx_maskstore_ps_256); llvm::Intrinsic::getDeclaration(m->module, llvm::Intrinsic::x86_avx_maskstore_ps_256);
llvm::Function *avxMaskedStore64 = llvm::Function *avxMaskedStore64 =
llvm::Intrinsic::getDeclaration(m->module, llvm::Intrinsic::x86_avx_maskstore_pd_256); llvm::Intrinsic::getDeclaration(m->module, llvm::Intrinsic::x86_avx_maskstore_pd_256);
assert(avxMaskedLoad32 != NULL && avxMaskedStore32 != NULL); Assert(avxMaskedLoad32 != NULL && avxMaskedStore32 != NULL);
assert(avxMaskedLoad64 != NULL && avxMaskedStore64 != NULL); Assert(avxMaskedLoad64 != NULL && avxMaskedStore64 != NULL);
#endif #endif
bool modifiedAny = false; bool modifiedAny = false;
@@ -631,7 +631,7 @@ IntrinsicsOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
if (mask == 0) { if (mask == 0) {
// nothing being loaded, replace with undef value // nothing being loaded, replace with undef value
llvm::Type *returnType = callInst->getType(); llvm::Type *returnType = callInst->getType();
assert(llvm::isa<llvm::VectorType>(returnType)); Assert(llvm::isa<llvm::VectorType>(returnType));
llvm::Value *undefValue = llvm::UndefValue::get(returnType); llvm::Value *undefValue = llvm::UndefValue::get(returnType);
llvm::ReplaceInstWithValue(iter->getParent()->getInstList(), llvm::ReplaceInstWithValue(iter->getParent()->getInstList(),
iter, undefValue); iter, undefValue);
@@ -641,7 +641,7 @@ IntrinsicsOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
else if (mask == 0xff) { else if (mask == 0xff) {
// all lanes active; replace with a regular load // all lanes active; replace with a regular load
llvm::Type *returnType = callInst->getType(); llvm::Type *returnType = callInst->getType();
assert(llvm::isa<llvm::VectorType>(returnType)); Assert(llvm::isa<llvm::VectorType>(returnType));
// cast the i8 * to the appropriate type // cast the i8 * to the appropriate type
llvm::Value *castPtr = llvm::Value *castPtr =
new llvm::BitCastInst(callInst->getArgOperand(0), new llvm::BitCastInst(callInst->getArgOperand(0),
@@ -755,7 +755,7 @@ llvm::RegisterPass<GatherScatterFlattenOpt> gsf("gs-flatten", "Gather/Scatter Fl
static int64_t static int64_t
lGetIntValue(llvm::Value *offset) { lGetIntValue(llvm::Value *offset) {
llvm::ConstantInt *intOffset = llvm::dyn_cast<llvm::ConstantInt>(offset); llvm::ConstantInt *intOffset = llvm::dyn_cast<llvm::ConstantInt>(offset);
assert(intOffset && (intOffset->getBitWidth() == 32 || Assert(intOffset && (intOffset->getBitWidth() == 32 ||
intOffset->getBitWidth() == 64)); intOffset->getBitWidth() == 64));
return intOffset->getSExtValue(); return intOffset->getSExtValue();
} }
@@ -780,15 +780,15 @@ lFlattenInsertChain(llvm::InsertElementInst *ie, int vectorWidth,
while (ie != NULL) { while (ie != NULL) {
int64_t iOffset = lGetIntValue(ie->getOperand(2)); int64_t iOffset = lGetIntValue(ie->getOperand(2));
assert(iOffset >= 0 && iOffset < vectorWidth); Assert(iOffset >= 0 && iOffset < vectorWidth);
assert(elements[iOffset] == NULL); Assert(elements[iOffset] == NULL);
elements[iOffset] = ie->getOperand(1); elements[iOffset] = ie->getOperand(1);
llvm::Value *insertBase = ie->getOperand(0); llvm::Value *insertBase = ie->getOperand(0);
ie = llvm::dyn_cast<llvm::InsertElementInst>(insertBase); ie = llvm::dyn_cast<llvm::InsertElementInst>(insertBase);
if (ie == NULL) if (ie == NULL)
assert(llvm::isa<llvm::UndefValue>(insertBase)); Assert(llvm::isa<llvm::UndefValue>(insertBase));
} }
} }
@@ -954,7 +954,7 @@ lGetBasePtrAndOffsets(llvm::Value *ptrs, llvm::Value **offsets) {
if (elementBase == NULL) if (elementBase == NULL)
return NULL; return NULL;
assert(delta[i] != NULL); Assert(delta[i] != NULL);
if (base == NULL) if (base == NULL)
// The first time we've found a base pointer // The first time we've found a base pointer
base = elementBase; base = elementBase;
@@ -964,7 +964,7 @@ lGetBasePtrAndOffsets(llvm::Value *ptrs, llvm::Value **offsets) {
return NULL; return NULL;
} }
assert(base != NULL); Assert(base != NULL);
#ifdef LLVM_2_9 #ifdef LLVM_2_9
*offsets = llvm::ConstantVector::get(delta); *offsets = llvm::ConstantVector::get(delta);
#else #else
@@ -1031,7 +1031,7 @@ GatherScatterFlattenOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
}; };
int numGSFuncs = sizeof(gsFuncs) / sizeof(gsFuncs[0]); int numGSFuncs = sizeof(gsFuncs) / sizeof(gsFuncs[0]);
for (int i = 0; i < numGSFuncs; ++i) for (int i = 0; i < numGSFuncs; ++i)
assert(gsFuncs[i].func != NULL && gsFuncs[i].baseOffsetsFunc != NULL && Assert(gsFuncs[i].func != NULL && gsFuncs[i].baseOffsetsFunc != NULL &&
gsFuncs[i].baseOffsets32Func != NULL); gsFuncs[i].baseOffsets32Func != NULL);
bool modifiedAny = false; bool modifiedAny = false;
@@ -1177,7 +1177,7 @@ struct MSInfo {
MSInfo(const char *name, const int a) MSInfo(const char *name, const int a)
: align(a) { : align(a) {
func = m->module->getFunction(name); func = m->module->getFunction(name);
assert(func != NULL); Assert(func != NULL);
} }
llvm::Function *func; llvm::Function *func;
const int align; const int align;
@@ -1321,7 +1321,7 @@ struct LMSInfo {
pseudoFunc = m->module->getFunction(pname); pseudoFunc = m->module->getFunction(pname);
blendFunc = m->module->getFunction(bname); blendFunc = m->module->getFunction(bname);
maskedStoreFunc = m->module->getFunction(msname); maskedStoreFunc = m->module->getFunction(msname);
assert(pseudoFunc != NULL && blendFunc != NULL && Assert(pseudoFunc != NULL && blendFunc != NULL &&
maskedStoreFunc != NULL); maskedStoreFunc != NULL);
} }
llvm::Function *pseudoFunc; llvm::Function *pseudoFunc;
@@ -1455,7 +1455,7 @@ lValuesAreEqual(llvm::Value *v0, llvm::Value *v1,
if (v0 == v1) if (v0 == v1)
return true; return true;
assert(seenPhi0.size() == seenPhi1.size()); Assert(seenPhi0.size() == seenPhi1.size());
for (unsigned int i = 0; i < seenPhi0.size(); ++i) for (unsigned int i = 0; i < seenPhi0.size(); ++i)
if (v0 == seenPhi0[i] && v1 == seenPhi1[i]) if (v0 == seenPhi0[i] && v1 == seenPhi1[i])
return true; return true;
@@ -1485,7 +1485,7 @@ lValuesAreEqual(llvm::Value *v0, llvm::Value *v1,
// then we're good. // then we're good.
bool anyFailure = false; bool anyFailure = false;
for (unsigned int i = 0; i < numIncoming; ++i) { for (unsigned int i = 0; i < numIncoming; ++i) {
assert(phi0->getIncomingBlock(i) == phi1->getIncomingBlock(i)); Assert(phi0->getIncomingBlock(i) == phi1->getIncomingBlock(i));
if (!lValuesAreEqual(phi0->getIncomingValue(i), if (!lValuesAreEqual(phi0->getIncomingValue(i),
phi1->getIncomingValue(i), seenPhi0, seenPhi1)) { phi1->getIncomingValue(i), seenPhi0, seenPhi1)) {
anyFailure = true; anyFailure = true;
@@ -1539,7 +1539,7 @@ lVectorValuesAllEqual(llvm::Value *v, int vectorLength,
// probably to just ignore undef elements and return true if // probably to just ignore undef elements and return true if
// all of the other ones are equal, but it'd be nice to have // all of the other ones are equal, but it'd be nice to have
// some test cases to verify this. // some test cases to verify this.
assert(elements[i] != NULL && elements[i+1] != NULL); Assert(elements[i] != NULL && elements[i+1] != NULL);
std::vector<llvm::PHINode *> seenPhi0; std::vector<llvm::PHINode *> seenPhi0;
std::vector<llvm::PHINode *> seenPhi1; std::vector<llvm::PHINode *> seenPhi1;
@@ -1573,7 +1573,7 @@ lVectorValuesAllEqual(llvm::Value *v, int vectorLength,
return true; return true;
} }
assert(!llvm::isa<llvm::Constant>(v)); Assert(!llvm::isa<llvm::Constant>(v));
if (llvm::isa<llvm::CallInst>(v) || llvm::isa<llvm::LoadInst>(v) || if (llvm::isa<llvm::CallInst>(v) || llvm::isa<llvm::LoadInst>(v) ||
!llvm::isa<llvm::Instruction>(v)) !llvm::isa<llvm::Instruction>(v))
@@ -1618,7 +1618,7 @@ lVectorIsLinearConstantInts(llvm::ConstantVector *cv, int vectorLength,
// Flatten the vector out into the elements array // Flatten the vector out into the elements array
llvm::SmallVector<llvm::Constant *, ISPC_MAX_NVEC> elements; llvm::SmallVector<llvm::Constant *, ISPC_MAX_NVEC> elements;
cv->getVectorElements(elements); cv->getVectorElements(elements);
assert((int)elements.size() == vectorLength); Assert((int)elements.size() == vectorLength);
llvm::ConstantInt *ci = llvm::dyn_cast<llvm::ConstantInt>(elements[0]); llvm::ConstantInt *ci = llvm::dyn_cast<llvm::ConstantInt>(elements[0]);
if (ci == NULL) if (ci == NULL)
@@ -1792,7 +1792,7 @@ struct GatherImpInfo {
loadBroadcastFunc = m->module->getFunction(lbName); loadBroadcastFunc = m->module->getFunction(lbName);
loadMaskedFunc = m->module->getFunction(lmName); loadMaskedFunc = m->module->getFunction(lmName);
assert(pseudoFunc != NULL && loadBroadcastFunc != NULL && Assert(pseudoFunc != NULL && loadBroadcastFunc != NULL &&
loadMaskedFunc != NULL); loadMaskedFunc != NULL);
} }
llvm::Function *pseudoFunc; llvm::Function *pseudoFunc;
@@ -1809,7 +1809,7 @@ struct ScatterImpInfo {
pseudoFunc = m->module->getFunction(pName); pseudoFunc = m->module->getFunction(pName);
maskedStoreFunc = m->module->getFunction(msName); maskedStoreFunc = m->module->getFunction(msName);
vecPtrType = vpt; vecPtrType = vpt;
assert(pseudoFunc != NULL && maskedStoreFunc != NULL); Assert(pseudoFunc != NULL && maskedStoreFunc != NULL);
} }
llvm::Function *pseudoFunc; llvm::Function *pseudoFunc;
llvm::Function *maskedStoreFunc; llvm::Function *maskedStoreFunc;
@@ -1888,7 +1888,7 @@ GSImprovementsPass::runOnBasicBlock(llvm::BasicBlock &bb) {
SourcePos pos; SourcePos pos;
bool ok = lGetSourcePosFromMetadata(callInst, &pos); bool ok = lGetSourcePosFromMetadata(callInst, &pos);
assert(ok); Assert(ok);
llvm::Value *base = callInst->getArgOperand(0); llvm::Value *base = callInst->getArgOperand(0);
llvm::Value *offsets = callInst->getArgOperand(1); llvm::Value *offsets = callInst->getArgOperand(1);
@@ -2066,7 +2066,7 @@ struct LowerGSInfo {
: isGather(ig) { : isGather(ig) {
pseudoFunc = m->module->getFunction(pName); pseudoFunc = m->module->getFunction(pName);
actualFunc = m->module->getFunction(aName); actualFunc = m->module->getFunction(aName);
assert(pseudoFunc != NULL && actualFunc != NULL); Assert(pseudoFunc != NULL && actualFunc != NULL);
} }
llvm::Function *pseudoFunc; llvm::Function *pseudoFunc;
llvm::Function *actualFunc; llvm::Function *actualFunc;
@@ -2143,7 +2143,7 @@ LowerGSPass::runOnBasicBlock(llvm::BasicBlock &bb) {
// instruction so that we can issue PerformanceWarning()s below. // instruction so that we can issue PerformanceWarning()s below.
SourcePos pos; SourcePos pos;
bool ok = lGetSourcePosFromMetadata(callInst, &pos); bool ok = lGetSourcePosFromMetadata(callInst, &pos);
assert(ok); Assert(ok);
callInst->setCalledFunction(info->actualFunc); callInst->setCalledFunction(info->actualFunc);
if (info->isGather) if (info->isGather)

View File

@@ -327,7 +327,7 @@ argument_expression_list
| argument_expression_list ',' assignment_expression | argument_expression_list ',' assignment_expression
{ {
ExprList *argList = dynamic_cast<ExprList *>($1); ExprList *argList = dynamic_cast<ExprList *>($1);
assert(argList != NULL); Assert(argList != NULL);
argList->exprs.push_back($3); argList->exprs.push_back($3);
argList->pos = Union(argList->pos, @3); argList->pos = Union(argList->pos, @3);
$$ = argList; $$ = argList;
@@ -629,7 +629,7 @@ type_specifier
: atomic_var_type_specifier { $$ = $1; } : atomic_var_type_specifier { $$ = $1; }
| TOKEN_TYPE_NAME | TOKEN_TYPE_NAME
{ const Type *t = m->symbolTable->LookupType(yytext); { const Type *t = m->symbolTable->LookupType(yytext);
assert(t != NULL); Assert(t != NULL);
$$ = t; $$ = t;
} }
| struct_or_union_specifier { $$ = $1; } | struct_or_union_specifier { $$ = $1; }
@@ -1223,7 +1223,7 @@ initializer_list
$$ = NULL; $$ = NULL;
else { else {
ExprList *exprList = dynamic_cast<ExprList *>($1); ExprList *exprList = dynamic_cast<ExprList *>($1);
assert(exprList); Assert(exprList);
exprList->exprs.push_back($3); exprList->exprs.push_back($3);
exprList->pos = Union(exprList->pos, @3); exprList->pos = Union(exprList->pos, @3);
$$ = exprList; $$ = exprList;
@@ -1554,7 +1554,7 @@ lAddDeclaration(DeclSpecs *ds, Declarator *decl) {
const FunctionType *ft = dynamic_cast<const FunctionType *>(t); const FunctionType *ft = dynamic_cast<const FunctionType *>(t);
if (ft != NULL) { if (ft != NULL) {
Symbol *funSym = decl->GetSymbol(); Symbol *funSym = decl->GetSymbol();
assert(funSym != NULL); Assert(funSym != NULL);
funSym->type = ft; funSym->type = ft;
funSym->storageClass = ds->storageClass; funSym->storageClass = ds->storageClass;
@@ -1578,7 +1578,7 @@ lAddFunctionParams(Declarator *decl) {
// walk down to the declarator for the function itself // walk down to the declarator for the function itself
while (decl->kind != DK_FUNCTION && decl->child != NULL) while (decl->kind != DK_FUNCTION && decl->child != NULL)
decl = decl->child; decl = decl->child;
assert(decl->kind == DK_FUNCTION); Assert(decl->kind == DK_FUNCTION);
// now loop over its parameters and add them to the symbol table // now loop over its parameters and add them to the symbol table
for (unsigned int i = 0; i < decl->functionParams.size(); ++i) { for (unsigned int i = 0; i < decl->functionParams.size(); ++i) {
@@ -1587,12 +1587,12 @@ lAddFunctionParams(Declarator *decl) {
// zero size declarators array corresponds to an anonymous // zero size declarators array corresponds to an anonymous
// parameter // parameter
continue; continue;
assert(pdecl->declarators.size() == 1); Assert(pdecl->declarators.size() == 1);
Symbol *sym = pdecl->declarators[0]->GetSymbol(); Symbol *sym = pdecl->declarators[0]->GetSymbol();
#ifndef NDEBUG #ifndef NDEBUG
bool ok = m->symbolTable->AddVariable(sym); bool ok = m->symbolTable->AddVariable(sym);
if (ok == false) if (ok == false)
assert(m->errorCount > 0); Assert(m->errorCount > 0);
#else #else
m->symbolTable->AddVariable(sym); m->symbolTable->AddVariable(sym);
#endif #endif
@@ -1659,7 +1659,7 @@ lGetStorageClassString(StorageClass sc) {
case SC_EXTERN_C: case SC_EXTERN_C:
return "extern \"C\""; return "extern \"C\"";
default: default:
assert(!"logic error in lGetStorageClassString()"); Assert(!"logic error in lGetStorageClassString()");
return ""; return "";
} }
} }
@@ -1743,7 +1743,7 @@ lFinalizeEnumeratorSymbols(std::vector<Symbol *> &enums,
if (enums[i]->constValue != NULL) { if (enums[i]->constValue != NULL) {
/* Already has a value, so first update nextVal with it. */ /* Already has a value, so first update nextVal with it. */
int count = enums[i]->constValue->AsUInt32(&nextVal); int count = enums[i]->constValue->AsUInt32(&nextVal);
assert(count == 1); Assert(count == 1);
++nextVal; ++nextVal;
/* When the source file as being parsed, the ConstExpr for any /* When the source file as being parsed, the ConstExpr for any
@@ -1756,7 +1756,7 @@ lFinalizeEnumeratorSymbols(std::vector<Symbol *> &enums,
false, enums[i]->pos); false, enums[i]->pos);
castExpr = castExpr->Optimize(); castExpr = castExpr->Optimize();
enums[i]->constValue = dynamic_cast<ConstExpr *>(castExpr); enums[i]->constValue = dynamic_cast<ConstExpr *>(castExpr);
assert(enums[i]->constValue != NULL); Assert(enums[i]->constValue != NULL);
} }
else { else {
enums[i]->constValue = new ConstExpr(enumType, nextVal++, enums[i]->constValue = new ConstExpr(enumType, nextVal++,

View File

@@ -287,7 +287,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
for (unsigned int i = 0; i < vars.size(); ++i) { for (unsigned int i = 0; i < vars.size(); ++i) {
Symbol *sym = vars[i].sym; Symbol *sym = vars[i].sym;
assert(sym != NULL); Assert(sym != NULL);
if (sym->type == NULL) if (sym->type == NULL)
continue; continue;
Expr *initExpr = vars[i].init; Expr *initExpr = vars[i].init;
@@ -324,7 +324,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
LLVM_TYPE_CONST llvm::Type *llvmType = sym->type->LLVMType(g->ctx); LLVM_TYPE_CONST llvm::Type *llvmType = sym->type->LLVMType(g->ctx);
if (llvmType == NULL) { if (llvmType == NULL) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return; return;
} }
@@ -645,12 +645,12 @@ IfStmt::emitMaskedTrueAndFalse(FunctionEmitContext *ctx, llvm::Value *oldMask,
lEmitIfStatements(ctx, trueStmts, "if: expr mixed, true statements"); lEmitIfStatements(ctx, trueStmts, "if: expr mixed, true statements");
// under varying control flow,, returns can't stop instruction // under varying control flow,, returns can't stop instruction
// emission, so this better be non-NULL... // emission, so this better be non-NULL...
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
} }
if (falseStmts) { if (falseStmts) {
ctx->SetInternalMaskAndNot(oldMask, test); ctx->SetInternalMaskAndNot(oldMask, test);
lEmitIfStatements(ctx, falseStmts, "if: expr mixed, false statements"); lEmitIfStatements(ctx, falseStmts, "if: expr mixed, false statements");
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
} }
} }
@@ -724,7 +724,7 @@ lSafeToRunWithAllLanesOff(Expr *expr) {
const SequentialType *seqType = const SequentialType *seqType =
dynamic_cast<const SequentialType *>(type); dynamic_cast<const SequentialType *>(type);
assert(seqType != NULL); Assert(seqType != NULL);
int nElements = seqType->GetElementCount(); int nElements = seqType->GetElementCount();
if (nElements == 0) if (nElements == 0)
// Unsized array, so we can't be sure // Unsized array, so we can't be sure
@@ -930,7 +930,7 @@ IfStmt::emitVaryingIf(FunctionEmitContext *ctx, llvm::Value *ltest) const {
(costIsAcceptable || g->opt.disableCoherentControlFlow)) { (costIsAcceptable || g->opt.disableCoherentControlFlow)) {
ctx->StartVaryingIf(oldMask); ctx->StartVaryingIf(oldMask);
emitMaskedTrueAndFalse(ctx, oldMask, ltest); emitMaskedTrueAndFalse(ctx, oldMask, ltest);
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->EndIf(); ctx->EndIf();
} }
else { else {
@@ -953,7 +953,7 @@ IfStmt::emitMaskAllOn(FunctionEmitContext *ctx, llvm::Value *ltest,
// compiler see what's going on so that subsequent optimizations for // compiler see what's going on so that subsequent optimizations for
// code emitted here can operate with the knowledge that the mask is // code emitted here can operate with the knowledge that the mask is
// definitely all on (until it modifies the mask itself). // definitely all on (until it modifies the mask itself).
assert(!g->opt.disableCoherentControlFlow); Assert(!g->opt.disableCoherentControlFlow);
if (!g->opt.disableMaskAllOnOptimizations) if (!g->opt.disableMaskAllOnOptimizations)
ctx->SetInternalMask(LLVMMaskAllOn); ctx->SetInternalMask(LLVMMaskAllOn);
llvm::Value *oldFunctionMask = ctx->GetFunctionMask(); llvm::Value *oldFunctionMask = ctx->GetFunctionMask();
@@ -1003,7 +1003,7 @@ IfStmt::emitMaskAllOn(FunctionEmitContext *ctx, llvm::Value *ltest,
emitMaskedTrueAndFalse(ctx, LLVMMaskAllOn, ltest); emitMaskedTrueAndFalse(ctx, LLVMMaskAllOn, ltest);
// In this case, return/break/continue isn't allowed to jump and end // In this case, return/break/continue isn't allowed to jump and end
// emission. // emission.
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->EndIf(); ctx->EndIf();
ctx->BranchInst(bDone); ctx->BranchInst(bDone);
@@ -1032,7 +1032,7 @@ IfStmt::emitMaskMixed(FunctionEmitContext *ctx, llvm::Value *oldMask,
// Emit statements for true // Emit statements for true
ctx->SetCurrentBasicBlock(bRunTrue); ctx->SetCurrentBasicBlock(bRunTrue);
lEmitIfStatements(ctx, trueStmts, "if: expr mixed, true statements"); lEmitIfStatements(ctx, trueStmts, "if: expr mixed, true statements");
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->BranchInst(bNext); ctx->BranchInst(bNext);
ctx->SetCurrentBasicBlock(bNext); ctx->SetCurrentBasicBlock(bNext);
} }
@@ -1049,7 +1049,7 @@ IfStmt::emitMaskMixed(FunctionEmitContext *ctx, llvm::Value *oldMask,
// Emit code for false // Emit code for false
ctx->SetCurrentBasicBlock(bRunFalse); ctx->SetCurrentBasicBlock(bRunFalse);
lEmitIfStatements(ctx, falseStmts, "if: expr mixed, false statements"); lEmitIfStatements(ctx, falseStmts, "if: expr mixed, false statements");
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->BranchInst(bNext); ctx->BranchInst(bNext);
ctx->SetCurrentBasicBlock(bNext); ctx->SetCurrentBasicBlock(bNext);
} }
@@ -1167,7 +1167,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->SetFunctionMask(LLVMMaskAllOn); ctx->SetFunctionMask(LLVMMaskAllOn);
if (bodyStmts) if (bodyStmts)
bodyStmts->EmitCode(ctx); bodyStmts->EmitCode(ctx);
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->SetFunctionMask(oldFunctionMask); ctx->SetFunctionMask(oldFunctionMask);
ctx->BranchInst(btest); ctx->BranchInst(btest);
@@ -1175,7 +1175,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->SetCurrentBasicBlock(bMixed); ctx->SetCurrentBasicBlock(bMixed);
if (bodyStmts) if (bodyStmts)
bodyStmts->EmitCode(ctx); bodyStmts->EmitCode(ctx);
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->BranchInst(btest); ctx->BranchInst(btest);
} }
else { else {
@@ -1328,7 +1328,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const {
// it and then jump into the loop test code. (Also start a new scope // it and then jump into the loop test code. (Also start a new scope
// since the initiailizer may be a declaration statement). // since the initiailizer may be a declaration statement).
if (init) { if (init) {
assert(dynamic_cast<StmtList *>(init) == NULL); Assert(dynamic_cast<StmtList *>(init) == NULL);
ctx->StartScope(); ctx->StartScope();
init->EmitCode(ctx); init->EmitCode(ctx);
} }
@@ -1356,7 +1356,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const {
if (uniformTest) { if (uniformTest) {
if (doCoherentCheck) if (doCoherentCheck)
Warning(pos, "Uniform condition supplied to cfor/cwhile statement."); Warning(pos, "Uniform condition supplied to cfor/cwhile statement.");
assert(ltest->getType() == LLVMTypes::BoolType); Assert(ltest->getType() == LLVMTypes::BoolType);
ctx->BranchInst(bloop, bexit, ltest); ctx->BranchInst(bloop, bexit, ltest);
} }
else { else {
@@ -1392,7 +1392,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->SetFunctionMask(LLVMMaskAllOn); ctx->SetFunctionMask(LLVMMaskAllOn);
if (stmts) if (stmts)
stmts->EmitCode(ctx); stmts->EmitCode(ctx);
assert(ctx->GetCurrentBasicBlock()); Assert(ctx->GetCurrentBasicBlock());
ctx->SetFunctionMask(oldFunctionMask); ctx->SetFunctionMask(oldFunctionMask);
ctx->BranchInst(bstep); ctx->BranchInst(bstep);
@@ -1741,7 +1741,7 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->StartScope(); ctx->StartScope();
// This should be caught during typechecking // This should be caught during typechecking
assert(startExprs.size() == dimVariables.size() && Assert(startExprs.size() == dimVariables.size() &&
endExprs.size() == dimVariables.size()); endExprs.size() == dimVariables.size());
int nDims = (int)dimVariables.size(); int nDims = (int)dimVariables.size();
@@ -1923,7 +1923,7 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->SetInternalMask(LLVMMaskAllOn); ctx->SetInternalMask(LLVMMaskAllOn);
ctx->AddInstrumentationPoint("foreach loop body"); ctx->AddInstrumentationPoint("foreach loop body");
stmts->EmitCode(ctx); stmts->EmitCode(ctx);
assert(ctx->GetCurrentBasicBlock() != NULL); Assert(ctx->GetCurrentBasicBlock() != NULL);
ctx->BranchInst(bbStep[nDims-1]); ctx->BranchInst(bbStep[nDims-1]);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@@ -2351,7 +2351,7 @@ PrintStmt::EmitCode(FunctionEmitContext *ctx) const {
// Now we can emit code to call __do_print() // Now we can emit code to call __do_print()
llvm::Function *printFunc = m->module->getFunction("__do_print"); llvm::Function *printFunc = m->module->getFunction("__do_print");
assert(printFunc); Assert(printFunc);
llvm::Value *mask = ctx->GetFullMask(); llvm::Value *mask = ctx->GetFullMask();
// Set up the rest of the parameters to it // Set up the rest of the parameters to it
@@ -2414,7 +2414,7 @@ AssertStmt::EmitCode(FunctionEmitContext *ctx) const {
llvm::Function *assertFunc = llvm::Function *assertFunc =
isUniform ? m->module->getFunction("__do_assert_uniform") : isUniform ? m->module->getFunction("__do_assert_uniform") :
m->module->getFunction("__do_assert_varying"); m->module->getFunction("__do_assert_varying");
assert(assertFunc != NULL); Assert(assertFunc != NULL);
#ifdef ISPC_IS_WINDOWS #ifdef ISPC_IS_WINDOWS
char errorString[2048]; char errorString[2048];

2
stmt.h
View File

@@ -341,7 +341,7 @@ public:
Like print() above, since we don't have strings as first-class types in Like print() above, since we don't have strings as first-class types in
the language, we need to do some gymnastics to support it. Like the language, we need to do some gymnastics to support it. Like
assert() in C, assert checks the given condition and prints an error assert() in C, assert() checks the given condition and prints an error
and calls abort if the condition fails. For varying conditions, the and calls abort if the condition fails. For varying conditions, the
assert triggers if it's true for any of the program instances. assert triggers if it's true for any of the program instances.
*/ */

12
sym.cpp
View File

@@ -72,7 +72,7 @@ SymbolTable::SymbolTable() {
SymbolTable::~SymbolTable() { SymbolTable::~SymbolTable() {
// Otherwise we have mismatched push/pop scopes // Otherwise we have mismatched push/pop scopes
assert(variables.size() == 1 && functions.size() == 1 && Assert(variables.size() == 1 && functions.size() == 1 &&
types.size() == 1); types.size() == 1);
PopScope(); PopScope();
} }
@@ -88,15 +88,15 @@ SymbolTable::PushScope() {
void void
SymbolTable::PopScope() { SymbolTable::PopScope() {
assert(variables.size() > 1); Assert(variables.size() > 1);
delete variables.back(); delete variables.back();
variables.pop_back(); variables.pop_back();
assert(functions.size() > 1); Assert(functions.size() > 1);
delete functions.back(); delete functions.back();
functions.pop_back(); functions.pop_back();
assert(types.size() > 1); Assert(types.size() > 1);
delete types.back(); delete types.back();
types.pop_back(); types.pop_back();
} }
@@ -104,7 +104,7 @@ SymbolTable::PopScope() {
bool bool
SymbolTable::AddVariable(Symbol *symbol) { SymbolTable::AddVariable(Symbol *symbol) {
assert(symbol != NULL); Assert(symbol != NULL);
// Check to see if a symbol of the same name has already been declared. // Check to see if a symbol of the same name has already been declared.
for (int i = (int)variables.size() - 1; i >= 0; --i) { for (int i = (int)variables.size() - 1; i >= 0; --i) {
@@ -154,7 +154,7 @@ SymbolTable::LookupVariable(const char *name) {
bool bool
SymbolTable::AddFunction(Symbol *symbol) { SymbolTable::AddFunction(Symbol *symbol) {
const FunctionType *ft = dynamic_cast<const FunctionType *>(symbol->type); const FunctionType *ft = dynamic_cast<const FunctionType *>(symbol->type);
assert(ft != NULL); Assert(ft != NULL);
if (LookupFunction(symbol->name.c_str(), ft) != NULL) if (LookupFunction(symbol->name.c_str(), ft) != NULL)
// A function of the same name and type has already been added to // A function of the same name and type has already been added to
// the symbol table // the symbol table

View File

@@ -102,7 +102,7 @@ void *ISPCAlloc(void **handle, int64_t size, int32_t alignment) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int w = width(); int w = width();
assert(w <= 16); Assert(w <= 16);
float returned_result[16]; float returned_result[16];
for (int i = 0; i < 16; ++i) for (int i = 0; i < 16; ++i)

View File

@@ -293,7 +293,7 @@ AtomicType::GetAsUniformType() const {
const Type * const Type *
AtomicType::GetSOAType(int width) const { AtomicType::GetSOAType(int width) const {
assert(width > 0); Assert(width > 0);
return new ArrayType(this, width); return new ArrayType(this, width);
} }
@@ -354,7 +354,7 @@ std::string
AtomicType::GetCDeclaration(const std::string &name) const { AtomicType::GetCDeclaration(const std::string &name) const {
std::string ret; std::string ret;
if (isUniform == false) { if (isUniform == false) {
assert(m->errorCount > 0); Assert(m->errorCount > 0);
return ret; return ret;
} }
if (isConst) ret += "const "; if (isConst) ret += "const ";
@@ -570,7 +570,7 @@ EnumType::GetAsUniformType() const {
const Type * const Type *
EnumType::GetSOAType(int width) const { EnumType::GetSOAType(int width) const {
assert(width > 0); Assert(width > 0);
return new ArrayType(this, width); return new ArrayType(this, width);
} }
@@ -644,9 +644,9 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
std::vector<llvm::Value *> enumeratorDescriptors; std::vector<llvm::Value *> enumeratorDescriptors;
for (unsigned int i = 0; i < enumerators.size(); ++i) { for (unsigned int i = 0; i < enumerators.size(); ++i) {
unsigned int enumeratorValue; unsigned int enumeratorValue;
assert(enumerators[i]->constValue != NULL); Assert(enumerators[i]->constValue != NULL);
int count = enumerators[i]->constValue->AsUInt32(&enumeratorValue); int count = enumerators[i]->constValue->AsUInt32(&enumeratorValue);
assert(count == 1); Assert(count == 1);
llvm::Value *descriptor = llvm::Value *descriptor =
m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue); m->diBuilder->createEnumerator(enumerators[i]->name, enumeratorValue);
@@ -938,7 +938,7 @@ const Type *SequentialType::GetElementType(int index) const {
ArrayType::ArrayType(const Type *c, int a) ArrayType::ArrayType(const Type *c, int a)
: child(c), numElements(a) { : child(c), numElements(a) {
// 0 -> unsized array. // 0 -> unsized array.
assert(numElements >= 0); Assert(numElements >= 0);
} }
@@ -1137,7 +1137,7 @@ ArrayType::GetDIType(llvm::DIDescriptor scope) const {
ArrayType * ArrayType *
ArrayType::GetSizedArray(int sz) const { ArrayType::GetSizedArray(int sz) const {
assert(numElements == 0); Assert(numElements == 0);
return new ArrayType(child, sz); return new ArrayType(child, sz);
} }
@@ -1178,7 +1178,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) {
for (unsigned int i = 1; i < exprList->exprs.size(); ++i) { for (unsigned int i = 1; i < exprList->exprs.size(); ++i) {
if (exprList->exprs[i] == NULL) { if (exprList->exprs[i] == NULL) {
// We should have seen an error earlier in this case. // We should have seen an error earlier in this case.
assert(m->errorCount > 0); Assert(m->errorCount > 0);
continue; continue;
} }
@@ -1204,9 +1204,9 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) {
SOAArrayType::SOAArrayType(const StructType *eltType, int nElem, int sw) SOAArrayType::SOAArrayType(const StructType *eltType, int nElem, int sw)
: ArrayType(eltType, nElem), soaWidth(sw) { : ArrayType(eltType, nElem), soaWidth(sw) {
assert(soaWidth > 0); Assert(soaWidth > 0);
if (numElements > 0) if (numElements > 0)
assert((numElements % soaWidth) == 0); Assert((numElements % soaWidth) == 0);
} }
@@ -1337,8 +1337,8 @@ SOAArrayType::soaType() const {
VectorType::VectorType(const AtomicType *b, int a) VectorType::VectorType(const AtomicType *b, int a)
: base(b), numElements(a) { : base(b), numElements(a) {
assert(numElements > 0); Assert(numElements > 0);
assert(base != NULL); Assert(base != NULL);
} }
@@ -1719,7 +1719,7 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
// element starts at an offset that's the correct alignment. // element starts at an offset that's the correct alignment.
if (currentSize > 0 && (currentSize % eltAlign)) if (currentSize > 0 && (currentSize % eltAlign))
currentSize += eltAlign - (currentSize % eltAlign); currentSize += eltAlign - (currentSize % eltAlign);
assert((currentSize == 0) || (currentSize % eltAlign) == 0); Assert((currentSize == 0) || (currentSize % eltAlign) == 0);
llvm::DIFile diFile = elementPositions[i].GetDIFile(); llvm::DIFile diFile = elementPositions[i].GetDIFile();
int line = elementPositions[i].first_line; int line = elementPositions[i].first_line;
@@ -1758,7 +1758,7 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
const Type * const Type *
StructType::GetElementType(int i) const { StructType::GetElementType(int i) const {
assert(i < (int)elementTypes.size()); Assert(i < (int)elementTypes.size());
// If the struct is uniform qualified, then each member comes out with // If the struct is uniform qualified, then each member comes out with
// the same type as in the original source file. If it's varying, then // the same type as in the original source file. If it's varying, then
// all members are promoted to varying. // all members are promoted to varying.
@@ -1958,7 +1958,7 @@ FunctionType::FunctionType(const Type *r, const std::vector<const Type *> &a,
paramTypes(a), paramNames(std::vector<std::string>(a.size(), "")), paramTypes(a), paramNames(std::vector<std::string>(a.size(), "")),
paramDefaults(std::vector<ConstExpr *>(a.size(), NULL)), paramDefaults(std::vector<ConstExpr *>(a.size(), NULL)),
paramPositions(std::vector<SourcePos>(a.size(), p)) { paramPositions(std::vector<SourcePos>(a.size(), p)) {
assert(returnType != NULL); Assert(returnType != NULL);
} }
@@ -1969,10 +1969,10 @@ FunctionType::FunctionType(const Type *r, const std::vector<const Type *> &a,
bool it, bool is, bool ec) bool it, bool is, bool ec)
: isTask(it), isExported(is), isExternC(ec), returnType(r), paramTypes(a), : isTask(it), isExported(is), isExternC(ec), returnType(r), paramTypes(a),
paramNames(an), paramDefaults(ad), paramPositions(ap) { paramNames(an), paramDefaults(ad), paramPositions(ap) {
assert(paramTypes.size() == paramNames.size() && Assert(paramTypes.size() == paramNames.size() &&
paramNames.size() == paramDefaults.size() && paramNames.size() == paramDefaults.size() &&
paramDefaults.size() == paramPositions.size()); paramDefaults.size() == paramPositions.size());
assert(returnType != NULL); Assert(returnType != NULL);
} }
@@ -2127,14 +2127,14 @@ FunctionType::GetDIType(llvm::DIDescriptor scope) const {
LLVM_TYPE_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 (isTask == true) assert(includeMask == true); if (isTask == true) Assert(includeMask == true);
// Get the LLVM Type *s for the function arguments // Get the LLVM Type *s for the function arguments
std::vector<LLVM_TYPE_CONST llvm::Type *> llvmArgTypes; std::vector<LLVM_TYPE_CONST llvm::Type *> llvmArgTypes;
for (unsigned int i = 0; i < paramTypes.size(); ++i) { for (unsigned int i = 0; i < paramTypes.size(); ++i) {
if (!paramTypes[i]) if (!paramTypes[i])
return NULL; return NULL;
assert(paramTypes[i] != AtomicType::Void); Assert(paramTypes[i] != AtomicType::Void);
LLVM_TYPE_CONST llvm::Type *t = paramTypes[i]->LLVMType(ctx); LLVM_TYPE_CONST llvm::Type *t = paramTypes[i]->LLVMType(ctx);
if (t == NULL) if (t == NULL)
@@ -2170,28 +2170,28 @@ FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool includeMask) const {
const Type * const Type *
FunctionType::GetParameterType(int i) const { FunctionType::GetParameterType(int i) const {
assert(i < (int)paramTypes.size()); Assert(i < (int)paramTypes.size());
return paramTypes[i]; return paramTypes[i];
} }
ConstExpr * ConstExpr *
FunctionType::GetParameterDefault(int i) const { FunctionType::GetParameterDefault(int i) const {
assert(i < (int)paramDefaults.size()); Assert(i < (int)paramDefaults.size());
return paramDefaults[i]; return paramDefaults[i];
} }
const SourcePos & const SourcePos &
FunctionType::GetParameterSourcePos(int i) const { FunctionType::GetParameterSourcePos(int i) const {
assert(i < (int)paramPositions.size()); Assert(i < (int)paramPositions.size());
return paramPositions[i]; return paramPositions[i];
} }
const std::string & const std::string &
FunctionType::GetParameterName(int i) const { FunctionType::GetParameterName(int i) const {
assert(i < (int)paramNames.size()); Assert(i < (int)paramNames.size());
return paramNames[i]; return paramNames[i];
} }
@@ -2244,7 +2244,7 @@ lVectorConvert(const Type *type, SourcePos pos, const char *reason, int vecSize)
const Type * const Type *
Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char *reason, Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char *reason,
bool forceVarying, int vecSize) { bool forceVarying, int vecSize) {
assert(reason != NULL); Assert(reason != NULL);
// First, if we need to go varying, promote both of the types to be // First, if we need to go varying, promote both of the types to be
// varying. // varying.
@@ -2315,7 +2315,7 @@ Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char
// The 'more general' version of the two vector element types must // The 'more general' version of the two vector element types must
// be an AtomicType (that's all that vectors can hold...) // be an AtomicType (that's all that vectors can hold...)
const AtomicType *at = dynamic_cast<const AtomicType *>(t); const AtomicType *at = dynamic_cast<const AtomicType *>(t);
assert(at != NULL); Assert(at != NULL);
return new VectorType(at, vt0->GetElementCount()); return new VectorType(at, vt0->GetElementCount());
} }
@@ -2330,7 +2330,7 @@ Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char
return NULL; return NULL;
const AtomicType *at = dynamic_cast<const AtomicType *>(t); const AtomicType *at = dynamic_cast<const AtomicType *>(t);
assert(at != NULL); Assert(at != NULL);
return new VectorType(at, vt0->GetElementCount()); return new VectorType(at, vt0->GetElementCount());
} }
else if (vt1) { else if (vt1) {
@@ -2342,7 +2342,7 @@ Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char
return NULL; return NULL;
const AtomicType *at = dynamic_cast<const AtomicType *>(t); const AtomicType *at = dynamic_cast<const AtomicType *>(t);
assert(at != NULL); Assert(at != NULL);
return new VectorType(at, vt1->GetElementCount()); return new VectorType(at, vt1->GetElementCount());
} }
@@ -2355,7 +2355,7 @@ Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char
const EnumType *et1 = dynamic_cast<const EnumType *>(t1->GetReferenceTarget()); const EnumType *et1 = dynamic_cast<const EnumType *>(t1->GetReferenceTarget());
if (et0 != NULL && et1 != NULL) { if (et0 != NULL && et1 != NULL) {
// Two different enum types -> make them uint32s... // Two different enum types -> make them uint32s...
assert(et0->IsVaryingType() == et1->IsVaryingType()); Assert(et0->IsVaryingType() == et1->IsVaryingType());
return et0->IsVaryingType() ? AtomicType::VaryingUInt32 : return et0->IsVaryingType() ? AtomicType::VaryingUInt32 :
AtomicType::UniformUInt32; AtomicType::UniformUInt32;
} }
@@ -2386,7 +2386,7 @@ Type::MoreGeneralType(const Type *t0, const Type *t1, SourcePos pos, const char
// Now all we can do is promote atomic types... // Now all we can do is promote atomic types...
if (at0 == NULL || at1 == NULL) { if (at0 == NULL || at1 == NULL) {
assert(reason != NULL); Assert(reason != NULL);
Error(pos, "Implicit conversion from type \"%s\" to \"%s\" for %s not possible.", Error(pos, "Implicit conversion from type \"%s\" to \"%s\" for %s not possible.",
t0->GetString().c_str(), t1->GetString().c_str(), reason); t0->GetString().c_str(), t1->GetString().c_str(), reason);
return NULL; return NULL;

View File

@@ -45,7 +45,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
@@ -147,7 +146,7 @@ lPrintWithWordBreaks(const char *buf, int columnWidth, FILE *out) {
fputs(buf, out); fputs(buf, out);
#else #else
int column = 0; int column = 0;
assert(strchr(buf, ':') != NULL); Assert(strchr(buf, ':') != NULL);
int indent = strchr(buf, ':') - buf + 2; int indent = strchr(buf, ':') - buf + 2;
int width = std::max(40, columnWidth - 2); int width = std::max(40, columnWidth - 2);
@@ -313,6 +312,12 @@ PerformanceWarning(SourcePos p, const char *fmt, ...) {
void void
FatalError(const char *file, int line, const char *message) { FatalError(const char *file, int line, const char *message) {
fprintf(stderr, "%s(%d): FATAL ERROR: %s\n", file, line, message); fprintf(stderr, "%s(%d): FATAL ERROR: %s\n", file, line, message);
fprintf(stderr, "***\n"
"*** Please file a bug report at https://github.com/ispc/ispc/issues\n"
"*** (Including as much information as you can about how to "
"reproduce this error).\n"
"*** You have apparently encountered a bug in the compiler that we'd "
"like to fix!\n***\n");
abort(); abort();
} }
@@ -392,7 +397,7 @@ GetDirectoryAndFileName(const std::string &currentDirectory,
char path[MAX_PATH]; char path[MAX_PATH];
const char *combPath = PathCombine(path, currentDirectory.c_str(), const char *combPath = PathCombine(path, currentDirectory.c_str(),
relativeName.c_str()); relativeName.c_str());
assert(combPath != NULL); Assert(combPath != NULL);
const char *filenamePtr = PathFindFileName(combPath); const char *filenamePtr = PathFindFileName(combPath);
*filename = filenamePtr; *filename = filenamePtr;
*directory = std::string(combPath, filenamePtr - combPath); *directory = std::string(combPath, filenamePtr - combPath);
@@ -414,9 +419,9 @@ GetDirectoryAndFileName(const std::string &currentDirectory,
// now, we need to separate it into the base name and the directory // now, we need to separate it into the base name and the directory
const char *fp = fullPath.c_str(); const char *fp = fullPath.c_str();
const char *basenameStart = strrchr(fp, '/'); const char *basenameStart = strrchr(fp, '/');
assert(basenameStart != NULL); Assert(basenameStart != NULL);
++basenameStart; ++basenameStart;
assert(basenameStart != '\0'); Assert(basenameStart != '\0');
*filename = basenameStart; *filename = basenameStart;
*directory = std::string(fp, basenameStart - fp); *directory = std::string(fp, basenameStart - fp);
#endif // ISPC_IS_WINDOWS #endif // ISPC_IS_WINDOWS