Skip to content

Commit

Permalink
[sancov] code readability improvement.
Browse files Browse the repository at this point in the history
Summary: Reply to http://reviews.llvm.org/D18341

Differential Revision: http://reviews.llvm.org/D18406

llvm-svn: 264213
  • Loading branch information
aizatsky-chromium committed Mar 23, 2016
1 parent 0f432aa commit 9987f43
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Expand Up @@ -315,24 +315,39 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
return true;
}

static bool shouldInstrumentBlock(const BasicBlock *BB, const DominatorTree *DT,
const PostDominatorTree *PDT) {
if (!ClPruneBlocks)
return true;
// True if block has successors and it dominates all of them.
static bool isFullDominator(const BasicBlock *BB, const DominatorTree *DT) {
if (succ_begin(BB) == succ_end(BB))
return false;

// Check if BB dominates all its successors.
bool DominatesAll = succ_begin(BB) != succ_end(BB);
for (const BasicBlock *SUCC : make_range(succ_begin(BB), succ_end(BB))) {
DominatesAll &= DT->dominates(BB, SUCC);
if (!DT->dominates(BB, SUCC))
return false;
}

// Check if BB pre-dominates all predecessors.
bool PreDominatesAll = pred_begin(BB) != pred_end(BB);
return true;
}

// True if block has predecessors and it postdominates all of them.
static bool isFullPostDominator(const BasicBlock *BB,
const PostDominatorTree *PDT) {
if (pred_begin(BB) == pred_end(BB))
return false;

for (const BasicBlock *PRED : make_range(pred_begin(BB), pred_end(BB))) {
PreDominatesAll &= PDT->dominates(BB, PRED);
if (!PDT->dominates(BB, PRED))
return false;
}

return !(DominatesAll || PreDominatesAll);
return true;
}

static bool shouldInstrumentBlock(const BasicBlock *BB, const DominatorTree *DT,
const PostDominatorTree *PDT) {
if (!ClPruneBlocks)
return true;

return !(isFullDominator(BB, DT) || isFullPostDominator(BB, PDT));
}

bool SanitizerCoverageModule::runOnFunction(Function &F) {
Expand Down

0 comments on commit 9987f43

Please sign in to comment.