SeqScanPlanNode::~SeqScanPlanNode() { // This is opposite the check that controls when the temp table is created in seqscanexecutor. // So, even if there is a temp table to be freed, it belongs to a subquery, so drop this // reference to it to prevent double-delete by AbstractPlanNode. if (getPredicate() == NULL && getInlinePlanNodes().size() == 0) { clearOutputTableReference(); } }
RValue Inst::Cmp(int type, RValue lhs, RValue rhs, CodeContext& context) { if (CastMatch(context, lhs, rhs)) return RValue(); auto pred = getPredicate(type, lhs.stype(), context); auto cmpType = lhs.stype()->isVec()? lhs.stype()->subType() : lhs.stype(); auto op = cmpType->isFloating()? Instruction::FCmp : Instruction::ICmp; auto cmp = CmpInst::Create(op, pred, lhs, rhs, "", context); auto retType = lhs.stype()->isVec()? SType::getVec(context, SType::getBool(context), lhs.stype()->size()) : SType::getBool(context); return RValue(cmp, retType); }
void Instruction::takeExtraSources(int s, Value *values[3]) { values[0] = getIndirect(s, 0); if (values[0]) setIndirect(s, 0, NULL); values[1] = getIndirect(s, 1); if (values[1]) setIndirect(s, 1, NULL); values[2] = getPredicate(); if (values[2]) setPredicate(cc, NULL); }
bool Inst::CastTo(CodeContext& context, RValue& value, SType* type, bool upcast) { auto valueType = value.stype(); if (type == valueType) { // non-assignment and non-comparison operations with enum types // must result in an int type to keep enum variables within range. if (upcast && valueType->isEnum()) value.castToSubtype(); return false; } else if (type->isComplex() || valueType->isComplex()) { context.addError("can not cast complex types"); return true; } else if (type->isPointer()) { if (value.isNullPtr()) { // NOTE: discard current null value and create // a new one using the right type value = RValue::getNullPtr(context, type); return false; } else if (type->subType()->isVoid()) { value = RValue(new BitCastInst(value, *type, "", context), type); return false; } context.addError("can't cast value to pointer type"); return true; } else if (type->isVec()) { // unwrap enum type if (valueType->isEnum()) valueType = value.castToSubtype(); if (valueType->isNumeric()) { CastTo(context, value, type->subType(), upcast); auto i32 = SType::getInt(context, 32); auto mask = RValue::getZero(context, SType::getVec(context, i32, type->size())); auto udef = UndefValue::get(*SType::getVec(context, type->subType(), 1)); auto instEle = InsertElementInst::Create(udef, value, RValue::getZero(context, i32), "", context); auto retVal = new ShuffleVectorInst(instEle, udef, mask, "", context); value = RValue(retVal, type); return false; } else if (valueType->isPointer()) { context.addError("can not cast pointer to vec type"); return true; } else if (type->size() != valueType->size()) { context.addError("can not cast vec types of different sizes"); return true; } else if (type->subType()->isBool()) { // cast to bool is value != 0 auto pred = getPredicate(ParserBase::TT_NEQ, valueType, context); auto op = valueType->subType()->isFloating()? Instruction::FCmp : Instruction::ICmp; auto val = CmpInst::Create(op, pred, value, RValue::getZero(context, valueType), "", context); value = RValue(val, type); return false; } else { auto op = getCastOp(valueType->subType(), type->subType()); auto val = CastInst::Create(op, value, *type, "", context); value = RValue(val, type); return false; } } else if (type->isEnum()) { // casting to enum would violate value constraints context.addError("can't cast to enum type"); return true; } else if (type->isBool()) { if (valueType->isVec()) { context.addError("can not cast vec type to bool"); return true; } else if (valueType->isEnum()) { valueType = value.castToSubtype(); } // cast to bool is value != 0 auto pred = getPredicate(ParserBase::TT_NEQ, valueType, context); auto op = valueType->isFloating()? Instruction::FCmp : Instruction::ICmp; auto val = CmpInst::Create(op, pred, value, RValue::getZero(context, valueType), "", context); value = RValue(val, type); return false; } if (valueType->isPointer()) { context.addError("can't cast pointer to numeric type"); return true; } // unwrap enum type if (valueType->isEnum()) valueType = value.castToSubtype(); auto op = getCastOp(valueType, type); auto val = op != Instruction::AddrSpaceCast? CastInst::Create(op, value, *type, "", context) : value; value = RValue(val, type); return false; }
void Rule::handle(EventBase *event) { if (getPredicate()->doesMatch(event)) { LTRACE("starting action %s", typeid(*getAction()).name()) getAction()->execute(event); } }