Make Function::getInstructionCount const
authorMircea Trofin <mtrofin@google.com>
Thu, 18 Oct 2018 19:49:44 +0000 (19:49 +0000)
committerMircea Trofin <mtrofin@google.com>
Thu, 18 Oct 2018 19:49:44 +0000 (19:49 +0000)
Summary: Function::getInstructionCount can be const.

Reviewers: davidxl, paquette

Reviewed By: davidxl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D53378

llvm-svn: 344754

llvm/include/llvm/IR/Function.h
llvm/lib/IR/Function.cpp

index 1b91537..630f47e 100644 (file)
@@ -158,7 +158,7 @@ public:
   /// Returns the number of non-debug IR instructions in this function.
   /// This is equivalent to the sum of the sizes of each basic block contained
   /// within this function.
-  unsigned getInstructionCount();
+  unsigned getInstructionCount() const;
 
   /// Returns the FunctionType for me.
   FunctionType *getFunctionType() const {
index 36ba8d0..ec09481 100644 (file)
@@ -195,9 +195,9 @@ LLVMContext &Function::getContext() const {
   return getType()->getContext();
 }
 
-unsigned Function::getInstructionCount() {
+unsigned Function::getInstructionCount() const {
   unsigned NumInstrs = 0;
-  for (BasicBlock &BB : BasicBlocks)
+  for (const BasicBlock &BB : BasicBlocks)
     NumInstrs += std::distance(BB.instructionsWithoutDebug().begin(),
                                BB.instructionsWithoutDebug().end());
   return NumInstrs;