[PATCH] D132089: [BOLT][NFC] Simplify handleRelocation

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 20:48:51 PDT 2022


Amir updated this revision to Diff 453519.
Amir added a comment.

Revert definitions in if clauses


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132089/new/

https://reviews.llvm.org/D132089

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp


Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -30,6 +30,7 @@
 #include "bolt/Utils/CommandLineOpts.h"
 #include "bolt/Utils/Utils.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
 #include "llvm/ExecutionEngine/RuntimeDyld.h"
@@ -2499,16 +2500,12 @@
             BC->getBinaryFunctionAtAddress(Address + 1)) {
       // Do an extra check that the function was referenced previously.
       // It's a linear search, but it should rarely happen.
-      bool Found = false;
-      for (const auto &RelKV : ContainingBF->Relocations) {
-        const Relocation &Rel = RelKV.second;
-        if (Rel.Symbol == RogueBF->getSymbol() &&
-            !Relocation::isPCRelative(Rel.Type)) {
-          Found = true;
-          break;
-        }
-      }
-
+      auto CheckReloc = [&](const Relocation &Rel) {
+        return Rel.Symbol == RogueBF->getSymbol() &&
+               !Relocation::isPCRelative(Rel.Type);
+      };
+      bool Found = llvm::any_of(
+          llvm::make_second_range(ContainingBF->Relocations), CheckReloc);
       if (Found) {
         errs() << "BOLT-WARNING: detected possible compiler de-virtualization "
                   "bug: -1 addend used with non-pc-relative relocation against "
@@ -2620,8 +2617,8 @@
         if (SymbolFlags & SymbolRef::SF_Global) {
           Name = SymbolName;
         } else {
-          if (StringRef(SymbolName)
-                  .startswith(BC->AsmInfo->getPrivateGlobalPrefix()))
+          StringRef PGPrefix(BC->AsmInfo->getPrivateGlobalPrefix());
+          if (StringRef(SymbolName).startswith(PGPrefix))
             Name = NR.uniquify("PG" + SymbolName);
           else
             Name = NR.uniquify(SymbolName);
@@ -2644,9 +2641,9 @@
       LLVM_DEBUG({
         dbgs() << "BOLT-DEBUG: processing ending on data relocation "
                << NumDataRelocations << ": ";
+        printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress,
+                            Addend, ExtractedValue);
       });
-      printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress,
-                          Addend, ExtractedValue);
     }
 
     return (!opts::MaxDataRelocations ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132089.453519.patch
Type: text/x-patch
Size: 2433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220818/af17de6a/attachment.bin>


More information about the llvm-commits mailing list