Exemplo n.º 1
0
// llvm.dbg.value is far away from the value then iSel may not be able
// handle it properly. iSel will drop llvm.dbg.value if it can not
// find a node corresponding to the value.
bool CodeGenPrepare::PlaceDbgValues(Function &F) {
    bool MadeChange = false;
    for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
        Instruction *PrevNonDbgInst = NULL;
        for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
            Instruction *Insn = BI;
            ++BI;
            DbgValueInst *DVI = dyn_cast<DbgValueInst>(Insn);
            if (!DVI) {
                PrevNonDbgInst = Insn;
                continue;
            }

            Instruction *VI = dyn_cast_or_null<Instruction>(DVI->getValue());
            if (VI && VI != PrevNonDbgInst && !VI->isTerminator()) {
                DEBUG(dbgs() << "Moving Debug Value before :\n" << *DVI << ' ' << *VI);
                DVI->removeFromParent();
                if (isa<PHINode>(VI))
                    DVI->insertBefore(VI->getParent()->getFirstInsertionPt());
                else
                    DVI->insertAfter(VI);
                MadeChange = true;
                ++NumDbgValueMoved;
            }
        }
    }
    return MadeChange;
}
Exemplo n.º 2
0
void DebugDatabase::addVariableSourceDbgValue(DebugValue *dbgVal,
                                              TraceScheduler *traceScheduler) {
    DbgValueInst *dbgValInst = dbgVal->getDbgValInsn();
    assert(dbgValInst);

    int id = addVariableSource(dbgVal->getVariable(), dbgValInst, true);

    std::string query;
    if (dbgVal->isConstantInt()) {
        // Get the integer value
        ConstantInt *ci = cast<ConstantInt>(dbgValInst->getValue());

        query = "INSERT INTO VariableSourceConstantInt ";
        query += "(VariableSourceId, constantInt) ";
        query += "VALUES (" + std::to_string(id);
        query += "," + std::to_string(ci->getSExtValue());
        query += ");";
        runQuery(query);

    } else if (dbgVal->isConstantNull()) {
        query = "INSERT INTO VariableSourceConstantInt ";
        query += "(VariableSourceId, constantInt) ";
        query += "VALUES (" + std::to_string(id);
        query += ",NULL";
        query += ");";
        runQuery(query);

    } else if (dbgVal->isConstantPointer()) {
        ConstantExpr *CE = dyn_cast<ConstantExpr>(dbgValInst->getValue());
        assert(CE);

        Value *base;
        int offset;
        getGEPBaseAndOffset(CE, &base, &offset);

        int ramId = ramToIds[dbgInfo->getAlloc()->getRAM(base)];
        assert(ramId);

        query = "INSERT INTO VariableSourcePointer ";
        query += "(VariableSourceId, ramId, offset) ";
        query += "VALUES (" + std::to_string(id);
        query += "," + std::to_string(ramId);
        query += "," + std::to_string(offset);
        query += ");";
        runQuery(query);

    } else if (dbgVal->isAlloca()) {
        RAM *ram =
            dbgInfo->getAlloc()->getRAM(dbgVal->getDbgValInsn()->getValue());
        assert(ram);

        int offset = dbgVal->getDbgValInsn()->getOffset();

        int ramId = ramToIds[ram];
        assert(ramId);

        query = "INSERT INTO VariableSourcePointer ";
        query += "(VariableSourceId, ramId, offset) ";
        query += "VALUES (" + std::to_string(id);
        query += "," + std::to_string(ramId);
        query += "," + std::to_string(offset);
        query += ");";
        runQuery(query);

        //        dbgs() << *(dbgVal->getDbgValInsn()) << " is an alloca\n";
    } else if (dbgVal->isArgument() || dbgVal->isFunctionCall() ||
               dbgVal->isRegister()) {
        GenerateRTL *hw = dbgVal->getVariable()->getGenRtl();

        string signalName = dbgVal->getSignalName();
        RTLSignal *signal;

        signal = hw->getRTL()->findExists(signalName);

        if (!signal) {
            dbgs() << *(dbgVal->getDbgValInsn()) << "\n";
            dbgs() << "Can't find signal " << dbgVal->getSignalName() << "\n";
        }

        //        RTLSignal *signal =
        //        hw->getRTL()->find(dbgVal->getSignalName());

        query = "INSERT INTO VariableSourceSignal ";
        query += "(VariableSourceId, rtlSignalId) ";
        query += "VALUES (" + std::to_string(id);
        query += "," + std::to_string(rtlSignalToIds[signal]);
        query += ");";
        runQuery(query);

    } else if (dbgVal->isUndefined()) {
        query = "INSERT INTO VariableSourceUndefined ";
        query += "(VariableSourceId) ";
        query += "VALUES (" + std::to_string(id);
        query += ");";
        runQuery(query);
    } else {
        dbgs() << *(dbgValInst) << "\n";
        dbgs() << *(dbgValInst->getValue()) << "\n";
        assert(false);
    }
}