Skip to content

Commit

Permalink
Use debugging information from newer LLVM versions
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowack authored and ccadar committed Mar 19, 2019
1 parent f8a481b commit 2558d3e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
7 changes: 6 additions & 1 deletion lib/Core/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os,
for (unsigned i=0, e=cds->getNumElements(); i != e; ++i)
initializeGlobalObject(state, os, cds->getElementAsConstant(i),
offset + i*elementSize);
} else if (!isa<UndefValue>(c)) {
} else if (!isa<UndefValue>(c) && !isa<MetadataAsValue>(c)) {
unsigned StoreBits = targetData->getTypeStoreSizeInBits(c->getType());
ref<ConstantExpr> C = evalConstant(c);

Expand Down Expand Up @@ -1329,6 +1329,8 @@ void Executor::executeCall(ExecutionState &state,
Function *f,
std::vector< ref<Expr> > &arguments) {
Instruction *i = ki->inst;
if (i && isa<DbgInfoIntrinsic>(i))
return;
if (f && f->isDeclaration()) {
switch(f->getIntrinsicID()) {
case Intrinsic::not_intrinsic:
Expand Down Expand Up @@ -1909,6 +1911,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {

case Instruction::Invoke:
case Instruction::Call: {
// Ignore debug intrinsic calls
if (isa<DbgInfoIntrinsic>(i))
break;
CallSite cs(i);

unsigned numArgs = cs.arg_size();
Expand Down
40 changes: 19 additions & 21 deletions lib/Core/StatsTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void StatsTracker::writeIStats() {
// KCachegrind can create two entries for the function, one with an
// unnamed file and one without.
Function *fn = &*fnIt;
const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fn);
const FunctionInfo &ii = executor.kmodule->infos->getFunctionInfo(*fn);
if (ii.file != sourceFile) {
of << "fl=" << ii.file << "\n";
sourceFile = ii.file;
Expand All @@ -558,7 +558,7 @@ void StatsTracker::writeIStats() {
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
Instruction *instr = &*it;
const InstructionInfo &ii = executor.kmodule->infos->getInfo(instr);
const InstructionInfo &ii = executor.kmodule->infos->getInfo(*instr);
unsigned index = ii.id;
if (ii.file!=sourceFile) {
of << "fl=" << ii.file << "\n";
Expand All @@ -575,14 +575,13 @@ void StatsTracker::writeIStats() {
(isa<CallInst>(instr) || isa<InvokeInst>(instr))) {
CallSiteSummaryTable::iterator it = callSiteStats.find(instr);
if (it!=callSiteStats.end()) {
for (std::map<llvm::Function*, CallSiteInfo>::iterator
fit = it->second.begin(), fie = it->second.end();
for (auto fit = it->second.begin(), fie = it->second.end();
fit != fie; ++fit) {
Function *f = fit->first;
const Function *f = fit->first;
CallSiteInfo &csi = fit->second;
const InstructionInfo &fii =
executor.kmodule->infos->getFunctionInfo(f);
const FunctionInfo &fii =
executor.kmodule->infos->getFunctionInfo(*f);

if (fii.file!="" && fii.file!=sourceFile)
of << "cfl=" << fii.file << "\n";
of << "cfn=" << f->getName().str() << "\n";
Expand Down Expand Up @@ -746,7 +745,7 @@ void StatsTracker::computeReachableUncovered() {
it != ie; ++it) {
Instruction *inst = &*it;
instructions.push_back(inst);
unsigned id = infos.getInfo(inst).id;
unsigned id = infos.getInfo(*inst).id;
sm.setIndexedValue(stats::minDistToReturn,
id,
isa<ReturnInst>(inst)
Expand All @@ -761,8 +760,8 @@ void StatsTracker::computeReachableUncovered() {
bool changed;
do {
changed = false;
for (std::vector<Instruction*>::iterator it = instructions.begin(),
ie = instructions.end(); it != ie; ++it) {
for (auto it = instructions.begin(), ie = instructions.end(); it != ie;
++it) {
Instruction *inst = *it;
unsigned bestThrough = 0;

Expand All @@ -782,13 +781,13 @@ void StatsTracker::computeReachableUncovered() {
}

if (bestThrough) {
unsigned id = infos.getInfo(*it).id;
unsigned id = infos.getInfo(*(*it)).id;
uint64_t best, cur = best = sm.getIndexedValue(stats::minDistToReturn, id);
std::vector<Instruction*> succs = getSuccs(*it);
for (std::vector<Instruction*>::iterator it2 = succs.begin(),
ie = succs.end(); it2 != ie; ++it2) {
uint64_t dist = sm.getIndexedValue(stats::minDistToReturn,
infos.getInfo(*it2).id);
infos.getInfo(*(*it2)).id);
if (dist) {
uint64_t val = bestThrough + dist;
if (best==0 || val<best)
Expand Down Expand Up @@ -824,7 +823,7 @@ void StatsTracker::computeReachableUncovered() {
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
Instruction *inst = &*it;
unsigned id = infos.getInfo(inst).id;
unsigned id = infos.getInfo(*inst).id;
instructions.push_back(inst);
sm.setIndexedValue(stats::minDistToUncovered,
id,
Expand All @@ -842,8 +841,8 @@ void StatsTracker::computeReachableUncovered() {
for (std::vector<Instruction*>::iterator it = instructions.begin(),
ie = instructions.end(); it != ie; ++it) {
Instruction *inst = *it;
uint64_t best, cur = best = sm.getIndexedValue(stats::minDistToUncovered,
infos.getInfo(inst).id);
uint64_t best, cur = best = sm.getIndexedValue(stats::minDistToUncovered,
infos.getInfo(*inst).id);
unsigned bestThrough = 0;

if (isa<CallInst>(inst) || isa<InvokeInst>(inst)) {
Expand All @@ -858,8 +857,8 @@ void StatsTracker::computeReachableUncovered() {
}

if (!(*fnIt)->isDeclaration()) {
uint64_t calleeDist = sm.getIndexedValue(stats::minDistToUncovered,
infos.getFunctionInfo(*fnIt).id);
uint64_t calleeDist = sm.getIndexedValue(
stats::minDistToUncovered, infos.getFunctionInfo(*(*fnIt)).id);
if (calleeDist) {
calleeDist = 1+calleeDist; // count instruction itself
if (best==0 || calleeDist<best)
Expand All @@ -876,7 +875,7 @@ void StatsTracker::computeReachableUncovered() {
for (std::vector<Instruction*>::iterator it2 = succs.begin(),
ie = succs.end(); it2 != ie; ++it2) {
uint64_t dist = sm.getIndexedValue(stats::minDistToUncovered,
infos.getInfo(*it2).id);
infos.getInfo(*(*it2)).id);
if (dist) {
uint64_t val = bestThrough + dist;
if (best==0 || val<best)
Expand All @@ -886,8 +885,7 @@ void StatsTracker::computeReachableUncovered() {
}

if (best != cur) {
sm.setIndexedValue(stats::minDistToUncovered,
infos.getInfo(inst).id,
sm.setIndexedValue(stats::minDistToUncovered, infos.getInfo(*inst).id,
best);
changed = true;
}
Expand Down
30 changes: 29 additions & 1 deletion lib/Module/InstructionInfoTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,28 @@ class DebugInfoExtractor {

std::unique_ptr<FunctionInfo> getFunctionInfo(const llvm::Function &Func) {
auto asmLine = lineTable.at(reinterpret_cast<std::uintptr_t>(&Func));
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0)
auto dsub = Func.getSubprogram();
#else
auto dsub = llvm::getDISubprogram(&Func);
#endif
if (dsub == nullptr)
return std::unique_ptr<FunctionInfo>(
new FunctionInfo(0, getInternedString(""), 0, asmLine));
auto path = getFullPath(dsub->getDirectory(), dsub->getFilename());
return std::unique_ptr<FunctionInfo>(
new FunctionInfo(0, getInternedString(path), dsub->getLine(), asmLine));

#else
// Acquire function debug information
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
for (auto subIt = DIF.subprogram_begin(), subItE = DIF.subprogram_end();
subIt != subItE; ++subIt) {
llvm::DISubprogram SubProgram(*subIt);
#else
for (const auto &SubProgram : DIF.subprograms()) {
#endif
if (SubProgram.getFunction() != &Func)
continue;

Expand All @@ -152,12 +169,23 @@ class DebugInfoExtractor {

return std::unique_ptr<FunctionInfo>(
new FunctionInfo(0, getInternedString(""), 0, asmLine));
#endif
}

std::unique_ptr<InstructionInfo>
getInstructionInfo(const llvm::Instruction &Inst, const FunctionInfo &f) {
auto asmLine = lineTable.at(reinterpret_cast<std::uintptr_t>(&Inst));

#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
auto dl = Inst.getDebugLoc();
auto dil = dl.get();
if (dil != nullptr) {
auto full_path = getFullPath(dil->getDirectory(), dil->getFilename());

return std::unique_ptr<InstructionInfo>(new InstructionInfo(
0, getInternedString(full_path), dl.getLine(), dl.getCol(), asmLine));
}
#else
llvm::DebugLoc Loc(Inst.getDebugLoc());
if (!Loc.isUnknown()) {
llvm::DIScope Scope(Loc.getScope(module.getContext()));
Expand All @@ -166,7 +194,7 @@ class DebugInfoExtractor {
new InstructionInfo(0, getInternedString(full_path), Loc.getLine(),
Loc.getCol(), asmLine));
}

#endif
// If nothing found, use the surrounding function
return std::unique_ptr<InstructionInfo>(
new InstructionInfo(0, f.file, f.line, 0, asmLine));
Expand Down
3 changes: 3 additions & 0 deletions lib/Module/IntrinsicCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
// increment now since deletion of instructions makes iterator invalid.
++i;
if (ii) {
if (isa<DbgInfoIntrinsic>(ii))
continue;

switch (ii->getIntrinsicID()) {
case Intrinsic::vastart:
case Intrinsic::vaend:
Expand Down
3 changes: 2 additions & 1 deletion lib/Module/KModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ static int getOperandNum(Value *v,
return a->getArgNo();
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
// Metadata is no longer a Value
} else if (isa<BasicBlock>(v) || isa<InlineAsm>(v)) {
} else if (isa<BasicBlock>(v) || isa<InlineAsm>(v) ||
isa<MetadataAsValue>(v)) {
#else
} else if (isa<BasicBlock>(v) || isa<InlineAsm>(v) ||
isa<MDNode>(v)) {
Expand Down

0 comments on commit 2558d3e

Please sign in to comment.