[llvm] [BPF] Remove 'may_goto 0' instructions (PR #123482)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 13:52:45 PST 2025


================
@@ -682,6 +685,56 @@ bool BPFMIPreEmitPeephole::insertMissingCallerSavedSpills() {
   return Changed;
 }
 
+bool BPFMIPreEmitPeephole::removeMayGotoZero() {
+  bool Changed = false;
+  MachineBasicBlock *Prev_MBB, *Curr_MBB = nullptr;
+
+  for (MachineBasicBlock &MBB : make_early_inc_range(reverse(*MF))) {
+    Prev_MBB = Curr_MBB;
+    Curr_MBB = &MBB;
+    if (Prev_MBB == nullptr)
+      continue;
+
+    MachineInstr &MI = MBB.back();
+    if (MI.getOpcode() != TargetOpcode::INLINEASM_BR)
+      continue;
+
+    const char *AsmStr = MI.getOperand(0).getSymbolName();
+    SmallVector<StringRef, 4> AsmPieces;
+    SplitString(AsmStr, AsmPieces, ";\n");
----------------
eddyz87 wrote:

Maybe count `";\n"` instead of splitting?
To avoid allocations for unrelated assembly blocks.

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


More information about the llvm-commits mailing list