[PATCH] D64984: [Verifier] Verify all blockaddress constants left over have at least one user.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 02:45:24 PDT 2019


fhahn created this revision.
fhahn added reviewers: craig.topper, brzycki, davide, Gerolf.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Some passes currently do not properly clean up blockaddress constants,
which limits further optimizations, as the blocks remain used by the
constant and remain marked as having their address taken.

With this patch and D64936 <https://reviews.llvm.org/D64936>, the following tests are failing:

  LLVM :: Transforms/ConstProp/basictest.ll
  LLVM :: Transforms/IndirectBrExpand/basic.ll


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64984

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -44,6 +44,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/Verifier.h"
+#include "LLVMContextImpl.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -308,6 +309,8 @@
 
   void checkAtomicMemAccessSize(Type *Ty, const Instruction *I);
 
+  using BlockAddressMapTy = decltype(LLVMContextImpl::BlockAddresses);
+
 public:
   explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError,
                     const Module &M)
@@ -381,6 +384,8 @@
     for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable())
       visitComdat(SMEC.getValue());
 
+    verifyBlockAddressConstants(M.getContext().pImpl->BlockAddresses);
+
     visitModuleFlags(M);
     visitModuleIdents(M);
     visitModuleCommandLines(M);
@@ -525,6 +530,9 @@
 
   /// Verify all-or-nothing property of DIFile source attribute within a CU.
   void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F);
+
+  /// Verify all blockaddresses in \p CM have at least one user.
+  void verifyBlockAddressConstants(const BlockAddressMapTy &CM);
 };
 
 } // end anonymous namespace
@@ -4971,6 +4979,12 @@
            "inconsistent use of embedded source");
 }
 
+void Verifier::verifyBlockAddressConstants(const BlockAddressMapTy &CM) {
+  for (auto &KV : CM)
+    Assert(!KV.second->use_empty(), "Blockaddress does not have any users",
+           KV.second);
+}
+
 //===----------------------------------------------------------------------===//
 //  Implement the public interfaces to this file...
 //===----------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64984.210784.patch
Type: text/x-patch
Size: 1837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190719/e5fc3755/attachment.bin>


More information about the llvm-commits mailing list