[PATCH] D18341: [sancov] do not instrument nodes that are full pre-dominators

Mike Aizatsky via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 16:13:24 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL264003: [sancov] do not instrument nodes that are full pre-dominators (authored by aizatsky).

Changed prior to commit:
  http://reviews.llvm.org/D18341?vs=51241&id=51243#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18341

Files:
  llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Index: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -315,20 +315,24 @@
   return true;
 }
 
-static bool shouldInstrumentBlock(const BasicBlock *BB,
-                                  const DominatorTree *DT) {
+static bool shouldInstrumentBlock(const BasicBlock *BB, const DominatorTree *DT,
+                                  const PostDominatorTree *PDT) {
   if (!ClPruneBlocks)
     return true;
-  if (succ_begin(BB) == succ_end(BB))
-    return true;
 
   // 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))) {
-    if (!DT->dominates(BB, SUCC))
-      return true;
+    DominatesAll &= DT->dominates(BB, SUCC);
+  }
+
+  // Check if BB pre-dominates all predecessors.
+  bool PreDominatesAll = pred_begin(BB) != pred_end(BB);
+  for (const BasicBlock *PRED : make_range(pred_begin(BB), pred_end(BB))) {
+    PreDominatesAll &= PDT->dominates(BB, PRED);
   }
 
-  return false;
+  return !(DominatesAll || PreDominatesAll);
 }
 
 bool SanitizerCoverageModule::runOnFunction(Function &F) {
@@ -349,10 +353,13 @@
   SmallVector<Instruction *, 8> CmpTraceTargets;
   SmallVector<Instruction *, 8> SwitchTraceTargets;
 
-  DominatorTree DT;
-  DT.recalculate(F);
+  const DominatorTree *DT =
+      &getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
+  const PostDominatorTree *PDT =
+      &getAnalysis<PostDominatorTreeWrapperPass>(F).getPostDomTree();
+
   for (auto &BB : F) {
-    if (shouldInstrumentBlock(&BB, &DT))
+    if (shouldInstrumentBlock(&BB, DT, PDT))
       BlocksToInstrument.push_back(&BB);
     for (auto &Inst : BB) {
       if (Options.IndirectCalls) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18341.51243.patch
Type: text/x-patch
Size: 1932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160321/db869aff/attachment.bin>


More information about the llvm-commits mailing list