[PATCH] D33608: [Analysis] Rewrite TotalMemInst counting in InstCount pass in a way that doesn't require reading back other Statistic variables

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 26 14:55:06 PDT 2017


craig.topper created this revision.

Previously, we counted TotalMemInst by reading certain instruction counters before and after calling visit and then finding the difference. But that wouldn't be thread safe if this same pass was being ran on multiple threads.

This patch changes this to just increment TotalMemInst in the visit functions for the instructions we care about.

This list of memory instructions doesn't completely make sense to me as it includes call/invoke and is missing atomics. Is that somethign that should also be fixed?


https://reviews.llvm.org/D33608

Files:
  lib/Analysis/InstCount.cpp


Index: lib/Analysis/InstCount.cpp
===================================================================
--- lib/Analysis/InstCount.cpp
+++ lib/Analysis/InstCount.cpp
@@ -42,7 +42,16 @@
     void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
 
 #define HANDLE_INST(N, OPCODE, CLASS) \
-    void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
+    void visit##OPCODE(CLASS &) { \
+      ++Num##OPCODE##Inst; ++TotalInsts; \
+      if (N == Instruction::GetElementPtr || \
+          N == Instruction::Load || \
+          N == Instruction::Store || \
+          N == Instruction::Call || \
+          N == Instruction::Invoke || \
+          N == Instruction::Alloca) \
+        ++TotalMemInst; \
+    }
 
 #include "llvm/IR/Instruction.def"
 
@@ -76,13 +85,6 @@
 // function.
 //
 bool InstCount::runOnFunction(Function &F) {
-  unsigned StartMemInsts =
-    NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
-    NumInvokeInst + NumAllocaInst;
   visit(F);
-  unsigned EndMemInsts =
-    NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
-    NumInvokeInst + NumAllocaInst;
-  TotalMemInst += EndMemInsts-StartMemInsts;
   return false;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33608.100476.patch
Type: text/x-patch
Size: 1190 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170526/9a81dcab/attachment.bin>


More information about the llvm-commits mailing list