[llvm] [BasicBlockSections] Apply path cloning with -basic-block-sections. (PR #68860)

Rahman Lavaee via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 14:31:30 PDT 2023


================
@@ -285,6 +314,130 @@ static bool hasInstrProfHashMismatch(MachineFunction &MF) {
   return false;
 }
 
+// Returns if we can legally apply all clonings specified in `ClonePaths`.
+static bool
+IsValidCloning(const MachineFunction &MF,
+               const DenseMap<unsigned, MachineBasicBlock *> &BBIDToBlock,
+               const SmallVector<unsigned> &ClonePath) {
+  const MachineBasicBlock *PrevBB = nullptr;
+  for (size_t I = 0; I < ClonePath.size(); ++I) {
+    unsigned BBID = ClonePath[I];
+    const MachineBasicBlock *PathBB = BBIDToBlock.lookup(BBID);
+    if (!PathBB) {
+      WithColor::warning() << "no block with id " << BBID << " in function "
+                           << MF.getName() << "\n";
+      return false;
+    }
+
+    if (PrevBB && !PrevBB->isSuccessor(PathBB)) {
+      WithColor::warning() << "block #" << BBID
+                           << " is not a successor of block #"
+                           << *PrevBB->getBBID() << " in function "
+                           << MF.getName() << "\n";
+      return false;
+    }
+
+    if (I != ClonePath.size() - 1 && !PathBB->empty() &&
+        PathBB->back().isIndirectBranch()) {
+      WithColor::warning()
+          << "block #" << BBID
+          << " has indirect branch and appears as the non-tail block of a "
+             "path in function "
----------------
rlavaee wrote:

We cannot clone a block that is in the middle of a path and has an indirect branch.

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


More information about the llvm-commits mailing list