C++ (Cpp) Value Examples

C++ (Cpp) Value - 30 examples found. These are the top rated real world C++ (Cpp) examples of Value extracted from open source projects. You can rate examples to help us improve the quality of examples.
void AccumulatorAddToSet::processInternal(const Value& input, bool merging) {
    if (!merging) {
        if (!input.missing()) {
            bool inserted = set.insert(input).second;
            if (inserted) {
                _memUsageBytes += input.getApproximateSize();
            }
        }
    }
    else {
        // If we're merging, we need to take apart the arrays we
        // receive and put their elements into the array we are collecting.
        // If we didn't, then we'd get an array of arrays, with one array
        // from each merge source.
        verify(input.getType() == Array);

        const vector<Value>& array = input.getArray();
        for (size_t i=0; i < array.size(); i++) {
            bool inserted = set.insert(array[i]).second;
            if (inserted) {
                _memUsageBytes += array[i].getApproximateSize();
            }
        }
    }
}
Example #2
0
bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
    // Propagate constants through ptrtoint.
    if (Constant *COp = dyn_cast<Constant>(I.getOperand(0)))
        if (Constant *C = ConstantExpr::getIntToPtr(COp, I.getType())) {
            SimplifiedValues[&I] = C;
            return true;
        }

    // Track base/offset pairs when round-tripped through a pointer without
    // modifications provided the integer is not too large.
    Value *Op = I.getOperand(0);
    unsigned IntegerSize = Op->getType()->getScalarSizeInBits();
    unsigned AS = I.getAddressSpace();
    if (TD && IntegerSize <= TD->getPointerSizeInBits(AS)) {
        std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.lookup(Op);
        if (BaseAndOffset.first)
            ConstantOffsetPtrs[&I] = BaseAndOffset;
    }

    // "Propagate" SROA here in the same manner as we do for ptrtoint above.
    Value *SROAArg;
    DenseMap<Value *, int>::iterator CostIt;
    if (lookupSROAArgAndCost(Op, SROAArg, CostIt))
        SROAArgValues[&I] = SROAArg;

    return isInstructionFree(&I, TD);
}
Example #3
0
void SanitizerCoverageModule::InjectTraceForSwitch(
    Function &F, ArrayRef<Instruction *> SwitchTraceTargets) {
    for (auto I : SwitchTraceTargets) {
        if (SwitchInst *SI = dyn_cast<SwitchInst>(I)) {
            IRBuilder<> IRB(I);
            SmallVector<Constant *, 16> Initializers;
            Value *Cond = SI->getCondition();
            if (Cond->getType()->getScalarSizeInBits() >
                    Int64Ty->getScalarSizeInBits())
                continue;
            Initializers.push_back(ConstantInt::get(Int64Ty, SI->getNumCases()));
            Initializers.push_back(
                ConstantInt::get(Int64Ty, Cond->getType()->getScalarSizeInBits()));
            if (Cond->getType()->getScalarSizeInBits() <
                    Int64Ty->getScalarSizeInBits())
                Cond = IRB.CreateIntCast(Cond, Int64Ty, false);
            for (auto It: SI->cases()) {
                Constant *C = It.getCaseValue();
                if (C->getType()->getScalarSizeInBits() <
                        Int64Ty->getScalarSizeInBits())
                    C = ConstantExpr::getCast(CastInst::ZExt, It.getCaseValue(), Int64Ty);
                Initializers.push_back(C);
            }
            ArrayType *ArrayOfInt64Ty = ArrayType::get(Int64Ty, Initializers.size());
            GlobalVariable *GV = new GlobalVariable(
                *CurModule, ArrayOfInt64Ty, false, GlobalVariable::InternalLinkage,
                ConstantArray::get(ArrayOfInt64Ty, Initializers),
                "__sancov_gen_cov_switch_values");
            IRB.CreateCall(SanCovTraceSwitchFunction,
            {Cond, IRB.CreatePointerCast(GV, Int64PtrTy)});
        }
    }
}
Example #4
0
void
MacroAssemblerX86::branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label)
{
    jsval_layout jv = JSVAL_TO_IMPL(v);
    if (v.isMarkable())
        cmpPtr(value.payloadReg(), ImmGCPtr(reinterpret_cast<gc::Cell*>(v.toGCThing())));
    else
        cmpPtr(value.payloadReg(), ImmWord(jv.s.payload.i32));

    if (cond == Equal) {
        Label done;
        j(NotEqual, &done);
        {
            cmp32(value.typeReg(), Imm32(jv.s.tag));
            j(Equal, label);
        }
        bind(&done);
    } else {
        MOZ_ASSERT(cond == NotEqual);
        j(NotEqual, label);

        cmp32(value.typeReg(), Imm32(jv.s.tag));
        j(NotEqual, label);
    }
}
Example #5
0
bool CallAnalyzer::visitSub(BinaryOperator &I) {
    // Try to handle a special case: we can fold computing the difference of two
    // constant-related pointers.
    Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
    Value *LHSBase, *RHSBase;
    APInt LHSOffset, RHSOffset;
    llvm::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.lookup(LHS);
    if (LHSBase) {
        llvm::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.lookup(RHS);
        if (RHSBase && LHSBase == RHSBase) {
            // We have common bases, fold the subtract to a constant based on the
            // offsets.
            Constant *CLHS = ConstantInt::get(LHS->getContext(), LHSOffset);
            Constant *CRHS = ConstantInt::get(RHS->getContext(), RHSOffset);
            if (Constant *C = ConstantExpr::getSub(CLHS, CRHS)) {
                SimplifiedValues[&I] = C;
                ++NumConstantPtrDiffs;
                return true;
            }
        }
    }

    // Otherwise, fall back to the generic logic for simplifying and handling
    // instructions.
    return Base::visitSub(I);
}
bool
StyledStreamWriter::hasCommentForValue( const Value &value )
{
    return value.hasComment( commentBefore )
           ||  value.hasComment( commentAfterOnSameLine )
           ||  value.hasComment( commentAfter );
}