1 //===- MemDerefPrinter.cpp - Printer for isDereferenceablePointer ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Analysis/Passes.h"
11 #include "llvm/ADT/SetVector.h"
12 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
13 #include "llvm/IR/CallSite.h"
14 #include "llvm/IR/InstIterator.h"
15 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/raw_ostream.h"
21 struct MemDerefPrinter : public FunctionPass {
22 SmallVector<Value *, 4> Vec;
24 static char ID; // Pass identifcation, replacement for typeid
25 MemDerefPrinter() : FunctionPass(ID) {
26 initializeMemDerefPrinterPass(*PassRegistry::getPassRegistry());
28 bool runOnFunction(Function &F) override;
29 void print(raw_ostream &OS, const Module * = nullptr) const override;
30 void releaseMemory() override {
36 char MemDerefPrinter::ID = 0;
37 INITIALIZE_PASS(MemDerefPrinter, "print-memderefs",
38 "Memory Dereferenciblity of pointers in function", false, true)
40 FunctionPass *llvm::createMemDerefPrinter() {
41 return new MemDerefPrinter();
44 bool MemDerefPrinter::runOnFunction(Function &F) {
45 for (auto &I: inst_range(F)) {
46 if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
47 Value *PO = LI->getPointerOperand();
48 if (PO->isDereferenceablePointer(nullptr))
55 void MemDerefPrinter::print(raw_ostream &OS, const Module *M) const {
56 OS << "The following are dereferenceable:\n";