[llvm] 857d699 - Move BasicBlock::getTerminator definition to the header

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 13:11:59 PDT 2022


Author: Artur Pilipenko
Date: 2022-04-05T13:11:38-07:00
New Revision: 857d699667f62b16e75a716f4b8bcb520684e740

URL: https://github.com/llvm/llvm-project/commit/857d699667f62b16e75a716f4b8bcb520684e740
DIFF: https://github.com/llvm/llvm-project/commit/857d699667f62b16e75a716f4b8bcb520684e740.diff

LOG: Move BasicBlock::getTerminator definition to the header

This way it can be inlined to its caller. This method
shows up in the profile and it is essentially a fancy
getter. It would benefit from inlining into its callers.

NFC.

Added: 
    

Modified: 
    llvm/include/llvm/IR/BasicBlock.h
    llvm/lib/IR/BasicBlock.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index 3204ec76b340d..d487223eca021 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -116,7 +116,11 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
 
   /// Returns the terminator instruction if the block is well formed or null
   /// if the block is not well formed.
-  const Instruction *getTerminator() const LLVM_READONLY;
+  const Instruction *getTerminator() const LLVM_READONLY {
+    if (InstList.empty() || !InstList.back().isTerminator())
+      return nullptr;
+    return &InstList.back();
+  }
   Instruction *getTerminator() {
     return const_cast<Instruction *>(
         static_cast<const BasicBlock *>(this)->getTerminator());

diff  --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 99e3afaa8ba8b..f064ff503ebab 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -148,12 +148,6 @@ const Module *BasicBlock::getModule() const {
   return getParent()->getParent();
 }
 
-const Instruction *BasicBlock::getTerminator() const {
-  if (InstList.empty() || !InstList.back().isTerminator())
-    return nullptr;
-  return &InstList.back();
-}
-
 const CallInst *BasicBlock::getTerminatingMustTailCall() const {
   if (InstList.empty())
     return nullptr;


        


More information about the llvm-commits mailing list