diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index 1b91537c5d9b..630f47e8bb57 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -158,7 +158,7 @@ class Function : public GlobalObject, public ilist_node { /// 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 { diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp index 36ba8d0721f3..ec094812ceb2 100644 --- a/lib/IR/Function.cpp +++ b/lib/IR/Function.cpp @@ -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;