[llvm] f2bd784 - [BPF] Avoid repeating MI->getOperand(NumDefs) x3

Tamir Duberstein via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 07:56:09 PDT 2023


Author: Tamir Duberstein
Date: 2023-08-02T10:56:01-04:00
New Revision: f2bd78415fd832c9ab3e5bfb323703f0be8c0baa

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

LOG: [BPF] Avoid repeating MI->getOperand(NumDefs) x3

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

Added: 
    

Modified: 
    llvm/lib/Target/BPF/BTFDebug.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index 485ba88a4654b7..54427b073cb897 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -17,6 +17,7 @@
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/MachineOperand.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCSectionELF.h"
@@ -1318,14 +1319,18 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) {
   if (MI->isInlineAsm()) {
     // Count the number of register definitions to find the asm string.
     unsigned NumDefs = 0;
-    for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
-         ++NumDefs)
-      ;
-
-    // Skip this inline asm instruction if the asmstr is empty.
-    const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
-    if (AsmStr[0] == 0)
-      return;
+    while (true) {
+      const MachineOperand &MO = MI->getOperand(NumDefs);
+      if (MO.isReg() && MO.isDef()) {
+        ++NumDefs;
+        continue;
+      }
+      // Skip this inline asm instruction if the asmstr is empty.
+      const char *AsmStr = MO.getSymbolName();
+      if (AsmStr[0] == 0)
+        return;
+      break;
+    }
   }
 
   if (MI->getOpcode() == BPF::LD_imm64) {


        


More information about the llvm-commits mailing list