-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #878 from JohanEngelen/coverage
Add Coverage Analysis (à la DMD)
- Loading branch information
Showing
12 changed files
with
300 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//===-- gen/coverage.h - Code Coverage Analysis -----------------*- C++ -*-===// | ||
// | ||
// LDC – the LLVM D compiler | ||
// | ||
// This file is distributed under the BSD-style LDC license. See the LICENSE | ||
// file for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "gen/coverage.h" | ||
|
||
#include "mars.h" | ||
#include "module.h" | ||
#include "gen/irstate.h" | ||
#include "gen/logger.h" | ||
|
||
void emitCoverageLinecountInc(Loc &loc) { | ||
// Only emit coverage increment for locations in the source of the current module | ||
// (for example, 'inlined' methods from other source files should be skipped). | ||
if ( global.params.cov && (loc.linnum != 0) && loc.filename | ||
&& (gIR->module->getModuleIdentifier().compare(loc.filename) == 0) ) | ||
{ | ||
unsigned line = loc.linnum-1; // convert to 0-based line# index | ||
assert(line < gIR->dmodule->numlines); | ||
{ | ||
IF_LOG Logger::println("Coverage: increment _d_cover_data[%d]", line); | ||
|
||
// Get GEP into _d_cover_data array | ||
LLConstant* idxs[] = { DtoConstUint(0), DtoConstUint(line) }; | ||
LLValue* ptr = llvm::ConstantExpr::getGetElementPtr(gIR->dmodule->d_cover_data, idxs, true); | ||
|
||
// Do an atomic increment, so this works when multiple threads are executed. | ||
gIR->ir->CreateAtomicRMW( | ||
llvm::AtomicRMWInst::Add, | ||
ptr, | ||
DtoConstUint(1), | ||
llvm::Monotonic | ||
); | ||
} | ||
|
||
{ | ||
unsigned num_sizet_bits = gDataLayout->getTypeSizeInBits(DtoSize_t()); | ||
unsigned idx = line / num_sizet_bits; | ||
unsigned bitidx = line % num_sizet_bits; | ||
|
||
IF_LOG Logger::println(" _d_cover_valid[%d] |= (1 << %d)", idx, bitidx); | ||
|
||
gIR->dmodule->d_cover_valid_init[idx] |= (size_t(1) << bitidx); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- gen/coverage.h - Code Coverage Analysis -----------------*- C++ -*-===// | ||
// | ||
// LDC – the LLVM D compiler | ||
// | ||
// This file is distributed under the BSD-style LDC license. See the LICENSE | ||
// file for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains functions to generate code for code coverage analysis. | ||
// The coverage analysis is enabled by the "-cov" commandline switch. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LDC_GEN_COVERAGE_H | ||
#define LDC_GEN_COVERAGE_H | ||
|
||
struct Loc; | ||
|
||
void emitCoverageLinecountInc(Loc &loc); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.