[llvm] c143b77 - [NFC] Cleanup: BasicBlock::getInstList() and BasicBlock::getSublistAccess() are now private

Vasileios Porpodas via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 10:20:41 PST 2022


Author: Vasileios Porpodas
Date: 2022-12-14T10:20:05-08:00
New Revision: c143b77b30fc23f70aac94be66e412651771c0fc

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

LOG: [NFC] Cleanup: BasicBlock::getInstList() and BasicBlock::getSublistAccess() are now private

We now have an adequate set of API functions, including BasicBlock::splice(),
BasicBlock::erase(), Instruction::insertAt() etc. that we shouldn't need access
to the underlying instruction list.

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

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 9a6def27bc7f..f01c14fc3d8d 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -89,6 +89,14 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
   using reverse_iterator = InstListType::reverse_iterator;
   using const_reverse_iterator = InstListType::const_reverse_iterator;
 
+  // These functions and classes need access to the instruction list.
+  friend void Instruction::removeFromParent();
+  friend iplist<Instruction>::iterator Instruction::eraseFromParent();
+  friend BasicBlock::iterator Instruction::insertAt(BasicBlock *BB,
+                                                    BasicBlock::iterator It);
+  friend class llvm::SymbolTableListTraits<llvm::Instruction>;
+  friend class llvm::ilist_node_with_parent<llvm::Instruction, llvm::BasicBlock>;
+
   /// Creates a new BasicBlock.
   ///
   /// If the Parent parameter is specified, the basic block is automatically
@@ -366,18 +374,21 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
   }
   iterator_range<phi_iterator> phis();
 
+private:
   /// Return the underlying instruction list container.
-  ///
-  /// Currently you need to access the underlying instruction list container
-  /// directly if you want to modify it.
+  /// This is deliberately private because we have implemented an adequate set
+  /// of functions to modify the list, including BasicBlock::splice(),
+  /// BasicBlock::erase(), Instruction::insertAt() etc.
   const InstListType &getInstList() const { return InstList; }
-        InstListType &getInstList()       { return InstList; }
+  InstListType &getInstList() { return InstList; }
 
   /// Returns a pointer to a member of the instruction list.
-  static InstListType BasicBlock::*getSublistAccess(Instruction*) {
+  /// This is private on purpose, just like `getInstList()`.
+  static InstListType BasicBlock::*getSublistAccess(Instruction *) {
     return &BasicBlock::InstList;
   }
 
+public:
   /// Returns a pointer to the symbol table if one exists.
   ValueSymbolTable *getValueSymbolTable();
 

diff  --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 0030ff6ce568..06660ba249ef 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -482,7 +482,7 @@ void BasicBlock::splice(BasicBlock::iterator ToIt, BasicBlock *FromBB,
 
 BasicBlock::iterator BasicBlock::erase(BasicBlock::iterator FromIt,
                                        BasicBlock::iterator ToIt) {
-  return getInstList().erase(FromIt, ToIt);
+  return InstList.erase(FromIt, ToIt);
 }
 
 void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {


        


More information about the llvm-commits mailing list