[llvm] r228611 - MemDerefPrinter: Require DataLayoutPass for higher accuracy

Ramkumar Ramachandra artagnon at gmail.com
Mon Feb 9 13:50:04 PST 2015


Author: artagnon
Date: Mon Feb  9 15:50:03 2015
New Revision: 228611

URL: http://llvm.org/viewvc/llvm-project?rev=228611&view=rev
Log:
MemDerefPrinter: Require DataLayoutPass for higher accuracy

Without a valid data layout, deferenceable(N) doesn't get parsed or
propagated. Since this is the key item we are testing, add a dependency
on the pass.

Differential Revision: http://reviews.llvm.org/D7508

Modified:
    llvm/trunk/lib/Analysis/MemDerefPrinter.cpp
    llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll

Modified: llvm/trunk/lib/Analysis/MemDerefPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemDerefPrinter.cpp?rev=228611&r1=228610&r2=228611&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemDerefPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/MemDerefPrinter.cpp Mon Feb  9 15:50:03 2015
@@ -11,6 +11,7 @@
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
 #include "llvm/IR/CallSite.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -25,6 +26,10 @@ namespace {
     MemDerefPrinter() : FunctionPass(ID) {
       initializeMemDerefPrinterPass(*PassRegistry::getPassRegistry());
     }
+    void getAnalysisUsage(AnalysisUsage &AU) const override {
+      AU.addRequired<DataLayoutPass>();
+      AU.setPreservesAll();
+    }
     bool runOnFunction(Function &F) override;
     void print(raw_ostream &OS, const Module * = nullptr) const override;
     void releaseMemory() override {
@@ -34,18 +39,22 @@ namespace {
 }
 
 char MemDerefPrinter::ID = 0;
-INITIALIZE_PASS(MemDerefPrinter, "print-memderefs",
-                "Memory Dereferenciblity of pointers in function", false, true)
+INITIALIZE_PASS_BEGIN(MemDerefPrinter, "print-memderefs",
+                      "Memory Dereferenciblity of pointers in function", false, true)
+INITIALIZE_PASS_DEPENDENCY(DataLayoutPass)
+INITIALIZE_PASS_END(MemDerefPrinter, "print-memderefs",
+                    "Memory Dereferenciblity of pointers in function", false, true)
 
 FunctionPass *llvm::createMemDerefPrinter() {
   return new MemDerefPrinter();
 }
 
 bool MemDerefPrinter::runOnFunction(Function &F) {
+  const DataLayout *DL = &getAnalysis<DataLayoutPass>().getDataLayout();
   for (auto &I: inst_range(F)) {
     if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
       Value *PO = LI->getPointerOperand();
-      if (PO->isDereferenceablePointer(nullptr))
+      if (PO->isDereferenceablePointer(DL))
         Vec.push_back(PO);
     }
   }

Modified: llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll?rev=228611&r1=228610&r2=228611&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll (original)
+++ llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll Mon Feb  9 15:50:03 2015
@@ -3,11 +3,13 @@
 ; Uses the print-deref (+ analyze to print) pass to run
 ; isDereferenceablePointer() on many load instruction operands
 
+target datalayout = "e"
+
 declare zeroext i1 @return_i1()
 
 @globalstr = global [6 x i8] c"hello\00"
 
-define void @test(i32 addrspace(1)* byval %dparam) {
+define void @test(i32 addrspace(1)* dereferenceable(8) %dparam) {
 ; CHECK: The following are dereferenceable:
 ; CHECK: %globalptr
 ; CHECK: %alloca





More information about the llvm-commits mailing list