[llvm] [IR] Add per-function numbers to basic blocks (PR #101052)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 13:00:20 PDT 2024


================
@@ -75,6 +75,22 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
 private:
   // Important things that make up a function!
   BasicBlockListType BasicBlocks;         ///< The basic blocks
+
+  // Basic blocks need to get their number when added to a function.
+  friend void BasicBlock::setParent(Function *);
+  unsigned NextBlockNum = 0;
+
+public:
+  /// Renumber basic blocks into a dense value range starting from 0. Be aware
+  /// that other data structures and analyses (e.g., DominatorTree) may depend
+  /// on the value numbers and need to be updated or invalidated.
+  void renumberBlocks();
+
+  /// Assert that all blocks have unique numbers within 0..NextBlockNum. This
+  /// has O(n) runtime complexity.
+  void validateBlockNumbers() const;
----------------
nikic wrote:

Can make this private, or do you expect this to be called from more places in future patches?

https://github.com/llvm/llvm-project/pull/101052


More information about the llvm-commits mailing list